Пример #1
0
 /// <summary>
 /// Finds the items.
 /// </summary>
 /// <param name="parameters">The parameters.</param>
 /// <param name="options">The options.</param>
 /// <returns></returns>
 public Entries FindItems(CatalogSearchParameters parameters, CatalogSearchOptions options)
 {
     return(_Proxy.FindItems(parameters, options));
 }
Пример #2
0
        /// <summary>
        /// Builds the index.
        /// </summary>
        /// <param name="rebuild">if set to <c>true</c> [rebuild].</param>
        public override void BuildIndex(bool rebuild)
        {
            OnEvent(String.Format("CatalogIndexBuilder Started"), 0);

            IndexBuilder indexer   = this.Indexer;
            DateTime     lastBuild = DateTime.MinValue;

            // Parameters used to restart build from the previous error
            //string restartCatalogName = String.Empty;
            //int restartRecordKey = 0;

            // On complete rebuild no need to check date
            if (!rebuild)
            {
                lastBuild = indexer.GetBuildConfig().LastBuildDate;
            }

            ICatalogSystem system = CatalogContext.Current;

            // Get catalog lists
            CatalogDto catalogs = system.GetCatalogDto();

            double percentage = 0;

            bool incremental      = false;
            int  allRecords       = 0;
            int  allCurrentRecord = 0;
            int  allRecordsCount  = GetTotalRecords();
            int  catalogCount     = 1;

            // If date is set, we do incremental rebuild
            if (lastBuild != DateTime.MinValue)
            {
                incremental = true;
            }

            // remove deleted items first
            if (incremental)
            {
                int startingRecord = 0;
                int totalRemoved   = 0;

                while (true)
                {
                    int    count = 0;
                    LogDto dto   = LogManager.GetAppLog("catalog", DataRowState.Deleted.ToString(), "entry", lastBuild.ToUniversalTime(), startingRecord, 100, ref count);

                    // add up to a total number to calculate percentage correctly
                    if (startingRecord == 0)
                    {
                        allRecordsCount += count;
                    }

                    if (count <= 0)
                    {
                        break;
                    }

                    foreach (LogDto.ApplicationLogRow row in dto.ApplicationLog)
                    {
                        allCurrentRecord++;
                        if (allCurrentRecord % 20 == 0)
                        {
                            percentage = ((double)allCurrentRecord / (double)allRecordsCount) * 100;
                            OnEvent(String.Format("Removing old entry from index ({1}/{2}) ...", allCurrentRecord, count), percentage);
                        }

                        totalRemoved += indexer.DeleteContent("_id", row.ObjectKey);
                    }

                    startingRecord += 100;
                }

                percentage = ((double)allCurrentRecord / (double)allRecordsCount) * 100;
                OnEvent(String.Format("CatalogIndexBuilder Removed {0} records.", totalRemoved), percentage);
            }

            // Index new or updated items
            foreach (CatalogDto.CatalogRow catalog in catalogs.Catalog)
            {
                string catalogName     = catalog.Name;
                string defaultCurrency = catalog.DefaultCurrency;

                OnEvent(String.Format("Indexing {0} catalog ...", catalogName), percentage);

                int currentRecord  = 0;
                int startingRecord = 0;
                int totalIndexed   = 0;
                int lastRecordKey  = 0;
                catalogCount++;

                while (true)
                {
                    // Get Catalog Nodes
                    CatalogSearchParameters pars    = new CatalogSearchParameters();
                    CatalogSearchOptions    options = new CatalogSearchOptions();

                    options.CacheResults = false;
                    pars.CatalogNames.Add(catalogName);
                    options.RecordsToRetrieve = 100;
                    options.StartingRecord    = startingRecord;

                    if (incremental)
                    {
                        pars.SqlMetaWhereClause = String.Format("META.Modified > '{0}'", lastBuild.ToUniversalTime().ToString("s"));
                    }

                    int             count    = 0;
                    CatalogEntryDto entryDto = CatalogContext.Current.FindItemsDto(pars, options, ref count, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));

                    if (count <= 0)
                    {
                        break;
                    }

                    startingRecord += options.RecordsToRetrieve;

                    List <string> languages = new List <string>();

                    languages.Add(catalog.DefaultLanguage);

                    foreach (CatalogDto.CatalogLanguageRow row in catalog.GetCatalogLanguageRows())
                    {
                        languages.Add(row.LanguageCode);
                    }

                    foreach (CatalogEntryDto.CatalogEntryRow row in entryDto.CatalogEntry)
                    {
                        currentRecord++;
                        allCurrentRecord++;

                        // Do not index non active entries
                        if (!row.IsActive)
                        {
                            continue;
                        }

                        // In case of incremental, check if item already exists and delete it
                        if (incremental)
                        {
                            indexer.DeleteContent("_id", row.CatalogEntryId.ToString());
                        }

                        try
                        {
                            lastRecordKey = row.CatalogEntryId;
                            totalIndexed += IndexCatalogEntryDto(indexer, row, defaultCurrency, languages.ToArray());
                        }
                        catch (Exception)
                        {
                            percentage = ((double)allCurrentRecord / (double)allRecordsCount) * 100;
                            OnEvent(String.Format("Failed to index catalog entry {0}({1}) in {2}.", row.Name, row.CatalogEntryId, catalogName), percentage);
                            throw;
                        }

                        if (allCurrentRecord % 20 == 0)
                        {
                            percentage = ((double)allCurrentRecord / (double)allRecordsCount) * 100;
                            OnEvent(String.Format("Indexing {0} catalog entries ({1}/{2}) ...", catalogName, allCurrentRecord, allRecordsCount), percentage);
                        }
                    }

                    // Save index every 500 records
                    if (allCurrentRecord % 500 == 0)
                    {
                        percentage = ((double)allCurrentRecord / (double)allRecordsCount) * 100;
                        OnEvent(String.Format("Saving {0} catalog index file.", catalogName), percentage);
                        Build config = indexer.GetBuildConfig();

                        // Preserve the information needed to restart the indexing on the exact same location as before
                        BuildProperty prop1 = new BuildProperty();
                        prop1.name  = "StartingRecord";
                        prop1.value = startingRecord.ToString();

                        BuildProperty prop2 = new BuildProperty();
                        prop2.name  = "LastRecordKey";
                        prop2.value = lastRecordKey.ToString();

                        BuildProperty prop3 = new BuildProperty();
                        prop3.name  = "CatalogName";
                        prop3.value = catalogName;

                        config.Properties = new BuildProperty[] { prop1, prop2, prop3 };
                        indexer.SaveBuild(Status.Started);
                        indexer.Close();
                    }

                    if (startingRecord > count)
                    {
                        break;
                    }
                }

                percentage = ((double)allCurrentRecord / (double)allRecordsCount) * 100;
                catalogCount++;

                allRecords += totalIndexed;
            }

            OnEvent(String.Format("CatalogIndexBuilder Indexed {0} language records in {1} catalog(s)", allRecords.ToString(), (catalogCount - 1).ToString()), 99);
            OnEvent(String.Format("CatalogIndexBuilder Finished"), 100);
        }
Пример #3
0
        /// <summary>
        /// Indexes the catalog.
        /// </summary>
        private static void IndexCatalog(string indexType)
        {
            ICatalogSystem system = CatalogContext.Current;

            // Get catalog lists
            CatalogDto catalogs = system.GetCatalogDto();

            foreach (CatalogDto.CatalogRow catalog in catalogs.Catalog)
            {
                string catalogName = catalog.Name;

                Console.WriteLine(String.Format("Indexing {0} catalog ...", catalogName));

                int currentRecord      = 0;
                int totalIndexed       = 0;
                int currentRecordIndex = 0;
                int origRow            = Console.CursorTop;
                int origCol            = Console.CursorLeft;
                int overallTotalCount  = 0;
                while (true)
                {
                    // Get Catalog Nodes
                    CatalogSearchParameters pars    = new CatalogSearchParameters();
                    CatalogSearchOptions    options = new CatalogSearchOptions();
                    options.CacheResults = false;
                    pars.CatalogNames.Add(catalogName);
                    options.RecordsToRetrieve = 500;
                    options.StartingRecord    = currentRecord;
                    if (!indexType.Equals("all", StringComparison.OrdinalIgnoreCase))
                    {
                        pars.SqlWhereClause = "SerializedData is null";
                    }

                    int             totalCount = 0;
                    CatalogEntryDto entryDto   = CatalogContext.Current.FindItemsDto(pars, options, ref totalCount, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));

                    if (!indexType.Equals("all", StringComparison.OrdinalIgnoreCase))
                    {
                        currentRecord = 0;
                        if (overallTotalCount == 0)
                        {
                            overallTotalCount = totalCount;
                        }
                    }
                    else
                    {
                        if (currentRecord == 0)
                        {
                            overallTotalCount = totalCount;
                        }

                        currentRecord += options.RecordsToRetrieve;
                    }


                    List <string> languages = new List <string>();

                    languages.Add(catalog.DefaultLanguage);

                    foreach (CatalogDto.CatalogLanguageRow row in catalog.GetCatalogLanguageRows())
                    {
                        languages.Add(row.LanguageCode);
                    }

                    int currentBatchCount = 0;

                    foreach (CatalogEntryDto.CatalogEntryRow row in entryDto.CatalogEntry)
                    {
                        Console.SetCursorPosition(origCol, origRow);
                        Console.WriteLine(String.Format("Indexing {0}/{1} record                  ", currentRecordIndex + 1, overallTotalCount));
                        currentBatchCount += IndexCatalogEntryDto(row, languages.ToArray());
                        totalIndexed      += currentBatchCount;
                        currentRecordIndex++;
                    }

                    Console.SetCursorPosition(origCol, origRow);
                    Console.WriteLine(String.Format("Saving {0}-{1}/{2} records            ", currentRecordIndex - currentBatchCount + 1, currentRecordIndex, overallTotalCount));
                    system.SaveCatalogEntry(entryDto);

                    // Break the loop if we retrieved all the record
                    if (currentRecord > overallTotalCount || totalCount <= 0)
                    {
                        break;
                    }
                }

                Console.WriteLine(String.Format("Successfully indexed {0} language records in {1} catalog", totalIndexed.ToString(), catalogName));
            }
        }
Пример #4
0
        /// <summary>
        /// Deletes the catalog.
        /// </summary>
        /// <param name="catalogId">The catalog id.</param>
        public static void DeleteCatalog(int catalogId)
        {
            CatalogDto dto = GetCatalogDto(catalogId, new CatalogResponseGroup(CatalogResponseGroup.ResponseGroup.CatalogFull));

            if (dto.Catalog.Count == 0)
            {
                return;
            }

            //Delete CatalogItemAsset rows by CatalogId
            CatalogNodeDto catalogNodeDto = CatalogNodeManager.GetCatalogNodesDto(catalogId, new CatalogNodeResponseGroup(CatalogNodeResponseGroup.ResponseGroup.Assets));

            if (catalogNodeDto.CatalogNode.Count > 0)
            {
                for (int i1 = 0; i1 < catalogNodeDto.CatalogItemAsset.Count; i1++)
                {
                    catalogNodeDto.CatalogItemAsset[i1].Delete();
                }

                CatalogNodeManager.SaveCatalogNode(catalogNodeDto);
            }

            // delete relations
            CatalogRelationDto catalogRelationDto = CatalogRelationManager.GetCatalogRelationDto(catalogId, 0, 0, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry | CatalogRelationResponseGroup.ResponseGroup.CatalogEntry | CatalogRelationResponseGroup.ResponseGroup.CatalogNode));

            foreach (CatalogRelationDto.NodeEntryRelationRow row in catalogRelationDto.NodeEntryRelation.Rows)
            {
                row.Delete();
            }

            foreach (CatalogRelationDto.CatalogEntryRelationRow row in catalogRelationDto.CatalogEntryRelation.Rows)
            {
                row.Delete();
            }

            foreach (CatalogRelationDto.CatalogNodeRelationRow row in catalogRelationDto.CatalogNodeRelation.Rows)
            {
                row.Delete();
            }

            if (catalogRelationDto.HasChanges())
            {
                CatalogRelationManager.SaveCatalogRelation(catalogRelationDto);
            }

            //Delete CatalogItemSeo rows by CatalogNodeId and CatalogNode rows
            catalogNodeDto = CatalogNodeManager.GetCatalogNodesDto(catalogId, new CatalogNodeResponseGroup(CatalogNodeResponseGroup.ResponseGroup.CatalogNodeFull));
            if (catalogNodeDto.CatalogNode.Count > 0)
            {
                for (int i1 = 0; i1 < catalogNodeDto.CatalogItemSeo.Count; i1++)
                {
                    catalogNodeDto.CatalogItemSeo[i1].Delete();
                }

                for (int i1 = 0; i1 < catalogNodeDto.CatalogNode.Count; i1++)
                {
                    catalogNodeDto.CatalogNode[i1].Delete();
                }

                CatalogNodeManager.SaveCatalogNode(catalogNodeDto);
            }

            //Delete entries
            while (true)
            {
                CatalogSearchParameters pars    = new CatalogSearchParameters();
                CatalogSearchOptions    options = new CatalogSearchOptions();

                options.Namespace         = String.Empty;
                options.RecordsToRetrieve = 100;
                options.StartingRecord    = 0;
                pars.CatalogNames.Add(dto.Catalog[0].Name);

                int             totalCount      = 0;
                CatalogEntryDto catalogEntryDto = CatalogContext.Current.FindItemsDto(pars, options, ref totalCount, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));

                //Delete CatalogEntryAssociation rows
                foreach (CatalogEntryDto.CatalogAssociationRow catalogAssociationRow in catalogEntryDto.CatalogAssociation)
                {
                    CatalogAssociationDto catalogAssociationDto = FrameworkContext.Current.CatalogSystem.GetCatalogAssociationDto(catalogAssociationRow.CatalogAssociationId);
                    foreach (CatalogAssociationDto.CatalogEntryAssociationRow itemCatalogEntryAssociation in catalogAssociationDto.CatalogEntryAssociation)
                    {
                        itemCatalogEntryAssociation.Delete();
                    }

                    if (catalogAssociationDto.HasChanges())
                    {
                        CatalogContext.Current.SaveCatalogAssociation(catalogAssociationDto);
                    }
                }

                //Delete CatalogEntry rows
                foreach (CatalogEntryDto.CatalogEntryRow catalogEntryRow in catalogEntryDto.CatalogEntry)
                {
                    if (catalogEntryRow.InventoryRow != null)
                    {
                        catalogEntryRow.InventoryRow.Delete();
                    }
                    catalogEntryRow.Delete();
                }

                CatalogContext.Current.SaveCatalogEntry(catalogEntryDto);

                // Break the loop if we retrieved all the record
                if (totalCount < options.RecordsToRetrieve)
                {
                    break;
                }
            }

            // Delete root entries
            CatalogEntryDto rootCatalogEntries = CatalogEntryManager.GetCatalogEntriesDto(catalogId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));

            foreach (CatalogEntryDto.CatalogEntryRow catalogEntryRow in rootCatalogEntries.CatalogEntry)
            {
                if (catalogEntryRow.InventoryRow != null)
                {
                    catalogEntryRow.InventoryRow.Delete();
                }
                catalogEntryRow.Delete();
            }

            CatalogEntryManager.SaveCatalogEntry(rootCatalogEntries);

            //Delete Catalog row by id
            dto.Catalog[0].Delete();
            SaveCatalog(dto);
        }
        /// <summary>
        /// Returns products to compare.
        /// </summary>
        /// <param name="mcId">Id of a metaClass.</param>
        /// <returns></returns>
        public static Entries GetCompareProducts(string mcId)
        {
            Entries    products      = new Entries();
            HttpCookie compareCookie = HttpContext.Current.Request.Cookies.Get(MakeCurrentApplicationCookieName(_CompareCookieItemsName));

            if (compareCookie != null && compareCookie.Values != null)
            {
                List <int> productIds = new List <int>();

                string[] values = new string[] { };
                if (String.IsNullOrEmpty(mcId))
                {
                    List <string> _values = new List <string>();
                    foreach (string key in compareCookie.Values.AllKeys)
                    {
                        if (!String.IsNullOrEmpty(key))
                        {
                            string[] valuesByKey = compareCookie.Values.GetValues(key);
                            _values.AddRange(valuesByKey);
                        }
                    }
                    values = _values.ToArray();
                }
                else
                {
                    values = compareCookie.Values.GetValues(mcId);
                }

                if (values != null && values.Length > 0)
                {
                    foreach (string productId in values)
                    {
                        int prodId = Int32.Parse(productId);
                        if (!productIds.Contains(prodId))
                        {
                            productIds.Add(prodId);
                        }
                    }
                }

                if (productIds.Count == 0)
                {
                    return(products);
                }

                // get the products
                CatalogSearchParameters pars    = new CatalogSearchParameters();
                CatalogSearchOptions    options = new CatalogSearchOptions();

                options.CacheResults      = true;
                options.StartingRecord    = 0;
                options.RecordsToRetrieve = _MaxProductsToCompare;
                options.ReturnTotalCount  = true;
                //pars.SqlWhereClause = String.Format("ClassTypeId='{0}'", "product");

                pars.SqlWhereClause = String.Format("1=1");

                // add productids to where statement, since we need to return only selected products
                pars.SqlWhereClause += BuildWhereStatementForSearch(productIds);

                products = CatalogContext.Current.FindItems(pars, options, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
            }

            return(products);
        }