Ejemplo n.º 1
0
        private void ShowTotalStatistic(TStatisticInformation statisticInformation)
        {
            if (statisticInformation == null)
            {
                return;
            }
            //Итоговая информация
            var titleTotal = "Запрограммировано - " + statisticInformation.TotalNumbers + ",  Полные - " + statisticInformation.GoodNumbers
                             + ",  Недостоверные - " + statisticInformation.NotCorrectNumbers + ",  Неполные - " + statisticInformation.DataNotFullNumbers
                             + ",  Отсутствует - " + statisticInformation.AllDataNotFullNumbers + ",  Недостаток тариф. данных - " + statisticInformation.IsHasInactiveTariffNumbers
                             + ", Расход по неакт. тарифу - " + statisticInformation.NotActiveChannelIntegralValueNumbers
                             + ", Некорректное показание - " + statisticInformation.IntegralValueNotCorrectNumbers;

            if (statisticInformation.IsWithEventsOnly)
            {
                titleTotal += " (только из ТИ с выбранными событиями)";
            }

            Dispatcher.BeginInvoke(new Action(() => TitleTotal = titleTotal));
        }
Ejemplo n.º 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);
        }