Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix versionable item references; fix creating a new package using an … #204

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 5 additions & 25 deletions InnovatorAdmin.Api/Export/ExportProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private async Task<IEnumerable<ItemReference>> NormalizeReferences(IEnumerable<I
// For versionable item types, get the latest generation
var toResolve = (await _conn.ApplyAsync(@"<Item type='@0' action='get' select='config_id'>
<id condition='in'>@1</id>
<is_current>0</is_current>
<is_current>1</is_current>
</Item>", true, false, group.Key.Type, group.Select(i => i.Unique).ToList()).ConfigureAwait(false)).Items()
.ToDictionary(i => i.Id(), i => i.ConfigId().Value);
results.AddRange(group.Where(i => !toResolve.ContainsKey(i.Unique)));
Expand Down Expand Up @@ -1221,13 +1221,12 @@ private void FloatVersionableRefs(XmlDocument result)
switch (e.LocalName)
{
case "Item":
// For item tags that are float properties, or root level item tags, set them to float
// For item tags root level item tags, set them to float
if (e.Parent().Parent() != null
&& e.Parent().Parent().LocalName == "Item"
&& e.Attribute("action", "") != "get")
{
if (_metadata.ItemTypeByName(e.Parent().Parent().Attribute("type").ToLowerInvariant(), out parent)
&& parent.FloatProperties.Contains(e.Parent().LocalName))
if (_metadata.ItemTypeByName(e.Parent().Parent().Attribute("type").ToLowerInvariant(), out parent))
{
e.SetAttribute(XmlFlags.Attr_Float, "1");
e.SetAttribute("id", e.Element("config_id", e.Attribute("id")));
Expand All @@ -1240,11 +1239,10 @@ private void FloatVersionableRefs(XmlDocument result)
}
break;
default:
// For item properties (with no Item tag) set to float, make sure they float
// For item properties (with no Item tag), make sure they float
if (!e.Elements().Any()
&& e.Parent().LocalName == "Item"
&& _metadata.ItemTypeByName(e.Parent().Attribute("type").ToLowerInvariant(), out parent)
&& parent.FloatProperties.Contains(e.LocalName))
&& _metadata.ItemTypeByName(e.Parent().Attribute("type").ToLowerInvariant(), out parent))
{
refs.Add(Tuple.Create(itemType, e.InnerText));
e.SetAttribute(_needs_float, "1");
Expand Down Expand Up @@ -2456,24 +2454,6 @@ internal static void EnsureSystemData(IAsyncConnection _conn, ref Dictionary<str
result.Relationships.Add(relType);
}
}

var floatProps = _conn.Apply(@"<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>").Items();
foreach (var floatProp in floatProps)
{
if (_itemTypes.TryGetValue(floatProp.SourceId().Attribute("name").Value.ToLowerInvariant(), out result))
{
result.FloatProperties.Add(floatProp.Property("name").AsString(""));
}
}
}
}
}
Expand Down
29 changes: 14 additions & 15 deletions InnovatorAdmin.Api/ItemReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ namespace InnovatorAdmin
public class ItemReference : IComparable<ItemReference>, IComparable, IEquatable<ItemReference>, ICloneable
{
private string _unique;
private string _baseUnique;
private string _type;

public string KeyedName { get; set; }
// Used when understanding dependencies
public ItemReference Origin { get; set; }
public string Type
{
get { return _type; }
set { _type = value; }
}
public string Unique
public string Type { get; set; }
public string Unique
{
get { return _unique; }
set
{
_unique = value;
if (_unique.IndexOf("[config_id] = '") > 0)
_baseUnique = _unique.Substring(_unique.Length - 33, 32);
// Example string: "[Item_Type].[config_id] = 'DBE8A841D6B74C679B1B3B9515C0377A'"
if (!String.IsNullOrEmpty(value) && value.IndexOf("[config_id] = '") > 0)
{
_unique = value.Substring(value.Length - 33, 32);
}
else
{
_unique = value;
}
}
}

Expand Down Expand Up @@ -203,13 +203,13 @@ public override bool Equals(object obj)

bool IEquatable<ItemReference>.Equals(ItemReference itemRef)
{
return string.Equals(_baseUnique ?? _unique, itemRef._baseUnique ?? itemRef._unique, StringComparison.OrdinalIgnoreCase)
return string.Equals(_unique, itemRef._unique, StringComparison.OrdinalIgnoreCase)
&& string.Equals(this.Type, itemRef.Type, StringComparison.OrdinalIgnoreCase);
}

public override int GetHashCode()
{
return (_baseUnique ?? _unique ?? "").ToUpperInvariant().GetHashCode()
return (_unique ?? "").ToUpperInvariant().GetHashCode()
^ (this.Type ?? "").ToUpperInvariant().GetHashCode();
}

Expand All @@ -235,9 +235,8 @@ public ItemReference Clone()
var result = new ItemReference();
result.KeyedName = this.KeyedName;
result.Origin = this.Origin;
result._type = this._type;
result.Type = this.Type;
result._unique = this._unique;
result._baseUnique = this._baseUnique;
return result;
}

Expand Down
11 changes: 0 additions & 11 deletions InnovatorAdmin.Api/Metadata/ArasMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,17 +361,6 @@ private async Task<bool> ReloadItemTypeMetadata()
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;
}

Expand Down
8 changes: 1 addition & 7 deletions InnovatorAdmin.Api/Metadata/ItemType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ private Dictionary<string, Property> _properties
= new Dictionary<string, Property>(StringComparer.OrdinalIgnoreCase);

public IEnumerable<string> ClassPaths { get; set; }
/// <summary>
/// List of the properties which reference versionable items and are set to float
/// </summary>
public IList<string> FloatProperties
{
get { return _floatProps; }
}

/// <summary>
/// ID of the item type
/// </summary>
Expand Down