Example #1
0
        /// <summary>
        /// Loads the entry.
        /// </summary>
        /// <param name="admin">The admin.</param>
        /// <param name="row">The row.</param>
        /// <param name="responseGroup">The response group.</param>
        private static void LoadEntry(CatalogEntryAdmin admin, CatalogEntryDto.CatalogEntryRow row, CatalogEntryResponseGroup responseGroup)
        {
            if (responseGroup.ContainsGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull))
            {
                // Load Variations
                admin.LoadVariation(row.CatalogEntryId);

                // Load inventory
                admin.LoadInventory(row.CatalogEntryId);
            }

            if (responseGroup.ContainsGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull) || responseGroup.ContainsGroup(CatalogEntryResponseGroup.ResponseGroup.Associations))
            {
                // Load Associations
                admin.LoadAssociation(row.CatalogEntryId);
            }

            if (responseGroup.ContainsGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull) || responseGroup.ContainsGroup(CatalogEntryResponseGroup.ResponseGroup.Assets))
            {
                // Load Associations
                admin.LoadAssets(row.CatalogEntryId);
            }
        }
Example #2
0
        /// <summary>
        /// Loads the entry.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="recursive">if set to <c>true</c> [recursive].</param>
        /// <param name="responseGroup">The response group.</param>
        /// <param name="entryList">The entry list.</param>
        /// <returns></returns>
        internal static Entry LoadEntry(CatalogEntryDto.CatalogEntryRow row, bool recursive, CatalogEntryResponseGroup responseGroup, ref StringCollection entryList)
        {
            Entry entry = null;

            // Load entry
            if (row != null)
            {
                // Track entries added, to avoid circular dependencies
                entryList.Add(row.Code);

                entry = new Entry(row);

                // Populate association detailed info
                if (recursive && (responseGroup.ContainsGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull) || responseGroup.ContainsGroup(CatalogEntryResponseGroup.ResponseGroup.Associations)))
                {
                    if (entry.Associations != null)
                    {
                        CatalogAssociationDto associationDto = CatalogAssociationManager.GetCatalogAssociationDtoByEntryId(row.CatalogEntryId);

                        // If associations do not contain any entries, then we do not need to go through the rest
                        if (associationDto.CatalogEntryAssociation.Count > 0)
                        {
                            foreach (Association association in entry.Associations)
                            {
                                int associationId = 0;
                                // Find out association id
                                foreach (CatalogAssociationDto.CatalogAssociationRow associationRow in associationDto.CatalogAssociation)
                                {
                                    if (associationRow.AssociationName.Equals(association.Name))
                                    {
                                        associationId = associationRow.CatalogAssociationId;
                                        break;
                                    }
                                }

                                // Load association entries
                                List <EntryAssociation> entryAssociationList = new List <EntryAssociation>();
                                CatalogEntryDto         associatedEntries    = GetAssociatedCatalogEntriesDto(row.CatalogEntryId, association.Name, responseGroup);
                                foreach (CatalogEntryDto.CatalogEntryRow childRow in associatedEntries.CatalogEntry)
                                {
                                    EntryAssociation entryAssociation = new EntryAssociation();
                                    // Find appropriate row
                                    CatalogAssociationDto.CatalogEntryAssociationRow entryAssociationRow = associationDto.CatalogEntryAssociation.FindByCatalogAssociationIdCatalogEntryId(associationId, childRow.CatalogEntryId);
                                    if (entryAssociationRow != null)
                                    {
                                        entryAssociation.SortOrder       = entryAssociationRow.SortOrder;
                                        entryAssociation.AssociationType = entryAssociationRow.AssociationTypeId;
                                        entryAssociation.AssociationDesc = entryAssociationRow.AssociationTypeRow.Description;
                                    }

                                    // Check for circular dependencies here

                                    /*
                                     * if (row.CatalogEntryId == childRow.CatalogEntryId)
                                     *  throw new CircularDependencyException(String.Format("Circular dependency detected. Entry association \"{0}\" for \"{1}[{2}]\" contains reference to itself.", entryAssociation.AssociationDesc, childRow.Name, childRow.CatalogEntryId));
                                     * */

                                    bool loadRecursive = recursive;

                                    // do not load recursive if there is potential circular dependency
                                    if (entryList.Contains(row.Code))
                                    {
                                        loadRecursive = false;
                                    }

                                    Entry childEntry = LoadEntry(childRow, loadRecursive, responseGroup, ref entryList);
                                    childEntry.ParentEntry = null;
                                    entryAssociation.Entry = childEntry;

                                    entryAssociationList.Add(entryAssociation);
                                }

                                association.EntryAssociations             = new EntryAssociations();
                                association.EntryAssociations.Association = entryAssociationList.ToArray();
                            }
                        }
                    }
                }

                // Populate children
                if (recursive && (responseGroup.ContainsGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull) || responseGroup.ContainsGroup(CatalogEntryResponseGroup.ResponseGroup.Children)))
                {
                    bool loadRecursive = recursive;

                    // do not load recursive if there is potential circular dependency
                    if (entryList.Contains(row.Code))
                    {
                        loadRecursive = false;
                    }

                    CatalogEntryDto childrenDto = GetCatalogEntriesDto(row.CatalogEntryId, String.Empty, String.Empty, responseGroup);
                    Entries         entries     = LoadEntries(childrenDto, entry, loadRecursive, responseGroup, ref entryList);
                    entry.Entries = entries;
                }
            }

            /*
             * else
             *  entry = new Entry();
             * */

            return(entry);
        }