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 <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 }); } }
internal async Task <TelemetryInitializeResponse> InitializeIfNeeded() { if (!this.IsInitialized) { TelemetryInitializeResponse response = await this.Initialize().ConfigureAwait(false); if (response != null && response.Exception == null) { this.IsInitialized = true; this.initializationResponse = response; return(this.initializationResponse); } else { return(response); } } return(this.initializationResponse); }