using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace RDH.PharmacyPlatform.Sync.Core
{
    /// <summary>
    /// 表示同步节点信息管理的类
    /// </summary>
    public class SyncNodeManager
    {
        public IEnumerable<SyncNode> ListNodes() 
        {
            using (ConnectionSessionScope conn = new ConnectionSessionScope(Bootstrap.DbConnectionString)) 
            {
                SyncNodeDAL syncNodeDAL = new SyncNodeDAL();
                return syncNodeDAL.ListModels();
            }
        }
        public void AddNode(SyncNode node) 
        {
            Debug.WriteLine($"添加同步节点 start, id:{Thread.CurrentThread.ManagedThreadId}");
            using (ConnectionSessionScope conn = new ConnectionSessionScope(Bootstrap.DbConnectionString))
            {
                SyncNodeDAL syncNodeDAL = new SyncNodeDAL();
                syncNodeDAL.InsertModel(node);
            }
        }
        public void RemoveNode(SyncNode node) 
        {
            Debug.WriteLine($"删除同步节点 start, id:{Thread.CurrentThread.ManagedThreadId}");
            using (ConnectionSessionScope conn = new ConnectionSessionScope(Bootstrap.DbConnectionString))
            {
                SyncNodeDAL syncNodeDAL = new SyncNodeDAL();
                syncNodeDAL.DeleteModel(node);
            }
        }
    }
}
