예제 #1
0
        public void GetAddressByOktmo_GootOktmo()
        {
            var address = _repository.GetAddressByOktmo(_goodOktmo);

            Assert.IsEmpty(address.Error);
            Assert.IsEmpty(address.ErrorLog);
            Assert.AreEqual(address.AddressMun, _goodOktmoAddress);
            Assert.AreEqual(address.Fias, _goodOktmoFias);
            Assert.AreEqual(address.Status, "True");
            Assert.AreEqual(address.OktmoWeb, _goodOktmo);
        }
예제 #2
0
        private async Task GetData(Action <int> callbackCount, string whatDo)
        {
            await Task.Factory.StartNew(() =>
            {
                ParallelOptions po = new ParallelOptions()
                {
                    MaxDegreeOfParallelism = 10
                };

                Parallel.ForEach(CollectionAddress, po, (item) =>
                {
                    lock (_lockCountReady)
                    {
                        _countReady++;
                    }

                    callbackCount(_countReady);

                    if (item == null)
                    {
                        return;
                    }

                    var count = _countAttempt;
                    while (count-- > 0)
                    {
                        try
                        {
                            EntityAddress address = null;

                            if (whatDo == "oktmo")
                            {
                                address = _repository.GetAddressByOktmo(item.Oktmo);
                            }
                            else if (whatDo == "address")
                            {
                                address = _repository.GetAddressByAddress(item.Address);
                            }
                            else if (whatDo == "fias")
                            {
                                address = _repository.GetAddressByFias(item.Fias);
                            }

                            item.AddressMun = address.AddressMun;
                            item.Fias       = address.Fias;
                            item.Status     = address.Status;
                            item.OktmoWeb   = address.OktmoWeb;
                            item.Error      = address.Error;
                            item.ErrorLog   = address.ErrorLog;

                            if (item.Oktmo != item.OktmoWeb && !string.IsNullOrEmpty(item.OktmoWeb))
                            {
                                item.ErrorLog += " Не совпадает октмо";
                            }

                            break;
                        }
                        catch (WebException exWeb)
                        {
                            if (count <= 0)
                            {
                                item.Error = exWeb.Message;
                                break;
                            }
                            Thread.Sleep(5000);
                        }
                        catch (Exception ex)
                        {
                            item.Error = ex.Message;
                            break;
                        }
                    }
                });

                FindDuplicate();
            });
        }