void ExistDictFileProcessing(Stream stream, Dictionary dict, UserChangeHistory change) { var tmpFolder = FileHelper.GetTemporaryDirectory(); var tmpFile = Path.Combine(tmpFolder, Path.GetFileName(dict.FileName)); FileHelper.LoadFileFromStream(stream, tmpFile); ZipHelper.UnZip(tmpFile); var newFile = Directory.GetFiles(tmpFolder, "*.mdb").Single(); if (AccessHelper.CheckIdentifyInfo(newFile) == dict.Dictionary_id) { var unZipFoler = ZipHelper.UnZipToTempDir(dict.PathToDict); var oldDict = Directory.GetFiles(unZipFoler, "*.mdb").Single(); var changes = DBComparer.CompareDataBase(newFile, oldDict); if (changes.Any()) { using (var db = new DictServiceEntities()) { db.DictionaryChangeHistories.AddRange(changes.Select(x => new DictionaryChangeHistory() { UserHistory_id = change.UserHistory_id, Change_id = (int)x.ChangeType, Dictionary_id = dict.Dictionary_id, TableName = x.TableName, PrimaryKey = x.PrimaryKey, ColumnName = x.ColumnName, OldValue = x.OldValue, NewValue = x.NewValue })); db.SaveChanges(); } CreateDictionaryVersion(dict); File.Move(tmpFile, dict.PathToDict); } } else { throw new Exception("Попытка загрузить неизвестный словарь"); } }