using SharpPcap;

namespace LogCap.Common
{
    public class PubRepository
    {
        public static LogExecute log { get; set; }
        public static ILiveDevice liveDevice { get; set; }


        public static List<DDD> GetDeviceList()
        {
            var ver = Pcap.SharpPcapVersion;

            if (CaptureDeviceList.Instance.Count < 1)
            {
                Console.WriteLine("No devices were found on this machine");
            }

            int i = 0;
            List<DDD> list = new List<DDD>();
            foreach (ILiveDevice dev in CaptureDeviceList.Instance)
            {
                DDD dd = new DDD();
                dd.Name = dev.Name;
                dd.Description = dev.Description;

                list.Add(dd);
                Console.WriteLine("{2} <> {0} {1}", dev.Name, dev.Description, i);
                i++;
            }
            return list;
        }

        public bool GetMonitor_Status()
        {
            return PubRepository.liveDevice.Started;
        }
        public static void StartMonitor(int i)
        {
            PubRepository.log = new LogExecute();
            PubRepository.log.Execute(i);

        }
        public static void StopMonitor()
        {
            try
            {

                PubRepository.liveDevice.StopCapture();
                PubRepository.liveDevice.Dispose();
                PubRepository.log = null;
            }
            catch (Exception)
            {

            }
        }

        public string Test()
        {
            return "hello";
        }


    }

    public class DDD
    {
        public string Name { get; set; }
        public string Description { get; set; }
    }
}
