private IPromise<Property> GetProperty(ItemType itemType, string name)
    {
      if (_conn == null || itemType.Properties.Count > 0)
        return LoadedProperty(itemType, name);

      return _conn.ApplyAsync("<AML><Item action=\"get\" type=\"ItemType\" select=\"name\"><name>@0</name><Relationships><Item action=\"get\" type=\"Property\" select=\"name,label,data_type,data_source\" /></Relationships></Item></AML>"
        , true, true, itemType.Name)
        .Continue(r =>
        {
          LoadProperties(itemType, r.AssertItem());
          return LoadedProperty(itemType, name);
        });
    }
 private IPromise<Property> LoadedProperty(ItemType itemType, string name)
 {
   Property prop;
   if (itemType.Properties.TryGetValue(name, out prop))
   {
     return Promises.Resolved(prop);
   }
   else
   {
     return Promises.Rejected<Property>(new KeyNotFoundException());
   }
 }
    private IPromise<IEnumerable<Property>> GetProperties(ItemType itemType)
    {
      if (_conn == null || itemType.Properties.Count > 0)
        return Promises.Resolved<IEnumerable<Property>>(itemType.Properties.Values);

      return _conn.ApplyAsync("<AML><Item action=\"get\" type=\"ItemType\" select=\"name\"><name>@0</name><Relationships><Item action=\"get\" type=\"Property\" select=\"name,label,data_type,data_source\" /></Relationships></Item></AML>"
        , true, true, itemType.Name)
        .Convert(r => {
          LoadProperties(itemType, r.AssertItem());
          return (IEnumerable<Property>)itemType.Properties.Values;
        });
    }
 /// <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");
   Property newProp = null;
   foreach (var prop in props)
   {
     newProp = new Property(prop.Property("name").Value);
     newProp.SetType(prop.Property("data_type").Value);
     if (newProp.Type == PropertyType.item && prop.Property("data_source").Attribute("name").HasValue())
     {
       newProp.Restrictions.Add(prop.Property("data_source").Attribute("name").Value);
     }
     type.Properties.Add(newProp);
   }
 }
 private void RecurseProperties(ItemType itemType, IEnumerable<string> remainingPath, Action<ItemType> callback)
 {
   if (remainingPath.Any())
   {
     GetProperty(itemType, remainingPath.First())
     .Done(currProp =>
     {
       ItemType it;
       if (currProp.Type == PropertyType.item
         && currProp.Restrictions.Any()
         && _itemTypes.TryGetValue(currProp.Restrictions.First(), out it))
       {
         RecurseProperties(it, remainingPath.Skip(1), callback);
       }
       else
       {
         callback(itemType);
       }
     })
     .Fail(ex => callback(itemType));
   }
   else
   {
     callback(itemType);
   }
 }
예제 #6
0
 public ItemType(string name, ItemType source, ItemType related)
 {
   this.Name = name;
   this.Source = source;
   this.Related = related;
 }
예제 #7
0
 private bool TryGetProperty(ItemType itemType, string name, out Property prop)
 {
     if (itemType.Properties.Count < 1)
     LoadProperties(itemType, GetItems("ApplyItem", string.Format("<AML><Item action=\"get\" type=\"ItemType\" select=\"name\"><name>{0}</name><Relationships><Item action=\"get\" type=\"Property\" select=\"name,label,data_type,data_source\" /></Relationships></Item></AML>", itemType.Name)));
       return itemType.Properties.TryGetValue(name, out prop);
 }
예제 #8
0
 /// <summary>
 /// Loads the property metadata for the current type into the schema.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="properties">The properties.</param>
 private void LoadProperties(ItemType type, IEnumerable<XmlElement> properties)
 {
     if (properties.Any())
       {
     var props = properties.Single().ElementsByXPath("Relationships/Item[@type='Property']");
     Property newProp = null;
     foreach (var prop in props)
     {
       newProp = new Property(prop.Element("name").InnerText);
       newProp.SetType(prop.Element("data_type").InnerText);
       if (newProp.Type == PropertyType.item && prop.Element("data_source").Attribute("name") != null)
       {
     newProp.Restrictions.Add(prop.Element("data_source").Attribute("name"));
       }
       type.Properties.Add(newProp);
     }
       }
 }
예제 #9
0
 private IEnumerable<Property> GetProperties(ItemType itemType)
 {
     if (itemType.Properties.Count < 1)
     LoadProperties(itemType, GetItems("ApplyItem", string.Format("<AML><Item action=\"get\" type=\"ItemType\" select=\"name\"><name>{0}</name><Relationships><Item action=\"get\" type=\"Property\" select=\"name,label,data_type,data_source\" /></Relationships></Item></AML>", itemType.Name)));
       return itemType.Properties.Values;
 }