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 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 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 WoopsaMultiRequestHandler(WoopsaObject root, WoopsaServer server) { _server = server; new WoopsaMethod(root, WoopsaMultiRequestConst.WoopsaMultiRequestMethodName, WoopsaValueType.JsonData, new List<WoopsaMethodArgumentInfo> { new WoopsaMethodArgumentInfo(WoopsaMultiRequestConst.WoopsaMultiRequestArgumentName, WoopsaValueType.JsonData) }, (s) => (HandleCall(s.ElementAt(0))) ); }
public WoopsaMultiRequestHandler(WoopsaObject root, WoopsaServer server) { _server = server; new WoopsaMethod(root, WoopsaMultiRequestConst.WoopsaMultiRequestMethodName, WoopsaValueType.JsonData, new List <WoopsaMethodArgumentInfo> { new WoopsaMethodArgumentInfo(WoopsaMultiRequestConst.WoopsaMultiRequestArgumentName, WoopsaValueType.JsonData) }, (s) => (HandleCall(s.ElementAt(0))) ); }
public void Load() { _rootWoopsaObject = new WoopsaObject(null, "root"); _woopsaServer = new WoopsaServer(_rootWoopsaObject, port); _woopsaServer.WebServer.Routes.Add("/Pages", HTTPMethod.GET, new RouteHandlerFileSystem(folderPathWebPages)); Thread thread; #region infoDebug DiagnosticWindow.AddToDebug("\nWoopsa server listening on http://localhost:" + _woopsaServer.WebServer.Port + _woopsaServer.RoutePrefix); DiagnosticWindow.AddToDebug("Some examples of what you can do directly from your browser:"); DiagnosticWindow.AddToDebug(" * View the object hierarchy of the root object:"); DiagnosticWindow.AddToDebug(" http://localhost:" + _woopsaServer.WebServer.Port + _woopsaServer.RoutePrefix + "meta/"); DiagnosticWindow.AddToDebug(" * Read the value of a property:"); DiagnosticWindow.AddToDebug(" http://localhost:" + _woopsaServer.WebServer.Port + _woopsaServer.RoutePrefix + "read/Temperature "); DiagnosticWindow.AddToDebug(" * Surfing on the web pages found in the directory \n specified in Advanced Settings :"); DiagnosticWindow.AddToDebug(" http://localhost:" + _woopsaServer.WebServer.Port + "/Pages/ \n"); #endregion bool allThreadAreAbort; do { lock (_thisLock) { allThreadAreAbort = _allThreadAreAbort; } } while (!allThreadAreAbort); DiagnosticWindow.ResetPlcStatus(); _woopsaAdsThreadList = new List<Thread>(); lock (plcParameterList) { _shouldStop = false; } foreach (PlcParameter parameter in plcParameterList) { thread = new Thread(Start); thread.Name = "WoopsaAdsController - " + parameter.name; thread.Start(parameter); _woopsaAdsThreadList.Add(thread); } lock (_thisLock) { _allThreadAreAbort = false; } isRunning = true; }
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); } } }
internal WoopsaServerModelAccessLockedSection(WoopsaServer server) { _server = server; server.ExecuteBeforeWoopsaModelAccess(); }
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); } } }
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 WoopsaSubscriptionService(WoopsaServer server, WoopsaContainer container) : base(container, WoopsaSubscriptionServiceConst.WoopsaServiceSubscriptionName) { _server = server; _subscriptionServiceImplementation = new WoopsaSubscriptionServiceImplementation(container, true); _subscriptionServiceImplementation.BeforeWoopsaModelAccess += (sender, e) => { server.ExecuteBeforeWoopsaModelAccess(); }; _subscriptionServiceImplementation.AfterWoopsaModelAccess += (sender, e) => { server.ExecuteAfterWoopsaModelAccess(); }; MethodCreateSubscriptionChannel = new WoopsaMethod( this, WoopsaSubscriptionServiceConst.WoopsaCreateSubscriptionChannel, WoopsaValueType.Integer, new WoopsaMethodArgumentInfo[] { new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaNotificationQueueSize, WoopsaValueType.Integer) }, arguments => _subscriptionServiceImplementation.CreateSubscriptionChannel(arguments[0].ToInt32()) ); MethodRegisterSubscription = new WoopsaMethod( this, WoopsaSubscriptionServiceConst.WoopsaRegisterSubscription, WoopsaValueType.Integer, new WoopsaMethodArgumentInfo[] { new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaSubscriptionChannel, WoopsaValueType.Integer), new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaPropertyLink, WoopsaValueType.WoopsaLink), new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaMonitorInterval, WoopsaValueType.TimeSpan), new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaPublishInterval, WoopsaValueType.TimeSpan) }, arguments => { return _subscriptionServiceImplementation.RegisterSubscription( arguments[0].ToInt32(), arguments[1].DecodeWoopsaLocalLink(), arguments[2].ToTimeSpan(), arguments[3].ToTimeSpan()); }); MethodUnregisterSubscription = new WoopsaMethod( this, WoopsaSubscriptionServiceConst.WoopsaUnregisterSubscription, WoopsaValueType.Logical, new WoopsaMethodArgumentInfo[] { new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaSubscriptionChannel, WoopsaValueType.Integer), new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaSubscriptionId, WoopsaValueType.Integer) }, arguments => { return _subscriptionServiceImplementation.UnregisterSubscription( arguments[0].ToInt32(), arguments[1].ToInt32()); }); MethodWaitNotification = new WoopsaMethod( this, WoopsaSubscriptionServiceConst.WoopsaWaitNotification, WoopsaValueType.JsonData, new WoopsaMethodArgumentInfo[] { new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaSubscriptionChannel, WoopsaValueType.Integer), new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaLastNotificationId, WoopsaValueType.Integer) }, arguments => { using (var accessFreeSection = _server.EnterModelAccessFreeSection()) return new WoopsaValue(_subscriptionServiceImplementation.WaitNotification( arguments[0].ToInt32(), arguments[1].ToInt32())); }); }
static void Main(string[] args) { try { WeatherStation root = new WeatherStation(); bool done = false; using (WoopsaServer woopsaServer = new WoopsaServer(root, 80)) { Console.WriteLine("Woopsa server listening on http://localhost:{0}{1}", woopsaServer.WebServer.Port, woopsaServer.RoutePrefix); Console.WriteLine("Some examples of what you can do directly from your browser:"); Console.WriteLine(" * View the object hierarchy of the root object:"); Console.WriteLine(" http://localhost:{0}{1}meta/", woopsaServer.WebServer.Port, woopsaServer.RoutePrefix); Console.WriteLine(" * Read the value of a property:"); Console.WriteLine(" http://localhost:{0}{1}read/Temperature", woopsaServer.WebServer.Port, woopsaServer.RoutePrefix); Console.WriteLine(); Console.WriteLine("Commands : QUIT, AUTH, NOAUTH"); do { Console.Write(">"); switch (Console.ReadLine().ToUpper()) { case "QUIT": done = true; break; case "AUTH": woopsaServer.Authenticator = new SimpleAuthenticator( "WoopsaDemoServer", (sender, e) => { e.IsAuthenticated = e.Username == "woopsa"; }); break; case "NOAUTH": woopsaServer.Authenticator = null; break; default: Console.WriteLine("Invalid command"); break; } } while (!done); } } catch (SocketException e) { // A SocketException is caused by an application already listening on a port in most cases // Applications known to use port 80: // - On Windows 10, IIS is on by default on some configurations. Disable it here: // http://stackoverflow.com/questions/30758894/apache-server-xampp-doesnt-run-on-windows-10-port-80 // - IIS // - Apache // - Nginx // - Skype Console.WriteLine("Error: Could not start Woopsa Server. Most likely because an application is already listening on port 80."); Console.WriteLine("Known culprits:"); Console.WriteLine(" - On Windows 10, IIS is on by default on some configurations."); Console.WriteLine(" - Skype"); Console.WriteLine(" - Apache, nginx, etc."); Console.WriteLine("SocketException: {0}", e.Message); Console.ReadLine(); } }
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 TestWoopsaDynamicNotificationUnexistingProperty() { TestObjectServer objectServer = new TestObjectServer(); using (WoopsaServer server = new WoopsaServer(objectServer)) { // Solution with dynamic client using (dynamic dynamicClient = new WoopsaDynamicClient("http://localhost/woopsa")) { int channel = dynamicClient.SubscriptionService.CreateSubscriptionChannel(QUEUE_SIZE); // Subscription for an nonexistent variable (should work) dynamicClient.SubscriptionService.RegisterSubscription(channel, WoopsaValue.WoopsaRelativeLink("/Vote"), TimeSpan.FromMilliseconds(MONITOR_INTERVAL), TimeSpan.FromMilliseconds(PUBLISH_INTERVAL)); Stopwatch watch = new Stopwatch(); WoopsaValue lastNotifications; WoopsaJsonData jsonData; int lastNotificationId; watch.Start(); do { lastNotifications = dynamicClient.SubscriptionService.WaitNotification(channel, 0); Assert.AreEqual(lastNotifications.Type, WoopsaValueType.JsonData); jsonData = lastNotifications.JsonData; if (watch.ElapsedMilliseconds > 1000) Assert.Fail("Timeout without receveiving any notification"); } while (jsonData.Length == 0); lastNotificationId = jsonData[jsonData.Length - 1]["Id"]; Assert.AreEqual(lastNotificationId, 1); // Get again the same notification lastNotifications = dynamicClient.SubscriptionService.WaitNotification(channel, 0); jsonData = lastNotifications.JsonData; Assert.IsTrue(jsonData.IsArray); Assert.AreEqual(jsonData.Length, 1); Assert.IsTrue(jsonData[0].IsDictionary); lastNotificationId = jsonData[jsonData.Length - 1]["Id"]; Assert.AreEqual(lastNotificationId, 1); } } }
public void TestWoopsaDynamicNotification() { TestObjectServer objectServer = new TestObjectServer(); using (WoopsaServer server = new WoopsaServer(objectServer)) { // Solution with dynamic client using (dynamic dynamicClient = new WoopsaDynamicClient("http://localhost/woopsa")) { int channel = dynamicClient.SubscriptionService.CreateSubscriptionChannel(QUEUE_SIZE); // Subscription for a valid variable dynamicClient.SubscriptionService.RegisterSubscription(channel, WoopsaValue.WoopsaRelativeLink("/Votes"), TimeSpan.FromMilliseconds(MONITOR_INTERVAL), TimeSpan.FromMilliseconds(PUBLISH_INTERVAL)); Stopwatch watch = new Stopwatch(); WoopsaValue lastNotifications; WoopsaJsonData jsonData; int lastNotificationId; watch.Start(); do { lastNotifications = dynamicClient.SubscriptionService.WaitNotification(channel, 0); Assert.AreEqual(lastNotifications.Type, WoopsaValueType.JsonData); jsonData = lastNotifications.JsonData; if (watch.ElapsedMilliseconds > 1000) Assert.Fail("Timeout without receveiving any notification"); } while (jsonData.Length == 0); lastNotificationId = jsonData[jsonData.Length - 1]["Id"]; Assert.AreEqual(lastNotificationId, 1); // Get again the same notification lastNotifications = dynamicClient.SubscriptionService.WaitNotification(channel, 0); jsonData = lastNotifications.JsonData; Assert.IsTrue(jsonData.IsArray); Assert.AreEqual(jsonData.Length, 1); Assert.IsTrue(jsonData[0].IsDictionary); lastNotificationId = jsonData[jsonData.Length - 1]["Id"]; Assert.AreEqual(lastNotificationId, 1); // Generate a new notification objectServer.Votes++; Thread.Sleep(PUBLISH_INTERVAL * 10); // Check we have now 2 lastNotifications = dynamicClient.SubscriptionService.WaitNotification(channel, 0); jsonData = lastNotifications.JsonData; Assert.IsTrue(jsonData.IsArray); Assert.AreEqual(jsonData.Length, 2); Assert.IsTrue(jsonData[0].IsDictionary); lastNotificationId = jsonData[jsonData.Length - 1]["Id"]; Assert.AreEqual(lastNotificationId, 2); // Check we can remove 1 and still have 1 lastNotifications = dynamicClient.SubscriptionService.WaitNotification(channel, 1); jsonData = lastNotifications.JsonData; Assert.AreEqual(jsonData.Length, 1); lastNotificationId = jsonData[jsonData.Length - 1]["Id"]; Assert.AreEqual(lastNotificationId, 2); // Enable the code below to test the wait of the timeout when they are 0 notifications pending /* // Check we can remove 1 and have 0. This takes 5 seconds (we wait the timeout) lastNotifications = dynamicClient.SubscriptionService.WaitNotification(channel, lastNotificationId); jsonData = lastNotifications.JsonData; Assert.AreEqual(jsonData.Length, 0); */ } } }
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 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 WoopsaSubscriptionService(WoopsaServer server, WoopsaContainer container) : base(container, WoopsaSubscriptionServiceConst.WoopsaServiceSubscriptionName) { _server = server; _subscriptionServiceImplementation = new WoopsaSubscriptionServiceImplementation(container, true); _subscriptionServiceImplementation.BeforeWoopsaModelAccess += (sender, e) => { server.ExecuteBeforeWoopsaModelAccess(); }; _subscriptionServiceImplementation.AfterWoopsaModelAccess += (sender, e) => { server.ExecuteAfterWoopsaModelAccess(); }; _subscriptionServiceImplementation.CanWatch += OnCanReconnectSubscriptionToNewObject; MethodCreateSubscriptionChannel = new WoopsaMethod( this, WoopsaSubscriptionServiceConst.WoopsaCreateSubscriptionChannel, WoopsaValueType.Integer, new WoopsaMethodArgumentInfo[] { new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaNotificationQueueSize, WoopsaValueType.Integer) }, arguments => _subscriptionServiceImplementation.CreateSubscriptionChannel(arguments[0].ToInt32()) ); MethodRegisterSubscription = new WoopsaMethod( this, WoopsaSubscriptionServiceConst.WoopsaRegisterSubscription, WoopsaValueType.Integer, new WoopsaMethodArgumentInfo[] { new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaSubscriptionChannel, WoopsaValueType.Integer), new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaPropertyLink, WoopsaValueType.WoopsaLink), new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaMonitorInterval, WoopsaValueType.TimeSpan), new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaPublishInterval, WoopsaValueType.TimeSpan) }, arguments => { return(_subscriptionServiceImplementation.RegisterSubscription( arguments[0].ToInt32(), arguments[1].DecodeWoopsaLocalLink(), arguments[2].ToTimeSpan(), arguments[3].ToTimeSpan())); }); MethodUnregisterSubscription = new WoopsaMethod( this, WoopsaSubscriptionServiceConst.WoopsaUnregisterSubscription, WoopsaValueType.Logical, new WoopsaMethodArgumentInfo[] { new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaSubscriptionChannel, WoopsaValueType.Integer), new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaSubscriptionId, WoopsaValueType.Integer) }, arguments => { return(_subscriptionServiceImplementation.UnregisterSubscription( arguments[0].ToInt32(), arguments[1].ToInt32())); }); MethodWaitNotification = new WoopsaMethod( this, WoopsaSubscriptionServiceConst.WoopsaWaitNotification, WoopsaValueType.JsonData, new WoopsaMethodArgumentInfo[] { new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaSubscriptionChannel, WoopsaValueType.Integer), new WoopsaMethodArgumentInfo(WoopsaSubscriptionServiceConst.WoopsaLastNotificationId, WoopsaValueType.Integer) }, arguments => { using (var accessFreeSection = _server.EnterModelAccessFreeSection()) return(new WoopsaValue(_subscriptionServiceImplementation.WaitNotification( arguments[0].ToInt32(), arguments[1].ToInt32()))); }); }
internal WoopsaServerModelAccessFreeSection(WoopsaServer server) { _server = server; server.ExecuteAfterWoopsaModelAccess(); }
public void ShutDown() { lock (plcParameterList) { _shouldStop = true; } // Thread to liberate de mainThread because another thread use Dispatcher.Invoke Thread joinWoopsaAdsThread = new Thread(() => JoinWoopsaAdsThread(_woopsaAdsThreadList)); joinWoopsaAdsThread.Name = "Join WoopsaAdsThread"; joinWoopsaAdsThread.Start(); isRunning = false; _woopsaServer.Dispose(); _woopsaServer = null; }
public void TestWoopsaServerPerformance() { TestObjectServer objectServer = new TestObjectServer(); using (WoopsaServer server = new WoopsaServer(objectServer)) { using (dynamic dynamicClient = new WoopsaDynamicClient("http://localhost/woopsa")) { Stopwatch watch = new Stopwatch(); watch.Start(); dynamicClient.Votes = 0; Console.WriteLine("First invocation duration : {0} ms", watch.Elapsed.TotalMilliseconds); int i = 0; watch.Restart(); while (watch.Elapsed < TimeSpan.FromSeconds(1)) { dynamicClient.Votes = i; Assert.AreEqual(objectServer.Votes, i); Assert.AreEqual((int)dynamicClient.Votes, i); i++; } Console.WriteLine("Invocation duration : {0} ms", watch.Elapsed.TotalMilliseconds / 2 / i); // TODO : Votes.Change does not work as Votes is a WoopsaValue does not contain Change !?! // dynamicClient.Votes.Change += new EventHandler<WoopsaNotificationEventArgs>((o, e) => Console.WriteLine("Value : {0}", e.Value.ToInt32())); // Thread.Sleep(100); // dynamicClient.Votes = 15; // WoopsaClient client = new WoopsaClient("http://localhost/woopsa"); // int votes = client.Properties.ByName("Votes").Value.ToInt32(); // client.Properties.ByName("Votes"); } } }