void DumpDataToConsole(LWTSD.DataController.DataPage Page) { foreach (var Resource in Page.Data) { LWTSD.ResourceTypes.ResourceInteger RInt = Resource as LWTSD.ResourceTypes.ResourceInteger; if (RInt != null) { Console.WriteLine("{0} = {1}", Resource.Path, RInt.Value); continue; } LWTSD.ResourceTypes.ResourceString RString = Resource as LWTSD.ResourceTypes.ResourceString; if (RString != null) { Console.WriteLine("{0} = {1}", Resource.Path, RString.Value); continue; } LWTSD.ResourceTypes.ResourceBoolean RBoolean = Resource as LWTSD.ResourceTypes.ResourceBoolean; if (RBoolean != null) { Console.WriteLine("{0} = {1}", Resource.Path, RBoolean.Value); continue; } LWTSD.ResourceTypes.ResourceDouble RDouble = Resource as LWTSD.ResourceTypes.ResourceDouble; if (RDouble != null) { Console.WriteLine("{0} = {1}", Resource.Path, RDouble.Value); continue; } } }
public RandomWriterTest() { Console.WriteLine("Connecting."); Connection = new Connection("baldershage-stefan.clayster.com", 5222, new JID("[email protected]/controllertest"), "test1234", null, true); Connection.OnConnectionStateChanged += OnConnectionStateChanged; Connection.Connect(); while (Client == null) { System.Threading.Thread.Sleep(100); } LWTSD.DataController.DataPage Page = new LWTSD.DataController.DataPage(); LWTSD.ResourceTypes.ResourceInteger Writable1 = new LWTSD.ResourceTypes.ResourceInteger(); Writable1.Path = "writables/item1"; Writable1.Value = 3; Page.Data.Add(Writable1); Console.WriteLine("Setting {0} to {1}", Writable1.Path, Writable1.Value); Console.WriteLine("Flushing data"); var WriteDataAwaiter = Client.WriteData(Page, "dummysession"); Console.WriteLine("Data flushed. Waiting for ack."); WriteDataAwaiter.Wait(); Console.WriteLine("Data written. Success: " + WriteDataAwaiter.Result.ToString()); if (WriteDataAwaiter.Result == false) { Console.WriteLine("Quiting because of error"); Quit = true; return; } WriterHasWritten = true; while (!Quit) { Thread.Sleep(100); } }
public ControllerTest() { Console.WriteLine("Connecting."); Connection = new Connection("baldershage-stefan.clayster.com", 5222, new JID("[email protected]/controllertest"), "test1234", null, true); Connection.OnConnectionStateChanged += OnConnectionStateChanged; Connection.Connect(); while (Client == null && !Quit) { System.Threading.Thread.Sleep(100); } Console.WriteLine("Requesting schema"); var SchemaWaiter = Client.GetSchema(0, "dummysession"); Console.WriteLine("Waiting for result"); SchemaWaiter.Wait(); Console.WriteLine("Got Schema"); LWTSD.SimplifiedSchema Schema = SchemaWaiter.Result; //Console.WriteLine(Schema.GetSerializedElement(0, 1000).ToString()); Console.WriteLine("Requesting data"); List <LWTSD.ResourcePath> ReadResources = new List <LWTSD.ResourcePath>(); foreach (var res in Schema.Resources.Values) { if (!res.SupportsRead) { continue; } Console.WriteLine("adding resource to get: " + res.Path); ReadResources.Add(res.Path); } var DataWaiter = Client.ReadData(Schema, ReadResources, "dummysession", 0); Console.WriteLine("Waiting for result"); DataWaiter.Wait(); Console.WriteLine("Got data."); LWTSD.DataController.DataPage Page = DataWaiter.Result; if (Page.Data == null) { throw new Exception("Data is null"); } DumpDataToConsole(Page); Console.WriteLine("Subscriping to data"); var SubscriptionAwaiter = Client.SubscribeToData(Schema, ReadResources, (Tuple <string, LWTSD.DataController.DataPage> obj) => { Console.WriteLine("Got new data on subscription " + obj.Item1); DumpDataToConsole(obj.Item2); GotSubscriptionData = true; }, (string obj) => { Console.WriteLine("Subscription cancelled with id {0}", obj); } , "dummysession"); Console.WriteLine("Waiting for subscription"); SubscriptionAwaiter.Wait(); Console.WriteLine("Got subscription: " + SubscriptionAwaiter.Result); RequestWrite = true; while (!GotSubscriptionData && !Quit) { Console.WriteLine("Waiting for subscriptiondata"); Thread.Sleep(100); } }