public static DeserializeBase64 ( string data ) : object | ||
data | string | |
return | object |
void IHttpHandler.ProcessRequest(HttpContext ctx) { try { if (ctx.Request.Url.GetComponents(UriComponents.Path, UriFormat.Unescaped).ToLower().EndsWith("/ui")) { UI.ProcessRequest(ctx); } else { string reqPayload; using (StreamReader reader = new StreamReader(ctx.Request.InputStream)) reqPayload = reader.ReadToEnd(); ICommand command = (ICommand)SerializationUtil.DeserializeBase64(reqPayload); Response response = command.Execute(ctx); ctx.Response.Write(SerializationUtil.SerializeBase64(response)); } } catch (Exception error) { var errorResponse = new ErrorResponse() { Message = error.Message, ExceptionType = error.GetType().FullName, StackTrace = error.StackTrace }; ctx.Response.Write(SerializationUtil.SerializeBase64(errorResponse)); } }
public TResponse Send(string serviceUrl, TimeSpan retryPeriodOnServiceUnavailable) { string reqPayload = SerializationUtil.SerializeBase64(this); DateTime startTime = DateTime.Now; RETRY: HttpWebRequest http = (HttpWebRequest)WebRequest.Create(serviceUrl + "?" + GetType().Name); http.Method = "POST"; http.Timeout = 10 * 60 * 1000; //if(Amnesia.Settings.Current.AuthenticationMode == AuthenticationMode.Windows) // http.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; using (StreamWriter writer = new StreamWriter(http.GetRequestStream())) { writer.Write(reqPayload); writer.Close(); } string respPayload; try { using (StreamReader reader = new StreamReader(http.GetResponse().GetResponseStream())) respPayload = reader.ReadToEnd(); } catch (WebException err) { if (err.Response != null && ((HttpWebResponse)err.Response).StatusCode == HttpStatusCode.ServiceUnavailable && (DateTime.Now - startTime) < retryPeriodOnServiceUnavailable) { // wait a moment then retry Thread.Sleep(1000); goto RETRY; } throw; } object response = SerializationUtil.DeserializeBase64(respPayload); if (response is Handler.ErrorResponse) { var errorResponse = (Handler.ErrorResponse)response; throw new ApplicationException(string.Format("Amnesia Handler Error: {0}\nException: {1}\nStack Track: {2}", errorResponse.Message, errorResponse.ExceptionType, errorResponse.StackTrace)); } return((TResponse)response); }