public ContentDirectoryController(ServiceController controller)
        {
            if (controller == null) throw new ArgumentNullException ("controller");

            this.controller = controller;
            Verify ();
        }
Пример #2
0
 public ServiceScpdInfo (ServiceController service)
 {
     this.Build ();
     
     this.service = service;
     
     actionModel = new TreeStore (typeof (string));
     stateVariableModel = new TreeStore (typeof (string));
     
     foreach (var action in service.Actions) {
         var iter = actionModel.AppendValues (action.Key);
         
         foreach (var argument in action.Value.Arguments) {
             var argument_iter = actionModel.AppendValues (iter, argument.Key);
             
             actionModel.AppendValues (argument_iter, Catalog.GetString ("Direction: ") +
                 (argument.Value.Direction == ArgumentDirection.In ? "In" : "Out"));
             actionModel.AppendValues (argument_iter, Catalog.GetString ("Is Return Value: ") + argument.Value.IsReturnValue);
             actionModel.AppendValues (argument_iter, Catalog.GetString ("Related State Variable: ") + argument.Value.RelatedStateVariable);
         }
     }
     
     foreach (var stateVariable in service.StateVariables) {
         var iter = stateVariableModel.AppendValues (stateVariable.Key);
         
         stateVariableModel.AppendValues (iter, Catalog.GetString ("Data Type: ") + stateVariable.Value.DataType);
         stateVariableModel.AppendValues (iter, Catalog.GetString ("Sends Events: ") + stateVariable.Value.SendsEvents);
         stateVariableModel.AppendValues (iter, Catalog.GetString ("Is Multicast: ") + stateVariable.Value.IsMulticast);
         
         if (stateVariable.Value.DefaultValue != null) {
             stateVariableModel.AppendValues (iter, Catalog.GetString ("Default Value: ") + stateVariable.Value.DefaultValue);
         }
         
         if (stateVariable.Value.AllowedValues != null) {
             var allowed_values_iter = stateVariableModel.AppendValues (iter, Catalog.GetString ("Allowed Values"));
             foreach (var value in stateVariable.Value.AllowedValues) {
                 stateVariableModel.AppendValues (allowed_values_iter, value);
             }
         }
         
         if (stateVariable.Value.AllowedValueRange != null) {
             var allowed_value_range_iter = stateVariableModel.AppendValues (iter, Catalog.GetString ("Allowed Value Range"));
             stateVariableModel.AppendValues (allowed_value_range_iter,
                 "Minimum: " + stateVariable.Value.AllowedValueRange.Minimum);
             stateVariableModel.AppendValues (allowed_value_range_iter,
                 "Maximum: " + stateVariable.Value.AllowedValueRange.Maximum);
             if (stateVariable.Value.AllowedValueRange.Step != null) {
                 stateVariableModel.AppendValues (allowed_value_range_iter,
                     "Step: " + stateVariable.Value.AllowedValueRange.Step);
             }
         }
     }
     
     actions.AppendColumn (Catalog.GetString ("Actions"), new CellRendererText (), "text", 0);
     actions.Model = actionModel;
     actions.Selection.Changed += ActionsSelectionChanged;
     
     stateVariables.AppendColumn (Catalog.GetString ("State Variables"), new CellRendererText (), "text", 0);
     stateVariables.Model = stateVariableModel;
 }
Пример #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 ("}");
 }
 public static void AssertEquality (ServiceController sourceController, ServiceController targetController)
 {
     Assert.IsNotNull (targetController);
     Assert.AreEqual (sourceController.SpecVersion.Major, targetController.SpecVersion.Major);
     Assert.AreEqual (sourceController.SpecVersion.Minor, targetController.SpecVersion.Minor);
     var source_actions = sourceController.Actions.Values.GetEnumerator ();
     var target_actions = targetController.Actions.Values.GetEnumerator ();
     while (source_actions.MoveNext ()) {
         Assert.IsTrue (target_actions.MoveNext ());
         AssertEquality (source_actions.Current, target_actions.Current);
     }
     Assert.IsFalse (target_actions.MoveNext ());
     var source_state_variables = sourceController.StateVariables.Values.GetEnumerator ();
     var target_state_variables = targetController.StateVariables.Values.GetEnumerator ();
     while (source_state_variables.MoveNext ()) {
         Assert.IsTrue (target_state_variables.MoveNext ());
         AssertEquality (source_state_variables.Current, target_state_variables.Current);
     }
     Assert.IsFalse (target_state_variables.MoveNext ());
 }
Пример #5
0
 public EventSubscriber(ServiceController serviceController)
 {
     controller = serviceController;
     prefix = GeneratePrefix ();
 }
Пример #6
0
 public void ArgumentsTest ()
 {
     var service = new DummyService<ArgumentsTestClass> ();
     var controller = new ServiceController (
         new[] {
             new DummyServiceAction ("Foo", new[] {
                 new Argument ("stringArg", "A_ARG_stringArg", ArgumentDirection.In),
                 new Argument ("intArg", "A_ARG_intArg", ArgumentDirection.In),
                 new Argument ("byteArg", "A_ARG_byteArg", ArgumentDirection.In),
                 new Argument ("ushortArg", "A_ARG_ushortArg", ArgumentDirection.In),
                 new Argument ("uintArg", "A_ARG_uintArg", ArgumentDirection.In),
                 new Argument ("sbyteArg", "A_ARG_sbyteArg", ArgumentDirection.In),
                 new Argument ("shortArg", "A_ARG_shortArg", ArgumentDirection.In),
                 new Argument ("longArg", "A_ARG_longArg", ArgumentDirection.In),
                 new Argument ("floatArg", "A_ARG_floatArg", ArgumentDirection.In),
                 new Argument ("doubleArg", "A_ARG_doubleArg", ArgumentDirection.In),
                 new Argument ("charArg", "A_ARG_charArg", ArgumentDirection.In),
                 new Argument ("dateTimeArg", "A_ARG_dateTimeArg", ArgumentDirection.In),
                 new Argument ("boolArg", "A_ARG_boolArg", ArgumentDirection.In),
                 new Argument ("byteArrayArg", "A_ARG_byteArrayArg", ArgumentDirection.In),
                 new Argument ("uriArg", "A_ARG_uriArg", ArgumentDirection.In)
             })
         },
         new[] {
             new StateVariable ("A_ARG_stringArg", "string"),
             new StateVariable ("A_ARG_intArg", "i4"),
             new StateVariable ("A_ARG_byteArg", "ui1"),
             new StateVariable ("A_ARG_ushortArg", "ui2"),
             new StateVariable ("A_ARG_uintArg", "ui4"),
             new StateVariable ("A_ARG_sbyteArg", "i1"),
             new StateVariable ("A_ARG_shortArg", "i2"),
             new StateVariable ("A_ARG_longArg", "int"),
             new StateVariable ("A_ARG_floatArg", "r4"),
             new StateVariable ("A_ARG_doubleArg", "r8"),
             new StateVariable ("A_ARG_charArg", "char"),
             new StateVariable ("A_ARG_dateTimeArg", "date"),
             new StateVariable ("A_ARG_boolArg", "boolean"),
             new StateVariable ("A_ARG_byteArrayArg", "bin"),
             new StateVariable ("A_ARG_uriArg", "uri")
         }
     );
     ServiceDescriptionTests.AssertEquality (controller, service.GetController ());
 }
Пример #7
0
 public void RelatedStateVariableAllowedValueRangeTest ()
 {
     var service = new DummyService<RelatedStateVariableAllowedValueRangeTestClass> ();
     var controller = new ServiceController (
         new[] {
             new DummyServiceAction ("Foo", new[] { new Argument ("bar", "A_ARG_bar", ArgumentDirection.In) })
         },
         new[] {
             new StateVariable ("A_ARG_bar", "i4", new AllowedValueRange ("0", "100", "2"))
         }
     );
     ServiceDescriptionTests.AssertEquality (controller, service.GetController ());
 }
Пример #8
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 ();
 }
Пример #9
0
 private void EndWriteService(CodeMonkey monkey, ServiceController service)
 {
     monkey.EndWriteBlock ();
     monkey.EndWriteBlock ();
 }
Пример #10
0
 public void ImplementedOptionalStateVariable ()
 {
     var service = new DummyService<OptionalStateVariablesClass> (new OptionalStateVariablesClass { HasFoo = true });
     var controller = new ServiceController (null,
         new[] {
             new DummyStateVariable ("FooChanged", "string"),
             new DummyStateVariable ("BarChanged", "string") });
     ServiceDescriptionTests.AssertEquality (controller, service.GetController ());
 }
Пример #11
0
 public void ActionNameTest ()
 {
     var service = new DummyService<ActionNameTestClass> ();
     var controller = new ServiceController (new[] { new DummyServiceAction ("foo") }, null);
     ServiceDescriptionTests.AssertEquality (controller, service.GetController ());
 }
Пример #12
0
 public void EventedRelatedStateVariableTest ()
 {
     var service = new DummyService<EventedRelatedStateVariableTestClass> ();
     var controller = new ServiceController (
         new[] {
             new DummyServiceAction ("GetFoo", new[] { new Argument ("foo", "Foo", ArgumentDirection.Out) })
         },
         new[] {
             new DummyStateVariable ("Foo", "string")
         }
     );
     ServiceDescriptionTests.AssertEquality (controller, service.GetController ());
 }
Пример #13
0
 public void ImplementedOptionalAction ()
 {
     var service = new DummyService<OptionalActionClass> (new OptionalActionClass { CanFoo = true });
     var controller = new ServiceController (
         new[] {
             new DummyServiceAction ("Foo", new [] { new Argument ("foo", "A_ARG_foo", ArgumentDirection.In) }),
             new DummyServiceAction ("Bar", new [] { new Argument ("bar", "A_ARG_bar", ArgumentDirection.In) })
         },
         new[] {
             new StateVariable ("A_ARG_foo", "string"),
             new StateVariable ("A_ARG_bar", "string") });
     ServiceDescriptionTests.AssertEquality (controller, service.GetController ());
 }
Пример #14
0
 public void StateVariablesTest ()
 {
     var service = new DummyService<StateVariablesTestClass> ();
     var controller = new ServiceController (null,
         new[] {
             new DummyStateVariable ("StringChanged", "string"),
             new DummyStateVariable ("IntChanged", "i4"),
             new DummyStateVariable ("ByteChanged", "ui1"),
             new DummyStateVariable ("UshortChanged", "ui2"),
             new DummyStateVariable ("UintChanged", "ui4"),
             new DummyStateVariable ("SbyteChanged", "i1"),
             new DummyStateVariable ("ShortChanged", "i2"),
             new DummyStateVariable ("LongChanged", "int"),
             new DummyStateVariable ("FloatChanged", "r4"),
             new DummyStateVariable ("DoubleChanged", "r8"),
             new DummyStateVariable ("CharChanged", "char"),
             new DummyStateVariable ("BoolChanged", "boolean"),
             new DummyStateVariable ("ByteArrayChanged", "bin"),
             new DummyStateVariable ("UriChanged", "uri")
         }
     );
     ServiceDescriptionTests.AssertEquality (controller, service.GetController ());
 }
Пример #15
0
 public void ArgumentTest ()
 {
     var service = new DummyService<ArgumentTestClass> ();
     var controller = new ServiceController (
         new[] {
             new DummyServiceAction ("Foo", new[] { new Argument ("bar", "A_ARG_bar", ArgumentDirection.In) })
         },
         new[] {
             new StateVariable ("A_ARG_bar", "string")
         }
     );
     ServiceDescriptionTests.AssertEquality (controller, service.GetController ());
 }
Пример #16
0
 public void StateVariableIsMulticastTest ()
 {
     var service = new DummyService<StateVariableIsMulticastTestClass> ();
     var controller = new ServiceController (null,
         new[] {
             new DummyStateVariable ("FooChanged", "string", true)
         }
     );
     ServiceDescriptionTests.AssertEquality (controller, service.GetController ());
 }
Пример #17
0
 static Root CreateRoot (ServiceController controller)
 {
     return new DummyRoot (
         new DeviceType ("schemas-upnp-org", "mono-upnp-tests-device", new Version (1, 0)),
         "uuid:d1",
         "Mono.Upnp.Tests Device",
         "Mono Project",
         "Device",
         new DeviceOptions {
             Services = new[] {
                 new Service (
                     new ServiceType ("schemas-upnp-org", "mono-upnp-test-service", new Version (1, 0)),
                     "urn:upnp-org:serviceId:testService1",
                     controller
                 )
             }
         }
     );
 }
Пример #18
0
        protected internal ServiceAction(ServiceController serviceController)
        {
            if (serviceController == null) throw new ArgumentNullException ("serviceController");

            controller = serviceController;
        }
 public ConnectionManager1(ServiceAnnouncement announcement)
 {
     if (announcement == null) throw new ArgumentNullException ("announcement");
     controller = announcement.GetDescription ().GetController ();
     Verify ();
 }
Пример #20
0
        private void WriteEvents(CodeMonkey monkey, ServiceController service)
        {
            foreach (OfflineStateVariable variable in service.StateVariables.Values) {
                if (variable.SendsEvents) {
                    if (variable.IsOptional) {
                        monkey.WriteLine (@"public bool Has{0} {{ get {{ return controller.StateVariables.ContainsKey (""{0}""); }} }}", variable.Name);
                    }
                    monkey.StartWriteBlock ("public event EventHandler<StateVariableChangedArgs<string>> {0}Changed", variable.Name, false);
                    if (variable.IsOptional) {
                        monkey.StartWriteBlock ("add", false);
                        monkey.WriteLine ("if (!Has{0}) return;", variable.Name);
                        monkey.WriteLine (@"controller.StateVariables[""{0}""].Changed += value;", variable.Name);
                        monkey.EndWriteBlock ();

                        monkey.StartWriteBlock ("remove", false);
                        monkey.WriteLine ("if (!Has{0}) return;", variable.Name);
                        monkey.WriteLine (@"controller.StateVariables[""{0}""].Changed -= value;", variable.Name);
                        monkey.EndWriteBlock ();
                    } else {
                        monkey.WriteLine (@"add {{ controller.StateVariables[""{0}""].Changed += value; }}", variable.Name);
                        monkey.WriteLine (@"remove {{ controller.StateVariables[""{0}""].Changed -= value; }}", variable.Name);
                    }
                    monkey.EndWriteBlock ();
                    monkey.WriteLine ();
                }
            }
        }
Пример #21
0
 private void WriteMethods(CodeMonkey monkey, ServiceController service)
 {
     foreach (var action in service.Actions.Values) {
         WriteMethod (monkey, action);
     }
 }
Пример #22
0
 public virtual ServiceAction DeserializeAction (ServiceController controller,
                                                 XmlDeserializationContext context)
 {
     var action = CreateAction (controller);
     Deserialize (action, context);
     return action;
 }
Пример #23
0
 private void WriteStateVariables(CodeMonkey monkey, ServiceController service)
 {
     foreach (StateVariable state_variable in service.StateVariables.Values) {
         if (state_variable.SendsEvents) {
             WriteStateVariable (monkey, state_variable);
         }
     }
 }
Пример #24
0
 public virtual StateVariable DeserializeStateVariable (ServiceController controller,
                                                        XmlDeserializationContext context)
 {
     var state_variable = CreateStateVariable (controller);
     Deserialize (state_variable, context);
     return state_variable;
 }
Пример #25
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 ();
 }
Пример #26
0
 public void RelatedStateVariableAllowedValuesConflictTest3 ()
 {
     var service = new DummyService<RelatedStateVariableAllowedValuesConflictTest3Class> ();
     var controller = new ServiceController (
         new[] {
             new DummyServiceAction ("Foo", new[] { new Argument ("bar", "A_ARG_bar", ArgumentDirection.In) }),
             new DummyServiceAction ("Bar", new[] { new Argument ("bar", "A_ARG_Bar_bar", ArgumentDirection.In) })
         },
         new[] {
             new StateVariable ("A_ARG_bar", new[] { "Foo", "Bar" }),
             new StateVariable ("A_ARG_Bar_bar", new[] { "foo", "bar" })
         }
     );
     ServiceDescriptionTests.AssertEquality (controller, service.GetController ());
 }
Пример #27
0
 protected virtual ServiceAction CreateAction (ServiceController controller)
 {
     return new ServiceAction (this, controller);
 }
Пример #28
0
 private void WriteVerify(CodeMonkey monkey, ServiceController service)
 {
     monkey.StartWriteBlock ("void Verify ()");
     foreach (OfflineAction action in service.Actions.Values) {
         WriteVerifyAction (monkey, action);
     }
     foreach (OfflineStateVariable state_variable in service.StateVariables.Values) {
         if (state_variable.SendsEvents && !state_variable.IsOptional) {
             monkey.WriteLine (@"if (!controller.StateVariables.ContainsKey (""{0}"")) throw new UpnpDeserializationException (string.Format (""The service {{0}} claims to be of type {1} but it does not have the required state variable {0}."", controller.Description.Id));", state_variable.Name, Context.Type);
         }
     }
     monkey.EndWriteBlock ();
 }
Пример #29
0
 protected virtual StateVariable CreateStateVariable (ServiceController controller)
 {
     return new StateVariable (controller);
 }
Пример #30
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 ();
 }