コード例 #1
0
 protected internal NetHttpChannelDispatcher(NetHttpChannelManager instance, WADLMethod method, NetHttpUriTemplate template)
 {
     Method = method;
     Instance = instance;
     Template = template;
     MatchType = MatchType.None;
 }
コード例 #2
0
 /// <summary>
 /// Gets all WADLMethod attributes on a method
 /// </summary>
 /// <param name="method"></param>
 /// <returns></returns>
 private static WADLMethod GetWADLMethod(MethodInfo method)
 {
     WADLMethod[] attributes = (WADLMethod[])method.GetCustomAttributes(typeof(WADLMethod), true);
     if (attributes.Length == 0)
     {
         return(null);
     }
     else
     {
         //make sure there is only one
         WADLMethod wadlMethod = attributes.Single <WADLMethod>();
         wadlMethod.methodInfo = method;
         return(wadlMethod);
     }
 }
コード例 #3
0
        public WADLApplication IntroSpect()
        {
            Dictionary <Type, XmlSchemaSet> grammars = new Dictionary <Type, XmlSchemaSet>();;
            WADLApplication application = WADLApplication.GetWADLApplication(type);
            WADLResource    resource    = WADLResource.GetWADLResource(type, baseUri);

            WADLMethod[] methods = WADLMethod.GetWADLMethods(type, delegate(WADLParam wadlParam, XmlSchemaSet schemas)
            {
                AddSchema(grammars, wadlParam.ParameterInfo.ParameterType, schemas);
            },
                                                             delegate(WADLRepresentation wadlParam, XmlSchemaSet schemas)
            {
                if (!String.IsNullOrEmpty(wadlParam.Href) && !application.Includes.Contains(wadlParam.Href.ToLower()))
                {
                    application.Includes.Add(wadlParam.Href.ToLower());
                }
                AddSchema(grammars, wadlParam.Type, schemas);
            });

            foreach (WADLMethod wadlMethod in methods)
            {
                //add method
                //TODO:allow dups if params and template are different
                if (resource.Methods.Exists(delegate(WADLMethod method)
                {
                    bool exists = (method.MethodName == wadlMethod.MethodName);
                    if (exists)
                    {
                        if (method.Parameters.Count == wadlMethod.Parameters.Count)
                        {
                            int index = 0;
                            method.Parameters.ForEach(delegate(WADLParam param)
                            {
                                exists = exists && (param.Style == wadlMethod.Parameters[0].Style);
                                index++;
                            });
                        }
                        else
                        {
                            exists = false;
                        }
                    }
                    return(exists);
                }))
                {
                    throw new NotSupportedException(String.Format("Duplicate WADLMethod '{0}'", wadlMethod.MethodName));
                }
                else
                {
                    resource.Methods.Add(wadlMethod);
                }
            }

            application.Resources.Add(resource);
            XmlSchemaSet schemaSet = new XmlSchemaSet();

            foreach (Type key in grammars.Keys)
            {
                foreach (XmlSchema schema in grammars[key].Schemas())
                {
                    string name = WADLUtility.GetSchemaName(schema);
                    if (!application.Grammars.ContainsKey(name))
                    {
                        application.Grammars.Add(name, schema);
                    }
                }
            }

            return(application);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static WADLMethod[] GetWADLMethods(Type type, WADLParameterAddedHandler onWADLParameterAdded, WADLRepresentationAddedHandler onWADLRepresentationAdded)
        {
            State EmptyWADLMethodFlag = State.None;
            var   headers             = WADLParam.GetWADLParams(type);

            return((from method in type.GetMethods(BindingFlags.Instance | BindingFlags.Public)
                    select method).Where <MethodInfo>(delegate(MethodInfo member)
            {
                return WADLMethod.GetWADLMethod(member) != null;
            }).Aggregate <MethodInfo, List <WADLMethod> >(new List <WADLMethod>(), delegate(List <WADLMethod> list, MethodInfo member)
            {
                WADLMethod method = WADLMethod.GetWADLMethod(member);
                method.doc = WADLDoc.GetWADLDoc(member);

                if (String.IsNullOrEmpty(method.MethodName))
                {
                    if ((EmptyWADLMethodFlag & State.EmptyWADLMethod) == State.EmptyWADLMethod)
                    {
                        //throw new NotSupportedException("only one WADLMethod can be defined without a MethodName");
                    }
                    else
                    {
                        EmptyWADLMethodFlag = State.EmptyWADLMethod | State.EmptyWADLMethodCurrent;
                    }
                }

                WADLParam.GetWADLParams(method.MethodInfo, delegate(WADLParam wadlParam, XmlSchemaSet schemas)
                {
                    if ((EmptyWADLMethodFlag & State.EmptyWADLMethodCurrent) == State.EmptyWADLMethodCurrent && wadlParam.Style == ParamStyles.Template)
                    {
                        EmptyWADLMethodFlag |= State.EmptyWADLMethodCurrentWithWADLPathVariable;
                    }

                    if (method.Parameters.Exists(delegate(WADLParam param)
                    {
                        return param.Name.ToLower() == wadlParam.Name.ToLower() && param.Style == wadlParam.Style;
                    }))
                    {
                        throw new NotSupportedException(String.Format("Duplicate WADLParam {0}", wadlParam.Name));
                    }
                    else
                    {
                        method.Parameters.Add(wadlParam);
                        if (onWADLParameterAdded != null)
                        {
                            onWADLParameterAdded(wadlParam, schemas);
                        }
                    }
                });

                WADLParam[] methodheaders = WADLParam.GetWADLParams(member);
                headers.Union <object>(methodheaders.Except <object>(headers, ((IEqualityComparer <object>) new WADLParam()))
                                       ).Aggregate <object, List <WADLParam> >(method.Headers, delegate(List <WADLParam> aggregator, object header){
                    aggregator.Add((WADLParam)header);
                    return aggregator;
                });

                if ((EmptyWADLMethodFlag & State.EmptyWADLMethodCurrent) == State.EmptyWADLMethodCurrent)
                {
                    if ((EmptyWADLMethodFlag & State.EmptyWADLMethodCurrentWithWADLPathVariable) == State.EmptyWADLMethodCurrentWithWADLPathVariable)
                    {
                        EmptyWADLMethodFlag = EmptyWADLMethodFlag ^ State.EmptyWADLMethodCurrent;
                    }
                    //else //obsolete?
                    //throw new InvalidOperationException("WADLMethods without a MethodName must define at least one WADLParam Template");
                }

                WADLRepresentation.GetWADLRepresentations(member.ReturnParameter, delegate(WADLRepresentation rep, XmlSchemaSet schemas)
                {
                    method.Representations.Add(rep);
                    onWADLRepresentationAdded(rep, schemas);
                });

                WADLRepresentation.GetWADLRepresentations(member.DeclaringType, delegate(WADLRepresentation rep, XmlSchemaSet schemas)
                {
                    if (!method.Representations.Contains(rep, (IEqualityComparer <WADLRepresentation>) new WADLRepresentation()))
                    {
                        method.Representations.Add(rep);
                        onWADLRepresentationAdded(rep, schemas);
                    }
                });



                list.Add(method);
                return list;
            }).ToArray <WADLMethod>());
        }