CreateBoundRoot() public method

public CreateBoundRoot ( string name = null ) : WoopsaBoundClientObject
name string
return WoopsaBoundClientObject
        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 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 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 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);
                        }
                    }
                }

            }
        }
Example #5
0
        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 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 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 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 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);
                }
            }
        }