Exemple #1
0
        /// <summary>
        /// Create a property template, under a property group parent.
        /// prop key is string, prop value is a TextCode.
        /// </summary>
        /// <param name="entityTempl"></param>
        /// <param name="tcKey"></param>
        /// <param name="tcValue"></param>
        /// <returns></returns>
        public PropTempl CreatePropTempl(EntityTempl entityTempl, PropGroupTempl propertyParent, string key, TextCode tcValue)
        {
            // check the entity parent
            if (entityTempl == null)
            {
                return(null);
            }

            PropKeyTemplString propKeyString = new PropKeyTemplString();

            propKeyString.Key = key;

            // transform the value
            ValTextCodeId valTextCodeId = null;

            if (tcValue != null)
            {
                valTextCodeId = new ValTextCodeId();
                // can be null (to set on instantiation)
                valTextCodeId.TextCodeId = tcValue.Id;
            }

            PropValueTempl propValue = PropValueTemplTool.CreatePropValueTemplFromValue(valTextCodeId);

            return(CreatePropTempl(entityTempl, propertyParent, propKeyString, propValue));
        }
        /// <summary>
        /// Set the prop root to an entity, from a template.
        /// the key is a string (like the root key from the template).
        /// </summary>
        /// <param name="entityTempl"></param>
        /// <param name="entity"></param>
        public void SetEntPropertyRootFromTempl(EntityTempl entityTempl, Entity entity)
        {
            // TODO: always a string?
            PropKeyTemplString propKeyTemplString = entityTempl.PropertyRoot.Key as PropKeyTemplString;

            // set a key to the property root
            PropertyKeyString key = new PropertyKeyString();

            key.Key = propKeyTemplString.Key; // CoreDef.DefaultPropertyRootName;
            entity.PropertyRoot.Key = key;
            entity.PropertyRoot.PropGroupTemplId = entityTempl.PropertyRoot.Id;
        }
Exemple #3
0
        /// <summary>
        /// Create a property group template.
        /// Under the prop root of the entity.
        /// </summary>
        /// <param name="entityTempl"></param>
        /// <param name="tcKey"></param>
        /// <param name="tcValue"></param>
        /// <returns></returns>
        public PropGroupTempl CreatePropGroupTempl(EntityTempl entityTempl, string key)
        {
            // check the entity parent
            if (entityTempl == null)
            {
                return(null);
            }

            // get the root group properties of the entity
            PropGroupTempl propertyParent = entityTempl.PropertyRoot;

            PropKeyTemplString propKeyString = new PropKeyTemplString();

            propKeyString.Key = key;
            return(CreatePropGroupTempl(entityTempl, propertyParent, propKeyString));
        }
Exemple #4
0
        /// <summary>
        /// Create a property template, under a property group parent.
        /// prop key is string, prop value is a bool.
        /// </summary>
        /// <param name="entityTempl"></param>
        /// <param name="tcKey"></param>
        /// <param name="tcValue"></param>
        /// <returns></returns>
        public PropTempl CreatePropTempl(EntityTempl entityTempl, PropGroupTempl propertyParent, string key, bool value)
        {
            // check the entity parent
            if (entityTempl == null)
            {
                return(null);
            }

            PropKeyTemplString propKeyString = new PropKeyTemplString();

            propKeyString.Key = key;

            // create the property value template, can be null
            PropValueTempl propValue = PropValueTemplTool.CreatePropValueTemplFromValue(value);

            return(CreatePropTempl(entityTempl, propertyParent, propKeyString, propValue));
        }
Exemple #5
0
        /// <summary>
        /// Create an entity template under the root folder parent.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public EntityTempl CreateEntityTempl(Folder folderParent, string name)
        {
            // parent folder is null? its the root
            if (folderParent == null)
            {
                folderParent = _reposit.Finder.GetRootFolder();
            }

            // TODO:
            if (string.IsNullOrWhiteSpace(name))
            {
                return(null);
            }

            // check the syntax
            // TODO: no special character,...

            // create an entity, attach it the parent
            EntityTempl entityTempl = new EntityTempl();

            entityTempl.ParentFolderId = folderParent.Id;
            entityTempl.Name           = name;

            // set a key to the property root
            PropKeyTemplString key = new PropKeyTemplString();

            key.Key = CoreDef.DefaultPropertyRootName;
            entityTempl.PropertyRoot.Key = key;

            // save it
            if (!_reposit.Builder.SaveEntityTempl(entityTempl))
            {
                return(null);
            }

            folderParent.AddChild(entityTempl);

            // update the parent foder, has a new child
            if (!_reposit.Builder.UpdateFolder(folderParent))
            {
                return(null);
            }

            return(entityTempl);
        }
Exemple #6
0
        // is the property key a textCode?
        private bool IsKeyMatchProperty(PropTemplBase property, string key, TextCode tcKey)
        {
            PropKeyTemplTextCode keyTextCode = property.Key as PropKeyTemplTextCode;

            if (keyTextCode != null)
            {
                if (tcKey != null)
                {
                    // the key to find is a TextCode
                    if (keyTextCode.TextCodeId.Equals(tcKey.Id))
                    {
                        return(true);
                    }
                }
                else
                {
                    // the property key is a textCode, load it to get the code, because the key is a string
                    TextCode tcPropKey = _reposit.Finder.FindTextCodeById(keyTextCode.TextCodeId);
                    if (tcPropKey.Code.Equals(key))
                    {
                        return(true);
                    }
                }
            }

            // is the property key a string?
            PropKeyTemplString keyString = property.Key as PropKeyTemplString;

            if (keyString != null)
            {
                // compare strings
                if (keyString.Key.Equals(key))
                {
                    return(true);
                }
            }

            // the property doesn't match the key (string or TextCode)
            return(false);
        }
        public void EntOneProp_KString_VString()
        {
            EtagairCore core = Common.CreateCore(RepositConfig);

            // create an entity template to instantiate
            EntityTempl templComputer = core.EditorTempl.CreateEntityTempl("TemplComputer");

            // add property
            PropTempl propTempl = core.EditorTempl.CreatePropTempl(templComputer, "Type", "Computer");

            // check the property key (type and value)
            PropKeyTemplString propKeyString = propTempl.Key as PropKeyTemplString;

            Assert.IsNotNull(propKeyString, "the key should be a string");
            Assert.AreEqual("Type", propKeyString.Key, "the key should be 'Type'");

            // check the property value (type and value)
            ValString propValueString = propTempl.PropValueTempl.Value as ValString;

            Assert.IsNotNull(propValueString, "the value should be a string");
            Assert.AreEqual("Computer", propValueString.Value, "the key should be 'Computer'");
        }
Exemple #8
0
        public string GetPropKeyTemplString(PropKeyTemplBase propKey)
        {
            string keyString = "";

            PropKeyTemplString propKeyTemplString = propKey as PropKeyTemplString;

            if (propKeyTemplString != null)
            {
                keyString = propKeyTemplString.Key;
                return(keyString);
            }

            PropKeyTemplTextCode propKeyTemplTextCode = propKey as PropKeyTemplTextCode;

            if (propKeyTemplTextCode != null)
            {
                // load the textCode
                keyString = _reposit.Finder.FindTextCodeById(propKeyTemplTextCode.TextCodeId).Code;
                return(keyString);
            }

            return(null);
        }
        /// <summary>
        /// Create a property key, based on the template.
        /// </summary>
        /// <param name="propTempl"></param>
        /// <returns></returns>
        public PropertyKeyBase CreatePropKeyFromTempl(PropTemplBase propTempl)
        {
            // create the key of the property, from the template
            PropKeyTemplTextCode templKeyTextCode = propTempl.Key as PropKeyTemplTextCode;

            if (templKeyTextCode != null)
            {
                PropertyKeyTextCode propKey = new PropertyKeyTextCode();
                propKey.TextCodeId = templKeyTextCode.TextCodeId;
                return(propKey);
            }

            PropKeyTemplString templKeyString = propTempl.Key as PropKeyTemplString;

            if (templKeyString != null)
            {
                PropertyKeyString propKey = new PropertyKeyString();
                propKey.Key = templKeyString.Key;
                return(propKey);
            }

            throw new Exception("Property Key templ not yet implemented!");
        }