public void Process(WorkflowPipelineArgs args)
        {
            Item      workflowItem = args.DataItem;
            IWorkflow itemwf       = this.master.WorkflowProvider.GetWorkflow(workflowItem);

            // Only run on project workflow
            if (itemwf.WorkflowID != Data.ProjectWorkflow.ToString())
            {
                return;
            }

            // Find other items that are in the same project
            var items = master.SelectItems("fast:/sitecore/content//*[@Project = '" + workflowItem.Fields[Data.ProjectFieldId].Value + "']");

            // Get the project defintion
            var       projectDefinition  = master.GetItem(workflowItem.Fields[Data.ProjectFieldId].Value);
            DateField projectReleaseDate = projectDefinition.Fields[Data.ProjectDetailsReleaseDate];

            // If there are no other items in the project, and it's after the project release date, continue the workflow.
            if (items == null && projectReleaseDate.DateTime < DateTime.Now)
            {
                // no other items using this so, send back
                RevertItemsWorkflowToOrigional(workflowItem);
                AutoPublish(args);
            }
            else
            {
                foreach (var item in items)
                {
                    // is the item in the same project
                    if (item.Fields[Data.ProjectFieldId].Value == workflowItem.Fields[Data.ProjectFieldId].Value)
                    {
                        // is it not in the waiting state
                        if (item.Fields["__Workflow state"].Value != Data.ProjectWorkflowReadytoGoLiveState.ToString())
                        {
                            if (item.ID != workflowItem.ID) // ignore if same item
                            {
                                AllItemsReady = false;
                                break;
                            }
                        }
                    }
                }

                if (AllItemsReady && projectReleaseDate.DateTime < DateTime.Now)
                {
                    foreach (var item in items)
                    {
                        // is the item in the same project
                        if (item.Fields[Data.ProjectFieldId].Value == workflowItem.Fields[Data.ProjectFieldId].Value)
                        {
                            RevertItemsWorkflowToOrigional(item);
                        }
                    }

                    AutoPublish(args);
                }
            }
        }
Ejemplo n.º 2
0
        public RoleStruct[] GetUsers(string sDomain)
        {
            using (new Sitecore.SecurityModel.SecurityDisabler())
            {
                Sitecore.SecurityModel.Domain domain = Sitecore.SecurityModel.Domain.FromName(sDomain);
                Sitecore.Data.Database        db     = domain.Database;
                if (db == null)
                {
                    return(null);
                }
                // create a query that will handle the Role retrieval
                // here we simply rely on the Role's Template ID
                string query = "//*[@@templateid='" + Sitecore.TemplateIDs.User + "']";

                Sitecore.Data.Items.Item[]        items = db.SelectItems(query);
                Sitecore.SecurityModel.UserItem[] users = new Sitecore.SecurityModel.UserItem[items.Length];

                List <RoleStruct> roles5x = new List <RoleStruct>();
                // fill this array with Role Items
                for (int i = 0; i < users.Length; i++)
                {
                    users[i] = new Sitecore.SecurityModel.UserItem(items[i], domain);
                    RoleStruct role = new RoleStruct();
                    role.Name        = users[i].Domain.Name + "\\" + users[i].Name;
                    role.ID          = users[i].ID.ToString();
                    role.Path        = users[i].InnerItem.Paths.ContentPath;
                    role.AccessRight = AccessRights.NotSet;
                    role.Email       = users[i].Email;
                    role.FullName    = users[i].Fullname;
                    if (users[i].InnerItem.Fields["password"] != null)
                    {
                        role.PassWord = users[i].InnerItem.Fields["password"].Value;
                    }
                    role.IsAdmin = users[i].IsAdministrator;
                    role.Roles   = "";
                    for (int t = 0; t < users[i].Roles.RoleNames.Length; t++)
                    {
                        if (role.Roles != "")
                        {
                            role.Roles += "|";
                        }
                        role.Roles += users[i].Roles.RoleNames[t];
                    }
                    roles5x.Add(role);
                }
                return(roles5x.ToArray());
            }
        }
Ejemplo n.º 3
0
        public static List <Item> GetRedirectsForItem(ID itemID)
        {
            // Based off the config file, we can run different types of queries.
            Sitecore.Data.Database db  = Database.GetDatabase("master");
            IEnumerable <Item>     ret = null;
            var redirectRoot           = Sitecore.Configuration.Settings.GetSetting(Constants.Settings.RedirectRootNode);

            ret = db.SelectItems(String.Format("{0}//*[@Redirect To Item = '{1}']", redirectRoot, itemID.ToString()));

            // make sure to return an empty list instead of null
            if (ret == null)
            {
                return(new List <Item>());
            }
            return(ret.ToList <Item>());
        }
Ejemplo n.º 4
0
    private DataTable getProductDataOld()
    {
        Sitecore.Data.Database masterDB = Sitecore.Configuration.Factory.GetDatabase("web");
        DataTable dt = new DataTable();

        dt.Columns.Add("ProductName");
        Item[] productGroup = masterDB.SelectItems("fast://*[@@templatekey='ProductGroup']");
        foreach (Item product in productGroup)
        {
            DataRow dr    = dt.NewRow();
            string  value = product.Fields["Product Group Name"].Value.ToString().Trim().Replace("<sup>", "").Replace("</sup>", "");
            dr["ProductName"] = value;
            dt.Rows.Add(dr);
        }
        DataView dv = new DataView(dt);

        return(dv.ToTable(true, "ProductName"));
    }
Ejemplo n.º 5
0
    private DataTable getProductData()
    {
        String ProductName = Request.QueryString["q"];

        Sitecore.Data.Database masterDB = Sitecore.Configuration.Factory.GetDatabase("web");
        DataTable dt = new DataTable();

        dt.Columns.Add("ProductName");

        double  intQuery = -1;
        String  productGroupTemplateID = "{A47497B6-472C-4E19-ADC4-A93C3BC80860}";
        String  productQuery           = String.Format("/sitecore/content//*[@@templateid='{0}']", productGroupTemplateID.ToString());
        Boolean filterByNDC            = false;

        if (double.TryParse(ProductName.Replace("-", ""), out intQuery))
        {
            filterByNDC = true;
            if (!ProductName.Contains("-"))
            {
                String formattedProductName = String.Format("{0}-{1}-{2}", ProductName.Substring(0, 5), ProductName.Substring(5, 3), ProductName.Substring(8, 2));
                if (!String.IsNullOrWhiteSpace(formattedProductName))
                {
                    ProductName = formattedProductName;
                }
            }
            productQuery = String.Format("/sitecore/content//*[contains(@_NDC, '{0}')]/ancestor::*", ProductName.ToString());
        }

        List <Item> lstProductGroup = new List <Item>();

        Item[] productGroup = masterDB.SelectItems(productQuery);

        foreach (Item productGrp in productGroup)
        {
            if (productGrp.TemplateID.ToString() == productGroupTemplateID.ToString())
            {
                lstProductGroup.Add(productGrp);
            }
        }

        foreach (Item product in lstProductGroup)
        {
            string value = string.Empty;
            if (!filterByNDC)
            {
                if (product.Fields["Product Group Name"].Value.ToLower().StartsWith(ProductName.ToLower()))
                {
                    value = product.Fields["Product Group Name"].Value.ToString().Trim().Replace("<sup>", "").Replace("</sup>", "");
                }
            }
            else
            {
                if (filterByNDC)
                {
                    foreach (Item ndc in product.Children)
                    {
                        if (ndc.Fields["_NDC"].Value.ToString().StartsWith(ProductName.ToString()))
                        {
                            value = product.Fields["Product Group Name"].Value.ToString().Trim().Replace("<sup>", "").Replace("</sup>", "");
                            break;
                        }
                    }
                }
            }

            if (!String.IsNullOrWhiteSpace(value))
            {
                DataRow dr = dt.NewRow();
                dr["ProductName"] = value;
                dt.Rows.Add(dr);
            }
        }
        DataView dv = new DataView(dt);

        dv.Sort = "ProductName ASC";
        return(dv.ToTable(true));
    }
Ejemplo n.º 6
0
        public static void ImportPosts(Item bh, List <WPPost> listWordpressPosts, string blogName, Item userBlogPostTemplate)
        {
            Sitecore.Data.Database master = Sitecore.Data.Database.GetDatabase("master");

            foreach (WPPost post in listWordpressPosts)
            {
                try
                {
                    using (new Sitecore.SecurityModel.SecurityDisabler())
                    {
                        if (string.IsNullOrEmpty(post.Content) || string.IsNullOrEmpty(post.Title))
                        {
                            continue;
                        }

                        TemplateItem blogPostTemplate = master.GetItem(userBlogPostTemplate.ID);

                        string validItemName = ItemUtil.ProposeValidItemName(post.Title);
                        if (string.IsNullOrEmpty(validItemName))
                        {
                            continue;
                        }


                        BlogPost bp = ItemManager.CreateItem(validItemName, bh, userBlogPostTemplate.ID).CreateAs <BlogPost>();

                        if (bp == null)
                        {
                            continue;
                        }

                        using (new EditContext(bp.InnerItem))
                        {
                            bp.InnerItem.SetString(BlogPost.BlogPostTitleFieldId, post.Title.Replace("-", " "));
                            bp.InnerItem.SetString(BlogPost.BlogPostBodyFieldId, post.Content);
                            bp.PublishDate.Value = Sitecore.DateUtil.ToIsoDate(post.PublishDate);

                            if (!string.IsNullOrEmpty(post.WPAuthor))
                            {
                                if (post.Tags.Any())
                                {
                                    foreach (string tag in post.Tags)
                                    {
                                        Item t = master.SelectItems("fast://sitecore/content/Data/" + blogName + "/Tags/*[@Tag Name= '" + tag + "']").FirstOrDefault();
                                        if (t == null)
                                        {
                                            continue;
                                        }
                                        bp.InnerItem.SetValue(BlogPost.BlogPostTagsFieldId, t.ID);
                                    }
                                }

                                if (post.Categories.Any())
                                {
                                    foreach (string cat in post.Categories)
                                    {
                                        Item c = master.SelectItems("fast://sitecore/content/Data/" + blogName + "/Categories/*[@Category Name= '" + cat + "']").FirstOrDefault();
                                        if (c == null)
                                        {
                                            continue;
                                        }
                                        bp.InnerItem.SetValue(BlogPost.BlogPostCategoryFieldId, c.ID);
                                    }
                                }

                                Item auth = master.SelectItems("fast://sitecore/content/Data/" + blogName + "/Authors/*[@Creator= '" + post.WPAuthor + "']").FirstOrDefault();
                                if (auth != null)
                                {
                                    bp.InnerItem.SetValue(BlogPost.BlogPostAuthorFieldId, auth.ID);
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("Cannot create entry for: " + post.Title + " " + ex.Message, "WPImporter");
                }
            }
        }