public Enums.ConfigDevicePostReturn GetDeviceHistoryPost(IAppCallbackAPI callback, int refId, string queryData) { var dataKeyPair = pluginConfig.DevicePersistenceData.FirstOrDefault(x => x.Value.DeviceRefId == refId); var data = dataKeyPair.Value; if (data != null) { NameValueCollection parts = HttpUtility.ParseQueryString(queryData ?? string.Empty); string id = parts["id"]; if (id == NameToIdWithPrefix(DoneButtonId)) { return(Enums.ConfigDevicePostReturn.DoneAndSave); } else { if (Enum.TryParse(parts[IFrameTypeId], true, out IFrameType frameType) && Enum.TryParse(parts[IFrameDurationId], true, out QueryDuration duration)) { Enum.TryParse(parts[IFrameGroupingId], true, out IFrameGrouping grouping); callback.ConfigDivToUpdateAdd(resultsDivPartId, GetQueryResultFrame(data, frameType, duration, grouping)); } } } return(Enums.ConfigDevicePostReturn.DoneAndCancelAndStay); }
public ConfigHandler(IHSApplication hs, IAppCallbackAPI callbackApi, IIniSettings iniSettings, ILog log) { _hs = hs; _callbackApi = callbackApi; _iniSettings = iniSettings; _log = log; }
public MainPlugin(IHSApplication hs, ILogging logging, IIniSettings iniSettings, IAppCallbackAPI callback, HsCollectionFactory collectionFactory) { _hs = hs; _logging = logging; _iniSettings = iniSettings; _callback = callback; _collectionFactory = collectionFactory; }
public MainConfig(ILogging logging, IHSApplication hs, IIniSettings iniSettings, IAppCallbackAPI callback, IMainPlugin mainPlugin) { _hs = hs; _logging = logging; _iniSettings = iniSettings; _callback = callback; _mainPlugin = mainPlugin; }
// private StringBuilder stb; public PageBuilderBase(IHSApplication pHS, IAppCallbackAPI pHSCB, HSPI_EnOcean.HSPI plugInInst) : base("dummy") { hsHost = pHS; hsHostCB = pHSCB; pluginInstance = plugInInst; reset(); }
public EnOceanController(IHSApplication pHsHost, IAppCallbackAPI pHsCB, HSPI pHspiInst, JObject initCfg) { hspiInst = pHspiInst; HS = pHsHost; HSCB = pHsCB; config = initCfg; portName = (string)config["portname"]; UniqueControllerId = (string)config["unique_id"]; }
public GeneralConfig(string pageName, IHSApplication hs, IAppCallbackAPI callback, IIniSettings iniSettings, ILog log) : base(pageName) { _pageName = pageName; _hs = hs; _callback = callback; _iniSettings = iniSettings; _log = log; }
public GetTriggersFromHomeSeerHandler(IIniSettings iniSettings, ILogging logging, IAppCallbackAPI callback, int?delayInSeconds = null) { _iniSettings = iniSettings; _logging = logging; _callback = callback; if (delayInSeconds.HasValue) { _delayInSeconds = delayInSeconds.Value; } }
public void Connect(string serverAddress, int serverPort) { // This method is called by our console wrapper at launch time // Create our main connection to the homeseer TCP communication framework // part 1 - hs object Proxy try { HsClient = ScsServiceClientBuilder.CreateClient <IHSApplication>(new ScsTcpEndPoint(serverAddress, serverPort), this); HsClient.Connect(); Hs = HsClient.ServiceProxy; // ReSharper disable once UnusedVariable var apiVersion = Hs.APIVersion; // just to make sure our connection is valid } catch (Exception ex) { throw new Exception("Error connecting homeseer SCS client: " + ex.Message, ex); } // part 2 - callback object Proxy try { CallbackClient = ScsServiceClientBuilder.CreateClient <IAppCallbackAPI>( new ScsTcpEndPoint(serverAddress, serverPort), this); CallbackClient.Connect(); Callback = CallbackClient.ServiceProxy; // ReSharper disable once UnusedVariable var apiVersion = Callback.APIVersion; // just to make sure our connection is valid } catch (Exception ex) { throw new Exception("Error connecting callback SCS client: " + ex.Message, ex); } // Establish the reverse connection from homeseer back to our plugin try { Hs.Connect(Name, InstanceFriendlyName()); } catch (Exception ex) { throw new Exception("Error connecting homeseer to our plugin: " + ex.Message, ex); } }
public TriggerHandler(IHSApplication hs, IAppCallbackAPI callback, IIniSettings iniSettings, ILogging logging, IHsCollectionFactory collectionFactory, IHomeSeerHandler homeSeerHandler, IStorageHandler storageHandler) { _hs = hs; _callback = callback; _iniSettings = iniSettings; _logging = logging; _collectionFactory = collectionFactory; _homeSeerHandler = homeSeerHandler; _storageHandler = storageHandler; _logging.LogDebug("Creating trigger types"); _triggerTypes = CreateTriggerTypes(); _logging.LogDebug("Starting thread to fetch triggers"); GetPluginTriggersFromHomeSeerInNewThread(); _logging.LogDebug("Done init TriggerHandler"); }
public PageBuilder(IHSApplication pHS, IAppCallbackAPI pHSCB, HSPI_EnOcean.HSPI pluginInstance, EnOceanManager pCore) : base(pHS, pHSCB, pluginInstance) { mCore = pCore; HS = pHS; }
public static void Main(string[] args) { string serverIp = "127.0.0.1"; string serverCmd = null; foreach (string serverCmd_loopVariable in args) { serverCmd = serverCmd_loopVariable; string[] ch = new string[1]; ch[0] = "="; string[] parts = serverCmd.Split(ch, StringSplitOptions.None); switch (parts[0].ToLower()) { case "server": serverIp = parts[1]; break; case "instance": try { Util.Instance = parts[1]; } catch (Exception) { Util.Instance = ""; } break; } } Reconnect: Console.WriteLine("Plugin: " + Util.IFACE_NAME + " Instance: " + Util.Instance + " starting..."); Console.WriteLine("Connecting to server at " + serverIp + "..."); client = ScsServiceClientBuilder.CreateClient <IHSApplication>(new ScsTcpEndPoint(serverIp, 10400), plugin); clientCallback = ScsServiceClientBuilder.CreateClient <IAppCallbackAPI>(new ScsTcpEndPoint(serverIp, 10400), plugin); int Attempts = 1; TryAgain: try { client.Connect(); clientCallback.Connect(); double APIVersion = 0; try { host = client.ServiceProxy; APIVersion = host.APIVersion; // will cause an error if not really connected Console.WriteLine("Host API Version: " + APIVersion.ToString()); } catch (Exception ex) { Console.WriteLine("Error getting API version from host object: " + ex.Message + "->" + ex.StackTrace); //Return } try { callback = clientCallback.ServiceProxy; APIVersion = callback.APIVersion; // will cause an error if not really connected } catch (Exception ex) { Console.WriteLine("Error getting API version from callback object: " + ex.Message + "->" + ex.StackTrace); return; } } catch (Exception ex) { Console.WriteLine("Cannot connect attempt " + Attempts.ToString() + ": " + ex.Message); if (ex.Message.ToLower().Contains("timeout occurred.")) { Attempts += 1; if (Attempts < 6) { goto TryAgain; } } if (client != null) { client.Dispose(); client = null; } if (clientCallback != null) { clientCallback.Dispose(); clientCallback = null; } wait(4); return; } try { connectionJunction(); if (reset) { HSPI.armReset(); goto Reconnect; } else { System.Environment.Exit(0); } } catch (Exception ex) { Console.WriteLine("Cannot connect(2): " + ex.Message); wait(2); System.Environment.Exit(0); return; } }
public EnOceanManager(IHSApplication pHsHost, IAppCallbackAPI pHsCB, HSPI pHspiInst) { hspiInst = pHspiInst; HS = pHsHost; HSCB = pHsCB; }
public void run() { string[] cmdArgs = Environment.GetCommandLineArgs(); Console.WriteLine("Manager::run() - arguments are {0}", Environment.CommandLine); String paramServer = "127.0.0.1"; String paramInstance = ""; foreach (string arg in cmdArgs) { Console.WriteLine(" - arg: {0}", arg); if (arg.Contains("=")) { String[] ArgS = arg.Split('='); Console.WriteLine(" -- {0}=>{1}", ArgS[0], ArgS[1]); switch (ArgS[0]) { case "server": paramServer = ArgS[1]; break; case "instance": paramInstance = ArgS[1]; break; default: Console.WriteLine("Unhandled param: {0}", ArgS[0]); break; } } } pluginInst = new HSPI(paramInstance); //Environment.CommandLine. client = ScsServiceClientBuilder.CreateClient <IHSApplication>(new ScsTcpEndPoint(paramServer, 10400), pluginInst); clientCB = ScsServiceClientBuilder.CreateClient <IAppCallbackAPI>(new ScsTcpEndPoint(paramServer, 10400), pluginInst); try { client.Connect(); clientCB.Connect(); hsHost = client.ServiceProxy; double ApiVer = hsHost.APIVersion; Console.WriteLine("Host ApiVersion : {0}", ApiVer); hsHostCB = clientCB.ServiceProxy; ApiVer = hsHostCB.APIVersion; Console.WriteLine("Host CB ApiVersion : {0}", ApiVer); } catch (Exception e) { Console.WriteLine("Cannot start instance because of : {0}", e.Message); return; } Console.WriteLine("Connection to HS succeeded!"); try { pluginInst.hsHost = hsHost; pluginInst.hsHostCB = hsHostCB; hsHost.Connect(pluginInst.Name, ""); Console.WriteLine("Connected, waiting to be initialized..."); do { Thread.Sleep(500); } while (client.CommunicationState == CommunicationStates.Connected && pluginInst.Running); Console.WriteLine("Connection lost, exiting"); pluginInst.Running = false; client.Disconnect(); clientCB.Disconnect(); } catch (Exception e) { Console.WriteLine("Failed to host connect: {0}", e.Message); return; } Console.WriteLine("Exiting!!!"); }
public static ITrigger Get(IHSApplication hs, string triggerType, ILogging logging, ITriggerHandler triggerHandler, IAppCallbackAPI callback, IHsCollectionFactory collectionFactory, IHomeSeerHandler homeSeerHandler) { switch (triggerType) { case "DataCurveSeer.TriggerHandling.Triggers.DataCurveTrigger": return(new DataCurveTrigger(hs, logging, collectionFactory, homeSeerHandler)); case "DataCurveSeer.TriggerHandling.Triggers.DataCurveTriggerB.DataCurveTriggerB": return(new DataCurveTrigger(hs, logging, collectionFactory, homeSeerHandler)); default: logging.Log($"Could not find any match for {triggerType}. Alert the creator and tell him to check for errors."); break; } return(null); }
public void SetUp() { _iniSettings = NSubstitute.Substitute.For <IIniSettings>(); _logging = NSubstitute.Substitute.For <ILogging>(); _callBack = NSubstitute.Substitute.For <IAppCallbackAPI>(); }
public void run() { string[] cmdArgs = Environment.GetCommandLineArgs(); Console.WriteLine("Manager::run() - arguments are {0}", Environment.CommandLine); String paramServer = "127.0.0.1"; String paramInstance = ""; foreach (string arg in cmdArgs) { Console.WriteLine(" - arg: {0}", arg); if (arg.Contains("=")) { String[] ArgS = arg.Split('='); Console.WriteLine(" -- {0}=>{1}", ArgS[0], ArgS[1]); switch (ArgS[0]) { case "server": paramServer = ArgS[1]; break; case "instance": paramInstance = ArgS[1]; break; default: Console.WriteLine("Unhandled param: {0}", ArgS[0]); break; } } } pluginInst = new HSPI(paramInstance); //Environment.CommandLine. client = ScsServiceClientBuilder.CreateClient<IHSApplication>(new ScsTcpEndPoint(paramServer, 10400), pluginInst); clientCB = ScsServiceClientBuilder.CreateClient<IAppCallbackAPI>(new ScsTcpEndPoint(paramServer, 10400), pluginInst); try { client.Connect(); clientCB.Connect(); hsHost = client.ServiceProxy; double ApiVer = hsHost.APIVersion; Console.WriteLine("Host ApiVersion : {0}", ApiVer); hsHostCB = clientCB.ServiceProxy; ApiVer = hsHostCB.APIVersion; Console.WriteLine("Host CB ApiVersion : {0}", ApiVer); } catch (Exception e) { Console.WriteLine("Cannot start instance because of : {0}", e.Message); return; } Console.WriteLine("Connection to HS succeeded!"); try { pluginInst.hsHost = hsHost; pluginInst.hsHostCB = hsHostCB; hsHost.Connect(pluginInst.Name, ""); Console.WriteLine("Connected, waiting to be initialized..."); do { Thread.Sleep(500); } while (client.CommunicationState == CommunicationStates.Connected && pluginInst.Running); Console.WriteLine("Connection lost, exiting"); pluginInst.Running = false; client.Disconnect(); clientCB.Disconnect(); } catch (Exception e) { Console.WriteLine("Failed to host connect: {0}", e.Message); return; } Console.WriteLine("Exiting!!!"); }
public static void Main(string[] args) { string serverIp = "127.0.0.1"; string serverCmd = null; foreach (string serverCmd_loopVariable in args) { serverCmd = serverCmd_loopVariable; string[] ch = new string[1]; ch[0] = "="; string[] parts = serverCmd.Split(ch, StringSplitOptions.None); switch (parts[0].ToLower()) { case "server": serverIp = parts[1]; break; case "instance": try { Util.Instance = parts[1]; } catch (Exception) { Util.Instance = ""; } break; } } Console.WriteLine("Plugin: " + Util.IFACE_NAME + " Instance: " + Util.Instance + " starting..."); Console.WriteLine("Connecting to server at " + serverIp + "..."); client = ScsServiceClientBuilder.CreateClient <IHSApplication>(new ScsTcpEndPoint(serverIp, 10400), plugin); clientCallback = ScsServiceClientBuilder.CreateClient <IAppCallbackAPI>(new ScsTcpEndPoint(serverIp, 10400), plugin); int Attempts = 1; TryAgain: try { client.Connect(); clientCallback.Connect(); double APIVersion = 0; try { host = client.ServiceProxy; APIVersion = host.APIVersion; // will cause an error if not really connected Console.WriteLine("Host API Version: " + APIVersion.ToString()); } catch (Exception ex) { Console.WriteLine("Error getting API version from host object: " + ex.Message + "->" + ex.StackTrace); //Return } try { callback = clientCallback.ServiceProxy; APIVersion = callback.APIVersion; // will cause an error if not really connected } catch (Exception ex) { Console.WriteLine("Error getting API version from callback object: " + ex.Message + "->" + ex.StackTrace); return; } } catch (Exception ex) { Console.WriteLine("Cannot connect attempt " + Attempts.ToString() + ": " + ex.Message); if (ex.Message.ToLower().Contains("timeout occurred.")) { Attempts += 1; if (Attempts < 6) { goto TryAgain; } } if (client != null) { client.Dispose(); client = null; } if (clientCallback != null) { clientCallback.Dispose(); clientCallback = null; } wait(4); return; } try { // create the user object that is the real plugin, accessed from the pluginAPI wrapper Util.callback = callback; Util.hs = host; plugin.OurInstanceFriendlyName = Util.Instance; // connect to HS so it can register a callback to us host.Connect(Util.IFACE_NAME, Util.Instance); Console.WriteLine("Connected, waiting to be initialized..."); do { System.Threading.Thread.Sleep(10); } while (client.CommunicationState == HSCF.Communication.Scs.Communication.CommunicationStates.Connected & !HSPI.bShutDown); Console.WriteLine("Connection lost, exiting"); // disconnect from server for good here client.Disconnect(); clientCallback.Disconnect(); wait(2); System.Environment.Exit(0); } catch (Exception ex) { Console.WriteLine("Cannot connect(2): " + ex.Message); wait(2); System.Environment.Exit(0); return; } }