Exemplo n.º 1
0
        /// <summary>
        /// Create a new ParticipantInfo object.
        /// </summary>
        /// <param name="id">Initial value of the Id property.</param>
        public static ParticipantInfo CreateParticipantInfo(global::System.Int32 id)
        {
            ParticipantInfo participantInfo = new ParticipantInfo();

            participantInfo.Id = id;
            return(participantInfo);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the ParticipantInfoSet EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToParticipantInfoSet(ParticipantInfo participantInfo)
 {
     base.AddObject("ParticipantInfoSet", participantInfo);
 }
Exemplo n.º 3
0
        private void ViewOnGetDataEvent(object sender, BicEventArgs eventArgs)
        {
            try
            {
                _view.AddLog("Выбранная дата " + eventArgs.SelectedDateTime.ToShortDateString());
                //Скачивание данных на выбранную дату
                string   s        = eventArgs.SelectedDateTime.ToString("yyyyMMdd");
                FileInfo fileInfo = new FileInfo(Path.GetTempFileName());
                //http://www.cbr.ru/VFS/mcirabis/BIKNew/20200409ED01OSBR.zip
                using (WebClient client = new WebClient())
                {
                    _view.AddLog("Скачивание");
                    client.DownloadFile("http://www.cbr.ru/VFS/mcirabis/BIKNew/" + s + "ED01OSBR.zip", fileInfo.FullName);
                }

                // распаковка
                _view.AddLog("Распаковка");
                string path = fileInfo.Directory.FullName + "\\" + s + "_ED807_full.xml";
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                ZipFile.ExtractToDirectory(fileInfo.FullName, fileInfo.Directory.FullName);

                {
                    // чтение xml
                    FileStream    fs            = new FileStream(path, FileMode.Open);
                    XmlReader     xmlReader     = XmlReader.Create(fs);
                    XmlSerializer xmlSerializer = new XmlSerializer(typeof(ED807));
                    _view.AddLog("Чтение");
                    object deserialize = xmlSerializer.Deserialize(xmlReader);
                    xmlReader.Close();
                    fs.Close();

                    if (deserialize == null)
                    {
                        return;
                    }

                    _view.AddLog("Сопоставление");
                    Model1Container contex = new Model1Container();

                    ObjectSet <BICDirectoryEntry> bicDirectoryEntries = contex.CreateObjectSet <BICDirectoryEntry>();
                    ObjectSet <ParticipantInfo>   participantInfos    = contex.CreateObjectSet <ParticipantInfo>();
                    ObjectSet <Accounts>          accountses          = contex.CreateObjectSet <Accounts>();

                    // перекладывание данных в сущности EntityFramework
                    foreach (XmlBicDirectoryEntry xmlBicDirectoryEntry in (deserialize as ED807).BICDirectoryEntry)
                    //(deserialize as ED807).BICDirectoryEntry.AsParallel()
                    {
                        // ищем существующий или создаем новый объект
                        BICDirectoryEntry bicDirectoryEntry =
                            bicDirectoryEntries.SingleOrDefault(x => x.BIC == xmlBicDirectoryEntry.BIC) ??
                            new BICDirectoryEntry()
                        {
                            Accounts = new EntityCollection <Accounts>()
                        };

                        if (string.IsNullOrWhiteSpace(bicDirectoryEntry.BIC))
                        {
                            bicDirectoryEntry = CopyObjectProperties(xmlBicDirectoryEntry, bicDirectoryEntry);
                            contex.AddToBICDirectoryEntrySet(bicDirectoryEntry);
                        }

                        // ищем существующий или создаем новый объект
                        ParticipantInfo participantInfo;
                        if (bicDirectoryEntry.ParticipantInfo == null)
                        {
                            participantInfo = new ParticipantInfo();
                            bicDirectoryEntry.ParticipantInfo =
                                CopyObjectProperties(xmlBicDirectoryEntry.ParticipantInfo,
                                                     participantInfo);
                            contex.AddToParticipantInfoSet(participantInfo);
                        }
                        else
                        {
                            participantInfo =
                                participantInfos.SingleOrDefault(x => x.Id == bicDirectoryEntry.ParticipantInfo.Id);
                            participantInfo = CopyObjectProperties(xmlBicDirectoryEntry.ParticipantInfo, participantInfo);
                        }

                        if (bicDirectoryEntry.Accounts == null)
                        {
                            bicDirectoryEntry.Accounts = new EntityCollection <Accounts>();
                        }

                        List <Accounts> newAccs = new List <Accounts>();
                        // ищем существующий или создаем новый объект
                        foreach (XmlAccounts xmlAccounts in xmlBicDirectoryEntry.Accounts.AsParallel())
                        {
                            if (bicDirectoryEntry.EntityState == EntityState.Added)
                            {
                                // если бик новый, то все счета создаем новые
                                Accounts accounts = CopyObjectProperties(xmlAccounts, new Accounts());
                                newAccs.Add(accounts);
                            }
                            else
                            {
                                Accounts accounts =
                                    bicDirectoryEntry.Accounts.AsParallel().SingleOrDefault(x => x.Account.Equals(xmlAccounts.Account)) ??
                                    new Accounts();
                                accounts = CopyObjectProperties(xmlAccounts, accounts);
                                if (accounts.EntityState == EntityState.Detached)
                                {
                                    newAccs.Add(accounts);
                                }
                            }
                        }

                        // удаляем счета, которых больше нет в источнике данных
                        if (bicDirectoryEntry.EntityState != EntityState.Added)
                        {
                            IEnumerable <Accounts> deletedAccounts =
                                from c in bicDirectoryEntry.Accounts.AsParallel()
                                where !(from o in xmlBicDirectoryEntry.Accounts.AsParallel()
                                        select o.Account)
                                .Contains(c.Account)
                                select c;
                            foreach (Accounts acc in deletedAccounts)
                            {
                                contex.DeleteObject(acc);
                            }
                        }

                        // добавляем новые счета
                        foreach (Accounts acc in newAccs)
                        {
                            bicDirectoryEntry.Accounts.Add(acc);
                            contex.AddToAccountsSet(acc);
                        }
                    }

                    //сохранение в бд
                    //
                    _view.AddLog("Сохранение");
                    contex.SaveChanges(SaveOptions.None);
                    _view.AddLog("Готово");
                }
            }
            catch (Exception ex)
            {
                _view.AddExceptionLog(ex.ToString());
            }
        }