예제 #1
0
        private static Dictionary <string, SettingBase> ReadSettings()
        {
            //XmlSerializer serializer = new XmlSerializer(typeof(KScriptSetting));

            XmlSerializer serializer =
                XmlSerializer.FromTypes(new[] { typeof(KScriptSetting) })[0];

            var path     = GetPath();
            var settings = new Dictionary <string, SettingBase>();
            var files    = Directory.GetFiles(path);

            for (var i = 0; i < files.Length; i++)
            {
                var file   = files[i];
                var reader = new StreamReader(file);
                try
                {
                    KScriptSetting setting = serializer.Deserialize(reader) as KScriptSetting;

                    var fileName = Path.GetFileNameWithoutExtension(file).ToLower();
                    settings.Add(fileName, setting);
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    reader.Close();
                }
            }
            return(settings);
        }
예제 #2
0
        public string RenderSettingHtml(RenderContext context, KScriptSetting setting, string name)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(RenderDetailStart());

            builder.Append(RenderModelBase(setting));

            var baseUrl = GetBaseurl(context);

            if (setting.Props.Count > 0)
            {
                builder.AppendFormat("<p><strong>{0}</strong></p>", "Properties");
                builder.AppendFormat("<table><thead><tr><th>{0}</th><th>{1}</th><th>{2}</th></tr></thead><tbody>", "Name", "Type", "Desc");

                foreach (var prop in setting.Props)
                {
                    var propStr = string.Empty;

                    if (prop.Type != null && ScriptHelperReader.Settings.ContainsKey(prop.Type.ToLower()))
                    {
                        var url = DocumentHelper.GetTypeUrl(prop.Type);

                        var type = string.Format("<a href='{0}'>{1}</a>", url, GetTypeName(prop.Type));
                        propStr = string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>", DocumentHelper.LowerCaseFirstChar(prop.Name), type, prop.Description);
                    }
                    else
                    {
                        propStr = string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>", DocumentHelper.LowerCaseFirstChar(prop.Name), prop.Type, prop.Description);
                    }

                    builder.Append(propStr);
                }
                builder.Append("</tbody></table>");
            }

            if (setting.Methods.Count > 0)
            {
                builder.AppendFormat("<p><strong>{0}</strong></p>", "Methods");
                builder.AppendFormat("<table><thead><tr><th>{0}</th><th>{1}</th><th>{2}</th></tr></thead><tbody>", "Name", "Return", "Desc");

                var methods = setting.Methods.OrderBy(m => m.Name).ToList();
                foreach (var method in methods)
                {
                    var paramBuilder = new StringBuilder();
                    foreach (var param in method.Params)
                    {
                        paramBuilder.Append(param.Name);
                    }
                    //method rul
                    var url             = baseUrl + DocumentHelper.GetMethodUrl(name, method.Name, paramBuilder.ToString());
                    var methodWithParam = string.Format("<a href='{0}'>{1}</a>", url, GetMethodWithParams(method));

                    //return type url
                    var type = method.ReturnType;
                    if (method.ReturnType != null && ScriptHelperReader.Settings.ContainsKey(method.ReturnType.ToLower()))
                    {
                        var returnTypeUrl = baseUrl + DocumentHelper.GetTypeUrl(method.ReturnType);
                        type = string.Format("<a href='{0}'>{1}</a>", returnTypeUrl, GetTypeName(method.ReturnType));
                    }

                    var str = string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td></tr>", methodWithParam, type, method.Description);
                    builder.Append(str);
                }
                builder.Append("</tbody></table>");
            }

            builder.Append(RenderDetailEnd());
            return(builder.ToString());
        }