示例#1
0
        public virtual IEnumerable messages()
        {
            Messages.Cache.Clear();

            PushNotificationsHook pricePN    = PushNotification.SelectSingle(KCMSMQQueueHelper.GetSyncName(SyncType.InventoryPrice));
            PushNotificationsHook quantityPN = PushNotification.SelectSingle(KCMSMQQueueHelper.GetSyncName(SyncType.InventoryQuantity));
            PushNotificationsHook vendorPN   = PushNotification.SelectSingle(KCMSMQQueueHelper.GetSyncName(SyncType.VendorQuantity));

            if (pricePN == null || quantityPN == null || vendorPN == null)
            {
                throw new PXException(KCMessages.MSMQShouldBeInitialized);
            }


            KCMSMQueueReader price    = null;
            KCMSMQueueReader quantity = null;
            KCMSMQueueReader vendor   = null;

            try
            {
                price    = new KCMSMQueueReader(pricePN.Address);
                quantity = new KCMSMQueueReader(quantityPN.Address);
                vendor   = new KCMSMQueueReader(vendorPN.Address);
                if (price.IsQueueExists && quantity.IsQueueExists && vendor.IsQueueExists)
                {
                    price.CleanEmptyMessages();
                    quantity.CleanEmptyMessages();
                    vendor.CleanEmptyMessages();
                }

                SetMessages(price);
                SetMessages(quantity);
                SetMessages(vendor);
            }
            catch
            {
                throw new PXException(KCMessages.MSMQShouldBeInitialized);
            }
            finally
            {
                price?.Dispose();
                quantity?.Dispose();
                vendor?.Dispose();
            }

            return(Messages.Cache.Inserted);
        }
示例#2
0
        private void CreatePN(SyncType syncType)
        {
            var pnName = KCMSMQQueueHelper.GetSyncName(syncType);

            PushNotificationsHook notification = PushNotifications.SelectSingle(pnName);

            if (notification != null)
            {
                PushNotifications.Delete(notification);
                PushNotifications.Cache.PersistDeleted(notification);

                foreach (var item in PushNotifocationSource.Select(notification.HookId))
                {
                    var obj = item.GetItem <PushNotificationsSource>();

                    PushNotifocationSource.Delete(obj);
                    PushNotifocationSource.Cache.PersistDeleted(obj);
                }

                foreach (var item in PushNotifocationErrors.Select(notification.HookId))
                {
                    var obj = item.GetItem <PushNotificationsErrors>();

                    PushNotifocationErrors.Delete(obj);
                    PushNotifocationErrors.Cache.PersistDeleted(obj);
                }

                foreach (var item in PushNotifocationFailed.Select(notification.HookId))
                {
                    var obj = item.GetItem <PushNotificationsFailedToSend>();

                    PushNotifocationFailed.Delete(obj);
                    PushNotifocationFailed.Cache.PersistDeleted(obj);
                }

                Persist();
            }

            notification = new PushNotificationsHook
            {
                Name    = pnName,
                Type    = "KCMQ",
                Active  = true,
                Address = Environment.MachineName + @"\private$\" + KCMSMQQueueHelper.GetSyncQueueName(syncType),
                HookId  = Guid.NewGuid()
            };
            PushNotifications.Insert(notification);

            GIDesign design = Design.SelectSingle(pnName);
            PushNotificationsSource source = new PushNotificationsSource
            {
                HookId     = notification.HookId,
                DesignID   = design.DesignID,
                SourceType = "GI"
            };

            PushNotifocationSource.Insert(source);

            InsertInitializationActivity(KCMSMQConstants.createPN(pnName), KCMSMQConstants.createPNSuccess(pnName));
            Persist();
        }
        public void ProcessMessageAPI(KCPriceAndInventoryMessage message)
        {
            KCDataExchangeMaint      masterGraph = PXGraph.CreateInstance <KCDataExchangeMaint>();
            KCSiteMaster             connection  = masterGraph.Connection.SelectSingle();
            KCARestClient            client      = new KCARestClient(connection);
            KCInventoryItemAPIHelper helper      = new KCInventoryItemAPIHelper(client, logger.LoggerProperties);
            KCPriceAndInventoryMaint graph       = PXGraph.CreateInstance <KCPriceAndInventoryMaint>();


            var syncType = KCMSMQQueueHelper.ParseSyncQueueName(message.Address);
            var syncName = KCMSMQQueueHelper.GetSyncName(syncType);
            PushNotificationsHook pnHook = graph.PushNotification.SelectSingle(syncName);

            if (syncType == SyncType.InventoryQuantity)
            {
                KCMSMQueueReader quantity = null;
                try
                {
                    quantity = new KCMSMQueueReader(pnHook.Address);
                    if (quantity.TryReceiveMessage(message.MessageID, out var msg))
                    {
                        foreach (object product in msg.Inserted)
                        {
                            KCMSMQInventoryQuantity quantityProduct = JsonConvert.DeserializeObject <KCMSMQInventoryQuantity>(product.ToString());
                            UpdateSiteQuantity(masterGraph, quantityProduct, helper);
                        }
                    }
                }
                finally
                {
                    quantity?.Dispose();
                }
            }
            else if (syncType == SyncType.InventoryPrice)
            {
                KCMSMQueueReader price = null;
                try
                {
                    price = new KCMSMQueueReader(pnHook.Address);
                    if (price.TryReceiveMessage(message.MessageID, out var msg))
                    {
                        foreach (object product in msg.Inserted)
                        {
                            KCMSMQInventoryPrice priceProduct = JsonConvert.DeserializeObject <KCMSMQInventoryPrice>(product?.ToString());
                            UpdatePrice(masterGraph, priceProduct, helper);
                        }
                    }
                }
                finally
                {
                    price?.Dispose();
                }
            }
            else if (syncType == SyncType.VendorQuantity)
            {
                KCMSMQueueReader vendor = null;
                try
                {
                    vendor = new KCMSMQueueReader(pnHook.Address);
                    if (vendor.TryReceiveMessage(message.MessageID, out var msg))
                    {
                        foreach (object product in msg.Inserted)
                        {
                            KCMSMQInventoryQuantity quantityProduct = JsonConvert.DeserializeObject <KCMSMQInventoryQuantity>(product.ToString());
                            UpdateSiteQuantity(masterGraph, quantityProduct, helper);
                        }
                    }
                }
                finally
                {
                    vendor?.Dispose();
                }
            }
        }
        public void ProcessMessageFTP(List <KCPriceAndInventoryMessage> messages, CancellationToken cancellationToken)
        {
            KCDataExchangeMaint      masterGraph = PXGraph.CreateInstance <KCDataExchangeMaint>();
            KCPriceAndInventoryMaint graph       = PXGraph.CreateInstance <KCPriceAndInventoryMaint>();


            var MSMQQuantityUpdates = new Dictionary <string, List <KCAPIQuantity> >();
            var MSMQPrices          = new Dictionary <string, KCAPIInventoryItem>();

            var productsForExportPrice    = new List <KeyValuePair <string, InventoryItem> >();
            var productsForExportQuantity = new Dictionary <string, KeyValuePair <string, InventoryItem> >();

            PushNotificationsHook pricePN    = graph.PushNotification.SelectSingle(KCMSMQQueueHelper.GetSyncName(SyncType.InventoryPrice));
            PushNotificationsHook quantityPN = graph.PushNotification.SelectSingle(KCMSMQQueueHelper.GetSyncName(SyncType.InventoryQuantity));
            PushNotificationsHook vendorPN   = graph.PushNotification.SelectSingle(KCMSMQQueueHelper.GetSyncName(SyncType.VendorQuantity));

            KCMSMQueueReader price    = null;
            KCMSMQueueReader quantity = null;
            KCMSMQueueReader vendor   = null;

            try
            {
                price    = new KCMSMQueueReader(pricePN.Address);
                quantity = new KCMSMQueueReader(quantityPN.Address);
                vendor   = new KCMSMQueueReader(vendorPN.Address);

                foreach (KCPriceAndInventoryMessage msg in messages)
                {
                    var syncType = KCMSMQQueueHelper.ParseSyncQueueName(msg.Address);
                    if (syncType == SyncType.InventoryQuantity || syncType == SyncType.VendorQuantity)
                    {
                        List <object> insertedMessages = null;
                        if (syncType == SyncType.InventoryQuantity && quantity.TryReceiveMessage(msg.MessageID, out var invMessage))
                        {
                            insertedMessages = invMessage.Inserted;
                        }
                        if (syncType == SyncType.VendorQuantity && vendor.TryReceiveMessage(msg.MessageID, out var vendorMessage))
                        {
                            insertedMessages = vendorMessage.Inserted;
                        }

                        if (insertedMessages != null)
                        {
                            foreach (object item in insertedMessages)
                            {
                                KCMSMQInventoryQuantity quantityProduct = JsonConvert.DeserializeObject <KCMSMQInventoryQuantity>(item.ToString());
                                InventoryItem           inventoryItem   = masterGraph.ProductByInvCd.Select(quantityProduct.InventoryID.Trim());
                                KNSIKCInventoryItem     kcProduct       = masterGraph.KCInventoryItem.SelectSingle(inventoryItem.InventoryID);

                                if (kcProduct.UsrKCCAID != null)
                                {
                                    var key = inventoryItem.InventoryCD;

                                    if (!MSMQQuantityUpdates.ContainsKey(key))
                                    {
                                        MSMQQuantityUpdates.Add(key, quantityProduct.Updates);
                                    }

                                    if (!productsForExportQuantity.ContainsKey(key))
                                    {
                                        InventoryItemPCExt inventoryItemPCExt = inventoryItem.GetExtension <InventoryItemPCExt>();

                                        productsForExportQuantity.Add(inventoryItem.InventoryCD, new KeyValuePair <string, InventoryItem>(inventoryItemPCExt.UsrKNCompositeType, inventoryItem));
                                    }
                                }
                            }
                        }
                    }
                    else if (syncType == SyncType.InventoryPrice)
                    {
                        if (price.TryReceiveMessage(msg.MessageID, out var message))
                        {
                            foreach (object item in message.Inserted)
                            {
                                KCMSMQInventoryPrice priceProduct       = JsonConvert.DeserializeObject <KCMSMQInventoryPrice>(item.ToString());
                                InventoryItem        inventoryItem      = masterGraph.ProductByInvCd.Select(priceProduct.InventoryID.Trim());
                                InventoryItemPCExt   inventoryItemPCExt = inventoryItem.GetExtension <InventoryItemPCExt>();

                                productsForExportPrice.Add(new KeyValuePair <string, InventoryItem>(inventoryItemPCExt.UsrKNCompositeType, inventoryItem));
                                MSMQPrices.Add(inventoryItem.InventoryCD, KCMapInventoryItem.GetAPIMSMQInventoryPrice(priceProduct));
                            }
                        }
                    }
                }
            }
            finally
            {
                price?.Dispose();
                quantity?.Dispose();
                vendor?.Dispose();
            }

            Export(masterGraph, productsForExportPrice, cancellationToken, MSMQPrices);
            Export(masterGraph, productsForExportQuantity.Values.ToList(), cancellationToken, null, MSMQQuantityUpdates);
        }