Beispiel #1
0
        public void UpdateApprovedEditionsFromStagingDb(string key, string connectionId)
        {
            if (key == WebConfigHelper.TaskSchedulerSecretKey)
            {
                try
                {
                    var approvedEditions = GetApprovedEditions();

                    var stagingEditions = GetStagingEditionsPossiblyHaveNewEditions(approvedEditions);

                    if (approvedEditions.Count > 0)
                    {
                        for (var i = 0; i < approvedEditions.Count; i++)
                        {
                            var approvedEdition = approvedEditions[i];

                            var siblingsOnCed = GetSiblingEditionsByApprovedEdition(approvedEdition);

                            var siblingsOnStaging = stagingEditions.Where(x => x.EventMasterCode == approvedEdition.Event.MasterCode).ToList();

                            if (siblingsOnStaging.Count == siblingsOnCed.Count)
                            {
                                var newlyAddedEdition = siblingsOnStaging.OrderByDescending(x => x.EventStartDate).Take(1).SingleOrDefault();
                                UpdateApprovedEdition(newlyAddedEdition, approvedEdition);
                                break;
                            }

                            if (siblingsOnStaging.Count > siblingsOnCed.Count)
                            {
                                var message = "In Staging database there are more editions of the event " +
                                              $"{approvedEdition.Event.MasterCode} - {approvedEdition.Event.MasterName} than in CED database." +
                                              "Both must be equal or the ones CED database must be lesser.";
                                var log = CreateInternalLog(message);
                                ExternalLogHelper.Log(log, LoggingEventType.Fatal);
                            }

                            if (!string.IsNullOrWhiteSpace(connectionId))
                            {
                                ProgressHub.SendProgress(connectionId, "Done", i + 1, approvedEditions.Count, TaskType.UpdateApprovedEditionsFromStagingDb.GetHashCode());
                            }
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrWhiteSpace(connectionId))
                        {
                            ProgressHub.SendProgress(connectionId, "Done", 1, 1, TaskType.UpdateApprovedEditionsFromStagingDb.GetHashCode());
                        }
                    }

                    var log2 = CreateInternalLog("The task UpdateApprovedEditionsFromStagingDb completed.", AutoIntegrationUser);
                    ExternalLogHelper.Log(log2, LoggingEventType.Information);
                }
                catch (Exception exc)
                {
                    var message = "The task UpdateApprovedEditionsFromStagingDb failed! " + exc.GetFullMessage();
                    ExternalLogHelper.Log(message, LoggingEventType.Fatal);
                }
            }
        }
Beispiel #2
0
        public JsonResult NotifyAboutMissingEditionImages(string key, string connectionId)
        {
            if (key == WebConfigHelper.TaskSchedulerSecretKey)
            {
                try
                {
                    var editions = TaskServices.GetEditionsWithMissingImages();

                    var pattern = "<a href='{0}'>{1}</a>";

                    var body = "<table>";

                    for (var i = 0; i < editions.Count; i++)
                    {
                        var edition = editions[i];

                        var url = _editionHelper.GetEditionUrl(new EditionEntity
                        {
                            EditionId   = edition.EditionId,
                            EditionName = edition.EventName,
                            Status      = edition.Status.ToEnum <EditionStatusType>()
                        });

                        body += "<tr><td class='font-lato' style='font-size: 14px; color: #888794'>" + string.Format(pattern, url, edition.EventName);
                        body += edition.EventBackGroundImage == null ? " [People Image] " : "";
                        body += edition.EventImage == null ? " [Web Logo] " : "";
                        body += edition.IconFileName == null ? " [Icon] " : "";
                        body += edition.MasterLogoFileName == null ? " [Master Logo] " : "";
                        body += edition.ProductImageFileName == null ? " [Product Image] " : "";
                        body += "</td></tr>";

                        if (!string.IsNullOrWhiteSpace(connectionId))
                        {
                            ProgressHub.SendProgress(connectionId, "Detecting missing images...", i + 1, editions.Count, TaskType.NotifyAboutMissingEditionImages.GetHashCode());
                        }
                    }

                    body += "</table>";

                    var subject    = "Events with Missing Images";
                    var recipients = WebConfigHelper.MarketingAdminEmails;

                    _emailNotificationHelper.Send(NotificationType.MissingEditionImages, subject, body, recipients);

                    var log = CreateInternalLog("The task NotifyAboutMissingEditionImages completed.", AutoIntegrationUser);
                    ExternalLogHelper.Log(log, LoggingEventType.Information);

                    return(Json("", JsonRequestBehavior.AllowGet));
                }
                catch (Exception exc)
                {
                    var message = "The task NotifyAboutMissingEditionImages failed! " + exc.GetFullMessage();
                    ExternalLogHelper.Log(message, LoggingEventType.Error);

                    return(Json(false, JsonRequestBehavior.AllowGet));
                }
            }

            return(Json(false, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        private void Process(bool multithread, string connectionID)
        {
            // Prepare
            var _Cancel = new CancellationTokenSource();

            Session["_Cancel"] = _Cancel;
            var FileName = Session["FileName"]?.ToString();
            var Parser   = _Facade.Parser;

            if (Parser.FileAlreadyParsed(FileName))
            {
                ProgressHub.SendMessage(connectionID, "File already parsed!");
                return;
            }
            // Fire and forget
            Task <bool> .Run(() =>
            {
                var progress = new Progress <int>();
                try
                {
                    var ProgressBarMaximum    = Parser.RowsInAnketa(FileName).Result;
                    progress.ProgressChanged += (sender, args) =>
                    {
                        ProgressHub.SendProgress(connectionID, args, ProgressBarMaximum);
                    };
                    if (!multithread)
                    {
                        Parser.Parse_SigleAsync(FileName, progress, _Cancel).Wait();
                    }
                    else
                    {
                        Parser.Parse_MultipleAsync(FileName, progress, _Cancel).Wait();
                    }
                }
                catch (Exception ex)
                {
                    ProgressHub.SendMessage(connectionID, ex.InnerException.Message);
                }
                int fileId = _Facade.Keeper.GetFile(Path.GetFileName(FileName)).ID;
                ProgressHub.ParsingCompleted(connectionID, fileId);
                return(true);
            });
        }
Beispiel #4
0
        public void UpdateEventDirectors(string key, string connectionId)
        {
            if (key == WebConfigHelper.TaskSchedulerSecretKey)
            {
                try
                {
                    TaskServices.UpdateEventDirectors();

                    var log = CreateInternalLog("The task UpdateEventDirectors completed.", AutoIntegrationUser);
                    ExternalLogHelper.Log(log, LoggingEventType.Information);

                    if (!string.IsNullOrWhiteSpace(connectionId))
                    {
                        ProgressHub.SendProgress(connectionId, "Done", 1, 1, TaskType.UpdateEventDirectors.GetHashCode());
                    }
                }
                catch (Exception exc)
                {
                    var log     = CreateInternalLog("The task UpdateEventDirectors failed!", AutoIntegrationUser);
                    var message = log.AdditionalInfo + " | " + exc.GetFullMessage();
                    ExternalLogHelper.Log(message, LoggingEventType.Fatal);
                }
            }
        }
Beispiel #5
0
        public JsonResult UpdateNotifications(string key, string connectionId)
        {
            if (key == WebConfigHelper.TaskSchedulerSecretKey)
            {
                try
                {
                    var notificationTypes = Enum.GetValues(typeof(NotificationType));

                    var allEditionNotifPairs = new Dictionary <EditionEntity, NotificationType>();
                    foreach (NotificationType notificationType in notificationTypes)
                    {
                        if (notificationType.GetAttribute <CompletenessNotificationTypeAttribute>() == null)
                        {
                            continue;
                        }

                        var editions = GetEditionsToNotify(notificationType);

                        foreach (var edition in editions)
                        {
                            allEditionNotifPairs.Add(edition, notificationType);
                        }
                    }

                    if (allEditionNotifPairs.Count > 0)
                    {
                        for (var i = 0; i < allEditionNotifPairs.Count; i++)
                        {
                            var pair = allEditionNotifPairs.ElementAt(i);

                            ProcessEditionNotifications(pair, i, allEditionNotifPairs.Count);

                            if (!string.IsNullOrWhiteSpace(connectionId))
                            {
                                ProgressHub.SendProgress(connectionId, pair.Value + " for " + pair.Key.EditionName, i + 1, allEditionNotifPairs.Count, TaskType.UpdateNotifications.GetHashCode());
                            }
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrWhiteSpace(connectionId))
                        {
                            ProgressHub.SendProgress(connectionId, "Done", 1, 1, TaskType.UpdateNotifications.GetHashCode());
                        }
                    }

                    var log = CreateInternalLog("The task UpdateNotifications completed.", AutoIntegrationUser);
                    ExternalLogHelper.Log(log, LoggingEventType.Information);

                    return(Json("", JsonRequestBehavior.AllowGet));
                }
                catch (Exception exc)
                {
                    var message = "The task UpdateNotifications failed! " + exc.GetFullMessage();
                    ExternalLogHelper.Log(message, LoggingEventType.Fatal);

                    return(Json(false, JsonRequestBehavior.AllowGet));
                }
            }

            return(Json("", JsonRequestBehavior.AllowGet));
        }
Beispiel #6
0
        public JsonResult UpdateEventsFromStagingDb(string key, string connectionId)
        {
            if (key == WebConfigHelper.TaskSchedulerSecretKey)
            {
                try
                {
                    var stagingEditionServices = new DWStaging.BusinessServices.EditionServices();

                    var stagingEditions =
                        WebConfigHelper.IsLocal || WebConfigHelper.IsTest
                        //? stagingEditionServices.GetEditionsByEventBeId("101558") :
                            ? stagingEditionServices.GetEditionsByMasterCode(new[] { "1102" }) :
                        stagingEditionServices.GetEditions();

                    //var stagingEditions =
                    //    stagingEditionServices.GetEditionsQueryable()
                    //        //.Where(x => new[] { "10117", "10215", "941", "969", "980" }.Contains(x.EventMasterCode))
                    //        .Where(x => x.EventMaster.ToLower().Contains("agent"))
                    //        .ToList();

                    stagingEditions = stagingEditions.OrderBy(x => x.EventStartDate).ToList();

                    for (var i = 0; i < stagingEditions.Count; i++)
                    {
                        var stagingEdition = stagingEditions[i];

                        var axId = Convert.ToInt32(stagingEdition.EventBEID);

                        if (!DateTime.TryParseExact(stagingEdition.EventStartDate.ToString(), "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime eventStartDate))
                        {
                            eventStartDate = new DateTime(1970, 1, 1);
                        }

                        if (!DateTime.TryParseExact(stagingEdition.EventEndDate.ToString(), "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime eventEndDate))
                        {
                            eventEndDate = new DateTime(1970, 1, 1);
                        }

                        var existingEdition = EditionServices.GetEditionByAxId(axId);

                        if (existingEdition != null) // UPDATE
                        {
                            TaskServices.UpdateEventEditionFromStagingDb(existingEdition, stagingEdition, eventStartDate, eventEndDate);
                        }
                        else // CREATE
                        {
                            TaskServices.CreateEventEditionFromStagingDb(stagingEdition, eventStartDate, eventEndDate);
                        }

                        if (!string.IsNullOrWhiteSpace(connectionId))
                        {
                            ProgressHub.SendProgress(connectionId, stagingEdition.EventName, i + 1, stagingEditions.Count, TaskType.UpdateEventsFromStagingDb.GetHashCode());
                        }
                    }

                    var log = CreateInternalLog("The task UpdateEventsFromStagingDb completed.", AutoIntegrationUser);
                    ExternalLogHelper.Log(log, LoggingEventType.Information);

                    return(Json("", JsonRequestBehavior.AllowGet));
                }
                catch (Exception exc)
                {
                    var message = "The task UpdateEventsFromStagingDb failed! " + exc.GetFullMessage();
                    ExternalLogHelper.Log(message, LoggingEventType.Fatal);

                    return(Json(false, JsonRequestBehavior.AllowGet));
                }
            }

            return(Json(false, JsonRequestBehavior.AllowGet));
        }