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 void OnConnectionStateChanged(Connection.CallbackConnectionState State) { if (State != Connection.CallbackConnectionState.Connected) { Console.WriteLine("Still waiting for being connected, new state: " + State.ToString()); return; } Console.WriteLine("Connected. Starting data source test."); DataHandler = new LWTSD.DataSource(Connection, false); // Some thermometers for (int i = 0; i < 3; i++) { LWTSD.ResourceTypes.ResourceInteger Point = new LWTSD.ResourceTypes.ResourceInteger(); Point.Path = "thermometers/temp" + i.ToString(); Point.Displayname = "Temperature " + i.ToString(); Point.Description = "A temperature"; Point.Unit = "Celcius"; Point.SupportsRead = true; Point.SupportsWrite = false; Point.Value = 20 + i; Point.MinExclusive = 3; DataHandler.AddResource(Point); } // Some writables for (int i = 0; i < 3; i++) { LWTSD.ResourceTypes.ResourceInteger Point = new LWTSD.ResourceTypes.ResourceInteger(); Point.Path = "writables/item" + i.ToString(); Point.Displayname = "Writable " + i.ToString(); Point.Description = "A writable thingy"; Point.Unit = "Unknown"; Point.SupportsRead = true; Point.SupportsWrite = true; Point.Value = i + 1; Point.MinExclusive = 0; Point.MaxExclusive = 10; DataHandler.AddResource(Point); } SourceStarted = true; }
public ExampleStorageEntity() { string CertPath = "../../../YOURCERTHERE.pfx"; var Cert = new System.Security.Cryptography.X509Certificates.X509Certificate2(CertPath); Uplink = new Connection("164.138.24.100", 5222, new JID("", "sandbox.clayster.com", ""), "", Cert, true, 30, 0); Uplink.Roster.OnSubscribe = Roster_OnSubscribe; Uplink.Roster.OnUnsubscribed = Roster_OnUnsubscribed; Uplink.OnConnectionStateChanged += Uplink_OnConnectionStateChanged; Uplink.Connect(); while (DataStorage == null) { Thread.Sleep(10); } // Set claim key string MyClaimKey = Cert.GetCertHashString(); var awaiter = DataStorage.SessionController.SetClaimKey(MyClaimKey); awaiter.Wait(); Console.WriteLine("Set claim key to {0} = {1}", awaiter.Result, MyClaimKey); CPUUsage = new LWTSD.ResourceTypes.ResourceInteger(); CPUUsage.Path = "meters/cpuusage"; CPUUsage.Displayname = "CPU%"; CPUUsage.SupportsRead = true; CPUUsage.SupportsWrite = false; CPUUsage.Unit = "percentage"; CPUUsage.Value = 0; AvailableMemory = new LWTSD.ResourceTypes.ResourceInteger(); AvailableMemory.Path = "meters/availablememory"; AvailableMemory.Displayname = "Available Memory"; AvailableMemory.SupportsRead = true; AvailableMemory.SupportsWrite = false; AvailableMemory.Unit = "MB"; AvailableMemory.Value = 0; ScratchPad = new LWTSD.ResourceTypes.ResourceString(); ScratchPad.Path = "misc/scratchpad"; ScratchPad.Displayname = "Scratchad"; ScratchPad.SupportsRead = true; ScratchPad.SupportsWrite = true; ScratchPad.Value = "Nothing"; DataStorage.AddResource(CPUUsage); DataStorage.AddResource(AvailableMemory); DataStorage.AddResource(ScratchPad); DataStorage.RegisterResources().Wait(); UpdateResourcesTimer = new System.Timers.Timer(1000.0); UpdateResourcesTimer.AutoReset = true; UpdateResourcesTimer.Elapsed += (sender, e) => { UpdateResources(); }; UpdateResourcesTimer.Start(); }