/// <summary>Получение версии приложения</summary><param name="appName"></param><returns></returns> public AppVersion GetAppVersion(string appName) { AppVersion AppVersions = null; clientControl = new ClientControlService(Address, Port); 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 = clientControl.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></returns> public AppVersionSetting GetSetting(string appName, string appVersion) { try { clientControl = new ClientControlService(Address, Port); 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 = clientControl.Select(command); if (datarows == null) { throw new Exception(); } AppVersionSetting result = new AppVersionSetting(); foreach (var info in datarows) { result.ActialAppName = info["Application"].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> public IList <AppVersion> FindAll() { try { clientControl = new ClientControlService(Address, Port); 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 { clientControl = new ClientControlService(Address, Port); 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 { clientControl = new ClientControlService(Address, Port); 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 { clientControl = new ClientControlService(Address, Port); IVersionRepo repo = new VersionInDBServerRepo("127.0.0.1", 8005); 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; clientControl.Insert(command); } for (int i = 0; i < version.Files.Count; i++) { clientControl = new ClientControlService(Address, Port); 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; clientControl.Insert(command1); } clientControl = new ClientControlService(Address, Port); 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(); clientControl.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 { clientControl = new ClientControlService(Address, Port); 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; clientControl.Insert(command); return(true); } catch (Exception ex) { throw new Exception(); } }
static string address = "192.168.1.2"; // адрес сервера static void Main(string[] args) { ClientControlService clientControl = new ClientControlService(address, port); SQLiteCommand command = new SQLiteCommand(); command.CommandText = "INSERT INTO Applications (ApplicationName) VALUES(@ApplicationName)"; command.Parameters.Add("@ApplicationName", DbType.String).Value = "Test21"; var test1 = clientControl.Insert(command); SQLiteCommand command1 = new SQLiteCommand(); command1.CommandText = "SELECT * FROM FilesVersions"; var test2 = clientControl.Select(command1); SQLiteCommand command2 = new SQLiteCommand(); command2.CommandText = "Update ApplicationInfo set AppDiscription=@AppDiscription,Flag=@Flag WHERE Application=@Application AND AppVersion=@AppVersion"; command2.Parameters.Add("@AppDiscription", DbType.String).Value = ""; command2.Parameters.Add("@Flag", DbType.String).Value = "False"; command2.Parameters.Add("@Application", DbType.String).Value = "TestA"; command2.Parameters.Add("@AppVersion", DbType.String).Value = "1_b0"; var test3 = clientControl.Update(command2); Console.WriteLine(); }
/// <summary>Получение описания приложения</summary><param name="appName"></param><param name="appVersion"></param><returns></returns> public string GetDiscription(string appName, string appVersion) { clientControl = new ClientControlService(Address, Port); SQLiteCommand command = new SQLiteCommand(); command.CommandText = "SELECT * FROM ApplicationInfo WHERE Flag = @Flag AND Application = @Application AND AppVersion = @AppVersion"; string flag = "True"; 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 = clientControl.Select(command); if (datarows == null) { throw new Exception(); } string discription = ""; foreach (var info in datarows) { discription = info["AppDiscription"].ToString(); } return(discription); }
public ClientController(ILogger <ClientController> logger, ClientControlService clientControlService) { _logger = logger; _clientControlService = clientControlService; }