/// <summary> /// Return a formatted, human readable Json string suitable for saving locally in a Config_WebDriver.json file /// </summary> /// <returns></returns> public string GetJsonConfigString() { // Serialising using json.net produces minimal, non readable json: Manually generate a readable, formatted string. StringBuilder jsonBuilder = new StringBuilder(); jsonBuilder.AppendLine("{"); jsonBuilder.AppendLine($" \"Browser\": \"{browser.ToString()}\","); jsonBuilder.AppendLine($" \"IsLocal\": {isLocal.ToString().ToLower()},"); jsonBuilder.AppendLine($" \"PlatformType\": \"{platformType.ToString()}\","); jsonBuilder.AppendLine($" \"Headless\": {headless.ToString().ToLower()},"); if (windowSize == WindowSize.Maximise || windowSize == WindowSize.Maximize || windowSize == WindowSize.Unchanged) { jsonBuilder.AppendLine($" \"WindowSize\": \"{windowSize.ToString()}\","); } else { jsonBuilder.AppendLine($" \"WindowSize\": \"{WindowSize.Defined.ToString()}\","); if (windowSize == WindowSize.Custom || windowSize == WindowSize.Defined) { jsonBuilder.AppendLine($" \"WindowDefinedSize\": {{\"width\":{windowDefinedSize.Width}, \"height\":{windowDefinedSize.Height}}},"); } else { jsonBuilder.AppendLine($" \"WindowDefinedSize\": {{\"width\":{windowSize.Size().Width}, \"height\":{windowSize.Size().Height}}},"); } } jsonBuilder.AppendLine($" \"GridUri\": \"{gridUri}\""); jsonBuilder.AppendLine("}"); return(jsonBuilder.ToString()); }
/// <inheritdoc /> public override XElement GetXml(string rootElemName, bool suppressDefaults) { XElement rootElem = new XElement(rootElemName, new XAttribute("fieldName", InputFieldName), new XAttribute("window", WindowSize.ToString(CultureInfo.InvariantCulture)), new XAttribute("output", OutputFigure.ToString()) ); Validate(rootElem, XsdTypeName); return(rootElem); }
//Methods /// <inheritdoc /> protected override void Check() { if (InputFieldName.Length == 0) { throw new ArgumentException($"Name of the input field must be specified.", "InputFieldName"); } if (WindowSize < 1) { throw new ArgumentException($"Invalid window size {WindowSize.ToString(CultureInfo.InvariantCulture)}. Window size must be GE to 2.", "Window"); } return; }
public void WriteConfigFile(XmlTextWriter xmlWriter) { xmlWriter.WriteStartElement("EyeMovementSettings"); Settings.WriteElement(xmlWriter, "MaxWindowSize", MaxWindowSize.ToString()); Settings.WriteElement(xmlWriter, "WindowSize", WindowSize.ToString()); Settings.WriteElement(xmlWriter, "DistanceUserToScreen", DistanceUserToScreen.ToString()); Settings.WriteElement(xmlWriter, "MaxAngularSpeed", MaxAngularSpeed.ToString()); Settings.WriteElement(xmlWriter, "MaxDispersion", MaxDispersion.ToString()); Settings.WriteElement(xmlWriter, "SmoothLevel", SmoothLevel.ToString()); Settings.WriteElement(xmlWriter, "SmoothNumberOfSamples", SmoothNumberOfSamples.ToString()); xmlWriter.WriteEndElement(); }
/// <summary> /// Return a WebDriver instance of the given configuration. /// </summary> /// <param name="browser"></param> /// <param name="windowSize"></param> /// <param name="isLocal"></param> /// <param name="platformType"></param> /// <param name="headless"></param> /// <param name="windowCustomSize"></param> /// <returns></returns> public IWebDriver GetWebDriver(Browser browser, WindowSize windowSize = WindowSize.Hd, bool isLocal = true, PlatformType platformType = PlatformType.Any, bool headless = false, Size windowCustomSize = new Size()) { string configurationDescription = new StringBuilder() .Append($"Browser: {browser.ToString()}") .Append(headless ? "headless" : "on screen") .Append($"WindowSize enum: {windowSize.ToString()}, ") .Append($"{((windowSize == WindowSize.Custom || windowSize == WindowSize.Defined) ? $"Size: {windowCustomSize.Width} x {windowCustomSize.Height}, " : string.Empty)}") .Append(isLocal ? "running locally)" : $"running remotely on {RemoteWebDriverFactory.GridUri} on platform: {platformType}.)") .ToString(); Logger.Info($"WebDriver requested using parameters: {configurationDescription}"); IWebDriver driver = isLocal ? LocalWebDriverFactory.GetWebDriver(browser, windowSize, headless, windowCustomSize) : RemoteWebDriverFactory.GetWebDriver(browser, platformType, windowSize, headless, windowCustomSize); if (IsDebugEnabled) { IJavaScriptExecutor js = (IJavaScriptExecutor)driver; Logger.Debug($"{driver} successfully launched. Agent String: {js.ExecuteScript("return navigator.userAgent;")}"); } return(driver); }
/// <summary cref="Packet.ToString(StringOutputType)" /> public override string ToString(StringOutputType outputFormat) { var buffer = new StringBuilder(); string color = ""; string colorEscape = ""; if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored) { color = Color; colorEscape = AnsiEscapeSequences.Reset; } if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored) { // build flagstring string flags = "{"; if (Urg) { flags += "urg[0x" + System.Convert.ToString(UrgentPointer, 16) + "]|"; } if (Ack) { flags += "ack[" + AcknowledgmentNumber + " (0x" + System.Convert.ToString(AcknowledgmentNumber, 16) + ")]|"; } if (Psh) { flags += "psh|"; } if (Rst) { flags += "rst|"; } if (Syn) { flags += "syn[0x" + System.Convert.ToString(SequenceNumber, 16) + "," + SequenceNumber + "]|"; } flags = flags.TrimEnd('|'); flags += "}"; // build the output string buffer.AppendFormat("{0}[TCPPacket: SourcePort={2}, DestinationPort={3}, Flags={4}]{1}", color, colorEscape, SourcePort, DestinationPort, flags); } if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored) { // collect the properties and their value Dictionary <string, string> properties = new Dictionary <string, string>(); properties.Add("source port", SourcePort.ToString()); properties.Add("destination port", DestinationPort.ToString()); properties.Add("sequence number", SequenceNumber.ToString() + " (0x" + SequenceNumber.ToString("x") + ")"); properties.Add("acknowledgement number", AcknowledgmentNumber.ToString() + " (0x" + AcknowledgmentNumber.ToString("x") + ")"); // TODO: Implement a HeaderLength property for TCPPacket //properties.Add("header length", HeaderLength.ToString()); properties.Add("flags", "(0x" + AllFlags.ToString("x") + ")"); string flags = Convert.ToString(AllFlags, 2).PadLeft(8, '0'); properties.Add("", flags[0] + "... .... = [" + flags[0] + "] congestion window reduced"); properties.Add(" ", "." + flags[1] + ".. .... = [" + flags[1] + "] ECN - echo"); properties.Add(" ", ".." + flags[2] + ". .... = [" + flags[2] + "] urgent"); properties.Add(" ", "..." + flags[3] + " .... = [" + flags[3] + "] acknowledgement"); properties.Add(" ", ".... " + flags[4] + "... = [" + flags[4] + "] push"); properties.Add(" ", ".... ." + flags[5] + ".. = [" + flags[5] + "] reset"); properties.Add(" ", ".... .." + flags[6] + ". = [" + flags[6] + "] syn"); properties.Add(" ", ".... ..." + flags[7] + " = [" + flags[7] + "] fin"); properties.Add("window size", WindowSize.ToString()); properties.Add("checksum", "0x" + Checksum.ToString() + " [" + (ValidChecksum ? "valid" : "invalid") + "]"); properties.Add("options", "0x" + BitConverter.ToString(Options).Replace("-", "").PadLeft(12, '0')); var parsedOptions = OptionsCollection; if (parsedOptions != null) { for (int i = 0; i < parsedOptions.Count; i++) { properties.Add("option" + (i + 1).ToString(), parsedOptions[i].ToString()); } } // calculate the padding needed to right-justify the property names int padLength = Utils.RandomUtils.LongestStringLength(new List <string>(properties.Keys)); // build the output string buffer.AppendLine("TCP: ******* TCP - \"Transmission Control Protocol\" - offset=? length=" + TotalPacketLength); buffer.AppendLine("TCP:"); foreach (var property in properties) { if (property.Key.Trim() != "") { buffer.AppendLine("TCP: " + property.Key.PadLeft(padLength) + " = " + property.Value); } else { buffer.AppendLine("TCP: " + property.Key.PadLeft(padLength) + " " + property.Value); } } buffer.AppendLine("TCP:"); } // append the base class output buffer.Append(base.ToString(outputFormat)); return(buffer.ToString()); }
public override string Description() { return("[" + SourcePort.ToString() + "] -> [" + DestPort.ToString() + "]" + " Seq: " + SequenceNumber.ToString() + " Ack: " + AcknowledgementNumber.ToString() + " WindowSize: " + WindowSize.ToString()); }