Пример #1
0
        /// <summary>
        /// Removes depencencies
        /// </summary>
        /// <returns>Nodes which are top-level nodes</returns>
        public IEnumerable <XmlNode> RemoveDependencyContexts(ItemReference dependency)
        {
            References refs;

            if (_allDependencies.TryGetValue(dependency, out refs))
            {
                foreach (var node in refs.GetContexts())
                {
                    if (node.ParentNode == null || node.Attribute(XmlFlags.Attr_DependenciesAnalyzed) == "1")
                    {
                        yield return(node);
                    }
                    else
                    {
                        node.Detach();
                    }
                }
            }
        }
Пример #2
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);
        }
Пример #3
0
        public PackageMetadataProvider()
        {
            _systemIdentities = ElementFactory.Local.FromXml(@"<Result>
  <Item type='Identity' typeId='E582AB17663F4EF28460015B2BE9E094' id='8FE5430B42014D94AE83246F299D9CC4'>
    <id keyed_name='Creator' type='Identity'>8FE5430B42014D94AE83246F299D9CC4</id>
    <name>Creator</name>
  </Item>
  <Item type='Identity' typeId='E582AB17663F4EF28460015B2BE9E094' id='DBA5D86402BF43D5976854B8B48FCDD1'>
    <id keyed_name='Innovator Admin' type='Identity'>DBA5D86402BF43D5976854B8B48FCDD1</id>
    <name>Innovator Admin</name>
  </Item>
  <Item type='Identity' typeId='E582AB17663F4EF28460015B2BE9E094' id='9200A800443E4A5AAA80D0BCE5760307'>
    <id keyed_name='Manager' type='Identity'>9200A800443E4A5AAA80D0BCE5760307</id>
    <name>Manager</name>
  </Item>
  <Item type='Identity' typeId='E582AB17663F4EF28460015B2BE9E094' id='538B300BB2A347F396C436E9EEE1976C'>
    <id keyed_name='Owner' type='Identity'>538B300BB2A347F396C436E9EEE1976C</id>
    <name>Owner</name>
  </Item>
  <Item type='Identity' typeId='E582AB17663F4EF28460015B2BE9E094' id='6B14D33C4A7D41C188CCF2BC15BD01A3'>
    <id keyed_name='Super User' type='Identity'>6B14D33C4A7D41C188CCF2BC15BD01A3</id>
    <name>Super User</name>
  </Item>
  <Item type='Identity' typeId='E582AB17663F4EF28460015B2BE9E094' id='A73B655731924CD0B027E4F4D5FCC0A9'>
    <id keyed_name='World' type='Identity'>A73B655731924CD0B027E4F4D5FCC0A9</id>
    <name>World</name>
  </Item>
</Result>")
                                .Items()
                                .Select(i =>
            {
                var itemRef       = ItemReference.FromFullItem(i, false);
                itemRef.KeyedName = i.Property("name").AsString("");
                return(itemRef);
            })
                                .ToArray();
        }
Пример #4
0
        public static InstallItem FromScript(XmlElement elem
                                             , Func <XmlElement, string> keyedNameGetter = null)
        {
            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(ScriptType, result._itemRef + " " + 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(ScriptType, result._itemRef + " " + 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);
        }
Пример #5
0
 public IEnumerable <XmlNode> GetReferencesByMaster(ItemReference masterRef)
 {
     return(from c in _contexts where c.MasterRef.Equals(masterRef) select c.Reference);
 }
Пример #6
0
 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);
     }
 }
Пример #7
0
        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 (_metadata.ItemTypeByName(elem.Attribute("type").ToLowerInvariant(), out itemType))
                {
                    AddDependency(itemType.Reference, elem, elem, masterRef);
                }
                else
                {
                    AddDependency(new ItemReference("ItemType", ItemTypeByNameWhere + 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 = GetInnovatorNames(elem.InnerText)
                            .Select(n => n.FullName.StartsWith("innovator.", StringComparison.OrdinalIgnoreCase) ?
                                    n.FullName.Substring(10).ToLowerInvariant() :
                                    n.FullName.ToLowerInvariant())
                            .Distinct();

                ItemType      itemType;
                ItemReference sql;
                foreach (var name in names)
                {
                    if (_metadata.ItemTypeByName(name.Replace('_', ' '), out itemType) ||
                        _metadata.ItemTypeByName(name, out itemType))
                    {
                        AddDependency(itemType.Reference, elem.Parent(), elem, masterRef);
                    }
                    else if (_metadata.SqlRefByName(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?.LocalName == "Item" && parent.Attribute("type") == "Property")
                {
                    var keyedName = elem.Attribute("keyed_name");
                    var itemtype  = _metadata.ItemTypes.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") &&
                    elem.Attribute("action", "") != "edit")
                {
                    _definitions.Add(ItemReference.FromFullItem(elem, elem.Attribute("type") == "ItemType"));
                }
                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 (_metadata.CustomPropertyByPath(newProp, out propRef))
                        {
                            propRef = propRef.Clone();
                            AddDependency(propRef, elem, child, masterRef);
                        }
                    }
                    VisitNode(child, masterRef);
                }
            }
        }
Пример #8
0
        public void GatherDependencies(XmlElement elem, ItemReference itemRef, IEnumerable <ItemReference> existingDependencies)
        {
            _dependencies.Clear();
            _definitions.Clear();

            if (existingDependencies != null)
            {
                _dependencies.UnionWith(existingDependencies);
            }

            _elem = elem;
            VisitNode(elem, itemRef);

            // Clean up dependencies
            foreach (var defn in _definitions)
            {
                _dependencies.Remove(defn);
                try
                {
                    _allDefinitions.Add(defn, itemRef);
                }
                catch (ArgumentException)
                {
                    //throw new ArgumentException(string.Format("Error: {0} is defined twice, once in {1} and another time in {2}.\r\nCurrently processing {3}",
                    //  defn, _allDefinitions[defn], itemRef, elem.OuterXml));
                }
            }
            _dependencies.ExceptWith(_metadata.SystemIdentities);
            _dependencies.ExceptWith(_metadata.Methods.Where(m => m.IsCore));
            _dependencies.ExceptWith(_metadata.ItemTypes.Where(i => i.IsCore).Select(i => i.Reference));
            _dependencies.ExceptWith(_dependencies.Where(d =>
            {
                if (d.Type == "ItemType" && !string.IsNullOrEmpty(d.KeyedName))
                {
                    ItemType it;
                    if (_metadata.ItemTypeByName(d.KeyedName, out it) && it.IsCore)
                    {
                        return(true);
                    }
                }
                return(false);
            }).ToList());
            _dependencies.Remove(itemRef);

            foreach (var depend in _dependencies)
            {
                depend.Origin = itemRef;
            }

            if (_dependencies.Any())
            {
                HashSet <ItemReference> dependSet;
                if (_allItemDependencies.TryGetValue(itemRef, out dependSet))
                {
                    dependSet.UnionWith(_dependencies);
                }
                else
                {
                    _allItemDependencies[itemRef] = new HashSet <ItemReference>(_dependencies);
                }
            }

            elem.SetAttribute(XmlFlags.Attr_DependenciesAnalyzed, "1");

            _dependencies.Clear();
            _definitions.Clear();
        }
        private async Task <bool> ReloadSecondaryMetadata()
        {
            var methods             = _conn.ApplyAsync(new Command(@"<AML>
  <Item type='Method' action='get' select='config_id,core,name,method_code,comments,execution_allowed_to,method_type'>
    <method_type condition='ne'>JavaScript</method_type>
  </Item>
  <Item type='Method' action='get' select='config_id,core,name,comments,method_type'>
    <method_type>JavaScript</method_type>
  </Item>
</AML>").WithAction(CommandAction.ApplyAML), true, false).ToTask();
            var sysIdents           = _conn.ApplyAsync(@"<Item type='Identity' action='get' select='id,name'>
  <name condition='in'>'World', 'Creator', 'Owner', 'Manager', 'Innovator Admin', 'Super User'</name>
</Item>", true, true).ToTask();
            var sqls                = _conn.ApplyAsync("<Item type='SQL' action='get' select='id,name,type'></Item>", true, false).ToTask();
            var customProps         = _conn.ApplyAsync(@"<Item type='Property' action='get' select='name,source_id(id,name)'>
  <created_by_id condition='ne'>AD30A6D8D3B642F5A2AFED1A4B02BEFA</created_by_id>
  <source_id>
    <Item type='ItemType' action='get'>
      <core>1</core>
      <created_by_id>AD30A6D8D3B642F5A2AFED1A4B02BEFA</created_by_id>
    </Item>
  </source_id>
</Item>", true, false).ToTask();
            var polyLists           = _conn.ApplyAsync(@"<Item type='Property' action='get' select='data_source(id)'>
  <name>itemtype</name>
  <data_type>list</data_type>
  <source_id>
    <Item type='ItemType' action='get'>
      <implementation_type>polymorphic</implementation_type>
    </Item>
  </source_id>
</Item>", true, false).ToTask();
            var sequences           = _conn.ApplyAsync(@"<Item type='Sequence' action='get' select='name'></Item>", true, false).ToTask();
            var elementTypes        = _conn.ApplyAsync(@"<Item action='get' type='cmf_ElementType' select='generated_type'>
  <Relationships>
    <Item action='get' type='cmf_PropertyType' select='generated_type'>
    </Item>
  </Relationships>
</Item>", true, false).ToTask();
            var contentTypes        = _conn.ApplyAsync(@"<Item action='get' type='cmf_ContentType' select='linked_item_type'>
  <linked_item_type>
    <Item type='ItemType' action='get'>
    </Item>
  </linked_item_type>
</Item>", true, false).ToTask();
            var presentationConfigs = _conn.ApplyAsync(@"<Item type='ITPresentationConfiguration' action='get' select='id,related_id'>
  <related_id>
    <Item type='PresentationConfiguration' action='get' select='id'>
      <name condition='like'>*_TOC_Configuration</name>
      <color condition='is null'></color>
      <Relationships>
        <Item action='get' type='cui_PresentConfigWinSection' select='id' />
        <Item action='get' type='PresentationCommandBarSection' select='id,related_id(id)' />
      </Relationships>
    </Item>
  </related_id>
</Item>", true, false).ToTask();
            var serverEvents        = _conn.ApplyAsync(@"<Item type='Server Event' action='get' related_expand='0' select='source_id,server_event,related_id,sort_order'>
</Item>", true, false).ToTask();
            var morphae             = _conn.ApplyAsync(@"<Item type='Morphae' action='get' related_expand='0' select='source_id,related_id'>
</Item>", true, false).ToTask();

            Methods = (await methods).Items().Select(i => new Method(i)).ToList();

            _systemIdentities = (await sysIdents).Items()
                                .Select(i =>
            {
                var itemRef       = ItemReference.FromFullItem(i, false);
                itemRef.KeyedName = i.Property("name").AsString("");
                return(itemRef);
            }).ToDictionary(i => i.Unique);


            _sql = (await sqls).Items()
                   .Select(i =>
            {
                var itemRef       = Sql.FromFullItem(i, false);
                itemRef.KeyedName = i.Property("name").AsString("");
                itemRef.Type      = i.Property("type").AsString("");
                return(itemRef);
            }).ToDictionary(i => i.KeyedName.ToLowerInvariant(), StringComparer.OrdinalIgnoreCase);

            var r = (await customProps);

            foreach (var customProp in r.Items())
            {
                var itemType = customProp.SourceItem();
                _customProps[new ItemProperty()
                             {
                                 ItemType = itemType.Property("name").Value,
                                 ItemTypeId = itemType.Id(),
                                 Property = customProp.Property("name").Value,
                                 PropertyId = customProp.Id()
                             }] = new ItemReference("Property", customProp.Id())
                {
                    KeyedName = customProp.Property("name").Value
                };
            }

            PolyItemLists = (await polyLists).Items()
                            .OfType <Innovator.Client.Model.Property>()
                            .Select(i => new ItemReference("List", i.DataSource().Value)
            {
                KeyedName = i.DataSource().KeyedName().Value
            }).ToArray();

            Sequences = (await sequences).Items().Select(i => ItemReference.FromFullItem(i, true)).ToArray();

            try
            {
                CmfGeneratedTypes = new HashSet <string>((await elementTypes).Items().SelectMany(x =>
                {
                    var relations = x.Relationships().Select(y => y.Property("generated_type").Value).ToList();
                    relations.Add(x.Property("generated_type").Value);
                    return(relations);
                }));

                CmfLinkedTypes = (await contentTypes).Items().ToDictionary(x => x.Property("linked_item_type").Value, y => ItemReference.FromFullItem(y, true));
            }
            catch (ServerException)
            {
                //TODO: Do something when cmf types don't exist
            }

            try
            {
                TocPresentationConfigs.Clear();
                TocPresentationConfigs.UnionWith((await presentationConfigs)
                                                 .Items()
                                                 .Select(i => i.RelatedItem())
                                                 .Where(i => i.Relationships().Count() == 1 &&
                                                        i.Relationships().Single().RelatedId().KeyedName().AsString("").EndsWith("_TOC_Content"))
                                                 .Select(i => i.Id()));
            }
            catch (ServerException)
            {
                //TODO: Do something
            }

            foreach (var serverEvent in (await serverEvents).Items())
            {
                var ev = new ServerEvent(serverEvent);
                if (_itemTypesById.TryGetValue(serverEvent.SourceId().Value, out var itemType))
                {
                    itemType.ServerEvents.Add(ev);
                }
                var method = Methods.FirstOrDefault(m => m.Unique == ev.Method.Unique);
                if (method != null)
                {
                    method.IsServerEvent = true;
                }
            }

            foreach (var poly in (await morphae).Items())
            {
                if (_itemTypesById.TryGetValue(poly.SourceId().Value, out var itemType))
                {
                    itemType.Morphae.Add(poly.RelatedId().Attribute("name").Value ?? poly.RelatedId().KeyedName().Value);
                }
            }

            return(true);
        }
Пример #10
0
 /// <summary>
 /// Try to get a custom property by the Item Type and name information
 /// </summary>
 public bool CustomPropertyByPath(ItemProperty path, out ItemReference propRef)
 {
     return(_customProps.TryGetValue(path, out propRef));
 }
Пример #11
0
        public ItemType(IReadOnlyItem itemType, HashSet <string> coreIds = null, bool defaultProperties = false, Func <string, string> getName = null)
        {
            var relType    = itemType.Property("relationship_id").AsItem();
            var sourceProp = itemType.SourceId();

            SourceTypeName = sourceProp.Attribute("name").Value ?? sourceProp.KeyedName().Value;
            var relatedProp = itemType.RelatedId();

            RelatedTypeName = relatedProp.Attribute("name").Value ?? relatedProp.KeyedName().Value;
            if (relType.Exists)
            {
                RelationshipTypeId = itemType.Id();
                TabLabel           = itemType.Property("label").Value;
                RelationshipView   = itemType.Relationships("Relationship View")
                                     .FirstOrNullItem(i => i.Property("start_page").HasValue())
                                     .Property("start_page").Value;
                itemType = relType;
            }

            Id             = itemType.Id();
            IsCore         = itemType.Property("core").AsBoolean(coreIds?.Contains(itemType.Id()) == true);
            IsDependent    = itemType.Property("is_dependent").AsBoolean(false);
            IsFederated    = itemType.Property("implementation_type").Value == "federated";
            IsRelationship = itemType.Property("is_relationship").AsBoolean(false);
            IsPolymorphic  = itemType.Property("implementation_type").Value == "polymorphic";
            IsVersionable  = itemType.Property("is_versionable").AsBoolean(false);
            Label          = itemType.Property("label").Value;
            Name           = itemType.Property("name").Value
                             ?? itemType.KeyedName().Value
                             ?? itemType.IdProp().KeyedName().Value;
            Reference   = ItemReference.FromFullItem(itemType, true);
            Description = itemType.Property("description").Value;
            if (itemType.Property("class_structure").HasValue())
            {
                ClassStructure = new ClassStructure(itemType.Property("class_structure").Value);
            }
            DefaultPageSize = itemType.Property("default_page_size").AsInt();
            MaxRecords      = itemType.Property("maxrecords").AsInt();

            HasLifeCycle = itemType.Relationships("ItemType Life Cycle").Any();

            _properties = itemType.Relationships("Property")
                          .Select(p => Property.FromItem(p, this, getName))
                          .ToDictionary(p => p.Name, StringComparer.OrdinalIgnoreCase);

            if (_properties.Count > 0 || defaultProperties)
            {
                if (!_properties.ContainsKey("id"))
                {
                    foreach (var property in ElementFactory.Local.FromXml(string.Format(_coreProperties, Id))
                             .Items()
                             .Select(p => Property.FromItem(p, this))
                             .Where(p => !_properties.ContainsKey(p.Name)))
                    {
                        _properties[property.Name] = property;
                    }
                }

                var propAml = @"<Item type='Property'>
  <column_alignment>left</column_alignment>
  <data_source keyed_name='{0}' type='ItemType' name='{0}'>{1}</data_source>
  <data_type>item</data_type>
  <is_hidden>{3}</is_hidden>
  <is_hidden2>1</is_hidden2>
  <is_indexed>1</is_indexed>
  <is_keyed>0</is_keyed>
  <is_multi_valued>0</is_multi_valued>
  <is_required>0</is_required>
  <item_behavior>float</item_behavior>
  <readonly>0</readonly>
  <sort_order>2944</sort_order>
  <name>{2}</name>
</Item>";
                if (sourceProp.Exists && !_properties.ContainsKey("source_id"))
                {
                    _properties["source_id"] = Property.FromItem(ElementFactory.Local.FromXml(string.Format(propAml
                                                                                                            , SourceTypeName
                                                                                                            , sourceProp.Value
                                                                                                            , "source_id"
                                                                                                            , "1")).AssertItem(), this);
                }

                if (relatedProp.Exists && !_properties.ContainsKey("related_id"))
                {
                    _properties["related_id"] = Property.FromItem(ElementFactory.Local.FromXml(string.Format(propAml
                                                                                                             , RelatedTypeName
                                                                                                             , relatedProp.Value
                                                                                                             , "related_id"
                                                                                                             , "0")).AssertItem(), this);
                }
            }
            WithExtra(itemType);
        }
Пример #12
0
        private async Task <bool> ReloadSecondaryMetadata()
        {
            var methods      = _conn.ApplyAsync("<Item type='Method' action='get' select='config_id,core,name'></Item>", true, false).ToTask();
            var sysIdents    = _conn.ApplyAsync(@"<Item type='Identity' action='get' select='id,name'>
                                      <name condition='in'>'World', 'Creator', 'Owner', 'Manager', 'Innovator Admin', 'Super User'</name>
                                    </Item>", true, true).ToTask();
            var sqls         = _conn.ApplyAsync("<Item type='SQL' action='get' select='id,name,type'></Item>", true, false).ToTask();
            var customProps  = _conn.ApplyAsync(@"<Item type='Property' action='get' select='name,source_id(id,name)'>
                                          <created_by_id condition='ne'>AD30A6D8D3B642F5A2AFED1A4B02BEFA</created_by_id>
                                          <source_id>
                                            <Item type='ItemType' action='get'>
                                              <core>1</core>
                                              <created_by_id>AD30A6D8D3B642F5A2AFED1A4B02BEFA</created_by_id>
                                            </Item>
                                          </source_id>
                                        </Item>", true, false).ToTask();
            var polyLists    = _conn.ApplyAsync(@"<Item type='Property' action='get' select='data_source(id)'>
                                          <name>itemtype</name>
                                          <data_type>list</data_type>
                                          <source_id>
                                            <Item type='ItemType' action='get'>
                                              <implementation_type>polymorphic</implementation_type>
                                            </Item>
                                          </source_id>
                                        </Item>", true, false).ToTask();
            var sequences    = _conn.ApplyAsync(@"<Item type='Sequence' action='get' select='name'></Item>", true, false).ToTask();
            var elementTypes = _conn.ApplyAsync(@"<Item action='get' type='cmf_ElementType' select='generated_type'>
                                                <Relationships>
                                                  <Item action='get' type='cmf_PropertyType' select='generated_type'>
                                                  </Item>
                                                </Relationships>
                                              </Item>", true, false).ToTask();
            var contentTypes = _conn.ApplyAsync(@"<Item action='get' type='cmf_ContentType' select='linked_item_type'>
                                              <linked_item_type>
                                                <Item type='ItemType' action='get'>
                                                </Item>
                                              </linked_item_type>
                                            </Item>", true, false).ToTask();

            _methods = (await methods).Items().Select(i =>
            {
                var method       = Method.FromFullItem(i, false);
                method.KeyedName = i.Property("name").AsString("");
                method.IsCore    = i.Property("core").AsBoolean(false);
                return(method);
            }).ToArray();


            _systemIdentities = (await sysIdents).Items()
                                .Select(i =>
            {
                var itemRef       = ItemReference.FromFullItem(i, false);
                itemRef.KeyedName = i.Property("name").AsString("");
                return(itemRef);
            }).ToDictionary(i => i.Unique);


            _sql = (await sqls).Items()
                   .Select(i =>
            {
                var itemRef       = Sql.FromFullItem(i, false);
                itemRef.KeyedName = i.Property("name").AsString("");
                itemRef.Type      = i.Property("type").AsString("");
                return(itemRef);
            }).ToDictionary(i => i.KeyedName.ToLowerInvariant(), StringComparer.OrdinalIgnoreCase);

            var           r = (await customProps);
            IReadOnlyItem itemType;

            foreach (var customProp in r.Items())
            {
                itemType = customProp.SourceItem();
                _customProps[new ItemProperty()
                             {
                                 ItemType = itemType.Property("name").Value,
                                 ItemTypeId = itemType.Id(),
                                 Property = customProp.Property("name").Value,
                                 PropertyId = customProp.Id()
                             }] = new ItemReference("Property", customProp.Id())
                {
                    KeyedName = customProp.Property("name").Value
                };
            }

            _polyItemLists = (await polyLists).Items()
                             .OfType <Innovator.Client.Model.Property>()
                             .Select(i => new ItemReference("List", i.DataSource().Value)
            {
                KeyedName = i.DataSource().KeyedName().Value
            }).ToArray();

            _sequences = (await sequences).Items().Select(i => ItemReference.FromFullItem(i, true)).ToArray();

            try
            {
                _cmfGeneratedTypes = new HashSet <string>((await elementTypes).Items().SelectMany(x =>
                {
                    var relations = x.Relationships().Select(y => y.Property("generated_type").Value).ToList();
                    relations.Add(x.Property("generated_type").Value);
                    return(relations);
                }));

                _cmfLinkedTypes = (await contentTypes).Items().ToDictionary(x => x.Property("linked_item_type").Value, y => ItemReference.FromFullItem(y, true));
            }
            catch (ServerException)
            {
                //TODO: Do something when cmf types don't exist
            }
            return(true);
        }
Пример #13
0
        private async Task <bool> ReloadItemTypeMetadata()
        {
            var itemTypes        = _conn.ApplyAsync("<Item type='ItemType' action='get' select='is_versionable,is_dependent,implementation_type,core,name,label'></Item>", true, true).ToTask();
            var relTypes         = _conn.ApplyAsync("<Item action='get' type='RelationshipType' related_expand='0' select='related_id,source_id,relationship_id,name,label' />", true, true).ToTask();
            var sortedProperties = _conn.ApplyAsync(@"<Item type='Property' action='get' select='source_id'>
  <order_by condition='is not null'></order_by>
</Item>", true, false).ToTask();
            var floatProps       = _conn.ApplyAsync(@"<Item type='Property' action='get' select='source_id,item_behavior,name' related_expand='0'>
                                      <data_type>item</data_type>
                                      <data_source>
                                        <Item type='ItemType' action='get'>
                                          <is_versionable>1</is_versionable>
                                        </Item>
                                      </data_source>
                                      <item_behavior>float</item_behavior>
                                      <name condition='not in'>'config_id','id'</name>
                                    </Item>", true, false).ToTask();

            // Load in the item types
            var      r = await itemTypes;
            ItemType result;

            foreach (var itemTypeData in r.Items())
            {
                result = new ItemType()
                {
                    Id            = itemTypeData.Id(),
                    IsCore        = itemTypeData.Property("core").AsBoolean(false),
                    IsDependent   = itemTypeData.Property("is_dependent").AsBoolean(false),
                    IsFederated   = itemTypeData.Property("implementation_type").Value == "federated",
                    IsPolymorphic = itemTypeData.Property("implementation_type").Value == "polymorphic",
                    IsVersionable = itemTypeData.Property("is_versionable").AsBoolean(false),
                    Label         = itemTypeData.Property("label").Value,
                    Name          = itemTypeData.Property("name").Value,
                    Reference     = ItemReference.FromFullItem(itemTypeData, true)
                };
                _itemTypesByName[result.Name] = result;
            }

            _itemTypesById = _itemTypesByName.Values.ToDictionary(i => i.Id);

            // Load in the relationship types
            r = await relTypes;
            ItemType relType;
            ItemType source;
            ItemType related;

            foreach (var rel in r.Items())
            {
                if (rel.SourceId().Attribute("name").HasValue() &&
                    _itemTypesByName.TryGetValue(rel.SourceId().Attribute("name").Value, out source) &&
                    rel.Property("relationship_id").Attribute("name").HasValue() &&
                    _itemTypesByName.TryGetValue(rel.Property("relationship_id").Attribute("name").Value, out relType))
                {
                    source.Relationships.Add(relType);
                    relType.Source   = source;
                    relType.TabLabel = rel.Property("label").AsString(null);
                    if (rel.RelatedId().Attribute("name").HasValue() &&
                        _itemTypesByName.TryGetValue(rel.RelatedId().Attribute("name").Value, out related))
                    {
                        relType.Related = related;
                    }
                }
            }

            // Sorted Types
            r = await sortedProperties;
            foreach (var prop in r.Items())
            {
                if (_itemTypesByName.TryGetValue(prop.SourceId().Attribute("name").Value, out result))
                {
                    result.IsSorted = true;
                }
            }

            // Float props
            r = await floatProps;
            foreach (var floatProp in r.Items())
            {
                if (_itemTypesByName.TryGetValue(floatProp.SourceId().Attribute("name").Value.ToLowerInvariant(), out result))
                {
                    result.FloatProperties.Add(floatProp.Property("name").AsString(""));
                }
            }

            return(true);
        }
Пример #14
0
 public bool CustomPropertyByPath(ItemProperty path, out ItemReference propRef)
 {
     propRef = null;
     return(false);
 }
Пример #15
0
        public void Add(IReadOnlyItem item)
        {
            if (item.Attribute(XmlFlags.Attr_ScriptType).HasValue())
            {
                return;
            }

            switch (item.TypeName().ToLowerInvariant())
            {
            case "method":
                var method = Method.FromFullItem(item, false);
                method.KeyedName = item.Property("name").AsString("");
                method.IsCore    = item.Property("core")
                                   .AsBoolean(_coreIds.Contains(item.ConfigId().Value ?? item.Id()));
                _methods.Add(method);
                break;

            case "itemtype":
                var itemType = new ItemType()
                {
                    Id     = item.Id(),
                    IsCore = item.Property("core")
                             .AsBoolean(_coreIds.Contains(item.Id())),
                    IsDependent   = item.Property("is_dependent").AsBoolean(false),
                    IsFederated   = item.Property("implementation_type").Value == "federated",
                    IsPolymorphic = item.Property("implementation_type").Value == "polymorphic",
                    IsVersionable = item.Property("is_versionable").AsBoolean(false),
                    Label         = item.Property("label").Value,
                    Name          = item.Property("name").Value
                                    ?? item.KeyedName().Value
                                    ?? item.IdProp().KeyedName().Value,
                    Reference = ItemReference.FromFullItem(item, true)
                };
                if (string.IsNullOrEmpty(itemType.Name))
                {
                    return;
                }
                _itemTypesByName[itemType.Name] = itemType;
                Add(item.Relationships("Property"));
                break;

            case "sql":
                var sql = Sql.FromFullItem(item, false);
                sql.KeyedName = item.Property("name").Value
                                ?? item.KeyedName().Value
                                ?? item.IdProp().KeyedName().Value
                                ?? "";
                sql.Type = item.Property("type").AsString("");
                if (string.IsNullOrEmpty(sql.KeyedName))
                {
                    return;
                }
                _sql[sql.KeyedName.ToLowerInvariant()] = sql;
                break;

            case "property":
                _propertyNames[item.Id()] = item.Property("name").Value
                                            ?? item.KeyedName().Value
                                            ?? item.IdProp().KeyedName().Value;
                break;
            }
        }