internal async Task LoadLiveData(TelemetryInitializeResponse response) { try { this.propertiesInternal.LiveProgramInfo = new LiveProgramInfo(this.Properties.StaticProgramInfo) { UserId = response.UserId }; Task <string> updaterNameTask = this.Messenger.SendGetRequest <string>($"{ApiRoutes.GetProgramUpdaterName(this.Properties.TelemetryKey)}"); await Task.WhenAll(updaterNameTask).ConfigureAwait(false); this.Properties.LiveProgramInfo.UpdaterName = updaterNameTask.Result; if (string.IsNullOrEmpty(this.Properties.LiveProgramInfo.UpdaterName)) { throw new InvalidOperationException($"Updater name is null or empty. Task result: {updaterNameTask.Status}"); } } catch (Exception ex) { TelimenaException exception = new TelimenaException("Error occurred while loading live program info", this.Properties, ex); if (!this.Properties.SuppressAllErrors) { throw exception; } } }
/// <inheritdoc /> public async Task <UpdateInstallationResult> InstallUpdatesAsync(UpdateCheckResult checkResult, bool takeBeta) { try { if (!takeBeta) { checkResult.ProgramUpdatesToInstall = checkResult.ProgramUpdatesToInstall.Where(x => x.IsBeta == false).ToList(); } UpdateHandler handler = new UpdateHandler(this.telimena.Messenger, this.telimena.Properties.LiveProgramInfo, new DefaultWpfInputReceiver() , new UpdateInstaller(), this.telimena.Locator); await handler.HandleUpdates(UpdatePromptingModes.DontPrompt, checkResult.ProgramUpdatesToInstall, checkResult.UpdaterUpdate).ConfigureAwait(false); return(new UpdateInstallationResult() { CheckResult = checkResult }); } catch (Exception ex) { TelimenaException exception = new TelimenaException("Error occurred while installing updates", this.telimena.Properties, ex); if (!this.telimena.Properties.SuppressAllErrors) { throw exception; } return(new UpdateInstallationResult() { CheckResult = checkResult , Exception = exception }); } }
/// <inheritdoc /> public async Task <UpdateCheckResult> CheckForUpdatesAsync(bool acceptBeta = true) { UpdateRequest updateRequest = null; try { TelemetryInitializeResponse result = await this.telimena.InitializeIfNeeded().ConfigureAwait(false); if (result.Exception != null) { throw result.Exception; } string updaterVersion = this.GetUpdaterVersion(); updateRequest = new UpdateRequest(this.telimena.Properties.TelemetryKey, this.telimena.Properties.ProgramVersion, this.telimena.Properties.LiveProgramInfo.UserId, acceptBeta , this.telimena.Properties.TelimenaVersion, updaterVersion); UpdateResponse temp = await this.GetUpdateResponse(ApiRoutes.ProgramUpdateCheck, updateRequest).ConfigureAwait(false); ConfiguredTaskAwaitable <UpdateResponse> programUpdateTask = this .GetUpdateResponse(ApiRoutes.ProgramUpdateCheck, updateRequest).ConfigureAwait(false); ConfiguredTaskAwaitable <UpdateResponse> updaterUpdateTask = this .GetUpdateResponse(ApiRoutes.UpdaterUpdateCheck, updateRequest).ConfigureAwait(false); UpdateResponse programUpdateResponse = await programUpdateTask; UpdateResponse updaterUpdateResponse = await updaterUpdateTask; return(new UpdateCheckResult { ProgramUpdatesToInstall = programUpdateResponse.UpdatePackages , UpdaterUpdate = updaterUpdateResponse?.UpdatePackages?.FirstOrDefault() }); } catch (Exception ex) { TelimenaException exception = new TelimenaException("Error occurred while sending check for updates request", this.telimena.Properties, ex , new KeyValuePair <Type, object>(typeof(UpdateRequest), updateRequest) , new KeyValuePair <Type, object>(typeof(UpdateRequest), updateRequest)); if (!this.telimena.Properties.SuppressAllErrors) { throw exception; } return(new UpdateCheckResult { Exception = exception }); } }
/// <summary> /// Initializes the Telimena client. /// <para /> /// Each time initialization is called, it will increment the program usage statistics. /// It should be called once per application execution /// <para>This is an ASYNC method which should be awaited</para> /// </summary> /// <returns></returns> public async Task <TelemetryInitializeResponse> Initialize() { TelemetryInitializeRequest request = null; try { request = new TelemetryInitializeRequest(this.Properties.TelemetryKey) { ProgramInfo = this.Properties.StaticProgramInfo , TelimenaVersion = this.Properties.TelimenaVersion , UserInfo = this.Properties.UserInfo }; TelemetryInitializeResponse response = await this.Messenger.SendPostRequest <TelemetryInitializeResponse>(ApiRoutes.Initialize, request).ConfigureAwait(false); await this.LoadLiveData(response).ConfigureAwait(false); if (response != null && response.Exception == null) { this.IsInitialized = true; this.initializationResponse = response; return(this.initializationResponse); } else { return(response); } } catch (Exception ex) { TelimenaException exception = new TelimenaException("Error occurred while sending registration request", this.Properties, ex, new KeyValuePair <Type, object>(typeof(TelemetryInitializeRequest), request)); if (!this.Properties.SuppressAllErrors) { throw exception; } return(new TelemetryInitializeResponse { Exception = exception }); } }
/// <inheritdoc /> public async Task <UpdateInstallationResult> HandleUpdatesAsync(bool acceptBeta) { UpdateCheckResult checkResult = null; try { checkResult = await this.CheckForUpdatesAsync(acceptBeta).ConfigureAwait(false); if (checkResult.Exception == null) { UpdateHandler handler = new UpdateHandler(this.telimena.Messenger, this.telimena.Properties.LiveProgramInfo, new DefaultWpfInputReceiver() , new UpdateInstaller(), this.telimena.Locator, this.telimena.telemetryModule); await handler.HandleUpdates(this.telimena.Properties.UpdatePromptingMode, checkResult.ProgramUpdatesToInstall, checkResult.UpdaterUpdate).ConfigureAwait(false); } else { throw checkResult.Exception; } return(new UpdateInstallationResult() { CheckResult = checkResult }); } catch (Exception ex) { TelimenaException exception = new TelimenaException("Error occurred while handling updates", this.telimena.Properties, ex); if (!this.telimena.Properties.SuppressAllErrors) { throw exception; } return(new UpdateInstallationResult() { CheckResult = checkResult , Exception = exception }); } }