Example #1
0
        private static void OnElement(AutomationElement element)
        {
            element.Focus();

            switch (element.ControlType)
            {
            case ControlType.AppBar:
                break;

            case ControlType.Button:
                element.AsButton().DoubleClick();
                break;

            case ControlType.Calendar:
                break;

            case ControlType.CheckBox:
                break;

            case ControlType.ComboBox:
                break;

            case ControlType.Custom:
                break;

            case ControlType.DataGrid:
                break;

            case ControlType.DataItem:
                break;

            case ControlType.Document:
                break;

            case ControlType.Edit:
                break;

            case ControlType.Group:
                break;

            case ControlType.Header:
                break;

            case ControlType.HeaderItem:
                break;

            case ControlType.Hyperlink:
                break;

            case ControlType.Image:
                break;

            case ControlType.List:
                break;

            case ControlType.ListItem:
                element.AsListBoxItem().DoubleClick();
                break;

            case ControlType.MenuBar:
                element.AsMenu().DoubleClick();
                break;

            case ControlType.Menu:
                element.AsMenu().DoubleClick();
                break;

            case ControlType.MenuItem:
                element.AsMenuItem().DoubleClick();
                break;

            case ControlType.Pane:
                break;

            case ControlType.ProgressBar:
                break;

            case ControlType.RadioButton:
                element.AsRadioButton().DoubleClick();
                break;

            case ControlType.ScrollBar:
                break;

            case ControlType.SemanticZoom:
                break;

            case ControlType.Separator:
                break;

            case ControlType.Slider:
                break;

            case ControlType.Spinner:
                break;

            case ControlType.SplitButton:
                break;

            case ControlType.StatusBar:
                break;

            case ControlType.Tab:
                break;

            case ControlType.TabItem:
                element.AsTabItem().DoubleClick();
                break;

            case ControlType.Table:
                break;

            case ControlType.Text:
                break;

            case ControlType.Thumb:
                break;

            case ControlType.TitleBar:
                element.AsTitleBar().DoubleClick();
                break;

            case ControlType.ToolBar:
                break;

            case ControlType.ToolTip:
                break;

            case ControlType.Tree:
                element.AsTree().DoubleClick();
                break;

            case ControlType.TreeItem:
                element.AsTreeItem().DoubleClick();
                break;

            case ControlType.Window:
                break;

            default:
                element.DoubleClick();
                break;
            }
        }
Example #2
0
        public void Compose(string[] images, Action <string> onEvent = null, Action <int> onProgress = null)
        {
            string[] lines = System.IO.File.ReadAllLines(@"C:\Projects\ICEAutomation\parameters.txt");
            IDictionary <string, string> parameters = new Dictionary <string, string>();

            foreach (string line in lines)
            {
                string[] words = line.Split('=');
                if (words.Count() > 1)
                {
                    parameters.Add(words[0], words[1]);
                }
            }
            this.onEvent    = onEvent;
            this.onProgress = onProgress;
            var appStr  = parameters["ice-app-path"];
            var appName = Path.GetFileName(appStr);

            var structuredPanoramaBtnLabel   = ConfigurationManager.AppSettings["Structured-panorama-btn-label"];
            var primaryDirectionCountTextBox = ConfigurationManager.AppSettings["Primary-direction-count-text-box"];

            var startTopLeftHelpText     = ConfigurationManager.AppSettings["Start-top-left-help-text"];
            var startTopRightHelpText    = ConfigurationManager.AppSettings["Start-top-right-help-text"];
            var startBottomLeftHelpText  = ConfigurationManager.AppSettings["Start-bottom-left-help-text"];
            var startBottomRightHelpText = ConfigurationManager.AppSettings["Start-bottom-right-help-text"];

            var moveRightHelpText = ConfigurationManager.AppSettings["Start-moving-right-help-text"];
            var moveLeftHelpText  = ConfigurationManager.AppSettings["Start-moving-left-help-text"];
            var moveUpHelpText    = ConfigurationManager.AppSettings["Start-moving-up-help-text"];
            var moveDownHelpText  = ConfigurationManager.AppSettings["Start-moving-down-help-text"];

            var cornerHelpText    = startBottomLeftHelpText;
            var directionHelpText = moveRightHelpText;

            if (parameters["start-upper-left-corner"] == "1")
            {
                cornerHelpText = startTopLeftHelpText;

                if (parameters["move-right"] == "1")
                {
                    directionHelpText = moveRightHelpText;
                }
                else if (parameters["move-down"] == "1")
                {
                    directionHelpText = moveDownHelpText;
                }
            }
            else if (parameters["start-upper-right-corner"] == "1")
            {
                cornerHelpText = startTopRightHelpText;

                if (parameters["move-left"] == "1")
                {
                    directionHelpText = moveLeftHelpText;
                }
                else if (parameters["move-down"] == "1")
                {
                    directionHelpText = moveDownHelpText;
                }
            }
            else if (parameters["start-bottom-right-corner"] == "1")
            {
                cornerHelpText = startBottomRightHelpText;

                if (parameters["move-left"] == "1")
                {
                    directionHelpText = moveLeftHelpText;
                }
                else if (parameters["move-up"] == "1")
                {
                    directionHelpText = moveUpHelpText;
                }
            }
            else
            {
                cornerHelpText = startBottomLeftHelpText;

                if (parameters["move-right"] == "1")
                {
                    directionHelpText = moveRightHelpText;
                }
                else if (parameters["move-up"] == "1")
                {
                    directionHelpText = moveUpHelpText;
                }
            }

            var serpentineBtnLabel = ConfigurationManager.AppSettings["Serpentine-btn-label"];
            var zigZagBtnLabel     = ConfigurationManager.AppSettings["Zig-zag-btn-label"];

            var angularRangeBtnLabel = ConfigurationManager.AppSettings["Less-than-360-angular-range-btn-label"];

            if (parameters["360-horizontal-angular-range"] == "1")
            {
                angularRangeBtnLabel = ConfigurationManager.AppSettings["360-horizontal-btn-label"];
            }
            else if (parameters["360-vertical-angular-range"] == "1")
            {
                angularRangeBtnLabel = ConfigurationManager.AppSettings["360-vertical-btn-label"];
            }

            var horizontalOverlapTextBox = ConfigurationManager.AppSettings["Horizontal-overlap-text-box"];
            var verticalOverlapTextBox   = ConfigurationManager.AppSettings["Vertical-overlap-text-box"];
            var searchRadiusTextBox      = ConfigurationManager.AppSettings["Search-radius-text-box"];

            var exportBtnLabel         = ConfigurationManager.AppSettings["Export-btn-label"];
            var exportToDiskBtnLabel   = ConfigurationManager.AppSettings["ExportToDisk-btn-label"];
            var exportPanoramaBtnLabel = ConfigurationManager.AppSettings["ExportPanorama-btn-label"];
            var saveBtnLabel           = ConfigurationManager.AppSettings["Save-btn-label"];
            int saveWait = int.Parse(ConfigurationManager.AppSettings["Save-wait"]);

            var imgStr           = string.Join(" ", images);
            var processStartInfo = new ProcessStartInfo(fileName: appStr, arguments: imgStr);

            Console.WriteLine(appStr);
            var app = FlaUI.Core.Application.Launch(processStartInfo);

            using (var automation = new UIA3Automation())
            {
                string            title                      = null;
                Window            window                     = null;
                AutomationElement importPage                 = null;
                AutomationElement accordionPage              = null;
                AutomationElement structuredPanorama         = null;
                AutomationElement structuredPanoramaSettings = null;
                AutomationElement layout                     = null;
                AutomationElement overlap                    = null;

                do
                {
                    app = FlaUI.Core.Application.Attach(appName);
                    Console.WriteLine("app");
                    window = app.GetMainWindow(automation);
                    Console.WriteLine("automation");
                    importPage = window.FindFirstDescendant(cf => cf.ByClassName("ImportPage"));
                    Console.WriteLine("import");
                    accordionPage = importPage.FindFirstDescendant(cf => cf.ByClassName("Accordion"));
                    Console.WriteLine("accordion");
                    structuredPanorama = accordionPage.FindFirstDescendant(cf => cf.ByName("Structured panorama"));
                    Console.WriteLine("structured");
                    structuredPanoramaSettings = structuredPanorama.FindFirstDescendant(cf => cf.ByClassName("StructuredPanoramaSettings"));
                    Console.WriteLine("settings");
                    layout = structuredPanoramaSettings.FindFirstDescendant(cf => cf.ByName("Layout"));
                    Console.WriteLine("layout");
                    overlap = structuredPanoramaSettings.FindFirstDescendant(cf => cf.ByName("Overlap"));
                    Console.WriteLine("overlap");
                    title = window.Title;
                    OnEvent("Opened :" + title);
                } while (string.IsNullOrWhiteSpace(title));

                OnEvent("files: " + imgStr);

                try
                {
                    AutomationElement button1 = null;
                    do
                    {
                        button1 = structuredPanorama.FindFirstDescendant(cf => cf.ByText(structuredPanoramaBtnLabel));
                        if (button1 == null)
                        {
                            OnEvent(".");
                        }
                    } while (button1 == null);

                    if (button1.ControlType != ControlType.Button)
                    {
                        button1 = button1.AsButton().Parent;
                    }
                    button1?.AsButton().Click();
                    AutomationElement button2 = null;
                    do
                    {
                        button2 = layout.FindFirstDescendant(cf => cf.ByHelpText(cornerHelpText));
                        if (button2 == null)
                        {
                            OnEvent(".");
                        }
                    } while (button2 == null);

                    if (button2.ControlType != ControlType.RadioButton)
                    {
                        button2 = button2.AsRadioButton().Parent;
                    }

                    button2?.AsRadioButton().Click();

                    AutomationElement[] button3Possibilities = null;
                    AutomationElement   button3 = null;
                    do
                    {
                        button3Possibilities = layout.FindAllDescendants(cf => cf.ByHelpText(directionHelpText));
                        for (int i = 0; i < button3Possibilities.Length; i += 1)
                        {
                            if (button3Possibilities[i].IsEnabled == true)
                            {
                                button3 = button3Possibilities[i];
                            }
                        }
                        if (button3 == null)
                        {
                            OnEvent(".");
                        }
                    } while (button3 == null);

                    if (button3.ControlType != ControlType.RadioButton)
                    {
                        button3 = button3.AsRadioButton().Parent;
                    }

                    button3?.AsRadioButton().Click();

                    AutomationElement button4 = null;
                    do
                    {
                        string imgOrderBtnLabel = null;
                        if (parameters["is-serpentine"] == "1")
                        {
                            imgOrderBtnLabel = serpentineBtnLabel;
                        }
                        else
                        {
                            imgOrderBtnLabel = zigZagBtnLabel;
                        }
                        button4 = layout.FindFirstDescendant(cf => cf.ByAutomationId(imgOrderBtnLabel));
                        if (button4 == null)
                        {
                            OnEvent(".");
                        }
                    } while (button4 == null);

                    if (button4.ControlType != ControlType.RadioButton)
                    {
                        button4 = button4.AsRadioButton().Parent;
                    }

                    button4?.AsRadioButton().Click();

                    AutomationElement button5 = null;
                    do
                    {
                        button5 = layout.FindFirstDescendant(cf => cf.ByName(angularRangeBtnLabel));
                        if (button5 == null)
                        {
                            OnEvent(".");
                        }
                    } while (button5 == null);

                    if (button5.ControlType != ControlType.RadioButton)
                    {
                        button5 = button5.AsRadioButton().Parent;
                    }

                    button5?.AsRadioButton().Click();

                    AutomationElement textBox1 = null;
                    do
                    {
                        textBox1 = layout.FindFirstDescendant(cf => cf.ByAutomationId(primaryDirectionCountTextBox));
                        if (textBox1 == null)
                        {
                            OnEvent(".");
                        }
                    } while (textBox1 == null);

                    if (textBox1.ControlType != ControlType.Edit)
                    {
                        textBox1 = textBox1.AsTextBox().Parent;
                    }

                    textBox1?.AsTextBox().Click();
                    textBox1?.AsTextBox().Enter(parameters["major-axis-image-count"]);

                    AutomationElement textBox2 = null;
                    do
                    {
                        textBox2 = overlap.FindFirstDescendant(cf => cf.ByAutomationId(horizontalOverlapTextBox));
                        if (textBox2 == null)
                        {
                            OnEvent(".");
                        }
                    } while (textBox2 == null);

                    if (textBox2.ControlType != ControlType.Edit)
                    {
                        textBox2 = textBox2.AsTextBox().Parent;
                    }

                    textBox2?.AsTextBox().Enter(parameters["horizontal-overlap"]);

                    AutomationElement textBox3 = null;
                    do
                    {
                        textBox3 = overlap.FindFirstDescendant(cf => cf.ByAutomationId(verticalOverlapTextBox));
                        if (textBox3 == null)
                        {
                            OnEvent(".");
                        }
                    } while (textBox3 == null);

                    if (textBox3.ControlType != ControlType.Edit)
                    {
                        textBox3 = textBox3.AsTextBox().Parent;
                    }

                    textBox3?.AsTextBox().Enter(parameters["vertical-overlap"]);

                    AutomationElement textBox4 = null;
                    do
                    {
                        textBox4 = overlap.FindFirstDescendant(cf => cf.ByAutomationId(searchRadiusTextBox));
                        if (textBox4 == null)
                        {
                            OnEvent(".");
                        }
                    } while (textBox4 == null);

                    if (textBox4.ControlType != ControlType.Edit)
                    {
                        textBox4 = textBox4.AsTextBox().Parent;
                    }

                    textBox4?.AsTextBox().Enter(parameters["search-radius"]);

                    AutomationElement button6 = null;
                    do
                    {
                        button6 = window.FindFirstDescendant(cf => cf.ByText(exportBtnLabel));
                        if (button6 == null)
                        {
                            OnEvent(".");
                        }
                    } while (button6 == null);

                    if (button6.ControlType != ControlType.Button)
                    {
                        button6 = button6.AsButton().Parent;
                    }

                    button6?.AsButton().Invoke();
                    bool finished = false;
                    onEvent("composing.");
                    do
                    {
                        var window2 = app.GetMainWindow(automation);
                        var button7 = window.FindFirstDescendant(cf => cf.ByText(exportToDiskBtnLabel));

                        title    = window2.Title;
                        finished = button7 != null && title.StartsWith("U");
                        int percent = 0;
                        if (!finished)
                        {
                            var percentStr = title.Substring(0, 2);
                            var numStr     = percentStr[1] == '%' ? percentStr.Substring(0, 1) : percentStr;
                            if (int.TryParse(numStr, out percent))
                            {
                                onProgress?.Invoke(percent);
                            }
                        }
                    } while (!finished);
                }
                catch (Exception ex)
                {
                    OnEvent(ex.Message);
                }
                try
                {
                    var button7 = window.FindFirstDescendant(cf => cf.ByText(exportToDiskBtnLabel));
                    if (button7 != null && button7.ControlType != ControlType.Button)
                    {
                        button7 = button7.AsButton().Parent;
                    }
                    button7?.AsButton().Invoke();
                    OnEvent("exporting to disk...");
                }
                catch (Exception ex)
                {
                    OnEvent(ex.Message);
                }
                try
                {
                    var saveDlg = window.ModalWindows.FirstOrDefault(w => w.Name == exportPanoramaBtnLabel);
                    Thread.Sleep(100);
                    var pane40965 = saveDlg.FindFirstDescendant(cf => cf.ByAutomationId("40965"));
                    Thread.Sleep(100);
                    var pane41477 = pane40965.FindFirstDescendant(cf => cf.ByAutomationId("41477"));
                    Thread.Sleep(100);
                    var progressBar = pane41477.FindFirstDescendant(cf => cf.ByClassName("msctls_progress32"));
                    Thread.Sleep(100);
                    var breadcrumbParent = progressBar.FindFirstDescendant(cf => cf.ByClassName("Breadcrumb Parent"));
                    Thread.Sleep(100);
                    var toolbar = breadcrumbParent.FindFirstDescendant(cf => cf.ByClassName("ToolbarWindow32"));
                    Thread.Sleep(100);

                    toolbar.Click();
                    Thread.Sleep(2000);
                    FlaUI.Core.Input.Keyboard.TypeSimultaneously(FlaUI.Core.WindowsAPI.VirtualKeyShort.CONTROL, FlaUI.Core.WindowsAPI.VirtualKeyShort.KEY_V);
                    Thread.Sleep(100);
                    FlaUI.Core.Input.Keyboard.Type(FlaUI.Core.WindowsAPI.VirtualKeyShort.ENTER);
                    Thread.Sleep(100);

                    var buttonSave = saveDlg.FindFirstDescendant(cf => cf.ByText(saveBtnLabel)).AsButton();
                    buttonSave?.DoubleClick();

                    Thread.Sleep(saveWait);
                }
                catch (Exception ex)
                {
                    OnEvent(ex.Message);
                }
            }
            app.Kill();
        }