Exemplo n.º 1
0
        public object monitorFields()
        {
            //Thi array should be a data table
            //unique key, window name (regex), elementID, text value to match, action to take if matched, class, function, unique key that must have fired prior (if applicable)
            string[,] fieldValueActions = { { "00000", "Login - WinSCP", Properties.Settings.Default.WinSCP_HostName_FieldID.ToString(), "test",       "Madge.Automation_Library.WinSCP_Automation", "GetHostName", "" },
                                            { "00001", "Login - WinSCP", Properties.Settings.Default.WinSCP_HostName_FieldID.ToString(), "(alpha)",    "Madge.Automation_Library.WinSCP_Automation", "GetHostName", "" },
                                            { "00002", "Login - WinSCP", Properties.Settings.Default.WinSCP_HostName_FieldID.ToString(), "(username)", "Madge.Automation_Library.WinSCP_Automation", "SetUsername", "" },
                                            { "00003", "Login - WinSCP", Properties.Settings.Default.WinSCP_HostName_FieldID.ToString(), "(add note)", "Madge.Automation_Library.WinSCP_Automation", "addNote",     "" } };

            //Instantiate custom UIAutomation functions
            var uiAutomator = new UIAutomation.UIAutomation_Functions();

            //infinite loop
            bool x = true;

            do
            {
                //for each node, check fields
                for (int i = 0; i < fieldValueActions.GetLength(0); i += 1)
                {
                    //Get Automation Element for Advanced Settings button
                    AutomationElement fieldElement = uiAutomator.GetElementbyID(fieldValueActions[i, 1], fieldValueActions[i, 2]);


                    if (fieldElement == null)
                    {
                        //control not found, exit for
                        break;

                        throw new InvalidOperationException("Could not find result box");
                    }

                    //string fieldVal = fieldElement.Current.Name;
                    Match match = Regex.Match(fieldElement.Current.Name, @fieldValueActions[i, 3], RegexOptions.IgnoreCase);

                    // Here we check the Match instance.
                    if (match.Success)
                    {
                        //if there is an event dependency for this match, check if it has not fired. Otherwise, invoke and log.
                        //Event_Memory.eventSafetyFire will automatically return false if dependency is blank
                        if (Event_Memory.eventSafetyFire(fieldValueActions[i, 0], fieldValueActions[i, 6]) == true)
                        {
                            //invoke automation call if there is a match on the field value
                            Invoke(fieldValueActions[i, 4], fieldValueActions[i, 5]);
                            Console.WriteLine("executing " + fieldValueActions[i, 4] + "." + fieldValueActions[i, 5]);
                            Event_Memory.addEventToMemory(fieldValueActions[i, 0], "");
                        }
                    }

                    //Console.WriteLine(fieldElement.Current.Name);
                }
            } while (x = true);


            return(null);
        }
        /// <summary>
        /// Insert string into username field
        /// </summary>
        /// <param name="username">user id</param>
        /// <returns></returns>
        public string SetUsername()
        {
            //Instantiate custom UIAutomation functions
            var uiAutomator = new UIAutomation.UIAutomation_Functions();

            //Get Automation Element for Username field
            AutomationElement usernameField = uiAutomator.GetElementbyID("Login - WinSCP", Properties.Settings.Default.WinSCP_Username_FieldID.ToString());

            //Insert username into field
            uiAutomator.InsertTextUsingUIAutomation(usernameField, "userID");

            return("Username field set to userID.");
        }
        public string addNote()
        {
            //Ask user if they want to add a note, politely!
            Console.WriteLine("I think you might be trying to add a note. Would you like assistance? (y/n)");
            string respondIndicator = Console.ReadLine();

            var languageIntepreter = new Language_Interpreter();

            //check if response was affirmative. If not, exit (and eventually log the event to a database)
            if (languageIntepreter.CheckForAffirmative(respondIndicator) == false)
            {
                return("Looks like I was wrong. Sorry.");
            }

            //Prompt user for what they want to put into the notes, in a semi-uniform fashion.
            Console.WriteLine("What's the title of your note?");
            Console.WriteLine("");
            string noteText = "Title: " + Console.ReadLine();

            Console.WriteLine("Describe the note.");
            Console.WriteLine("");
            noteText += System.Environment.NewLine + "Description: " + Console.ReadLine();

            //Instantiate custom UIAutomation functions
            var uiAutomator = new UIAutomation.UIAutomation_Functions();

            //Get Automation Element for Advanced Settings button
            AutomationElement advancedButton = uiAutomator.GetElementbyID("Login - WinSCP", Properties.Settings.Default.WinSCP_AdvancedButton_FieldID.ToString());

            System.Windows.Point p = advancedButton.GetClickablePoint();
            //Click the button where it lays!
            SetCursorPosition(p.X, p.Y);
            MouseEvent(MouseEventFlags.LeftDown);
            MouseEvent(MouseEventFlags.LeftUp);

            //Move to Notes section and paste. This could be done using UIAutomation, but I'm not there yet...
            uiAutomator.sendKeysToApp("N");
            uiAutomator.sendKeysToApp("{TAB}");
            uiAutomator.sendKeysToApp(noteText);

            return("Clickety clack");
        }
        public object GetHostName()
        {
            //Uncomment if you need to start a new process
            //_WinSCPProcess = Process.Start("WinSCP.exe");

            //Instantiate custom UIAutomation functions
            var uiAutomator = new UIAutomation.UIAutomation_Functions();

            AutomationElement _resultTextBoxAutomationElement = uiAutomator.GetElementbyID("Login - WinSCP", Properties.Settings.Default.WinSCP_HostName_FieldID.ToString());

            if (_resultTextBoxAutomationElement == null)
            {
                throw new InvalidOperationException("Could not find result box");
            }

            string fieldVal = _resultTextBoxAutomationElement.Current.Name;

            Console.WriteLine(fieldVal);

            return(fieldVal);
        }