Пример #1
0
        /// <summary>Checks if the trash is enabled, the item is not already thrown and for the NotThrowable attribute.</summary>
        /// <param name="affectedItem">The item to check.</param>
        /// <returns>True if the item may be thrown.</returns>
        public bool CanThrow(ContentItem affectedItem)
        {
            TrashContainerItem trash = GetTrashContainer(false);
            bool enabled             = trash == null || trash.Enabled;
            bool alreadyThrown       = IsInTrash(affectedItem);

            var  throwables = (ThrowableAttribute[])affectedItem.GetContentType().GetCustomAttributes(typeof(ThrowableAttribute), true);
            bool throwable  = throwables.Length == 0 || throwables[0].Throwable == AllowInTrash.Yes;

            return(enabled && !alreadyThrown && throwable);
        }
Пример #2
0
        /// <summary>Delete items lying in trash for longer than the specified interval.</summary>
        public void PurgeOldItems()
        {
            TrashContainerItem trash = GetTrashContainer(false);

            if (trash == null)
            {
                return;
            }
            if (trash.PurgeInterval == TrashPurgeInterval.Never)
            {
                return;
            }

            DateTime            tresholdDate = Utility.CurrentTime().AddDays(-(int)trash.PurgeInterval);
            IList <ContentItem> expiredItems = null;

            if (UseNavigationMode)
            {
                expiredItems = trash.Children
                               .Where(i => i[DeletedDate] != null)
                               .Where(i => ((DateTime)i[DeletedDate]) < tresholdDate)
                               .ToList();
            }
            else
            {
                expiredItems = finder.Where.Parent.Eq(trash)
                               .And.Detail(TrashHandler.DeletedDate).Le(tresholdDate)
                               .Select();
            }

            try
            {
                security.ScopeEnabled = false;
                foreach (var item in expiredItems)
                {
                    persister.Delete(item);
                }
            }
            finally
            {
                security.ScopeEnabled = true;
            }
        }
        public void TestFixtureSetUp()
        {
            engine = new ContentEngine();
            var schemaCreator = new SchemaExport(engine.Resolve<IConfigurationBuilder>().BuildConfiguration());
            schemaCreator.Execute(false, true, false, engine.Resolve<ISessionProvider>().OpenSession.Session.Connection, null);

            engine.Initialize();
            engine.SecurityManager.Enabled = false;

            root = new ThrowableItem();
            root.Name = "root";

            engine.Persister.Save(root);
            engine.Resolve<IHost>().DefaultSite.RootItemID = root.ID;
            engine.Resolve<IHost>().DefaultSite.StartPageID = root.ID;

            currentTimeBackup = Utility.CurrentTime;

            trash = ((TrashHandler)engine.Resolve<ITrashHandler>()).GetTrashContainer(true);
        }
Пример #4
0
        /// <summary>Determines wether an item has been thrown away.</summary>
        /// <param name="item">The item to check.</param>
        /// <returns>True if the item is in the scraps.</returns>
        public bool IsInTrash(ContentItem item)
        {
            TrashContainerItem trash = GetTrashContainer(false);

            return(trash != null && Find.IsDescendantOrSelf(item, trash));
        }