public void ControlTypeCondition()
 {
     Assert.Equal("(ControlType=button or ControlType=check box)", SearchConditionFactory.CreateForControlType(typeof(Button), WindowsFramework.Wpf).ToString());
     Assert.Equal("ControlType=pane", SearchConditionFactory.CreateForControlType(typeof(TestCustomUIItem), WindowsFramework.Wpf).ToString());
     Assert.Equal("ControlType=menu bar", SearchConditionFactory.CreateForControlType(typeof(MenuBar), WindowsFramework.WinForms).ToString());
     Assert.Equal("ControlType=menu", SearchConditionFactory.CreateForControlType(typeof(MenuBar), WindowsFramework.Wpf).ToString());
 }
Exemple #2
0
 public void ControlTypeCondition()
 {
     Assert.AreEqual("ControlType=button", SearchConditionFactory.CreateForControlType(typeof(Button)).ToString());
     Assert.AreEqual("ControlType=pane", SearchConditionFactory.CreateForControlType(typeof(TestCustomUIItem)).ToString());
     Assert.AreEqual("ControlType=menu bar", SearchConditionFactory.CreateForControlType(typeof(MenuBar), Constants.WinFormFrameworkId).ToString());
     Assert.AreEqual("ControlType=menu", SearchConditionFactory.CreateForControlType(typeof(MenuBar), Constants.WPFFrameworkId).ToString());
 }
 public void Create()
 {
     Assert.That(SearchConditionFactory.CreateForControlType(element.Current.ControlType).AppliesTo(element), Is.True);
     Assert.That(SearchConditionFactory.CreateForAutomationId(element.Current.AutomationId).AppliesTo(element), Is.True);
     Assert.That(SearchConditionFactory.CreateForFrameworkId(element.Current.FrameworkId).AppliesTo(element), Is.True);
     Assert.That(SearchConditionFactory.CreateForClassName(element.Current.ClassName).AppliesTo(element), Is.True);
 }
Exemple #4
0
 public void ControlTypeCondition()
 {
     Assert.That(SearchConditionFactory.CreateForControlType(typeof(Button), WindowsFramework.Wpf).ToString(),
                 Is.EqualTo(String.Format("(ControlType={0} or ControlType={1})", ControlType.Button, ControlType.CheckBox)));
     Assert.That(SearchConditionFactory.CreateForControlType(typeof(TestCustomUIItem), WindowsFramework.Wpf).ToString(),
                 Is.EqualTo(String.Format("ControlType={0}", ControlType.Pane)));
     Assert.That(SearchConditionFactory.CreateForControlType(typeof(MenuBar), WindowsFramework.WinForms).ToString(),
                 Is.EqualTo(String.Format("ControlType={0}", ControlType.MenuBar)));
     Assert.That(SearchConditionFactory.CreateForControlType(typeof(MenuBar), WindowsFramework.Wpf).ToString(),
                 Is.EqualTo(String.Format("ControlType={0}", ControlType.Menu)));
 }
 public void ControlTypeCondition()
 {
     Assert.Equal(string.Format("(ControlType={0} or ControlType={1})",
                                ControlType.Button.LocalizedControlType,
                                ControlType.CheckBox.LocalizedControlType),
                  SearchConditionFactory.CreateForControlType(typeof(Button), WindowsFramework.Wpf).ToString());
     Assert.Equal(string.Format("ControlType={0}", ControlType.Pane.LocalizedControlType),
                  SearchConditionFactory.CreateForControlType(typeof(TestCustomUIItem), WindowsFramework.Wpf).ToString());
     Assert.Equal(string.Format("ControlType={0}", ControlType.MenuBar.LocalizedControlType),
                  SearchConditionFactory.CreateForControlType(typeof(MenuBar), WindowsFramework.WinForms).ToString());
     Assert.Equal(string.Format("ControlType={0}", ControlType.Menu.LocalizedControlType),
                  SearchConditionFactory.CreateForControlType(typeof(MenuBar), WindowsFramework.Wpf).ToString());
 }
        public void NativePropertyCondition()
        {
            SearchCondition   test = SearchConditionFactory.CreateForNativeProperty(AutomationElement.IsControlElementProperty, true);
            PropertyCondition expected;

            expected = new PropertyCondition(AutomationElement.IsControlElementProperty, true);
            Assert.AreEqual((bool)expected.Value, (bool)((PropertyCondition)test.AutomationCondition).Value);
            Assert.AreEqual(expected.Property.ProgrammaticName, ((PropertyCondition)test.AutomationCondition).Property.ProgrammaticName);
            expected = new PropertyCondition(AutomationElement.NameProperty, "hello");
            test     = SearchConditionFactory.CreateForNativeProperty(AutomationElement.NameProperty, "hello");
            Assert.AreEqual((string)expected.Value, (string)((PropertyCondition)test.AutomationCondition).Value);
            Assert.AreEqual(expected.Property.ProgrammaticName, ((PropertyCondition)test.AutomationCondition).Property.ProgrammaticName);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            // create the leaf condition for the file extension
            SearchCondition fileExtCondition =
                SearchConditionFactory.CreateLeafCondition(
                    SystemProperties.System.FileExtension, textBox1.Text,
                    SearchConditionOperation.Equal);

            // create the leaf condition for the file name
            SearchCondition fileNameCondition =
                SearchConditionFactory.CreateLeafCondition(
                    SystemProperties.System.FileName, textBox2.Text,
                    SearchConditionOperation.ValueContains);

            // combine the two leaf conditions
            SearchCondition comboCondition =
                SearchConditionFactory.CreateAndOrCondition(
                    SearchConditionType.And,
                    false, fileExtCondition, fileNameCondition);

            // create the search folder
            ShellSearchFolder searchFolder = new ShellSearchFolder(
                comboCondition, (ShellContainer)KnownFolders.UsersFiles);

            // clear the result text box
            textBox3.Clear();
            textBox3.AppendText("Processing search results...\n");

            // run through each search result
            foreach (ShellObject shellObject in searchFolder)
            {
                textBox3.AppendText("Result: "
                                    + shellObject.ParsingName + "\n");
            }

            // display a final message to the user
            textBox3.AppendText("All results processed\n");
        }
        private void DoAdvancedSearch()
        {
            // This is our final searchcondition that we'll create the search folder from
            SearchCondition finalSearchCondition = null;

            // This is Prop1 + prop2 search condition... if the user didn't specify one of the properties,
            // we can just use the one property/value they specify...if they do, then we can do the and/or operation
            SearchCondition combinedPropSearchCondition = null;

            // Because we are doing the search on a background thread,
            // we can't access the UI controls from that thread.
            // Invoke from the main UI thread and get the values
            string prop1TextBox_Text   = string.Empty;
            string prop2TextBox_Text   = string.Empty;
            string prop1ComboBox_Value = string.Empty;
            string prop2ComboBox_Value = string.Empty;
            SearchConditionOperation prop1ConditionOperation = SearchConditionOperation.ValueContains;
            SearchConditionOperation prop2ConditionOperation = SearchConditionOperation.ValueContains;
            string prop1prop2OperationComboBox_Value         = string.Empty;
            string comboBoxDateCreated_Value = string.Empty;
            int    prop1prop2OperationComboBox_SelectedIndex = 0;
            bool   dateSelected          = false;
            List <ShellContainer> scopes = new List <ShellContainer>();

            Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(
                                  delegate()
            {
                prop1TextBox_Text                         = prop1TextBox.Text;
                prop1TextBox_Text                         = prop1TextBox.Text;
                prop1ComboBox_Value                       = prop1ComboBox.SelectedItem.ToString();
                prop2ComboBox_Value                       = prop2ComboBox.SelectedItem.ToString();
                prop1ConditionOperation                   = GetConditionOperation(prop1OperationComboBox);
                prop2ConditionOperation                   = GetConditionOperation(prop2OperationComboBox);
                prop1prop2OperationComboBox_Value         = prop1prop2OperationComboBox.SelectedItem.ToString();
                prop1prop2OperationComboBox_SelectedIndex = prop1prop2OperationComboBox.SelectedIndex;
                comboBoxDateCreated_Value                 = comboBoxDateCreated.SelectedItem.ToString();
                dateSelected = (comboBoxDateCreated.SelectedItem != dateCreatedNone);

                foreach (StackPanel sp in locationsListBox.Items)
                {
                    if (sp.Tag is ShellContainer)
                    {
                        scopes.Add((ShellContainer)sp.Tag);
                    }
                }
            }));

            // If we have a valid first property/value, then create a search condition
            if (!string.IsNullOrEmpty(prop1TextBox_Text))
            {
                SearchCondition prop1Condition = SearchConditionFactory.CreateLeafCondition(
                    GetSearchProperty(prop1ComboBox_Value),
                    prop1TextBox_Text,
                    prop1ConditionOperation);

                // After creating the first condition, see if we need to create a second leaf condition
                if (prop1prop2OperationComboBox_SelectedIndex != 0 &&
                    !(string.IsNullOrEmpty(prop2TextBox_Text)))
                {
                    SearchCondition prop2Condition = SearchConditionFactory.CreateLeafCondition(
                        GetSearchProperty(prop2ComboBox_Value),
                        prop2TextBox_Text,
                        prop2ConditionOperation);

                    // Create our combined search condition AND or OR
                    if (prop1prop2OperationComboBox.SelectedIndex == 1)
                    {
                        combinedPropSearchCondition = SearchConditionFactory.CreateAndOrCondition(
                            SearchConditionType.And,
                            false, prop1Condition, prop2Condition);
                    }
                    else
                    {
                        combinedPropSearchCondition = SearchConditionFactory.CreateAndOrCondition(
                            SearchConditionType.Or,
                            false, prop1Condition, prop2Condition);
                    }
                }
                else
                {
                    combinedPropSearchCondition = prop1Condition;
                }
            }
            else
            {
                return; // no search text entered
            }
            // Get the date condition
            if (dateSelected)
            {
                SearchCondition dateCreatedCondition = SearchConditionFactory.CreateLeafCondition(
                    SystemProperties.System.DateCreated,
                    ParseDate(((ComboBoxItem)comboBoxDateCreated.SelectedItem).Tag.ToString(), DateTime.Now),
                    SearchConditionOperation.GreaterThan);

                // If we have a property based search condition, create an "AND" search condition from these 2
                if (combinedPropSearchCondition != null)
                {
                    finalSearchCondition = SearchConditionFactory.CreateAndOrCondition(SearchConditionType.And,
                                                                                       false, combinedPropSearchCondition, dateCreatedCondition);
                }
                else
                {
                    finalSearchCondition = dateCreatedCondition;
                }
            }
            else
            {
                finalSearchCondition = combinedPropSearchCondition;
            }


            ShellSearchFolder searchFolder = new ShellSearchFolder(finalSearchCondition, scopes.ToArray());

            //
            List <SearchItem> items = new List <SearchItem>();

            try
            {
                // Because we cannot pass ShellObject or IShellItem (native interface)
                // across multiple threads, creating a helper object and copying the data we need from the ShellObject
                foreach (ShellObject so in searchFolder)
                {
                    // For each of our ShellObject,
                    // create a SearchItem object
                    // We will bind these items to the ListView
                    SearchItem item = new SearchItem();
                    item.Name = so.Name;

                    // We must freeze the ImageSource before passing across threads
                    BitmapSource thumbnail = so.Thumbnail.MediumBitmapSource;
                    thumbnail.Freeze();
                    item.Thumbnail = thumbnail;

                    item.Authors     = so.Properties.System.Author.Value;
                    item.Title       = so.Properties.System.Title.Value;
                    item.Keywords    = so.Properties.System.Keywords.Value;
                    item.Copyright   = so.Properties.System.Copyright.Value;
                    item.TotalPages  = so.Properties.System.Document.PageCount.Value.HasValue ? so.Properties.System.Document.PageCount.Value.Value : 0;
                    item.Rating      = so.Properties.System.SimpleRating.Value.HasValue ? (int)so.Properties.System.SimpleRating.Value.Value : 0;
                    item.ParsingName = so.ParsingName;

                    items.Add(item);
                }

                // Invoke the search on the main thread

                Dispatcher.Invoke(
                    System.Windows.Threading.DispatcherPriority.Normal,
                    new Action(
                        delegate()
                {
                    MainWindow.UpdateSearchItems(items);
                }
                        ));
            }
            finally
            {
                // TODO - dispose other

                finalSearchCondition.Dispose();
                finalSearchCondition = null;

                searchFolder.Dispose();
                searchFolder = null;
            }
        }
Exemple #9
0
 public void Equals()
 {
     Assert.AreEqual(SearchConditionFactory.CreateForAutomationId("foo"), SearchConditionFactory.CreateForAutomationId("foo"));
     Assert.AreNotEqual(SearchConditionFactory.CreateForAutomationId("foo"), SearchConditionFactory.CreateForAutomationId("foo1"));
     Assert.AreNotEqual(SearchConditionFactory.CreateForAutomationId("foo"), SearchConditionFactory.CreateForName(("foo")));
 }
Exemple #10
0
        // Helper method to do the search on a background thread
        internal void DoSimpleSearch(object arg)
        {
            string text = arg as string;

            // Specify a culture for our query.
            CultureInfo cultureInfo = new CultureInfo("en-US");

            SearchCondition searchCondition = SearchConditionFactory.ParseStructuredQuery(text, cultureInfo);

            // Create a new search folder by setting our search condition and search scope
            // KnownFolders.SearchHome - This is the same scope used by Windows search
            searchFolder = new ShellSearchFolder(
                searchCondition,
                selectedScope);

            List <SearchItem> items = new List <SearchItem>();

            try
            {
                // Because we cannot pass ShellObject or IShellItem (native interface)
                // across multiple threads, creating a helper object and copying the data we need from the ShellObject
                foreach (ShellObject so in searchFolder)
                {
                    // For each of our ShellObject,
                    // create a SearchItem object
                    // We will bind these items to the ListView
                    SearchItem item = new SearchItem {
                        Name = so.Name
                    };

                    // We must freeze the ImageSource before passing across threads
                    BitmapSource thumbnail = so.Thumbnail.MediumBitmapSource;
                    thumbnail.Freeze();
                    item.Thumbnail = thumbnail;

                    item.Authors     = so.Properties.System.Author.Value;
                    item.Title       = so.Properties.System.Title.Value;
                    item.Keywords    = so.Properties.System.Keywords.Value;
                    item.Copyright   = so.Properties.System.Copyright.Value;
                    item.TotalPages  = so.Properties.System.Document.PageCount.Value ?? 0;
                    item.Rating      = so.Properties.System.SimpleRating.Value.HasValue ? (int)so.Properties.System.SimpleRating.Value.Value : 0;
                    item.ParsingName = so.ParsingName;

                    items.Add(item);
                }

                // Invoke the search on the main thread

                Dispatcher.Invoke(
                    System.Windows.Threading.DispatcherPriority.Normal,
                    new Action(
                        delegate()
                {
                    UpdateSearchItems(items);
                }
                        ));
            }
            catch
            {
                searchFolder.Dispose();
                searchFolder = null;
            }
        }
 public void EqualsTests()
 {
     Assert.That(SearchConditionFactory.CreateForAutomationId("foo"), Is.EqualTo(SearchConditionFactory.CreateForAutomationId("foo")));
     Assert.That(SearchConditionFactory.CreateForAutomationId("foo"), Is.Not.EqualTo(SearchConditionFactory.CreateForAutomationId("foo1")));
     Assert.That(SearchConditionFactory.CreateForAutomationId("foo"), Is.Not.EqualTo(SearchConditionFactory.CreateForName(("foo"))));
 }