Exemplo n.º 1
0
        public static Tuple <Region, List <Method> > Serialize(IMethodImpl method, DocumentConfig documentConfig)
        {
            var template = documentConfig.Templates.FirstOrDefault(t => t.Name == method.Template);

            if (template == null)
            {
                throw new InvalidOperationException($"Template '{method.Template}' does not exist");
            }

            template = new TemplateEvaluator(method, template, documentConfig.Templates).ResolveAll();

            var finalRegions = template.Regions.Select(r => r.Serialize(method, documentConfig)).Where(r => r != null).ToReadOnlyList();
            var finalMethods = template.MethodDefs.SelectMany(m => m.Serialize(method, documentConfig)).ToList();

            if (method.Region)
            {
                var regionName = (method.Description ?? method.Name);

                if (method.PluralRegion)
                {
                    regionName += "s";
                }

                return(Tuple.Create(new Region(regionName, finalRegions, finalMethods.ToReadOnlyList(), false), new List <Method>()));
            }
            else
            {
                return(Tuple.Create <Region, List <Method> >(null, finalMethods));
            }
        }
 /// <summary>
 /// Merges any method specific methods and regions and resolves any templated method/region redirections.
 /// </summary>
 /// <param name="method">The method that is instantiating this template</param>
 /// <param name="template">The template that is being instantiated.</param>
 /// <param name="templates">A list of all known templates.</param>
 /// <returns></returns>
 public TemplateEvaluator(IMethodImpl method, Template template,
                          ReadOnlyCollection <Template> templates)
 {
     methodImpl     = method;
     this.template  = template;
     this.templates = templates;
 }
Exemplo n.º 3
0
        public List <Method> Serialize(IMethodImpl method, DocumentConfig documentConfig, IRegion region = null)
        {
            List <Method> methods = new List <Method>();

            foreach (var type in method.Types)
            {
                var methodConfig = new MethodConfig(method, this, type, documentConfig, region);

                if (!methodConfig.MethodRequired)
                {
                    continue;
                }

                methods.Add(BuildMethod(methodConfig));

                //Query methods don't require any other request types
                if (methodConfig.MethodType == MethodType.Query || methodConfig.MethodType == MethodType.Watch)
                {
                    break;
                }

                if (methodConfig.NeedsTokenInterfaceOverload)
                {
                    var tokenConfig = methodConfig.GetTokenOverloadConfig();

                    methods.Add(BuildMethod(tokenConfig));
                }
            }

            return(methods);
        }
Exemplo n.º 4
0
        //Serialize to either a collection of methods or a region that contains the methods
        public static IEnumerable <IElement> Serialize(IMethodImpl method, DocumentConfig documentConfig)
        {
            var template = documentConfig.Templates.FirstOrDefault(t => t.Name == method.Template);

            if (template == null)
            {
                throw new InvalidOperationException($"Template '{method.Template}' does not exist");
            }

            template = new TemplateEvaluator(method, template, documentConfig.Templates).ResolveAll();

            var finalRegions = template.Regions.Select(r => r.Serialize(method, documentConfig)).Where(r => r != null);
            var finalMethods = template.MethodDefs.SelectMany(m => m.Serialize(method, documentConfig)).ToList();

            if (method.Region)
            {
                var regionName = (method.Description ?? method.Name);

                if (method.PluralRegion)
                {
                    regionName += "s";
                }

                var regionMembers = new List <IElement>();
                regionMembers.AddRange(finalRegions);
                regionMembers.AddRange(finalMethods);

                return(new IElement[] { new Region(regionName, regionMembers.ToReadOnlyList(), false) });
            }
            else
            {
                return(finalMethods);
            }
        }
Exemplo n.º 5
0
        public Region Serialize(IMethodImpl method, DocumentConfig documentConfig)
        {
            if (Type == MethodType.Query && !method.Query)
            {
                return(null);
            }

            var serialized = new List <IElement>();

            foreach (var element in Elements)
            {
                if (element is RegionDef)
                {
                    serialized.Add(((RegionDef)element).Serialize(method, documentConfig));
                }
                else if (element is MethodDef)
                {
                    serialized.AddRange(((MethodDef)element).Serialize(method, documentConfig, this));
                }
                else
                {
                    throw new NotImplementedException($"Don't know how to serialize element of type '{element.GetType()}'.");
                }
            }

            return(new Region(Name, serialized.ToReadOnlyList(), false));
        }
Exemplo n.º 6
0
        private Template GetResolvedTemplate(IMethodImpl methodImpl, DocumentConfig config)
        {
            var template = config.Templates.First(t => t.Name == methodImpl.Template);

            var evaluatedTemplate = new TemplateEvaluator(methodImpl, template, config.Templates);
            var resolvedTemplate  = evaluatedTemplate.ResolveAll();

            return(resolvedTemplate);
        }
Exemplo n.º 7
0
        public Region Serialize(IMethodImpl method, DocumentConfig documentConfig)
        {
            if (Type == MethodType.Query && !method.Query)
            {
                return(null);
            }

            var regions = Regions.Select(r => r.Serialize(method, documentConfig)).ToReadOnlyList();
            var methods = MethodDefs.SelectMany(m => m.Serialize(method, documentConfig, this)).ToReadOnlyList();

            return(new Region(Name, regions, methods, false));
        }
Exemplo n.º 8
0
        public WarpedMethodImpl(IMethodImpl baseImpl, Type argsType, PropertyDescriptorCollection args, PropertyDescriptor result)
        {
            if (baseImpl == null)
                throw new ArgumentNullException("baseImpl");
            if (argsType == null)
                throw new ArgumentNullException("argsType");
            if (args == null)
                throw new ArgumentNullException("args");

            _handler = baseImpl;
            _argsType = argsType;
            _args = args;
            _result = result;
        }
Exemplo n.º 9
0
        private MethodConfig(IMethodImpl methodImpl, MethodDef methodDef, MethodType type, DocumentConfig documentConfig, IRegion region, bool isTokenOverload)
        {
            Method     = methodImpl;
            MethodDef  = methodDef;
            MethodType = type;

            if (region != null && region.Type != MethodType.Unspecified)
            {
                MethodType = region.Type;
            }

            DocumentConfig = documentConfig;
            this.region    = region;

            CalculateCancellationTokenMode(isTokenOverload);
        }
Exemplo n.º 10
0
        public WarpedMethodImpl(IMethodImpl baseImpl, Type argsType, PropertyDescriptorCollection args, PropertyDescriptor result)
        {
            if (baseImpl == null)
            {
                throw new ArgumentNullException("baseImpl");
            }
            if (argsType == null)
            {
                throw new ArgumentNullException("argsType");
            }
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            _handler  = baseImpl;
            _argsType = argsType;
            _args     = args;
            _result   = result;
        }
Exemplo n.º 11
0
        internal Method(MethodBuilder methodBuilder, ServiceClass clazz)
        {
            Debug.Assert(methodBuilder != null);
            Debug.Assert(clazz != null);

            _name         = methodBuilder.Name;
            _internalName = Mask.EmptyString(methodBuilder.InternalName, methodBuilder.Name);
            _resultType   = methodBuilder.ResultType;
            _description  = methodBuilder.Description;
            _handler      = methodBuilder.Handler;
            _idempotent   = methodBuilder.Idempotent;
            _attributes   = methodBuilder.CustomAttributes;
            _class        = clazz;

            //
            // Set up parameters and their names.
            //

            ICollection parameterBuilders = methodBuilder.Parameters;

            _parameters     = new Parameter[parameterBuilders.Count];
            _parameterNames = new string[parameterBuilders.Count];

            foreach (ParameterBuilder parameterBuilder in parameterBuilders)
            {
                Parameter parameter = new Parameter(parameterBuilder, this);
                int       position  = parameter.Position;
                _parameters[position]     = parameter;
                _parameterNames[position] = parameter.Name;
            }

            //
            // Keep a sorted list of parameters and their names so we can
            // do fast look ups using binary search.
            //

            _sortedParameters = (Parameter[])_parameters.Clone();
            InvariantStringArray.Sort(_parameterNames, _sortedParameters);
        }
Exemplo n.º 12
0
        internal Method(MethodBuilder methodBuilder, ServiceClass clazz)
        {
            Debug.Assert(methodBuilder != null);
            Debug.Assert(clazz != null);
            
            _name = methodBuilder.Name;
            _internalName = Mask.EmptyString(methodBuilder.InternalName, methodBuilder.Name);
            _resultType = methodBuilder.ResultType;
            _description = methodBuilder.Description;
            _handler = methodBuilder.Handler;
            _idempotent = methodBuilder.Idempotent;
            _attributes = DeepCopy(methodBuilder.GetCustomAttributes());
            _class = clazz;
            
            //
            // Set up parameters and their names.
            //
            
            ICollection parameterBuilders = methodBuilder.Parameters;
            _parameters = new Parameter[parameterBuilders.Count];
            _parameterNames = new string[parameterBuilders.Count];

            foreach (ParameterBuilder parameterBuilder in parameterBuilders)
            {
                Parameter parameter = new Parameter(parameterBuilder, this);
                int position = parameter.Position;
                _parameters[position] = parameter;
                _parameterNames[position] = parameter.Name;
            }
            
            //
            // Keep a sorted list of parameters and their names so we can
            // do fast look ups using binary search.
            //
            
            _sortedParameters = (Parameter[]) _parameters.Clone();
            InvariantStringArray.Sort(_parameterNames, _sortedParameters);
        }
Exemplo n.º 13
0
 public MethodConfig(IMethodImpl methodImpl, MethodDef methodDef, MethodType type, DocumentConfig documentConfig, IRegion region = null) :
     this(methodImpl, methodDef, type, documentConfig, region, false)
 {
 }