public async static Task<AppInfoEnvelope> Load(UserConfiguration uc) { HttpWebRequest webRequest = HttpWebRequest.CreateHttp(uc.ApiBase + "apps"); webRequest.Method = WebRequestMethods.Http.Get; webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.UserAgent = "HockeyAppLoader"; webRequest.Headers.Add("X-HockeyAppToken", uc.UserToken); WebResponse response = await webRequest.GetResponseAsync(); Stream stream = response.GetResponseStream(); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(AppInfoEnvelope)); AppInfoEnvelope envelope = serializer.ReadObject(stream) as AppInfoEnvelope; List<AppInfo> localAppData = uc.AppInfos; foreach (AppInfo app in envelope.Apps) { var local = localAppData.FirstOrDefault(p => p.Id.Equals(app.Id)); if (local != null) { app.CompleteWithLocalData(local); } } uc.AppInfos = envelope.Apps; return envelope; }
public static UserConfiguration CreateNew(string configurationName) { Configuration config = IoC.Get <Configuration>(); if (config.UserConfigurations.Any(p => p.ConfigurationName.Equals(configurationName))) { throw new Exception("Configuration name already in use!"); } UserConfiguration newConfig = new UserConfiguration(configurationName); config.UserConfigurations.Add(newConfig); return(newConfig); }
private async Task<string> AddVersion(UserConfiguration uc, CancellationToken cancelToken) { string versionID = ""; Dictionary<string, string> formParms = new Dictionary<string, string>(); formParms.Add("bundle_version", _appInfo.Version); FormUrlEncodedContent paramContent = new FormUrlEncodedContent(formParms); HttpClient client = HttpClientFactory.Create(); client.DefaultRequestHeaders.Add("X-HockeyAppToken", uc.UserToken); HttpResponseMessage response = await client.PostAsync(uc.ApiBase + "apps/" + _appInfo.PublicID + "/app_versions/new", paramContent, cancelToken); if (response.StatusCode == HttpStatusCode.Created) { StreamContent sr = response.Content as StreamContent; string result = await sr.ReadAsStringAsync(); JavaScriptSerializer serializer = new JavaScriptSerializer(); dynamic responseInfo = serializer.Deserialize<object>(result); versionID = ((Dictionary<string, object>)responseInfo)["id"].ToString(); } else { StreamContent sr = response.Content as StreamContent; string result = await sr.ReadAsStringAsync(); JavaScriptSerializer serializer = new JavaScriptSerializer(); dynamic responseInfo = serializer.Deserialize<object>(result); Dictionary<string, object> errors = responseInfo["errors"]; StringBuilder message = new StringBuilder(); message.AppendLine(response.ReasonPhrase); foreach (string key in errors.Keys) { object[] values = (object[])errors[key]; string val = ""; foreach (object obj in values) { val += obj.ToString() + ", "; } if (val.Length > -2) { val = val.Substring(0, val.Length - 2); } message.AppendLine(key + ":" + val); } throw new Exception(message.ToString()); } return versionID; }
public UploadDialogViewModel(List<AppInfo> list, UserConfiguration uc) { this.ValidApps = new List<AppDialogViewModel>(); foreach (AppInfo app in list) { AppDialogViewModel newVM = new AppDialogViewModel(app); newVM.PropertyChanged += (sender, p) => { if (p.PropertyName.Equals("CanUpload")) { this.NotifyOfPropertyChange(() => this.CanUpload); } }; this.ValidApps.Add(newVM); } if (this.ValidApps.Count == 1) { this.SelectedApp = this.ValidApps[0]; } else { this.SelectedApp = null; } this._activeUserConfiguration = uc; }
public UserConfigurationViewModel(UserConfiguration userConfiguration) { this._configuration = IoC.Get<Configuration>(); this._userConfiguration = userConfiguration; this.Cancel(); }
public void Save() { if (this.IsNew) { this._userConfiguration = UserConfiguration.CreateNew(this.ConfigurationName); } this._userConfiguration.UserToken = this.UserToken; if (!this.ApiBase.EndsWith("/")) { this.ApiBase += "/"; } this._userConfiguration.ApiBase = this.ApiBase; if (this._userConfiguration.IsDefault && !this.IsDefaultConfiguration) { this._configuration.SetDefaultUserConfiguration(null); } else if (!this._userConfiguration.IsDefault && this.IsDefaultConfiguration) { this._configuration.SetDefaultUserConfiguration(this._userConfiguration); } this._configuration.Save(); this.WasChanged = false; NotifyOfPropertyChange(""); base.Close(); }
public void SetDefaultUserConfiguration(UserConfiguration uc=null) { if (uc != null && this.UserConfigurations.IndexOf(uc) > -1) { this.DefaultConfigurationName = uc.ConfigurationName; } else { this.DefaultConfigurationName = ""; } }
public static UserConfiguration CreateNew(string configurationName) { Configuration config = IoC.Get<Configuration>(); if (config.UserConfigurations.Any(p=>p.ConfigurationName.Equals(configurationName))){ throw new Exception("Configuration name already in use!"); } UserConfiguration newConfig = new UserConfiguration(configurationName); config.UserConfigurations.Add(newConfig); return newConfig; }
public abstract Task Upload(string filename, UserConfiguration uc, EventHandler<HttpProgressEventArgs> progressHandler, CancellationToken cancelToken);