Esempio n. 1
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();
        }
Esempio n. 2
0
        private void WriteService(ServiceController service)
        {
            CodeMonkey monkey = new CodeMonkey(Context.ClassName + ".cs");

            StartWriteService(monkey, service);
            WriteMethods(monkey, service);
            WriteStateVariables(monkey, service);
            EndWriteService(monkey, service);
            monkey.Close();
        }
Esempio n. 3
0
        private void WriteService(ServiceController service)
        {
            CodeMonkey monkey = new CodeMonkey(Context.ClassName + "Controller.cs");

            StartWriteService(monkey, service);
            WriteMethods(monkey, service);
            WriteEvents(monkey, service);
            WriteVerify(monkey, service);
            EndWriteService(monkey);
            monkey.Close();
        }
Esempio n. 4
0
 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();
         }
     }
 }
Esempio n. 5
0
        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();
        }
Esempio n. 6
0
 private void WriteService(ServiceController service)
 {
     CodeMonkey monkey = new CodeMonkey (Context.ClassName + ".cs");
     StartWriteService (monkey, service);
     WriteMethods (monkey, service);
     WriteStateVariables (monkey, service);
     EndWriteService (monkey, service);
     monkey.Close ();
 }
Esempio n. 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 ();
 }
Esempio n. 8
0
 private void WriteService(ServiceController service)
 {
     CodeMonkey monkey = new CodeMonkey (Context.ClassName + "Controller.cs");
     StartWriteService (monkey, service);
     WriteMethods (monkey, service);
     WriteEvents (monkey, service);
     WriteVerify (monkey, service);
     EndWriteService (monkey);
     monkey.Close ();
 }