/// <summary> /// Manually searches for a <see cref="UIItem"/> in a container. /// </summary> /// <param name="container">The container.</param> /// <param name="automationId">The automation ID for the control.</param> /// <param name="log">The log object.</param> /// <returns>The control if it can be found; otherwise, <see langword="null" />.</returns> public static IUIItem FindItemManuallyInUIContainer(UIItemContainer container, string automationId, Log log) { const string logPrefix = "Controls - Find element manually"; log.Debug( logPrefix, string.Format( CultureInfo.InvariantCulture, "Searching for UI element with ID: [{0}].", automationId)); if ((container == null) || string.IsNullOrEmpty(automationId)) { return null; } var stack = new Stack<UIItemContainer>(); stack.Push(container); while (stack.Count > 0) { var localContainer = stack.Pop(); foreach (var element in localContainer.Items) { log.Debug( logPrefix, string.Format( CultureInfo.InvariantCulture, "Found UI item of type [{0}] with ID: [{1}]. Name: [{2}]", element.GetType().Name, element.Id, element.Name)); if (string.Equals(element.Id, automationId, StringComparison.Ordinal)) { log.Info( logPrefix, string.Format( CultureInfo.InvariantCulture, "Found desired element of type [{0}] with ID: [{1}]", element.GetType().Name, element.Id)); return element; } var subContainer = element as UIItemContainer; if (subContainer != null) { stack.Push(subContainer); } } } return null; }
static void Main(string[] args) { Log logInstance = new Log(); ProcessStartInfo start = new ProcessStartInfo(); for (int i = 0; i < args.Length; i++) { start.FileName = args[i]; try { using (Process proc = Process.Start(start)) logInstance.Message(String.Format("lanciato il processo : {0}", start.FileName.ToString())); } catch (Exception ex) { logInstance.Debug(ex.Message); } } }
protected void Page_Load(object sender, EventArgs e) { try { homeSeerApp = (hsapplication)Context.Items["Content"]; // Used for debugging in VS if (homeSeerApp == null) homeSeerApp = Global.homeSeerApp; if (homeSeerApp == null) throw new Exception("Error loading HomeSeer application object"); log = Log.GetInstance("HSPI_JJLATITUDE.Web.Distances", homeSeerApp); plugin = (HSPI)homeSeerApp.Plugin(App.PLUGIN_NAME); if (plugin == null) throw new Exception("Error getting a reference to the plug-in. Is it loaded and enabled?"); } catch (Exception ex) { Response.Write(ex.Message + ex.StackTrace); } log.Debug("Loading Distances web page"); // Inject HomeSeer HTML litHSHeader.Text = HomeSeer.GetHeadContent(homeSeerApp); litHSBody.Text = HomeSeer.GetBodyContent(homeSeerApp); litHSFooter.Text = HomeSeer.GetFooterContent(homeSeerApp); dsPeople.DataFile = Db.DbPath; dsPlaces.DataFile = Db.DbPath; dsDistances.DataFile = Db.DbPath; if (!IsPostBack) { } }
private static TextBox GetDatasetSummaryTextControl(Application application, Log log, int id) { const string prefix = "Project page - Get dataset summary control"; var tab = TabProxies.GetProjectPageTabItem(application, log); if (tab == null) { return null; } var textBoxId = string.Format( CultureInfo.InvariantCulture, "TextBox_[{0}_[DatasetId: [{1}]]]", DatasetViewAutomationIds.DatasetSummary, id); var textBoxSearchCriteria = SearchCriteria .ByAutomationId(textBoxId); return Retry.Times( () => { log.Debug(prefix, "Trying to get the dataset summary control."); var textBox = (TextBox)tab.Get(textBoxSearchCriteria); if (textBox == null) { log.Error(prefix, "Failed to get the dataset summary control."); } return textBox; }); }
public void Debug_ExceptionWithMessageFormat_MessageFormatNull() { LogManager.AddDebugListener(); var log = new Log(typeof (int)); var exception = new ArgumentNullException("log test"); log.Debug(exception, null, 1); }
public void Debug_ExceptionWithMessage_ExceptionNull() { LogManager.AddDebugListener(); var log = new Log(typeof (int)); ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => log.Debug(null, string.Empty)); }
public void Debug_MessageFormat() { LogManager.AddDebugListener(); var log = new Log(typeof (int)); LogMessageEventArgs eventArgs = null; log.LogMessage += (sender, e) => eventArgs = e; log.Debug("log message {0}", 1); Assert.IsNotNull(eventArgs); Assert.AreEqual(log, eventArgs.Log); Assert.AreEqual(LogEvent.Debug, eventArgs.LogEvent); Assert.AreEqual("log message 1", eventArgs.Message); }
public void CorrectlyLogsMessageWithBraces() { LogManager.AddDebugListener(); var log = new Log(typeof(int)); log.Debug("This is a string with { and sometimes and ending }"); }
private static string FindApolloInstallDirectoryInDefaultLocation(Log log) { const string prefix = "Application - Search install directory"; var expectedX64Path = string.Format( CultureInfo.InvariantCulture, @"c:\program files\{0}\{1}\{2}", CompanyInformation.CompanyNameInFilePath, ProductInformation.ProductNameInFilePath, VersionNumberPath()); if (Directory.Exists(expectedX64Path)) { return expectedX64Path; } log.Debug( prefix, string.Format( CultureInfo.InvariantCulture, "Failed to find application directory at: {0}.", expectedX64Path)); var expectedX86Path = string.Format( CultureInfo.InvariantCulture, @"c:\Program Files (x86)\{0}\{1}\{2}", CompanyInformation.CompanyNameInFilePath, ProductInformation.ProductNameInFilePath, VersionNumberPath()); if (Directory.Exists(expectedX86Path)) { return expectedX86Path; } log.Debug( prefix, string.Format( CultureInfo.InvariantCulture, "Failed to find application directory at: {0}.", expectedX86Path)); return null; }
public static ITabPage GetStartPageTabItem(Application application, Log log) { const string prefix = "Tabs - Get start page"; var tab = GetMainTab(application, log); if (tab == null) { return null; } try { log.Debug(prefix, "Trying to get the 'Start page' tab item."); var startPage = tab.Pages.FirstOrDefault(p => string.Equals(WelcomeViewAutomationIds.Header, p.Id)); if (startPage == null) { log.Error(prefix, "Failed to get the 'Start page' tab item."); } return startPage; } catch (Exception) { return null; } }
/// <summary> /// Returns the tab control in the main window of the application. /// </summary> /// <param name="application">The application.</param> /// <param name="log">The log object.</param> /// <returns>The tab control in the main window of the application.</returns> public static Tab GetMainTab(Application application, Log log) { const string prefix = "Tabs - Get main tab control"; var mainWindow = DialogProxies.MainWindow(application, log); if (mainWindow == null) { return null; } var tabSearchCriteria = SearchCriteria .ByAutomationId(ShellAutomationIds.Tabs); return Retry.Times( () => { log.Debug(prefix, "Trying to get the main tab control."); var tab = (Tab)mainWindow.Get(tabSearchCriteria); if (tab == null) { log.Error(prefix, "Failed to get the main tab control."); } return tab; }); }
/// <summary> /// Manually searches for a <see cref="UIItem"/> in a container. /// </summary> /// <param name="container">The container.</param> /// <param name="automationId">The partial automation ID for the control.</param> /// <param name="log">The log object.</param> /// <returns>A collection containing all the controls that have an automation ID that matches the partial ID.</returns> public static IEnumerable<IUIItem> FindItemsManuallyInUIContainerWithPartialId(UIItemContainer container, string automationId, Log log) { const string logPrefix = "Controls - Find element manually with partial ID"; log.Debug( logPrefix, string.Format( CultureInfo.InvariantCulture, "Searching for UI element with partial ID: [{0}].", automationId)); var result = new List<IUIItem>(); if ((container == null) || string.IsNullOrEmpty(automationId)) { return result; } var stack = new Stack<UIItemContainer>(); stack.Push(container); while (stack.Count > 0) { var localContainer = stack.Pop(); foreach (var element in localContainer.Items) { log.Debug( logPrefix, string.Format( CultureInfo.InvariantCulture, "Found UI item of type [{0}] with ID: [{1}]. Name: [{2}]", element.GetType().Name, element.Id, element.Name)); if ((!string.IsNullOrEmpty(element.Id)) && element.Id.Contains(automationId)) { log.Info( logPrefix, string.Format( CultureInfo.InvariantCulture, "Found matching element of type [{0}] with ID: [{1}]", element.GetType().Name, element.Id)); result.Add(element); } var subContainer = element as UIItemContainer; if (subContainer != null) { stack.Push(subContainer); } } } return result; }
private static void SelectMachineForDatasetActivation(Application application, Log log) { const string prefix = "Project page - Machine selection"; var dialog = DialogProxies.DatasetMachineSelectionWindow(application, log); if (dialog == null) { throw new RegressionTestFailedException(prefix + " - Failed to get the machine selection window."); } var listSearchCriteria = SearchCriteria .ByAutomationId(MachineSelectorViewAutomationIds.AvailableMachines); var list = Retry.Times( () => { log.Debug(prefix, "Trying to get available machines list."); var listBox = dialog.Get<ListBox>(listSearchCriteria); if (listBox == null) { log.Error(prefix, "Failed to get the available machines list."); } return listBox; }); if (list == null) { list = (ListBox)ControlProxies.FindItemManuallyInUIContainer( dialog, MachineSelectorViewAutomationIds.AvailableMachines, log); if (list == null) { throw new RegressionTestFailedException(prefix + " - Failed to get the available machines list."); } } // Find the item that matches the current machine var item = list.Items.Find(i => string.Equals(Environment.MachineName, i.Text)); if (item == null) { log.Debug( prefix, string.Format( CultureInfo.InvariantCulture, "Expected machine with name [{0}] but found following machines: [{1}]", Environment.MachineName, list.Items.Aggregate( string.Empty, (c, i) => { var next = string.Format( CultureInfo.InvariantCulture, "; [{0}]", i.Text); return c + next; }))); throw new RegressionTestFailedException(prefix + " - Failed to get the item for the current machine."); } item.Select(); var buttonSearchCriteria = SearchCriteria .ByAutomationId(MachineSelectorViewAutomationIds.ConfirmSelection); var confirmButton = Retry.Times( () => { log.Debug(prefix, "Trying to get confirm button."); var button = dialog.Get<Button>(buttonSearchCriteria); if (button == null) { log.Error(prefix, "Failed to get the confirm button."); } return button; }); if (confirmButton == null) { confirmButton = (Button)ControlProxies.FindItemManuallyInUIContainer( dialog, MachineSelectorViewAutomationIds.ConfirmSelection, log); if (confirmButton == null) { throw new RegressionTestFailedException(prefix + " - Failed to get the machine selection confirm button."); } } try { confirmButton.Click(); } catch (Exception e) { throw new RegressionTestFailedException(prefix + " - Failed to confirm the machine selection.", e); } }
private static TextBox GetProjectSummaryTextControl(Application application, Log log) { const string prefix = "Project page - Get project summary control"; var tab = TabProxies.GetProjectPageTabItem(application, log); if (tab == null) { return null; } var projectSummarySearchCriteria = SearchCriteria .ByAutomationId(ProjectViewAutomationIds.ProjectSummary); return Retry.Times( () => { log.Debug(prefix, "Trying to get the project summary control."); var textBox = (TextBox)tab.Get(projectSummarySearchCriteria); if (textBox == null) { log.Error(prefix, "Failed to get the project summary control."); } return textBox; }); }
private static Label GetProjectDatasetCountControl(Application application, Log log) { const string prefix = "Project page - Get dataset count control"; var tab = TabProxies.GetProjectPageTabItem(application, log); if (tab == null) { return null; } var datasetCountSearchCriteria = SearchCriteria .ByAutomationId(ProjectViewAutomationIds.DatasetCount); return Retry.Times( () => { log.Debug(prefix, "Trying to get the dataset count control."); var label = (Label)tab.Get(datasetCountSearchCriteria); if (label == null) { log.Error(prefix, "Failed to get the dataset count control."); } return label; }); }
/// <summary> /// Returns the main menu of the application. /// </summary> /// <param name="application">The application.</param> /// <param name="log">The log object.</param> /// <returns>The main menu of the application.</returns> public static MenuBar GetMainMenu(Application application, Log log) { const string prefix = "Menus - Get main menu"; var mainWindow = DialogProxies.MainWindow(application, log); if (mainWindow == null) { return null; } var menuSearchCriteria = SearchCriteria .ByAutomationId(MainMenuAutomationIds.Menu) .AndControlType(ControlType.Menu); return Retry.Times( () => { log.Debug(prefix, "Trying to get main menu."); var menu = (MenuBar)mainWindow.Get(menuSearchCriteria); if (menu == null) { log.Error(prefix, "Failed to get the main menu."); } return menu; }); }
protected void Page_Load(object sender, EventArgs e) { try { homeSeerApp = (hsapplication)Context.Items["Content"]; // Used for debugging in VS if (homeSeerApp == null) homeSeerApp = Global.homeSeerApp; if (homeSeerApp == null) throw new Exception("Error loading HomeSeer application object"); plugin = (HSPI)homeSeerApp.Plugin(App.PLUGIN_NAME); if (plugin == null) throw new Exception("Error getting a reference to the plug-in. Is it loaded and enabled?"); } catch (Exception ex) { Response.Write(ex.Message + ex.StackTrace); } log = Log.GetInstance("HSPI_JJLATITUDE.Web.Config", homeSeerApp); if (!IsPostBack) { log.Debug("Loading Config page"); // Inject HomeSeer HTML litHSHeader.Text = HomeSeer.GetHeadContent(homeSeerApp); litHSBody.Text = HomeSeer.GetBodyContent(homeSeerApp); litHSFooter.Text = HomeSeer.GetFooterContent(homeSeerApp); try { lstLogLevel.SelectedValue = AppConfig.Read("Main", "LogLevel"); } catch (Exception) { log.Error("Error reading config value: LogLevel"); } try { lstUpdateFreq.SelectedValue = AppConfig.Read("Main", "UpdateFrequency"); } catch (Exception) { log.Error("Error reading config value: UpdateFrequency"); } try { chkLogFile.Checked = Convert.ToBoolean(AppConfig.Read("Main", "LogToFile")); } catch (Exception) { log.Error("Error reading config value: LogToFile"); } try { chkLogHomeSeer.Checked = Convert.ToBoolean(AppConfig.Read("Main", "LogToHomeSeer")); } catch (Exception) { log.Error("Error reading config value: LogToHomeSeer"); } } // (!IsPostBack) }
public void Debug_Message() { LogManager.RegisterDebugListener(); var log = new Log(typeof(int)); LogMessageEventArgs eventArgs = null; log.LogMessage += (sender, e) => eventArgs = e; log.Debug("log message"); Assert.IsNotNull(eventArgs); Assert.AreEqual(log, eventArgs.Log); Assert.AreEqual(LogEvent.Debug, eventArgs.LogEvent); Assert.AreEqual("[System.Int32] log message", eventArgs.Message); }
public void TestMethod1() { Log4NetInit.Init(AppDomain.CurrentDomain.BaseDirectory + "log4net.config"); ILog log = new Log(); log.Debug("test"); }
public void Debug_MessageFormat_Null() { LogManager.RegisterDebugListener(); var log = new Log(typeof(int)); ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => log.Debug((string)null, null)); }
private static string FindApolloInstallDirectoryInRegistry(Log log) { var keyPath = string.Format( CultureInfo.InvariantCulture, @"software\{0}\{1}\{2}", CompanyInformation.CompanyNameInFilePath, ProductInformation.ProductNameInFilePath, VersionNumberPath()); var key = Registry.LocalMachine.OpenSubKey(keyPath); if (key == null) { log.Debug( "Application - Search registry", string.Format( CultureInfo.InvariantCulture, "Failed to find registry path at: {0}.", keyPath)); return null; } return (string)key.GetValue(Constants.GetInstallLocationRegistryKeyName()); }
public void Debug_Exception() { LogManager.RegisterDebugListener(); var log = new Log(typeof(int)); LogMessageEventArgs eventArgs = null; log.LogMessage += (sender, e) => eventArgs = e; var exception = new ArgumentNullException("log test"); log.Debug(exception); Assert.IsNotNull(eventArgs); Assert.AreEqual(log, eventArgs.Log); Assert.AreEqual(LogEvent.Debug, eventArgs.LogEvent); Assert.AreEqual(string.Format("[System.Int32] {0}\r\nParameter name: log test", ArgumentNullExceptionText), eventArgs.Message); }
public void Debug_MessageFormat_Null() { LogManager.AddDebugListener(); var log = new Log(typeof (int)); log.Debug((string) null, null); }
public void Debug_ExceptionWithMessageFormat_MessageFormatNull() { LogManager.RegisterDebugListener(); var log = new Log(typeof(int)); var exception = new ArgumentNullException("log test"); ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => log.Debug(exception, null, 1)); }
public void Debug_Exception_Null() { LogManager.AddDebugListener(); var log = new Log(typeof (int)); ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => log.Debug((Exception) null)); }
public TestResult VerifyWelcomeTab(Application application, Log log) { const string prefix = "Welcome tab"; var result = new TestResult(); var assert = new Assert(result, log); try { var startPage = TabProxies.GetStartPageTabItem(application, log); if (startPage == null) { log.Info(prefix, "Opening start page."); MenuProxies.SwitchToStartPageViaViewStartPageMenuItem(application, log); } startPage = TabProxies.GetStartPageTabItem(application, log); if (startPage == null) { var message = "Failed to get the start page."; log.Error(prefix, message); result.AddError(prefix + " - " + message); return result; } try { if (!startPage.IsSelected) { log.Info(prefix, "Setting focus to start page."); startPage.Select(); } } catch (Exception e) { var message = string.Format( CultureInfo.InvariantCulture, "Failed to select the start page tab. Error was: {0}", e); log.Error(prefix, message); result.AddError(prefix + " - " + message); return result; } var applicationNameSearchCiteria = SearchCriteria .ByAutomationId(WelcomeViewAutomationIds.ApplicationName); var nameLabel = Retry.Times( () => { log.Debug(prefix, "Trying to get the application name label."); var label = (Label)startPage.Get(applicationNameSearchCiteria); if (label == null) { log.Error(prefix, "Failed to find the application name label."); } return label; }); if (nameLabel == null) { var message = "Failed to get the application name label."; log.Error(prefix, message); result.AddError(prefix + " - " + message); return result; } var nameText = nameLabel.Text; assert.AreEqual(ProductInformation.ProductName, nameText, prefix + " - Product Name"); } catch (RegressionTestFailedException e) { var message = string.Format( CultureInfo.InvariantCulture, "Failed with exception. Error: {0}", e); log.Error(prefix, message); result.AddError(prefix + " - " + message); } return result; }
public void Debug_ExceptionWithMessageFormat_ExceptionNull() { LogManager.AddDebugListener(); var log = new Log(typeof (int)); ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => log.Debug(null, "additional message", 1)); }
/// <summary> /// Returns the 'File- New' menu item. /// </summary> /// <param name="application">The application.</param> /// <param name="log">The log object.</param> /// <returns>The 'File - New' menu item.</returns> public static Menu GetFileNewMenuItem(Application application, Log log) { const string prefix = "Menus - Get 'File - New' menu"; var menu = GetMainMenu(application, log); if (menu == null) { return null; } var fileMenuSearchCriteria = SearchCriteria.ByAutomationId(MainMenuAutomationIds.File); var newSearchCriteria = SearchCriteria.ByAutomationId(MainMenuAutomationIds.FileNew); return Retry.Times( () => { log.Debug(prefix, "Trying to get the 'File - New' menu item."); var menuItem = menu.MenuItemBy(fileMenuSearchCriteria, newSearchCriteria); if (menuItem == null) { log.Error(prefix, "Failed to find the 'File - New' menu item."); } return menuItem; }); }
public void Debug_ExceptionWithMessageFormat() { LogManager.AddDebugListener(); var log = new Log(typeof (int)); LogMessageEventArgs eventArgs = null; log.LogMessage += (sender, e) => eventArgs = e; var exception = new ArgumentNullException("log test"); log.Debug(exception, "additional message {0}", 1); Assert.IsNotNull(eventArgs); Assert.AreEqual(log, eventArgs.Log); Assert.AreEqual(LogEvent.Debug, eventArgs.LogEvent); Assert.AreEqual(string.Format("additional message 1 | {0}\r\nParameter name: log test", ArgumentNullExceptionText), eventArgs.Message); }
/// <summary> /// Checks the 'Keep welcome page open' checkbox. /// </summary> /// <param name="application">The application.</param> /// <param name="log">The log object.</param> /// <exception cref="RegressionTestFailedException"> /// Thrown if the 'Keep welcome page open' checkbox could not be checked for some reason. /// </exception> public static void CheckCloseWelcomePageOnProjectOpen(Application application, Log log) { const string prefix = "Welcome page - Check close welcome page on project open"; var startPage = TabProxies.GetStartPageTabItem(application, log); if (startPage == null) { MenuProxies.SwitchToStartPageViaViewStartPageMenuItem(application, log); } startPage = TabProxies.GetStartPageTabItem(application, log); if (startPage == null) { throw new RegressionTestFailedException(prefix + ": Failed to get start page."); } try { if (!startPage.IsSelected) { log.Debug(prefix, "Selecting start page."); startPage.Select(); } } catch (Exception e) { throw new RegressionTestFailedException( prefix + ": Failed to select the start page", e); } // Check 'keep open' flag var closePageSearchCriteria = SearchCriteria .ByAutomationId(WelcomeViewAutomationIds.ClosePageAfterLoad) .AndControlType(ControlType.CheckBox); var closePageCheckBox = Retry.Times( () => { log.Debug(prefix, "Trying to get checkbox."); var checkBox = (CheckBox)startPage.Get(closePageSearchCriteria); if (checkBox == null) { log.Error(prefix, "Failed to get checkbox."); } return checkBox; }); if (closePageCheckBox == null) { closePageCheckBox = (CheckBox)ControlProxies.FindItemManuallyInUIContainer( startPage as UIItemContainer, WelcomeViewAutomationIds.ClosePageAfterLoad, log); if (closePageCheckBox == null) { throw new RegressionTestFailedException(prefix + ": Failed to get checkbox."); } } try { if (!closePageCheckBox.Checked) { log.Debug(prefix, "Checking 'Close welcome page on project open' checkbox."); closePageCheckBox.Checked = true; } } catch (Exception e) { throw new RegressionTestFailedException( prefix + ": Failed to check the 'Keep start page open' checkbox.", e); } }