Ejemplo n.º 1
0
        /// <summary>
        /// Add new object into collections
        /// </summary>
        /// <param name="obj">Added object</param>
        /// <returns>Return value 0 - OK, -1 - duplicit Id, -10 - the type of object there is not in the data colections</returns>
        /// <remarks>
        /// If the obj.Id is set to zero or lesser, this method finds the first available free Id and sets it into the obj.Id.
        /// </remarks>
        public int AddObject(OpenElementId obj)
        {
            var   typeName = GetObjectListName(obj);
            IList lst1;

            if (!GetData().TryGetValue(typeName, out lst1))
            {
                return(-10);
            }

            //var lst = lst1 as List<OpenElementId>;
            var lst = ((IEnumerable)lst1).Cast <OpenElementId>();
            var id  = obj.Id;

            if (id < 1)
            {
                id = obj.Id = GetMaxId(typeName) + 1;
            }

            if (lst.Any(o => (o as OpenElementId).Id == id))
            {
                System.Diagnostics.Debug.Assert(false, "Snažíš se přidat do IOM objekt se stejným ID");
                return(-1);
            }

            lst1.Add(obj);
            return(0);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="element">Referenced element</param>
 public ReferenceElement(OpenElementId element)
 {
     this.element = element;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructor
 /// </summary>
 public ReferenceElement()
 {
     element  = null;
     id       = 0;
     typeName = string.Empty;
 }
Ejemplo n.º 4
0
        private string GetObjectListName(OpenElementId obj)
        {
            var t = obj.GetType();

            return(GetObjectListName(t));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get max Id value for specified type
        /// </summary>
        /// <param name="obj">Object</param>
        /// <returns>Max Id value or zero if don't any exists</returns>
        public int GetMaxId(OpenElementId obj)
        {
            var typeName = GetObjectListName(obj);

            return(GetMaxId(typeName));
        }