예제 #1
0
        public static Sitecore5xItem GetItem(string sItemPath, Sitecore5x.VisualSitecoreService sitecoreApi, Sitecore5x.Credentials credentials, ConverterOptions Options)
        {
            XmlNode        node = sitecoreApi.GetXML(sItemPath, false, Options.Database, credentials);
            Sitecore5xItem item = new Sitecore5xItem(node.SelectSingleNode("//item"), null, sitecoreApi, credentials, Options);

            return(item);
        }
예제 #2
0
        //  sTemplatePath = "/sitecore/templates/common/folder"
        public string AddFromTemplate(string sName, string sTemplatePath)
        {
            Sitecore5xItem template   = GetSitecore5xItem(sTemplatePath);
            XmlNode        resultNode = _sitecoreApi.AddFromTemplate(this.ID, template.ID, sName, _Options.Database, _credentials);

            CheckSitecoreReturnValue(resultNode);
            return(resultNode.SelectSingleNode("//data/data").InnerText);
        }
예제 #3
0
        /// <summary>
        /// Change a templates inheritance from another template
        /// returns TemplateItem
        /// </summary>
        private Sitecore5xItem ChangeTemplateInheritance(Sitecore5xItem templateItem, string sTemplatePath, string sBaseTemplatePath)
        {
            // Get standard template
            XmlNode baseTemplate    = GetItemXml(sBaseTemplatePath);
            string  sBaseTemplateID = baseTemplate.Attributes["id"].Value;

            templateItem._fields.Add(new Sitecore5xField("__base template", "__base template", "tree list", new Guid("{12C33F3F-86C5-43A5-AEB4-5598CEC45116}"), sBaseTemplateID, null, ""));

            // Return changed template item
            return(templateItem);
        }
예제 #4
0
 private void AddItemToCache(Sitecore5xItem item)
 {
     // Add to cache two times because we might request it by key or by path
     if (!_existingTemplates.ContainsKey(item.ID.ToLower()))
     {
         _existingTemplates.Add(item.ID.ToLower(), item);
     }
     if (!_existingTemplates.ContainsKey(item.Path.ToLower()))
     {
         _existingTemplates.Add(item.Path.ToLower(), item);
     }
 }
예제 #5
0
        private Sitecore5xItem AddFieldFromTemplate(Sitecore5xItem templateFieldItem, string sFieldTemplate, string sContent)
        {
            // Get sType field template
            XmlNode field            = GetItemXml(sFieldTemplate);
            string  sTemplateFieldID = field.Attributes["id"].Value;
            string  sfieldTypename   = field.SelectSingleNode("//item/version[@language = '" + this.Options.Language + "']/fields/field[@key='type']").InnerText;

            string sName = sFieldTemplate.Remove(0, sFieldTemplate.LastIndexOf("/") + 1);
            string sKey  = sFieldTemplate.Remove(0, sFieldTemplate.LastIndexOf("/") + 1).ToLower();

            templateFieldItem._fields.Add(new Sitecore5xField(sName, sKey, sfieldTypename, new Guid(sTemplateFieldID), sContent, null, ""));

            return(templateFieldItem);
        }
예제 #6
0
        /// <summary>
        /// Adds a new field to a template using the IField fromField object
        /// </summary>
        private void AddTemplateField(string sTemplatePath, IField fromField)
        {
            // Get "Template section" template
            XmlNode templateSection   = GetItemXml("/sitecore/templates/System/Templates/Template section");
            string  templateSectionID = templateSection.Attributes["id"].Value;

            string templateSectionName = "Data";

            if (fromField.Section != "")
            {
                templateSectionName = fromField.Section;
            }

            string dataSectionID = GetItemAttribute(sTemplatePath + "/" + templateSectionName, "id");

            if (dataSectionID == null)
            {
                // Create new "Template section" item from the "Template section" template
                XmlNode resultNode = _sitecoreApi.AddFromTemplate(sTemplatePath, templateSectionID, templateSectionName, _Options.Database, _credentials);
                CheckSitecoreReturnValue(resultNode);
                dataSectionID = resultNode.SelectSingleNode("//data/data").InnerText;
            }

            // Create new field below Section
            CreateTemplateItemWithSpecificID(dataSectionID, "/sitecore/templates/System/Templates/Template field", new Guid(fromField.TemplateFieldID), fromField.Name);

            Sitecore5xItem templateFieldItem = GetSitecore5xItem(fromField.TemplateFieldID);

            // Add "Sort order" to template
            AddFieldFromTemplate(templateFieldItem, "/sitecore/templates/System/Templates/Sections/Appearance/Appearance/__Sortorder", fromField.SortOrder);

            // Add "Field type" to template
            string sFromFieldTranslated = Util.TranslateToNewFieldTypes(fromField.Type);

            AddFieldFromTemplate(templateFieldItem, "/sitecore/templates/System/Templates/Template field/Data/Type", sFromFieldTranslated);

            // Add "Field source" to template
            AddFieldFromTemplate(templateFieldItem, "/sitecore/templates/System/Templates/Template field/Data/Source", fromField.Source);

            // Add "LanguageTitle" to template
            AddFieldFromTemplate(templateFieldItem, "/sitecore/templates/System/Templates/Template field/Data/Title", fromField.LanguageTitle);

            templateFieldItem.Save(templateFieldItem.Fields, this.Options.Language, "1");
        }
예제 #7
0
        private Sitecore5xItem GetSitecore5xItem(string sItemPath, Sitecore5xItem parentItem)
        {
            if (_existingTemplates.ContainsKey(sItemPath.ToLower()))
            {
                Sitecore5xItem item = null;
                _existingTemplates.TryGetValue(sItemPath.ToLower(), out item);
                return(item);
            }

            XmlNode node       = _sitecoreApi.GetXML(sItemPath, false, _Options.Database, _credentials);
            XmlNode statusNode = node.SelectSingleNode("status");

            if (statusNode.InnerText == "failed")
            {
                return(null);
            }

            return(new Sitecore5xItem(node.SelectSingleNode("//item"), parentItem, _sitecoreApi, _credentials, _Options));
        }
예제 #8
0
        private Sitecore5xItem(XmlNode itemNode, IItem parent, Sitecore5x.VisualSitecoreService sitecoreApi, Sitecore5x.Credentials credentials, ConverterOptions Options)
        {
            _Parent      = parent;
            _sitecoreApi = sitecoreApi;
            _credentials = credentials;
            _Options     = Options;

            _ID            = new Guid(itemNode.Attributes["id"].Value);
            _sName         = itemNode.Attributes["name"].Value;
            _sKey          = itemNode.Attributes["key"].Value;
            _TemplateID    = new Guid(itemNode.Attributes["tid"].Value);
            _sTemplateName = itemNode.Attributes["template"].Value;
            // If basetemplate isn't defined use _TemplateID otherwise extract list of inherited templates
            XmlNode baseTemplateNode = itemNode.SelectSingleNode("//field[@key='__base template']/content");

            if (baseTemplateNode == null)
            {
                _sTemplateIDs = new string[1];
                // If template is "template" then there is an error in sitecore webservice and
                // we change it to "Standard template".
                if (Util.GuidToSitecoreID(_TemplateID) == "{AB86861A-6030-46C5-B394-E8F99E8B87DB}")
                {
                    _sTemplateIDs[0] = "{1930BBEB-7805-471A-A3BE-4858AC7CF696}";
                }
                else
                {
                    _sTemplateIDs[0] = Util.GuidToSitecoreID(_TemplateID);
                }
            }
            else
            {
                _sTemplateIDs = baseTemplateNode.InnerText.Split('|');
            }

            // _sParentID = itemNode.Attributes["parentid"].Value;

            _sSortOrder = Util.GetNodeFieldValue(itemNode, "//field[@key='__sortorder']/content");
            if ((itemNode.Attributes["haschildren"] != null) && (itemNode.Attributes["haschildren"].Value == "1"))
            {
                _bHasChildren = true;
            }

            _sPath = "";
            string      sLatestVersion = "1";
            XmlNodeList versions       = itemNode.SelectNodes("//version[@language = '" + this.Options.Language + "']");

            if (versions != null && versions.Count > 0)
            {
                sLatestVersion = versions[versions.Count - 1].SelectSingleNode("@version").Value;
            }

            XmlNode     contentNode = _sitecoreApi.GetItemFields(Util.GuidToSitecoreID(_ID), this.Options.Language, sLatestVersion, false, _Options.Database, _credentials);
            XmlNodeList paths       = contentNode.SelectNodes("/path/item");

            foreach (XmlNode path in paths)
            {
                if (_sPath == "")
                {
                    _sPath = "/" + path.Attributes["name"].Value;
                }
                else
                {
                    _sPath = "/" + path.Attributes["name"].Value + _sPath;
                }
            }


            // The program always assumes that all fields exists, so the fieldvalues could be empty in
            // order to prevent copying to another language.
            XmlNodeList fieldList = itemNode.SelectNodes("version[@language='" + this.Options.Language + "' and @version = '" + sLatestVersion + "']/fields/field");

            foreach (XmlNode node in fieldList)
            {
                Sitecore5xField field          = new Sitecore5xField(node);
                var             existingfields = from f in _fields
                                                 where f.TemplateFieldID == field.TemplateFieldID
                                                 select f;
                if (existingfields.Count() == 0)
                {
                    // The content is cleared because it is from another language layer
                    //                    field.Content = "";

                    if (field.Name.ToLower() == "__icon")
                    {
                        _sIcon = field.Content;
                    }

                    if (field.Name.ToLower() == "__sortorder")
                    {
                        _sSortOrder = field.Content;
                    }

                    if ((field.Name.ToLower() == "__display name") && (field.Content != ""))
                    {
                        _sName = field.Content;
                    }

                    // Skip security field, it is copied in the extended sitecoreApi
                    if (field.Name.ToLower() == "__security")
                    {
                        continue;
                    }

                    // Skip standard values, it's set in the extended sitecoreApi
                    if (field.Name.ToLower() == "__standard values")
                    {
                        continue;
                    }


                    // Caching of template fields items
                    XmlNode templateFieldNode = null;
                    if (!_Options.ExistingTemplateFields.TryGetValue(field.TemplateFieldID, out templateFieldNode))
                    {
                        try
                        {
                            templateFieldNode = GetItemXml(field.TemplateFieldID);
                            _Options.ExistingTemplateFields.Add(field.TemplateFieldID, templateFieldNode);
                        }
                        catch (Exception ex)
                        {
                            if (ex.Message.ToLower().IndexOf("object reference not set to an instance of an object.") > -1)
                            {
                                // Do nothing this happens when there is content that is missing it's template field (probably the whole template)
                                continue;
                            }
                            else
                            {
                                throw new Exception("Error retrieving sitecore Field.", ex);
                            }
                        }
                    }
                    field.SortOrder = templateFieldNode.Attributes["sortorder"].Value;
                    field.Name      = templateFieldNode.Attributes["name"].Value;

                    // Get section from contentNode
                    XmlNode fieldNode = contentNode.SelectSingleNode("/field[@fieldid='" + field.TemplateFieldID + "']");
                    if ((fieldNode != null) && (fieldNode.Attributes["section"] != null))
                    {
                        field.Section = fieldNode.Attributes["section"].Value;
                    }

                    _fields.Add(field);
                }
            }

            // This is a template item
            if ((_sPath.ToLower().IndexOf("/sitecore/templates") > -1) && (_sName != "__Standard Values"))
            {
                XmlNode childrenNode = _sitecoreApi.GetChildren("{" + _ID.ToString().ToUpper() + "}", _Options.Database, _credentials);

                XmlNodeList nodeList = childrenNode.SelectNodes("./item");
                foreach (XmlNode node in nodeList)
                {
                    // Get full-blown item
                    XmlNode item     = GetItemXml(node.Attributes["id"].Value);
                    string  sSection = "";
                    if (item.Attributes["template"].Value == "template section")
                    {
                        sSection = item.Attributes["name"].Value;

                        XmlNode sectionChildNodes = _sitecoreApi.GetChildren(node.Attributes["id"].Value, _Options.Database, _credentials);
                        foreach (XmlNode tempNode in sectionChildNodes.SelectNodes("./item"))
                        {
                            XmlNode templateFieldNode = GetItemXml(tempNode.Attributes["id"].Value);

                            Sitecore5xField field = new Sitecore5xField(
                                templateFieldNode.Attributes["name"].Value,
                                templateFieldNode.Attributes["name"].Value.ToLower(),
                                Util.GetNodeFieldValue(templateFieldNode, "//field[@key='type']/content"),
                                new Guid(templateFieldNode.Attributes["id"].Value),
                                "",
                                Util.GetNodeFieldValue(templateFieldNode, "//field[@key='__sortorder']/content"),
                                sSection);
                            field.Source        = Util.GetNodeFieldValue(templateFieldNode, "//field[@key='source']/content");
                            field.LanguageTitle = Util.GetNodeFieldValue(templateFieldNode, "//field[@key='title']/content");


                            var existingfields = from f in _fields
                                                 where f.TemplateFieldID == field.TemplateFieldID
                                                 select f;
                            if (existingfields.Count() == 0)
                            {
                                _fields.Add(field);
                            }
                        }
                    }
                    // Clear template items values, will be fille later with standard values
//                    foreach (Sitecore5xField field in _fields)
//                        field.Content = "";
                }

                // Fill template field values with standard values
                Sitecore5xItem standardValueItem = GetSitecore5xItem(_sPath + "/__Standard Values");
                if (standardValueItem != null)
                {
                    foreach (Sitecore5xField standardField in standardValueItem._fields)
                    {
                        // Add field values from this and inherited templates
                        Sitecore5xField curField = Util.GetFieldByID(standardField.TemplateFieldID, Fields) as Sitecore5xField;
                        if (curField == null)
                        {
                            _fields.Add(standardField);
                        }
                        else
                        {
                            curField.Content = standardField.Content;
                        }
                    }
                }
            }
            // This is a "__Standard Values" item for the current language layer
            else if ((_sPath.ToLower().IndexOf("/sitecore/templates") > -1) && (_sName == "__Standard Values"))
            {
            }

            _sXmlNode = itemNode.OuterXml;
        }