Atmo.UI.DevEx.ImportDataForm.ImportDataProcesser.ImportData C# (CSharp) Метод

ImportData() приватный Метод

private ImportData ( object o ) : void
o object
Результат void
            private void ImportData(object o)
            {
                int doneCount = 0;
                int failedCount = 0;
                int successCount = 0;

                Action<int> reportProgress = null;
                if(o is BackgroundWorker)
                    reportProgress = (o as BackgroundWorker).ReportProgress;
                else
                    reportProgress = x => { };

                while(true) {
                    ImportDataSet currentSet = null;
                    lock(_queueLock) {
                        if(_importSetQueue.Count == 0) {
                            if(null == _moveSetQueue) {
                                _importSetQueue = null;
                                break;
                            }
                            Thread.Sleep(100);
                        }
                        else {
                            currentSet = _importSetQueue.Dequeue();
                        }
                    }
                    if (null != currentSet) {
                        bool savedData = false;
                        int lastAnemId = -1;
                        foreach (var file in currentSet.Files) {
                            FileInfo fileLocation;
                            if (!currentSet.MovedToLocation.TryGetValue(file, out fileLocation))
                                fileLocation = file.Path;

                            if (null != fileLocation) {

                                var currentFile = file.Path == fileLocation ? file : DaqDataFileInfo.Create(fileLocation);
                                try {
                                    var pushOk = _dataStore.Push(
                                        currentSet.Sensor.Name, GetPackedReadings(currentFile), _recordOverwrite);

                                    if (pushOk) {
                                        successCount++;
                                        savedData = true;
                                        lastAnemId = file.Nid;
                                    }
                                    else {
                                        failedCount++;
                                    }
                                }
                                catch {
                                    failedCount++;
                                }
                            }

                        }
                        if (savedData) {
                            _dataStore.SetLatestSensorNameForHardwareId(
                                currentSet.Sensor.Name,
                                ((char) (lastAnemId + (byte) ('A'))).ToString()
                            );
                        }

                        System.Diagnostics.Debug.WriteLine("Importing..." + currentSet.Files.Count);
                        doneCount++;
                    }
                    lock(_queueLock) {
                        ImportProgress = doneCount / (double)MaxQueue;
                        reportProgress((int)(Progress * 100));
                    }
                }

                _message = null;
                if (failedCount > 0 || successCount == 0)
                {
                    _message = "Data import failed.";
                }
                else {

                    _message = "Data import completed successfully.";
                }

                lock (_queueLock) {
                    ImportProgress = 1.0;
                    reportProgress((int)(Progress * 100));
                }
            }