예제 #1
0
        private Umbraco6xItem(string sID, Umbraco6xAPI umbracoAPI, ConverterOptions Options)
        {
            _umbracoAPI = umbracoAPI;
            _Options    = Options;

//            XmlNode node = umbracoAPI._umbracoWebService.GetDocumentValidate(0, umbracoAPI._credentials.UserName, umbracoAPI._credentials.Password);
//            node = umbracoAPI._umbracoWebService.GetDocument(0, "");
            int iID = 0;

            if (!string.IsNullOrEmpty(sID))
            {
                iID = Util.StringGuid2Int(sID);
            }

            // Special handling of root item
            if (iID == 0)
            {
                documentCarrier[] docCarrierList = _umbracoAPI._umbracoDocumentApi.readList(iID, umbracoAPI._credentials.UserName, umbracoAPI._credentials.Password);
                iID = docCarrierList[0].Id;
            }

            _docCarrier = _umbracoAPI._umbracoDocumentApi.read(iID, umbracoAPI._credentials.UserName, umbracoAPI._credentials.Password);
            _Fields     = new Umbraco6xField[_docCarrier.DocumentProperties.Length];
            int t = 0;

            foreach (documentProperty docprop in _docCarrier.DocumentProperties)
            {
                string sDocProp = docprop.PropertyValue as string;
                if (sDocProp != null)
                {
                    sDocProp.Split(',');
                }
                else
                {
                    int iDocProp = (docprop.PropertyValue as Nullable <int>).GetValueOrDefault(-1);
                    // _umbracoAPI._umbracoWebService.Credentials = new NetworkCredential(umbracoAPI._credentials.UserName, umbracoAPI._credentials.Password);
                    // XmlNode node = _umbracoAPI._umbracoWebService.GetDocument(iDocProp, "");
//                    documentCarrier fieldCarrier = _umbracoAPI._umbracoDocumentApi.read(iDocProp, umbracoAPI._credentials.UserName, umbracoAPI._credentials.Password);
                }

                _Fields[t++] = new Umbraco6xField(docprop.Key, docprop.PropertyValue.ToString());
            }

            _iID   = _docCarrier.Id;
            _sName = _docCarrier.Name;
        }
예제 #2
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);
        }
예제 #3
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;
        }
예제 #4
0
 public static Umbraco6xItem GetRoot(Umbraco6xAPI umbracoAPI, ConverterOptions Options)
 {
     return(new Umbraco6xItem(null, umbracoAPI, Options));
 }