Exemplo n.º 1
0
        protected void bntStart_Click(object sender, EventArgs e)
        {
            try
            {
                lblError.Text = string.Empty;

                if (IsValidInput() == false)
                {
                    return;
                }

                ArticleMovingParameters parameters = new ArticleMovingParameters();
                parameters.SourceType   = SourceType.ArticleIDs;              // rdMoveByArticleIDs.Checked ? SourceType.ArticleIDs : SourceType.FolderIDs;
                parameters.SourceIDs    = txtIDs.Text.Trim();
                parameters.SourceIDType = rdIsItemIDs.Checked ? SourceIDType.ItemID : SourceIDType.ArticleID;

                parameters.DestinationType = rdPreserveDateFoldersHier.Checked ? DestinationType.PreserveFolderHierarchy : DestinationType.ToSpecificFolderID;
                parameters.DestinationMainArticlesFolder = rdPreserveDateFoldersHier.Checked ? txtDestinationArticlesFolder.Text.Trim() : string.Empty;
                parameters.DestinationFolderID           = rdMoveToFolderID.Checked ? txtToFolderID.Text.Trim() : string.Empty;
                //parameters.MoveChildrenWithoutParentFolder = rdMoveToFolderID.Checked ? chkWithoutParentFolder.Checked : false;

                parameters.GenerateNewArticleNumbers = chkGenerateNumber.Checked;
                parameters.ClearTaxonomy             = chkClearTaxonomy.Checked;
                parameters.NewTaxonomyIDsToAdd       = chkNewTaxonomyFields.Checked ? txtNewTaxonomyFields.Text.Trim() : string.Empty;

                parameters.PublishDestinationItems = chkPublishDestination.Checked;

                string resultStatus;
                bool   result = ArticleMoverUtility.Process(parameters, out resultStatus);

                if (result)
                {
                    lblError.ForeColor = System.Drawing.Color.Green;
                    lblError.Text      = resultStatus;
                }
                else
                {
                    lblError.ForeColor = System.Drawing.Color.Red;
                    lblError.Text      = resultStatus;
                }
            }
            catch (Exception ex)
            {
                lblError.Text = "An error has occured: " + ex.ToString();
            }
        }
Exemplo n.º 2
0
        private bool IsValidInput()
        {
            string logText = "- Validating </br>";

            lblError.ForeColor = System.Drawing.Color.Red;
            var masterDb = Sitecore.Data.Database.GetDatabase("master");

            if (txtIDs.Text.Trim() == string.Empty)
            {
                lblError.Text = "Please specify source ID(s)";
                txtIDs.Focus();
                return(false);
            }

            logText += "- Item ID(s): </br>";
            if (rdIsItemIDs.Checked)
            {
                string idStatus = string.Empty;
                foreach (var itemID in txtIDs.Text.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    Guid tempGuid;
                    if (Guid.TryParse(itemID, out tempGuid) == false)
                    {
                        idStatus = "Item ID " + itemID + ": is not a valid Item ID <br/>";
                    }
                    else
                    {
                        var temp = masterDb.GetItem(new ID(new Guid(itemID)));
                        if (temp == null)
                        {
                            idStatus = "Item ID " + itemID + ": does not exist <br/>";
                        }
                        else if (temp.TemplateID.Guid.Equals(new Guid(Constants.ArticlesTemplateID)) == false)
                        {
                            idStatus = "Item ID " + itemID + ": is not an article <br/>";
                        }

                        logText += "- Item: " + temp.Paths.FullPath + " - " + temp.Fields["Article Number"].Value + "|" + temp.ID + " </br>";
                    }
                }

                if (string.IsNullOrEmpty(idStatus) == false)
                {
                    lblError.Text = idStatus;
                    return(false);
                }
            }
            else
            {
                string        idStatus       = string.Empty;
                List <string> articleNumbers = txtIDs.Text.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToList();

                var           articles = ArticleMoverUtility.SearchArticlesByArticleNumbers(articleNumbers);
                List <string> missingArticleNumbers = new List <string>();

                foreach (var item in articleNumbers)
                {
                    if (articles == null || articles.Count(w => w?.Article_Number?.ToLower() == item.ToLower()) == 0)
                    {
                        missingArticleNumbers.Add(item);
                    }
                }
                //articleNumbers.Where(w => articles.Any(a => a.Article_Number == w) == false).ToList();

                if (missingArticleNumbers.Any())
                {
                    idStatus = "Following Article ID(s) do not exist: " + string.Join(", ", missingArticleNumbers);
                }

                if (string.IsNullOrEmpty(idStatus) == false)
                {
                    lblError.Text = idStatus;
                    return(false);
                }

                foreach (var temp in articles)
                {
                    logText += "- Item: " + temp._Path + " - " + temp.Article_Number + "|" + temp._Id + " </br>";
                }
            }

            if (rdPreserveDateFoldersHier.Checked && txtDestinationArticlesFolder.Text.Trim() == string.Empty)
            {
                lblError.Text = "Please specify destination main Articles Folder ID";
                txtDestinationArticlesFolder.Focus();
                return(false);
            }

            var tempF = masterDb.GetItem(txtDestinationArticlesFolder.Text);

            if (rdPreserveDateFoldersHier.Checked && tempF == null)
            {
                lblError.Text = "Destintation main Articles folder specified does not exist";
                txtDestinationArticlesFolder.Focus();
                return(false);
            }

            if (rdPreserveDateFoldersHier.Checked && !tempF.TemplateID.Guid.Equals(new Guid(Constants.MainArticlesFolderTemplateID)))
            {
                lblError.Text = "Destintation Main Articles folder specified is not a main Articles folder";
                txtDestinationArticlesFolder.Focus();
                return(false);
            }
            if (rdPreserveDateFoldersHier.Checked)
            {
                logText += "- Destination Folder: " + tempF.Paths.FullPath + " - " + tempF.ID + "</br>";
            }

            if (rdMoveToFolderID.Checked && txtToFolderID.Text.Trim() == string.Empty)
            {
                lblError.Text = "Please specify destination Folder ID";
                txtToFolderID.Focus();
                return(false);
            }

            tempF = masterDb.GetItem(txtToFolderID.Text);
            if (rdMoveToFolderID.Checked && tempF == null)
            {
                lblError.Text = "Destintation folder specified does not exist";
                txtToFolderID.Focus();
                return(false);
            }

            if (rdMoveToFolderID.Checked && !tempF.TemplateID.Guid.Equals(new Guid(Constants.MainArticlesFolderTemplateID)) && !tempF.TemplateID.Guid.Equals(new Guid(Constants.SubArticlesFolderTemplateID)))
            {
                lblError.Text = "Destintation folder specified is not a main Articles folder or a sub (by date) article folder";
                txtToFolderID.Focus();
                return(false);
            }

            if (rdMoveToFolderID.Checked)
            {
                logText += "- Destination Folder: " + tempF.Paths.FullPath + " - " + tempF.ID + "</br>";
            }

            if (chkNewTaxonomyFields.Checked && txtNewTaxonomyFields.Text.Trim() == string.Empty)
            {
                lblError.Text = "Please specify new Taxonomy ID(s)";
                txtNewTaxonomyFields.Focus();
                return(false);
            }

            if (chkNewTaxonomyFields.Checked)
            {
                foreach (var taxID in txtNewTaxonomyFields.Text.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var tempT = masterDb.GetItem(taxID);
                    if (tempT == null || tempT?.TemplateID.Guid.Equals(new Guid(Constants.TaxonomyTemplateID)) == false)
                    {
                        lblError.Text = "Taxonomy ID (" + taxID + ") specified is not a Taxonomy Item";
                        txtNewTaxonomyFields.Focus();
                        return(false);
                    }
                    logText += "- Taxonomy to be added: " + tempT.ID + " (" + tempT.Name + ")" + "</br>";
                }
            }

            lblError.ForeColor = System.Drawing.Color.Green;
            lblError.Text      = logText;
            return(true);
        }
Exemplo n.º 3
0
        public static bool MoveByArticleIDs(ArticleMovingParameters parameters, out List <Item> items)
        {
            log("-----------------------------------------------------------------------------");
            log("Moving By IDs started");
            var masterDb = Sitecore.Data.Database.GetDatabase("master");

            List <Item> articlesToMove = new List <Item>();
            List <Informa.Models.Informa.Models.sitecore.templates.User_Defined.Pages.IArticle> articlesByArticleNumber = new List <IArticle>();

            if (parameters.SourceIDType == SourceIDType.ArticleID)
            {
                articlesByArticleNumber = ArticleMoverUtility.SearchArticlesByArticleNumbers(parameters.SourceIDs.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToList());
                log("Searched: " + string.Join(", ", articlesByArticleNumber?.Select(s => string.Format("{0} - {1}", s?._Id, s?.Article_Number))));
            }

            foreach (var id in parameters.SourceIDs.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries))
            {
                try
                {
                    log("Retrieving items");
                    if (parameters.SourceIDType == SourceIDType.ItemID)
                    {
                        var item = masterDb.GetItem(new ID(new Guid(id)));

                        log("Retrieved Item " + id + " (" + item.Name + ")");

                        if (!item.TemplateID.Guid.Equals(new Guid(Constants.ArticlesTemplateID)))
                        {
                            log("**Item " + id + " is not an article");
                            continue;
                        }

                        articlesToMove.Add(item);
                    }
                    else
                    {
                        var article = articlesByArticleNumber?.FirstOrDefault(w => w?.Article_Number == id);
                        if (article == null)
                        {
                            log("**Article ID " + id + ": does not exist");
                            continue;
                        }

                        var item = masterDb.GetItem(new ID(article._Id));

                        log("Retrieved Item " + id + " (" + item.Name + ")");

                        if (!item.TemplateID.Guid.Equals(new Guid(Constants.ArticlesTemplateID)))
                        {
                            log("**Item " + id + " is not an article");
                            continue;
                        }

                        articlesToMove.Add(item);
                    }
                }
                catch (Exception ex)
                {
                    log("failed to retrieve Item " + id + ". " + ex.ToString(), true);
                }
            }

            items = articlesToMove;
            return(MoveArticleToDestination(articlesToMove, parameters));
        }