예제 #1
0
        public static OrderCreateSyncRequest ConvertDateTimesToCEST(this OrderCreateSyncRequest request)
        {
            request.EarliestFulfillmentDateTime = GetCEST(request.EarliestFulfillmentDateTime);
            request.LatestFulfillmentDateTime   = GetCEST(request.LatestFulfillmentDateTime);

            return(request);
        }
예제 #2
0
        private int ProcessQueueEntries()
        {
            SqlTransaction LMSTransaction   = null;
            string         errorReason      = "";
            string         errorDescription = "";

            int liveUpdateCounter = 0;

            OrderCreateSyncRequest              orderCreateSyncRequest      = null;
            OrderUpdateSyncRequest              orderUpdateSyncRequest      = null;
            OrderCancelSyncRequest              orderCancelSyncRequest      = null;
            OrderFulfillSyncRequest             orderFulfillRequest         = null;
            OrderRollbackFulfillmentSyncRequest orderRollbackFulfillRequest = null;

            string  messageId = "";
            string  lockToken = "";
            Message message   = null;

            try
            {
                Tuple <String, String, Message> queueRequest = this.LQTools.LiveQueueToolsGetLiveRequest();
                if (queueRequest != null)
                {
                    Console.WriteLine(""); // IsAlive Hinweis für Console
                    messageId = queueRequest.Item1;
                    lockToken = queueRequest.Item2;

                    message = queueRequest.Item3;

                    bool success = false;
                    switch (message.ContentType)
                    {
                    case nameof(OrderCreateSyncRequest):
                        orderCreateSyncRequest = message.As <OrderCreateSyncRequest>().ConvertDateTimesToCEST();

                        Console.WriteLine("Bearbeite OrderCreateSyncRequest:");
                        Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(orderCreateSyncRequest,
                                                                                      new JsonSerializerSettings
                        {
                            Formatting = Formatting.Indented,
                        }));

                        LMSTransaction = this.LMSSqlConnection.BeginTransaction();
                        switch (orderCreateSyncRequest.Type)
                        {
                        case OrderType.Supply:
                            if (!orderCreateSyncRequest.IsPermanent)
                            {
                                // Normale Verfügbarkeit
                                if (LiveDBTools.CheckAvailability(this.MyConfig, LMSTransaction, orderCreateSyncRequest, out errorReason, out errorDescription) &&
                                    (success = LiveDBTools.InsertAvailability(MyConfig, LMSTransaction, orderCreateSyncRequest, out errorReason, out errorDescription)))
                                {
                                    liveUpdateCounter++;
                                }
                            }
                            else
                            {
                                // Dauerverfügbarkeit
                                if (LiveDBTools.CheckPermanentAvailability(this.MyConfig, LMSTransaction, orderCreateSyncRequest, out errorReason, out errorDescription) &&
                                    (success = LiveDBTools.InsertPermanentAvailability(MyConfig, LMSTransaction, orderCreateSyncRequest, out errorReason, out errorDescription)))
                                {
                                    liveUpdateCounter++;
                                }
                            }
                            break;

                        case OrderType.Demand:
                            if (LiveDBTools.CheckDelivery(this.MyConfig, LMSTransaction, orderCreateSyncRequest, out errorReason, out errorDescription) &&
                                (success = LiveDBTools.InsertDelivery(MyConfig, LMSTransaction, orderCreateSyncRequest, out errorReason, out errorDescription)))
                            {
                                liveUpdateCounter++;
                            }
                            break;
                        }

                        if (!success)
                        {
                            this.LogWarning("Bearbeitung Queue Entry '" + messageId + "' nicht möglich, Grund: '" + errorReason + "', Beschreibung: '" + errorDescription + "'");
                            this.LQTools.LiveQueueToolsDenyLiveRequest(lockToken, errorReason, errorDescription);
                            break;
                        }
                        break;

                    case nameof(OrderUpdateSyncRequest):
                        orderUpdateSyncRequest = message.As <OrderUpdateSyncRequest>().ConvertDateTimesToCEST();

                        Console.WriteLine("Bearbeite OrderUpdateSyncRequest:");
                        Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(orderUpdateSyncRequest,
                                                                                      new JsonSerializerSettings
                        {
                            Formatting = Formatting.Indented,
                        }));

                        LMSTransaction = this.LMSSqlConnection.BeginTransaction();
                        switch (orderUpdateSyncRequest.Type)
                        {
                        case OrderType.Supply:
                            if (orderUpdateSyncRequest.IsPermanent)
                            {
                                // Dauerverfügbarkeit
                                if (success = LiveDBTools.UpdatePermanentAvailability(MyConfig, LMSTransaction, orderUpdateSyncRequest, out errorReason, out errorDescription))
                                {
                                    liveUpdateCounter++;
                                }
                            }
                            else
                            {
                                errorReason      = ErrorReasonNotImplemented;
                                errorDescription = ErrorDescriptionNotImplemented;
                                success          = false;
                            }
                            break;

                        case OrderType.Demand:
                            errorReason      = ErrorReasonNotImplemented;
                            errorDescription = ErrorDescriptionNotImplemented;
                            success          = false;
                            break;
                        }

                        if (!success)
                        {
                            this.LogWarning("Bearbeitung Queue Entry '" + messageId + "' nicht möglich, Grund: '" + errorReason + "', Beschreibung: '" + errorDescription + "'");
                            this.LQTools.LiveQueueToolsDenyLiveRequest(lockToken, errorReason, errorDescription);
                            break;
                        }
                        break;

                    case nameof(OrderCancelSyncRequest):
                        orderCancelSyncRequest = message.As <OrderCancelSyncRequest>().ConvertDateTimesToCEST();

                        Console.WriteLine("Bearbeite OrderCancelSyncRequest:");
                        Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(orderCancelSyncRequest,
                                                                                      new JsonSerializerSettings
                        {
                            Formatting = Formatting.Indented,
                        }));

                        LMSTransaction = this.LMSSqlConnection.BeginTransaction();
                        switch (orderCancelSyncRequest.Type)
                        {
                        case OrderType.Supply:
                            if (success = LiveDBTools.CancelAvailability(MyConfig, LMSTransaction, orderCancelSyncRequest, out errorReason, out errorDescription))
                            {
                                liveUpdateCounter++;
                            }
                            break;

                        case OrderType.Demand:
                            if (success = LiveDBTools.CancelDelivery(MyConfig, LMSTransaction, orderCancelSyncRequest, out errorReason, out errorDescription))
                            {
                                liveUpdateCounter++;
                            }
                            break;
                        }

                        if (!success)
                        {
                            this.LogWarning("Bearbeitung Queue Entry '" + messageId + "' nicht möglich, Grund: '" + errorReason + "', Beschreibung: '" + errorDescription + "'");
                            this.LQTools.LiveQueueToolsDenyLiveRequest(lockToken, errorReason, errorDescription);
                            break;
                        }
                        break;

                    case nameof(OrderFulfillSyncRequest):
                        orderFulfillRequest = message.As <OrderFulfillSyncRequest>().ConvertDateTimesToCEST();

                        Console.WriteLine("Bearbeite OrderFulfillSyncRequest:");
                        Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(orderFulfillRequest,
                                                                                      new JsonSerializerSettings
                        {
                            Formatting = Formatting.Indented,
                        }));

                        LMSTransaction = this.LMSSqlConnection.BeginTransaction();
                        if (success = LiveDBTools.FullfillEntries(MyConfig, LMSTransaction, orderFulfillRequest, out errorReason, out errorDescription))
                        {
                            liveUpdateCounter++;
                        }

                        if (!success)
                        {
                            this.LogWarning("Bearbeitung Queue Entry '" + messageId + "' nicht möglich, Grund: '" + errorReason + "', Beschreibung: '" + errorDescription + "'");
                            this.LQTools.LiveQueueToolsDenyLiveRequest(lockToken, errorReason, errorDescription);
                            break;
                        }
                        break;

                    case nameof(OrderRollbackFulfillmentSyncRequest):
                        orderRollbackFulfillRequest = message.As <OrderRollbackFulfillmentSyncRequest>();

                        Console.WriteLine("Bearbeite OrderRollbackFulfillmentSyncRequest:");
                        Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(orderRollbackFulfillRequest,
                                                                                      new JsonSerializerSettings
                        {
                            Formatting = Formatting.Indented,
                        }));

                        LMSTransaction = this.LMSSqlConnection.BeginTransaction();
                        if (success = LiveDBTools.RollbackFullfillEntries(MyConfig, LMSTransaction, orderRollbackFulfillRequest, out errorReason, out errorDescription))
                        {
                            liveUpdateCounter++;
                        }

                        if (!success)
                        {
                            this.LogWarning("Bearbeitung Queue Entry '" + messageId + "' nicht möglich, Grund: '" + errorReason + "', Beschreibung: '" + errorDescription + "'");
                            this.LQTools.LiveQueueToolsDenyLiveRequest(lockToken, errorReason, errorDescription);
                            break;
                        }
                        break;

                    default:
                        errorDescription = ErrorDescriptionMessageType + message.ContentType;
                        this.LogError("Bearbeitung Queue Entry '" + messageId + "' nicht möglich, Grund: '" + ErrorReasonMessageType + "', Beschreibung: '" + errorDescription + "'");
                        this.LQTools.LiveQueueToolsDenyLiveRequest(lockToken, ErrorReasonMessageType, errorDescription);
                        break;
                    }
#if !TEST_ONLY
                    if (success)
                    {
                        success = this.LQTools.LiveQueueToolsConfirmLiveRequest(lockToken);
                        if (success)
                        {
                            LMSTransaction.Commit();
                        }
                        else
                        {
                            LMSTransaction.Rollback();
                        }
                        LMSTransaction = null;
                    }
                    if (!success)
                    {
                        liveUpdateCounter = 0;
                        if (LMSTransaction != null)
                        {
                            LMSTransaction.Rollback();
                            LMSTransaction = null;
                        }
                    }
#else
                    LMSTransaction.Rollback();
                    LMSTransaction = null;
#endif
                }
            }
            catch (Exception ex)
            {
                this.LogException("ServiceMain", ex);
                if (LMSTransaction != null)
                {
                    LMSTransaction.Rollback();
                    liveUpdateCounter = 0;
                }
                if (lockToken != "")
                {
                    errorDescription = ErrorDescriptionException + ex.Message;
                    this.LogError("Bearbeitung Queue Entry '" + messageId + "' nicht möglich, Grund: '" + ErrorReasonException + "', Beschreibung: '" + errorDescription + "'");
                    this.LQTools.LiveQueueToolsDenyLiveRequest(lockToken, ErrorReasonMessageType, errorDescription);
                }
                //this.ServiceErrorFlag = true; TODO
            }

            return(liveUpdateCounter);
        }