public void TestWoopsaProtocol() { TestObjectServer objectServer = new TestObjectServer(); using (WoopsaServer server = new WoopsaServer(objectServer)) { using (WoopsaClient client = new WoopsaClient("http://localhost/woopsa")) { WoopsaBoundClientObject root = client.CreateBoundRoot(); root.Properties.ByName("Votes").Value = new WoopsaValue(11); Assert.AreEqual(objectServer.Votes, 11); var result = root.Properties.ByName("Votes").Value; Assert.AreEqual(11, result.ToInt64()); result = root.Methods.ByName(nameof(TestObjectServer.IncrementVotes)). Invoke(5); Assert.AreEqual(16, root.Properties.ByName("Votes").Value.ToInt64()); Assert.AreEqual(WoopsaValueType.Null, result.Type); NameValueCollection args = new NameValueCollection(); args.Add("count", "8"); result = client.ClientProtocol.Invoke("/" + nameof(TestObjectServer.IncrementVotes), args); Assert.AreEqual(24, root.Properties.ByName("Votes").Value.ToInt64()); Assert.AreEqual(WoopsaValueType.Null, result.Type); } } }
public void TestWoopsaClientSubscriptionChannel() { bool isValueChanged = false; TestObjectServer objectServer = new TestObjectServer(); using (WoopsaServer server = new WoopsaServer(objectServer)) { using (WoopsaClient client = new WoopsaClient("http://localhost/woopsa")) { WoopsaBoundClientObject root = client.CreateBoundRoot(); WoopsaClientSubscription subscription = root.Subscribe(nameof(TestObjectServer.Votes), (sender, e) => { isValueChanged = true; }, TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(20)); Stopwatch watch = new Stopwatch(); watch.Start(); while ((!isValueChanged) && (watch.Elapsed < TimeSpan.FromSeconds(20))) Thread.Sleep(10); if (isValueChanged) Console.WriteLine("Notification after {0} ms", watch.Elapsed.TotalMilliseconds); else Console.WriteLine("No notification received"); subscription.Unsubscribe(); Assert.AreEqual(true, isValueChanged); } } }
public void TestWoopsaProtocolPerformance() { TestObjectServer objectServer = new TestObjectServer(); using (WoopsaServer server = new WoopsaServer(objectServer)) { using (WoopsaClient client = new WoopsaClient("http://localhost/woopsa")) { WoopsaBoundClientObject root = client.CreateBoundRoot(); IWoopsaProperty property = root.Properties.ByName("Votes"); property.Value = new WoopsaValue(0); int n = property.Value.ToInt32(); Stopwatch watch = new Stopwatch(); watch.Start(); for (int i = 0; i < 100; i++) { property.Value = new WoopsaValue(i); Assert.AreEqual(objectServer.Votes, i); var result = property.Value; Assert.AreEqual(result.ToInt64(), i); } TimeSpan duration = watch.Elapsed; Assert.IsTrue(duration < TimeSpan.FromMilliseconds(200)); } } }
public void TestWoopsaWaitNotification() { TestObjectServer objectServer = new TestObjectServer(); using (WoopsaServer server = new WoopsaServer(objectServer)) { using (WoopsaClient client = new WoopsaClient("http://localhost/woopsa")) { WoopsaBoundClientObject root = client.CreateBoundRoot(); // Just to show how to see all items foreach (var item in root.Items) { Console.WriteLine("Item = " + item.Name); if (item.Name == "SubscriptionService") Console.WriteLine("Trouvé"); } // create a subscription object WoopsaObject subscription = root.Items.ByNameOrNull("SubscriptionService") as WoopsaObject; if (subscription != null) { int result = 0; WoopsaMethod methodCreateScubscriptionChannel = subscription.Methods.ByNameOrNull("CreateSubscriptionChannel"); if (methodCreateScubscriptionChannel != null) // call the method "CreateSubscriptionChannel" on the server result = methodCreateScubscriptionChannel.Invoke(1000); // define the queue size int channel = result; WoopsaMethod methodRegisterScubscription = subscription.Methods.ByNameOrNull("RegisterSubscription"); if (methodRegisterScubscription != null) // call the method "registerScubscription" on the server result = methodRegisterScubscription.Invoke(channel, WoopsaValue.WoopsaRelativeLink("/Votes"), 0.01, 0.01); int subscriptionNbr = result; WoopsaJsonData jData; WoopsaMethod methodWaitNotification = subscription.Methods.ByNameOrNull("WaitNotification"); if (methodWaitNotification != null) { Stopwatch watch = new Stopwatch(); watch.Start(); // call the method "WaitNotification" on the server Thread.Sleep(100); jData = methodWaitNotification.Invoke(channel, 0).JsonData; Assert.IsTrue(jData.Length > 0); int lastNotification; lastNotification = jData[0]["Id"]; Assert.AreEqual(lastNotification, 1); // Get notifications again Thread.Sleep(100); jData = methodWaitNotification.Invoke(channel, 0).JsonData; Assert.IsTrue(jData.Length > 0); lastNotification = jData[0]["Id"]; Assert.AreEqual(lastNotification, 1); } } } } }
public WoopsaClientSubscriptionChannel(WoopsaClient client, WoopsaUnboundClientObject woopsaRoot, int notificationQueueSize) { _client = client; _woopsaRoot = woopsaRoot; _woopsaSubscribeService = _woopsaRoot.GetUnboundItem( WoopsaSubscriptionServiceConst.WoopsaServiceSubscriptionName); CreateWoopsaSubscriptionServiceMethods(); _notificationQueueSize = notificationQueueSize; _subscriptions = new List <WoopsaClientSubscription>(); _registeredSubscriptions = new Dictionary <int, WoopsaClientSubscription>(); _channelLock = new object(); _subscriptionLock = new object(); _lostSubscriptions = new List <int>(); }
public void TestWoopsaClientSubscriptionDisappearingProperty() { bool isValueChanged = false; MainClass objectServer = new MainClass(); InnerClass inner = new InnerClass(); objectServer.Inner = inner; using (WoopsaServer server = new WoopsaServer(objectServer)) { using (WoopsaClient client = new WoopsaClient("http://localhost/woopsa")) { WoopsaBoundClientObject root = client.CreateBoundRoot(); WoopsaObject Inner = root.Items.ByName(nameof(MainClass.Inner)) as WoopsaObject; WoopsaClientProperty propertyInfo = Inner.Properties.ByName(nameof(InnerClass.Info)) as WoopsaClientProperty; WoopsaClientSubscription subscription = propertyInfo.Subscribe( (sender, e) => { isValueChanged = true; }, TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(20)); inner.Info = "Test"; Stopwatch watch = new Stopwatch(); watch.Start(); while ((!isValueChanged) && (watch.Elapsed < TimeSpan.FromSeconds(20))) Thread.Sleep(10); if (isValueChanged) Console.WriteLine("Notification after {0} ms", watch.Elapsed.TotalMilliseconds); else Console.WriteLine("No notification received"); isValueChanged = false; objectServer.Inner = new BaseInnerClass(); // objectServer.Inner = new object(); while ((!isValueChanged) && (watch.Elapsed < TimeSpan.FromSeconds(20))) Thread.Sleep(10); subscription.Unsubscribe(); Assert.AreEqual(true, isValueChanged); } } }
public void TestWoopsaClientSubscriptionChannelUnexistingItem() { TestObjectServer objectServer = new TestObjectServer(); using (WoopsaServer server = new WoopsaServer(objectServer)) { using (WoopsaClient client = new WoopsaClient("http://localhost/woopsa")) { WoopsaBoundClientObject root = client.CreateBoundRoot(); try { WoopsaClientSubscription sub = root.Subscribe("ThisDoesNotExistInTheServer", (sender, e) => { }, TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(20)); Assert.Fail(); } catch (Exception) { } } } }
public void TestWoopsaClientSubscriptionChannelNoRemoteSubscriptionService() { bool isValueChanged = false; WoopsaObject objectServer = new WoopsaObject(null, ""); int Votes = 0; WoopsaProperty propertyVotes = new WoopsaProperty(objectServer, "Votes", WoopsaValueType.Integer, (p) => Votes, (p, value) => { Votes = value.ToInt32(); }); using (WoopsaServer server = new WoopsaServer((IWoopsaContainer)objectServer)) { using (WoopsaClient client = new WoopsaClient("http://localhost/woopsa")) { WoopsaBoundClientObject root = client.CreateBoundRoot(); WoopsaClientSubscription subscription = root.Subscribe(nameof(TestObjectServer.Votes), (sender, e) => { isValueChanged = true; }, TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(20)); Votes = 2; Stopwatch watch = new Stopwatch(); watch.Start(); while ((!isValueChanged) && (watch.Elapsed < TimeSpan.FromSeconds(2000))) Thread.Sleep(10); if (isValueChanged) Console.WriteLine("Notification after {0} ms", watch.Elapsed.TotalMilliseconds); else Console.WriteLine("No notification received"); subscription.Unsubscribe(); Assert.AreEqual(true, isValueChanged); } } }
internal WoopsaBaseClientObject(WoopsaClient client, WoopsaContainer container, string name, IWoopsaContainer root) : base(container, name) { Client = client; Root = root ?? this; }
static void Main(string[] args) { Console.WriteLine(" *** Welcome to the Woopsa Demo Client! *** "); Console.WriteLine(" Note: read the source code to understand what's happening behind the scenes!"); Console.WriteLine(""); string serverUrl; if (File.Exists("url.config")) { serverUrl = File.ReadAllText("url.config"); Console.WriteLine("Using url.config"); } else { Console.Write("Please enter the Woopsa server URL or leave blank for default (http://localhost/woopsa): "); serverUrl = Console.ReadLine(); if (serverUrl == "") serverUrl = "http://localhost/woopsa"; } WoopsaClient client = new WoopsaClient(serverUrl); Console.WriteLine("Woopsa client created on URL: {0}", serverUrl); WoopsaBoundClientObject root = client.CreateBoundRoot(); ExploreItem(root); // Leave the DOS window open Console.WriteLine("Press any key to exit..."); Console.ReadLine(); client.Dispose(); }
public void TestWoopsaServerAuthentication() { TestObjectServerAuthentification objectServer = new TestObjectServerAuthentification(); using (WoopsaServer server = new WoopsaServer(objectServer)) { server.Authenticator = new SimpleAuthenticator("TestRealm", (sender, e) => { e.IsAuthenticated = e.Username=="woopsa"; }); using (WoopsaClient client = new WoopsaClient("http://localhost/woopsa")) { const string TestUserName ="******"; client.Username = TestUserName; WoopsaBoundClientObject root = client.CreateBoundRoot(); WoopsaProperty propertyVotes = root.Properties.ByName("Votes"); propertyVotes.Value = 5; Assert.AreEqual(objectServer.Votes, 5); Assert.AreEqual((int)propertyVotes.Value, 5); WoopsaProperty propertyCurrentUserName = root.Properties.ByName(nameof(TestObjectServerAuthentification.CurrentUserName)); Assert.AreEqual(propertyCurrentUserName.Value, TestUserName); client.Username = "******"; bool authenticationCheckOk; try { propertyVotes.Value = 5; authenticationCheckOk = false; } catch { authenticationCheckOk = true; } Assert.IsTrue(authenticationCheckOk); } } }
public void TestWoopsaProtocolUnboundClient() { TestObjectServer objectServer = new TestObjectServer(); using (WoopsaClient client = new WoopsaClient("http://localhost/woopsa")) { WoopsaUnboundClientObject root = client.CreateUnboundRoot("root"); WoopsaProperty propertyVote = root.GetProperty("Votes", WoopsaValueType.Integer, false); using (WoopsaServer server = new WoopsaServer(objectServer)) { propertyVote.Value = new WoopsaValue(123); Assert.AreEqual(objectServer.Votes, 123); var result = propertyVote.Value; Assert.AreEqual(result.ToInt64(), 123); } } }
public WoopsaClientSubscriptionChannel(WoopsaClient client, WoopsaUnboundClientObject woopsaRoot, int notificationQueueSize) { _client = client; _woopsaRoot = woopsaRoot; _woopsaSubscribeService = _woopsaRoot.GetUnboundItem( WoopsaSubscriptionServiceConst.WoopsaServiceSubscriptionName); CreateWoopsaSubscriptionServiceMethods(); _notificationQueueSize = notificationQueueSize; _subscriptions = new List<WoopsaClientSubscription>(); _registeredSubscriptions = new Dictionary<int, WoopsaClientSubscription>(); _channelLock = new object(); _subscriptionLock = new object(); _lostSubscriptions = new List<int>(); }
public void ExecuteMultiRequestTestSerie(WoopsaClient client, TestObjectMultiRequest objectServer) { WoopsaClientMultiRequest multiRequest = new WoopsaClientMultiRequest(); WoopsaClientRequest request1 = multiRequest.Write("TestObject/A", 1); WoopsaClientRequest request2 = multiRequest.Write("TestObject/B", 2); WoopsaClientRequest request3 = multiRequest.Read("TestObject/Sum"); WoopsaClientRequest request4 = multiRequest.Write("TestObject/C", 4); WoopsaClientRequest request5 = multiRequest.Meta("TestObject"); WoopsaMethodArgumentInfo[] argumentInfosSet = new WoopsaMethodArgumentInfo[] { new WoopsaMethodArgumentInfo("a", WoopsaValueType.Real), new WoopsaMethodArgumentInfo("b", WoopsaValueType.Real) }; WoopsaClientRequest request6 = multiRequest.Invoke("TestObject/Set", argumentInfosSet, 4, 5); WoopsaClientRequest request7 = multiRequest.Read("TestObject/Sum"); WoopsaClientRequest request8 = multiRequest.Invoke("TestObject/Click", new Dictionary<string, WoopsaValue>()); WoopsaClientRequest request9 = multiRequest.Read("TestObject/IsClicked"); WoopsaClientRequest request10 = multiRequest.Write("TestObject/IsClicked", false); WoopsaClientRequest request11 = multiRequest.Read("TestObject/IsClicked"); WoopsaMethodArgumentInfo[] argumentInfosSetS = new WoopsaMethodArgumentInfo[] { new WoopsaMethodArgumentInfo("value", WoopsaValueType.Text) }; WoopsaClientRequest request12 = multiRequest.Invoke("TestObject/SetS", argumentInfosSetS, "Hello"); WoopsaClientRequest request13 = multiRequest.Read("TestObject/S"); WoopsaClientRequest request14 = multiRequest.Write("TestObject/S", "ABC"); WoopsaClientRequest request15 = multiRequest.Read("TestObject/S"); client.ExecuteMultiRequest(multiRequest); Assert.AreEqual(objectServer.A, 4); Assert.AreEqual(objectServer.B, 5); Assert.AreEqual(request3.Result.ResultType, WoopsaClientRequestResultType.Value); Assert.AreEqual(request3.Result.Value, 3.0); Assert.AreEqual(request4.Result.ResultType, WoopsaClientRequestResultType.Error); Assert.IsNotNull(request4.Result.Error); Assert.AreEqual(request5.Result.ResultType, WoopsaClientRequestResultType.Meta); Assert.IsNotNull(request5.Result.Meta); Assert.AreEqual(request6.Result.ResultType, WoopsaClientRequestResultType.Value); Assert.IsNotNull(request6.Result.Value); Assert.AreEqual(request6.Result.Value.Type, WoopsaValueType.Null); Assert.AreEqual(request7.Result.ResultType, WoopsaClientRequestResultType.Value); Assert.IsNotNull(request7.Result.Value); Assert.AreEqual(request7.Result.Value, 9.0); Assert.AreEqual(request8.Result.ResultType, WoopsaClientRequestResultType.Value); Assert.AreEqual(request8.Result.Value.Type, WoopsaValueType.Null); Assert.IsTrue(request9.Result.Value); Assert.AreEqual(request10.Result.ResultType, WoopsaClientRequestResultType.Value); Assert.IsFalse(request11.Result.Value); Assert.AreEqual(request12.Result.ResultType, WoopsaClientRequestResultType.Value); Assert.AreEqual(request12.Result.Value.Type, WoopsaValueType.Null); Assert.AreEqual(request13.Result.ResultType, WoopsaClientRequestResultType.Value); Assert.IsNotNull(request13.Result.Value); Assert.AreEqual(request13.Result.Value, "Hello"); Assert.AreEqual(objectServer.S, "ABC"); Assert.AreEqual(request15.Result.ResultType, WoopsaClientRequestResultType.Value); Assert.IsNotNull(request15.Result.Value); Assert.AreEqual(request15.Result.Value, "ABC"); }
public void TestWoopsaMultiRequestNoRemoteMultiRequestService() { WoopsaObject serverRoot = new WoopsaObject(null, ""); TestObjectMultiRequest objectServer = new TestObjectMultiRequest(); WoopsaObjectAdapter adapter = new WoopsaObjectAdapter(serverRoot, "TestObject", objectServer); using (WoopsaServer server = new WoopsaServer((IWoopsaContainer)serverRoot)) { using (WoopsaClient client = new WoopsaClient("http://localhost/woopsa")) { ExecuteMultiRequestTestSerie(client, objectServer); } } }
public void TestWoopsaClientSubscriptionChannel5000SubscriptionsObservableCollection() { const int ObjectsCount = 5000; int totalNotifications = 0; ObservableCollection<ManySubscriptionTestObject> list = new ObservableCollection<WoopsaTest.UnitTestWoopsaClient.ManySubscriptionTestObject>(); for (int i = 0; i < ObjectsCount; i++) list.Add(new ManySubscriptionTestObject() { Trigger = i }); using (WoopsaServer server = new WoopsaServer(new WoopsaObjectAdapter(null, "list", list, null, null, WoopsaObjectAdapterOptions.None, WoopsaVisibility.DefaultIsVisible | WoopsaVisibility.IEnumerableObject))) { using (WoopsaClient client = new WoopsaClient("http://localhost/woopsa", null, ObjectsCount)) { WoopsaBoundClientObject root = client.CreateBoundRoot(); for (int i = 0; i < list.Count; i++) { int index = i; WoopsaClientSubscription subscription = root.Subscribe( WoopsaUtils.CombinePath( WoopsaObjectAdapter.EnumerableItemDefaultName(i), nameof(ManySubscriptionTestObject.Trigger)), (sender, e) => { list[index].HasNotified = true; totalNotifications++; }, TimeSpan.FromMilliseconds(10), TimeSpan.FromMilliseconds(200)); } Stopwatch watch = new Stopwatch(); watch.Start(); while ((totalNotifications < ObjectsCount) && (watch.Elapsed < TimeSpan.FromSeconds(500))) Thread.Sleep(10); if (totalNotifications == ObjectsCount) Console.WriteLine("All notification after {0} ms", watch.Elapsed.TotalMilliseconds); else Console.WriteLine("{0} notification received, {1} expected", totalNotifications, ObjectsCount); Assert.AreEqual(ObjectsCount, totalNotifications); } } }
public void TestWoopsaProtocolRootContainer() { WoopsaRoot serverRoot = new WoopsaRoot(); TestObjectServer objectServer = new TestObjectServer(); WoopsaObjectAdapter adapter = new WoopsaObjectAdapter(serverRoot, "TestObject", objectServer); using (WoopsaServer server = new WoopsaServer(serverRoot)) { using (WoopsaClient client = new WoopsaClient("http://localhost/woopsa")) { WoopsaBoundClientObject root = client.CreateBoundRoot(); (root.Items.ByName("TestObject") as WoopsaObject).Properties.ByName("Votes").Value = 17; Assert.AreEqual(objectServer.Votes, 17); } } }
public WoopsaDynamicClient(string url) { _client = new WoopsaClient(url); Refresh(); }
internal WoopsaUnboundClientObject(WoopsaClient client, WoopsaContainer container, string name, IWoopsaContainer root) : base(client, container, name, root) { }
public WoopsaDynamicClient(WoopsaClient client, WoopsaConverters customTypeConverters = null) : base(customTypeConverters) { _client = client; Refresh(); }