/// <summary> /// Updates database if needed. /// </summary> /// <param name="backupBeforeUpdate">If true, backups database before udpating.</param> public async Task UpdateDatabaseAsync() { Version databaseVersion = VersionAccess.GetVersionInfo(); if (databaseVersion < new Version(1, 4, 0, 0)) { if (isDatabaseRecreated) { throw new Exception(string.Format("InitialDatabase version {0} is outdated.", databaseVersion.ToString())); } string Msg = string.Format("Database v{0} is outdated. Do you wish to delete it and recreate an updated database? All your personal data will be lost.", databaseVersion.ToString(3)); if (MessageBox.Show(owner, Msg, "Database Update", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) { throw new Exception(string.Format("Database is outdated.")); } GC.Collect(); await TryUntilTimeout(() => FileOperationAPIWrapper.MoveToRecycleBin(AppPaths.DatabasePath), 10000); isDatabaseRecreated = true; await EnsureAvailableAsync(); // UpdateDatabaseToVersion(backupBeforeUpdate, 0, 9, 3, 0); } }
public Shell(IEventAggregator eventAggregator, IModuleManager moduleManager) { InitializeComponent(); this.receive_Aggregator = eventAggregator; this.send_Aggregator = eventAggregator; this.moduleManager = moduleManager; //定义消息结构 receiveMsgOrder = new ReceiveMsgOrder(); //获取服务器端参数 configModel = ConfigAccess.GetConfig(); //获取客户端版本信息 versionModel = VersionAccess.GetConfig(); //获取连接信息类的单例 connectParam = ConnectParam.GetInstance(); //获取日志记录实例 this.ilogger = ILogger.GetInstance(); //订阅接收信息事件 RequestEvent(); //定义接收消息线程 connectParam.ListenerMsgThread = new Thread(ListenerMsgThreadMethod); connectParam.ListenerMsgThread.IsBackground = true; //先建立连接及SSL通道,再发送 ConnectToServer(MessageTypes.UPD + versionModel.AppVs + MessageTypes.NSP + versionModel.UpdateTime, //确认更新 configModel.LoginIP, int.Parse(configModel.LoginPort)); }
private async void ConfirmButtonClick(object sender, EventArgs e) { try { // Validate name and access input. if (!VersionNameValid(_nameEntry.Text)) { return; } if (_protectionSpinner.SelectedItem != null) { VersionAccess access = (VersionAccess)Enum.Parse(typeof(VersionAccess), _protectionSpinner.SelectedItem.ToString()); // Set the user defined name, access level and description as service version parameters ServiceVersionParameters newVersionParameters = new ServiceVersionParameters(); newVersionParameters.Name = _nameEntry.Text; newVersionParameters.Access = access; newVersionParameters.Description = _descriptionEntry.Text ?? ""; ServiceVersionInfo newVersion = await _serviceGeodatabase.CreateVersionAsync(newVersionParameters); _userCreatedVersionName = newVersion.Name; _ = SwitchVersion(); _versionButton.Text = "Switch version"; } else { ShowAlert("Please select an access level"); return; } } catch (Exception ex) { ShowAlert(ex.Message, ex.GetType().Name); } finally { SwitchView(_defaultView); } }
/// <summary> /// Checks server and database availability. /// If there is no database file, copy and attach initial database. /// Update database if it is outdated. /// </summary> /// <remarks>If connection fails, the exception must be handled by the caller.</remarks> public async Task EnsureAvailableAsync() { Version CurrentVersion = null; try { // Test query. CurrentVersion = await Task.Run(() => VersionAccess.GetVersionInfo()); } catch { } if (CurrentVersion == null) { // Check if database exists. If it doesn't, create blank database. if (!File.Exists(AppPaths.DatabasePath) || new FileInfo(AppPaths.DatabasePath).Length == 0) { await CreateNewDatabaseAsync(); } await TryUntilTimeout(() => VersionAccess.GetVersionInfo(), 10000); } // If database connection is successfull, ensure database file is up to date. await UpdateDatabaseAsync(); }
private void SetVersionAccess(VersionAccess access) { _userVersionAccess = access; _proButton.SetTitle($"Protection: {access}", UIControlState.Normal); }
/// <summary> /// Updates database by running a script, after making an optional backup. /// </summary> /// <param name="backupBeforeUpdate">Wether to backup database.</param> /// <param name="major">The Major version number.</param> /// <param name="minor">The Minor version number.</param> /// <param name="build">The Build version number.</param> /// <param name="revision">The Revision version number.</param> private void UpdateDatabaseToVersion(bool backupBeforeUpdate, int major, int minor, int build, int revision) { // Update database. RunScript(string.Format("{0}.{1}.{2}.{3}.sql", major, minor, build, revision)); VersionAccess.UpdateVersionInfo(new Version(major, minor, build, revision)); }