Example #1
0
 public static void ReloadExtractors()
 {
     lock (ExtractorServer.Extractors)
     {
         foreach (BcDevices item_2 in ExtractorServer.AllDevices)
         {
             int local_1 = 0;
             foreach (ExtractorServer.KeyExtractor item_0 in ExtractorServer.Extractors)
             {
                 if (item_0.Device.Id == item_2.Id && item_0.CurrentThread != null && item_0.CurrentThread.ThreadState != System.Threading.ThreadState.Aborted && item_0.CurrentThread.ThreadState != System.Threading.ThreadState.Stopped)
                 {
                     item_0.Device = item_2;
                     ++local_1;
                 }
             }
             if (local_1 < item_2.ExtractorCount)
             {
                 for (; local_1 < item_2.ExtractorCount; ++local_1)
                 {
                     ExtractorServer.KeyExtractor local_2_1 = new ExtractorServer.KeyExtractor()
                     {
                         Device        = item_2,
                         CurrentThread = new Thread(new ParameterizedThreadStart(ExtractorServer.WorkerThread))
                         {
                             IsBackground = true
                         }
                     };
                     local_2_1.CurrentThread.Start((object)local_2_1);
                     ExtractorServer.Extractors.Add(local_2_1);
                 }
             }
             else if (local_1 > item_2.ExtractorCount)
             {
                 while (local_1 > item_2.ExtractorCount)
                 {
                     ExtractorServer.KeyExtractor local_5 = (ExtractorServer.KeyExtractor)null;
                     foreach (ExtractorServer.KeyExtractor item_1 in ExtractorServer.Extractors)
                     {
                         if (item_1.Device.Id == item_2.Id)
                         {
                             local_5          = item_1;
                             local_5.StopFlag = true;
                             local_5.WaitForStop();
                             --local_1;
                             break;
                         }
                     }
                     if (local_5 != null)
                     {
                         local_5.CurrentThread.Abort();
                         ExtractorServer.Extractors.Remove(local_5);
                     }
                 }
             }
         }
     }
 }
Example #2
0
 public void SetDevice(Guid id, Hashtable row, bool delete)
 {
     try
     {
         BcDevices deviceById = ExtractorServer.GetDeviceById(id);
         BcDevices bcDevices1 = BcDevicesStorageExtensions.LoadById(id);
         if (bcDevices1.Esid != ExtractorServer.MainServer.Id)
         {
             delete = true;
         }
         if (!delete)
         {
             if (deviceById.Id != Guid.Empty)
             {
                 int extractorCount = deviceById.ExtractorCount;
                 ExtractorServer.BreakExtractor(deviceById.Id);
                 deviceById.SetData(row);
                 if (extractorCount != deviceById.ExtractorCount)
                 {
                     ExtractorServer.ReloadExtractors();
                 }
                 ExtractorServer.UnBreakExtractor(deviceById.Id);
             }
             else
             {
                 try
                 {
                     if (bcDevices1.Esid != ExtractorServer.MainServer.Id)
                     {
                         BcDevices bcDevices2 = BcDevicesStorageExtensions.LoadById(id);
                         bcDevices2.CurrentThread = new Thread(new ParameterizedThreadStart(ExtractorServer.VideoThread))
                         {
                             IsBackground = true
                         };
                         bcDevices2.CurrentThread.Start((object)bcDevices2);
                         ExtractorServer.AllDevices.Add(bcDevices2);
                         ExtractorServer.ReloadExtractors();
                     }
                 }
                 catch (Exception ex)
                 {
                     ExtractorServer.Logger.Error((object)"Set device error", ex);
                 }
             }
         }
         else
         {
             for (int index = 0; index < ExtractorServer.Extractors.Count; ++index)
             {
                 if (ExtractorServer.Extractors.Count > 0 && index >= 0 && index < ExtractorServer.Extractors.Count)
                 {
                     ExtractorServer.KeyExtractor keyExtractor = ExtractorServer.Extractors[index];
                     if (keyExtractor.Device.Id == id)
                     {
                         keyExtractor.StopFlag = true;
                         keyExtractor.WaitForStop();
                         ExtractorServer.Extractors.RemoveAt(index);
                         break;
                     }
                 }
             }
             for (int index = 0; index < ExtractorServer.AllDevices.Count; ++index)
             {
                 if (ExtractorServer.AllDevices[index].Id == id)
                 {
                     ExtractorServer.AllDevices.RemoveAt(index);
                     break;
                 }
             }
         }
     }
     catch
     {
     }
 }