private ICompareService CreateComparer(TransportProtocolEnum transport) { switch (transport) { case TransportProtocolEnum.Http: return(CompareService.CreateHttpService("localhost", 8080)); case TransportProtocolEnum.NamedPipe: return(CompareService.CreateNamedPipeService()); case TransportProtocolEnum.Tcp: return(CompareService.CreateTcpService("localhost", 8090)); default: return(null); } }
/// <summary> /// Create appropriate service based on protocol specified by the user. Its safe to assume that this /// page will always be running on the same machine as the service. /// </summary> /// <param name="protocol"></param> /// <returns></returns> private ICompareService CreateAppropriateService(TransportProtocolEnum protocol) { switch (protocol) { case TransportProtocolEnum.Tcp: _divideFactor = 1; return(CompareService.CreateTcpService("localhost", Int32.Parse(System.Configuration.ConfigurationSettings.AppSettings["tcp_port"]))); case TransportProtocolEnum.NamedPipe: _divideFactor = 10; return(CompareService.CreateNamedPipeService()); case TransportProtocolEnum.Http: default: _divideFactor = 1; return(CompareService.CreateHttpService("localhost", Int32.Parse(System.Configuration.ConfigurationSettings.AppSettings["http_port"]))); } }
protected void Page_Load(object sender, EventArgs e) { try { // Only activated if postedback // Dont do anything on startup if (this.IsPostBack) { TransportProtocolEnum transportProtocol = (TransportProtocolEnum)Enum.Parse(typeof(TransportProtocolEnum), this.Protocol.Text, true); int chunkingSize = 512; try { if (this.Chunksize.Text != null) { chunkingSize = Convert.ToInt32(this.Chunksize.Text); } } catch { chunkingSize = 512; } ICompareService cp = CreateAppropriateService(transportProtocol); string user = (string)Session["UserName"]; string pass = CodePassword((string)Session["Passw"]); string domain = (string)Session["Domain"]; cp.SetClientCredentials(user, pass, domain); // We need to hook into this event to calculate the progress and data rate. cp.DataSent += new EventHandler <DataSentArgs>(CompareService_OnDataSent); //Call into benchmarking with specified chunk size and 40 MB of dummy data cp.BenchmarkTransfer(chunkingSize * 1024, 40 * 1024 * 1024); } } catch (Exception ex) { ShowMessage(ex.Message); } }
/// <summary> /// Reads variables from web.config file's appSettings section /// Reads httpRuntime section for maxRequestLength /// Reads registry for version string. /// </summary> private void InitConfigVariables() { try { _renderSetPath = ConfigurationSettings.AppSettings["renderset.path"]; } catch { _renderSetPath = "data/renderset"; } try { _tempDataPath = ConfigurationSettings.AppSettings["tempdata.path"]; } catch { _tempDataPath = "data/temp"; } try { _host = ConfigurationSettings.AppSettings["cs.host"]; } catch { _host = "localhost"; } try { _port = Int32.Parse(ConfigurationSettings.AppSettings["cs.port"]); } catch { _port = 8080; } try { _chunkSize = Int32.Parse(ConfigurationSettings.AppSettings["chunk.size"]); } catch { _chunkSize = 1024; } try { string transportProtocol = ConfigurationSettings.AppSettings["transport.protocol"]; _protocol = (TransportProtocolEnum)Enum.Parse(typeof(TransportProtocolEnum), transportProtocol, true); } catch { _protocol = TransportProtocolEnum.Http; } try { // Update maxRequestLength in the message to user. Configuration config = WebConfigurationManager.OpenWebConfiguration("~"); HttpRuntimeSection configSection = config.GetSection("system.web/httpRuntime") as HttpRuntimeSection; // MaxRequestLength returns KB. Convert that to MB. double nMaxContentLength = (double)configSection.MaxRequestLength / 1024; string message = "Please note: The combined size limit for all files being compared is {0} MB."; message = string.Format(message, Math.Round(nMaxContentLength, 2)); FileSizeWarningLabel.Text = message; } catch (Exception ex) { ShowMessage(GenerateScriptID("configSectionError"), "error", ex.Message); } // Update version VersionLabel.Text = GetVersionString(); }