public static string ProcessAsyncError(AsyncError asyncError) { var error = asyncError.Error.InnerException; if (error is RdfQueryException || error is RdfParseException || //TODO: should it be here? error is WebException || error is BrowserException) { return(error.Message); } else { string ret = "An unexpected error occured while processing the query. "; /*TODO remove*/ ret += error.Message; return(ret); } }
public virtual void WriteTo(XElement xE) { XElement xItem = null; if (TrialId != null) { xItem = new XElement(XName.Get("trialId", "https://adwords.google.com/api/adwords/cm/v201609")); xItem.Add(TrialId.Value.ToString()); xE.Add(xItem); } if (AsyncError != null) { xItem = new XElement(XName.Get("asyncError", "https://adwords.google.com/api/adwords/cm/v201609")); AsyncError.WriteTo(xItem); xE.Add(xItem); } if (TrialCampaignId != null) { xItem = new XElement(XName.Get("trialCampaignId", "https://adwords.google.com/api/adwords/cm/v201609")); xItem.Add(TrialCampaignId.Value.ToString()); xE.Add(xItem); } if (TrialAdGroupId != null) { xItem = new XElement(XName.Get("trialAdGroupId", "https://adwords.google.com/api/adwords/cm/v201609")); xItem.Add(TrialAdGroupId.Value.ToString()); xE.Add(xItem); } if (BaseCampaignId != null) { xItem = new XElement(XName.Get("baseCampaignId", "https://adwords.google.com/api/adwords/cm/v201609")); xItem.Add(BaseCampaignId.Value.ToString()); xE.Add(xItem); } if (BaseAdGroupId != null) { xItem = new XElement(XName.Get("baseAdGroupId", "https://adwords.google.com/api/adwords/cm/v201609")); xItem.Add(BaseAdGroupId.Value.ToString()); xE.Add(xItem); } }
/// <summary> /// Processes a SPARQL Query using given SPARQL procesor returning either an IGraph instance or SparqlResultSet, or AsyncError if the processing failed /// </summary> /// <returns>IGraph or SparqlResultSet or AsyncError or null</returns> public static Task <object> ProcessQuery(SparqlQuery query, ISparqlQueryProcessor processor) { TaskCompletionSource <object> taskComplSource = new TaskCompletionSource <object>(); if (query == null || processor == null) { var asyncError = new AsyncError(new BrowserException("An internal error occured while processing the query."), null); taskComplSource.SetResult(asyncError); } else { //state will contain AsyncError //catches all exceptions inside, putting them into AsyncError processor.ProcessQuery( query, (IGraph g, object state) => { taskComplSource.SetResult(g ?? state); }, (SparqlResultSet results, object state) => { taskComplSource.SetResult(results ?? state); }, null ); } return(taskComplSource.Task); }
public virtual void ReadFrom(XElement xE) { TrialId = null; AsyncError = null; TrialCampaignId = null; TrialAdGroupId = null; BaseCampaignId = null; BaseAdGroupId = null; foreach (var xItem in xE.Elements()) { var localName = xItem.Name.LocalName; if (localName == "trialId") { TrialId = long.Parse(xItem.Value); } else if (localName == "asyncError") { AsyncError = InstanceCreator.CreateApiError(xItem); AsyncError.ReadFrom(xItem); } else if (localName == "trialCampaignId") { TrialCampaignId = long.Parse(xItem.Value); } else if (localName == "trialAdGroupId") { TrialAdGroupId = long.Parse(xItem.Value); } else if (localName == "baseCampaignId") { BaseCampaignId = long.Parse(xItem.Value); } else if (localName == "baseAdGroupId") { BaseAdGroupId = long.Parse(xItem.Value); } } }
protected void HandleResponseError(AsyncError err, ExecuteWebRequestEventArgs args) { Logger.Error("Error in response handling", err.Exception); Application.Current.Dispatcher.Invoke(new Action(() => { IsExecutingRequest = false; if (err.Response.WebResponse != null) { StatusLine = string.Format("{0} {1}", (int)err.Response.StatusCode, err.Response.StatusCode.ToString()); } else if (err.Exception != null) { StatusLine = err.Exception.Message; } else { StatusLine = "Unknown error"; } PreviousStatusLine = null; if (args.OnFailure != null) { args.OnFailure(err.Response); } RenderResponse(err.Response); MessageBox.Show(GetOwnerWindow(), err.Exception.Message); if (err.Response != null) { TryHandleAuthorization(err.Response); } })); }