Esempio n. 1
0
        private void CheckNewWindows()
        {
            /*
             * Need this API, as the OnWindowCreate doesn't
             * get all the subwindow events (WindowOpenedEvent), let us add such window
             * with this API
             * */
            AutomationElementCollection c;
            InternalTreeWalker          w = new InternalTreeWalker();
            Condition condition           = new PropertyCondition(
                AutomationElement.ControlTypeProperty, ControlType.Window);
            AutomationElement element = w.walker.GetFirstChild(AutomationElement.RootElement);

            try
            {
                while (null != element)
                {
                    try
                    {
                        if (this.IndexOf(element) == -1)
                        {
                            // New parent window is available, add it to the list
                            this.Add(element);
                            common.LogMessage(element.Current.Name);
                        }
                    }
                    catch (System.UnauthorizedAccessException ex)
                    {
                        // https://bugzilla.gnome.org/show_bug.cgi?id=706992
                        // Cobra looses all objects after steps specified inside
                        common.LogMessage(ex);
                        common.Wait(1);
                        element = w.walker.GetFirstChild(AutomationElement.RootElement);
                        this.Clear();
                        continue;
                    }
                    c = element.FindAll(TreeScope.Subtree, condition);
                    foreach (AutomationElement e in c)
                    {
                        if (this.IndexOf(e) == -1)
                        {
                            // New subwindow is available, add it to the list
                            this.Add(e);
                            common.LogMessage(e.Current.Name);
                        }
                    }
                    // Get next application in the list
                    element = w.walker.GetNextSibling(element);
                }
            }
            catch (Exception ex)
            {
                common.LogMessage(ex);
            }
            finally
            {
                c = null;
                w = null;
            }
        }
Esempio n. 2
0
        public float NextValue()
        {
            float firstValue = 0, secondValue = 0;

            try
            {
                // firstValue always returns 0
                firstValue = cpuCounter.NextValue();
                // Need to wait 1 second to get actual CPU usage
                // Refer above blog post
                common.Wait(1);
                // Call once again NextValue to get the actual CPU usage
                secondValue = cpuCounter.NextValue();
                if (common.Debug)
                {
                    common.LogMessage("?First value: " + firstValue);
                    common.LogMessage("?Second value: " + secondValue);
                }
            }
            catch (Exception ex)
            {
                // Process doesn't exist
                common.LogMessage(ex);
                // adjust instance name based on process id
                GetInstanceName(processId);
                //cpuCounter.InstanceName = instanceName;
                common.Wait(1);
                secondValue = cpuCounter.NextValue();
                if (common.Debug)
                {
                    common.LogMessage("#First value: " + firstValue);
                    common.LogMessage("#Second value: " + secondValue);
                }
            }
            return(secondValue);
        }
Esempio n. 3
0
 private void MonitorProcess(object interval)
 {
     while (monitorProcess)
     {
         try
         {
             foreach (string processName in processList)
             {
                 long[] memoryUsage = GetPhysicalMemoryUsage(processName,
                                                             true);
                 double[] cpuUsage = GetCpuUsage(processName, true);
             }
         }
         catch (Exception ex)
         {
             common.LogMessage(ex);
         }
         common.Wait((int)interval);
     }
 }
Esempio n. 4
0
 /*
  * BackgroundThread: Cleanup window handle that are not current valid
  */
 private void BackgroundThread()
 {
     while (true)
     {
         try
         {
             // Wait 10 second before starting the next
             // cleanup cycle
             common.Wait(10);
             CleanUpWindowElements();
             // With GC collect,
             // noticed very less memory being used all the time
             GC.Collect();
         }
         catch (Exception ex)
         {
             common.LogMessage(ex);
         }
     }
 }
Esempio n. 5
0
 internal void InternalWait(int time)
 {
     common.Wait(time);
 }
Esempio n. 6
0
        private void CheckNewWindows()
        {
            /*
             * Need this API, as the OnWindowCreate doesn't
             * get all the subwindow events (WindowOpenedEvent), let us add such window
             * with this API
             * */
            AutomationElementCollection c;
            InternalTreeWalker          w = new InternalTreeWalker();
            Condition condition           = new PropertyCondition(
                AutomationElement.ControlTypeProperty, ControlType.Window);
            AutomationElement element = w.walker.GetFirstChild(AutomationElement.RootElement);

            try
            {
                while (null != element)
                {
                    try
                    {
                        mutex.WaitOne();

                        if (this.IndexOf(element) == -1)
                        {
                            // New parent window is available, add it to the list
                            this.Add(element);
                            common.LogMessage("New window (parent): " + element.Current.Name);
                        }
                    }
                    catch (System.UnauthorizedAccessException ex)
                    {
                        // https://bugzilla.gnome.org/show_bug.cgi?id=706992
                        // Cobra looses all objects after steps specified inside
                        common.LogMessage(ex);
                        common.Wait(1);
                        element = w.walker.GetFirstChild(AutomationElement.RootElement);
                        this.Clear();
                        continue;
                    }
                    finally
                    {
                        mutex.ReleaseMutex();
                    }
                    c = element.FindAll(TreeScope.Subtree, condition);
                    foreach (AutomationElement e in c)
                    {
                        try // ".IndexOf" sometimes throws an exception on my system
                        {
                            mutex.WaitOne();

                            if (this.IndexOf(e) == -1)
                            {
                                // New subwindow is available, add it to the list
                                this.Add(e);
                                common.LogMessage("New window (sub): " + e.Current.Name);
                            }
                        }
                        catch (System.UnauthorizedAccessException ex)
                        {
                            common.LogMessage(ex);
                            common.Wait(1);

                            // In case of an exception during IndexOf-call, the program adds the element as
                            // new element to the windowList. Same code like on other positions.
                            this.Add(e);
                            common.LogMessage("New window (via System.UnauthorizedAccessException exception): " + e.Current.Name);
                        }
                        finally
                        {
                            mutex.ReleaseMutex();
                        }
                    }
                    // Get next application in the list
                    element = w.walker.GetNextSibling(element);
                }
            }
            catch (Exception ex)
            {
                common.LogMessage(ex);
            }
            finally
            {
                c = null;
                w = null;
            }
        }