private (Lazy <ConfigSectionNode> request, Lazy <ConfigSectionNode> response) writeCommon(
            string defTitle,
            string defDescription,
            MemberInfo info,
            ApiDocGenerator gen,
            ApiDocAttribute attr,
            ConfigSectionNode data)
        {
            MetadataUtils.AddMetadataTokenIdAttribute(data, info);

            var title = attr.Title.Default(defTitle);

            if (title.IsNotNullOrWhiteSpace())
            {
                data.AddAttributeNode("title", title);
            }

            var descr = attr.Description.Default(defDescription);

            if (descr.IsNotNullOrWhiteSpace())
            {
                data.AddAttributeNode("description", descr);
            }

            var drequest  = new Lazy <ConfigSectionNode>(() => data.AddChildNode("request"));
            var dresponse = new Lazy <ConfigSectionNode>(() => data.AddChildNode("response"));

            writeCollection(attr.RequestHeaders, "header", drequest, ':');
            writeCollection(attr.RequestQueryParameters, "param", drequest, '=');
            writeCollection(attr.ResponseHeaders, "header", dresponse, ':');

            if (attr.Connection.IsNotNullOrWhiteSpace())
            {
                data.AddAttributeNode("connection", attr.Connection);
            }

            if (attr.RequestBody.IsNotNullOrWhiteSpace())
            {
                drequest.Value.AddAttributeNode("body", attr.RequestBody);
            }

            if (attr.ResponseContent.IsNotNullOrWhiteSpace())
            {
                dresponse.Value.AddAttributeNode("content", attr.ResponseContent);
            }

            writeTypeCollection(attr.TypeSchemas, TYPE_REF, data, gen);

            return(drequest, dresponse);
        }
Example #2
0
        /// <summary>
        /// Describes type including generic arguments
        /// </summary>
        public static void WriteType(Type t, ConfigSectionNode node)
        {
            node.AddAttributeNode("name-in-code", tname(t));
            node.AddAttributeNode("name", t.Name);
            if (t == typeof(void))
            {
                node.AddAttributeNode("void", true);
                return;
            }
            node.AddAttributeNode("ns", t.Namespace);
            node.AddAttributeNode("asm-q-name", t.AssemblyQualifiedName);
            node.AddAttributeNode("asm-name", t.Assembly.FullName);
            node.AddAttributeNode("intf", t.IsInterface);
            node.AddAttributeNode("valuetype", t.IsValueType);

            if (t.IsEnum)
            {
                var enode = node.AddChildNode("enum");
                foreach (var name in Enum.GetNames(t))
                {
                    var inode = enode.AddChildNode("item");
                    inode.AddAttributeNode("key", name);
                    inode.AddAttributeNode("value", (int)Enum.Parse(t, name));
                }
            }

            if (t.IsGenericType)
            {
                var ganode = node.AddChildNode("generic-type-args");
                foreach (var garg in t.GetGenericArguments())
                {
                    WriteType(garg, ganode.AddChildNode("type-arg"));
                }
            }
        }
Example #3
0
        // IConfigurationPersistent Members
        /// <summary>
        /// Persists column configuration to config node. [grid] subnode will be created under specified node pr reused if one already exists
        /// </summary>
        public void PersistConfiguration(ConfigSectionNode node)
        {
            if (node == null)
            {
                return;
            }

            ConfigSectionNode gnode = findSubNodeForThisGrid(node) as ConfigSectionNode; //see if node for this grid already exists

            if (gnode != null)                                                           //delete with all column defs that are different now
            {
                gnode.Delete();
            }


            gnode = node.AddChildNode(CONFIG_GRID_SECTION);

            if (!string.IsNullOrEmpty(m_ID))
            {
                gnode.AddAttributeNode(CONFIG_ID_ATTR, ID);
            }

            foreach (var col in m_Columns)
            {
                col.PersistConfiguration(gnode);
            }
        }
Example #4
0
        private static void redactAclLevel(ConfigSectionNode level, bool cascadePub)
        {
            //1 Check visibility
            var visibility = level.Of(ACL_LEVEL_VISIBILITY_ATTRIBUTE).ValueAsEnum(cascadePub ? AclLevelVisibility.PubCascade : AclLevelVisibility.None);

            if (visibility == AclLevelVisibility.None)
            {
                level.Delete();
                return;
            }

            //2 Process this level
            var effectiveAccessLevel = level.Of(ACL_LEVEL_OVERRIDE_ATTRIBUTE, AccessLevel.CONFIG_LEVEL_ATTR).ValueAsInt(0);

            level.DeleteAllAttributes();
            if (effectiveAccessLevel > 0)
            {
                level.AddAttributeNode(AccessLevel.CONFIG_LEVEL_ATTR, effectiveAccessLevel);
            }

            //3 Loop through all child nodes
            foreach (var child in level.Children)
            {
                redactAclLevel(child, visibility == AclLevelVisibility.PubCascade);
            }
        }
Example #5
0
        private void outError(ConfigSectionNode node, Exception error)
        {
            var nesting = 0;

            while (error != null)
            {
                node = node.AddChildNode("error", error.GetType().Name);
                node.AddAttributeNode("type", error.GetType().AssemblyQualifiedName);
                node.AddAttributeNode("nesting", nesting);
                node.AddAttributeNode("msg", error.Message);
                node.AddAttributeNode("stack", error.StackTrace);

                error = error.InnerException;
                nesting++;
            }
        }
Example #6
0
        private void populateSection(ConfigSectionNode section)
        {
            if (token.Type != LaconfigTokenType.tBraceOpen)
            {
                errorAndAbort(LaconfigMsgCode.eSectionOpenBraceExpected);
            }

            fetchPrimary();    //skip {  section started

            while (true)
            {
                if (token.Type == LaconfigTokenType.tBraceClose)
                {
                    fetchPrimaryOrEOF();  //skip }  section ended
                    return;
                }

                if (token.Type != LaconfigTokenType.tIdentifier && token.Type != LaconfigTokenType.tStringLiteral)
                {
                    errorAndAbort(LaconfigMsgCode.eSectionOrAttributeNameExpected);
                }

                var name = token.Text;
                fetchPrimary();

                if (token.Type == LaconfigTokenType.tBraceOpen)  //section w/o value
                {
                    var subsection = section.AddChildNode(name, null);
                    populateSection(subsection);
                }
                else if (token.Type == LaconfigTokenType.tEQ) //section with value or attribute
                {
                    fetchPrimary();                           //skip =

                    if (token.Type != LaconfigTokenType.tIdentifier &&
                        token.Type != LaconfigTokenType.tStringLiteral &&
                        token.Type != LaconfigTokenType.tNull)
                    {
                        errorAndAbort(LaconfigMsgCode.eSectionOrAttributeValueExpected);
                    }

                    var value = token.Type == LaconfigTokenType.tNull ? null : token.Text;
                    fetchPrimary();                                 //skip value

                    if (token.Type == LaconfigTokenType.tBraceOpen) //section with value
                    {
                        var subsection = section.AddChildNode(name, value);
                        populateSection(subsection);
                    }
                    else
                    {
                        section.AddAttributeNode(name, value);
                    }
                }
                else
                {
                    errorAndAbort(LaconfigMsgCode.eSyntaxError);
                }
            }
        }
Example #7
0
        private ConfigSectionNode buildSection(string name, JSONDataMap sectData, ConfigSectionNode parent)
        {
            var value = sectData[SECTION_VALUE_ATTR].AsString();
            ConfigSectionNode result = parent == null ? new ConfigSectionNode(this, null, name, value)
                                                  : parent.AddChildNode(name, value);

            foreach (var kvp in sectData)
            {
                if (kvp.Value is JSONDataMap)
                {
                    buildSection(kvp.Key, (JSONDataMap)kvp.Value, result);
                }
                else if (kvp.Value is JSONDataArray)
                {
                    var lst = (JSONDataArray)kvp.Value;
                    foreach (var lnode in lst)
                    {
                        var lmap = lnode as JSONDataMap;
                        if (lmap == null)
                        {
                            throw new ConfigException(StringConsts.CONFIG_JSON_STRUCTURE_ERROR, new ConfigException("Bad structure: " + sectData.ToJSON()));
                        }
                        buildSection(kvp.Key, lmap, result);
                    }
                }
                else
                {
                    result.AddAttributeNode(kvp.Key, kvp.Value);
                }
            }

            return(result);
        }
Example #8
0
 /// <summary>
 /// Virtual method using in DO configuration script processing.
 /// If evaluate is "false" then each attribute is cloned by the Value
 /// else if "true" then each attribute is cloned by the VerbatimValue
 /// </summary>
 protected virtual void CloneAttributes(ConfigSectionNode from, ConfigSectionNode to, bool evaluate = false)
 {
     if (evaluate)
     {
         foreach (var atr in from.Attributes)
         {
             to.AddAttributeNode(atr.Name, atr.Value);
         }
     }
     else
     {
         foreach (var atr in from.Attributes)
         {
             to.AddAttributeNode(atr.Name, atr.VerbatimValue);
         }
     }
 }
        // -arg1 -arg2 -arg3 opt1 opt2 -arg4 optA=v1 optB=v2
        private void parseArgs()
        {
            m_Root = new ConfigSectionNode(this, null, ROOT_NODE_NAME, string.Empty);

            var uargcnt = 1; //unknown arg length

            for (int i = 0; i < m_Args.Length;)
            {
                var argument = m_Args[i];

                if (argument.Length > 1 && ((!m_InhibitSlashArg && argument.StartsWith(ARG_PREFIX_SLASH)) || argument.StartsWith(ARG_PREFIX_DASH)))
                {
                    argument = argument.Remove(0, 1);//get rid of prefix
                    var argNode = m_Root.AddChildNode(argument, null);

                    var uopcnt = 1;               //unknown option length
                    for (i++; i < m_Args.Length;) //read args's options
                    {
                        var option = m_Args[i];
                        if ((!m_InhibitSlashArg && option.StartsWith(ARG_PREFIX_SLASH)) || option.StartsWith(ARG_PREFIX_DASH))
                        {
                            break;
                        }
                        i++;

                        var j = option.IndexOf(OPTION_EQ);

                        if (j < 0)
                        {
                            argNode.AddAttributeNode(string.Format("?{0}", uopcnt), option);
                            uopcnt++;
                        }
                        else
                        {
                            var name = option.Substring(0, j);
                            var val  = (j < option.Length - 1) ? option.Substring(j + 1) : string.Empty;

                            if (string.IsNullOrEmpty(name))
                            {
                                name = string.Format("?{0}", uopcnt);
                                uopcnt++;
                            }
                            argNode.AddAttributeNode(name, val);
                        }
                    }
                }
                else
                {
                    m_Root.AddAttributeNode(string.Format("?{0}", uargcnt), argument);
                    uargcnt++;
                    i++;
                }
            }

            m_Root.ResetModified();
        }
Example #10
0
        public void BeginRunnable(Runner runner, FID id, object runnable)
        {
            m_TotalRunnables++;
            var t = runnable.GetType();

            m_RunnableHeader     = "Starting {0}::{1}.{2} ...".Args(t.Assembly.GetName().Name, t.Namespace, t.DisplayNameWithExpandedGenericArgs());
            m_HadRunnableMethods = false;
            m_PriorMethodName    = null;
            m_PriorMethodCount   = 0;

            var o = m_Out?.Root;

            if (o != null)
            {
                m_RunnableNode = o.AddChildNode("runnable", runnable.GetType().Name);
                m_RunnableNode.AddAttributeNode("id", id);
                m_RunnableNode.AddAttributeNode("type", runnable.GetType().AssemblyQualifiedName);
                m_RunnableNode.AddAttributeNode("now-loc", App.LocalizedTime);
                m_RunnableNode.AddAttributeNode("now-utc", App.TimeSource.UTCNow);
            }
        }
Example #11
0
 private void buildNode(ConfigSectionNode node, JsonDataMap map)
 {
     foreach (var kvp in map)
     {
         var cmap = kvp.Value as JsonDataMap;
         if (cmap != null)
         {
             buildNode(node.AddChildNode(kvp.Key), cmap);
         }
         else
         {
             node.AddAttributeNode(kvp.Key, kvp.Value);
         }
     }
 }
 private void writeTypeCollection(Type[] items, string iname, ConfigSectionNode data, ApiDocGenerator gen)
 {
     if (items != null && items.Length > 0)
     {
         foreach (var type in items.Where(t => t != null))
         {
             var id   = gen.AddTypeToDescribe(type);
             var node = data.Children.FirstOrDefault(c => c.IsSameName(iname) && c.AttrByName("id").Value.EqualsIgnoreCase(id));
             if (node != null)
             {
                 continue;  //already exists
             }
             data.AddAttributeNode(iname, id);
         }
     }
 }
Example #13
0
        private void field(Schema.FieldDef def, IMetadataGenerator context, ConfigSectionNode data, TypedDoc doc)
        {
            var fname = def.GetBackendNameForTarget(context.DataTargetName, out var fatr);

            if (fatr == null)
            {
                return;
            }

            if (context.DetailLevel > MetadataDetailLevel.Public)
            {
                data.AddAttributeNode("prop-name", def.Name);
                data.AddAttributeNode("prop-type", def.Type.AssemblyQualifiedName);
                data.AddAttributeNode("non-ui", fatr.NonUI);
                data.AddAttributeNode("is-arow", fatr.IsArow);
                data.AddAttributeNode("store-flag", fatr.StoreFlag);
                data.AddAttributeNode("backend-type", fatr.BackendType);
                if (fatr.Metadata != null)
                {
                    data.AddChildNode(fatr.Metadata);
                }
            }

            data.AddAttributeNode("name", fname);
            data.AddAttributeNode("type", context.AddTypeToDescribe(def.Type));
            data.AddAttributeNode("order", def.Order);

            if (fatr.Description.IsNotNullOrWhiteSpace())
            {
                data.AddAttributeNode("description", fatr.Description);
            }
            data.AddAttributeNode("key", fatr.Key);

            if (def.Type == typeof(string))
            {
                data.AddAttributeNode("kind", fatr.Kind);
            }

            data.AddAttributeNode("required", fatr.Required);
            data.AddAttributeNode("visible", fatr.Required);
            data.AddAttributeNode("case", fatr.CharCase);
            if (fatr.Default != null)
            {
                data.AddAttributeNode("default", fatr.Default);
            }
            if (fatr.DisplayFormat.IsNotNullOrWhiteSpace())
            {
                data.AddAttributeNode("display-format", fatr.DisplayFormat);
            }
            if (fatr.FormatRegExp.IsNotNullOrWhiteSpace())
            {
                data.AddAttributeNode("format-reg-exp", fatr.FormatRegExp);
            }
            if (fatr.FormatDescription.IsNotNullOrWhiteSpace())
            {
                data.AddAttributeNode("format-description", fatr.FormatDescription);
            }
            if (fatr.Max != null)
            {
                data.AddAttributeNode("max", fatr.Max);
            }
            if (fatr.Min != null)
            {
                data.AddAttributeNode("min", fatr.Min);
            }
            if (fatr.MinLength > 0 || fatr.MaxLength > 0)
            {
                data.AddAttributeNode("min-len", fatr.MinLength);
            }
            if (fatr.MinLength > 0 || fatr.MaxLength > 0)
            {
                data.AddAttributeNode("max-len", fatr.MaxLength);
            }

            //add values from field attribute .ValueList property
            var nvlist = new Lazy <ConfigSectionNode>(() => data.AddChildNode("value-list"));

            if (fatr.HasValueList)
            {
                fatr.ParseValueList().ForEach(item => nvlist.Value.AddAttributeNode(item.Key, item.Value));
            }

            //if doc!=null call doc.GetClientFieldValueList on the instance to get values from Database lookups etc...
            if (doc != null)
            {
                var lookup = doc.GetClientFieldValueList(def, context.DataTargetName, null);
                if (lookup != null)
                {
                    lookup.ForEach(item => nvlist.Value.AddAttributeNode(item.Key, item.Value));
                }
            }
        }
Example #14
0
        public void Inventorize(Type t, ConfigSectionNode root)
        {
            InventorizationManager.WriteInventoryAttributes(
                 t.GetCustomAttributes(typeof(InventoryAttribute), false).Cast<InventoryAttribute>(),
                 root.AddChildNode(InventorizationManager.ATTRIBUTES_NODE));

               if (t.BaseType!=null)
            root.AddAttributeNode("base", t.BaseType.FullName);

               root.AddAttributeNode("abstract",  t.IsAbstract);
               root.AddAttributeNode("class",  t.IsClass);
               root.AddAttributeNode("enum",  t.IsEnum);
               root.AddAttributeNode("intf",  t.IsInterface);
               root.AddAttributeNode("nested",  t.IsNested);
               root.AddAttributeNode("public",  t.IsPublic);
               root.AddAttributeNode("sealed",  t.IsSealed);
               root.AddAttributeNode("serializable",  t.IsSerializable);
               root.AddAttributeNode("valuetype",  t.IsValueType);
               root.AddAttributeNode("visible",  t.IsVisible);

               var members = t.GetMembers().Where(m=>m.GetCustomAttributes(typeof(InventoryAttribute), false).Count()>0);
               foreach(var mem in members)
               {
             var mnode = root.AddChildNode("member");
             mnode.AddAttributeNode("name", mem.Name);
             mnode.AddAttributeNode("kind", mem.MemberType.ToString());

             InventorizationManager.WriteInventoryAttributes(
                 mem.GetCustomAttributes(typeof(InventoryAttribute), false).Cast<InventoryAttribute>(),
                 mnode.AddChildNode(InventorizationManager.ATTRIBUTES_NODE));

             if (mem is PropertyInfo)
             {
               var pinf = (PropertyInfo)mem;
               mnode.AddAttributeNode("can-get", pinf.CanRead);
               mnode.AddAttributeNode("can-set", pinf.CanWrite);
               mnode.AddAttributeNode("type", pinf.PropertyType.FullName);
             }
             else
             if (mem is FieldInfo)
             {
               var finf = (FieldInfo)mem;
               mnode.AddAttributeNode("not-serialized", finf.IsNotSerialized);
               mnode.AddAttributeNode("public", finf.IsPublic);
               mnode.AddAttributeNode("private", finf.IsPrivate);
               mnode.AddAttributeNode("static", finf.IsStatic);
               mnode.AddAttributeNode("type", finf.FieldType.FullName);
             }
             else
             if (mem is MethodInfo)
             {
               var minf = (MethodInfo)mem;
               mnode.AddAttributeNode("virtual", minf.IsVirtual);
               mnode.AddAttributeNode("public", minf.IsPublic);
               mnode.AddAttributeNode("private", minf.IsPrivate);
               mnode.AddAttributeNode("static", minf.IsStatic);
               if (minf.ReturnType!=null)
                mnode.AddAttributeNode("return-type", minf.ReturnType.FullName);
             }
               }
        }
Example #15
0
        public void Inventorize(Type t, ConfigSectionNode root)
        {
            InventorizationManager.WriteInventoryAttributes(
                t.GetCustomAttributes(typeof(InventoryAttribute), false).Cast <InventoryAttribute>(),
                root.AddChildNode(InventorizationManager.ATTRIBUTES_NODE));

            if (t.BaseType != null)
            {
                root.AddAttributeNode("base", t.BaseType.FullName);
            }

            root.AddAttributeNode("abstract", t.IsAbstract);
            root.AddAttributeNode("class", t.IsClass);
            root.AddAttributeNode("enum", t.IsEnum);
            root.AddAttributeNode("intf", t.IsInterface);
            root.AddAttributeNode("nested", t.IsNested);
            root.AddAttributeNode("public", t.IsPublic);
            root.AddAttributeNode("sealed", t.IsSealed);
            root.AddAttributeNode("serializable", t.IsSerializable);
            root.AddAttributeNode("valuetype", t.IsValueType);
            root.AddAttributeNode("visible", t.IsVisible);

            var members = t.GetMembers().Where(m => m.GetCustomAttributes(typeof(InventoryAttribute), false).Count() > 0);

            foreach (var mem in members)
            {
                var mnode = root.AddChildNode("member");
                mnode.AddAttributeNode("name", mem.Name);
                mnode.AddAttributeNode("kind", mem.MemberType.ToString());

                InventorizationManager.WriteInventoryAttributes(
                    mem.GetCustomAttributes(typeof(InventoryAttribute), false).Cast <InventoryAttribute>(),
                    mnode.AddChildNode(InventorizationManager.ATTRIBUTES_NODE));

                if (mem is PropertyInfo)
                {
                    var pinf = (PropertyInfo)mem;
                    mnode.AddAttributeNode("can-get", pinf.CanRead);
                    mnode.AddAttributeNode("can-set", pinf.CanWrite);
                    mnode.AddAttributeNode("type", pinf.PropertyType.FullName);
                }
                else
                if (mem is FieldInfo)
                {
                    var finf = (FieldInfo)mem;
                    mnode.AddAttributeNode("not-serialized", finf.IsNotSerialized);
                    mnode.AddAttributeNode("public", finf.IsPublic);
                    mnode.AddAttributeNode("private", finf.IsPrivate);
                    mnode.AddAttributeNode("static", finf.IsStatic);
                    mnode.AddAttributeNode("type", finf.FieldType.FullName);
                }
                else
                if (mem is MethodInfo)
                {
                    var minf = (MethodInfo)mem;
                    mnode.AddAttributeNode("virtual", minf.IsVirtual);
                    mnode.AddAttributeNode("public", minf.IsPublic);
                    mnode.AddAttributeNode("private", minf.IsPrivate);
                    mnode.AddAttributeNode("static", minf.IsStatic);
                    if (minf.ReturnType != null)
                    {
                        mnode.AddAttributeNode("return-type", minf.ReturnType.FullName);
                    }
                }
            }
        }
Example #16
0
 private void cloneAttributes(ConfigSectionNode from, ConfigSectionNode to, bool evaluate = false)
 {
     if (evaluate)
                            foreach(var atr in from.Attributes) to.AddAttributeNode(atr.Name, atr.Value);
                         else
                            foreach(var atr in from.Attributes) to.AddAttributeNode(atr.Name, atr.VerbatimValue);
 }
Example #17
0
        // -arg1 -arg2 -arg3 opt1 opt2 -arg4 optA=v1 optB=v2
        private void parseArgs()
        {
            m_Root = new ConfigSectionNode(this, null, ROOT_NODE_NAME, string.Empty);

              var uargcnt = 1; //unknown arg length
              for (int i = 0; i < m_Args.Length; )
              {
            var argument = m_Args[i];

            if (argument.Length > 1 && (argument.StartsWith(ARG_PREFIX1) || argument.StartsWith(ARG_PREFIX2)))
            {
              argument = argument.Remove(0, 1);//get rid of prefix
              var argNode = m_Root.AddChildNode(argument, null);

              var uopcnt = 1;//unknown option length
              for (i++; i < m_Args.Length; )//read args's options
              {
            var option = m_Args[i];
            if (option.StartsWith(ARG_PREFIX1) || option.StartsWith(ARG_PREFIX2)) break;
            i++;

            var j = option.IndexOf(OPTION_EQ);

            if (j < 0)
            {
              argNode.AddAttributeNode(string.Format("?{0}", uopcnt), option);
              uopcnt++;
            }
            else
            {
              var name = option.Substring(0, j);
              var val = (j < option.Length - 1) ? option.Substring(j + 1) : string.Empty;

              if (string.IsNullOrEmpty(name))
              {
                name = string.Format("?{0}", uopcnt);
                uopcnt++;
              }
              argNode.AddAttributeNode(name, val);
            }
              }
            }
            else
            {
              m_Root.AddAttributeNode(string.Format("?{0}", uargcnt), argument);
              uargcnt++;
              i++;
            }
              }

              m_Root.ResetModified();
        }
Example #18
0
        private void field(string targetName, Schema.FieldDef def, IMetadataGenerator context, ConfigSectionNode data, TypedDoc doc)
        {
            var fname = def.GetBackendNameForTarget(targetName, out var fatr);

            if (fatr == null)
            {
                return;
            }

            if (context.DetailLevel > MetadataDetailLevel.Public)
            {
                data.AddAttributeNode("prop-name", def.Name);
                data.AddAttributeNode("prop-type", def.Type.AssemblyQualifiedName);
                data.AddAttributeNode("non-ui", fatr.NonUI);
                data.AddAttributeNode("is-arow", fatr.IsArow);
                data.AddAttributeNode("store-flag", fatr.StoreFlag);
                data.AddAttributeNode("backend-type", fatr.BackendType);

                //try to disclose ALL metadata (as we are above PUBLIC)
                if (fatr.Metadata != null && fatr.Metadata.Exists)
                {
                    var metad = data.AddChildNode("meta");
                    metad.MergeSections(fatr.Metadata);
                    metad.MergeAttributes(fatr.Metadata);
                }
            }
            else //try to disclose pub-only metadata
            {
                var pubSection = context.PublicMetadataSection;
                if (fatr.Metadata != null && pubSection.IsNotNullOrWhiteSpace())
                {
                    var metasrc = fatr.Metadata[pubSection];//<-- pub metadata only
                    if (metasrc.Exists)
                    {
                        var metad = data.AddChildNode("meta");
                        metad.MergeSections(metasrc);
                        metad.MergeAttributes(metasrc);
                    }
                }
            }

            data.AddAttributeNode("name", fname);
            data.AddAttributeNode("type", context.AddTypeToDescribe(def.Type));
            data.AddAttributeNode("order", def.Order);

            if (fatr.Description.IsNotNullOrWhiteSpace())
            {
                data.AddAttributeNode("description", fatr.Description);
            }
            data.AddAttributeNode("key", fatr.Key);

            data.AddAttributeNode("kind", fatr.Kind);

            data.AddAttributeNode("required", fatr.Required);
            data.AddAttributeNode("visible", fatr.Required);
            data.AddAttributeNode("case", fatr.CharCase);
            if (fatr.Default != null)
            {
                data.AddAttributeNode("default", fatr.Default);
            }
            if (fatr.DisplayFormat.IsNotNullOrWhiteSpace())
            {
                data.AddAttributeNode("display-format", fatr.DisplayFormat);
            }
            if (fatr.FormatRegExp.IsNotNullOrWhiteSpace())
            {
                data.AddAttributeNode("format-reg-exp", fatr.FormatRegExp);
            }
            if (fatr.FormatDescription.IsNotNullOrWhiteSpace())
            {
                data.AddAttributeNode("format-description", fatr.FormatDescription);
            }
            if (fatr.Max != null)
            {
                data.AddAttributeNode("max", fatr.Max);
            }
            if (fatr.Min != null)
            {
                data.AddAttributeNode("min", fatr.Min);
            }
            if (fatr.MinLength > 0 || fatr.MaxLength > 0)
            {
                data.AddAttributeNode("min-len", fatr.MinLength);
            }
            if (fatr.MinLength > 0 || fatr.MaxLength > 0)
            {
                data.AddAttributeNode("max-len", fatr.MaxLength);
            }

            //add values from field attribute .ValueList property
            var nvlist = new Lazy <ConfigSectionNode>(() => data.AddChildNode("value-list"));

            if (fatr.HasValueList)
            {
                fatr.ParseValueList().ForEach(item => nvlist.Value.AddAttributeNode(item.Key, item.Value));
            }

            //if doc!=null call doc.GetClientFieldValueList on the instance to get values from Database lookups etc...
            if (doc != null)
            {
                var lookup = doc.GetDynamicFieldValueList(def, targetName, null);
                if (lookup != null)//non-null blank lookup is treated as blank lookup overshadowing the hard-coded choices from .ValueList
                {
                    if (nvlist.IsValueCreated)
                    {
                        nvlist.Value.DeleteAllAttributes();
                    }

                    lookup.ForEach(item => nvlist.Value.AddAttributeNode(item.Key, item.Value));
                }
            }
        }
Example #19
0
 public override ConfigSectionNode ProvideInstanceMetadata(IMetadataGenerator context, ConfigSectionNode dataRoot, NodeOverrideRules overrideRules = null)
 {
     dataRoot.AddAttributeNode("max-content-length", MaxContentLength);
     return(dataRoot);
 }