private static void OnTimedEvent(Object source, ElapsedEventArgs e) { if (aTimer.Interval > 0) { string item = items[GetNumber()]; string payload = new JObject(new JProperty("value", counter.ToString()), new JProperty("halfed-times", (counter / 50).ToString()), new JProperty("type", "knx"), new JProperty("itemid", item)).ToString(); PlugLog.memoryLog.Add("RESULT-PUBLISHED, " + counter + ", " + DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() + ", " + item + ", " + aTimer.Interval); RequestUtils publishRequestUtils = new RequestUtils("netx_test.cfei.ba/sharptesting", RequestType.PUBLISH) .SetPrimaryAccessChain("nw0ChNe30YJBq4Q1LzI2TefzcfypV6-vYYOc_cUaaRc="); byte[] message = Encoding.UTF8.GetBytes(payload); byte[] text = { 64, 0, 0, 0 }; PayloadObject payloadObject = new PayloadObject(new PayloadType(text), message); publishRequestUtils.AddPayloadObject(payloadObject); Request publishRequest = publishRequestUtils.BuildPublisher(); bwClient.Publish(publishRequest, BWDefaults.DEFAULT_RESPONSEHANDLER(0)); if (counter > nextAddOn) { aTimer.Interval = aTimer.Interval - (aTimer.Interval / 4); nextAddOn += 50; } string item2 = items[GetNumber()]; host.WriteLog(nxaXIO.PlugKit.Logging.LogLevel.Warning, "published: " + counter + ", timer: " + aTimer.Interval + ", item: " + item); host.WriteLog(nxaXIO.PlugKit.Logging.LogLevel.Warning, "modified: " + -counter + ", timer: " + aTimer.Interval + ", item: " + item2); PlugLog.memoryLog.Add("ITEM-CHANGED, " + -counter + ", " + DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() + ", " + item2 + ", " + aTimer.Interval); host.GetItem(item2).ItemFacade.SetValue(new UpdateRequest(-counter, ItemChangeReason.IoReceived)); counter += 1; } else { PlugLog.LogWriter.Stop(); Thread.Sleep(1000); Environment.Exit(0); } }
public void Publish(string ns, string primaryAccessChain, string payload) { try { if (BossWavePlugin.Instance != null) { RequestUtils publishRequestUtils = new RequestUtils(ns, RequestType.PUBLISH) .SetPrimaryAccessChain(primaryAccessChain); byte[] message = Encoding.UTF8.GetBytes(payload); byte[] text = { 64, 0, 0, 0 }; PayloadObject payloadObject = new PayloadObject(new PayloadType(text), message); publishRequestUtils.AddPayloadObject(payloadObject); Request publishRequest = publishRequestUtils.BuildPublisher(); bwClient.Publish(publishRequest, new TempResponseHandler()); } } catch (Exception e) { BossWavePlugin.Instance.host.WriteLog(LogLevel.Error, e.Message + " " + e); } }
private static void test() { BossWaveClient bwClient = new BossWaveClient("localhost", BWDefaults.DEFAULT_PORT_NUMBER); bwClient.Connect(); bwClient.SetEntity("C:/Users/Emil S. Kolvig-Raun/stubbe.ent", BWDefaults.DEFAULT_RESPONSEHANDLER(1)); Request subscribeRequest = new RequestUtils("stubbe.demo.dk/sharptesting", RequestType.SUBSCRIBE) .SetExpiryDelta(3600000) .SetAutoChain(true) .BuildSubcriber(); bwClient.Subscribe(subscribeRequest, subscribeHandler, nsgHandler); semaphore.WaitOne(); RequestUtils publishRequestUtils = new RequestUtils("stubbe.demo.dk/sharptesting", RequestType.PUBLISH) .SetPrimaryAccessChain("klAVQ9UOajySAZZWzdU4IBrdyqs85JOk3TJhnpecFqg="); byte[] message = Encoding.UTF8.GetBytes("Rest is for the wicked."); byte[] text = { 64, 0, 0, 0 }; PayloadObject payload = new PayloadObject(new PayloadType(text), message); publishRequestUtils.AddPayloadObject(payload); Request publishRequest = publishRequestUtils.BuildPublisher(); bwClient.Publish(publishRequest, publishHandler); semaphore.WaitOne(); Printer.PrintResponse(RequestType.MAKE_ENTITY, BWDefaults.DEFAULT_RESPONSEHANDLER(1).result.status); Printer.PrintResponse(RequestType.SUBSCRIBE, subscribeHandler.result.status); Printer.PrintResponse(RequestType.PUBLISH, publishHandler.result.status); semaphore.WaitOne(); Printer.PrintMessage(nsgHandler.message); RequestUtils publishRequestUtils1 = new RequestUtils("stubbe.demo.dk/sharptesting", RequestType.PUBLISH) .SetPrimaryAccessChain("klAVQ9UOajySAZZWzdU4IBrdyqs85JOk3TJhnpecFqg="); string message1 = "Oh man, dawg! That sucks, cause I could really use some goddamn sleep right now. Ya' know, I have been awake for 43 hours? Oh man, dawg! That sucks, cause I could really use some goddamn sleep right now. Ya' know, I have been awake for 43 hours? Oh man, dawg! That sucks, cause I could really use some goddamn sleep right now. Ya' know, I have been awake for 43 hours?"; byte[] text1 = { 64, 0, 0, 0 }; publishRequestUtils1.AddPayloadObject(new PayloadObject(new PayloadType(text1), Encoding.UTF8.GetBytes(message1))); Request publishRequest1 = publishRequestUtils1.BuildPublisher(); bwClient.Publish(publishRequest1, publishHandler1); semaphore.WaitOne(); semaphore.WaitOne(); Printer.PrintMessage(nsgHandler.message); RequestUtils publishRequestUtils2 = new RequestUtils("stubbe.demo.dk/sharptesting", RequestType.PUBLISH) .SetPrimaryAccessChain("klAVQ9UOajySAZZWzdU4IBrdyqs85JOk3TJhnpecFqg="); byte[] message2 = Encoding.UTF8.GetBytes("You can sleep at 11PM!"); byte[] text2 = { 64, 0, 0, 0 }; PayloadObject payload2 = new PayloadObject(new PayloadType(text2), message2); publishRequestUtils2.AddPayloadObject(payload2); Request publishRequest2 = publishRequestUtils2.BuildPublisher(); bwClient.Publish(publishRequest2, publishHandler2); semaphore.WaitOne(); semaphore.WaitOne(); Printer.PrintMessage(nsgHandler.message); }