コード例 #1
0
        /// <summary>
        /// Given a destination Item, this will create the structures on this item to host unstructured data
        /// </summary>
        /// <returns>This will return the destination parent Item that hosts the new Item</returns>
        /// <param name="topParent">Gets the root of where this item will be created</param>
        /// <param name="childItemCreationDateTime">Determins the folder that the item will be created within</param>
        internal static Item CreateAndReturnDateFolderDestination(Item topParent, DateTime childItemCreationDateTime)
        {
            #if NET40
            Contract.Requires(topParent.IsNotNull());
            Contract.Requires(childItemCreationDateTime.IsNotNull());
            #else
            Assert.ArgumentNotNull(topParent, "topParent");
            Assert.ArgumentNotNull(childItemCreationDateTime, "childItemCreationDateTime");
            #endif

            var database = topParent.Database;
            var dateFolder = childItemCreationDateTime.ToString(Config.BucketFolderPath);
            var destinationFolderPath = topParent.Paths.FullPath + Constants.ContentPathSeperator + dateFolder;
            Item destinationFolderItem;

            // TODO: Use the Path Cache to determine if the path exists instead of looking it up on the item everytime I create an item (will be noticed if programmatically adding items)
            if ((destinationFolderItem = database.GetItem(destinationFolderPath)).IsNull())
            {
                var containerTemplate = database.Templates[new TemplateID(Config.ContainerTemplateId)];
                destinationFolderItem = database.CreateItemPath(destinationFolderPath, containerTemplate, containerTemplate);
            }

            using (new SecurityDisabler())
            {
                topParent.GetChildren().ToList().ForEach(HideItem);
            }

            #if NET40
            Contract.Ensures(destinationFolderItem.IsNotNull());
            #else
            Assert.IsTrue(destinationFolderItem.IsNotNull(), "destinationFolderItem cannot be null");
            #endif
            return destinationFolderItem;
        }
コード例 #2
0
        /// <summary>
        /// Given a destination Item, this will create the structures on this item to host unstructured data
        /// </summary>
        /// <returns>This will return the destination parent Item that hosts the new Item</returns>
        /// <param name="topParent">Gets the root of where this item will be created</param>
        /// <param name="childItemCreationDateTime">Determins the folder that the item will be created within</param>
        internal static Item CreateAndReturnDateFolderDestination(Item topParent, DateTime childItemCreationDateTime)
        {
            Contract.Requires(topParent.IsNotNull());
            Contract.Requires(childItemCreationDateTime.IsNotNull());

            var database = topParent.Database;
            var dateFolder = childItemCreationDateTime.ToString(Config.BucketFolderPath);
            DateTimeFormatInfo dateTimeInfo = System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat;

            if (dateTimeInfo.DateSeparator != Constants.ContentPathSeperator)
            {
                Log.Info("ItemBuckets. DateTimeFormat inconsistency. Current date separator is " + dateTimeInfo.DateSeparator + " and time separator is " + dateTimeInfo.TimeSeparator + ". Relative path to folder is " + dateFolder, new object());
                dateFolder = dateFolder.Replace(dateTimeInfo.DateSeparator, Constants.ContentPathSeperator).Replace(dateTimeInfo.TimeSeparator,Constants.ContentPathSeperator);
            }

            var destinationFolderPath = topParent.Paths.FullPath + Constants.ContentPathSeperator + dateFolder;
            Item destinationFolderItem;

            // TODO: Use the Path Cache to determine if the path exists instead of looking it up on the item everytime I create an item (will be noticed if programmatically adding items)
            if ((destinationFolderItem = database.GetItem(destinationFolderPath)).IsNull())
            {
                var containerTemplate = database.Templates[new TemplateID(Config.ContainerTemplateId)];
                destinationFolderItem = database.CreateItemPath(destinationFolderPath, containerTemplate, containerTemplate);
            }

            using (new SecurityDisabler())
            {
                topParent.GetChildren().ToList().ForEach(HideItem);
            }

            Contract.Ensures(destinationFolderItem.IsNotNull());

            return destinationFolderItem;
        }