static void FiddlerApplication_BeforeRequest(Session rpSession) { if (Preference.Current.Network.UpstreamProxy.Enabled) rpSession["x-OverrideGateway"] = Preference.Current.Network.UpstreamProxy.Address; var rRequest = rpSession.oRequest; var rFullUrl = rpSession.fullUrl; var rPath = rpSession.PathAndQuery; NetworkSession rSession; if (rPath.StartsWith("/kcsapi/")) rSession = new ApiSession(rFullUrl); else if (rPath.StartsWith("/kcs/") || rPath.StartsWith("/gadget/")) rSession = new ResourceSession(rFullUrl, rPath); else rSession = new NetworkSession(rFullUrl); rSession.RequestBodyString = Uri.UnescapeDataString(rpSession.GetRequestBodyAsString()); rpSession.Tag = rSession; SessionSubject.OnNext(rSession); if (rFullUrl == GameConstants.GamePageUrl || rPath == "/gadget/js/kcs_flash.js") rpSession.bBufferResponse = true; var rResourceSession = rSession as ResourceSession; if (rResourceSession != null) CacheService.Instance.ProcessRequest(rResourceSession, rpSession); }
void ProcessCore(ApiSession rpSession) { var rApi = rpSession.DisplayUrl; var rRequest = rpSession.RequestBodyString; var rResponse = rpSession.ResponseBodyString; try { var rContent = rResponse.Replace("svdata=", string.Empty); ApiParserBase rParser; if (!rContent.IsNullOrEmpty() && rContent.StartsWith("{") && Parsers.TryGetValue(rApi, out rParser)) { Dictionary<string, string> rRequests = null; if (!rRequest.IsNullOrEmpty() && rRequest.Contains('&')) rRequests = rRequest.Split('&').Where(r => r.Length > 0).Select(r => r.Split('=')) .ToDictionary(r => Uri.UnescapeDataString(r[0]), r => Uri.UnescapeDataString(r[1])); var rJson = JObject.Parse(rContent); rParser.Requests = rRequests; rParser.Process(rJson); rParser.Requests = null; } } catch (ApiFailedException e) { Logger.Write(LoggingLevel.Error, string.Format(StringResources.Instance.Main.Log_Exception_API_Failed, rApi, e.ResultCode)); } catch (Exception e) { Logger.Write(LoggingLevel.Error, string.Format(StringResources.Instance.Main.Log_Exception_API_ParseException, e.Message)); ExceptionSources.OnNext(Tuple.Create(rpSession, e)); } }
static void FiddlerApplication_BeforeRequest(Session rpSession) { if (r_BlockingList.Any(rpSession.uriContains)) { rpSession.utilCreateResponseAndBypassServer(); return; } if (!r_UpstreamProxy.IsNullOrEmpty()) { rpSession["x-OverrideGateway"] = r_UpstreamProxy; } var rRequest = rpSession.oRequest; var rFullUrl = rpSession.fullUrl; var rPath = rpSession.PathAndQuery; NetworkSession rSession; if (rPath.StartsWith("/kcsapi/")) { rSession = new ApiSession(rFullUrl); } else if (rPath.StartsWith("/kcs/") || rPath.StartsWith("/gadget/")) { rSession = new ResourceSession(rFullUrl, rPath); } else { rSession = new NetworkSession(rFullUrl); } rSession.RequestBodyString = Uri.UnescapeDataString(rpSession.GetRequestBodyAsString()); rSession.Method = rpSession.RequestMethod; rpSession.Tag = rSession; if (rFullUrl.OICEquals(GameConstants.GamePageUrl) || rFullUrl.OICEquals("http://www.dmm.com/netgame_s/kancolle/") || rPath.OICEquals("/gadget/js/kcs_flash.js")) { rpSession.bBufferResponse = true; } var rResourceSession = rSession as ResourceSession; if (rResourceSession != null) { CacheService.Instance.ProcessRequest(rResourceSession, rpSession); } rSession.RequestHeaders = rpSession.RequestHeaders.Select(r => new SessionHeader(r.Name, r.Value)).ToArray(); SessionSubject.OnNext(rSession); if (!rpSession.bHasResponse && r_TrafficBarrier != null) { r_TrafficBarrier.Wait(); } }
internal override sealed void Process(ApiSession rpSession, JObject rpJson) { base.Process(rpSession, rpJson); Process(); OnProcessSucceeded(new ApiData(rpSession, Api, Parameters, rpJson)); }
static void FiddlerApplication_BeforeRequest(Session rpSession) { if (r_BlockingList.Any(rpSession.uriContains)) { rpSession.utilCreateResponseAndBypassServer(); return; } var rUpstreamProxyPreference = Preference.Instance.Network.UpstreamProxy; if (rUpstreamProxyPreference.Enabled && (!rUpstreamProxyPreference.HttpOnly || !rpSession.RequestMethod.OICEquals("CONNECT"))) { rpSession["x-OverrideGateway"] = $"{rUpstreamProxyPreference.Host.Value}:{rUpstreamProxyPreference.Port.Value}"; } var rRequest = rpSession.oRequest; var rFullUrl = rpSession.fullUrl; var rPath = rpSession.PathAndQuery; NetworkSession rSession; if (rPath.StartsWith("/kcsapi/")) { rSession = new ApiSession(rFullUrl); } else if (rPath.StartsWith("/kcs/") || rPath.StartsWith("/gadget/")) { rSession = new ResourceSession(rFullUrl, rPath); } else { rSession = new NetworkSession(rFullUrl); } rSession.RequestBodyString = Uri.UnescapeDataString(rpSession.GetRequestBodyAsString()); rSession.Method = rpSession.RequestMethod; rpSession.Tag = rSession; if (rFullUrl == GameConstants.GamePageUrl || rPath == "/gadget/js/kcs_flash.js") { rpSession.bBufferResponse = true; } var rResourceSession = rSession as ResourceSession; if (rResourceSession != null) { CacheService.Instance.ProcessRequest(rResourceSession, rpSession); } rSession.RequestHeaders = rpSession.RequestHeaders.Select(r => new SessionHeader(r.Name, r.Value)).ToArray(); SessionSubject.OnNext(rSession); }
static void ProcessCore(ApiSession rpSession) { var rApi = rpSession.DisplayUrl; var rResponse = rpSession.ResponseBodyString; try { var rContent = rResponse.Replace("svdata=", string.Empty); ApiParserBase rParser; if (!rContent.IsNullOrEmpty() && rContent.StartsWith("{") && r_Parsers.TryGetValue(rApi, out rParser)) { var rJson = JObject.Parse(rContent); var rResultCode = (int)rJson["api_result"]; if (rResultCode != 1) { Logger.Write(LoggingLevel.Error, string.Format(StringResources.Instance.Main.Log_Exception_API_Failed, rApi, rResultCode)); return; } var rData = new ApiInfo(rpSession, rApi, rpSession.Parameters, rJson); rParser.Process(rData); } } catch (AggregateException e) when (e.InnerExceptions.Count == 1) { Logger.Write(LoggingLevel.Error, string.Format(StringResources.Instance.Main.Log_Exception_API_ParseException, e.InnerExceptions[0].Message)); rpSession.ErrorMessage = e.ToString(); HandleException(rpSession, e); } catch (Exception e) { Logger.Write(LoggingLevel.Error, string.Format(StringResources.Instance.Main.Log_Exception_API_ParseException, e.Message)); rpSession.ErrorMessage = e.ToString(); HandleException(rpSession, e); } }
void ProcessCore(ApiSession rpSession) { var rApi = rpSession.DisplayUrl; var rRequest = rpSession.RequestBodyString; var rResponse = rpSession.ResponseBodyString; try { var rContent = rResponse.Replace("svdata=", string.Empty); ApiParserBase rParser; if (!rContent.IsNullOrEmpty() && rContent.StartsWith("{") && Parsers.TryGetValue(rApi, out rParser)) { ListDictionary<string, string> rParameters = null; if (!rRequest.IsNullOrEmpty() && rRequest.Contains('&')) { rParameters = new ListDictionary<string, string>(StringComparer.OrdinalIgnoreCase); foreach (var rParameter in rRequest.Split('&').Where(r => r.Length > 0).Select(r => r.Split('='))) rParameters.Add(Uri.UnescapeDataString(rParameter[0]), Uri.UnescapeDataString(rParameter[1])); } rParser.Parameters = rParameters; rParser.Process(rpSession, JObject.Parse(rContent)); rParser.Parameters = null; } } catch (ApiFailedException e) { Logger.Write(LoggingLevel.Error, string.Format(StringResources.Instance.Main.Log_Exception_API_Failed, rApi, e.ResultCode)); } catch (Exception e) { Logger.Write(LoggingLevel.Error, string.Format(StringResources.Instance.Main.Log_Exception_API_ParseException, e.Message)); r_ExceptionObservable.OnNext(Tuple.Create(rpSession, e)); } }
public void Process(ApiSession rpSession) => r_SessionSources.OnNext(rpSession);
public bool IsBlocked(ApiSession rpSession) => Filter == null ? false : Filter(rpSession.DisplayUrl, rpSession.Parameters);
static void Retry(ApiSession rpSession, Session rpFiddlerSession) { TaskDialog rDialog = null; var rMaxAutoRetryCount = Preference.Instance.Network.AutoRetryCount.Value; var rErrorMessage = rpSession.ErrorMessage; try { for (var i = 1; ; i++) { if (i > rMaxAutoRetryCount) { if (!Preference.Instance.Network.AutoRetryConfirmation.Value) { return; } if (rDialog == null) { rDialog = new TaskDialog() { OwnerWindowHandle = ServiceManager.GetService <IMainWindowService>().Handle, Instruction = StringResources.Instance.Main.MessageDialog_Proxy_AutoRetry, Content = string.Format(StringResources.Instance.Main.MessageDialog_Proxy_AutoRetry_Message, rpSession.DisplayUrl), Buttons = { new TaskDialogCommandLink(TaskDialogCommonButton.Yes, StringResources.Instance.Main.MessageDialog_Proxy_AutoRetry_Button_Continue), new TaskDialogCommandLink(TaskDialogCommonButton.No, StringResources.Instance.Main.MessageDialog_Proxy_AutoRetry_Button_Abort), }, ButtonStyle = TaskDialogButtonStyle.CommandLink, } } ; if (i == rMaxAutoRetryCount + 2) { rDialog.Content = string.Format(StringResources.Instance.Main.MessageDialog_Proxy_AutoRetry_Message2, rpSession.DisplayUrl); } rDialog.Detail = rErrorMessage; if (rDialog.Show().ClickedCommonButton == TaskDialogCommonButton.No) { return; } } var rStringDictionary = new StringDictionary(); rStringDictionary.Add("X-RetryCount", i.ToString()); Logger.Write(LoggingLevel.Info, string.Format(StringResources.Instance.Main.Log_Proxy_AutoRetry, i.ToString(), rpSession.DisplayUrl)); var rNewSession = FiddlerApplication.oProxy.SendRequestAndWait(rpFiddlerSession.oRequest.headers, rpFiddlerSession.requestBodyBytes, rStringDictionary, null); if (rNewSession.responseCode != 200) { rErrorMessage = rNewSession.GetResponseBodyAsString(); } else { rpFiddlerSession.oResponse.headers = rNewSession.oResponse.headers; rpFiddlerSession.responseBodyBytes = rNewSession.responseBodyBytes; rpFiddlerSession.oResponse.headers["Connection"] = "close"; return; } } } finally { rDialog?.Dispose(); } }
internal static void HandleException(ApiSession rpSession, Exception rException) { try { using (var rStreamWriter = new StreamWriter(Logger.GetNewExceptionLogFilename(), false, new UTF8Encoding(true))) { rStreamWriter.WriteLine(TokenRegex.Replace(rpSession.FullUrl, "***************************")); rStreamWriter.WriteLine("Request Data:"); rStreamWriter.WriteLine(TokenRegex.Replace(rpSession.RequestBodyString, "***************************")); rStreamWriter.WriteLine(); rStreamWriter.WriteLine("Exception:"); rStreamWriter.WriteLine(rException.ToString()); rStreamWriter.WriteLine(); rStreamWriter.WriteLine("Response Data:"); rStreamWriter.WriteLine(Regex.Unescape(rpSession.ResponseBodyString)); } } catch { } }
public static void Process(ApiSession rpSession) => Task.Run(() => ProcessCore(rpSession));
internal void HandleException(ApiSession rpSession, Exception rException) { try { using (var rStreamWriter = new StreamWriter(Logger.GetNewExceptionLogFilename(), false, new UTF8Encoding(true))) { rStreamWriter.WriteLine("Exception:"); rStreamWriter.WriteLine(rException.ToString()); rStreamWriter.WriteLine(); var rCommandTexts = HistoryCommandTexts.ToArray(); rStreamWriter.WriteLine("SQL:"); for (var i = 0; i < rCommandTexts.Length; i++) { rStreamWriter.Write(i + 1); rStreamWriter.WriteLine(rCommandTexts[i]); } rStreamWriter.WriteLine(); rStreamWriter.WriteLine(ApiParserManager.TokenRegex.Replace(rpSession.FullUrl, "***************************")); rStreamWriter.WriteLine("Request Data:"); rStreamWriter.WriteLine(ApiParserManager.TokenRegex.Replace(rpSession.RequestBodyString, "***************************")); rStreamWriter.WriteLine(); rStreamWriter.WriteLine("Response Data:"); rStreamWriter.WriteLine(Regex.Unescape(rpSession.ResponseBodyString)); } } catch { } }
public void Process(ApiSession rpSession) => r_SessionObservable.OnNext(rpSession);