Beispiel #1
0
 public ItemType WithScripts(IReadOnlyItem itemType)
 {
     foreach (var prop in itemType.Relationships("Property")
              .Select(p => Property.FromItem(p, this)))
     {
         _properties[prop.Name] = prop;
     }
     WithExtra(itemType);
     return(this);
 }
        /// <summary>
        /// Loads the property metadata for the current type into the schema.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="itemTypeMeta">The properties.</param>
        private void LoadProperties(ItemType type, IReadOnlyItem itemTypeMeta)
        {
            var props = itemTypeMeta.Relationships("Property")
                        .Concat(itemTypeMeta.Relationships("ItemType_xPropertyDefinition").Select(i => i.RelatedItem()));

            foreach (var prop in props)
            {
                var newProp = Property.FromItem(prop, type);
                type.Properties[newProp.Name] = newProp;
            }
        }
        /// <summary>
        /// Gets a promise to return information about all properties of a given Item Type
        /// </summary>
        public IPromise <IEnumerable <Property> > GetProperties(ItemType itemType)
        {
            if (_conn == null || itemType.Properties.Count > 0)
            {
                return(Promises.Resolved <IEnumerable <Property> >(itemType.Properties.Values));
            }

            var xPropQuery = default(string);

            if (_itemTypesById.ContainsKey("A253DB1415194344AEFB5E6A2029AB3A"))
            {
                xPropQuery = @"<Item type='ItemType_xPropertyDefinition' action='get' select='related_id(name,label,data_type,data_source,stored_length,prec,scale,default_value,column_width,is_required,readonly)'></Item>";
            }

            var aml = $@"<AML>
  <Item action='get' type='ItemType' select='name'>
    <name>@0</name>
    <Relationships>
      <Item action='get' type='Property' select='name,label,data_type,data_source,stored_length,prec,scale,foreign_property(name,source_id),is_hidden,is_hidden2,sort_order,default_value,column_width,is_required,readonly,help_text,help_tooltip,class_path,keyed_name_order,default_search,pattern,order_by' />
      {xPropQuery}
    </Relationships>
  </Item>
</AML>";

            var promise = _conn.ApplyAsync(aml, true, true, itemType.Name)
                          .Convert(r =>
            {
                LoadProperties(itemType, r.AssertItem());
                return((IEnumerable <Property>)itemType.Properties.Values);
            }).Fail(ex => System.Diagnostics.Debug.Print("PROPLOAD: " + ex.ToString()));

            if (!string.IsNullOrEmpty(xPropQuery))
            {
                promise = promise.Continue(p =>
                {
                    return(_conn.ApplyAsync(@"<Item type='xClassificationTree' action='get' select='id'>
  <Relationships>
    <Item type='xClassificationTree_ItemType' action='get' select='id'>
      <related_id>@0</related_id>
    </Item>
    <Item action='get' type='xClass' select='id'>
      <Relationships>
        <Item action='get' type='xClass_xPropertyDefinition' select='related_id(name,label,data_type,data_source,stored_length,prec,scale,default_value,column_width,is_required,readonly)'>
          <is_current>1</is_current>
        </Item>
      </Relationships>
    </Item>
  </Relationships>
</Item>", true, false, itemType.Id));
                }).Convert(r =>
                {
                    foreach (var prop in r.Items()
                             .SelectMany(i => i.Relationships("xClass"))
                             .SelectMany(i => i.Relationships("xClass_xPropertyDefinition"))
                             .Select(i => i.RelatedItem()))
                    {
                        var newProp = Property.FromItem(prop, itemType);
                        itemType.Properties[newProp.Name] = newProp;
                    }
                    return((IEnumerable <Property>)itemType.Properties.Values);
                }).Fail(ex => System.Diagnostics.Debug.Print("PROPLOAD: " + ex.ToString()));
            }

            return(promise);
        }
Beispiel #4
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);
        }