Exemplo n.º 1
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);
        }
Exemplo n.º 2
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;
            }
        }