Пример #1
0
        public MonitoringClientFactory(DateTime dtStart,
                                       DateTime dtEnd,
                                       double?maxValue,
                                       bool isConcentratorsEnabled,
                                       bool isMetersEnabled,
                                       List <int> selectedEvents,
                                       List <byte> selectedСhannels,
                                       VALUES_FLAG_DB?filterFlag,
                                       CancellationToken cancellationToken,
                                       ProgressBarButton progressBar, Action <TStatisticInformation> showTotalStatistic, Guid waiterId,
                                       MonitoringDBSupport monitoringDBResult, ModuleType типМодуля)
        {
            DtStart   = dtStart;
            DtEnd     = dtEnd;
            _maxValue = maxValue;
            IsConcentratorsEnabled = isConcentratorsEnabled;
            IsMetersEnabled        = isMetersEnabled;
            _selectedEvents        = selectedEvents;
            _selectedСhannels      = selectedСhannels;
            _filterFlag            = filterFlag;
            _cancellationToken     = cancellationToken;
            _rowsComparer          = new TMonitoringAnalyseRowEqualityComparer();

            MonitoringAnalyseDict = MakeMonitoringSource(monitoringDBResult, типМодуля);
            _progressBar          = progressBar;
            _showTotalStatistic   = showTotalStatistic;
            _waiterId             = waiterId;
            _progressBar.SetIndeterminat(true);
        }
Пример #2
0
        public Task RunServerBuild(BackgroundWorker worker)
        {
            var parents = MonitoringAnalyseDict.Keys.ToList();

            try
            {
                //Запрос формирования данных
                ARM_Service_.Monit_GetArchive(_waiterId, parents, _selectedСhannels
                                              , DtStart, DtEnd, _maxValue, _selectedEvents, IsConcentratorsEnabled, _filterFlag);
                //Ждем формирования первых пакетов
                Thread.Sleep(1000);
            }
            catch (Exception ex)
            {
                Manager.UI.ShowMessage(ex.Message);
                return(null);
            }


            //if (_showTotalStatistic != null)
            //{
            //    _showTotalStatistic(request.StatisticInformation);
            //}

            _isRequestCompleted = false;
            //double packetSize = request.ProgressPercent;

            //if (request.Result != null && request.Result.Count > 0)
            //{
            //    _stackForBuildResult.PushRange(request.Result.ToArray());
            //    _progressBar.IncValue(packetSize);
            //}

            //Отмена выполнения
            if (worker.CancellationPending || _cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            //Запускаем построитель результатов
            var builderTask = Task.Factory.StartNew(BuildPacketResult, _cancellationToken);

            //Получение следующих пакетов
            bool isLastPacket = false;
            int  voidCounter  = 0;
            int  errCounter   = 0;
            bool isFirst      = true;
            TStatisticInformation statisticInformation = null;

            int requestNumber = 0;

            do
            {
                try
                {
                    if (_cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }

                    var packet = ServiceFactory.ArmServiceInvokeSync <Tuple <bool, MemoryStream, string, TStatisticInformation, TMonitoringAnalyseResult> >("Monit_WaitArchives", requestNumber, _waiterId);
                    if (packet != null)
                    {
                        if (!string.IsNullOrEmpty(packet.Item3))
                        {
                            Manager.UI.ShowMessage(packet.Item3);
                        }

                        isLastPacket = packet.Item1;
                        if (isLastPacket)
                        {
                            statisticInformation = packet.Item4;
                            break;
                        }

                        if (packet.Item2 != null)
                        {
                            requestNumber++;
                            //var nextPart = packet.Item2.DecompressAndDeserialize<List<TMonitoringAnalyseResult>>();
                            var decomoressed = CompressUtility.DecompressGZip(packet.Item2);
                            decomoressed.Position = 0;
                            var nextPart = Serializer.Deserialize <List <TMonitoringAnalyseResult> >(decomoressed);
                            if (nextPart != null && nextPart.Count > 0)
                            {
                                _stackForBuildResult.PushRange(nextPart.ToArray());
                                voidCounter = 0;
                                _mres.Set();
                                if (isFirst)
                                {
                                    _progressBar.SetIndeterminat(false);
                                    isFirst = false;
                                }
                            }
                            else
                            {
                                Thread.Sleep(2000);
                            }
                        }
                        else
                        {
                            if (++voidCounter > 501)
                            {
                                isLastPacket = true;
                                Manager.UI.ShowMessage("MonitoringClientFactory: Превышен лимит ожидания пакетов");
                            }
                            else
                            {
                                Thread.Sleep(5000);
                            }
                        }
                    }
                    else
                    {
                        throw new Exception();
                    }

                    errCounter = 0;
                }
                catch (Exception ex)
                {
                    if (++errCounter > 6)
                    {
                        isLastPacket = true;
                        Manager.UI.ShowMessage("MonitoringClientFactory: Превышен лимит пустых пакетов");
                        _progressBar.SetIndeterminat(false);
                    }
                    else
                    {
                        Manager.UI.ShowMessage(ex.Message);
                        Thread.Sleep(1000);
                    }
                }
                Thread.Sleep(200);
            } while (!isLastPacket);

            if (statisticInformation != null && _showTotalStatistic != null)
            {
                _showTotalStatistic(statisticInformation);
            }

            _isRequestCompleted = true;
            _mres.Set();
            return(builderTask);
        }