//private void PrintAllTree(AutomationElement ae)
        //{
        //    Stack<AutomationElement> automationElements = XmlController.MakeStack(ae);
        //    AutomationElement ans = automationElements.Pop();

        //    Console.WriteLine(ans);

        //    TraverseAll(ans);
        //}

        //private void TraverseAll(AutomationElement ans)
        //{
        //    TreeWalker walker = TreeWalker.RawViewWalker;
        //    AutomationElement child = walker.GetFirstChild(ans);
        //    while(child != null)
        //    {
        //        Console.WriteLine(child.Current.Name);
        //        Console.WriteLine(child.Current.IsEnabled);
        //        TraverseAll(child);
        //        child = walker.GetNextSibling(child);
        //    }
        //}
        #endregion

        public void StartRecorded()
        {
            XmlController xmlController = new XmlController();

            while (contextController.CountRecorderXmlQueue() > 1)
            {
                String            xmlData = contextController.DequeueRecorderXmlQueue();
                AutomationElement ae;
                int num;
                Thread.Sleep(1500);

                (num, ae) = xmlController.XmlFinder(xmlData);

                for (int i = 10; i > 0; i++)
                {
                    if (num == 1)
                    {
                        break;
                    }
                    else
                    {
                        recorder.DebugConsole.Text += "num=" + num;
                        (num, ae) = xmlController.XmlFinder(xmlData);
                    }
                }

                WindowControl(xmlData, ae);
                Thread.Sleep(300);

                DoAction(xmlData, ae);
            }
        }
        //private void MouseHook_DoubleClick(MouseHook.MSLLHOOKSTRUCT mouseStruct)
        //{
        //    Point point = new Point(mouseStruct.pt.x, mouseStruct.pt.y);
        //    Add add = new Add(AddList);
        //    IAsyncResult result = add.BeginInvoke(point, 2,  null, null);
        //}


        private void AddList(Point point, int type)
        {
            AutomationElement ae = AutomationElement.FromPoint(point);

            #region code for keyboard input

            String inputText = null;
            if (ae != null)
            {
                AutomationPattern[] aps = ae.GetSupportedPatterns();
                foreach (AutomationPattern ap in aps)
                {
                    if (ap == ValuePattern.Pattern)
                    {
                        ValuePattern valuePattern = ae.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
                        if (valuePattern.Current.IsReadOnly == false)
                        {
                            recorder.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate
                            {
                                Stop();

                                InputBox inputBox = new InputBox();
                                inputBox.ShowDialog();

                                inputText = inputBox.InputText.Text;
                                if (inputText == "")
                                {
                                    type = 2; //dbclick
                                }
                                else
                                {
                                    type = 3;
                                }
                                Start();
                            }));
                        }
                    }
                }
            }
            #endregion

            String xmlData = XmlController.MakeXmlFile(XmlController.MakeStack(ae), type, inputText);
            contextController.AddRecorderXmlQueue(xmlData);
        }
 public WorkflowController()
 {
     xmlController      = new XmlController();
     recorderController = new RecorderController();
 }