/// <summary>Получение версии приложения</summary><param name="appName"></param><returns></returns> public AppVersion GetAppVersion(string appName) { AppVersion AppVersions = null; mydb = new DB.SQLite.SQLite(BDPath); string flag = "True"; SQLiteCommand command = new SQLiteCommand(); command.CommandText = "SELECT * FROM ApplicationInfo WHERE Flag = @Flag AND Application = @Application"; command.Parameters.Add("@Flag", DbType.String).Value = flag; command.Parameters.Add("@Application", DbType.String).Value = appName; DataRow[] datarows = mydb.Select(command); if (datarows == null) { throw new Exception(); } foreach (DataRow dr in datarows) { VersionNumber VerNum; VersionNumber.TryParse(dr["AppVersion"].ToString().Trim(), out VerNum); AppVersion AppVer = new AppVersion(dr["Application"].ToString(), VerNum); AppVersions = (AppVer); } return(AppVersions); }
/// <summary>Получение настроек сообщения</summary><param name="appName"></param><param name="appVersion"></param><returns>result</returns> public AppVersionSetting GetSetting(string appName, string appVersion) { try { mydb = new DB.SQLite.SQLite(BDPath); SQLiteCommand command = new SQLiteCommand(); command.CommandText = "SELECT * FROM ApplicationInfo WHERE Application = @Application AND AppVersion = @AppVersion "; command.Parameters.Add("@Application", DbType.String).Value = appName; command.Parameters.Add("@AppVersion", DbType.String).Value = appVersion; DataRow[] datarows = mydb.Select(command); if (datarows == null) { throw new Exception(); } AppVersionSetting result = new AppVersionSetting(); foreach (var info in datarows) { result.ActialAppName = info["Aplication"].ToString(); result.ActialAppVersion = info["AppVersion"].ToString(); result.ActialFlag = info["Flag"].ToString(); result.AppDiscription = info["AppDiscription"].ToString(); result.NameExe = info["Name_EXE"].ToString(); } return(result); } catch { throw new Exception(); } }
/// <summary>Получение содержимого файла версии приложения</summary><param name="version"></param><param name="name"></param><returns>byte[]</returns> public byte[] GetFile(AppVersion version, FileOfVersion name) { try { byte[] contains = null; mydb = new DB.SQLite.SQLite(BDPath); SQLiteCommand command = new SQLiteCommand(); command.CommandText = "SELECT * FROM FilesContains WHERE Applications = @Applications AND AppVersions = @AppVersions AND FilePath = @FilePath"; command.Parameters.Add("@Applications", DbType.String).Value = version.VersionName; command.Parameters.Add("@AppVersions", DbType.String).Value = version.VersionNumber.ToString(); command.Parameters.Add("@FilePath", DbType.String).Value = name.FilePath; DataRow[] datarows = mydb.Select(command); if (datarows == null) { logger.Add("Не удалось подключиться к базе данных"); throw new FilePathIsNullException(); } foreach (var dr in from DataRow dr in datarows select dr) { contains = (byte[])dr["Contains"]; } return(contains); } catch { throw new FilePathIsNullException();; } }
/// <summary>Список метаданных файлов приложения</summary><param name="ver"></param> public IList <FileOfVersion> FindFileOfVersions(AppVersion ver)// попробовать рпеределать не по индексу а по ключу { try { mydb = new DB.SQLite.SQLite(BDPath); SQLiteCommand command = new SQLiteCommand(); command.CommandText = "SELECT * FROM FilesContains WHERE Applications = @Applications"; command.Parameters.Add("@Applications", DbType.String).Value = ver.VersionName; DataRow[] datarows = mydb.Select(command); if (datarows == null) { logger.Add("Не удалось подключиться к базе данных"); throw new FilePathIsNullException(); } string[] versss = (from vers in datarows orderby vers.ItemArray[0] descending select vers.ItemArray[1].ToString()).ToArray();//поиск наибольшей версии VersionNumber Vers; VersionNumber.TryParse(versss[0], out Vers); List <FileOfVersion> fileApp = new List <FileOfVersion>(); foreach (var dr in from DataRow dr in datarows where Vers.ToString() == dr["AppVersions"].ToString().Trim() select dr)// Заполнение списка мета данных файлов { FileOfVersion verss = new FileOfVersion(dr["FilePath"].ToString(), (byte[])dr["Contains"], File.GetCreationTime(dr["FilePath"].ToString())); fileApp.Add(verss); } return(fileApp); } catch (VersionInFileSystemRepo.FilePathIsNullException ex) { logger.Add(ex); throw new FilePathIsNullException(); } }
/// <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> public IList <AppVersion> FindAll() { try { mydb = new DB.SQLite.SQLite(BDPath); SQLiteCommand command = new SQLiteCommand(); command.CommandText = "SELECT * FROM FilesVersions"; return(AppVersions(command)); } catch (FilePathIsNullException ex) { logger.Add(ex); throw new FilePathIsNullException(); } }
///<summary>Всех версий приложения</summary><param name="version_name"></param> public IList <AppVersion> FindAll(string version_name) { try { mydb = new DB.SQLite.SQLite(BDPath); SQLiteCommand command = new SQLiteCommand(); command.CommandText = "SELECT * FROM FilesVersions WHERE Applications = " + "'" + version_name + "'"; command.Parameters.Add("@Applications", DbType.String).Value = version_name; return(AppVersions(command)); } catch (FilePathIsNullException ex) { logger.Add(ex); throw new FilePathIsNullException(); } }
///<summary>Поиск последней версии приложения</summary><param name="app"></param> public AppVersion Find(AppVersion app) { try { mydb = new DB.SQLite.SQLite(BDPath); SQLiteCommand command = new SQLiteCommand(); command.CommandText = "SELECT * FROM FilesVersions WHERE Applications = @Applications"; command.Parameters.Add("@Applications", DbType.String).Value = app.VersionName; logger.Add("Версия найдена"); return(Result(command)); } catch (FilePathIsNullException ex) { logger.Add(ex); throw new FilePathIsNullException(); } }
/// <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(); } }
/// <summary>Получение описания приложения</summary><param name="appName"></param><param name="appVersion"></param><returns>discription</returns> public string GetDiscription(string appName, string appVersion) { mydb = new DB.SQLite.SQLite(BDPath); string flag = "True"; string discription = ""; SQLiteCommand command = new SQLiteCommand(); command.CommandText = "SELECT * FROM ApplicationInfo WHERE Flag = @Flag AND Application = @Application AND AppVersion = @AppVersion"; command.Parameters.Add("@Flag", DbType.String).Value = flag; command.Parameters.Add("@Application", DbType.String).Value = appName; command.Parameters.Add("@Application", DbType.String).Value = appVersion; DataRow[] datarows = mydb.Select(command); if (datarows == null) { throw new Exception(); } foreach (DataRow dr in datarows) { discription = dr["AppDiscription"].ToString(); } return(discription); }
/// <summary>Получение имени исполняемого файла приложения</summary><param name="appName"></param><param name="appVersion"></param><returns></returns> public string GetNameExe(string appName, string appVersion) { mydb = new DB.SQLite.SQLite(BDPath); string flag = "True"; SQLiteCommand command = new SQLiteCommand(); command.CommandText = "SELECT * FROM ApplicationInfo WHERE Flag = @Flag AND Application = @Application AND AppVersion = @AppVersion"; command.Parameters.Add("@Flag", DbType.String).Value = flag; command.Parameters.Add("@Application", DbType.String).Value = appName; command.Parameters.Add("@AppVersion", DbType.String).Value = appVersion; DataRow[] datarows = mydb.Select(command); if (datarows == null) { throw new Exception(); } string name = ""; foreach (var info in datarows) { name = info["Name_EXE"].ToString(); } return(name); }