public static string GetStringValue(this Oms oms, InstanceHandle[] stringComponents, InstanceHandle currentInstance) { if (stringComponents == null) { return(null); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < stringComponents.Length; i++) { InstanceHandle ihParent = oms.GetParentClassInstance(stringComponents[i]); if (oms.GetInstanceID(ihParent) == KnownInstanceGuids.Classes.ExtractSingleInstanceStringComponent) { InstanceHandle ihRelationship = oms.GetRelatedInstance(stringComponents[i], oms.GetInstance(KnownRelationshipGuids.Extract_Single_Instance_String_Component__has__Relationship)); InstanceHandle relInst = oms.GetRelatedInstance(currentInstance, ihRelationship); if (relInst.IsEmpty) { // FIXME } sb.Append(GetInstanceTitle(oms, relInst)); } else if (oms.GetInstanceID(ihParent) == KnownInstanceGuids.Classes.InstanceAttributeStringComponent) { InstanceHandle ihAttribute = oms.GetRelatedInstance(stringComponents[i], oms.GetInstance(KnownRelationshipGuids.Instance_Attribute_String_Component__has__Attribute)); string value = oms.GetAttributeValue <string>(currentInstance, ihAttribute); sb.Append(value); } else if (oms.GetInstanceID(ihParent) == KnownInstanceGuids.Classes.TextConstantStringComponent) { string value = oms.GetAttributeValue <string>(stringComponents[i], oms.GetInstance(KnownAttributeGuids.Text.Value)); sb.Append(value); } } return(sb.ToString()); }
public static string GetInstanceTitle(this Oms oms, InstanceHandle inst) { InstanceHandle ihParentClass = oms.GetRelatedInstance(inst, oms.GetInstance(KnownRelationshipGuids.Instance__for__Class)); if (ihParentClass.IsEmpty) { Console.WriteLine("[mocha warning]: GetInstanceTitle: parent class is empty for inst with UID {0}", oms.GetInstanceID(inst)); Console.WriteLine("---------------- (using relationship with UID {0}, valid? {1} )", KnownRelationshipGuids.Instance__for__Class, oms.GetInstance(KnownRelationshipGuids.Instance__for__Class)); } InstanceHandle ihTitleString = oms.GetRelatedInstance(ihParentClass, oms.GetInstance(KnownRelationshipGuids.Class__instance_labeled_by__String)); InstanceHandle[] ihStringComponents = oms.GetRelatedInstances(ihTitleString, oms.GetInstance(KnownRelationshipGuids.String__has__String_Component)); string value = oms.GetStringValue(ihStringComponents, inst); return(value); }