private void WriteMethodParameters(CodeMonkey monkey, ServiceAction action, bool definition, bool includeAttributes) { bool first = true; foreach (Argument argument in Concat(action.InArguments.Values, action.OutArguments.Values)) { if (first) { first = false; } else { monkey.Write(", "); } if (definition) { if (includeAttributes) { WriteArgumentAttribute(monkey, argument); } WriteMethodParameter(monkey, argument); } else { monkey.Write("{0}{1}", argument.Direction == ArgumentDirection.Out ? "out " : "", ToCamelCase(argument.Name)); } } }
private void WriteMethodSig(CodeMonkey monkey, ServiceAction action, string modifiers, string name, bool includeAttributes) { monkey.WriteLine(modifiers); monkey.Write(action.ReturnArgument != null ? GetTypeName(action.ReturnArgument.RelatedStateVariable.Type) : "void"); monkey.Write(" {0} (", name); WriteMethodParameters(monkey, action, true, includeAttributes); monkey.Write(")"); }
private void WriteArgumentParameterDefinition(CodeMonkey monkey, Argument argument) { if (argument.RelatedStateVariable.AllowedValues != null) { monkey.Write("{0} {1}", EnumerationNames[argument.RelatedStateVariable], ToCamelCase(argument.Name)); } else { monkey.Write("{0} {1}", GetTypeName(argument.RelatedStateVariable.Type), ToCamelCase(argument.Name)); } }
private void WriteMethodParameter(CodeMonkey monkey, Argument argument) { if (argument.Direction == ArgumentDirection.Out) { monkey.Write("out "); } if (argument.RelatedStateVariable.AllowedValues != null) { monkey.Write("{0}AllowedValues {1}", argument.RelatedStateVariable.Name, ToCamelCase(argument.Name)); } else { monkey.Write("{0} {1}", GetTypeName(argument.RelatedStateVariable.Type), ToCamelCase(argument.Name)); } }
private void WriteMethod(CodeMonkey monkey, ServiceAction action) { monkey.WriteLine("[UpnpAction]"); WriteArgumentAttribute(monkey, action.ReturnArgument); WriteMethodSig(monkey, action, "public ", action.Name, true); monkey.StartWriteBlock(); monkey.WriteLine("{0}{1}Core (", action.ReturnArgument == null ? "" : "return ", action.Name); WriteMethodParameters(monkey, action, false, false); monkey.Write(");"); monkey.EndWriteBlock(); monkey.WriteLine(); WriteMethodSig(monkey, action, "public abstract ", action.Name + "Core", false); monkey.Write(";"); monkey.WriteLine(); }
private void StartWriteService(CodeMonkey monkey, ServiceController service) { monkey.Write("// {0}Controller.cs auto-generated at {1} by Sharpener", Context.ClassName, DateTime.Now); monkey.WriteLine(); monkey.WriteUsing("System", "System.Collections.Generic"); monkey.WriteLine(); if (!Context.Namespace.StartsWith("Mono.Upnp")) { monkey.WriteUsing("Mono.Upnp"); } monkey.WriteUsing("Mono.Upnp.Discovery"); monkey.WriteUsing("Mono.Upnp.Description"); monkey.WriteUsing("Mono.Upnp.Control"); monkey.WriteLine(); monkey.StartWriteBlock("namespace {0}", Context.Namespace); monkey.StartWriteBlock("public class {0}Controller", Context.ClassName); monkey.WriteLine(@"public static readonly ServiceType ServiceType = new ServiceType (""{0}"");", Context.Type); monkey.WriteLine("readonly ServiceController controller;"); monkey.StartWriteBlock("public {0}Controller (ServiceAnnouncement announcement)", Context.ClassName); monkey.WriteLine(@"if (announcement == null) throw new ArgumentNullException (""announcement"");"); monkey.WriteLine("ServiceDescription description = announcement.GetDescription ();"); monkey.WriteLine("controller = description.GetController ();"); monkey.WriteLine(@"if (controller == null) throw new UpnpDeserializationException (string.Format (""{0} has no controller."", description));"); monkey.WriteLine("Verify ();"); monkey.EndWriteBlock(); monkey.WriteLine(); monkey.StartWriteBlock("public ServiceDescription ServiceDescription", false); monkey.WriteLine("get { return controller.Description; }"); monkey.EndWriteBlock(); monkey.WriteLine(); }
void WriteServiceClient() { CodeMonkey monkey = new CodeMonkey(Context.ClassName + "Client.cs"); monkey.Write("// {0}.cs auto-generated at {1} by Sharpener", Context.ClassName, DateTime.Now); monkey.WriteLine(); monkey.WriteUsing("System"); monkey.WriteLine(); if (!Context.Namespace.StartsWith("Mono.Upnp")) { monkey.WriteUsing("Mono.Upnp"); monkey.WriteLine(); } monkey.StartWriteBlock("namespace {0}", Context.Namespace); monkey.StartWriteBlock("public class {0}Client", Context.ClassName); monkey.WriteLine("readonly UpnpClient client;"); monkey.WriteLine(); monkey.WriteLine("public event EventHandler<DiscoveryEventArgs<{0}>> {0}Added;", Context.ClassName); monkey.WriteLine(); monkey.StartWriteBlock("public {0}Client () : this (null)", Context.ClassName); monkey.EndWriteBlock(); monkey.WriteLine(); monkey.StartWriteBlock("public {0}Client (UpnpClient client)", Context.ClassName); monkey.WriteLine("this.client = client ?? new UpnpClient ();"); monkey.WriteLine("client.ServiceAdded += ClientServiceAdded;"); monkey.EndWriteBlock(); monkey.WriteLine(); monkey.StartWriteBlock("public UpnpClient Client", false); monkey.WriteLine("get { return client; }"); monkey.EndWriteBlock(); monkey.WriteLine(); monkey.StartWriteBlock("void ClientServiceAdded (object sender, ServiceEventArgs args)"); monkey.WriteLine("if (args.Service.Type != {0}.ServiceType) return;", Context.ClassName); monkey.WriteLine(); monkey.StartWriteBlock("try", false); monkey.WriteLine("{0} service = new {0} (args.Service);", Context.ClassName); monkey.WriteLine("On{0}Added (service);", Context.ClassName); monkey.EndWriteBlock(); monkey.StartWriteBlock("catch"); monkey.EndWriteBlock(); monkey.EndWriteBlock(); monkey.WriteLine(); monkey.StartWriteBlock("public void Browse ()"); monkey.WriteLine("client.Browse ({0}.ServiceType);", Context.ClassName); monkey.EndWriteBlock(); monkey.WriteLine(); monkey.StartWriteBlock("void On{0}Added ({0} service)", Context.ClassName); monkey.WriteLine("EventHandler<DiscoveryEventArgs<{0}>> handler = {0}Added;", Context.ClassName); monkey.StartWriteBlock("if (handler != null)", false); monkey.WriteLine("handler (this, new DiscoveryEventArgs<{0}> (service));", Context.ClassName); monkey.EndWriteBlock(); monkey.EndWriteBlock(); monkey.EndWriteBlock(); monkey.EndWriteBlock(); monkey.Close(); }
private void WriteArgumentAttribute(CodeMonkey monkey, Argument argument) { if (argument == null) { return; } bool writen = false; if (argument.RelatedStateVariable.DefaultValue != null) { string value; if (argument.RelatedStateVariable.Type == typeof(string)) { if (argument.RelatedStateVariable.AllowedValues != null) { value = String.Format(@"""{0}""", argument.RelatedStateVariable.DefaultValue); } else { value = String.Format("{0}.{1}", argument.RelatedStateVariable.Name + "AllowedValues", argument.RelatedStateVariable.DefaultValue); } } else { value = argument.RelatedStateVariable.DefaultValue; } monkey.Write("[UpnpArgument (DefaultValue = {0}", value); writen = true; } if (argument.RelatedStateVariable.AllowedValueRange != null) { if (!writen) { monkey.Write("[UpnpArgument ("); } else { monkey.Write(", "); } monkey.Write("AllowedValueRange = new AllowedValueRange ({0}, {1}, {2})", argument.RelatedStateVariable.AllowedValueRange.Minimum, argument.RelatedStateVariable.AllowedValueRange.Maximum, argument.RelatedStateVariable.AllowedValueRange.Step); writen = true; } if (!IsCamelCase(argument.Name)) { if (!writen) { monkey.Write(@"[UpnpArgument (""{0}"")]", argument.Name); } else { monkey.Write(@", Name = ""{0}""", argument.Name); } } if (writen) { monkey.Write(")]"); } }
protected void WriteEnums(ServiceController service) { foreach (StateVariable variable in service.StateVariables.Values) { if (variable.AllowedValues != null) { string name = variable.Name; if (name.StartsWith("A_ARG_TYPE_")) { name = name.Substring(11); } int count = 1; while (enumeration_names.ContainsValue(name)) { name = variable.Name + count++; } enumeration_names.Add(variable, name); CodeMonkey monkey = new CodeMonkey(name + ".cs"); monkey.Write("// {0}.cs auto-generated at {1} by Sharpener", name, DateTime.Now); monkey.WriteLine(); monkey.StartWriteBlock("namespace {0}", Context.Namespace); monkey.StartWriteBlock("public enum {0}", name); bool first = true; foreach (string value in variable.AllowedValues) { if (first) { first = false; } else { monkey.Write(","); } monkey.WriteLine(value); } monkey.EndWriteBlock(); monkey.EndWriteBlock(); monkey.Close(); } } }
private void StartWriteService(CodeMonkey monkey, ServiceController service) { monkey.Write ("// {0}.cs auto-generated at {1} by Sharpener", Context.ClassName, DateTime.Now); monkey.WriteLine (); monkey.WriteUsing ("System"); monkey.WriteLine (); if (!Context.Namespace.StartsWith ("Mono.Upnp")) { monkey.WriteUsing ("Mono.Upnp"); } monkey.WriteUsing ("Mono.Upnp.Server"); monkey.WriteLine (); monkey.StartWriteBlock ("namespace {0}", Context.Namespace); monkey.StartWriteBlock ("public abstract class {0} : Service", Context.ClassName); monkey.WriteLine ("protected {0} (string id)", Context.ClassName); ServiceType type = new ServiceType (Context.Type); monkey.WriteLine (@"{0}: base (new ServiceType (""{1}"", ""{2}"", new Version ({3}, {4})), id)", monkey.Indentation, type.DomainName, type.Type, type.Version.Major, type.Version.Minor); monkey.WriteLine ("{"); monkey.WriteLine ("}"); }
protected void WriteHelpers() { CodeMonkey monkey = new CodeMonkey("DiscoveryEventArgs.cs"); monkey.Write("// {0}.cs auto-generated at {1} by Sharpener", Context.ClassName, DateTime.Now); monkey.WriteLine(); monkey.WriteUsing("System"); monkey.WriteLine(); monkey.StartWriteBlock("namespace {0}", Context.Namespace); monkey.StartWriteBlock("public class DiscoveryEventArgs<T> : EventArgs"); monkey.WriteLine("readonly T item;"); monkey.StartWriteBlock("internal DiscoveryEventArgs (T item)"); monkey.WriteLine("this.item = item;"); monkey.EndWriteBlock(); monkey.StartWriteBlock("public T Item", false); monkey.WriteLine("get { return item; }"); monkey.EndWriteBlock(); monkey.EndWriteBlock(); monkey.EndWriteBlock(); monkey.Close(); }
private void StartWriteService(CodeMonkey monkey, ServiceController service) { monkey.Write("// {0}.cs auto-generated at {1} by Sharpener", Context.ClassName, DateTime.Now); monkey.WriteLine(); monkey.WriteUsing("System"); monkey.WriteLine(); if (!Context.Namespace.StartsWith("Mono.Upnp")) { monkey.WriteUsing("Mono.Upnp"); } monkey.WriteUsing("Mono.Upnp.Server"); monkey.WriteLine(); monkey.StartWriteBlock("namespace {0}", Context.Namespace); monkey.StartWriteBlock("public abstract class {0} : Service", Context.ClassName); monkey.WriteLine("protected {0} (string id)", Context.ClassName); ServiceType type = new ServiceType(Context.Type); monkey.WriteLine(@"{0}: base (new ServiceType (""{1}"", ""{2}"", new Version ({3}, {4})), id)", monkey.Indentation, type.DomainName, type.Type, type.Version.Major, type.Version.Minor); monkey.WriteLine("{"); monkey.WriteLine("}"); }
private void WriteArgumentAttribute(CodeMonkey monkey, Argument argument) { if (argument == null) { return; } bool writen = false; if (argument.RelatedStateVariable.DefaultValue != null) { string value; if (argument.RelatedStateVariable.Type == typeof (string)) { if (argument.RelatedStateVariable.AllowedValues != null) { value = String.Format (@"""{0}""", argument.RelatedStateVariable.DefaultValue); } else { value = String.Format ("{0}.{1}", argument.RelatedStateVariable.Name + "AllowedValues", argument.RelatedStateVariable.DefaultValue); } } else { value = argument.RelatedStateVariable.DefaultValue; } monkey.Write ("[UpnpArgument (DefaultValue = {0}", value); writen = true; } if (argument.RelatedStateVariable.AllowedValueRange != null) { if (!writen) { monkey.Write ("[UpnpArgument ("); } else { monkey.Write (", "); } monkey.Write ("AllowedValueRange = new AllowedValueRange ({0}, {1}, {2})", argument.RelatedStateVariable.AllowedValueRange.Minimum, argument.RelatedStateVariable.AllowedValueRange.Maximum, argument.RelatedStateVariable.AllowedValueRange.Step); writen = true; } if (!IsCamelCase (argument.Name)) { if (!writen) { monkey.Write (@"[UpnpArgument (""{0}"")]", argument.Name); } else { monkey.Write (@", Name = ""{0}""", argument.Name); } } if (writen) { monkey.Write (")]"); } }
private void WriteMethodSig(CodeMonkey monkey, ServiceAction action, string modifiers, string name, bool includeAttributes) { monkey.WriteLine (modifiers); monkey.Write (action.ReturnArgument != null ? GetTypeName (action.ReturnArgument.RelatedStateVariable.Type) : "void"); monkey.Write (" {0} (", name); WriteMethodParameters (monkey, action, true, includeAttributes); monkey.Write (")"); }
private void WriteMethodParameters(CodeMonkey monkey, ServiceAction action, bool definition, bool includeAttributes) { bool first = true; foreach (Argument argument in Concat (action.InArguments.Values, action.OutArguments.Values)) { if (first) { first = false; } else { monkey.Write (", "); } if (definition) { if (includeAttributes) { WriteArgumentAttribute (monkey, argument); } WriteMethodParameter (monkey, argument); } else { monkey.Write ("{0}{1}", argument.Direction == ArgumentDirection.Out ? "out " : "", ToCamelCase (argument.Name)); } } }
private void WriteMethodParameter(CodeMonkey monkey, Argument argument) { if (argument.Direction == ArgumentDirection.Out) { monkey.Write ("out "); } if (argument.RelatedStateVariable.AllowedValues != null) { monkey.Write ("{0}AllowedValues {1}", argument.RelatedStateVariable.Name, ToCamelCase (argument.Name)); } else { monkey.Write ("{0} {1}", GetTypeName (argument.RelatedStateVariable.Type), ToCamelCase (argument.Name)); } }
private void WriteMethod(CodeMonkey monkey, ServiceAction action) { monkey.WriteLine ("[UpnpAction]"); WriteArgumentAttribute (monkey, action.ReturnArgument); WriteMethodSig (monkey, action, "public ", action.Name, true); monkey.StartWriteBlock (); monkey.WriteLine ("{0}{1}Core (", action.ReturnArgument == null ? "" : "return ", action.Name); WriteMethodParameters (monkey, action, false, false); monkey.Write (");"); monkey.EndWriteBlock (); monkey.WriteLine (); WriteMethodSig (monkey, action, "public abstract ", action.Name + "Core", false); monkey.Write (";"); monkey.WriteLine (); }
private void WriteArgumentParameterDefinition(CodeMonkey monkey, Argument argument) { if (argument.RelatedStateVariable.AllowedValues != null) { monkey.Write ("{0} {1}", EnumerationNames[argument.RelatedStateVariable], ToCamelCase (argument.Name)); } else { monkey.Write ("{0} {1}", GetTypeName (argument.RelatedStateVariable.Type), ToCamelCase (argument.Name)); } }
private void WriteMethod(CodeMonkey monkey, OfflineAction action) { if (action.IsOptional) { monkey.WriteLine(@"public bool Can{0} {{ get {{ return controller.Actions.ContainsKey(""{0}""); }} }}", action.Name); } bool return_single_out_arg = action.ReturnArgument == null && action.OutArguments.Count == 1; string return_type = action.ReturnArgument != null || return_single_out_arg ? "string" : "void"; monkey.WriteLine("public {0} {1} (", return_type, action.Name); bool first = true; List <Argument> enums = new List <Argument>(); foreach (Argument argument in action.InArguments.Values) { if (first) { first = false; } else { monkey.Write(", "); } // TODO proper typing WriteArgumentParameterDefinition(monkey, argument); if (argument.RelatedStateVariable.AllowedValues != null) { enums.Add(argument); } } if (action.OutArguments.Count > 0 && !return_single_out_arg) { foreach (Argument argument in action.OutArguments.Values) { if (first) { first = false; } else { monkey.Write(", "); } monkey.Write("out string {0}", ToCamelCase(argument.Name)); } } monkey.Write(")"); monkey.StartWriteBlock(); if (action.IsOptional) { monkey.WriteLine("if (!Can{0}) throw new NotImplementedException ();", action.Name); } foreach (Argument argument in enums) { IList <string> values = argument.RelatedStateVariable.AllowedValues; monkey.WriteLine(@"if ({0} < {1}.{2} || {1}.{3} < {0}) throw new ArgumentOutOfRangeException (""{0}"");", ToCamelCase(argument.Name), EnumerationNames[argument.RelatedStateVariable], values[0], values[values.Count - 1]); } if (action.InArguments.Count > 0) { monkey.WriteLine("Dictionary<string, string> in_arguments = new Dictionary<string, string> ({0});", action.InArguments.Count); foreach (Argument argument in action.InArguments.Values) { monkey.WriteLine(@"in_arguments.Add (""{0}"", {1});", argument.Name, InArgumentAssignment(argument)); } monkey.WriteLine(@"ActionResult action_result = controller.Actions[""{0}""].Invoke (in_arguments);", action.Name); } else { monkey.WriteLine(@"ActionResult action_result = controller.Actions[""{0}""].Invoke ();", action.Name); } if (!return_single_out_arg) { foreach (Argument argument in action.OutArguments.Values) { monkey.WriteLine(@"{0} = action_result.OutValues[""{1}""];", ToCamelCase(argument.Name), argument.Name); } } if (action.ReturnArgument != null) { monkey.WriteLine("return action_result.ReturnValue;"); } else if (return_single_out_arg) { Argument out_argument = null; foreach (Argument argument in action.OutArguments.Values) { out_argument = argument; break; } monkey.WriteLine(@"return action_result.OutValues[""{0}""];", out_argument.Name); } monkey.EndWriteBlock(); monkey.WriteLine(); }
private void WriteMethod(CodeMonkey monkey, OfflineAction action) { if (action.IsOptional) { monkey.WriteLine (@"public bool Can{0} {{ get {{ return controller.Actions.ContainsKey(""{0}""); }} }}", action.Name); } bool return_single_out_arg = action.ReturnArgument == null && action.OutArguments.Count == 1; string return_type = action.ReturnArgument != null || return_single_out_arg ? "string" : "void"; monkey.WriteLine ("public {0} {1} (", return_type, action.Name); bool first = true; List<Argument> enums = new List<Argument>(); foreach (Argument argument in action.InArguments.Values) { if (first) { first = false; } else { monkey.Write (", "); } // TODO proper typing WriteArgumentParameterDefinition (monkey, argument); if(argument.RelatedStateVariable.AllowedValues != null) { enums.Add(argument); } } if (action.OutArguments.Count > 0 && !return_single_out_arg) { foreach (Argument argument in action.OutArguments.Values) { if (first) { first = false; } else { monkey.Write (", "); } monkey.Write ("out string {0}", ToCamelCase (argument.Name)); } } monkey.Write (")"); monkey.StartWriteBlock (); if (action.IsOptional) { monkey.WriteLine ("if (!Can{0}) throw new NotImplementedException ();", action.Name); } foreach (Argument argument in enums) { IList<string> values = argument.RelatedStateVariable.AllowedValues; monkey.WriteLine (@"if ({0} < {1}.{2} || {1}.{3} < {0}) throw new ArgumentOutOfRangeException (""{0}"");", ToCamelCase(argument.Name), EnumerationNames[argument.RelatedStateVariable], values[0], values[values.Count - 1]); } if (action.InArguments.Count > 0) { monkey.WriteLine ("Dictionary<string, string> in_arguments = new Dictionary<string, string> ({0});", action.InArguments.Count); foreach (Argument argument in action.InArguments.Values) { monkey.WriteLine (@"in_arguments.Add (""{0}"", {1});", argument.Name, InArgumentAssignment (argument)); } monkey.WriteLine (@"ActionResult action_result = controller.Actions[""{0}""].Invoke (in_arguments);", action.Name); } else { monkey.WriteLine (@"ActionResult action_result = controller.Actions[""{0}""].Invoke ();", action.Name); } if (!return_single_out_arg) { foreach (Argument argument in action.OutArguments.Values) { monkey.WriteLine (@"{0} = action_result.OutValues[""{1}""];", ToCamelCase (argument.Name), argument.Name); } } if (action.ReturnArgument != null) { monkey.WriteLine ("return action_result.ReturnValue;"); } else if (return_single_out_arg) { Argument out_argument = null; foreach (Argument argument in action.OutArguments.Values) { out_argument = argument; break; } monkey.WriteLine (@"return action_result.OutValues[""{0}""];", out_argument.Name); } monkey.EndWriteBlock (); monkey.WriteLine (); }
void WriteServiceClient() { CodeMonkey monkey = new CodeMonkey (Context.ClassName + "Client.cs"); monkey.Write ("// {0}.cs auto-generated at {1} by Sharpener", Context.ClassName, DateTime.Now); monkey.WriteLine (); monkey.WriteUsing ("System"); monkey.WriteLine (); if (!Context.Namespace.StartsWith ("Mono.Upnp")) { monkey.WriteUsing ("Mono.Upnp"); monkey.WriteLine (); } monkey.StartWriteBlock ("namespace {0}", Context.Namespace); monkey.StartWriteBlock ("public class {0}Client", Context.ClassName); monkey.WriteLine ("readonly UpnpClient client;"); monkey.WriteLine (); monkey.WriteLine ("public event EventHandler<DiscoveryEventArgs<{0}>> {0}Added;", Context.ClassName); monkey.WriteLine (); monkey.StartWriteBlock ("public {0}Client () : this (null)", Context.ClassName); monkey.EndWriteBlock (); monkey.WriteLine (); monkey.StartWriteBlock ("public {0}Client (UpnpClient client)", Context.ClassName); monkey.WriteLine ("this.client = client ?? new UpnpClient ();"); monkey.WriteLine ("client.ServiceAdded += ClientServiceAdded;"); monkey.EndWriteBlock (); monkey.WriteLine (); monkey.StartWriteBlock ("public UpnpClient Client", false); monkey.WriteLine ("get { return client; }"); monkey.EndWriteBlock (); monkey.WriteLine (); monkey.StartWriteBlock ("void ClientServiceAdded (object sender, ServiceEventArgs args)"); monkey.WriteLine ("if (args.Service.Type != {0}.ServiceType) return;", Context.ClassName); monkey.WriteLine (); monkey.StartWriteBlock ("try", false); monkey.WriteLine ("{0} service = new {0} (args.Service);", Context.ClassName); monkey.WriteLine ("On{0}Added (service);", Context.ClassName); monkey.EndWriteBlock (); monkey.StartWriteBlock ("catch"); monkey.EndWriteBlock (); monkey.EndWriteBlock (); monkey.WriteLine (); monkey.StartWriteBlock ("public void Browse ()"); monkey.WriteLine ("client.Browse ({0}.ServiceType);", Context.ClassName); monkey.EndWriteBlock (); monkey.WriteLine (); monkey.StartWriteBlock ("void On{0}Added ({0} service)", Context.ClassName); monkey.WriteLine ("EventHandler<DiscoveryEventArgs<{0}>> handler = {0}Added;", Context.ClassName); monkey.StartWriteBlock ("if (handler != null)", false); monkey.WriteLine ("handler (this, new DiscoveryEventArgs<{0}> (service));", Context.ClassName); monkey.EndWriteBlock (); monkey.EndWriteBlock (); monkey.EndWriteBlock (); monkey.EndWriteBlock (); monkey.Close (); }
private void StartWriteService(CodeMonkey monkey, ServiceController service) { monkey.Write ("// {0}Controller.cs auto-generated at {1} by Sharpener", Context.ClassName, DateTime.Now); monkey.WriteLine (); monkey.WriteUsing ("System", "System.Collections.Generic"); monkey.WriteLine (); if (!Context.Namespace.StartsWith ("Mono.Upnp")) { monkey.WriteUsing ("Mono.Upnp"); } monkey.WriteUsing ("Mono.Upnp.Discovery"); monkey.WriteUsing ("Mono.Upnp.Description"); monkey.WriteUsing ("Mono.Upnp.Control"); monkey.WriteLine (); monkey.StartWriteBlock ("namespace {0}", Context.Namespace); monkey.StartWriteBlock ("public class {0}Controller", Context.ClassName); monkey.WriteLine (@"public static readonly ServiceType ServiceType = new ServiceType (""{0}"");", Context.Type); monkey.WriteLine ("readonly ServiceController controller;"); monkey.StartWriteBlock ("public {0}Controller (ServiceAnnouncement announcement)", Context.ClassName); monkey.WriteLine (@"if (announcement == null) throw new ArgumentNullException (""announcement"");"); monkey.WriteLine ("ServiceDescription description = announcement.GetDescription ();"); monkey.WriteLine ("controller = description.GetController ();"); monkey.WriteLine (@"if (controller == null) throw new UpnpDeserializationException (string.Format (""{0} has no controller."", description));"); monkey.WriteLine ("Verify ();"); monkey.EndWriteBlock (); monkey.WriteLine (); monkey.StartWriteBlock ("public ServiceDescription ServiceDescription", false); monkey.WriteLine ("get { return controller.Description; }"); monkey.EndWriteBlock (); monkey.WriteLine (); }