public Stream Serialize(Encoding encoding) { Stream stream; WADLApplication application = IntroSpect(); WADLUtility.Serialize <WADLApplication>(application, out stream); return(stream); }
public static WADLRepresentation CreateWADLRepresentation(Type type, out XmlSchemaSet schemas) { WADLRepresentation representation = null; if (type.GetInterface("IXmlSerializable") == null)//not IXmlSerializable { //must infer if (type.IsSerializable) { schemas = WADLUtility.Infer(type); } else { throw new NotSupportedException(String.Format("{0} must be marked as serializable or implement the IXmlSerializable interface", type.Name)); } } else { var instance = Activator.CreateInstance(type); schemas = new XmlSchemaSet(); XmlSchema schema = ((IXmlSerializable)instance).GetSchema(); if (schema == null) { throw new NotSupportedException(String.Format("{0} must be marked as serializable or implement the IXmlSerializable interface", type.Name)); } else { schemas.Add(schema); } } representation = new WADLRepresentation(ContentTypes.xml); representation.Path = WADLUtility.GetSchemaName(schemas, type); if (String.IsNullOrEmpty(representation.Path)) { throw new ArgumentNullException(String.Format("Could not locate Schema for {0}", type.Name)); } return(representation); }
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); }