Ejemplo n.º 1
0
        public async Task <SigSpecDocument> GenerateForHubsAsync(IReadOnlyDictionary <string, Type> hubs)
        {
            var document = new SigSpecDocument();

            return(await GenerateForHubsAsync(hubs, document));
        }
Ejemplo n.º 2
0
        public async Task <SigSpecDocument> GenerateForHubsAsync(IReadOnlyDictionary <string, Type> hubs, SigSpecDocument template)
        {
            var document  = template;
            var resolver  = new SigSpecSchemaResolver(document, _settings);
            var generator = new JsonSchemaGenerator(_settings);

            foreach (var h in hubs)
            {
                var type = h.Value;

                var hub = new SigSpecHub();
                hub.Name        = type.Name.EndsWith("Hub") ? type.Name.Substring(0, type.Name.Length - 3) : type.Name;
                hub.Description = type.GetXmlDocsSummary();

                foreach (var method in GetOperationMethods(type))
                {
                    var operation = GenerateOperation(type, method, generator, resolver, SigSpecOperationType.Sync);
                    hub.Operations[method.Name] = operation;
                }

                foreach (var method in GetChannelMethods(type))
                {
                    hub.Operations[method.Name] = GenerateOperation(type, method, generator, resolver, SigSpecOperationType.Observable);
                }

                var baseTypeGenericArguments = type.BaseType.GetGenericArguments();
                if (baseTypeGenericArguments.Length == 1)
                {
                    var callbackType = baseTypeGenericArguments[0];
                    foreach (var callbackMethod in GetOperationMethods(callbackType))
                    {
                        var callback = GenerateOperation(type, callbackMethod, generator, resolver, SigSpecOperationType.Sync);
                        hub.Callbacks[callbackMethod.Name] = callback;
                    }
                }

                document.Hubs[h.Key] = hub;
            }

            return(document);
        }