Exemplo n.º 1
0
        /// <summary>
        /// Indexes the files.
        /// </summary>
        /// <param name="servers">The servers.</param>
        /// <returns></returns>
        public bool CreateIndexFiles(ProductType productType)
        {
            string ImpersonatedUser         = ConfigurationManager.AppSettings.Get("User");
            string ImpersonatedUserPassword = ConfigurationManager.AppSettings.Get("Password");
            string ImpersonatedUserDomain   = ConfigurationManager.AppSettings.Get("Domain");

            using (UserImpersonation user = new UserImpersonation(ImpersonatedUser, ImpersonatedUserDomain, ImpersonatedUserPassword))
            {
                if (user.ImpersonateValidUser())
                {
                    XmlProcessor processor = new XmlProcessor();
                    Product      product   = processor.ReadProduct(productType);

                    if (product.LastIndexedDate.HasValue && DateTime.Compare(product.LastIndexedDate.Value, DateTime.Today) == 0)
                    {
                        return(true);
                    }

                    DateTime startDate = product.LastIndexedDate ?? product.IndexStartDate;
                    DateTime endDate   = DateTime.Today.AddDays(-1);

                    string targetDirectory = ConfigurationManager.AppSettings.Get("DecompressedFolder");
                    string indexLocation   = ConfigurationManager.AppSettings.Get("IndexFolder") + productType.ToString();
                    ClearLogDecompress(targetDirectory);
                    DeleteEarlierIndexes(product, processor);

                    while (startDate <= endDate)
                    {
                        foreach (string file in processor.CopyFiles(startDate.ToShortDateString(), productType))
                        {
                            string   fileName;
                            FileInfo fi = new DirectoryInfo(targetDirectory).GetFiles("*.zip").FirstOrDefault();

                            fileName = fi != null?processor.DecompressFile(fi) : string.Empty;

                            if (!string.IsNullOrEmpty(fileName))
                            {
                                LuceneIndexer    li  = new LuceneIndexer();
                                HashSet <string> set = processor.ReadFile(product, fileName);
                                li.IndexFile(indexLocation, fileName, startDate.ToShortDateString(), set);
                            }
                        }

                        startDate = startDate.AddDays(1);
                        this.UpdateProductDate(product, startDate, "LastIndexedDate");
                    }
                }
            }

            return(true);
        }