public ActionResult DeleteBlobs()
        {
            IContentRepository repo        = ServiceLocator.Current.GetInstance <IContentRepository>();
            IBlobFactory       blobFactory = ServiceLocator.Current.GetInstance <IBlobFactory>();
            var           assetHelper      = ServiceLocator.Current.GetInstance <ContentAssetHelper>();
            StringBuilder sb = new StringBuilder();

            IEnumerable <ContentReference> contentReferences = null;

            contentReferences = repo.GetDescendents(EPiServer.Core.ContentReference.GlobalBlockFolder);
            DeleteBlobs(contentReferences, repo, sb, blobFactory);
            DeleteContentInAssetFolders(contentReferences, assetHelper, repo, sb, blobFactory);

            contentReferences = repo.GetDescendents(EPiServer.Core.ContentReference.SiteBlockFolder);
            DeleteBlobs(contentReferences, repo, sb, blobFactory);
            DeleteContentInAssetFolders(contentReferences, assetHelper, repo, sb, blobFactory);

            // Private page folders too
            contentReferences = repo.GetDescendents(EPiServer.Core.ContentReference.StartPage);
            DeleteContentInAssetFolders(contentReferences, assetHelper, repo, sb, blobFactory);

            ContentResult result = new ContentResult();

            result.Content = sb.ToString();
            return(result);
        }
        public virtual IHttpActionResult QueryDescendents(string Reference, [FromBody] ExpandoObject Query, string contenttype = null, string Select = null, int Skip = 0, int Take = 100)
        {
            var r = LookupRef(Reference);

            if (r == ContentReference.EmptyReference)
            {
                return(NotFound());
            }
            var             descendents = _repo.GetDescendents(r);
            List <IContent> ToReturn    = new List <IContent>(Take + Skip);
            int             Skipped     = 0;

            foreach (var d in descendents)
            {
                var c = _repo.Get <IContent>(d);
                //if((contenttype!=null) && (c.ContentTypeID))
                //TODO: Apply Queries

                if (Skip > Skipped)
                {
                    Skipped++; continue;
                }
                ToReturn.Add(c);
                if (ToReturn.Count == Take)
                {
                    break;
                }
            }
            return(Ok(ToReturn.Select(c => ConstructExpandoObject(c, Select)).ToArray()));
        }
        public virtual IEnumerable <T> GetDescendents <T>(ContentReference contentLink, IEnumerable <ContentReference> categories, LoaderOptions loaderOptions) where T : ICategorizableContent, IContentData
        {
            var contentLinks = ContentRepository.GetDescendents(contentLink);

            return(ContentRepository
                   .GetItems(contentLinks, loaderOptions)
                   .OfType <T>()
                   .Where(x => x.Categories.MemberOfAny(categories)));
        }
Exemple #4
0
        public virtual T GetFirstBySegment <T>(ContentReference parentLink, string urlSegment, LoaderOptions loaderOptions) where T : CategoryData
        {
            var descendents = ContentRepository.GetDescendents(parentLink);

            var categories = ContentRepository
                             .GetItems(descendents, loaderOptions)
                             .OfType <T>();

            return(categories.FirstOrDefault(x => x.RouteSegment.Equals(urlSegment, StringComparison.InvariantCultureIgnoreCase)));
        }
 private static void DeleteContentInAssetFolders(IEnumerable <ContentReference> contentReferences, ContentAssetHelper assetHelper,
                                                 IContentRepository repo, StringBuilder sb, IBlobFactory blobFactory)
 {
     foreach (ContentReference reference in contentReferences)
     {
         ContentAssetFolder folder = assetHelper.GetAssetFolder(reference);
         if (folder != null && folder.ContentLink != null)
         {
             var folderContents = repo.GetDescendents(folder.ContentLink);
             DeleteBlobs(folderContents, repo, sb, blobFactory);
         }
     }
 }
        private IEnumerable <ImageData> GetImages(ContentReference root)
        {
            var fileReferences = _contentRepository.GetDescendents(root);

            foreach (var fileReference in fileReferences)
            {
                var image = _contentRepository.Get <IContent>(fileReference) as ImageData;
                if (image != null)
                {
                    yield return(image);
                }
            }
        }
        private List <BasePage> GetUnpublishedPages()
        {
            var unpublishedPages = new List <BasePage>();

            foreach (var descendent in _contentRepository.GetDescendents(ContentReference.StartPage))
            {
                foreach (var content in _contentRepository.GetLanguageBranches <IContent>(descendent).ToList())
                {
                    if (content is BasePage page && page.IsPendingPublish && !page.IsDeleted)
                    {
                        unpublishedPages.Add(page);
                    }
                }
            }

            return(unpublishedPages);
        }
        public ActionResult Index(string id)
        {
            var contextContentLink = PageReference.Parse(id);

            PublishItem(contextContentLink);

            var descendents = ContentRepository.GetDescendents(contextContentLink);

            foreach (var descendent in descendents)
            {
                PublishItem(descendent);
            }

            // Return identifier to the updated version of the page, i.e. page ID including work ID
            return(new JsonResult {
                Data = id
            });
        }
Exemple #9
0
        public string Execute(params string[] parameters)
        {
            int cnt = 0;

            if (string.IsNullOrEmpty(Parent) && parameters.Any())
            {
                Parent = parameters.First();
            }

            ContentReference start = ContentReference.StartPage;

            if (!string.IsNullOrEmpty(Parent))
            {
                if (Parent.ToLower() == "root")
                {
                    start = ContentReference.RootPage;
                }
                else if (Parent.ToLower() == "globalblocks")
                {
                    start = ContentReference.GlobalBlockFolder;
                }
                else if (Parent.ToLower() == "siteblocks")
                {
                    start = ContentReference.SiteBlockFolder;
                }
                else
                {
                    start = ContentReference.Parse(Parent);
                }
            }

            foreach (var r in _repo.GetDescendents(start))
            {
                OnCommandOutput?.Invoke(this, _repo.Get <IContent>(r));
                cnt++;
            }

            return($"Done, listing {cnt} content items");
        }
Exemple #10
0
        private void PopulateForm()
        {
            // Set the project and template Ids from query string.
            Session["TemplateId"] = Server.UrlDecode(Request.QueryString["TemplateId"]);
            Session["ProjectId"]  = Server.UrlDecode(Request.QueryString["ProjectId"]);

            // If the DDS for credentials is null or empty, turn off the page visibility and alert the user to set up the config.
            if (_credentialsStore.IsNullOrEmpty())
            {
                Response.Write("<script>alert('Please setup your GatherContent config first!');" +
                               "window.location='/modules/GcEpiPlugin/GatherContentConfigSetup.aspx'</script>");
                Visible = false;
                return;
            }

            // This is to validate the user to not access this page directly.
            if (Session["TemplateId"] == null || Session["ProjectId"] == null)
            {
                Response.Write("<script>alert('This page is not directly accessible! Review your GatherContent items from Template Mappings page!');" +
                               "window.location='/modules/GcEpiPlugin/GcEpiTemplateMappings.aspx'</script>");
                Visible = false;
                return;
            }

            // Local variables initialization and setting the values for some of the form components.
            Client = new GcConnectClient(_credentialsStore.First().ApiKey, _credentialsStore.First().Email);

            // This is to make sure we only fetch mappings associated with this GcAccount.
            _mappingsStore = GcDynamicUtilities.RetrieveStore <GcDynamicTemplateMappings>().
                             FindAll(i => i.AccountId == _credentialsStore.First().AccountId);

            // Fetch the mapping for current template.
            var currentMapping = _mappingsStore.First(i => i.TemplateId == Session["TemplateId"].ToString());

            // Make a usable templateId and projectId
            var templateId = Convert.ToInt32(Session["TemplateId"]);
            var projectId  = Convert.ToInt32(Session["ProjectId"]);

            // Fetch Template details from GatherContentConnect.
            var gcTemplate = Client.GetTemplateById(templateId);

            // Set the labels with the gathered values.
            templateName.Text        = gcTemplate.Name;
            projectName.Text         = Client.GetProjectById(projectId).Name;
            templateDescription.Text = gcTemplate.Description;

            // Fetch the items (if there are any) from trash.
            var recycleBin = _contentRepository.GetDescendents(ContentReference.WasteBasket).ToList();

            // This is to make sure that the drop down doesn't persist previous values upon page refresh.
            ddlDefaultParent.Items.Clear();

            // Create an empty list to store all the content descendants.
            List <IContent> sortedDescendants = new EditableList <IContent>();

            // Populating the default parent selection drop down based on the type of the post type.
            switch (currentMapping.PostType)
            {
            case "PageType":
                // Add the root parent before everything else.
                ddlDefaultParent.Items.Add(new ListItem("Root", "1"));

                SortContent <PageData>(_contentRepository.Get <PageData>(ContentReference.RootPage), sortedDescendants);
                foreach (var pageData in sortedDescendants)
                {
                    // If the page is in recycle bin or if the page itself is recycle bin,
                    // Then do not add it to the drop down.
                    if (recycleBin.Contains(pageData.ContentLink) || pageData.ContentLink.ID == 2)
                    {
                        continue;
                    }

                    // Fetch the page data of its immediate parent.
                    var parentPage = _contentRepository.Get <PageData>(pageData.ParentLink);

                    // Add the parent's name along with the page name to avoid the confusion between the same page names.
                    ddlDefaultParent.Items.Add(new ListItem(parentPage.Name + " => " + pageData.Name, pageData.ContentLink.ID.ToString()));
                }
                break;

            case "BlockType":
                // Add the root parent before everything else.
                ddlDefaultParent.Items.Add(new ListItem("SysGlobalAssets", "3"));

                SortContent <ContentFolder>(_contentRepository.Get <ContentFolder>(ContentReference.GlobalBlockFolder), sortedDescendants);
                foreach (var contentFolder in sortedDescendants)
                {
                    // If the block is in recycle bin,
                    // Then do not add it to the drop down.
                    if (recycleBin.Contains(contentFolder.ContentLink))
                    {
                        continue;
                    }

                    // Fetch the block data of its immediate parent.
                    var parentFolder = _contentRepository.Get <ContentFolder>(contentFolder.ParentLink);
                    // Add the parent's name along with the block name to avoid the confusion between the same block names.
                    ddlDefaultParent.Items.Add(new ListItem(parentFolder.Name + " => " + contentFolder.Name,
                                                            contentFolder.ContentLink.ID.ToString()));
                }
                break;
            }
            // Add the data source to the repeater and bind it.
            rptGcItems.DataSource = Client.GetItemsByTemplateId(templateId, projectId);
            rptGcItems.DataBind();
        }
 private static void DeleteContentInAssetFolders(IEnumerable<ContentReference> contentReferences, ContentAssetHelper assetHelper,
     IContentRepository repo, StringBuilder sb, BlobFactory blobFactory)
 {
     foreach (ContentReference reference in contentReferences)
     {
         ContentAssetFolder folder = assetHelper.GetAssetFolder(reference);
         if (folder != null && folder.ContentLink != null)
         {
             var folderContents = repo.GetDescendents(folder.ContentLink);
             DeleteBlobs(folderContents, repo, sb, blobFactory);
         }
     }
 }
 public static IEnumerable <ContentReference> GetDescendents(this IContentRepository contentRepository, ContentReference contentLink)
 {
     return(contentRepository.GetDescendents(contentLink));
 }
 public static IEnumerable <T> GetAll <T>(this IContentRepository contentRepository, ContentReference fromContentReference) where T : IContent
 {
     return(contentRepository.GetItems(contentRepository.GetDescendents(fromContentReference)).OfType <T>());
 }