Esempio n. 1
0
 public bool GetState(Action <string, LanStatus> cb)
 {
     if (NICList.Count > 0)
     {
         NICList.ForEach((nic) =>
         {
             cb(nic.DeviceId, nic.Status);
         });
         return(true);
     }
     return(false);
 }
 /// <summary>
 ///
 /// </summary>
 public void Dispose()
 {
     try
     {
         watcher.Enabled = false;
         watcher.Dispose();
         NICList.Clear();
     }
     catch (Exception x)
     {
         RaiseMessageError(x);
     }
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void watcher_EventRecordWritten(object sender, EventRecordWrittenEventArgs e)
 {
     if (e.EventRecord.LogName == Cfg.WindowsLog && e.EventRecord.ProviderName == Cfg.EventSource &&
         (e.EventRecord.Id == Cfg.UpEventId || e.EventRecord.Id == Cfg.DownEventId))
     {
         lock (NICList)
         {
             // 20181106. Configurar los eventos e ID de las LAN's
             if (e.EventRecord.Properties.Count > Cfg.PropertyIndex)
             {
                 string  idLan = e.EventRecord.Properties[Cfg.PropertyIndex /*0*/].Value.ToString();
                 NICItem lan   = NICList.Where(nic => nic.DeviceId == idLan).FirstOrDefault();
                 if (lan != null)
                 {
                     lan.Status = e.EventRecord.Id == Cfg.UpEventId ? LanStatus.Up : LanStatus.Down;
                     RaiseStatusChanged(lan.Index);
                 }
             }
         }
     }
 }
        /// <summary>
        ///
        /// </summary>
        protected void SearchForPhysicalDevices()
        {
            try
            {
                NICList.Clear();
                foreach (EventRecord evento in _LogEntries)
                {
                    if (evento.Properties.Count > 0)
                    {
                        string idDevice = evento.Properties.Count > Cfg.PropertyIndex ? evento.Properties[Cfg.PropertyIndex].Value.ToString() : "Unknow";
#if DEBUG
                        if (NICList.Contains(new NICItem()
                        {
                            DeviceId = idDevice
                        }) == false)
#else
                        if (NICList.Count < 2 && NICList.Contains(new NICItem()
                        {
                            DeviceId = idDevice
                        }) == false)
#endif
                        {
                            NICList.Add(new NICItem()
                            {
                                DeviceId = idDevice, Status = LanStatus.Down                        /*, Index = Index++*/
                            });
                        }
                    }
                }

                int Index = 0;
                NICList = NICList.OrderBy(lan => lan.DeviceId).ToList();
                NICList.ForEach(i => { i.Index = Index++; });
            }
            catch (Exception x)
            {
                RaiseMessageError(x);
            }
        }