예제 #1
0
 /// <summary>
 /// Appends information to the string builder.
 /// </summary>
 public static void AppendInfo(ArcUploadState uploadState, StringBuilder sbInfo)
 {
     if (uploadState == null)
     {
         sbInfo
         .AppendLine(Localization.UseRussian ? "Отключена" : "Disabled")
         .AppendLine();
     }
     else
     {
         uploadState.AppendInfo(sbInfo);
     }
 }
예제 #2
0
        /// <summary>
        /// Writes the exporter information to the file.
        /// </summary>
        private void WriteInfo()
        {
            try
            {
                // build text
                StringBuilder sbInfo = new StringBuilder();

                if (Localization.UseRussian)
                {
                    sbInfo
                    .AppendLine("Состояние экспортёра")
                    .AppendLine("--------------------")
                    .Append("Наименование   : ").AppendLine(exporterTitle)
                    .Append("Сервер БД      : ").AppendLine(exporterConfig.ConnectionOptions.Server)
                    .Append("Соединение     : ").AppendLine(ConnStatusNamesRu[(int)connStatus])
                    .AppendLine();

                    void AppendQueueStatsRu(QueueStats queueStats, int?queueSize)
                    {
                        if (queueStats == null)
                        {
                            sbInfo.AppendLine("Очередь не используется");
                        }
                        else
                        {
                            sbInfo
                            .Append("Состояние      : ").AppendLine(queueStats.ErrorState ? "ошибка" : "норма")
                            .Append("В очереди      : ").Append(queueSize).Append(" из ").Append(maxQueueSize).AppendLine()
                            .Append("Экспортировано : ").Append(queueStats.ExportedItems).AppendLine()
                            .Append("Пропущено      : ").Append(queueStats.SkippedItems).AppendLine();
                        }

                        sbInfo.AppendLine();
                    }

                    sbInfo.AppendLine("Текущие данные");
                    sbInfo.AppendLine("--------------");
                    AppendQueueStatsRu(curDataStats, curDataQueue?.Count);

                    sbInfo.AppendLine("Архивные данные");
                    sbInfo.AppendLine("---------------");
                    AppendQueueStatsRu(arcDataStats, arcDataQueue?.Count);

                    sbInfo.AppendLine("События");
                    sbInfo.AppendLine("-------");
                    AppendQueueStatsRu(eventStats, eventQueue?.Count);

                    sbInfo.AppendLine("Передача архивов");
                    sbInfo.AppendLine("----------------");
                    ArcUploadState.AppendInfo(arcUploadState, sbInfo);

                    if (taskUploadState != null)
                    {
                        sbInfo.AppendLine("Передача архивов по заданию");
                        sbInfo.AppendLine("---------------------------");
                        taskUploadState.AppendInfo(sbInfo);
                    }
                }
                else
                {
                    sbInfo
                    .AppendLine("Exporter State")
                    .AppendLine("--------------")
                    .Append("Name       : ").AppendLine(exporterTitle)
                    .Append("DB server  : ").AppendLine(exporterConfig.ConnectionOptions.Server)
                    .Append("Connection : ").AppendLine(ConnStatusNamesEn[(int)connStatus])
                    .AppendLine();

                    void AppendQueueStatsEn(QueueStats queueStats, int?queueSize)
                    {
                        if (queueStats == null)
                        {
                            sbInfo.AppendLine("Queue is not in use");
                        }
                        else
                        {
                            sbInfo
                            .Append("Status     : ").AppendLine(queueStats.ErrorState ? "Error" : "Normal")
                            .Append("In queue   : ").Append(queueSize).Append(" of ").Append(maxQueueSize).AppendLine()
                            .Append("Exported   : ").Append(queueStats.ExportedItems).AppendLine()
                            .Append("Skipped    : ").Append(queueStats.SkippedItems).AppendLine();
                        }

                        sbInfo.AppendLine();
                    }

                    sbInfo.AppendLine("Current Data");
                    sbInfo.AppendLine("------------");
                    AppendQueueStatsEn(curDataStats, curDataQueue?.Count);

                    sbInfo.AppendLine("Archive Data");
                    sbInfo.AppendLine("------------");
                    AppendQueueStatsEn(arcDataStats, arcDataQueue?.Count);

                    sbInfo.AppendLine("Events");
                    sbInfo.AppendLine("------");
                    AppendQueueStatsEn(eventStats, eventQueue?.Count);

                    sbInfo.AppendLine("Archive Uploading");
                    sbInfo.AppendLine("-----------------");
                    ArcUploadState.AppendInfo(arcUploadState, sbInfo);

                    if (taskUploadState != null)
                    {
                        sbInfo.AppendLine("Archive Uploading by Task");
                        sbInfo.AppendLine("-------------------------");
                        taskUploadState.AppendInfo(sbInfo);
                    }
                }

                // write to file
                using (StreamWriter writer = new StreamWriter(infoFileName, false, Encoding.UTF8))
                {
                    writer.Write(sbInfo.ToString());
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                log.WriteException(ex, ModPhrases.WriteInfoError);
            }
        }
예제 #3
0
        /// <summary>
        /// Uploads archive data if possible.
        /// </summary>
        private void UploadArcData()
        {
            ArcUploadState uploadState    = taskUploadState ?? arcUploadState;
            bool           maxTimeReached = false;

            if (uploadState.IsReady &&
                serverData.GetAvailableSnapshots(uploadState.SnapshotDate, exporterConfig.ArcUploadOptions.SnapshotType) is
                DateTime[] availableSnapshots)
            {
                int snapshotIndex = uploadState.SnapshotIndex;
                int snapshotCount = availableSnapshots.Length;

                if (snapshotCount > 0)
                {
                    if (uploadState.SentSnapshotDT < uploadState.SnapshotDate)
                    {
                        if (uploadState.MinSnapshotDT.Date == uploadState.SnapshotDate)
                        {
                            // find a snapshot to upload
                            int index = Array.BinarySearch(availableSnapshots, uploadState.MinSnapshotDT);
                            snapshotIndex = index >= 0 ? index : ~index;
                        }
                        else
                        {
                            // upload the first snapshot
                            snapshotIndex = 0;
                        }
                    }
                    else if (0 <= snapshotIndex && snapshotIndex < snapshotCount &&
                             availableSnapshots[snapshotIndex] == uploadState.SentSnapshotDT)
                    {
                        // upload the next snapshot
                        snapshotIndex++;
                    }
                    else
                    {
                        // correct the index
                        int index = Array.BinarySearch(availableSnapshots, uploadState.SentSnapshotDT);
                        snapshotIndex = index >= 0 ? index + 1 : ~index;
                    }
                }

                if (0 <= snapshotIndex && snapshotIndex < snapshotCount)
                {
                    DateTime snapshotDT = availableSnapshots[snapshotIndex];

                    if (snapshotDT <= uploadState.MaxSnapshotDT)
                    {
                        if (snapshotDT.AddMilliseconds(exporterConfig.ArcUploadOptions.Delay) <= DateTime.Now)
                        {
                            // upload the snapshot
                            uploadState.IsReady          = false;
                            uploadState.SnapshotIndex    = snapshotIndex;
                            uploadState.QueuedSnapshotDT = snapshotDT;
                            MakeArcSnapshots(snapshotDT);
                        }
                    }
                    else
                    {
                        maxTimeReached = true;
                    }
                }
                else if (uploadState.SnapshotDate < DateTime.Today)
                {
                    // go to the next day
                    uploadState.SnapshotIndex = -1;
                    uploadState.SnapshotDate  = uploadState.SnapshotDate.AddDays(1.0);

                    if (uploadState.SnapshotDate > uploadState.MaxSnapshotDT)
                    {
                        maxTimeReached = true;
                    }
                }
                else
                {
                    // date is today and no snapshots to upload
                    maxTimeReached = true;
                }

                if (maxTimeReached && taskUploadState != null)
                {
                    // stop the task
                    taskUploadState = null;
                }
            }
        }
예제 #4
0
 /// <summary>
 /// Initializes objects required for uploading archives.
 /// </summary>
 private void InitArcUploading()
 {
     arcUploadState  = exporterConfig.ArcUploadOptions.Enabled ? new ArcUploadState() : null;
     taskUploadState = null;
 }
예제 #5
0
        /// <summary>
        /// Enqueues the command for execution.
        /// </summary>
        public void EnqueueCmd(int outCnlNum, Command cmd, ref bool passToClients)
        {
            if (cmd == null)
            {
                throw new ArgumentNullException(nameof(cmd));
            }

            if (outCnlNum == exporterConfig.GeneralOptions.OutCnlNum)
            {
                passToClients = false;

                if (CmdParams.Parse(cmd.GetCmdDataStr(), out CmdParams cmdParams, out string errMsg))
                {
                    switch (cmdParams.Action)
                    {
                    case CmdAction.ArcUpload:
                        if (arcDataQueue == null)
                        {
                            log.WriteError(Localization.UseRussian ?
                                           "Невозможно выполнить команду, потому что экспорт архивов отключен" :
                                           "Unable to execute a command because archive export is disabled");
                        }
                        else
                        {
                            log.WriteError(Localization.UseRussian ?
                                           "Получена команда экспорта архивов" :
                                           "Archive export command received");

                            taskUploadState = new ArcUploadState()
                            {
                                SnapshotDate  = cmdParams.MinDT.Date,
                                MinSnapshotDT = cmdParams.MinDT,
                                MaxSnapshotDT = cmdParams.MaxDT
                            };
                        }
                        break;

                    case CmdAction.EvUpload:
                        if (eventQueue == null)
                        {
                            log.WriteError(Localization.UseRussian ?
                                           "Невозможно выполнить команду, потому что экспорт событий отключен" :
                                           "Unable to execute a command because event export is disabled");
                        }
                        else
                        {
                            log.WriteError(Localization.UseRussian ?
                                           "Получена команда экспорта событий" :
                                           "Event export command received");
                            ExportEventsFromFile(cmdParams.MinDT, cmdParams.MaxDT);
                        }
                        break;

                    default:
                        log.WriteError(Localization.UseRussian ?
                                       "Неизвестная команда" :
                                       "Unknown command");
                        break;
                    }
                }
                else
                {
                    log.WriteError(errMsg);
                }
            }