Esempio n. 1
0
        /// <summary>
        /// Creates a class with the given <paramref name="classInstanceId" /> and optional name and title.
        /// </summary>
        /// <remarks>
        /// This method makes several calls to the underlying <see cref="Oms" /> to create the class instance and assign the
        /// Name attribute the value of the <paramref name="name" /> parameter. A Translation with relationship
        /// `Class.has title Translation` is associated with the newly-created Class. By default, the Translation Value is
        /// created with the given <paramref name="title" /> and Language set to `English (United Sstates)`. If
        /// <paramref name="title"/> is null, the <paramref name="name" /> parameter is used instead.
        /// </remarks>
        /// <returns>The <see cref="InstanceKey" /> of the newly-created class.</returns>
        /// <param name="oms">Oms.</param>
        /// <param name="classInstanceId">Class instance identifier.</param>
        /// <param name="name">The language-agnostic name to assign to the newly-created class.</param>
        /// <param name="title">The language-specific title to assign to the newly-created class.</param>
        public static InstanceHandle CreateClass(this Oms oms, Guid classInstanceId, Guid parentClassInstanceId, string name = null, string title = null)
        {
            // FIXME: this should take into account security policy for the currently-logged-in user
            InstanceHandle ih = oms.CreateInstance(classInstanceId, KnownInstanceGuids.Classes.Class);

            if (parentClassInstanceId != Guid.Empty)
            {
                oms.CreateRelationship(ih, oms.GetInstance(KnownRelationshipGuids.Class__has_super__Class), oms.GetInstance(parentClassInstanceId));
                oms.CreateRelationship(oms.GetInstance(parentClassInstanceId), oms.GetInstance(KnownRelationshipGuids.Class__has_sub__Class), ih);
            }
            if (name != null)
            {
                oms.SetAttributeValue(ih, oms.GetInstance(KnownAttributeGuids.Text.Name), name);
                if (title == null)
                {
                    title = name;
                }

                oms.CreateTranslation(ih, oms.GetInstance(KnownRelationshipGuids.Class__has_title__Translatable_Text_Constant), oms.GetInstance(KnownInstanceGuids.Languages.English), title);
            }
            return(ih);
        }