예제 #1
0
 public FtpExporter(IMapper mapper, ILifetimeScope autofac, FtpExporterConfig config)
 {
     mapper.Map(config, this);
     mapper.Map(config, Properties);
     this.autofac = autofac;
     viewExecutor = autofac.ResolveNamed <IViewExecutor>("commonviewex");
 }
예제 #2
0
        public Logic(ILifetimeScope autofac, IRepository repository, IMonik monik,
                     IMapper mapper, IArchiver archiver, ITelegramBotClient bot, IPackageBuilder builder)
        {
            this.autofac  = autofac;
            this.mapper   = mapper;
            this.monik    = monik;
            this.archiver = archiver;
            this.bot      = bot;
            bot.StartReceiving();
            this.repository = repository;
            packageBuilder  = builder;
            contextsInWork  = new Dictionary <long, IReportTaskRunContext>();

            checkScheduleAndExecuteScheduler =
                new Scheduler {
                Period = 60, TaskMethod = CheckScheduleAndExecute
            };

            tableView = this.autofac.ResolveNamed <IViewExecutor>("CommonTableViewEx");

            operTemplates    = new List <DtoOperTemplate>();
            recepientGroups  = new List <DtoRecepientGroup>();
            telegramChannels = new List <DtoTelegramChannel>();
            schedules        = new List <DtoSchedule>();
            tasks            = new List <IReportTask>();
            operations       = new List <DtoOperation>();

            this.bot.OnUpdate += OnBotUpd;
        } //ctor
예제 #3
0
 public DefaultTaskExporter(ILifetimeScope autofac, IConfigurationRoot serviceConfig)
 {
     executor                = autofac.ResolveNamed <IViewExecutor>("CommonTableViewEx");
     smtpServer              = serviceConfig["EmailSenderSettings:SMTPServer"];
     fromAddress             = serviceConfig["EmailSenderSettings:From"];
     administrativeAddresses = serviceConfig["AdministrativeAddresses"];
 }
예제 #4
0
        public TelegramDataSender(IMapper mapper, ITelegramBotClient botClient,
                                  ILifetimeScope autofac,
                                  ILogic logic, TelegramExporterConfig config)
        {
            mapper.Map(config, this);
            mapper.Map(config, Properties);

            channel      = logic.GetTelegramChatIdByChannelId(config.TelegramChannelId);
            viewExecutor = autofac.ResolveNamed <IViewExecutor>("commonviewex");
            bot          = botClient;
        }
예제 #5
0
        public RTask(ILifetimeScope autofac, IPostMaster postMaster, IRepository repository,
                     IClientControl monik, IMapper mapper, IArchiver archiver, ITelegramBotClient botClient,
                     int id, string reportName, string template, DtoSchedule schedule, string connStr, string query,
                     long chatId, RRecepientGroup sendAddress, int tryCount, int timeOut,
                     RReportType reportType, int reportId, bool htmlBody, bool jsonAttach)
        {
            Type = reportType;

            switch (Type)
            {
            case RReportType.Common:
                _dataEx = autofac.ResolveNamed <IDataExecutor>("commondataex");
                _viewEx = autofac.ResolveNamed <IViewExecutor>("commonviewex");
                break;

            case RReportType.Custom:
                _dataEx = autofac.ResolveNamed <IDataExecutor>(query);
                _viewEx = autofac.ResolveNamed <IViewExecutor>(template);
                break;

            default:
                throw new NotImplementedException();
            }

            _archiver         = archiver;
            _postMaster       = postMaster;
            Id                = id;
            ReportName        = reportName;
            Query             = query;
            ChatId            = chatId;
            ViewTemplate      = template;
            ReportId          = reportId;
            SendAddresses     = sendAddress;
            Schedule          = schedule;
            _repository       = repository;
            TryCount          = tryCount;
            QueryTimeOut      = timeOut;
            ConnectionString  = connStr;
            HasHtmlBody       = htmlBody;
            HasJsonAttachment = jsonAttach;
            _monik            = monik;
            _mapper           = mapper;
            _bot              = botClient;
        }
예제 #6
0
        public Logic(ILifetimeScope autofac, IRepository repository, IClientControl monik,
                     IMapper mapper, IArchiver archiver, ITelegramBotClient bot)
        {
            _autofac    = autofac;
            _mapper     = mapper;
            _monik      = monik;
            _archiver   = archiver;
            _bot        = bot;
            _repository = repository;

            _checkScheduleAndExecuteScheduler = new Scheduler {
                Period = 60, TaskMethod = CheckScheduleAndExecute
            };
            _tableView = _autofac.ResolveNamed <IViewExecutor>("tasklistviewex");

            _recepientGroups  = new List <RRecepientGroup>();
            _schedules        = new List <DtoSchedule>();
            _reports          = new List <DtoReport>();
            _telegramChannels = new ConcurrentDictionary <long, DtoTelegramChannel>();
            _tasks            = new List <IRTask>();
            _bot.OnUpdate    += OnBotUpd;
        } //ctor
예제 #7
0
 public DefaultTaskExporter(ILifetimeScope autofac)
 {
     executor = autofac.ResolveNamed <IViewExecutor>("CommonTableViewEx");
 }
예제 #8
0
        public async Task ExecuteAsync(IReportTaskRunContext taskContext)
        {
            var package = taskContext.Packages[Properties.PackageName];

            if (!RunIfVoidPackage && package.DataSets.Count == 0)
            {
                if (!RunIfVoidPackage && package.DataSets.Count == 0)
                {
                    return;
                }
            }

            string fileName = (string.IsNullOrEmpty(ReportName)
                                  ? $@"{Properties.PackageName}"
                                  : taskContext.SetStringParameters(ReportName))
                              + (DateInName
                                  ? $" {DateTime.Now:dd.MM.yy}"
                                  : null);

            using var msg = ConfigureMessage(taskContext, fileName);

            var dataSets = parser.GetPackageValues(package);
            var firstSet = dataSets.First();

            viewExecutor = firstSet.GroupColumns != null && firstSet.GroupColumns.Any()
                ? autofac.ResolveNamed <IViewExecutor>("GroupedViewex")
                : string.IsNullOrEmpty(ViewTemplate)
                    ? autofac.ResolveNamed <IViewExecutor>("CommonTableViewEx")
                    : autofac.ResolveNamed <IViewExecutor>("commonviewex");

            if (HasHtmlBody)
            {
                msg.IsBodyHtml = true;
                msg.Body       = viewExecutor.ExecuteHtml(ViewTemplate, package);
            }

            MemoryStream streamJson = null;
            MemoryStream streamXlsx = null;

            try
            {
                if (HasJsonAttachment)
                {
                    var dataToSave = UseAllSetsJson
                        ? JsonConvert.SerializeObject(dataSets)
                        : JsonConvert.SerializeObject(dataSets.First());

                    streamJson =
                        new MemoryStream(System.Text.Encoding.UTF8
                                         .GetBytes(dataToSave));

                    AddDataSetsJson(msg, streamJson, fileName);
                }

                if (HasXlsxAttachment)
                {
                    streamXlsx = new MemoryStream();

                    AddDataSetsXlsx(package, msg, streamXlsx, fileName);
                }

                using var client = ConfigureClient();

                await using (taskContext.CancelSource.Token.Register(() => client.SendAsyncCancel()))
                {
                    var tryCount = 0;
                    while (tryCount < 3)
                    {
                        try
                        {
                            await client.SendMailAsync(msg);

                            break;
                        }
                        catch (Exception exc)
                        {
                            if (tryCount == 2)
                            {
                                throw new Exception("Message not sent", exc);
                            }
                            else
                            {
                                tryCount++;
                            }
                        }
                    }
                }
            }

            finally
            {
                streamJson?.Dispose();

                streamXlsx?.Dispose();
            }
        }
예제 #9
0
        } //ctor

        public void Execute(IReportTaskRunContext taskContext)
        {
            var package = taskContext.Packages[Properties.PackageName];

            if (!RunIfVoidPackage && package.DataSets.Count == 0)
            {
                return;
            }

            string filename = (string.IsNullOrEmpty(ReportName)
                                  ? $@"{Properties.PackageName}"
                                  : taskContext.SetStringParameters(ReportName))
                              + (DateInName
                                  ? null
                                  : $" {DateTime.Now:dd.MM.yy}");

            string filenameJson = $@"{filename}.json";
            string filenameXlsx = $@"{filename}.xlsx";

            using (var client = new SmtpClient(ConfigurationManager.AppSettings["SMTPServer"], 25))
                using (var msg = new MailMessage())
                {
                    client.DeliveryFormat = SmtpDeliveryFormat.International;
                    client.EnableSsl      = true;
                    client.DeliveryMethod = SmtpDeliveryMethod.Network;

                    msg.From = new MailAddress(ConfigurationManager.AppSettings["from"]);
                    msg.AddRecepientsFromGroup(addresses);

                    if (!string.IsNullOrEmpty(RecepientsDatasetName))
                    {
                        msg.AddRecepientsFromPackage(taskContext.Packages[RecepientsDatasetName]);
                    }

                    msg.Subject = filename;

                    var dataset = parser.GetPackageValues(package).First();

                    viewExecutor = dataset.GroupColumns != null && dataset.GroupColumns.Any()
                    ? autofac.ResolveNamed <IViewExecutor>("GroupedViewex")
                    : !string.IsNullOrEmpty(ViewTemplate)
                        ? autofac.ResolveNamed <IViewExecutor>("CommonTableViewEx")
                        : autofac.ResolveNamed <IViewExecutor>("commonviewex");

                    if (HasHtmlBody)
                    {
                        msg.IsBodyHtml = true;
                        msg.Body       = viewExecutor.ExecuteHtml(ViewTemplate, package);
                    }

                    MemoryStream streamJson = null;
                    MemoryStream streamXlsx = null;

                    try
                    {
                        if (HasJsonAttachment)
                        {
                            var sets       = parser.GetPackageValues(package);
                            var dataToSave = UseAllSetsJson
                            ? JsonConvert.SerializeObject(sets)
                            : JsonConvert.SerializeObject(sets.First());

                            streamJson =
                                new MemoryStream(System.Text.Encoding.UTF8
                                                 .GetBytes(dataToSave));
                            msg.Attachments.Add(new Attachment(streamJson, filenameJson,
                                                               @"application/json"));
                        }

                        if (HasXlsxAttachment)
                        {
                            streamXlsx = new MemoryStream();
                            var excel = viewExecutor.ExecuteXlsx(package, filename, UseAllSetsXlsx);
                            excel.SaveAs(streamXlsx);
                            excel.Dispose();
                            streamXlsx.Position = 0;
                            msg.Attachments.Add(new Attachment(streamXlsx, filenameXlsx,
                                                               @"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"));
                        }

                        var tryCount = 0;
                        while (tryCount < 3)
                        {
                            try
                            {
                                client.Send(msg);
                                break;
                            }
                            catch (Exception exc)
                            {
                                if (tryCount == 2)
                                {
                                    throw new Exception("Message not sent", exc);
                                }
                                else
                                {
                                    tryCount++;
                                }
                            }
                        }
                    }

                    finally
                    {
                        streamJson?.Dispose();

                        streamXlsx?.Dispose();
                    }
                }
        } //method