예제 #1
0
        static void Main(string[] args)
        {
            Application              objApp     = null;
            ISearchManager           objManager = null;
            ISearchCatalogManager    objCatalog = null;
            ISearchCrawlScopeManager objScope   = null;
            string strSID = null;

            try
            {
                Console.WriteLine("Creating search management objects...");
                objManager = new CSearchManagerClass();
                objCatalog = objManager.GetCatalog("SystemIndex");
                objScope   = objCatalog.GetCrawlScopeManager();
                Console.WriteLine("Obtaining currently logged user's SID...");
                strSID = String.Concat("{", WindowsIdentity.GetCurrent().User.Value.ToString().ToLower(), "}");
                Console.WriteLine("  The SID is: {0}", strSID);
                Console.WriteLine("Starting Outlook application...");
                objApp = new Application();
                Console.WriteLine("Enumerating PST files...");
                foreach (Store objStore in objApp.GetNamespace("MAPI").Stores)
                {
                    Console.WriteLine("Analysing file: {0}...", objStore.FilePath);
                    if (objStore.ExchangeStoreType != OlExchangeStoreType.olNotExchange || objStore.IsCachedExchange != true)
                    {
                        Console.WriteLine("  Rejected. This file is not cached exchange store.");
                    }
                    else if (Path.GetPathRoot(objStore.FilePath).StartsWith("C", StringComparison.OrdinalIgnoreCase))
                    {
                        Console.WriteLine("  Rejected. This file is located on the C: drive.");
                    }
                    else if (objStore.IsInstantSearchEnabled != true)
                    {
                        Console.WriteLine("  Rejected. Instant search was already disabled for this file.");
                    }
                    else
                    {
                        Console.WriteLine("  Accepted. Indexing of this file will be disabled.");
                        Console.WriteLine("    Computing store hash...");
                        string strHash = ComputeHash(objStore.StoreID);
                        Console.WriteLine("      The hash is: {0}.", strHash);
                        string strUrl = String.Format("mapi://{0}/{1}(${2})/", strSID, objStore.DisplayName, strHash);
                        Console.WriteLine("    Disabling indexing...");
                        Console.WriteLine("      The rule url is: {0}.", strUrl);
                        objScope.AddUserScopeRule(strUrl, 0, 1, 0);
                        objScope.SaveAll();
                        Console.WriteLine("    Operation successfull!");
                    }
                }
            }
            catch (System.Exception e)
            {
                Console.WriteLine();
                Console.WriteLine("An error occured!");
                Console.WriteLine(e.ToString());
            }
            Console.WriteLine();
            Console.WriteLine("Press return to exit.");
            Console.ReadLine();
        }
예제 #2
0
파일: MainForm.cs 프로젝트: bazile/Training
        private void btnSearch_Click(object sender, EventArgs e)
        {
            //const string connectionString = "Provider=Search.CollatorDSO; Extended Properties=\"Application=Windows\"";
            //using (OleDbConnection connection = new OleDbConnection(connectionString))
            //{
            //    // Список поддерживаемых свойств (обширный!) доступен на MSDN
            //    // https://msdn.microsoft.com/en-us/library/ff521735%28v=vs.85%29.aspx
            //    string query = @"SELECT System.ItemName, System.ItemFolderPathDisplayNarrow FROM SystemIndex " +
            //                   @"WHERE scope ='file\u003a" + GetSearchPath() + "'"; //" AND FREETEXT('XML')";
            //    OleDbCommand command = new OleDbCommand(query, connection);
            //    connection.Open();

            //    //List<string> result = new List<string>();

            //    OleDbDataReader reader = command.ExecuteReader();
            //    while (reader.Read())
            //    {
            //        //result.Add(reader.GetString(reader.GetOrdinal("System.ItemName")));
            //        listBox1.Items.Add(reader.GetString(reader.GetOrdinal("System.ItemName")));
            //    }
            //    //result.Dump();
            //}
            CSearchManager manager = new CSearchManagerClass();
            ISearchCatalogManager catalogManager = manager.GetCatalog("SystemIndex");
            //catalogManager.
            //ISearchQueryHelper queryHelper = catalogManager.GetQueryHelper();
            //queryHelper.

            //string sqlQuery = queryHelper.GenerateSQLFromUserQuery(aqsQuery);
        }
예제 #3
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            //const string connectionString = "Provider=Search.CollatorDSO; Extended Properties=\"Application=Windows\"";
            //using (OleDbConnection connection = new OleDbConnection(connectionString))
            //{
            //    // Список поддерживаемых свойств (обширный!) доступен на MSDN
            //    // https://msdn.microsoft.com/en-us/library/ff521735%28v=vs.85%29.aspx
            //    string query = @"SELECT System.ItemName, System.ItemFolderPathDisplayNarrow FROM SystemIndex " +
            //                   @"WHERE scope ='file\u003a" + GetSearchPath() + "'"; //" AND FREETEXT('XML')";
            //    OleDbCommand command = new OleDbCommand(query, connection);
            //    connection.Open();

            //    //List<string> result = new List<string>();

            //    OleDbDataReader reader = command.ExecuteReader();
            //    while (reader.Read())
            //    {
            //        //result.Add(reader.GetString(reader.GetOrdinal("System.ItemName")));
            //        listBox1.Items.Add(reader.GetString(reader.GetOrdinal("System.ItemName")));
            //    }
            //    //result.Dump();
            //}
            CSearchManager        manager        = new CSearchManagerClass();
            ISearchCatalogManager catalogManager = manager.GetCatalog("SystemIndex");
            //catalogManager.
            //ISearchQueryHelper queryHelper = catalogManager.GetQueryHelper();
            //queryHelper.

            //string sqlQuery = queryHelper.GenerateSQLFromUserQuery(aqsQuery);
        }
        public List<SearchFile> Post(HttpRequestMessage request)
        {
            var content = HttpUtility.ParseQueryString(request.Content.ReadAsString());
            string keyword = String.Format("{0}", content.Get(0));

            CSearchManager cManager;
            ISearchQueryHelper cHelper;
            OleDbConnection cConnection;

            cManager = new CSearchManagerClass();
            List<SearchFile> searchResults = new List<SearchFile>();

            // Atualmente, o Windows Search suporta apenas um catálogo e esse já é definido como SYSTEMINDEX
            cHelper = cManager.GetCatalog("SYSTEMINDEX").GetQueryHelper();

            cHelper.QuerySelectColumns = "System.ItemPathDisplay,System.ItemNameDisplay,System.ItemType";

            try
            {
                using (cConnection = new OleDbConnection(
                            cHelper.ConnectionString))
                {
                    // Define o número máximo de resultados
                    cHelper.QueryMaxResults = 100;

                    // Procura apenas os arquivos
                    cHelper.QueryWhereRestrictions = "AND scope='file:C:/ekdvault'";

                    cConnection.Open();
                    using (OleDbCommand cmd = new OleDbCommand(
                            cHelper.GenerateSQLFromUserQuery(keyword),
                            cConnection))
                    {
                        if (cConnection.State == ConnectionState.Open)
                        {
                            using (OleDbDataReader reader = cmd.ExecuteReader())
                            {

                                int i = 0;
                                while (!reader.IsClosed && reader.Read())
                                {
                                    SearchFile searchResult = new SearchFile
                                    {
                                        FilePath = reader[0].ToString(),
                                        FileName = reader[1].ToString(),
                                        ItemType = reader[2].ToString(),
                                    };
                                    //if (i < 3)
                                    if(searchResult.ItemType != "Directory")
                                        searchResults.Add(searchResult);
                                    i++;

                                }
                            }

                        }
                        cConnection.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
            return searchResults;
        }
예제 #5
0
파일: wdsgrep.cs 프로젝트: kawabata/wdsgrep
        /// <summary>
        /// Performs search for a given term and returns results as a list of strings
        /// </summary>
        /// <param name="data">Search term</param>
        /// <returns>Search results</returns>
        public static List<string> ExecuteQuery(string aqsQuery, string sortcols)
        {
            //string selectcol = "System.ItemURL";

            CSearchManager manager = new CSearchManagerClass();
            CSearchCatalogManager catalogManager = manager.GetCatalog("SystemIndex");
            CSearchQueryHelper queryHelper = catalogManager.GetQueryHelper();
            queryHelper.QuerySorting = sortcols;
            string sqlQuery = queryHelper.GenerateSQLFromUserQuery(aqsQuery);

            OleDbCommand cmd = new OleDbCommand();
            cmd.Connection = conn;
            cmd.CommandText = sqlQuery;
            /*
            cmd.CommandText = string.Format(
                "SELECT {0} FROM systemindex WHERE CONTAINS(*, '{1}')", // search contents and properties
                // "SELECT {0} FROM systemindex WHERE CONTAINS('{1}')", // search contents only
                selectcol, aqsQuery);
             */
            OleDbDataReader results = cmd.ExecuteReader();

            List<string> items = new List<string>();
            while (results.Read())
            {
                items.Add(results.GetString(0));
            }

            results.Close();

            return items;
        }