public TrendbarJson[] getMinuteTredbars(long accountId, string symbolName, DateTime from, DateTime to) { IDictionary <string, string> pathParams = new Dictionary <string, string>(); pathParams["id"] = accountId.ToString(); pathParams["symbolName"] = symbolName; IDictionary <string, string> requestParams = new Dictionary <string, string>(); requestParams["from"] = from.ToString("yyyyMMddHHmmss"); requestParams["to"] = to.ToString("yyyyMMddHHmmss"); string service = getServiceURLString(MINUTE_TRENDBARS_SERVICE, pathParams, requestParams); try { MessageJson <TrendbarJson[]> messageJson = JsonConvert.DeserializeObject <MessageJson <TrendbarJson[]> >(callURL(service)); ErrorJson error = messageJson.Error; if (error != null) { throw new AccountsAPIException(error.ErrorCode, error.Description); } return(messageJson.Data); } catch (System.Exception e) { throw new AccountsAPIException(e); } }
public void Issue308() { var error = new Error(); error.QueryString.Add(new NameValueCollection { { null, "foo" } }); var json = ErrorJson.EncodeString(error); Assert.NotNull(json); }
public JObject GetErrorById(int id) { var error = _elmahErrorLogManager.GetErrorById(id.ToString()); return(JObject.Parse(JsonConvert.SerializeObject (new { Error = ErrorJson.EncodeString(ErrorXml.DecodeString(error.Error)), IsDebugMode = error.IsDebugMode, IsMobileMode = error.IsMobileMode, }, Formatting.None))); }
// Отправка страницы с ошибкой public string SendError(int Code) { // Получаем строку вида "200 OK" // HttpStatusCode хранит в себе все статус-коды HTTP/1.1 //string CodeStr = Code.ToString() + " " + ((HttpStatusCode)Code).ToString(); ErrorJson account = new ErrorJson { Code = Code, MessageCode = ((HttpStatusCode)Code).ToString() }; return(JsonConvert.SerializeObject(account, Formatting.Indented)); }
public TradingAccountJson[] getTradingAccounts() { string service = getServiceURLString(TRADING_ACCOUNTS_SERVICE); try { MessageJson <TradingAccountJson[]> messageJson = JsonConvert.DeserializeObject <MessageJson <TradingAccountJson[]> >(callURL(service)); ErrorJson error = messageJson.Error; if (error != null) { throw new AccountsAPIException(error.ErrorCode, error.Description); } return(messageJson.Data); } catch (System.Exception e) { throw new AccountsAPIException(e); } }
public SymbolJson[] getSymbols(long accountId) { IDictionary <string, string> pathParams = new Dictionary <string, string>(); pathParams["id"] = accountId.ToString(); string service = getServiceURLString(SYMBOLS_SERVICE, pathParams); try { MessageJson <SymbolJson[]> messageJson = JsonConvert.DeserializeObject <MessageJson <SymbolJson[]> >(callURL(service)); ErrorJson error = messageJson.Error; if (error != null) { throw new AccountsAPIException(error.ErrorCode, error.Description); } return(messageJson.Data); } catch (System.Exception e) { throw new AccountsAPIException(e); } }
public static void ProcessRequest(HttpContext context, ElmahCore.ErrorLog errorLog) { var response = context.Response; response.ContentType = "application/json"; // // Retrieve the ID of the requested error and read it from // the store. // var errorId = context.Request.Query["id"].FirstOrDefault(); if (string.IsNullOrEmpty(errorId)) { throw new ApplicationException("Missing error identifier specification."); } var entry = errorLog.GetError(errorId); // // Perhaps the error has been deleted from the store? Whatever // the reason, pretend it does not exist. // if (entry == null) { context.Response.StatusCode = 404; } // // Stream out the error as formatted JSON. // using (var sw = new StreamWriter(response.Body)) ErrorJson.Encode(entry?.Error, sw); }
public override IEnumerable <string> Entries(IList <ErrorLogEntry> entries, int index, int count, int total) { Debug.Assert(entries != null); Debug.Assert(index >= 0); Debug.Assert(index + count <= entries.Count); var writer = new StringWriter { NewLine = "\n" }; if (_wrapped) { writer.WriteLine("<script type='text/javascript' language='javascript'>"); writer.WriteLine("//<[!CDATA["); } writer.Write(_callback); writer.Write('('); var json = new JsonTextWriter(writer); json.Object() .Member("total").Number(total) .Member("errors").Array(); var requestUrl = $"{Context.Request.Scheme}://{Context.Request.Host}{Context.Request.Path}"; for (var i = index; i < count; i++) { var entry = entries[i]; writer.WriteLine(); if (i == 0) { writer.Write(' '); } writer.Write(" "); var urlTemplate = $"{requestUrl}?id=" + Uri.EscapeDataString(entry.Id); json.Object(); ErrorJson.EncodeMembers(entry.Error, json); json.Member("hrefs") .Array() .Object() .Member("type").String("text/html") .Member("href").String(string.Format(urlTemplate, "detail")).Pop() .Object() .Member("type").String("application/json") .Member("href").String(string.Format(urlTemplate, "json")).Pop() .Object() .Member("type").String("application/xml") .Member("href").String(string.Format(urlTemplate, "xml")).Pop() .Pop() .Pop(); } json.Pop(); json.Pop(); if (count > 0) { writer.WriteLine(); } writer.WriteLine(");"); if (_wrapped) { writer.WriteLine("//]]>"); writer.WriteLine("</script>"); if (count == 0) { writer.WriteLine(@"</body></html>"); } } yield return(writer.ToString()); }
private void SetError(HttpContext context, ErrorLogEntry entry) { if (entry == null) { throw new ArgumentNullException("entry"); } var error = entry.Error; try { var request = (HttpWebRequest)WebRequest.Create(_targetUrl); request.Credentials = CredentialCache.DefaultNetworkCredentials; request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; // See http://blogs.msdn.com/shitals/archive/2008/12/27/9254245.aspx request.ServicePoint.Expect100Continue = false; // The idea is to post to an url the json representation // of the intercepted error. We do a base 64 encoding // to fool the other side just in case some sort of // automated post validation is performed (do we have a // better way to do this?). We post also the application // name and the handshaking token. var token = GetSourceId(context); var payload = ErrorJson.EncodeString(error); payload = string.IsNullOrEmpty(_secret) ? payload : Crypto.EncryptStringAes(payload, _secret); var form = new NameValueCollection { { "error", Base64Encode(payload) }, { "errorId", entry.Id }, { "sourceId", token }, { "infoUrl", _infoUrl != null ? _infoUrl.AbsoluteUri : null }, }; // Get the bytes to determine // and set the content length. var data = Encoding.ASCII.GetBytes(W3.ToW3FormEncoded(form)); Debug.Assert(data.Length > 0); request.ContentLength = data.Length; // Post it! (asynchronously) request.BeginGetRequestStream(ErrorReportingAsyncCallback(ar => { using (var output = request.EndGetRequestStream(ar)) output.Write(data, 0, data.Length); request.BeginGetResponse(ErrorReportingAsyncCallback(rar => request.EndGetResponse(rar).Close() /* Not interested; assume OK */), null); }), null); } catch (Exception e) { // IMPORTANT! We swallow any exception raised during the // logging and send them out to the trace . The idea // here is that logging of exceptions by itself should not // be critical to the overall operation of the application. // The bad thing is that we catch ANY kind of exception, // even system ones and potentially let them slip by. OnWebPostError(/* request, */ e); } }