コード例 #1
0
        public static IEnumerable <KeyValuePair <string, Tuple <string, string> > > GetAugmentationMethods()
        {
            var methods = OmnisharpControllerExtractor.GetMethods().Where(x => !x.StringBased)
                          .Where(x => x.RequestType != null)
                          .GroupBy(x => x.ActionName)
                          .SelectMany(x => { var max = x.Max(z => z.VersionNumber); return(x.Where(z => max == z.VersionNumber)); })
                          .ToArray();
            var events = OmnisharpControllerExtractor.GetEvents().Where(x => !x.StringBased)
                         .Where(x => x.RequestType != null)
                         .GroupBy(x => x.ActionName)
                         .SelectMany(x => { var max = x.Max(z => z.VersionNumber); return(x.Where(z => max == z.VersionNumber)); })
                         .Join(
                OmnisharpControllerExtractor.GetAggregateEvents().Where(x => !x.StringBased)
                .Where(x => x.RequestType != null)
                .GroupBy(x => x.ActionName)
                .SelectMany(x => { var max = x.Max(z => z.VersionNumber); return(x.Where(z => max == z.VersionNumber)); }),
                x => x.ActionName,
                x => x.ActionName,
                (@event, aggregateEvent) => new { @event, aggregateEvent });

            var serverEvents = OmnisharpEventExtractor.GetEvents().GroupBy(x => x.Name).Select(x => x.First(z => !z.Value.Contains("listen")))
                               .Join(OmnisharpEventExtractor.GetAggregateEvents().GroupBy(x => x.Name).Select(x => x.First(z => !z.Value.Contains("listen"))), x => x.Name, x => x.Name, (@event, aggregateEvent) => new { @event, aggregateEvent });

            var v = $@"{string.Join("\n", methods.Select(x => $"request(ReactiveClient.prototype, \"{x.ActionName}\");"))}
{string.Join("\n", events.Select(x => $"response(ReactiveClientEvents.prototype, \"{[email protected]}\", \"/{[email protected]}\");"))}
{string.Join("\n", serverEvents.Select(x => $"event(ReactiveClientEvents.prototype, \"{[email protected]}\");"))}
";

            yield return(new KeyValuePair <string, Tuple <string, string> >("reactive", Tuple.Create("reactive-client.ts", v)));

            v = $@"{string.Join("\n", events.Select(x => $"makeObservable(ReactiveObservationClient.prototype, \"{[email protected]}\", \"/{[email protected]}\");"))}
{string.Join("\n", serverEvents.Select(x => $"makeObservable(ReactiveObservationClient.prototype, \"{[email protected]}\", \"{[email protected]}\");"))}
";

            yield return(new KeyValuePair <string, Tuple <string, string> >("reactive", Tuple.Create("reactive-observation-client.ts", v)));

            v = $@"{string.Join("\n", events.Select(x => $"makeObservable(ReactiveCombinationClient.prototype, \"{[email protected]}\", \"/{[email protected]}\");"))}
{string.Join("\n", serverEvents.Select(x => $"makeObservable(ReactiveCombinationClient.prototype, \"{[email protected]}\", \"{[email protected]}\");"))}
";

            yield return(new KeyValuePair <string, Tuple <string, string> >("reactive", Tuple.Create("reactive-combination-client.ts", v)));

            v = $@"{string.Join("\n", methods.Select(x => $"request(AsyncClient.prototype, \"{x.ActionName}\");"))}
";

            yield return(new KeyValuePair <string, Tuple <string, string> >("async", Tuple.Create("async-client.ts", v)));
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            var path = string.Empty;

            if (args.Length == 1)
            {
                path = args[0];
            }

            var fluent = TypeScript.Definitions();

            fluent.ScriptGenerator.IndentationString = "    ";

            fluent.WithMemberTypeFormatter(TsFluentFormatters.FormatPropertyType);
            fluent.WithMemberFormatter(TsFluentFormatters.FormatPropertyName);

            foreach (var model in GetApplicableTypes())
            {
                fluent.For(model);
            }

            var tsModel = fluent.ModelBuilder.Build();

            foreach (var @class in tsModel.Classes.Where(z => z.Module.Name.StartsWith("System", StringComparison.Ordinal)))
            {
                @class.IsIgnored = true;
            }

            var result = fluent.Generate();

            var generated         = string.Join("\n", OmnisharpControllerExtractor.GetInterface());
            var projectInterfaces = $@"
declare module {OmnisharpControllerExtractor.InferNamespace(typeof(Request)).TrimEnd('.')} {{
    interface ProjectInformationResponse {{
        MsBuildProject: OmniSharp.Models.MSBuildProject;
        DotNetProject: OmniSharp.Models.DotNetProjectInformation;
    }}

    interface WorkspaceInformationResponse {{
        DotNet: OmniSharp.Models.DotNetWorkspaceInformation;
        MSBuild: OmniSharp.Models.MsBuildWorkspaceInformation;
        ScriptCs: OmniSharp.ScriptCs.ScriptCsContextModel;
    }}
}}
            ";

            result = string.Join("\n", "import {Observable} from \"rxjs\";", result, generated, OmnisharpEventExtractor.GetInterface(), projectInterfaces);
            result = result
                     .Replace("interface", "export interface")
                     .Replace("declare module", "export module")
                     .Replace("export module OmniSharp {", "")
                     .Replace("OmniSharp.", "")
                     .Replace("DotNet.Models", "Models")
            ;

            var lines = result.Split('\n');
            var opens = 0;

            for (var i = 0; i < lines.Length; i++)
            {
                if (lines[i].Contains('{'))
                {
                    opens++;
                }
                if (lines[i].Contains('}'))
                {
                    opens--;
                }
                if (opens < 0 && lines[i].TrimEnd().Length == 1)
                {
                    lines[i] = string.Empty;
                    opens    = 0;
                }
            }

            result = string.Join("\n", lines);

            result = "/* tslint:disable */\n" + result + "\n";

            if (!string.IsNullOrWhiteSpace(path))
            {
                File.WriteAllText(Path.Combine(path, "lib", "omnisharp-server.ts"), result);
                foreach (var item in OmnisharpAugmentationExtractor.GetAugmentationMethods())
                {
                    var p        = Path.Combine(path, "lib", item.Key, item.Value.Item1);
                    var contents = File.ReadAllText(p);
                    contents  = contents.Substring(0, contents.IndexOf("// <#GENERATED />"));
                    contents += "// <#GENERATED />\n" + item.Value.Item2;
                    File.WriteAllText(p, contents);
                }
            }
            else
            {
                Console.Write(result);
                Console.ReadLine();
            }
        }