Esempio n. 1
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));
        }