using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MediII.Adapter.Scan.Interface;
using IL.Common;

namespace MediII.Adapter.Scanner
{
    public class Scaner
    {
        IEnumerable<IScan> listScaner = new List<IScan>();


        public int Start(string[] importsPaths)
        {
            return Start(importsPaths, null);
        }
        public int Start(string[] importsPaths, MessageLogDelegate msgLog)
        {
            ServicesContainer container = new ServicesContainer();
            foreach (string path in importsPaths)
            {
                HostingMEF.SatisfyImports(container, path);
            }
            listScaner = container.Scanners;

            foreach (var scanner in container.Scanners)
            {
                //间隔可以分别设置
                //scanner.Interval = XX
                //启动扫描     
                //if (!scanner.ToString().Contains("HL7_Treatment_Create_Scanner"))
                //{
                //    continue;
                //}
                LogHelper.LogInfo("服务启动 " + scanner.GetType().FullName, LogCatagories.AdapterScan);
                scanner.MessageLog += msgLog;
                scanner.Start();
            }
            return 1;
        }

        public int Stop()
        {
            foreach (var scaner in listScaner)
            {
                if (scaner.IsRuning)
                {
                    LogHelper.LogInfo("服务停止 " + scaner.GetType().FullName, LogCatagories.AdapterScan);
                    scaner.Stop();
                }
                   
            }
            return 1;
        }
    }
}
