public JArray RunSearch(string model, IEnumerable<KeyValuePair<string, string>> searchParams, bool singleSearch = false) { if (this.IsEventSearchModel(model)) searchParams = searchParams.Concat1(new KeyValuePair<string, string>("event", this.EventId.ToString())); if (!this.SessionSet) throw new TrackerError(TrackerErrorType.NoConnection, "Error, session is not set."); Uri u = new Uri(Domain, "search/"); //this.CreateSearchUri(model, searchParams); WebClientEx client = this.CreateClient(); string paramsString = SearchParams(model, searchParams); string response = null; try { response = client.DownloadString(new Uri(u, "?" + paramsString)); } catch (WebException e) { this.HandleWebException(e); } JArray result = JArray.Parse(response); if (singleSearch && result.Count != 1) throw new TrackerError(TrackerErrorType.InstanceDoesNotExist, model + " with id = " + searchParams.Where(p => p.Key.IEquals("id")).Single().Value + " does not exist."); return result; }
private string SearchParams(string modelName, IEnumerable<KeyValuePair<string, string>> searchParams) { string result = StringParams(searchParams.Concat1(new KeyValuePair<string, string>("type", modelName))); return result; //result = string.Format("{0}", string.Join("&", searchParams.Select(x => (x.Key.Equals("domainId") ? x.Key : x.Key.ToLower()) + "=" + (x.Value == null ? "None" : Uri.EscapeDataString(x.Value))))); //return string.Format("type={0}&{1}", modelName, result); }
public JObject RunSave(string model, IEnumerable<KeyValuePair<string, string>> saveParams) { if (this.IsEventSaveModel(model)) saveParams = saveParams.Concat1(new KeyValuePair<string, string>("event", this.EventId.ToString())); if (string.Equals(model, "run", StringComparison.OrdinalIgnoreCase)) saveParams = saveParams.Concat1(new KeyValuePair<string, string>("sortkey", "0")); if (!this.SessionSet) throw new TrackerError(TrackerErrorType.NoConnection, "Error, session is not set."); Uri u; if (saveParams.Any(p => string.Equals(p.Key, "id", StringComparison.OrdinalIgnoreCase))) { u = new Uri(Domain, "edit/"); } else { u = new Uri(Domain, "add/"); } WebClientEx client = this.CreateClient(); string response = null; try { string parameters = SearchParams(model, saveParams); response = client.UploadString(u, "POST", parameters); } catch (WebException e) { this.HandleWebException(e); } return JArray.Parse(response).Value<JObject>(0); }