Пример #1
0
        public void Work()
        {
            ConfigurationItems = LoadJson(); // load new config before start tester
            var ipList = new List <string>();

            if (_filesContentList != null)
            {
                if ((_filePathList.Count == 0 || _filesContentList.Count == 0 || ConfigurationItems == null) && Operation.IpList.Count == 0)
                {
                    return;
                }
                ipList.Clear();
                ipList = Operation.GetIpList(_filesContentList); //from files
            }
            if (Operation.IpList != null && Operation.IpList.Count > 0)
            {
                ipList.Clear();
                ipList = Operation.IpList; // form txt file
            }
            if (Operation.CheckIPList(ipList) == false)
            {
                MessageBox.Show(@"Not all lines in file are IP's", @"Error");
                return;
            }
            //progressbar
            BeginInvoke((Action) delegate { ScanProgressBar.Minimum = 0; });
            BeginInvoke((Action) delegate { ScanProgressBar.Maximum = ipList.Count; });
            var progressBarCounter = 0;
            //

            //parallel restrict
            var parallelOptions = new ParallelOptions {
                MaxDegreeOfParallelism = ConfigurationItems[0].parallelOpt
            };

            //
            Parallel.ForEach(ipList, parallelOptions, ip =>
            {
                if (ip == null)
                {
                    return;
                }
                Video.Check(ip, ConfigurationItems[0].scanPort, ConfigurationItems[0].defaultChannel);
                var counter = progressBarCounter;
                BeginInvoke((Action) delegate
                {
                    ScanProgressBar.Value    = counter;
                    progressValue_Label.Text = (int)((float)ScanProgressBar.Value / (float)ScanProgressBar.Maximum * 100) + @"%";
                });
                progressBarCounter += 1;
            });

            BeginInvoke((Action) delegate
            {
                ScanProgressBar.Value    = ScanProgressBar.Maximum;
                progressValue_Label.Text =
                    (int)((float)ScanProgressBar.Value / (float)ScanProgressBar.Maximum * 100) + @"%"; //for visual 100%
                GC.Collect();                                                                          //clean cache
                MessageBox.Show(@"Done!", @"Info!");
                ScanProgressBar.Value    = 0;
                progressValue_Label.Text =
                    (int)((float)ScanProgressBar.Value / (float)ScanProgressBar.Maximum * 100) + @"%";
                Operation.OpenOutputDirectory();
            });
            Operation.RemoveTemp(Operation.DirectoryPath); //remove files and dir with *.mpeg
            Operation.IpList.Clear();
            Operation.FtpCounter = 0;
        }