Example #1
0
        public static InstallItem FromDependency(ItemReference itemRef)
        {
            var result = new InstallItem();

            result._itemRef = itemRef;
            result._elem    = new XmlDocument().CreateElement("Item");
            result._elem.SetAttribute("type", result._itemRef.Type);
            if (result._itemRef.Unique.IsGuid())
            {
                result._elem.SetAttribute("id", result._itemRef.Unique);
            }
            else
            {
                result._elem.SetAttribute("where", result._itemRef.Unique);
            }
            result._elem.SetAttribute("action", "get");
            result._elem.SetAttribute("_dependency_check", "1");
            result._elem.SetAttribute("_keyed_name", result._itemRef.KeyedName);
            result._type = InstallType.DependencyCheck;
            return(result);
        }
 public IEnumerable <XmlNode> GetReferencesByMaster(ItemReference masterRef)
 {
     return(from c in _contexts where c.MasterRef.Equals(masterRef) select c.Reference);
 }
 private void AddDependency(ItemReference itemRef, XmlNode context, XmlNode reference, ItemReference masterRef)
 {
     _dependencies.Add(itemRef);
     if (context != null)
     {
         References refs;
         if (!_allDependencies.TryGetValue(itemRef, out refs))
         {
             refs = new References();
             _allDependencies.Add(itemRef, refs);
         }
         refs.AddReferences(reference, context, masterRef);
     }
 }
        private void VisitNode(XmlElement elem, ItemReference masterRef)
        {
            var textChildren = elem.ChildNodes.OfType <XmlText>().ToList();

            // Add a dependency to the relevant itemTypes
            if (elem.LocalName == "Item" && elem.HasAttribute("type"))
            {
                ItemType itemType;
                if (_itemTypes.TryGetValue(elem.Attribute("type").ToLowerInvariant(), out itemType))
                {
                    AddDependency(itemType.Reference, elem, elem, masterRef);
                }
                else
                {
                    AddDependency(new ItemReference("ItemType", "[ItemType].[name] = '" + elem.Attributes["type"].Value + "'")
                    {
                        KeyedName = elem.Attributes["type"].Value
                    }, elem, elem, masterRef);
                }
            }

            // Item property node
            if (elem.HasAttribute("type") && textChildren.Count == 1 && !string.IsNullOrEmpty(textChildren[0].Value))
            {
                AddDependency(ItemReference.FromItemProp(elem), elem.Parent(), elem, masterRef);
            }
            else if (elem.LocalName == "sqlserver_body" && elem.Parent().LocalName == "Item" && elem.Parent().Attribute("type") == "SQL")
            {
                var names = _parser.FindSqlServerObjectNames(elem.InnerText)
                            .Select(n => n.StartsWith(_parser.SchemaToKeep + ".", StringComparison.OrdinalIgnoreCase) ?
                                    n.Substring(_parser.SchemaToKeep.Length + 1).ToLowerInvariant() :
                                    n.ToLowerInvariant())
                            .Distinct();

                ItemType      itemType;
                ItemReference sql;
                foreach (var name in names)
                {
                    if (_itemTypes.TryGetValue(name.Replace('_', ' '), out itemType))
                    {
                        AddDependency(itemType.Reference, elem.Parent(), elem, masterRef);
                    }
                    else if (_sql.TryGetValue(name, out sql))
                    {
                        AddDependency(sql, elem.Parent(), elem, masterRef);
                    }
                }
            }
            else if (elem.LocalName == "data_source" && textChildren.Count == 1 && !string.IsNullOrEmpty(textChildren[0].Value))
            {
                // Property data source dependencies
                var parent = elem.ParentNode as XmlElement;
                if (parent != null && parent.LocalName == "Item" && parent.Attribute("type") == "Property")
                {
                    var keyedName = elem.Attribute("keyed_name");
                    var itemtype  = _itemTypes.Values.FirstOrDefault(i => i.Reference.Unique == elem.Parent().Parent().Parent().Attribute("id") && i.IsPolymorphic);
                    if (itemtype == null)
                    {
                        var dataType = parent.Element("data_type");
                        if (dataType != null)
                        {
                            switch (dataType.InnerText.ToLowerInvariant())
                            {
                            case "list":
                            case "mv_list":
                            case "filter list":
                                AddDependency(new ItemReference("List", textChildren[0].Value)
                                {
                                    KeyedName = keyedName
                                }, parent, elem, masterRef);
                                break;

                            case "item":
                                AddDependency(new ItemReference("ItemType", textChildren[0].Value)
                                {
                                    KeyedName = keyedName
                                }, parent, elem, masterRef);
                                break;

                            case "sequence":
                                AddDependency(new ItemReference("Sequence", textChildren[0].Value)
                                {
                                    KeyedName = keyedName
                                }, parent, elem, masterRef);
                                break;
                            }
                        }
                    }
                }
            }
            else if (elem != _elem && elem.LocalName == "Item" && elem.HasAttribute("type") &&
                     elem.Attribute("action", "") == "get" &&
                     (elem.HasAttribute("id") || elem.HasAttribute("where")))
            {
                // Item queries
                AddDependency(ItemReference.FromFullItem(elem, true), elem.Parent().Parent(), elem.Parent(), masterRef);
            }
            else if (textChildren.Count == 1 && textChildren[0].Value.StartsWith("vault:///?fileId=", StringComparison.OrdinalIgnoreCase))
            {
                // Vault Id references for image properties
                AddDependency(new ItemReference("File", textChildren[0].Value.Substring(17)), elem.Parent(), elem, masterRef);
            }
            else
            {
                if (elem != _elem && elem.LocalName == "Item" && elem.HasAttribute("type") && elem.HasAttribute("id"))
                {
                    _definitions.Add(ItemReference.FromFullItem(elem, false));
                }
                var           isItem = (elem.LocalName == "Item" && elem.HasAttribute("type"));
                ItemProperty  newProp;
                ItemReference propRef;

                foreach (var child in elem.Elements())
                {
                    if (isItem)
                    {
                        newProp = new ItemProperty()
                        {
                            ItemType   = elem.Attributes["type"].Value,
                            ItemTypeId = (elem.HasAttribute("typeid") ? elem.Attributes["typeid"].Value : null),
                            Property   = child.LocalName
                        };
                        if (_customProps.TryGetValue(newProp, out propRef))
                        {
                            propRef = propRef.Clone();
                            AddDependency(propRef, elem, child, masterRef);
                        }
                    }
                    VisitNode(child, masterRef);
                }
            }
        }
Example #5
0
        public static InstallItem FromScript(XmlElement elem)
        {
            var result = new InstallItem();

            result._elem    = elem;
            result._itemRef = ItemReference.FromFullItem(elem, true);
            if (result._itemRef.Type.IsGuid())
            {
                result.InstalledId = result._itemRef.Type;
            }
            else
            {
                result.InstalledId = elem.Attribute("id", "");
            }

            if (elem.HasAttribute("_dependency_check"))
            {
                result._type = InstallType.DependencyCheck;
            }
            else if (elem.HasAttribute("action"))
            {
                switch (elem.Attributes["action"].Value)
                {
                case "add":
                case "merge":
                case "create":
                    result._type = InstallType.Create;
                    break;

                case "ActivateActivity":
                case "AddItem":
                case "AddHistory":
                case "ApplyUpdate":
                case "BuildProcessReport":
                case "CancelWorkflow":
                case "checkImportedItemType":
                case "closeWorkflow":
                case "copy":
                case "copyAsIs":
                case "copyAsNew":
                case "delete":
                case "edit":
                case "EmailItem":
                case "EvaluateActivity":
                case "exportItemType":
                case "get":
                case "getItemAllVersions":
                case "getAffectedItems":
                case "getItemConfig":
                case "getItemLastVersion":
                case "getItemNextStates":
                case "getItemRelationships":
                case "GetItemRepeatConfig":
                case "getItemWhereUsed":
                case "GetMappedPath":
                case "getPermissions":
                case "getRelatedItem":
                case "GetUpdateInfo":
                case "instantiateWorkflow":
                case "lock":
                case "New Workflow Map":
                case "PromoteItem":
                case "purge":
                case "recache":
                case "replicate":
                case "resetAllItemsAccess":
                case "resetItemAccess":
                case "resetLifecycle":
                case "setDefaultLifecycle":
                case "skip":
                case "startWorkflow":
                case "unlock":
                case "update":
                case "ValidateWorkflowMap":
                case "version":
                    if ((elem.Attributes["type"].Value != "Form" && elem.Attributes["type"].Value != "View") ||
                        elem.Attributes["action"].Value != "delete")
                    {
                        result._dependencies = Enumerable.Repeat(result._itemRef, 1);
                    }
                    result._itemRef = new ItemReference("*Script", result._itemRef.ToString() + " " + Utils.GetChecksum(Encoding.UTF8.GetBytes(elem.OuterXml)))
                    {
                        KeyedName = RenderAttributes(elem)
                    };
                    result._type = InstallType.Script;
                    break;

                default:
                    result._dependencies = Enumerable.Repeat(new ItemReference("Method", "[Method].[name] = '" + elem.Attributes["action"].Value + "'")
                    {
                        KeyedName = elem.Attributes["action"].Value
                    }, 1);
                    result._itemRef = new ItemReference("*Script", result._itemRef.ToString() + " " + Utils.GetChecksum(Encoding.UTF8.GetBytes(elem.OuterXml)))
                    {
                        KeyedName = RenderAttributes(elem)
                    };
                    result._type = InstallType.Script;
                    break;
                }
            }

            if (elem.Attribute(XmlFlags.Attr_IsScript) == "1")
            {
                if (string.IsNullOrEmpty(result._itemRef.KeyedName))
                {
                    result._itemRef.KeyedName = RenderAttributes(elem);
                }
                result._type = InstallType.Script;
            }
            return(result);
        }