Esempio n. 1
0
        private void AddPortableImports(Project proj)
        {
            var projectFile = GetProjectFilePath(proj);
            var lines       = File.ReadAllLines(projectFile).ToList();

            if (!lines.Any(l => l.Contains("\"portable-net45+win8\"")))
            {
                if (lines.Any(l => l.Contains("\"imports\": \"dnxcore50\"")))
                {
                    var index = TextFileHelper.FindLineWith(lines, "\"imports\": \"dnxcore50\"");
                    lines.RemoveAt(index);
                    lines.Insert(index, "\"imports\": [\"dnxcore50\", \"portable-net45+win8\"]");
                }
                else if (lines.Any(l => l.Contains("\"dnxcore50\"")))
                {
                    var index = TextFileHelper.FindLineWith(lines, "\"dnxcore50\"");
                    lines[index] = lines[index].Replace("\"dnxcore50\"", "\"dnxcore50\", \"portable-net45+win8\"");
                }
                // dotnet5.6
                else if (lines.Any(l => l.Contains("\"imports\": \"dotnet5.6\"")))
                {
                    var index = TextFileHelper.FindLineWith(lines, "\"imports\": \"dotnet5.6\"");
                    lines.RemoveAt(index);
                    lines.Insert(index, "\"imports\": [\"dotnet5.6\", \"portable-net45+win8\"]");
                }
                else if (lines.Any(l => l.Contains("\"dotnet5.6\"")))
                {
                    var index = TextFileHelper.FindLineWith(lines, "\"dotnet5.6\"");
                    lines[index] = lines[index].Replace("\"dotnet5.6\"", "\"dotnet5.6\", \"portable-net45+win8\"");
                }

                File.WriteAllText(projectFile, string.Join(Environment.NewLine, lines));
            }
        }
        private void ConfigureNetCoreMvcServices(List <string> lines)
        {
            var addService = "            services.AddScoped<RAML.WebApiExplorer.ApiExplorerDataFilter>();";

            int line;

            if (!lines.Any(l => l.Contains("services.AddMvc")))
            {
                line = TextFileHelper.FindLineWith(lines, "public void ConfigureServices");
                lines.Insert(line + 2, addService);
                lines.Insert(line + 2, AddMvcWithOptions());
                return;
            }

            line = TextFileHelper.FindLineWith(lines, "services.AddMvc()");
            if (line > 0)
            {
                lines.Insert(line - 1, addService);
                lines.RemoveAt(line);
                lines.Insert(line, AddMvcWithOptions());
                return;
            }

            line = TextFileHelper.FindLineWith(lines, "services.AddMvc(options =>");
            if (line > 0 && lines[line + 1] == "{")
            {
                lines.Insert(line + 1, addService);
                lines.Insert(line + 2, AddOptions());
            }
        }
        private static void RemoveLine(List <string> lines, string content)
        {
            var line = TextFileHelper.FindLineWith(lines, content);

            if (line > 0)
            {
                lines.RemoveAt(line);
            }
        }
        private void ConfigureNetCoreMvc(List <string> lines)
        {
            var appUsestaticfiles = "            app.UseStaticFiles();";

            if (lines.Any(l => l.Contains("app.UseStaticFiles();")))
            {
                return;
            }

            var line = TextFileHelper.FindLineWith(lines, "public void Configure(IApplicationBuilder app");

            if (line > 0)
            {
                lines.Insert(line + 2, appUsestaticfiles);
            }
        }
        private static void InsertLine(List <string> lines)
        {
            var line     = TextFileHelper.FindLineWith(lines, "Register(HttpConfiguration config)");
            var inserted = false;

            if (line != -1)
            {
                if (lines[line + 1].Contains("{"))
                {
                    lines.Insert(line + 2, "\t\t\tRAML.WebApiExplorer.DocumentationProviderConfig.IncludeXmlComments();");
                    inserted = true;
                }
            }

            if (!inserted)
            {
                line = TextFileHelper.FindLineWith(lines, ".MapHttpAttributeRoutes();");
                if (line != -1)
                {
                    lines.Insert(line + 1, "\t\t\tRAML.WebApiExplorer.DocumentationProviderConfig.IncludeXmlComments();");
                }
            }
        }