Exemple #1
0
        void ExecuteWindowsSearchQuery()
        {
            string tempString     = queryText;
            int    index          = tempString.IndexOf('#');
            string queryWithParam = tempString.Remove(index, 1);

            if (query.Contains(""))
            {
                tempString = queryWithParam.Insert(index, "\"" + query + "\"");
            }
            else
            {
                tempString = queryWithParam.Insert(index, query);
            }

            SearchXPSItemCollection list = new SearchXPSItemCollection();

            try
            {
                using (OleDbConnection connection = new OleDbConnection(connectionString))
                {
                    connection.Open();

                    OleDbCommand    cmd    = new OleDbCommand(tempString, connection);
                    OleDbDataReader reader = cmd.ExecuteReader();
                    if (reader.HasRows)
                    {
                        int numColumns = reader.FieldCount;

                        object[] values = new object[numColumns];

                        while (reader.Read())
                        {
                            reader.GetValues(values);
                            string[] rowTextValues = GetRowTextValues(values);

                            SearchXPSItem searchXPSItem = new SearchXPSItem();
                            searchXPSItem.Name = rowTextValues[0];
                            searchXPSItem.Path = rowTextValues[1];
                            list.Add(searchXPSItem);
                        }
                    }
                }
            }
            catch { }

            if (uiDispatcher != null)
            {
                uiDispatcher.BeginInvoke(DispatcherPriority.Normal, new DispatcherOperationCallback(OnWindowsSearchCompleteEvent), (object)list);
            }
        }
Exemple #2
0
        void windowsSearcher_WindowsSearchCompleteEvent(object sender)
        {
            LocalExpander.Header = "Local Search Results";

            if (sender == null)
            {
                return;
            }

            // Fill in search results
            ObjectDataProvider odp = (ObjectDataProvider)this.FindResource("SearchDataResults");

            if (odp == null)
            {
                return;
            }

            SearchData sd = odp.Data as SearchData;

            if (sd == null)
            {
                return;
            }
            SearchXPSItemCollection xpsCollection = null;

            try
            {
                //check if Operating System is Vista
                if (Environment.OSVersion.Platform == PlatformID.Win32NT && Environment.OSVersion.Version.Major == 6)
                {
                    SearchXPSItemCollection windowsSearchResults = sender as SearchXPSItemCollection;
                    xpsCollection = sd.SearchXPSData;

                    if (windowsSearchResults != null)
                    {
                        foreach (SearchXPSItem var in windowsSearchResults)
                        {
                            xpsCollection.Add(var);
                        }
                    }
                }
            }
            catch
            {
                if (xpsCollection != null)
                {
                    xpsCollection.Clear();
                }
            }
        }