示例#1
0
        private IEnumerable <CatalogEntryDto.CatalogEntryRow> GetCatalogEntrys(IEnumerable <string> catalogNames)
        {
            // Changed to return all entries here
            string entryType = String.Empty;             //Mediachase.Commerce.Catalog.Objects.EntryType.Product.ToString();

            CatalogSearchParameters pars    = new CatalogSearchParameters();
            CatalogSearchOptions    options = new CatalogSearchOptions();

            options.RecordsToRetrieve = int.MaxValue;
            options.Namespace         = "Mediachase.Commerce.Catalog";
            options.StartingRecord    = 0;
            options.ReturnTotalCount  = true;
            //pars.SqlWhereClause = String.Format("[CatalogEntry].Name like '%{0}%' OR [CatalogEntry].Code like '%{0}%'", sFilter);

            // Add catalogs
            pars.CatalogNames.AddRange(catalogNames.ToArray());
            //CatalogDto catalogDto = CatalogContext.Current.GetCatalogDto();
            //foreach (CatalogDto.CatalogRow catalogRow in catalogDto.Catalog)
            //{
            //    pars.CatalogNames.Add(catalogRow.Name);
            //}

            int             totalRecords = 0;
            CatalogEntryDto dto          = CatalogContext.Current.FindItemsDto(pars, options, ref totalRecords);

            foreach (CatalogEntryDto.CatalogEntryRow entryRow in dto.CatalogEntry)
            {
                //ComboBoxItem item = new ComboBoxItem(entryRow.Name + " [" + entryRow.Code.ToString() + "]");
                //item.Value = entryRow.Code.ToString();
                //item["icon"] = Page.ResolveClientUrl(String.Format("~/app_themes/Default/images/icons/{0}.gif", entryRow.ClassTypeId));
                //EntriesFilter.Items.Add(item);
                yield return(entryRow);
            }
        }
示例#2
0
        public void Search_JoinQuery()
        {
            ICatalogSystem system = CatalogContext.Current;

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

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

                // Get Catalog Nodes
                CatalogNodeDto nodes = system.GetCatalogNodesDto(catalogName);
                foreach (CatalogNodeDto.CatalogNodeRow node in nodes.CatalogNode)
                {
                    CatalogSearchParameters pars    = new CatalogSearchParameters();
                    CatalogSearchOptions    options = new CatalogSearchOptions();
                    options.CacheResults = true;

                    pars.CatalogNames.Add(catalogName);
                    pars.CatalogNodes.Add(node.Code);
                    pars.JoinType           = "inner join";
                    pars.Language           = "en-us";
                    pars.JoinSourceTable    = "CatalogEntry";
                    pars.JoinTargetQuery    = "(select distinct ObjectId, DisplayName from CatalogEntryEx) CatalogEntryEx";
                    pars.JoinSourceTableKey = "CatalogEntryId";
                    pars.JoinTargetTableKey = "CatalogEntryEx.ObjectId";
                    pars.OrderByClause      = "CatalogEntryEx.DisplayName";

                    Entries entries = CatalogContext.Current.FindItems(pars, options, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
                }
            }
        }
示例#3
0
        private void WalkCatalogNodes(ICatalogSystem catalogSystem, CatalogNodeDto nodes, CatalogDto.CatalogRow catalog, Dictionary <int, CatalogEntryDto.CatalogEntryRow> catalogEntryRows)
        {
            foreach (CatalogNodeDto.CatalogNodeRow node in nodes.CatalogNode)
            {
                CatalogSearchParameters pars    = new CatalogSearchParameters();
                CatalogSearchOptions    options = new CatalogSearchOptions {
                    CacheResults = false
                };
                pars.CatalogNames.Add(catalog.Name);
                pars.CatalogNodes.Add(node.Code);
                //CatalogEntryDto entries = CatalogContext.Current.FindItemsDto(
                //    pars,
                //    options,
                //    ref count,
                //    new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
                CatalogEntryDto entries = catalogSystem.GetCatalogEntriesDto(catalog.CatalogId, node.CatalogNodeId,
                                                                             new CatalogEntryResponseGroup(
                                                                                 CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo));

                _log.DebugFormat("Entries in Node: {0} (Count: {1})", node.Name, entries.CatalogEntry.Rows.Count);
                foreach (CatalogEntryDto.CatalogEntryRow entry in entries.CatalogEntry)
                {
                    // _log.DebugFormat("{3}: {0} ({1} - {2})", entry.Name, entry.Code, entry.CatalogEntryId, entry.ClassTypeId);
                    if (catalogEntryRows.ContainsKey(entry.CatalogEntryId) == false)
                    {
                        catalogEntryRows.Add(entry.CatalogEntryId, entry);
                    }
                }

                // Get Subnodes
                CatalogNodeDto subNodes = catalogSystem.GetCatalogNodesDto(catalog.CatalogId, node.CatalogNodeId);
                WalkCatalogNodes(catalogSystem, subNodes, catalog, catalogEntryRows);
            }
        }
示例#4
0
        /// <summary>
        /// Gets the total records.
        /// </summary>
        /// <returns></returns>
        private int GetTotalRecords()
        {
            int            numRecords = 0;
            ICatalogSystem system     = CatalogContext.Current;

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

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

                // Get Catalog Nodes
                CatalogSearchParameters pars    = new CatalogSearchParameters();
                CatalogSearchOptions    options = new CatalogSearchOptions();
                options.CacheResults = false;
                pars.CatalogNames.Add(catalogName);
                options.RecordsToRetrieve = 1;
                options.StartingRecord    = 0;

                int             totalCount = 0;
                CatalogEntryDto entryDto   = CatalogContext.Current.FindItemsDto(pars, options, ref totalCount);
                numRecords += totalCount;
            }

            return(numRecords);
        }
示例#5
0
        public void CatalogSystem_UnitTest_SearchEntries()
        {
            ICatalogSystem system = CatalogContext.Current;

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

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

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


                // Search phrase arbitrary
                pars.FreeTextSearchPhrase = "policy";

                // Set language
                pars.Language = "en-us";

                pars.CatalogNames.Add(catalogName);

                Entries entries = CatalogContext.Current.FindItems(pars, options, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));

                // Meaningless assert - to be replaced with appropriate assert once the problem with search is figured out
                Assert.IsTrue(entries.TotalResults == entries.TotalResults);
                Console.WriteLine("Number of entries matching \"{0}\" in the {1} catalog: {2}", pars.FreeTextSearchPhrase, catalogName, entries.TotalResults);
            }
            //Assert.Inconclusive("Verify the correctness of this test method.");
        }
示例#6
0
        public void Search_BrowseEntries()
        {
            ICatalogSystem system = CatalogContext.Current;

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

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

                // Get Catalog Nodes
                CatalogNodeDto nodes = system.GetCatalogNodesDto(catalogName);
                foreach (CatalogNodeDto.CatalogNodeRow node in nodes.CatalogNode)
                {
                    CatalogSearchParameters pars    = new CatalogSearchParameters();
                    CatalogSearchOptions    options = new CatalogSearchOptions();
                    options.CacheResults = true;

                    pars.CatalogNames.Add(catalogName);
                    pars.CatalogNodes.Add(node.Code);

                    Entries entries = CatalogContext.Current.FindItems(pars, options, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
                }
            }
        }
示例#7
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)
        {
            CatalogSearch search = new CatalogSearch();

            search.SearchOptions    = options;
            search.SearchParameters = parameters;
            return(CatalogEntryManager.FindItems(search, new CatalogEntryResponseGroup()));
        }
示例#8
0
        /// <summary>
        /// Finds the nodes dto.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="options">The options.</param>
        /// <param name="recordsCount">The records count.</param>
        /// <returns></returns>
        public CatalogNodeDto FindNodesDto(CatalogSearchParameters parameters, CatalogSearchOptions options, ref int recordsCount)
        {
            CatalogSearch search = new CatalogSearch();

            search.SearchOptions    = options;
            search.SearchParameters = parameters;
            return(CatalogNodeManager.FindNodesDto(search, ref recordsCount, new CatalogNodeResponseGroup()));
        }
示例#9
0
        /// <summary>
        /// Finds the items dto.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="options">The options.</param>
        /// <param name="recordsCount">The records count.</param>
        /// <param name="responseGroup">The response group.</param>
        /// <returns></returns>
        public CatalogEntryDto FindItemsDto(CatalogSearchParameters parameters, CatalogSearchOptions options, ref int recordsCount, CatalogEntryResponseGroup responseGroup)
        {
            CatalogSearch search = new CatalogSearch();

            search.SearchOptions    = options;
            search.SearchParameters = parameters;
            return(CatalogEntryManager.FindItemsDto(search, ref recordsCount, responseGroup));
        }
示例#10
0
        /// <summary>
        /// Loads the items.
        /// </summary>
        /// <param name="iStartIndex">Start index of the i.</param>
        /// <param name="iNumItems">The i num items.</param>
        /// <param name="sFilter">The s filter.</param>
        private void LoadItems(int iStartIndex, int iNumItems, string sFilter)
        {
            // This method filters which entries to display in the search results.
            // By default the system displays only variations for product variations. So for instance
            // product can not have sub products and any entry for all other types of products. So
            // for instance package can have other packages and related items.
            // This behaviour can be customized by modifying the following IF statement.
            string entryType = EntryType.Variation.ToString();

            if (RelationTypeId == EntryRelationType.ProductVariation.ToString())
            {
                entryType = EntryType.Variation.ToString();
            }
            else
            {
                entryType = String.Empty;
            }

            CatalogSearchParameters pars    = new CatalogSearchParameters();
            CatalogSearchOptions    options = new CatalogSearchOptions();

            options.RecordsToRetrieve = iNumItems;
            options.Namespace         = "Mediachase.Commerce.Catalog";
            options.StartingRecord    = iStartIndex;
            options.ReturnTotalCount  = true;
            pars.SqlWhereClause       = String.Format("[CatalogEntry].Name like '%{0}%' OR [CatalogEntry].Code like '%{0}%'", sFilter);
            if (!String.IsNullOrEmpty(entryType))
            {
                pars.SqlWhereClause = pars.SqlWhereClause + String.Format(" AND ClassTypeId='{0}'", entryType);
            }

            // Add catalogs
            CatalogDto catalogDto = CatalogContext.Current.GetCatalogDto();

            foreach (CatalogDto.CatalogRow catalogRow in catalogDto.Catalog)
            {
                pars.CatalogNames.Add(catalogRow.Name);
            }

            int             totalRecords = 0;
            CatalogEntryDto dto          = CatalogContext.Current.FindItemsDto(pars, options, ref totalRecords);

            //CatalogEntryDto dto = CatalogContext.Current.GetCatalogEntriesDto(String.Format("%{0}%", sFilter), entryType);

            ItemsFilter.Items.Clear();

            foreach (CatalogEntryDto.CatalogEntryRow row in dto.CatalogEntry)
            {
                ComboBoxItem item = new ComboBoxItem(row.Name);
                item.Value   = row.CatalogEntryId.ToString();
                item["icon"] = Page.ResolveClientUrl(String.Format("~/app_themes/Default/images/icons/{0}.gif", row.ClassTypeId));
                ItemsFilter.Items.Add(item);
            }

            ItemsFilter.ItemCount = totalRecords;
        }
        private void InitDataSource()
        {
            CatalogSearchParameters pars = new CatalogSearchParameters();

            // language filter
            pars.Language = ListLanguages.SelectedValue;

            // catalog filter
            //CatalogDto dto = CatalogContext.Current.GetCatalogDto();
            //foreach (CatalogDto.CatalogRow row in dto.Catalog.Rows)
            //{
            //    pars.CatalogNames.Add(row.Name);
            //}
            if (ListCatalogs.SelectedValue == "[all]")
            {
                foreach (ListItem item in ListCatalogs.Items)
                {
                    if (item.Value == "[all]")
                    {
                        continue;
                    }

                    pars.CatalogNames.Add(item.Value);
                }
            }
            else if (ListCatalogs.SelectedIndex >= 0)            // selected catalogs
            {
                for (int iTmp = 0; iTmp < ListCatalogs.Items.Count; iTmp++)
                {
                    ListItem li = ListCatalogs.Items[iTmp];
                    if (li.Selected)
                    {
                        pars.CatalogNames.Add(li.Value);
                    }
                }
            }
            pars.FreeTextSearchPhrase = tbKeywords.Text;
            CatalogSearchOptions opts = new CatalogSearchOptions();

            opts.RecordsToRetrieve = Int32.MaxValue;
            opts.Namespace         = "Mediachase.Commerce.Catalog";
            opts.StartingRecord    = 0;
            opts.ReturnTotalCount  = true;
            CatalogEntryResponseGroup respgroup = new CatalogEntryResponseGroup();
            int             totalRecordsCount   = 0;
            CatalogEntryDto entries             = CatalogContext.Current.FindItemsDto(pars, opts, ref totalRecordsCount, respgroup);

            if (totalRecordsCount > 0)
            {
                lbSource.DataSource = entries.CatalogEntry.Rows;
            }
        }
示例#12
0
        public void CatalogSystem_UnitTest_BrowseEntries()
        {
            ICatalogSystem system = CatalogContext.Current;

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

            // Number of entries in CatalogEntry table
            int entryCount = 0;

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

                // Get Catalog Nodes
                CatalogNodeDto nodes = system.GetCatalogNodesDto(catalogName);
                foreach (CatalogNodeDto.CatalogNodeRow node in nodes.CatalogNode)
                {
                    CatalogSearchParameters pars    = new CatalogSearchParameters();
                    CatalogSearchOptions    options = new CatalogSearchOptions();
                    options.CacheResults = true;

                    pars.Language = "en-us";

                    pars.CatalogNames.Add(catalogName);
                    pars.CatalogNodes.Add(node.Code);

                    // Test does not seem to be working: entries are mostly returning empty.
                    Entries entries = CatalogContext.Current.FindItems(pars, options, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));

                    try
                    {
                        foreach (Entry entry in entries.Entry)
                        {
                            // Something to do? Just looking at entries
                            entryCount++;
                        }
                    }
                    catch (Exception e)
                    {
                        Assert.IsFalse(new NullReferenceException().Equals(e));
                    }
                }
            }
            // As of testing 4/19/09, entryCount incremented 22 times (there are over 1300 entries in the table CatalogEntry)
            Console.WriteLine("Number of entries browsed: {0:d}", entryCount);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
示例#13
0
        /// <summary>
        /// Finds the items. Results can be cached. Caching parameters are specified in CatalogSearch variable.
        /// </summary>
        /// <param name="search">The search.</param>
        /// <param name="responseGroup">The response group.</param>
        /// <returns></returns>
        internal static Entries FindItems(CatalogSearch search, CatalogEntryResponseGroup responseGroup)
        {
            // Assign new cache key, specific for site guid and response groups requested
            string cacheKey = String.Empty;

            // Only cache results if specified
            if (search.SearchOptions.CacheResults)
            {
                cacheKey = CatalogCache.CreateCacheKey("catalog-entries", responseGroup.CacheKey, search.CacheKey);

                // check cache first
                object cachedObject = CatalogCache.Get(cacheKey);

                if (cachedObject != null)
                {
                    return((Entries)cachedObject);
                }
            }

            int recordsCount = 0;

            CatalogSearchOptions opt = search.SearchOptions;
            CatalogEntryDto      dto = FindItemsDto2(search, ref recordsCount, responseGroup);

            Entries items = new Entries();

            if (dto.CatalogEntry.Count > 0)
            {
                items = LoadEntries(dto, null, true, responseGroup);
            }

            items.TotalResults = recordsCount;
            items.TotalPages   = (int)Math.Ceiling((decimal)recordsCount / opt.RecordsToRetrieve);

            if (!String.IsNullOrEmpty(cacheKey)) // cache results
            {
                // Insert to the cache collection
                CatalogCache.Insert(cacheKey, items, search.SearchOptions.CacheTimeout);
            }

            return(items);
        }
示例#14
0
        public void Search_AdvancedFTS()
        {
            ICatalogSystem system = CatalogContext.Current;

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

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

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

                pars.AdvancedFreeTextSearchPhrase = "(\"sweet and savory\" NEAR sauces) OR (\"sweet and savory\" NEAR candies)";
                pars.CatalogNames.Add(catalogName);

                Entries entries = CatalogContext.Current.FindItems(pars, options, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
            }
        }
        /// <summary>
        /// Returns products to compare.
        /// </summary>
        /// <param name="mcId">Id of a metaClass.</param>
        /// <returns></returns>
        public static CatalogEntryDto GetCompareProductsDto(string mcId)
        {
            CatalogEntryDto products      = null;
            HttpCookie      compareCookie = HttpContext.Current.Request.Cookies.Get(MakeCurrentApplicationCookieName(_CompareCookieItemsName));

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

                string[] 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);
                        }
                    }
                }

                // 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}'", EntryType.Product);

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

                int totalCount = 0;
                products = CatalogContext.Current.FindItemsDto(pars, options, ref totalCount, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull));
            }
            return(products);
        }
        /// <summary>
        /// Loads the association items.
        /// </summary>
        /// <param name="iStartIndex">Start index of the i.</param>
        /// <param name="iNumItems">The i num items.</param>
        /// <param name="sFilter">The s filter.</param>
        private void LoadAssociationItems(int iStartIndex, int iNumItems, string sFilter)
        {
            AssociataionItemsFilter.Items.Clear();

            // Changed to return all entries here
            string entryType = String.Empty; //Mediachase.Commerce.Catalog.Objects.EntryType.Product.ToString();

            CatalogSearchParameters pars    = new CatalogSearchParameters();
            CatalogSearchOptions    options = new CatalogSearchOptions();

            options.RecordsToRetrieve = iNumItems;
            options.Namespace         = "Mediachase.Commerce.Catalog";
            options.StartingRecord    = iStartIndex;
            options.ReturnTotalCount  = true;
            pars.SqlWhereClause       = String.Format("[CatalogEntry].Name like '%{0}%'", sFilter);

            // Add catalogs
            CatalogDto catalogDto = CatalogContext.Current.GetCatalogDto();

            foreach (CatalogDto.CatalogRow catalogRow in catalogDto.Catalog)
            {
                pars.CatalogNames.Add(catalogRow.Name);
            }

            int             totalRecords = 0;
            CatalogEntryDto dto          = CatalogContext.Current.FindItemsDto(pars, options, ref totalRecords);

            //CatalogEntryDto dto = CatalogContext.Current.GetCatalogEntriesDto(String.Format("%{0}%", sFilter), entryType);

            foreach (CatalogEntryDto.CatalogEntryRow entryRow in dto.CatalogEntry)
            {
                ComboBoxItem item = new ComboBoxItem(entryRow.Name);
                item.Value   = entryRow.CatalogEntryId.ToString();
                item["icon"] = Page.ResolveClientUrl(String.Format("~/app_themes/Default/images/icons/{0}.gif", entryRow.ClassTypeId));
                AssociataionItemsFilter.Items.Add(item);
            }

            AssociataionItemsFilter.ItemCount = totalRecords;// dto.CatalogEntry.Count;
        }
示例#17
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));
 }
        /// <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);
        }
示例#19
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);
        }
示例#20
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);
        }
示例#21
0
 /// <summary>
 /// Finds the nodes dto.
 /// </summary>
 /// <param name="parameters">The parameters.</param>
 /// <param name="options">The options.</param>
 /// <param name="recordsCount">The records count.</param>
 /// <param name="responseGroup">The response group.</param>
 /// <returns></returns>
 public CatalogNodeDto FindNodesDto(CatalogSearchParameters parameters, CatalogSearchOptions options, ref int recordsCount, CatalogNodeResponseGroup responseGroup)
 {
     return(_Proxy.FindNodesDto(parameters, options, ref recordsCount, responseGroup));
 }
示例#22
0
 /// <summary>
 /// Finds the items dto.
 /// </summary>
 /// <param name="parameters">The parameters.</param>
 /// <param name="options">The options.</param>
 /// <param name="recordsCount">The records count.</param>
 /// <returns></returns>
 public CatalogEntryDto FindItemsDto(CatalogSearchParameters parameters, CatalogSearchOptions options, ref int recordsCount)
 {
     return(_Proxy.FindItemsDto(parameters, options, ref recordsCount));
 }
示例#23
0
 /// <summary>
 /// Finds the items.
 /// </summary>
 /// <param name="parameters">The parameters.</param>
 /// <param name="options">The options.</param>
 /// <param name="responseGroup">The response group.</param>
 /// <returns></returns>
 public Entries FindItems(CatalogSearchParameters parameters, CatalogSearchOptions options, CatalogEntryResponseGroup responseGroup)
 {
     return(_Proxy.FindItems(parameters, options, responseGroup));
 }
示例#24
0
文件: Program.cs 项目: hdgardner/ECF
        /// <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));
            }
        }