Ejemplo n.º 1
0
 protected void OnItemSaved(object sender, System.EventArgs args)
 {
     if ((args != null))
     {
         Item item = Event.ExtractParameter(args, 0) as Item;
         Assert.IsNotNull(item, "No item in parameters");
         ID parentID = item.ParentID;
         if (BucketManager.IsItemContainedWithinBucket(item))
         {
             parentID = item.GetParentBucketItemOrParent().ParentID;
         }
         IHasExternalId i = item.GlassCast <IHasExternalId>();
         if (i != null && !string.IsNullOrEmpty(i.ExternalId))
         {
             string prefix = i.TemplateId.GetMatchingPrefix();
             if (IDTable.GetID(prefix, i.ExternalId) == null)
             {
                 IDTable.Add(prefix, i.ExternalId, item.ID, parentID);
             }
         }
         else if (parentID.Equals(RebootConstants.ImageRootID))
         {
             string prefix = RebootConstants.ImageItemPrefix;
             if (IDTable.GetID(prefix, item.Name) == null)
             {
                 IDTable.Add(prefix, item.Name, item.ID, parentID);
             }
         }
     }
 }
Ejemplo n.º 2
0
        public IEnumerable <Guid> GetGenreIDs(IEnumerable <int> ids)
        {
            List <Guid> genreIDs =
                (ids.Select(id => IDTable.GetID(typeof(GenreModel).ToString(), id.ToString()))
                 .Where(idTableEntry => idTableEntry != null)
                 .Select(idTableEntry => idTableEntry.ID.Guid)).ToList();

            return(genreIDs);
        }
Ejemplo n.º 3
0
        internal static ID GetItemIdFromIDTableEntry(string prefix, string key)
        {
            IDTableEntry idTableEntry = IDTable.GetID(prefix, key);

            if (idTableEntry == null)
            {
                return(ID.Null);
            }
            return(idTableEntry.ID);
        }
        private static string GetEncryptionKey([NotNull] Item targetIntegrationItem)
        {
            Assert.ArgumentNotNull(targetIntegrationItem, "targetIntegrationItem");

            IDTableEntry encryptionKeyEntry = IDTable.GetID(EncryptionKeyIDTableEntryPrefix, targetIntegrationItem.ID.ToShortID().ToString());

            if (encryptionKeyEntry == null)
            {
                return(null);
            }

            return(encryptionKeyEntry.CustomData);
        }
Ejemplo n.º 5
0
        public IDTableEntry GetID(string prefix, string key)
        {
            var idTableStringKey = new IdTableStringKey(prefix, key);

            //if (_idByKey.ContainsKey(idTableStringKey))
            //{
            //    return _idByKey[idTableStringKey];
            //}

            _idByKey[idTableStringKey] = IDTable.GetID(prefix, key);

            return(_idByKey[idTableStringKey]);
        }
Ejemplo n.º 6
0
        public override void Execute(CommandContext context)
        {
            IEnumerable <Type> allGlassBasedModels = null;

            allGlassBasedModels = ReflectionHelper.GetAllTypesThatImplement <GlassBase>(
                new List <string>
            {
                "Projects.Common.Models",
                "Projects.Reboot.Models"
            }
                );
            Database database    = Factory.GetDatabase("master");
            Item     modelFolder = database.GetItem(RebootConstants.ModelRootId);

            foreach (var glassModel in allGlassBasedModels.Where(t => !t.IsAbstract))
            {
                Log.Info(string.Format("Adding model {0} to Sitecore", glassModel.FullName), context);
                string       displayName  = glassModel.Name;
                string       name         = ItemUtil.ProposeValidItemName(glassModel.FullName.Replace(".", "_"));
                string       prefix       = RebootConstants.ModelTemplateId.ToString();
                string       key          = name;
                IDTableEntry idTableEntry = IDTable.GetID(prefix, key);
                if (idTableEntry != null)
                {
                    continue;
                }
                Item model = modelFolder.Add(name, new TemplateID(RebootConstants.ModelTemplateId));
                if (model == null)
                {
                    continue;
                }
                using (new SecurityDisabler())
                {
                    model.Editing.BeginEdit();
                    try
                    {
                        model.Appearance.DisplayName = displayName;
                        model["Model Type"]          = glassModel.AssemblyQualifiedName;
                    }
                    catch (Exception ex)
                    {
                        Log.Error("An error occured while editing Model " + displayName, context);
                        model.Editing.CancelEdit();
                    }
                    finally
                    {
                        model.Editing.EndEdit();
                    }
                }
            }
        }
Ejemplo n.º 7
0
        internal static ID GetItemIdFromIDTableEntry <T>(this T obj, string key) where T : class, IHasExternalId
        {
            if (obj == null)
            {
                return(ID.Null);
            }
            string       prefix       = obj.GetType().ToString();
            IDTableEntry idTableEntry = IDTable.GetID(prefix, key);

            if (idTableEntry == null)
            {
                return(ID.Null);
            }
            return(idTableEntry.ID);
        }
Ejemplo n.º 8
0
        // From the entity ID, get the Sitecore ID.
        // Also can creates the new ID if one does not exist.
        private ID getSitecoreId(Guid id, ID parentId, Boolean createIfNotExist = true)
        {
            var tableEntry = IDTable.GetID(IDTablePrefix, id.ToString());

            if (tableEntry == null && createIfNotExist)
            {
                tableEntry = IDTable.GetNewID(IDTablePrefix, id.ToString(), parentId);
            }
            if (tableEntry != null)
            {
                Trace.WriteLine(String.Format("{0} (repository) is {1} (sitecore)", id, tableEntry.ID), "ProductDataProvider");
                return(tableEntry.ID);
            }
            Trace.WriteLine(String.Format("{0} doesn't have a Sitecore id", id), "ProductDataProvider");
            return(null);
        }
Ejemplo n.º 9
0
        public void ShouldSwitchIdTableProvider()
        {
            // arrange
            var switchedProvider = Substitute.For <IDTableProvider>();

            var fixture = new Fixture();
            var entry   = fixture.Create <IDTableEntry>();

            switchedProvider.GetID("prefix", "key").Returns(entry);

            // act
            using (new IDTableProviderSwitcher(switchedProvider))
            {
                // assert
                IDTable.GetID("prefix", "key").Should().BeSameAs(entry);
            }
        }
Ejemplo n.º 10
0
 public override IDList GetChildIDs(ItemDefinition itemDefinition, CallContext context)
 {
     if (itemDefinition.ID == ID.Parse(_parentItem))
     {
         context.Abort();
         XmlNodeList videos   = VideoData.SelectNodes("/response/videos/video");
         IDList      videoIDs = new IDList();
         foreach (XmlNode video in videos)
         {
             string       videoKey = video.Attributes["key"].Value;
             IDTableEntry mappedID = IDTable.GetID(ID_TABLE_PREFIX, videoKey);
             if (mappedID == null)
             {
                 mappedID = IDTable.GetNewID(ID_TABLE_PREFIX, videoKey, ID.Parse(_parentItem));
             }
             videoIDs.Add(mappedID.ID);
         }
         return(videoIDs);
     }
     return(base.GetChildIDs(itemDefinition, context));
 }
Ejemplo n.º 11
0
 protected void OnItemSaved(object sender, System.EventArgs args)
 {
     if ((args != null))
     {
         Item item = Event.ExtractParameter(args, 0) as Item;
         Assert.IsNotNull(item, "No item in parameters");
         if (!item.TemplateID.Equals(RebootConstants.ModelTemplateId))
         {
             return;
         }
         ID parentID = item.ParentID;
         if (BucketManager.IsItemContainedWithinBucket(item))
         {
             parentID = item.GetParentBucketItemOrParent().ParentID;
         }
         string       prefix       = item.TemplateID.ToString();
         string       key          = item.Name;
         IDTableEntry idTableEntry = IDTable.GetID(prefix, key);
         if (idTableEntry == null)
         {
             IDTable.Add(prefix, key, item.ID, parentID);
         }
     }
 }
Ejemplo n.º 12
0
        public override IDList GetChildIDs(ItemDefinition itemDefinition, CallContext context)
        {
            if (this.CanProcessParent(itemDefinition.ID, context))
            {
                context.Abort();

                var idList   = new IDList();
                ID  parentId = itemDefinition.ID;

                var database   = context.DataManager.Database;
                var actualItem = database.GetItem(parentId);

                var values = this.DataProviderDamHelper.ProcessingParentFieldNames.ToDictionary(fieldName => fieldName, fieldName => actualItem[fieldName]);

                var keyList = this.DataProviderDamHelper.GetChildKeys(values);

                var keys = keyList as string[] ?? keyList.ToArray();
                if (!keys.Any())
                {
                    return(new IDList());
                }

                foreach (var key in keys)
                {
                    if (string.IsNullOrEmpty(key))
                    {
                        continue;
                    }

                    var keyString = key + "|" + parentId.ToShortID();

                    IDTableEntry idEntry = IDTable.GetID(this.IdTablePrefix,
                                                         keyString);
                    ID newID;
                    if (idEntry == null)
                    {
                        var itemName = this.DataProviderDamHelper.GetItemName(key);

                        if (itemName == "Undefined")
                        {
                            continue;
                        }

                        newID = ID.NewID;
                        IDTable.Add(this.IdTablePrefix,
                                    keyString,
                                    newID, parentId, ItemUtil.ProposeValidItemName(Path.GetFileNameWithoutExtension(itemName)));
                    }
                    else
                    {
                        newID = idEntry.ID;
                    }
                    idList.Add(newID);
                }

                context.DataManager.Database.Caches.DataCache.Clear();

                return(idList);
            }

            return(base.GetChildIDs(itemDefinition, context));
        }
Ejemplo n.º 13
0
        internal static bool HasIDTableEntry(string prefix, string key)
        {
            IDTableEntry idTableEntry = IDTable.GetID(prefix, key);

            return(idTableEntry != null);
        }
 public IDTableEntry GetID(string prefix, string key)
 {
     return(IDTable.GetID(prefix, key));
 }