コード例 #1
0
        private string GenerateFileName(ExportReportCommand exportCommand)
        {
            VkGroup vkGroup = this.vkGroupRepository.GetGroupById(exportCommand.VkGroupId);

            return(!exportCommand.DateRange.IsSpecified
                ? string.Format("export_of_{0}.xslx", vkGroup.Name)
                : string.Format("export_of_{0}_from_{1}_to_{2}.xlsx", vkGroup.Name, exportCommand.DateRange.From.ToString(CONST_DateTimeFormat), exportCommand.DateRange.To.ToString(CONST_DateTimeFormat)));
        }
コード例 #2
0
 private string ScheduleExport(VkGroup vkGroup, DateRange dateRange, int initiatorUserId)
 {
     using (ICommandSender commandSender = Factory.GetInstance <ICommandSender>().Open(CONST_ExportQueueName))
     {
         string ticketId             = Guid.NewGuid().ToString();
         ExportReportCommand command = new ExportReportCommand
         {
             VkGroupId       = vkGroup.Id,
             DateRange       = dateRange,
             InitiatorUserId = initiatorUserId,
             TicketId        = ticketId
         };
         commandSender.SendCommand(command);
         return(ticketId);
     }
 }
コード例 #3
0
        private void SendExportFinished(ExportReportCommand exportCommand, bool isSuccess, string virtualFilePath = "")
        {
            using (ICommandSender commandSender = Factory.GetInstance <ICommandSender>().Open(CONST_ExportResultQueueName))
            {
                ExportResultCommand command = new ExportResultCommand
                {
                    VkGroupId       = exportCommand.VkGroupId,
                    DateRange       = exportCommand.DateRange,
                    InitiatorUserId = exportCommand.InitiatorUserId,
                    TicketId        = exportCommand.TicketId,
                    IsSuccess       = isSuccess,
                    FilePath        = virtualFilePath
                };

                commandSender.SendCommand(command);
            }
        }
コード例 #4
0
        public void ProcessExportQueue()
        {
            using (ICommandReceiver receiver = Factory.GetInstance <ICommandReceiver>().Open(CONST_ExportQueueName))
            {
                while (true)
                {
                    ExportReportCommand exportCommand = null;

                    try
                    {
                        exportCommand = receiver.GetCommand <ExportReportCommand>();

                        if (exportCommand == null)
                        {
                            this.log.Debug("No export command found. Processing stopped.");
                            return;
                        }

                        string      fileName   = this.GenerateFileName(exportCommand);
                        IFileSystem fileSystem = this.fileSystemFactory.CreateFileSystem(exportCommand.InitiatorUserId);

                        byte[] exportResult    = this.dataProvider.ExportToXlsx(exportCommand.VkGroupId, exportCommand.DateRange);
                        string virtualFilePath = fileSystem.SaveToFile(fileName, exportResult);

                        this.SendExportFinished(exportCommand, true, virtualFilePath);
                    }
                    catch (Exception exc)
                    {
                        this.log.ErrorFormat("Exception is occured while processing a group Id = {0}, for userId = {1}: {2}", exportCommand != null ? exportCommand.VkGroupId : 0, exportCommand != null ? exportCommand.InitiatorUserId : 0, exc.ToString());

                        if (exportCommand != null)
                        {
                            this.SendExportFinished(exportCommand, isSuccess: false);
                        }
                    }
                    finally
                    {
                        if (exportCommand != null)
                        {
                            exportCommand.MarkAsCompleted();
                        }
                    }
                }
            }
        }