示例#1
0
        public static WADLApplication GetWADLApplication(System.Type type)
        {
            WADLApplication application = (WADLApplication)type.GetCustomAttributes(typeof(WADLApplication), true).Single <object>();

            application.Doc = WADLDoc.GetWADLDoc(type);
            return(application);
        }
        public Stream Serialize(Encoding encoding)
        {
            Stream          stream;
            WADLApplication application = IntroSpect();

            WADLUtility.Serialize <WADLApplication>(application, out stream);
            return(stream);
        }
        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);
        }