private void CreateCert_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); DateTime validFrom = DateTime.Today.AddDays(-1); //from yesterday, in case server we might want to use it on is still within the previous calendar day DateTime validTo = new DateTime(9999, 12, 31); //dont ever expire. var windowCentre = WindowGeometry.WindowCentre(this); var inputPrompt = "Name of this identity that will be visible to servers as the certificate 'Common Name'. For example you can use your name/username. " + "\n\nDo not include any sensitive information, such as a password."; string commonName = Interaction.InputBox(inputPrompt, "Name of the identity/certificate", "", windowCentre.Item1, windowCentre.Item2); if (commonName == "") { //user pressed cancel or left it empty ToastNotify("Identity certificate creation abandoned - identity name was not provided", ToastMessageStyles.Warning); return; } var cert = CertificateCreator.GenSelfSignedCert(commonName, validFrom, validTo); var fileBase = CleanFileName(commonName).Trim(); if (fileBase.Length > 20) { fileBase = fileBase.Substring(0, 20); } //make a filename based on the common name and thumbprint fileBase = fileBase + "_" + cert.Thumbprint.Substring(0, 6) + ".pfx"; //Foo_ABC1.pfx, with forbidden chars removed var settings = new UserSettings(); var certBytes = cert.Export(X509ContentType.Pfx); //save with no password var certFile = Path.Combine(settings.ClientCertificatesFolder, fileBase); using (FileStream fileStream = new FileStream(certFile, FileMode.Create)) { for (int i = 0; i < certBytes.Length; i++) { fileStream.WriteByte(certBytes[i]); } fileStream.Seek(0, SeekOrigin.Begin); fileStream.Close(); } ToastNotify("Certificate created and saved in user profile", ToastMessageStyles.Success); //load the cert var certManager = Session.Instance.CertificatesManager; certManager.AddCertificate(cert); ToastNotify("Certificate loaded - select it on in the menu to use it on any site"); BuildCertsMenu(); }
public void geometry_specified(string option, BrowserWindowState expectedBrowserWindowState, int expectedWidth, int expectedHeight) { WindowGeometry windowGeometry = ArgOptions.ParseWindowGeometry(option); windowGeometry.ShouldNotBeNull(); windowGeometry.State.ShouldEqual(expectedBrowserWindowState); windowGeometry.Size.Width = expectedWidth; windowGeometry.Size.Height = expectedHeight; }
public void Should_determine_minimized_correctly() { var windowGeometry = new WindowGeometry { State = BrowserWindowState.Minimized }; windowGeometry.ShouldShowWindow.ShouldBeFalse(); }
public IEnumerable <IWebBrowser> CreateWebBrowsers() { var statLightConfiguration = _currentStatLightConfiguration.Current; WebBrowserType webBrowserType = statLightConfiguration.Client.WebBrowserType; string queryString = statLightConfiguration.Server.QueryString; bool forceBrowserStart = statLightConfiguration.Server.ForceBrowserStart; WindowGeometry windowGeometry = statLightConfiguration.Client.WindowGeometry; int numberOfBrowserHosts = statLightConfiguration.Client.NumberOfBrowserHosts; var testPageUrlWithQueryString = new Uri(_webServerLocation.TestPageUrl + "?" + queryString); _logger.Debug("testPageUrlWithQueryString = " + testPageUrlWithQueryString); List <IWebBrowser> webBrowsers = Enumerable .Range(1, numberOfBrowserHosts) .Select(browserI => Create(webBrowserType, testPageUrlWithQueryString, forceBrowserStart, numberOfBrowserHosts > 1, windowGeometry)) .ToList(); return(webBrowsers); }
public ArgOptions(string[] args) { MethodsToTest = new Collection <string>(); _optionSet = GetOptions(); NumberOfBrowserHosts = 1; _args = args; WindowGeometry = new WindowGeometry(); List <string> extra; try { extra = _optionSet.Parse(_args); } catch (OptionException e) { System.Console.Write("Error parsing arguments: "); System.Console.WriteLine(e.Message); System.Console.WriteLine("Try --help' for more information."); } }
public SelfHostedWebBrowser(ILogger logger, Uri pageToHost, bool browserVisible, WindowGeometry windowGeometry) { if (logger == null) { throw new ArgumentNullException("logger"); } if (pageToHost == null) { throw new ArgumentNullException("pageToHost"); } if (windowGeometry == null) { throw new ArgumentNullException("windowGeometry"); } _logger = logger; _pageToHost = pageToHost; _browserVisible = browserVisible; _windowGeometry = windowGeometry; }
public IEnumerable <IWebBrowser> CreateWebBrowsers() { var statLightConfiguration = _currentStatLightConfiguration.Current; WebBrowserType webBrowserType = statLightConfiguration.Client.WebBrowserType; string queryString = statLightConfiguration.Server.QueryString; bool forceBrowserStart = statLightConfiguration.Server.ForceBrowserStart; WindowGeometry windowGeometry = statLightConfiguration.Client.WindowGeometry; int numberOfBrowserHosts = statLightConfiguration.Client.NumberOfBrowserHosts; var testPageUrlWithQueryString = new Uri(_webServerLocation.TestPageUrl + "?" + queryString); Func <int, IWebBrowser> webBrowserFactoryHelper; if (statLightConfiguration.Server.IsPhoneRun) { webBrowserFactoryHelper = instanceId => { Func <byte[]> hostXap = statLightConfiguration.Server.HostXap; return(CreatePhone(hostXap)); }; } else { webBrowserFactoryHelper = instanceId => Create(webBrowserType, testPageUrlWithQueryString, forceBrowserStart, numberOfBrowserHosts > 1, windowGeometry); } _logger.Debug("testPageUrlWithQueryString = " + testPageUrlWithQueryString); List <IWebBrowser> webBrowsers = Enumerable .Range(1, numberOfBrowserHosts) .Select(browserI => webBrowserFactoryHelper(browserI)) .ToList(); return(webBrowsers); }
public IWebBrowser Create(WebBrowserType browserType, Uri pageToHost, bool forceBrowserStart, bool isStartingMultipleInstances, WindowGeometry windowGeometry) { if (windowGeometry == null) { throw new ArgumentNullException("windowGeometry"); } switch (browserType) { case WebBrowserType.SelfHosted: return(new SelfHostedWebBrowser(_logger, pageToHost, windowGeometry.ShouldShowWindow, windowGeometry)); case WebBrowserType.Firefox: return(new FirefoxWebBrowser(_logger, pageToHost, forceBrowserStart, isStartingMultipleInstances)); case WebBrowserType.Chrome: return(new ChromeWebBrowser(_logger, pageToHost, forceBrowserStart, isStartingMultipleInstances)); } throw new NotImplementedException(); }
internal static WindowGeometry ParseWindowGeometry(string input) { if (string.IsNullOrEmpty(input)) { return new WindowGeometry { State = BrowserWindowState.Normal } } ; input = input.Trim().Replace("'", string.Empty).Replace("\"", string.Empty); var geometry = new WindowGeometry { State = BrowserWindowState.Normal, }; const string pattern = "(Maximized|Minimized|maximized|minimized|Normal|normal|M|m|N)?(([0-9]+)x([0-9]+))?"; var matches = Regex.Match(input, pattern); if (matches.Groups.Count != 5) { throw new StatLightException("If specifying the geometry it must be 'WIDTHxHEIGHT'"); } var stateFlag = matches.Groups[1].Value; switch (stateFlag) { case "": break; // leave the default case "M": case "Maximized": case "maximized": geometry.State = BrowserWindowState.Maximized; break; case "m": case "Minimized": case "minimized": geometry.State = BrowserWindowState.Minimized; break; case "N": case "Normal": case "normal": geometry.State = BrowserWindowState.Normal; break; default: throw new StatLightException("Unknown browser state flag [{0}]. Try specifying either [M|m|N] for [Maximized|minimized|Normal]".FormatWith(stateFlag)); } var widthString = matches.Groups[3].Value; var heightString = matches.Groups[4].Value; if (!string.IsNullOrEmpty(widthString) || !string.IsNullOrEmpty(heightString)) { int width; int height; if (!int.TryParse(widthString, out width) || !int.TryParse(heightString, out height) || width < 1 || height < 1) { throw new Exception("Width and height in geometry must be positive integers. (We parsed width[{0}] and height[{1}])".FormatWith(widthString, heightString)); } geometry.Size = new WindowSize(width, height); } return(geometry); }