/// <summary> /// 永続化されているアプリケーション構成情報を非同期で読み込みます。 /// </summary> /// <returns>この操作を待機するための <see cref="Task"/> 。</returns> public async Task LoadAsync() { Applications.Clear(); await _repository.LoadAsync(this).ConfigureAwait(false); if (String.IsNullOrEmpty(Settings.ApplicationInformationServiceUrl)) { Settings.SetDefaultService(); } RegisterMeIfNotRegistered(); var httpClient = new HttpClient(); // アプリケーションの日本語名、説明と更新情報の URL はサービスから取得 var response = await httpClient.GetAsync(Settings.ApplicationInformationServiceUrl).ConfigureAwait(false); if (response.StatusCode != HttpStatusCode.OK) { return; } var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false); _appInfo = JsonConvert.DeserializeObject <ApplicationJson>(json); foreach (var application in Applications) { await application.InitializeAsync(_appInfo).ConfigureAwait(false); } }
/// <summary> /// 指定されたアプリケーション情報によってこのインスタンスを初期化します。 /// </summary> /// <param name="appInfo"></param> /// <returns></returns> public async Task InitializeAsync(ApplicationJson appInfo) { if (_isInitalized) { return; } using (await _initializeLock.LockAsync().ConfigureAwait(false)) { if (_isInitalized) { return; } try { FileSystemWatcher.Changed += async(_, e) => { if (String.Equals(InstalledPath, e.FullPath, StringComparison.OrdinalIgnoreCase)) { await RefreshFileInfoAsync().ConfigureAwait(false); } }; var app = appInfo.Applications.FirstOrDefault(x => x.Id == Id); if (app != null) { IsSupported = true; _updateServiceUrlTemplate = app.UpdateServiceUrl ?? appInfo.DefaultServiceUrl; InstallUrl = new Uri(app.InstallUrl ?? appInfo.DefaultInstallUrl); DisplayName = app.DisplayName; Definition = app.Definition; DeveloperName = app.DeveloperName; await RefreshFileInfoAsync().ConfigureAwait(false); } else { IsSupported = false; } } finally { _isInitalized = true; } } }
/// <summary> /// 指定されたアプリケーション情報によってこのインスタンスを初期化します。 /// </summary> /// <param name="appInfo"></param> /// <returns></returns> public async Task InitializeAsync(ApplicationJson appInfo) { if (_isInitalized) return; using (await _initializeLock.LockAsync().ConfigureAwait(false)) { if (_isInitalized) return; try { FileSystemWatcher.Changed += async (_, e) => { if (String.Equals(InstalledPath, e.FullPath, StringComparison.OrdinalIgnoreCase)) { await RefreshFileInfoAsync().ConfigureAwait(false); } }; var app = appInfo.Applications.FirstOrDefault(x => x.Id == Id); if (app != null) { IsSupported = true; _updateServiceUrlTemplate = app.UpdateServiceUrl ?? appInfo.DefaultServiceUrl; InstallUrl = new Uri(app.InstallUrl ?? appInfo.DefaultInstallUrl); DisplayName = app.DisplayName; Definition = app.Definition; await RefreshFileInfoAsync().ConfigureAwait(false); } else { IsSupported = false; } } finally { _isInitalized = true; } } }
/// <summary> /// 永続化されているアプリケーション構成情報を非同期で読み込みます。 /// </summary> /// <returns>この操作を待機するための <see cref="Task"/> 。</returns> public async Task LoadAsync() { Applications.Clear(); await _repository.LoadAsync(this).ConfigureAwait(false); if (String.IsNullOrEmpty(Settings.ApplicationInformationServiceUrl)) { Settings.SetDefaultService(); } RegisterMeIfNotRegistered(); var httpClient = new HttpClient(); // アプリケーションの日本語名、説明と更新情報の URL はサービスから取得 var response = await httpClient.GetAsync(Settings.ApplicationInformationServiceUrl).ConfigureAwait(false); if (response.StatusCode != HttpStatusCode.OK) { return; } var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false); _appInfo = JsonConvert.DeserializeObject<ApplicationJson>(json); foreach (var application in Applications) { await application.InitializeAsync(_appInfo).ConfigureAwait(false); } }