private void SaveEncoding(object sender, EventArgs e) { //指定格式保存 if (_saveWindow != null) { _saveWindow.Focus(); _saveWindow.Show(); return; } var dte = (DTE)ServiceProvider.GetService(typeof(DTE)); var s = dte.ActiveDocument.FullName; var window = new Window(); var definitionPage = new EncodingPage(); definitionPage.Closing += (_s, _e) => { window.Close(); _definitionWindow = null; }; window.Closed += (_s, _e) => { _definitionWindow = null; }; window.Title = "指定保存格式"; window.Content = definitionPage; window.Show(); _saveWindow = window; }
private void Save() { #region Socket parameter clientSocketParams.LocalIP = ""; clientSocketParams.LocalPort = -1; clientSocketParams.CallbackIP = this.txtCallbackIP.Text; clientSocketParams.CallbackPort = (int)this.txtCallbackPort.Value; clientSocketParams.ServerIP = this.txtServerIP.Text; clientSocketParams.ServerPort = (int)this.txtServerPort.Value; SocketOutboundAdapterConfigMgt.SocketOutAdapterConfig.OutGeneralParams.TimerInterval = Int32.Parse(this.txtInterval.Text); clientSocketParams.ConnectTimeout = Int32.Parse(this.txtConnectTimeout.Text); clientSocketParams.ConnectTryCount = Int32.Parse(this.txtTryCount.Text); clientSocketParams.RecTimeout = Int32.Parse(this.txtReceiveTimeout.Text); clientSocketParams.SendTimeout = Int32.Parse(this.txtSendTimeout.Text); clientSocketParams.CodePageName = EncodingPage.GetAllCodePages()[cbCodePage.SelectedIndex].Name; #endregion string FileName = Application.StartupPath + "\\" + SocketOutboundAdapterConfigMgt.FileName; if (!SocketOutboundAdapterConfigMgt.Save(FileName)) { if (SocketOutboundAdapterConfigMgt.LastException != null) { Program.log.Write(LogType.Error, "Cannot save information to configuration file: " + FileName); } MessageBox.Show(SocketOutboundAdapterConfigMgt.LastException.Message); } }
private void CreateClientSocket() { if (_ClientSocket == null) { _ClientSocket = new ClientSocket(_logClient); _ClientSocket.CodePageName = EncodingPage.GetAllCodePages()[cbcCodePage.SelectedIndex].Name; } }
private void InitCodePage() { this.cbCodePage.Items.Clear(); for (int i = 0; i < EncodingPage.GetAllCodePages().Length; i++) { EncodingInfo ei = EncodingPage.GetAllCodePages()[i]; cbCodePage.Items.Add(ei.DisplayName + " (" + ei.CodePage.ToString() + ")"); } }
private void CreateServerSocket() { string sListenIP = tbListenIP.Text; int iListenPort = Convert.ToInt32(tbListentPort.Text); _ServerSocket = new ServerSocket(sListenIP, iListenPort, _logServer); _ServerSocket.CodePageName = EncodingPage.GetAllCodePages()[cbsCodePage.SelectedIndex].Name; _ServerSocket.OnClientDataReceived += OnDataReceived; }
private void cbcCodePage_SelectedIndexChanged(object sender, EventArgs e) { if (_ServerSocket != null) { _ServerSocket.CodePageName = EncodingPage.GetAllCodePages()[cbsCodePage.SelectedIndex].Name; } if (_ClientSocket != null) { _ClientSocket.CodePageName = EncodingPage.GetAllCodePages()[cbcCodePage.SelectedIndex].Name; } }
private void Initialization() { InitCodePage(); clientSocketParams = SocketOutboundAdapterConfigMgt.SocketOutAdapterConfig.ClientSocketParams; channelSet = SocketOutboundAdapterConfigMgt.SocketOutAdapterConfig.OutboundChanels; LUTableSet = SocketOutboundAdapterConfigMgt.SocketOutAdapterConfig.LookupTables; #region ClientSocketParameters this.txtCallbackIP.Text = clientSocketParams.CallbackIP.ToString(); this.txtCallbackPort.Value = clientSocketParams.CallbackPort; this.txtServerIP.Text = clientSocketParams.ServerIP.ToString(); this.txtServerPort.Text = clientSocketParams.ServerPort.ToString(); this.txtInterval.Text = SocketOutboundAdapterConfigMgt.SocketOutAdapterConfig.OutGeneralParams.TimerInterval.ToString(); this.txtConnectTimeout.Text = clientSocketParams.ConnectTimeout.ToString(); this.txtTryCount.Text = clientSocketParams.ConnectTryCount.ToString(); this.txtReceiveTimeout.Text = clientSocketParams.RecTimeout.ToString(); this.txtSendTimeout.Text = clientSocketParams.SendTimeout.ToString(); this.cbCodePage.SelectedIndex = EncodingPage.GetIndex(clientSocketParams.CodePageName); #endregion #region Channel if (channelSet != null) { if (channelSet.Count != 0) { ShowChannelSetInformation(); } //It sign that there is no channel in the channelset } else { //Never occur as SocketOutAdapterConfigMgt.SocketOutAdapterConfig was be constuctured channelSet = new XCollection <SocketOutChannel>(); } #endregion #region Look up tables if (LUTableSet != null) { if (LUTableSet.Count != 0) { ShowLUTableSetInformation(); } } else { //Never occur as SocketOutAdapterConfigMgt.SocketOutAdapterConfig was be constuctured LUTableSet = new XCollection <LookupTable>(); } #endregion }
private void Initialization() { InitCodePage(); ServerSocketParams = SocketInboundAdapterConfigMgt.SocketInAdapterConfig.ListenServerSocketParams; channelSet = SocketInboundAdapterConfigMgt.SocketInAdapterConfig.InboundChanels; LUTableSet = SocketInboundAdapterConfigMgt.SocketInAdapterConfig.LookupTables; #region ServerSocketParameters this.txtIP.Text = ServerSocketParams.ListenIP; this.txtPort.Text = ServerSocketParams.ListenPort.ToString(); this.txtConnectTimeout.Text = ServerSocketParams.ConnectTimeout.ToString(); this.txtTryCount.Text = ServerSocketParams.ConnectTryCount.ToString(); this.txtReceiveTimeout.Text = ServerSocketParams.RecTimeout.ToString(); this.txtSendTimeout.Text = ServerSocketParams.SendTimeout.ToString(); this.cbCodePage.SelectedIndex = EncodingPage.GetIndex(ServerSocketParams.CodePageName); #endregion #region Channel if (channelSet != null) { if (channelSet.Count != 0) { ShowChannelSetInformation(); } //It sign that there is no channel in the channelset } else { //Never occur as SocketInAdapterConfigMgt.SocketInAdapterConfig was be constuctured channelSet = new XCollection <SocketInChannel>(); } #endregion #region Look up tables if (LUTableSet != null) { if (LUTableSet.Count != 0) { ShowLUTableSetInformation(); } //It sign that there is no channel in the channelset } else { //Never occur as SocketInAdapterConfigMgt.SocketInAdapterConfig was be constuctured LUTableSet = new XCollection <LookupTable>(); } #endregion }
private void Save() { #region Server Socket parameter ServerSocketParams.ListenIP = this.txtIP.Text; ServerSocketParams.ListenPort = Int32.Parse(this.txtPort.Text); ServerSocketParams.ConnectTimeout = Int32.Parse(this.txtConnectTimeout.Text); ServerSocketParams.ConnectTryCount = Int32.Parse(this.txtTryCount.Text); ServerSocketParams.RecTimeout = Int32.Parse(this.txtReceiveTimeout.Text); ServerSocketParams.SendTimeout = Int32.Parse(this.txtSendTimeout.Text); ServerSocketParams.CodePageName = EncodingPage.GetAllCodePages()[cbCodePage.SelectedIndex].Name; #endregion string FileName = Application.StartupPath + "\\" + SocketInboundAdapterConfigMgt.FileName; if (!SocketInboundAdapterConfigMgt.Save(FileName)) { if (SocketInboundAdapterConfigMgt.LastException != null) { Program.log.Write(LogType.Error, "Cannot save information to configuration file: " + FileName); } MessageBox.Show(SocketInboundAdapterConfigMgt.LastException.Message); } }
private HttpWebRequest CreateRequest() { HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Url); httpWebRequest.UserAgent = UserAgent; httpWebRequest.PreAuthenticate = PreAuthenticate; httpWebRequest.Accept = Accept; httpWebRequest.Timeout = TimeoutRequest; httpWebRequest.KeepAlive = KeepAlive; if (this.Parameters != null && this.Parameters.Length > 0) { httpWebRequest.Method = "POST"; } else { httpWebRequest.Method = "GET"; } httpWebRequest.Headers["Accept-Encoding"] = AcceptEncoding; httpWebRequest.Headers["Accept-Language"] = AcceptLanguage; httpWebRequest.Headers["UA-CPU"] = UACPU; httpWebRequest.Headers["Cache-Control"] = CacheControl; if (!string.IsNullOrEmpty(RequestedWith)) { httpWebRequest.Headers["x-requested-with"] = RequestedWith; } httpWebRequest.ContentLength = 0L; httpWebRequest.AllowAutoRedirect = AutoRedirect; if (Headers != null) { foreach (KeyValuePair <string, string> header in Headers) { httpWebRequest.Headers.Add(header.Key, header.Value); } } if (Referer != null) { httpWebRequest.Referer = Referer; } httpWebRequest.CookieContainer = new CookieContainer(); if (AllCookies.Count > 0) { foreach (Cookie todosCookie in AllCookies) { httpWebRequest.CookieContainer.Add(todosCookie); } } if (Parameters != null && Parameters.Trim().Length > 0) { byte[] bytes = EncodingPage.GetBytes(Parameters); httpWebRequest.Method = "POST"; httpWebRequest.ContentType = ContentType; httpWebRequest.ContentLength = bytes.Length; using (Stream requestStream = httpWebRequest.GetRequestStream()) { requestStream.Write(bytes, 0, bytes.Length); requestStream.Close(); } } return(httpWebRequest); }
internal ResponseHttp LoadPage(string url) { responseHttp = new ResponseHttp(); this.Url = url; lock (SyncRoot) { try { HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(Url); httpWebRequest.UserAgent = UserAgent; httpWebRequest.PreAuthenticate = PreAuthenticate; httpWebRequest.Accept = Accept; httpWebRequest.Timeout = TimeoutRequest; httpWebRequest.KeepAlive = KeepAlive; if (this.Parameters != null && this.Parameters.Length > 0) { httpWebRequest.Method = "POST"; } else { httpWebRequest.Method = "GET"; } httpWebRequest.Headers["Accept-Encoding"] = AcceptEncoding; httpWebRequest.Headers["Accept-Language"] = AcceptLanguage; httpWebRequest.Headers["UA-CPU"] = UACPU; httpWebRequest.Headers["Cache-Control"] = CacheControl; if (!string.IsNullOrEmpty(RequestedWith)) { httpWebRequest.Headers["x-requested-with"] = RequestedWith; } httpWebRequest.ContentLength = 0L; httpWebRequest.AllowAutoRedirect = AutoRedirect; if (Headers != null) { foreach (KeyValuePair <string, string> header in Headers) { httpWebRequest.Headers.Add(header.Key, header.Value); } } if (Referer != null) { httpWebRequest.Referer = Referer; } httpWebRequest.CookieContainer = new CookieContainer(); if (AllCookies.Count > 0) { foreach (Cookie todosCookie in AllCookies) { httpWebRequest.CookieContainer.Add(todosCookie); } } if (Parameters != null && Parameters.Trim().Length > 0) { byte[] bytes = EncodingPage.GetBytes(Parameters); httpWebRequest.Method = "POST"; httpWebRequest.ContentType = ContentType; httpWebRequest.ContentLength = bytes.Length; using (Stream requestStream = httpWebRequest.GetRequestStream()) { requestStream.Write(bytes, 0, bytes.Length); requestStream.Close(); } } string html; string responseHeader; using (HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse()) { responseHttp.StatusCode = response.StatusCode; if (response.ContentType.StartsWith("image")) { using (Stream responseStream = response.GetResponseStream()) html = string.Format("data:{0};base64,{1}", response.ContentType, Convert.ToBase64String(responseStream.ReadAllBytes())); } else { using (Stream responseStream = response.GetResponseStream()) { Stream stream = null; try { stream = string.IsNullOrEmpty(response.ContentEncoding) || !response.ContentEncoding.ToLower().Contains("gzip") ? (string.IsNullOrEmpty(response.ContentEncoding) || !response.ContentEncoding.ToLower().Contains("deflate") ? responseStream : new DeflateStream(responseStream, CompressionMode.Decompress)) : new GZipStream(responseStream, CompressionMode.Decompress); using (StreamReader streamReader = new StreamReader(stream, DefaultEncoding)) { html = streamReader.ReadToEnd(); streamReader.Close(); } responseStream.Close(); } finally { if (stream != null) { stream.Dispose(); } } } } AddCookies(response.Cookies, responseHttp); AddInternalCookie(response, responseHttp); responseHeader = response.GetResponseHeader("Location"); responseHttp.UrlLocation = responseHeader; responseHttp.Method = response.Method; responseHttp.Server = response.Server; responseHttp.HeadersAdded = this.Headers; response.Close(); } if (MaxRedirect > 0) { if (!string.IsNullOrEmpty(responseHeader) && Uri.IsWellFormedUriString(responseHeader, UriKind.Absolute)) { MaxRedirect--; this.Referer = url; return(LoadPage(responseHeader)); } } responseHttp.HtmlPage = html; LoadTypes(html, responseHttp); OnLoad?.Invoke(this, new RequestHttpEventArgs(html, responseHttp)); return(responseHttp); } catch (WebException ex) { responseHttp.StatusCode = HttpStatusCode.InternalServerError; } //catch (Exception ex) //{ // return null; //} return(responseHttp); } }