/// <summary>Сохранение содержимого файлов приложения</summary><param name="ver"></param><param name="file"></param> public bool Save(AppVersion ver, IDictionary <FileOfVersion, byte[]> file) { try { List <FileOfVersion> fileVersion = (from dir in file.Keys select dir).ToList(); List <byte[]> fileContains = (from contains in file.Values select contains).ToList(); for (int i = 0; i < fileVersion.Count; i++) { if (fileVersion[i].FileHash == HashCode(fileContains[i])) { mydb = new DB.SQLite.SQLite(BDPath); SQLiteCommand command = new SQLiteCommand(); command.CommandText = "INSERT INTO FilesContains (Applications,AppVersions,FilePath,DateCreateDB,Contains) VALUES(@Applications,@AppVersions,@FilePath,@DateCreateDB,@Contains)"; command.Parameters.Add("@Applications", DbType.String).Value = ver.VersionName; command.Parameters.Add("@AppVersions", DbType.String).Value = ver.VersionNumber.ToString(); command.Parameters.Add("@FilePath", DbType.String).Value = fileVersion[i].FilePath; command.Parameters.Add("@DateCreateDB", DbType.String).Value = DateTime.Now.ToString(); command.Parameters.Add("@Contains", DbType.Binary).Value = fileContains[i].ToArray(); mydb.Insert(command); logger.Add("Запись добавлена!"); } else { throw new Exception("Метаданные не соответствуют содержимому файла!"); } } return(true); } catch (SaveException ex) { logger.Add(ex); throw new SaveException(); } }
/// <summary>Сохранение метаданных</summary><param name="version"></param> public bool SaveApplication(AppVersion version) { try { mydb = new DB.SQLite.SQLite(BDPath); IVersionRepo repo = new VersionInDBRepo(AppDomain.CurrentDomain.BaseDirectory); IList <AppVersion> apps = repo.FindAll(version.VersionName); if (apps.Count == 0) { SQLiteCommand command = new SQLiteCommand(); command.CommandText = "INSERT INTO Applications(ApplicationName) VALUES(@ApplicationName)"; command.Parameters.Add("@ApplicationName", DbType.String).Value = version.VersionName; mydb.Insert(command); } for (int i = 0; i < version.Files.Count; i++) { mydb = new DB.SQLite.SQLite(BDPath); SQLiteCommand command1 = new SQLiteCommand(); command1.CommandText = "INSERT INTO FilesVersions(AppVersions,FileHash,CreationDate,FileSize,FilePath,DateCreateDB,Applications)" + "VALUES(@AppVersions,@FileHash,@CreationDate,@FileSize,@FilePath,@DateCreateDB,@Applications)"; command1.Parameters.Add("@AppVersions", DbType.String).Value = version.VersionNumber.ToString(); command1.Parameters.Add("@FileHash", DbType.String).Value = version.Files[i].FileHash; command1.Parameters.Add("@CreationDate", DbType.String).Value = DateTime.Now.ToString(); command1.Parameters.Add("@FileSize", DbType.Int32).Value = version.Files[i].FileSize.FileSize; command1.Parameters.Add("@FilePath", DbType.String).Value = version.Files[i].FilePath; command1.Parameters.Add("@DateCreateDB", DbType.String).Value = DateTime.Now.ToString(); command1.Parameters.Add("@Applications", DbType.String).Value = version.VersionName; mydb.Insert(command1); } mydb = new DB.SQLite.SQLite(BDPath); SQLiteCommand command2 = new SQLiteCommand(); command2.CommandText = "INSERT INTO ApplicationInfo(Application,AppVersion)VALUES(@Applications,@AppVersions)"; command2.Parameters.Add("@Applications", DbType.String).Value = version.VersionName; command2.Parameters.Add("@AppVersions", DbType.String).Value = version.VersionNumber.ToString(); mydb.Insert(command2); logger.Add("Запись добавлена!"); return(true); } catch (SaveException ex) { logger.Add(ex); throw new SaveException(); } }
/// <summary>Сохранение настроек приложения</summary><param name="versionSetting"></param><returns></returns> public bool SaveSetting(AppVersionSetting versionSetting) { try { mydb = new DB.SQLite.SQLite(BDPath); SQLiteCommand command = new SQLiteCommand(); command.CommandText = "Update ApplicationInfo set AppDiscription = @AppDiscription, Flag=@Flag, Name_EXE = @EXE WHERE Application = @Application AND AppVersion = @AppVersion"; command.Parameters.Add("@AppDiscription", DbType.String).Value = versionSetting.AppDiscription; command.Parameters.Add("@Flag", DbType.String).Value = versionSetting.ActialFlag; command.Parameters.Add("@Application", DbType.String).Value = versionSetting.ActialAppName; command.Parameters.Add("@AppVersion", DbType.String).Value = versionSetting.ActialAppVersion; command.Parameters.Add("@EXE", DbType.String).Value = versionSetting.NameExe; mydb.Insert(command); return(true); } catch (Exception ex) { throw new Exception(); } }