예제 #1
0
        /// <summary>
        /// Add or update a metatable in the local table map
        /// </summary>
        /// <param name="mt"></param>

        public static bool Add(
            MetaTable mt)
        {
            mt.Name = mt.Name.Trim().ToUpper();                      // normalize name

            if (RestrictedMetaTables.MetatableIsRestricted(mt.Name)) // if restricted then don't add to map
            {
                return(false);
            }

            if (RestrictedMetaTables.MetatableIsGenerallyRestricted(mt.Name))
            {
                return(false);      //if metatable is generally restricted to the user don't add to map
            }
            TableMap[mt.Name] = mt; // store/update in map
            return(true);
        }
예제 #2
0
        /// <summary>
        /// Lookup a MetaTable by name throwing any exceptions from underlying factories
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        ///

        public static MetaTable GetWithException(
            String name)
        {
            MetaTable mt = null;

            // See if in map

            if (name == null || name.Trim() == "")
            {
                throw new Exception("Undefined metatable name");
            }
            name = name.Trim().ToUpper();             // normalize name

            if (TableMap.ContainsKey(name))
            {
                mt = TableMap[name];
                return(mt);
            }

            if (RestrictedMetaTables.MetatableIsRestricted(name))
            {
                mt = null;
            }

            if (RestrictedMetaTables.MetatableIsGenerallyRestricted(name))
            {
                mt = null;
            }

            else
            {
                if (MetaTableFactory == null)
                {
                    throw new Exception("MetaTableFactory instance is not defined");
                }
                mt = MetaTableFactory.GetMetaTable(name);
            }

            if (mt == null)             // table not available
            {
                if (Lex.Contains(name, "calcfield"))
                {
                    name = name;                                                  // debug
                }
                string msg = "Unable to find data table: " + name + "\r\n\r\n" +
                             "The table may not exist or you may not be authorized for access.";

                //DebugLog.Message(msg); // log for debugging
                throw new Exception(msg);                 // no luck
            }

            mt.Name = mt.Name.Trim().ToUpper(); // normalize name

            TableMap[mt.Name] = mt;             // store in map
            if (Lex.Ne(mt.Name, name))          // if original name was an alias then store under that alias also
            {
                TableMap[name] = mt;
            }

            return(mt);
        }