コード例 #1
0
 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();
 }
コード例 #2
0
        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();
        }
コード例 #3
0
 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 ("}");
 }
コード例 #4
0
        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("}");
        }
コード例 #5
0
ファイル: Runner.cs プロジェクト: MustafaUzumcuCom/mono-upnp
        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();
        }
コード例 #6
0
 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 ();
 }
コード例 #7
0
 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 ();
 }