Exemplo n.º 1
0
        /// <summary>
        ///  turns portable content ids back into static ones.
        /// </summary>
        private static XElement HuntContentNodes(XElement node)
        {
            var nodes     = node.Element("Nodes");
            var preValues = node.Element("PreValues");

            if (nodes != null && preValues != null)
            {
                if (nodes.HasElements && preValues.HasElements)
                {
                    LogHelper.Info <SyncDataType>("Mapping PreValue Content Ids to Local Content Id Values");

                    foreach (var nodepath in nodes.Elements("Node"))
                    {
                        // go through the mapped things, and see if they are
                        var alias = (string)nodepath.Attribute("Alias");
                        if (!String.IsNullOrWhiteSpace(alias))
                        {
                            // find the alias in the preValues...
                            var preVal = preValues.Elements().Where(x => (string)x.Attribute("Alias") == alias).FirstOrDefault();
                            if (preVal != null)
                            {
                                var preValVal = (string)preVal.Attribute("Value");
                                if (!string.IsNullOrWhiteSpace(preValVal))
                                {
                                    LogHelper.Debug <SyncDataType>("We have the preValue (we think....) {0}", () => preValVal);

                                    var nodeidPath = (string)nodepath.Attribute("Value");
                                    var nodeid     = (string)nodepath.Attribute("Id");

                                    if (!string.IsNullOrWhiteSpace(nodeidPath))
                                    {
                                        int id = -1;

                                        var nodeType = (string)nodepath.Attribute("Type");
                                        if (nodeType == "stylesheet")
                                        {
                                            // it's a stylesheet id - quick swapsy ...
                                            // the core api - doesn't do getStyleSheetByID... so we're not doing this just yet
                                            //
                                        }
                                        else if (nodeType == "media")
                                        {
                                            LogHelper.Debug <SyncDataType>("searching for a media node");
                                            MediaWalker mw = new MediaWalker();
                                            id = mw.GetIdFromPath(nodeidPath);
                                        }
                                        else
                                        {
                                            // content
                                            LogHelper.Debug <SyncDataType>("searching for a content node");
                                            ContentWalker cw = new ContentWalker();
                                            id = cw.GetIdFromPath(nodeidPath);
                                        }

                                        if (id != -1)
                                        {
                                            // try to illiminate changes for changes sake.
                                            if (preValVal.Contains(nodeid) && nodeid != id.ToString())
                                            {
                                                preVal.SetAttributeValue("Value", preValVal.Replace(nodeid, id.ToString()));
                                                LogHelper.Debug <SyncDataType>("Set preValue value to {0}", () => preVal.Attribute("Value"));
                                            }
                                        }
                                        else
                                        {
                                            LogHelper.Debug <SyncDataType>("We didn't match the pre-value so we're leaving it alone");
                                        }
                                    }
                                    else
                                    {
                                        LogHelper.Info <SyncDataType>("Couldn't retrieve nodeIdPath from Value");
                                    }
                                }
                            }
                        }
                    }
                }
            }


            return(node);
        }
Exemplo n.º 2
0
        /// <summary>
        ///  goes through the prevalues and makes content ids portable.
        /// </summary>
        private static XElement ReplaceCotentNodes(XElement node)
        {
            XElement nodepaths = null;

            var preValueRoot = node.Element("PreValues");

            if (preValueRoot.HasElements)
            {
                var preValues = preValueRoot.Elements("PreValue");
                foreach (var preValue in preValues)
                {
                    if (!((string)preValue.Attribute("Alias")).IsNullOrWhiteSpace())
                    {
                        // look for an alias name that contains a content node
                        if (uSyncSettings.dataTypeSettings.ContentPreValueAliases.Contains((string)preValue.Attribute("Alias")))
                        {
                            LogHelper.Info <SyncDataType>("Mapping Content Ids in PreValue {0}", () => preValue.Attribute("Alias"));
                            var propVal = (string)preValue.Attribute("Value");
                            if (!String.IsNullOrWhiteSpace(propVal))
                            {
                                foreach (Match m in Regex.Matches(propVal, @"\d{1,9}"))
                                {
                                    int id;

                                    if (int.TryParse(m.Value, out id))
                                    {
                                        // we have an ID : yippe, time to do some walking...
                                        string type = "content";

                                        helpers.ContentWalker cw = new ContentWalker();
                                        string nodePath          = cw.GetPathFromID(id);

                                        // Didn't find the content id try media ...
                                        if (string.IsNullOrWhiteSpace(nodePath))
                                        {
                                            type = "media";
                                            helpers.MediaWalker mw = new MediaWalker();
                                            nodePath = mw.GetPathFromID(id);
                                        }

                                        if (!string.IsNullOrWhiteSpace(nodePath))
                                        {
                                            // attach the node tree to the XElement
                                            if (nodepaths == null)
                                            {
                                                nodepaths = new XElement("Nodes");
                                                node.Add(nodepaths);
                                            }
                                            nodepaths.Add(new XElement("Node",
                                                                       new XAttribute("Id", m.Value),
                                                                       new XAttribute("Value", nodePath),
                                                                       new XAttribute("Alias", (string)preValue.Attribute("Alias")),
                                                                       new XAttribute("Type", type)));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(node);
        }