Exemplo n.º 1
0
        private void CheckArticles()
        {
            int countA = 0;

            if (_isArticlesBusy)
            {
                _loger.Log("Check articles is busy");
                return;
            }
            try
            {
                if (UpdateTimeWatcher.TimeToCheck(Ix4RequestProps.Articles))
                {
                    WrightLog("Check Artikles started");
                    _isArticlesBusy = true;

                    int         currentClientID = _customerInfo.ClientID;
                    LICSRequest request         = new LICSRequest();
                    request.ClientId = currentClientID;
                    LICSRequestArticle[] articles = _dataCompositor.GetRequestArticles();

                    _loger.Log(string.Format("Got ARTICLES {0}", articles != null ? articles.Length : 0));

                    if (articles == null || articles.Length == 0)
                    {
                        _loger.Log("There is no available articles");
                        return;
                    }

                    List <LICSRequestArticle> tempAtricles = new List <LICSRequestArticle>();

                    for (int i = 0; i < articles.Length; i++)
                    {
                        articles[i].ClientNo = currentClientID;
                        tempAtricles.Add(articles[i]);
                        if (tempAtricles.Count >= _articlesPerRequest || i == articles.Length - 1)
                        {
                            request.ArticleImport = tempAtricles.ToArray();
                            var resSent = SendLicsRequestToIx4(request, "articleFile.xml");
                            if (resSent)
                            {
                                countA++;
                                _loger.Log(string.Format("Was sent {0} request with {1} articles", countA, tempAtricles.Count));
                                tempAtricles = new List <LICSRequestArticle>();
                            }
                        }
                    }
                    UpdateTimeWatcher.SetLastUpdateTimeProperty(Ix4RequestProps.Articles);
                }
            }
            catch (Exception ex)
            {
                _loger.Log(ex);
                _loger.Log("Inner excep " + ex.InnerException);
                _loger.Log("Inner excep MESSAGE" + ex.InnerException.Message);
            }
            finally
            {
                _isArticlesBusy = false;
            }
        }
Exemplo n.º 2
0
        private void CheckDeliveries()
        {
            try
            {
                if (UpdateTimeWatcher.TimeToCheck(Ix4RequestProps.Deliveries))
                {
                    if (_cachedArticles == null)
                    {
                        _loger.Log("There is no cheched articles for filling deliveries");
                        CheckArticles();
                        if (_cachedArticles == null)
                        {
                            _loger.Log("WE CANNOT GET DELIVERIES WITHOUT ARTICLES");
                            return;
                        }
                    }
                    int         currentClientID = _customerInfo.ClientID;
                    LICSRequest request         = new LICSRequest();
                    request.ClientId = currentClientID;
                    LICSRequestDelivery[]     deliveries            = _dataCompositor.GetRequestDeliveries();
                    List <LICSRequestArticle> articlesByDelliveries = new List <LICSRequestArticle>();
                    _loger.Log(deliveries, "deliveries");
                    if (deliveries.Length == 0)
                    {
                        _loger.Log("There is no deliveries");
                        return;
                    }
                    foreach (LICSRequestDelivery delivery in deliveries)
                    {
                        bool deliveryHasErrors = false;
                        articlesByDelliveries  = new List <LICSRequestArticle>();
                        delivery.ClientNo      = currentClientID;
                        request.DeliveryImport = new LICSRequestDelivery[] { delivery };
                        foreach (var position in delivery.Positions)
                        {
                            LICSRequestArticle findArticle = GetArticleByNumber(position.ArticleNo);
                            if (findArticle == null)
                            {
                                _loger.Log("Cannot find article with no:  " + position.ArticleNo);
                                _loger.Log("Delivery with wrong article position:  " + delivery);
                                deliveryHasErrors = true;
                            }
                            else
                            {
                                articlesByDelliveries.Add(findArticle);
                            }
                        }
                        if (deliveryHasErrors)
                        {
                            _loger.Log("Delivery " + delivery + "WAS NOT SEND");
                            continue;
                        }
                        else
                        {
                            request.ArticleImport = articlesByDelliveries.ToArray();
                            _loger.Log("Delivery before sending: ");
                            foreach (LICSRequestDelivery item in request.DeliveryImport)
                            {
                                _loger.Log(item.SerializeObjectToString <LICSRequestDelivery>());
                            }

                            var res = SendLicsRequestToIx4(request, "deliveryFile.xml");
                            _loger.Log("Delivery result: " + res);
                        }
                    }
                    UpdateTimeWatcher.SetLastUpdateTimeProperty(Ix4RequestProps.Deliveries);
                }
            }
            catch (Exception ex)
            {
                _loger.Log(ex);
            }
        }