コード例 #1
0
        private void SetIndex(IMochaStore library, MochaInstance instance)
        {
            if (instance.Index == null)
            {
                return;
            }

            MochaAttributeValue mav = new MochaAttributeValue();

            mav.AttributeInstanceID = global::Mocha.Core.KnownAttributeGuids.Numeric.Index;
            mav.Value = instance.Index.Value;
            instance.AttributeValues.Add(mav);
        }
コード例 #2
0
        private void SetParentClass(IMochaStore library, Guid sourceInstanceID, Guid parentClassID)
        {
            MochaRelationship relHasSuperClass = new MochaRelationship();

            relHasSuperClass.SourceInstanceID = sourceInstanceID;
            relHasSuperClass.DestinationInstanceIDs.Add(parentClassID);
            relHasSuperClass.RelationshipInstanceID = global::Mocha.Core.KnownRelationshipGuids.Instance__for__Class;
            library.Relationships.Add(relHasSuperClass);

            MochaRelationship relHasSubClass = new MochaRelationship();

            relHasSubClass.SourceInstanceID = parentClassID;
            relHasSubClass.DestinationInstanceIDs.Add(sourceInstanceID);
            relHasSubClass.RelationshipInstanceID = global::Mocha.Core.KnownRelationshipGuids.Class__has__Instance;
            library.Relationships.Add(relHasSubClass);
        }
コード例 #3
0
        private void SetClass(IMochaStore library, Guid id)
        {
            MochaRelationship relClass__has__Instance = new MochaRelationship();

            relClass__has__Instance.SourceInstanceID       = global::Mocha.Core.KnownInstanceGuids.Classes.Class;
            relClass__has__Instance.RelationshipInstanceID = global::Mocha.Core.KnownRelationshipGuids.Class__has__Instance;
            relClass__has__Instance.DestinationInstanceIDs.Add(id);
            library.Relationships.Add(relClass__has__Instance);

            MochaRelationship relInstance__for__Class = new MochaRelationship();

            relInstance__for__Class.SourceInstanceID       = id;
            relInstance__for__Class.RelationshipInstanceID = global::Mocha.Core.KnownRelationshipGuids.Instance__for__Class;
            relInstance__for__Class.DestinationInstanceIDs.Add(global::Mocha.Core.KnownInstanceGuids.Classes.Class);
            library.Relationships.Add(relInstance__for__Class);
        }
コード例 #4
0
        private void SetOwner(IMochaStore library, Guid instanceId, Guid ownerId)
        {
            MochaRelationship relClass__has__Instance = new MochaRelationship();

            relClass__has__Instance.SourceInstanceID       = instanceId;
            relClass__has__Instance.RelationshipInstanceID = global::Mocha.Core.KnownRelationshipGuids.Class__has_owner__User;
            relClass__has__Instance.DestinationInstanceIDs.Add(ownerId);
            library.Relationships.Add(relClass__has__Instance);

            MochaRelationship relInstance__for__Class = new MochaRelationship();

            relInstance__for__Class.SourceInstanceID       = ownerId;
            relInstance__for__Class.RelationshipInstanceID = global::Mocha.Core.KnownRelationshipGuids.User__owner_for__Class;
            relInstance__for__Class.DestinationInstanceIDs.Add(instanceId);
            library.Relationships.Add(relInstance__for__Class);
        }
コード例 #5
0
        private void SetSource(IMochaStore library, Guid instanceId, Guid sourceTypeId)
        {
            MochaRelationship relClass__has__Instance = new MochaRelationship();

            relClass__has__Instance.SourceInstanceID       = instanceId;
            relClass__has__Instance.RelationshipInstanceID = global::Mocha.Core.KnownRelationshipGuids.Class__has__Object_Source;
            relClass__has__Instance.DestinationInstanceIDs.Add(sourceTypeId);
            library.Relationships.Add(relClass__has__Instance);

            MochaRelationship relInstance__for__Class = new MochaRelationship();

            relInstance__for__Class.SourceInstanceID       = sourceTypeId;
            relInstance__for__Class.RelationshipInstanceID = global::Mocha.Core.KnownRelationshipGuids.Object_Source__for__Class;
            relInstance__for__Class.DestinationInstanceIDs.Add(instanceId);
            library.Relationships.Add(relInstance__for__Class);
        }
コード例 #6
0
        private MochaInstance LoadInstance(IMochaStore library, MarkupTagElement tag)
        {
            if (tag == null)
            {
                return(null);
            }
            if (tag.FullName != "instance")
            {
                return(null);
            }

            MarkupAttribute attID = tag.Attributes["id"];

            if (attID == null)
            {
                return(null);
            }

            MarkupAttribute attIndex = tag.Attributes["index"];
            int?            index    = null;

            if (attIndex != null)
            {
                if (Int32.TryParse(attIndex.Value, out int index2))
                {
                    index = index2;
                }
            }

            MarkupAttribute attClassInstanceId = tag.Attributes["classInstanceId"];
            MarkupAttribute attSuperClassId    = tag.Attributes["superClassId"];

            Guid          instanceId = new Guid(attID.Value);
            MochaInstance inst       = library.Instances[instanceId];

            if (inst == null)
            {
                inst    = new MochaInstance();
                inst.ID = instanceId;
            }
            inst.Index = index;

            if (inst.Index != null)
            {
                // SetIndex(library, inst);
            }

            if (attClassInstanceId != null)
            {
                if (Guid.TryParse(attClassInstanceId.Value, out Guid classInstanceId))
                {
                    SetParentClass(library, inst.ID, classInstanceId);
                }
                else
                {
                    Console.Error.WriteLine("bad guid for classInstanceId: {0}", attClassInstanceId.Value);
                }
            }
            if (attSuperClassId != null)
            {
                if (Guid.TryParse(attSuperClassId.Value, out Guid superClassId))
                {
                    SetClass(library, inst.ID);
                    SetOwner(library, inst.ID, global::Mocha.Core.KnownInstanceGuids.Users.XQEnvironments);
                    SetSource(library, inst.ID, library.DefaultObjectSourceID);                     // global::Mocha.Core.KnownInstanceGuids.ObjectSources.System);
                    SetSuperClass(library, inst.ID, superClassId);
                }
                else
                {
                    Console.Error.WriteLine("bad guid for superClassId: {0}", attSuperClassId.Value);
                }
            }

            MarkupTagElement tagAttributeValues = tag.Elements["attributeValues"] as MarkupTagElement;

            if (tagAttributeValues != null)
            {
                for (int i = 0; i < tagAttributeValues.Elements.Count; i++)
                {
                    MochaAttributeValue attv = LoadAttributeValue(tagAttributeValues.Elements[i] as MarkupTagElement);
                    if (attv == null)
                    {
                        continue;
                    }

                    inst.AttributeValues.Add(attv);
                }
            }


            MarkupTagElement tagRelationships = tag.Elements["relationships"] as MarkupTagElement;

            if (tagRelationships != null)
            {
                for (int i = 0; i < tagRelationships.Elements.Count; i++)
                {
                    MarkupTagElement tagRelationship = tagRelationships.Elements[i] as MarkupTagElement;
                    if (tagRelationship == null)
                    {
                        continue;
                    }
                    if (tagRelationship.FullName != "relationship")
                    {
                        continue;
                    }

                    MarkupAttribute attRelationshipInstanceId = tagRelationship.Attributes["relationshipInstanceId"];
                    if (attRelationshipInstanceId == null)
                    {
                        continue;
                    }

                    if (String.IsNullOrEmpty(attRelationshipInstanceId.Value))
                    {
                        Console.Error.WriteLine("relationshipInstanceId not specified for relationship");
                        continue;
                    }

                    MochaRelationship rel = new MochaRelationship();
                    rel.SourceInstanceID = inst.ID;

                    if (Guid.TryParse(attRelationshipInstanceId.Value, out Guid id))
                    {
                        rel.RelationshipInstanceID = id;
                    }
                    else
                    {
                        Console.Error.WriteLine("bad guid for relationship: relationshipInstanceId='{0}'", attRelationshipInstanceId.Value);
                    }

                    MarkupTagElement tagTargetInstances = tagRelationship.Elements["targetInstances"] as MarkupTagElement;
                    if (tagTargetInstances != null)
                    {
                        for (int j = 0; j < tagTargetInstances.Elements.Count; j++)
                        {
                            MarkupTagElement tagInstanceReference = tagTargetInstances.Elements[j] as MarkupTagElement;
                            if (tagInstanceReference == null)
                            {
                                continue;
                            }
                            if (tagInstanceReference.FullName != "instanceReference")
                            {
                                continue;
                            }

                            MarkupAttribute attInstanceId = tagInstanceReference.Attributes["instanceId"];
                            if (attInstanceId == null)
                            {
                                continue;
                            }

                            if (Guid.TryParse(attInstanceId.Value, out Guid instId))
                            {
                                rel.DestinationInstanceIDs.Add(instId);
                            }
                            else
                            {
                                Console.Error.WriteLine("bad guid for instanceReference: instanceId='{0}'", attInstanceId.Value);
                            }
                        }
                    }

                    library.Relationships.Add(rel);
                }
            }

            MarkupTagElement tagTranslations = tag.Elements["translations"] as MarkupTagElement;

            if (tagTranslations != null)
            {
                for (int i = 0; i < tagTranslations.Elements.Count; i++)
                {
                    MarkupTagElement tagTranslation = (tagTranslations.Elements[i] as MarkupTagElement);
                    if (tagTranslation == null)
                    {
                        continue;
                    }
                    if (tagTranslation.FullName != "translation")
                    {
                        continue;
                    }

                    MarkupAttribute attRelationshipId = tagTranslation.Attributes["relationshipInstanceId"];
                    if (attRelationshipId == null)
                    {
                        continue;
                    }

                    MarkupTagElement tagTranslationValues = (tagTranslation.Elements["translationValues"] as MarkupTagElement);
                    if (tagTranslationValues == null)
                    {
                        continue;
                    }

                    MochaInstance instTTC = new MochaInstance();
                    instTTC.ID = Guid.NewGuid();
                    SetParentClass(library, instTTC.ID, global::Mocha.Core.KnownInstanceGuids.Classes.Translation);

                    MochaRelationship relInstance__has__Translatable_Text_Constant = new MochaRelationship();
                    relInstance__has__Translatable_Text_Constant.SourceInstanceID       = inst.ID;
                    relInstance__has__Translatable_Text_Constant.RelationshipInstanceID = new Guid(attRelationshipId.Value);
                    relInstance__has__Translatable_Text_Constant.DestinationInstanceIDs.Add(instTTC.ID);
                    library.Relationships.Add(relInstance__has__Translatable_Text_Constant);

                    MochaRelationship relTranslatable_Text_Constant__has__Translatable_Text_Constant_Value = new MochaRelationship();
                    relTranslatable_Text_Constant__has__Translatable_Text_Constant_Value.SourceInstanceID       = instTTC.ID;
                    relTranslatable_Text_Constant__has__Translatable_Text_Constant_Value.RelationshipInstanceID = global::Mocha.Core.KnownRelationshipGuids.Translatable_Text_Constant__has__Translatable_Text_Constant_Value;

                    for (int j = 0; j < tagTranslationValues.Elements.Count; j++)
                    {
                        MarkupTagElement tagTranslationValue = (tagTranslationValues.Elements[j] as MarkupTagElement);
                        if (tagTranslationValue == null)
                        {
                            continue;
                        }
                        if (tagTranslationValue.FullName != "translationValue")
                        {
                            continue;
                        }

                        MarkupAttribute attLanguageInstanceID = tagTranslationValue.Attributes["languageInstanceId"];
                        MarkupAttribute attValue = tagTranslationValue.Attributes["value"];
                        if (attLanguageInstanceID == null || attValue == null)
                        {
                            continue;
                        }

                        // create a new TTCValue instance
                        MochaInstance instTranslationValue = new MochaInstance();
                        instTranslationValue.ID = Guid.NewGuid();
                        SetParentClass(library, instTranslationValue.ID, global::Mocha.Core.KnownInstanceGuids.Classes.TranslatableTextConstantValue);

                        // associate the TTCValue with the Language
                        MochaRelationship relTranslatable_Text_Constant_Value__has__Language = new MochaRelationship();
                        relTranslatable_Text_Constant_Value__has__Language.SourceInstanceID       = instTranslationValue.ID;
                        relTranslatable_Text_Constant_Value__has__Language.RelationshipInstanceID = global::Mocha.Core.KnownRelationshipGuids.Translatable_Text_Constant_Value__has__Language;
                        relTranslatable_Text_Constant_Value__has__Language.DestinationInstanceIDs.Add(new Guid(attLanguageInstanceID.Value));
                        library.Relationships.Add(relTranslatable_Text_Constant_Value__has__Language);

                        // set the Value attribute of the TTCValue
                        MochaAttributeValue mavValue = new MochaAttributeValue();
                        mavValue.AttributeInstanceID = global::Mocha.Core.KnownAttributeGuids.Text.Value;
                        mavValue.Value = attValue.Value;
                        instTranslationValue.AttributeValues.Add(mavValue);

                        // add the TTCValue to the instance list
                        library.Instances.Add(instTranslationValue);

                        // add the TTCValue to the TTC.has TTC Value relationship
                        relTranslatable_Text_Constant__has__Translatable_Text_Constant_Value.DestinationInstanceIDs.Add(instTranslationValue.ID);
                    }

                    library.Relationships.Add(relTranslatable_Text_Constant__has__Translatable_Text_Constant_Value);

                    library.Instances.Add(instTTC);
                }
            }

            return(inst);
        }