예제 #1
0
파일: Program.cs 프로젝트: Eragra3/Dogu
        public static void Main(string[] args)
        {
#if DEBUG
            if (args.Length == 0)
            {
                args = new[] { @"Dogu.dll", "dogu.md" };
            }
#endif
            if (args.Length < 1)
            {
                throw new Exception("You have to provide assembly path");
            }

            if (args.Length < 2)
            {
                throw new Exception("You have to provide output path");
            }

            string assemblyPath = args[0];
            string outputPath   = args[1];

            var parser = new TypeParser(new AssemblyReader(assemblyPath));

            foreach (TopLevelType type in parser.Parse())
            {
                Colorful.Console.WriteLine(type, Color.Gray);
            }

            var frontend = new MarkdownFrontend(parser.Parse());

            frontend.WriteToFile(outputPath);

            Colorful.Console.WriteLine("Finishing Dogu", Color.Green);
        }
예제 #2
0
파일: Tuple.cs 프로젝트: git4paulqu/PB2CS
        public bool Parse(bool isClass)
        {
            if (string.IsNullOrEmpty(content))
            {
                return(false);
            }

            content  = content.Trim();
            repeated = content.StartsWith(Matcher.REPEATED);

            string dv = null;

            content      = Matcher.MatchDefaultValue(content, out dv);
            defaultValue = dv;

            string[] name2id = content.Split('=');
            if (name2id.Length != 2)
            {
                throw new Exception(string.Format("tuple content:{0} is error.", content));
            }

            name = name2id[0].Trim();
            string[] type2name = Matcher.SplitBlank(name);

            if (isClass)
            {
                name       = type2name[2].Trim();
                typeString = TypeParser.Parse(type2name[1].Trim(), repeated);
            }

            index = name2id[1].Trim();
            return(true);
        }
예제 #3
0
        /// <summary>
        /// Splits full name into subnamespaces and adds corresponding nodes to the tree.
        /// </summary>
        /// <param name="fullName">Can be empty, but not null.</param>
        /// <param name="parseNames">if names should be parsed by mono parser</param>
        private void Add(string fullName, bool parseNames)
        {
            if (fullName == null)
            {
                throw new ArgumentNullException(nameof(fullName));
            }

            var deepestNode = _root;

            foreach (var token in TypeParser.Parse(fullName, parseNames))
            {
                int subnameEndIndex = -1;
                while (subnameEndIndex != token.Length)
                {
                    int subnameStartIndex = subnameEndIndex + 1;
                    subnameEndIndex = GetSubnameEndIndex(token, subnameStartIndex);

                    deepestNode = deepestNode.GetOrAddNode(token.Substring(subnameStartIndex, subnameEndIndex - subnameStartIndex));
                }
            }
            if (!deepestNode.IsTerminated)
            {
                deepestNode.Terminate(fullName);
                TerminatedNodesCount++;
            }
        }
예제 #4
0
        private static void BuildDocumentation(string content, List <string> matches, string schemaName)
        {
            PGSchema schema = SchemaProcessor.GetSchema(schemaName);

            content = content.Replace("[DBName]", Program.Database.ToUpperInvariant());
            content = content.Replace("[SchemaName]", schemaName);

            content = SequenceParser.Parse(content, matches, SequenceProcessor.GetSequences(schemaName));
            content = TableParser.Parse(content, matches, schema.Tables);
            content = ViewParser.Parse(content, matches, schema.Views);
            content = SequenceParser.Parse(content, matches, schema.Sequences);
            content = MaterializedViewParser.Parse(content, matches, schema.MaterializedViews);
            content = FunctionParser.Parse(content, matches, schema.Functions);
            content = FunctionParser.ParseTriggers(content, matches, schema.TriggerFunctions);
            content = TypeParser.Parse(content, matches, schema.Types);

            foreach (PgTable table in schema.Tables)
            {
                Console.WriteLine("Generating documentation for table \"{0}\".", table.Name);
                TableRunner.Run(table);
            }


            foreach (PgFunction function in schema.Functions)
            {
                Console.WriteLine("Generating documentation for function \"{0}\".", function.Name);
                FunctionRunner.Run(function);
            }

            foreach (PgFunction function in schema.TriggerFunctions)
            {
                Console.WriteLine("Generating documentation for trigger function \"{0}\".", function.Name);
                FunctionRunner.Run(function);
            }

            foreach (PgMaterializedView materializedView in schema.MaterializedViews)
            {
                Console.WriteLine("Generating documentation for materialized view \"{0}\".", materializedView.Name);
                MaterializedViewRunner.Run(materializedView);
            }

            foreach (PgView view in schema.Views)
            {
                Console.WriteLine("Generating documentation for view \"{0}\".", view.Name);
                ViewRunner.Run(view);
            }
            foreach (PgType type in schema.Types)
            {
                Console.WriteLine("Generating documentation for type \"{0}\".", type.Name);
                TypeRunner.Run(type);
            }

            string targetPath = System.IO.Path.Combine(OutputPath, schemaName + ".html");

            FileHelper.WriteFile(content, targetPath);
        }
예제 #5
0
        private void ValidateFailedParseResult(string typeFullName, int errorIndex)
        {
            try
            {
                var parsedTypeData = _typeParser.Parse(typeFullName);
                Assert.Fail();
            }
            catch (ParseTypeException e)
            {
                Assert.AreEqual(errorIndex, e.ErrorIndex);

                LogHelper.Context.Log.Error(e.Message);

                var errorLocationText = "Error location: \"";
                LogHelper.Context.Log.Error($"{errorLocationText}{typeFullName}\"");

                var errorLocationLine = new StringBuilder();
                errorLocationLine.Append(new String('-', errorLocationText.Length + e.ErrorIndex));
                // 2191=up arrow.
                errorLocationLine.Append('\u2191');
                LogHelper.Context.Log.Error(errorLocationLine.ToString());
            }
        }
예제 #6
0
        /// <summary>
        /// Creates an api operation
        /// </summary>
        /// <param name="api">Description of the api via the ApiExplorer</param>
        /// <param name="docProvider">Access to the XML docs written in code</param>
        /// <returns>An api operation</returns>
        public static ResourceApiOperation CreateResourceApiOperation(ApiDescription api, XmlCommentDocumentationProvider docProvider)
        {
            ResourceApiOperation rApiOperation = new ResourceApiOperation()
            {
                httpMethod     = api.HttpMethod.ToString(),
                nickname       = docProvider.GetNickname(api.ActionDescriptor),
                responseClass  = TypeParser.Parse(docProvider.GetResponseClass(api.ActionDescriptor)),
                summary        = api.Documentation,
                notes          = docProvider.GetNotes(api.ActionDescriptor),
                parameters     = new List <ResourceApiOperationParameter>(),
                errorResponses = docProvider.GetErrorResponses(api)
            };

            return(rApiOperation);
        }
예제 #7
0
        /// <summary>
        /// Creates an operation parameter
        /// </summary>
        /// <param name="api">Description of the api via the ApiExplorer</param>
        /// <param name="param">Description of a parameter on an operation via the ApiExplorer</param>
        /// <param name="docProvider">Access to the XML docs written in code</param>
        /// <returns>An operation parameter</returns>
        public static ResourceApiOperationParameter CreateResourceApiOperationParameter(ApiDescription api, ApiParameterDescription param, XmlCommentDocumentationProvider docProvider)
        {
            string paramType = (param.Source.ToString().Equals(FROMURI)) ? QUERY : BODY;

            var parameter = new ResourceApiOperationParameter()
            {
                paramType   = (paramType == "query" && api.RelativePath.IndexOf("{" + param.Name + "}") > -1) ? PATH : paramType,
                name        = param.Name,
                description = param.Documentation,
                dataType    = TypeParser.Parse(param.ParameterDescriptor.ParameterType),
                required    = docProvider.GetRequired(param.ParameterDescriptor)
            };

            parameter.allowMultiple   = parameter.dataType.StartsWith("List[");
            parameter.allowableValues = CreateAllowableValues(param.ParameterDescriptor.ParameterType);

            CustomAttributeHelper.PrepareByOptionAttribute(parameter, param.ParameterDescriptor);

            return(parameter);
        }
예제 #8
0
 public override void When()
 {
     Expected = 7;
     Actual   = TypeParser.Parse <int>((object)7);
 }
예제 #9
0
        private static IList <ResourceModelNode> CreateResourceModel(ApiParameterDescription param, Type modelType, XmlCommentDocumentationProvider docProvider)
        {
            lock (s_lock)
            {
                var result = new List <ResourceModelNode>();
                ResourceModelNode rModel = null;

                if ((!modelType.IsEnum && !modelType.Equals(typeof(string))))
                {
                    if (modelType.IsGenericType)
                    {
                        modelType = modelType.GetGenericArguments().First();
                        return(CreateResourceModel(param, modelType, docProvider));
                    }

                    if (s_cache.ContainsKey(modelType))
                    {
                        result.AddRange(s_cache[modelType]);
                        return(result);
                    }


                    rModel = new ResourceModelNode()
                    {
                        Id = TypeParser.Parse(modelType.Name)
                    };

                    s_cache.Add(modelType, result);

                    foreach (var typeProperty in modelType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
                    {
                        var property = new ResourceModelPropertyNode();
                        property.Id   = TypeParser.Parse(typeProperty.Name);
                        property.Type = TypeParser.Parse(typeProperty.PropertyType);

                        if (typeProperty.PropertyType.IsValueType || Nullable.GetUnderlyingType(typeProperty.PropertyType) == null)
                        {
                            rModel.Required.Add(property.Id);
                        }

                        if (property.Type.StartsWith("List["))
                        {
                            property.Type = "array";

                            var itemType = typeProperty.PropertyType.GetGenericArguments().FirstOrDefault();

                            if (itemType == null)
                            {
                                itemType = typeProperty.PropertyType;
                            }

                            property.DefineContainerType(itemType);
                        }

                        result.AddRange(CreateResourceModel(typeProperty.PropertyType, docProvider));

                        if (docProvider != null)
                        {
                            property.Description = docProvider.GetDocumentation(typeProperty);

                            if (typeProperty.PropertyType.IsEnum)
                            {
                                property.AllowableValues = CreateAllowableValues(typeProperty.PropertyType);
                            }
                            else if ((typeProperty.PropertyType.IsClass || typeProperty.PropertyType.IsValueType) && typeof(string) != typeProperty.PropertyType)
                            {
                                result.AddRange(CreateResourceModel(typeProperty.PropertyType, docProvider));
                            }
                        }

                        rModel.Properties.Add(property);
                    }

                    if (rModel.Properties.Count > 0)
                    {
                        result.Add(rModel);
                    }
                }

                return(result);
            }
        }
예제 #10
0
 public override void When()
 {
     Expected = new DateTime(2014, 1, 1);
     Actual   = TypeParser.Parse(typeof(DateTime), null, Expected);
 }
예제 #11
0
 public override void When()
 {
     Expected = Formatting.Indented;
     Actual   = TypeParser.Parse("Indented", Formatting.None);
 }
예제 #12
0
 public override void When()
 {
     Expected = 7d;
     Actual   = TypeParser.Parse <Nullable <double> >("7");
 }
예제 #13
0
 public override void When()
 {
     Expected = 7;
     Actual   = TypeParser.Parse <int?>("7");
 }
        public AddInSchema Parse(XElement e)
        {
            if (e.Name != "schema")
            {
                throw new ArgumentException();
            }

            var schema = new AddInSchema();

            var typeParser   = new TypeParser();
            var entityParser = new AddInEntityParser();

            schema.Types = new List <Type>(e.Element("types").Elements("type").Select(o => typeParser.Parse(o)));

            entityParser.types = schema.Types;

            schema.Entities = new List <AddInEntity>(e.Element("entities").Elements("entity").Select(x => (AddInEntity)entityParser.Parse(x)));



            return(schema);
        }
예제 #15
0
 public override void When()
 {
     Expected = 0;
     Actual   = TypeParser.Parse(typeof(int), (object)"0x7FFFFFFFFFFFFFFF");
 }
 public void DefineContainerType(Type type)
 {
     Items = new Dictionary<string, string>();
     Items.Add("$ref", TypeParser.Parse(type));
 }
예제 #17
0
 public override void When()
 {
     Expected = 11d;
     Actual   = TypeParser.Parse <double>(null, 11);
 }
예제 #18
0
 public override void When()
 {
     Expected = 0d;
     Actual   = TypeParser.Parse(typeof(double), (object)"blarg");
 }
예제 #19
0
 public override void When()
 {
     Expected = null;
     Actual   = TypeParser.Parse <DateTime?>(null);
 }
예제 #20
0
 public override void When()
 {
     Expected = 14;
     Actual   = TypeParser.Parse <int>(null, 14);
 }
예제 #21
0
 public override void When()
 {
     Expected = "test string";
     Actual   = TypeParser.Parse <string>((object)"test string");
 }
예제 #22
0
 public override void When()
 {
     Expected = "";
     Actual   = TypeParser.Parse <string>(null, "");
 }
예제 #23
0
 public override void When()
 {
     Expected = DateTime.Today;
     Actual   = TypeParser.Parse <DateTime?>(Expected.ToString());
 }