Exemplo n.º 1
0
 /// <summary>
 /// Determines the result of a Simian sensation.
 /// Problems with sensors are not generally logged
 /// since they are frequently called and most are not
 /// fatal.
 /// </summary>
 /// <param name="sensorRef">A sensor expression in a rule.</param>
 /// <returns>true if the sensor detected its target.</returns>
 public bool sensation(EmptyElement sensorRef)
 {
     if (sensorRef.getName().Equals("window"))
     {                                                // is the window showing?
         string     id    = sensorRef.getValue("id"); // a VarNode
         string     title = sensorRef.getValue("title");
         MarkedNode mn    = null;
         if (Utilities.isGoodStr(id) && Utilities.isGoodStr(title))
         {                  // fetch the title from the model node via id + title
             mn = m_varNodes.get(id);
             // bail out if id not defined yet.
             if (mn == null)
             {
                 return(false);
             }
             if (mn.node != null)
             {
                 title = m_GuiModel.selectToString(mn.node, title, "title");
             }
             if (!Utilities.isGoodStr(title))
             {
                 return(false);
             }
         }
         else if (id == null && title == null)
         {                   // get the main window title from the model
             title = m_Config.getDataBase() + m_GuiModel.getTitle();
         }
         if (title == null)
         {
             return(false);                                // model lacks title
         }
         if (Utilities.isGoodStr(title))
         {
             IntPtr winHand = FindWindow(null, title);
             if ((int)winHand != 0)
             {
                 AccessibilityHelper ah = new AccessibilityHelper(winHand);
                 // look for a titlebar
                 GuiPath             gPath = new GuiPath("1:NAMELESS");
                 AccessibilityHelper tah   = ah.SearchPath(gPath, this);
                 if (tah == null || !tah.Value.Equals(title))
                 {
                     return(false);
                 }
                 m_ah = ah;
                 return(true);
             }
         }
     }
     if (sensorRef.getName().Equals("tested"))
     {
         string id      = sensorRef.getValue("id");            // which controls
         string control = sensorRef.getValue("control");       // which controls
         string count   = sensorRef.getValue("count");         // indicates how many
         if (control != null && count == null)
         {
             return(false);
         }
         if (control == null && count != null)
         {
             return(false);
         }
         if (control == null && count == null && id == null)
         {
             return(false);
         }
         if (id != null)
         {
             MarkedNode mn = m_varNodes.get(id);
             if (mn != null)
             {
                 if (mn.mark == null)
                 {
                     return(false);
                 }
                 return(mn.mark.Equals("tested"));
             }
         }
         // if id fails to return a marked node, try a control count
         if (control != null)
         {
             int n = 0; int k = 0;
             if (control.Equals("view"))
             {
                 if (m_views == null)
                 {
                     m_views = new MarkedList(m_GuiModel, "//*[@role='view']");
                 }
                 n = m_views.Count();
                 k = m_views.Count("tested");
             }
             if (count.Equals("all") && n == k)
             {
                 return(true);
             }
             if (count.Equals("not-all") && k < n)
             {
                 return(true);
             }
             return(false);
         }
         return(false);
     }
     if (sensorRef.getName().Equals("glimpse"))
     {
         string id       = sensorRef.getValue("id");           // a VarNode
         string appPath  = sensorRef.getValue("on");           // an appPath
         string guiPath  = sensorRef.getValue("at");           // a giuPath
         string property = sensorRef.getValue("prop");         // an ah property
         string expect   = sensorRef.getValue("expect");       // value expected
         // Id provides a context ah that must be used to find the rest of the path!
         // can't just use the appPath from it. What if it's a dialog?
         XmlNode    context = null;
         MarkedNode mn      = null;
         if (Utilities.isGoodStr(id))
         {
             mn = m_varNodes.get(id);
             // bail out if id not defined yet.
             if (mn == null)
             {
                 return(false);
             }
             if (mn.node != null)
             {
                 context = mn.node;
             }
         }
         return(glimpse(context, appPath, guiPath, property, expect));
     }
     return(false);
 }