/// <summary>
        /// Public Constructor for WindowsService.
        /// - Put all of your Initialization code here.
        /// </summary>
        public OSAEService()
        {
            serviceObject = CheckServiceObject();
            if (serviceObject == null)
            {
                Log = new General.OSAELog("Faulted Service");
                Log.Fatal("Failed to retrieve Service's Object!");
            }
            //else
            //   OSAE.OSAEObjectStateManager.ObjectStateSet(serviceObject, "ON", serviceObject);

            Log = new General.OSAELog(serviceObject);
            Log.Info("Service Starting");

            Common.CheckComputerObject(serviceObject);
            OSAEObject obj = OSAEObjectManager.GetObjectByName(serviceObject);

            OSAEObjectManager.ObjectUpdate(serviceObject, serviceObject, obj.Address, obj.Description, obj.Type, obj.Address, Common.ComputerName, obj.MinTrustLevel, obj.Enabled);

            InitialiseOSAInEventLog();

            // These Flags set whether or not to handle that specific type of event. Set to true if you need it, false otherwise.

            CanStop     = true;
            CanShutdown = true;
        }
Beispiel #2
0
        public VideoStreamViewer(string url, OSAEObject obj, string appName)
        {
            InitializeComponent();
            Log                = new General.OSAELog(appName);
            screenObject       = obj;
            _mjpeg             = new MjpegDecoder();
            _mjpeg.FrameReady += mjpeg_FrameReady;
            _mjpeg.Error      += _mjpeg_Error;
            imgWidth           = Convert.ToDouble(OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Property("Object Name").Value, "Width").Value);
            imgHeight          = Convert.ToDouble(OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Property("Object Name").Value, "Height").Value);
            ControlWidth       = Convert.ToDouble(OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Name, "Width").Value);
            imgRatio           = ControlWidth / imgWidth;
            ControlHeight      = Convert.ToDouble(imgHeight * imgRatio);
            streamURI          = OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Property("Object Name").Value, "Stream Address").Value;
            //  if (imgWidth > 0) { imgWidth = imgWidth); }
            // if (imgHeight > 0) { imgHeight = Convert.ToDouble(imgHeight); }
            this.Width  = ControlWidth;
            this.Height = ControlHeight;

            image.Width  = ControlWidth;
            image.Height = ControlHeight;
            if (streamURI == null)
            {
                Log.Error("Stream Path Not Found: " + streamURI);
                message.Content = "Can Not Open: " + streamURI;
            }
            else
            {
                streamURI = renameingSys(streamURI);
                Log.Info("Streaming: " + streamURI);
                _mjpeg.ParseStream(new Uri(streamURI));
            }
        }
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log   = new General.OSAELog(pName);

            _oAuth.OAuthToken     = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Auth Token").Value;
            _oAuth.PIN            = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Pin").Value;
            _oAuth.Token          = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Token").Value;
            _oAuth.TokenSecret    = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Token Secret").Value;
            _oAuth.ConsumerKey    = "g3QfE1xOc3AQQnvRaRqzQ";
            _oAuth.ConsumerSecret = "yYj3J2u3CtXwwmn98m4VBFUdYDopduv4NOSn6E1aQ";

            try
            {
                if (_oAuth.Token != "" && _oAuth.TokenSecret != "" && _oAuth.PIN != "" && _oAuth.OAuthToken != "")
                {
                    //We are already authenticated
                    Log.Info("Acount authenticated.  Ready for tweeting");
                }
                else
                {
                    // Each Twitter application has an authorization page where the user can specify
                    // 'yes, allow this application' or 'no, deny this application'. The following
                    // call obtains the URL to that page. Authorization link will look something like this:
                    // http://twitter.com/oauth/authorize?oauth_token=c8GZ6vCDdgKO4gTx0ZZXzvjZ76auuvlD1hxoLeiWc
                    string authLink = _oAuth.AuthorizationLinkGet();
                    Log.Info("Here is the Twitter Authorization Link.  Copy and paste into your browser to authorize OSA to use your twitter account.  \nCopy the PIN you are given and put it into the PIN property for the Twitter plugin object and then execute the Authorize method: \n" + authLink);
                }
            }
            catch (Exception ex)
            { Log.Error("Error running interface", ex); }
        }
        public VideoStreamViewer(string url, OSAEObject obj, string appName)
        {
            InitializeComponent();
            Log = new General.OSAELog(appName);
            screenObject = obj;
            _mjpeg = new MjpegDecoder();
            _mjpeg.FrameReady += mjpeg_FrameReady;
            _mjpeg.Error += _mjpeg_Error;
            imgWidth = Convert.ToDouble(OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Property("Object Name").Value, "Width").Value);
            imgHeight = Convert.ToDouble(OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Property("Object Name").Value, "Height").Value);
            ControlWidth = Convert.ToDouble(OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Name, "Width").Value);
            imgRatio = ControlWidth / imgWidth;
            ControlHeight = Convert.ToDouble(imgHeight * imgRatio);
            streamURI = OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Property("Object Name").Value, "Stream Address").Value;
              //  if (imgWidth > 0) { imgWidth = imgWidth); }
               // if (imgHeight > 0) { imgHeight = Convert.ToDouble(imgHeight); }
            this.Width = ControlWidth;
            this.Height = ControlHeight;

            image.Width = ControlWidth;
            image.Height = ControlHeight;
            if (streamURI == null)
            {
                Log.Error("Stream Path Not Found: " + streamURI);
                message.Content = "Can Not Open: " + streamURI;
            }
            else
            {
                streamURI = renameingSys(streamURI);
                Log.Info("Streaming: " + streamURI);
                _mjpeg.ParseStream(new Uri(streamURI));
            }
        }
        public override void RunInterface(string pluginName)
        {
            gAppName = pluginName;
            Log = new General.OSAELog(gAppName);
            Log.Info("*** Running Interface! ***");
            OwnTypes();

            try
            {
                gDebug = Convert.ToBoolean(OSAEObjectPropertyManager.GetObjectPropertyValue(gAppName, "Debug").Value);
            }
            catch
            { Log.Error("I think the Debug property is missing from the Speech object type!"); }

            Log.Info("Debug Mode Set to " + gDebug);

            int iScanInterval = int.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(gAppName, "Scan Interval").Value);
            Log.Info("Scan Interval Set to " + iScanInterval);

            Clock = new System.Timers.Timer();
            Clock.Interval = iScanInterval * 1000;
            Clock.Start();
            Clock.Elapsed += new ElapsedEventHandler(Timer_Tick);

            search_thread = new Thread(new ThreadStart(search));
            search_thread.Start();
            Log.Info("Bluetooth Plugin is now scanning for devices.");
        }
        public override void RunInterface(string pluginName)
        {
            gAppName = pluginName;
            Log = new General.OSAELog(gAppName);
            OwnTypes();

            try
            {
                gDebug = Convert.ToBoolean(OSAEObjectPropertyManager.GetObjectPropertyValue(gAppName, "Debug").Value);
            }
            catch
            { Log.Error("I think the Debug property is missing from the Speech object type!"); }

            Log.Info("Running Interface!");
            int interval;
            bool isNum = int.TryParse(OSAEObjectPropertyManager.GetObjectPropertyValue(gAppName, "Poll Interval").Value, out interval);
            Clock = new System.Timers.Timer();
            if(isNum)
                Clock.Interval = interval * 1000;
            else
                Clock.Interval = 30000;

            Clock.Start();
            Clock.Elapsed += new ElapsedEventHandler(Timer_Tick);

            updateThread = new Thread(new ThreadStart(update));
            updateThread.Start();
        }
        /// <summary>
        /// Searches the passed Path for Plugins
        /// </summary>
        /// <param name="Path">Directory to search for Plugins in</param>
        public void FindPlugins(string Path)
        {
            Log2 = new OSAE.General.OSAELog("Plugins");
            try {
                //First empty the collection, we're reloading them all
                colAvailablePlugins.Clear();

                //Go through all the files in the plugin directory
                foreach (var fileOn in Directory.GetFiles(Path, "*.dll", SearchOption.AllDirectories))
                {
                    FileInfo file = new FileInfo(fileOn);

                    //Preliminary check, must be .dll
                    if (file.Extension.Equals(".dll"))
                    {
                        //Add the 'plugin'
                        AddPlugin(fileOn);
                    }
                }
            }
            catch (Exception ex)
            {
                Log2.Error("Find Plugins Error!", ex);
            }
        }
Beispiel #8
0
        public override void RunInterface(string pluginName)
        {
            gAppName = pluginName;
            Log      = new General.OSAELog(gAppName);
            OwnTypes();

            try
            {
                gDebug = Convert.ToBoolean(OSAEObjectPropertyManager.GetObjectPropertyValue(gAppName, "Debug").Value);
            }
            catch
            { Log.Error("I think the Debug property is missing from the Speech object type!"); }

            Log.Info("Running Interface!");
            int  interval;
            bool isNum = int.TryParse(OSAEObjectPropertyManager.GetObjectPropertyValue(gAppName, "Poll Interval").Value, out interval);

            Clock = new System.Timers.Timer();
            if (isNum)
            {
                Clock.Interval = interval * 1000;
            }
            else
            {
                Clock.Interval = 30000;
            }

            Clock.Start();
            Clock.Elapsed += new ElapsedEventHandler(Timer_Tick);

            updateThread = new Thread(new ThreadStart(update));
            updateThread.Start();
        }
        public ClientService()
        {
            serviceObject = "SERVICE-" + Common.ComputerName;
            Log = new OSAE.General.OSAELog(serviceObject);
            bool found = OSAEObjectManager.ObjectExists(serviceObject);
            if (!found)
                OSAEObjectManager.ObjectAdd(serviceObject, "", "SERVICE", "SERVICE", "", Common.ComputerName, 50, true);
            else
            {
                OSAEObject obj = OSAEObjectManager.GetObjectByName(serviceObject);
                OSAEObjectManager.ObjectUpdate(serviceObject, serviceObject, "", obj.Description, obj.Type, "", Common.ComputerName, obj.MinTrustLevel, obj.Enabled);
            }

            OSAE.OSAEObjectStateManager.ObjectStateSet(serviceObject, "ON", serviceObject);
          
            Log.Info("ClientService Starting");

            try
            {
                if (!EventLog.SourceExists("OSAEClient"))
                    EventLog.CreateEventSource("OSAEClient", "Application");
            }
            catch (Exception ex)
            { Log.Error("CreateEventSource error", ex); }
            ServiceName = "OSAEClient";
            EventLog.Source = "OSAEClient";
            EventLog.Log = "Application";

            // These Flags set whether or not to handle that specific
            //  type of event. Set to true if you need it, false otherwise.
            CanStop = true;
        }
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log = new General.OSAELog(pName);

            _oAuth.OAuthToken = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Auth Token").Value;
            _oAuth.PIN = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Pin").Value;
            _oAuth.Token = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Token").Value;
            _oAuth.TokenSecret = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Token Secret").Value;
            _oAuth.ConsumerKey = "g3QfE1xOc3AQQnvRaRqzQ";
            _oAuth.ConsumerSecret = "yYj3J2u3CtXwwmn98m4VBFUdYDopduv4NOSn6E1aQ";

            try
            {
                if (_oAuth.Token != "" && _oAuth.TokenSecret != "" && _oAuth.PIN != "" && _oAuth.OAuthToken != "")
                {
                    //We are already authenticated
                    Log.Info("Acount authenticated.  Ready for tweeting");
                }
                else
                {
                    // Each Twitter application has an authorization page where the user can specify
                    // 'yes, allow this application' or 'no, deny this application'. The following
                    // call obtains the URL to that page. Authorization link will look something like this:
                    // http://twitter.com/oauth/authorize?oauth_token=c8GZ6vCDdgKO4gTx0ZZXzvjZ76auuvlD1hxoLeiWc
                    string authLink = _oAuth.AuthorizationLinkGet();
                    Log.Info("Here is the Twitter Authorization Link.  Copy and paste into your browser to authorize OSA to use your twitter account.  \nCopy the PIN you are given and put it into the PIN property for the Twitter plugin object and then execute the Authorize method: \n" + authLink);
                }
            }
            catch(Exception ex)
            { Log.Error("Error running interface", ex); }
        }
Beispiel #11
0
        public ClientService()
        {
            Log = new OSAE.General.OSAELog();

            this.Log.Info("ClientService Starting");

            try
            {
                if (!EventLog.SourceExists("OSAEClient"))
                {
                    EventLog.CreateEventSource("OSAEClient", "Application");
                }
            }
            catch (Exception ex)
            {
                this.Log.Error("CreateEventSource error", ex);
            }
            this.ServiceName     = "OSAEClient";
            this.EventLog.Source = "OSAEClient";
            this.EventLog.Log    = "Application";

            // These Flags set whether or not to handle that specific
            //  type of event. Set to true if you need it, false otherwise.

            this.CanStop = true;
        }
        /// <summary>
        /// Public Constructor for WindowsService.
        /// - Put all of your Initialization code here.
        /// </summary>
        public OSAEService()
        {
            serviceObject = CheckServiceObject();
            if (serviceObject == null)
            {
                Log = new General.OSAELog("Faulted Service");
                Log.Fatal("Failed to retrieve Service's Object!");
            }
            //else
             //   OSAE.OSAEObjectStateManager.ObjectStateSet(serviceObject, "ON", serviceObject);

            Log = new General.OSAELog(serviceObject);
            Log.Info("Service Starting");

            Common.CheckComputerObject(serviceObject);
            OSAEObject obj = OSAEObjectManager.GetObjectByName(serviceObject);
            OSAEObjectManager.ObjectUpdate(serviceObject, serviceObject, obj.Address, obj.Description, obj.Type, obj.Address, Common.ComputerName, obj.MinTrustLevel, obj.Enabled);

            InitialiseOSAInEventLog();

            // These Flags set whether or not to handle that specific type of event. Set to true if you need it, false otherwise.

            CanStop = true;
            CanShutdown = true;
        }
Beispiel #13
0
        public override void RunInterface(string pluginName)
        {
            gAppName = pluginName;
            Log      = new General.OSAELog(gAppName);
            Log.Info("*** Running Interface! ***");
            OwnTypes();

            try
            {
                gDebug = Convert.ToBoolean(OSAEObjectPropertyManager.GetObjectPropertyValue(gAppName, "Debug").Value);
            }
            catch
            { Log.Error("I think the Debug property is missing from the Speech object type!"); }

            Log.Info("Debug Mode Set to " + gDebug);

            int iScanInterval = int.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(gAppName, "Scan Interval").Value);

            Log.Info("Scan Interval Set to " + iScanInterval);

            Clock          = new System.Timers.Timer();
            Clock.Interval = iScanInterval * 1000;
            Clock.Start();
            Clock.Elapsed += new ElapsedEventHandler(Timer_Tick);

            search_thread = new Thread(new ThreadStart(search));
            search_thread.Start();
            Log.Info("Bluetooth Plugin is now scanning for devices.");
        }
Beispiel #14
0
 public override void RunInterface(string pluginName)
 {
     pName = pluginName;
     Log   = new OSAE.General.OSAELog(pName);
     Log.Info(pluginName + " is starting...");
     Log.Info("===================================================");
     OwnTypes();
 }
Beispiel #15
0
 public override void RunInterface(string pluginName)
 {
     gAppName = pluginName;
     Log      = new General.OSAELog(gAppName);
     OwnTypes();
     Load_Settings();
     SubscribePubNubMessages();
 }
 public override void RunInterface(string pluginName)
 {
     gAppName = pluginName;
     Log = new General.OSAELog(gAppName);
     OwnTypes();
     Load_Settings();
     SubscribePubNubMessages();
 }
Beispiel #17
0
        public override void RunInterface(string pluginName)
        {
            gAppName = pluginName;
            Log      = new General.OSAELog(gAppName);

            Log.Info("Email Plugin is Starting...");

            OwnTypes();
        }
Beispiel #18
0
 public override void RunInterface(string pluginName)
 {
     gAppName = pluginName;
     Log      = new General.OSAELog(gAppName);
     OwnTypes();
     Load_Settings();
     OSAEObjectPropertyManager.ObjectPropertySet(gAppName, "Speaking", "TRUE", gAppName);
     oSpeech.Speak("speech client started");
     OSAEObjectPropertyManager.ObjectPropertySet(gAppName, "Speaking", "FALSE", gAppName);
 }
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log = new General.OSAELog(pName);

            OSAEObjectType objt = OSAEObjectTypeManager.ObjectTypeLoad("KILLAWATT MODULE");
            OSAEObjectTypeManager.ObjectTypeUpdate(objt.Name, objt.Name, objt.Description, pName, "THING", objt.Owner, objt.SysType, objt.Container, objt.HideRedundant);

            xb = new xbee(Int32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Port").Value));
            xb.xbeePacketReceived += new xbee.xbeePacketReceivedEventHandler(xb_xbeePacketReceived);
        }
Beispiel #20
0
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log   = new General.OSAELog(pName);
            Log.Info("Running Interface!");

            OSAEObjectType objt = OSAEObjectTypeManager.ObjectTypeLoad("RADIO THERMOSTAT DEVICE");

            OSAEObjectTypeManager.ObjectTypeUpdate(objt.Name, objt.Name, "Radio Thermostat Device", pName, "RADIO THERMOSTAT DEVICE", objt.Owner, objt.SysType, objt.Container, objt.HideRedundant);
            OSAEObjectCollection devices = OSAEObjectManager.GetObjectsByType("RADIO THERMOSTAT DEVICE");

            foreach (OSAEObject obj in devices)
            {
                ThermostatLib.SystemInfo si = ThermostatLib.SystemInfo.Load(obj.Address);
                Log.Info("---------------------------------");
                Log.Info("Device Name: " + ThermostatLib.SystemInfo.LoadSystemName(obj.Address));
                Log.Info("API Version: " + si.ApiVersion.ToString());
                Log.Info("Firmware Version: " + si.FirmwareVersion);
                Log.Info("UUID: " + si.UUID);
                Log.Info("WLAN Version: " + si.WlanFirmwareVersion);
                Log.Info("Model: " + ThermostatLib.SystemInfo.LoadModelName(obj.Address));
                Log.Info("Operating Mode: " + ThermostatLib.SystemInfo.LoadOperatingMode(obj.Address));

                ThermostatLib.Services services = ThermostatLib.Services.Load(obj.Address);
                string service = "";
                foreach (ThermostatLib.HttpdHandler handler in services.Handlers)
                {
                    service  = "";
                    service += handler.Url + " (";
                    if (handler.AllowsGet && handler.AllowsPost)
                    {
                        service += "GET, POST";
                    }
                    else
                    {
                        if (handler.AllowsGet)
                        {
                            service += "GET";
                        }
                        if (handler.AllowsPost)
                        {
                            service += "POST";
                        }
                    }
                    service += ")";
                    Log.Info("Service: " + service);
                }
            }
            Clock          = new System.Timers.Timer();
            Clock.Interval = Int32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Poll Interval").Value) * 60000;
            Clock.Start();
            Clock.Elapsed += new ElapsedEventHandler(Timer_Tick);
        }
Beispiel #21
0
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log   = new General.OSAELog(pName);

            OSAEObjectType objt = OSAEObjectTypeManager.ObjectTypeLoad("KILLAWATT MODULE");

            OSAEObjectTypeManager.ObjectTypeUpdate(objt.Name, objt.Name, objt.Description, pName, "THING", objt.Owner, objt.SysType, objt.Container, objt.HideRedundant, objt.Tooltip);

            xb = new xbee(Int32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Port").Value));
            xb.xbeePacketReceived += new xbee.xbeePacketReceivedEventHandler(xb_xbeePacketReceived);
        }
Beispiel #22
0
        /// <summary>
        /// OSA Plugin Interface - called on start up to allow plugin to do any tasks it needs
        /// </summary>
        /// <param name="pluginName">The name of the plugin from the system</param>
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log   = new General.OSAELog(pName);
            OwnTypes();
            try
            {
                this.Log.Info("Starting Rest Interface");

                bool showHelp = bool.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Show Help").Value);
                int  restPort = 8732;

                if (!OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "REST Port").Id.Equals(String.Empty))
                {
                    try
                    {
                        restPort = int.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "REST Port").Value);
                        Log.Info("Rest Port read in as: " + restPort);
                    }
                    catch (FormatException ex)
                    { Log.Error("Error pulling REST port from property (not a valid number)", ex); }
                    catch (OverflowException ex)
                    { Log.Error("Error pulling REST port from property (too large)", ex); }
                    catch (ArgumentNullException ex)
                    { Log.Error("Error pulling REST port from property (null)", ex); }
                }

                String restUrl = "http://localhost:" + restPort.ToString() + "/api";
                serviceHost = new WebServiceHost(typeof(OSAERest.api), new Uri(restUrl));

                WebHttpBinding binding = new WebHttpBinding(WebHttpSecurityMode.None);
                binding.CrossDomainScriptAccessEnabled = true;

                var endpoint = serviceHost.AddServiceEndpoint(typeof(IRestService), binding, "");

                ServiceDebugBehavior sdb = serviceHost.Description.Behaviors.Find <ServiceDebugBehavior>();
                sdb.HttpHelpPageEnabled = false;
                if (showHelp)
                {
                    serviceHost.Description.Endpoints[0].Behaviors.Add(new WebHttpBehavior {
                        HelpEnabled = true
                    });
                }


                checkAPIKey();
                checkSecurityKey();
                serviceHost.Open();
            }
            catch (Exception ex)
            { Log.Error("Error starting RESTful web service", ex); }
        }
Beispiel #23
0
        public void RunInterface(string serviceName)
        {
            Log = new OSAE.General.OSAELog(serviceName);
            Log.Debug(PluginName + " - Running interface.");
            try
            {
                _plugin.RunInterface(PluginName);
                _running = true;
            }
            catch (Exception ex)
            { Log.Error(PluginName + " - Run Interface Error", ex); }

            Log.Debug(PluginName + " - Moving on...");
        }
        /// <summary>
        /// Set up the powershell plugin ready to process commands
        /// </summary>
        /// <param name="pluginName"></param>
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log = new General.OSAELog(pName);
            Log.Info("Running Interface!");

            if (PluginRegistered())
                Log.Debug("Powershell Plugin already registered");
            else
            {
                Log.Debug("Powershell Plugin needs registering");
                Register(false);
            }
            OwnTypes();
        }
Beispiel #25
0
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log   = new General.OSAELog(pName);
            Log.Info("Current Environment Version: " + Environment.Version.Major.ToString());
            if (Environment.Version.Major >= 4)
            {
                string folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), @"Microsoft.NET\Framework64\v2.0.50727");
                if (!Directory.Exists(folder))
                {
                    folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), @"Microsoft.NET\Framework\v2.0.50727");
                }

                Log.Debug("vjsnativ.dll path: " + folder);
                folder = Path.GetFullPath(folder);
                LoadLibrary(Path.Combine(folder, "vjsnativ.dll"));
            }

            string adapterProp = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Adapter").Value;
            string port        = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Port").Value;

            uom = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Unit of Measure").Value;
            Log.Debug("adapterProp: " + adapterProp + ", port: " + port + ", uom: " + uom);
            try
            {
                adapter = OneWireAccessProvider.getAdapter(adapterProp, "COM" + port);
            }
            catch (Exception ex)
            { Log.Error("Failed to GetAdapter ", ex); }


            if (adapter.adapterDetected())
            {
                Log.Info("Adapter Detected");
                adapter.setSearchAllDevices();

                Clock = new System.Threading.Timer(poll, null, 0, 10000);

                if (restarting)
                {
                    restarting = false;
                }
            }
            else
            {
                Log.Info("Adapter(" + adapterProp + ") not found on port " + port);
            }
        }
        public override void RunInterface(string pluginName)
        {
            gAppName = pluginName;
            Log      = new General.OSAELog(gAppName);

            try
            {
                gDebug = Convert.ToBoolean(OSAEObjectPropertyManager.GetObjectPropertyValue(gAppName, "Debug").Value);
            }
            catch
            { Log.Info("The JABBER Object Type seems to be missing the Debug Property!"); }
            Log.Info("Debug Mode Set to " + gDebug);

            OwnTypes();

            OSAE.OSAEObject tempAlias = OSAE.OSAEObjectManager.GetObjectByName(gSystemName);
            if (tempAlias.Alias.Length > 0)
            {
                gSystemName = tempAlias.Alias;
            }

            try
            {
                oRecognizer.SpeechRecognized += new EventHandler <SpeechRecognizedEventArgs>(oRecognizer_SpeechRecognized);
                //oRecognizer.AudioStateChanged += new EventHandler<AudioStateChangedEventArgs>(oRecognizer_StateChanged);
            }
            catch (Exception ex)
            { Log.Error("Unable to configure oRecognizer", ex); }

            oRecognizer = OSAEGrammar.Load_Direct_Grammar(oRecognizer);
            Log.Info("Load_Direct_Grammar completed");
            oRecognizer = OSAEGrammar.Load_Voice_Grammars(oRecognizer);
            Log.Info("Load_Voice_Grammars completed");
            oRecognizer = OSAEGrammar.Load_Text_Only_Grammars(oRecognizer);
            Log.Info("Load_Text_Only_Grammars completed");
            // Subscribe to Events
            xmppCon.OnLogin       += new ObjectHandler(xmppCon_OnLogin);
            xmppCon.OnRosterStart += new ObjectHandler(xmppCon_OnRosterStart);
            xmppCon.OnRosterEnd   += new ObjectHandler(xmppCon_OnRosterEnd);
            xmppCon.OnRosterItem  += new XmppClientConnection.RosterHandler(xmppCon_OnRosterItem);
            xmppCon.OnPresence    += new agsXMPP.protocol.client.PresenceHandler(xmppCon_OnPresence);
            xmppCon.OnAuthError   += new XmppElementHandler(xmppCon_OnAuthError);
            xmppCon.OnError       += new ErrorHandler(xmppCon_OnError);
            xmppCon.OnClose       += new ObjectHandler(xmppCon_OnClose);
            xmppCon.OnMessage     += new agsXMPP.protocol.client.MessageHandler(xmppCon_OnMessage);

            connect();
        }
Beispiel #27
0
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log   = new General.OSAELog(pName);
            Log.Info("Running Interface!");
            Clock          = new System.Timers.Timer();
            Clock.Interval = Int32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Update Interval").Value) * 60000;
            Log.Info(updateInterval.ToString());
            Clock.Elapsed += new ElapsedEventHandler(Timer_Tick);
            Log.Info(Clock.Interval.ToString());
            Clock.Start();

            Log.Info("Starting timer");
            updateThread = new Thread(new ThreadStart(updateFeeds));
            updateThread.Start();
        }
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log = new General.OSAELog(pName);
            Log.Info("Running Interface!");
            Clock = new System.Timers.Timer();
            Clock.Interval = Int32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Update Interval").Value) * 60000;
            Log.Info(updateInterval.ToString());
            Clock.Elapsed += new ElapsedEventHandler(Timer_Tick);
            Log.Info(Clock.Interval.ToString());
            Clock.Start();

            Log.Info("Starting timer");
            updateThread = new Thread(new ThreadStart(updateFeeds));
            updateThread.Start();
        }
        /// <summary>
        /// Set up the powershell plugin ready to process commands
        /// </summary>
        /// <param name="pluginName"></param>
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log   = new General.OSAELog(pName);
            Log.Info("Running Interface!");

            if (PluginRegistered())
            {
                Log.Debug("Powershell Plugin already registered");
            }
            else
            {
                Log.Debug("Powershell Plugin needs registering");
                Register(false);
            }
            OwnTypes();
        }
 public override void RunInterface(string pluginName)
 {
     Log.Info("Loading COSMUpdater..");
     cosmTest = new COSMWriter();
     pName = pluginName;
     Log = new General.OSAELog(pName);
     try
     {
         pollInterval = int.Parse("0" + OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "PollRate").Value);
         if (!ReportAndCheckUsage()) return;
         SetUpPoller();
         enabled = true;
         Log.Info("Started COSMUpdater...");
     }
     catch (Exception ex)
     { Log.Error("COSMUpdater Exception in RunInterface. ", ex); }
 }
Beispiel #31
0
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log   = new General.OSAELog(pName);
            Log.Info("Starting Android plugin");
            OwnTypes();

            //connect to devices
            OSAEObjectCollection objects = OSAEObjectManager.GetObjectsByType("ANDROID DEVICE");

            foreach (OSAEObject obj in objects)
            {
                createdevice(obj);
            }

            Log.Debug("Run Interface Complete");
        }
        /// <summary>
        /// OSA Plugin Interface - called on start up to allow plugin to do any tasks it needs
        /// </summary>
        /// <param name="pluginName">The name of the plugin from the system</param>
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log = new General.OSAELog(pName);
            OwnTypes();
            try
            {
                this.Log.Info("Starting Rest Interface");

                bool showHelp = bool.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Show Help").Value);
                int restPort = 8732;

                if (!OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "REST Port").Id.Equals(String.Empty))
                {
                    try
                    {
                        restPort = int.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "REST Port").Value);
                        Log.Info("Rest Port read in as: " + restPort);
                    }
                    catch (FormatException ex)
                    { Log.Error("Error pulling REST port from property (not a valid number)", ex); }
                    catch (OverflowException ex)
                    { Log.Error("Error pulling REST port from property (too large)", ex); }
                    catch (ArgumentNullException ex)
                    { Log.Error("Error pulling REST port from property (null)", ex); }
                }

                String restUrl = "http://localhost:"+restPort.ToString()+"/api";
                serviceHost = new WebServiceHost(typeof(OSAERest.api), new Uri(restUrl));

                WebHttpBinding binding = new WebHttpBinding(WebHttpSecurityMode.None);
                binding.CrossDomainScriptAccessEnabled = true;
                var endpoint = serviceHost.AddServiceEndpoint(typeof(IRestService), binding, "");

                ServiceDebugBehavior sdb = serviceHost.Description.Behaviors.Find<ServiceDebugBehavior>();
                sdb.HttpHelpPageEnabled = false;
                if (showHelp) serviceHost.Description.Endpoints[0].Behaviors.Add(new WebHttpBehavior { HelpEnabled = true });

                Log.Info("Starting RESTful Interface");
                serviceHost.Open();
            }
            catch (Exception ex)
            { Log.Error("Error starting RESTful web service", ex); }
        }
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log = new General.OSAELog(pName);
            Log.Info("Running Interface!");

            OSAEObjectType objt = OSAEObjectTypeManager.ObjectTypeLoad("RADIO THERMOSTAT DEVICE");
            OSAEObjectTypeManager.ObjectTypeUpdate(objt.Name, objt.Name, "Radio Thermostat Device", pName, "RADIO THERMOSTAT DEVICE", objt.Owner, objt.SysType, objt.Container, objt.HideRedundant);
            OSAEObjectCollection devices = OSAEObjectManager.GetObjectsByType("RADIO THERMOSTAT DEVICE");

            foreach (OSAEObject obj in devices)
            {
                ThermostatLib.SystemInfo si = ThermostatLib.SystemInfo.Load(obj.Address);
                Log.Info("---------------------------------");
                Log.Info("Device Name: " + ThermostatLib.SystemInfo.LoadSystemName(obj.Address));
                Log.Info("API Version: " + si.ApiVersion.ToString());
                Log.Info("Firmware Version: " + si.FirmwareVersion);
                Log.Info("UUID: " + si.UUID);
                Log.Info("WLAN Version: " + si.WlanFirmwareVersion);
                Log.Info("Model: " + ThermostatLib.SystemInfo.LoadModelName(obj.Address));
                Log.Info("Operating Mode: " + ThermostatLib.SystemInfo.LoadOperatingMode(obj.Address));

                ThermostatLib.Services services = ThermostatLib.Services.Load(obj.Address);
                string service = "";
                foreach (ThermostatLib.HttpdHandler handler in services.Handlers)
                {
                    service = "";
                    service += handler.Url + " (";
                    if (handler.AllowsGet && handler.AllowsPost) service += "GET, POST";
                    else
                    {
                        if (handler.AllowsGet) service += "GET";
                        if (handler.AllowsPost) service += "POST";
                    }
                    service += ")";
                    Log.Info("Service: " + service);
                }
            }
            Clock = new System.Timers.Timer();
            Clock.Interval = Int32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Poll Interval").Value) * 60000;
            Clock.Start();
            Clock.Elapsed += new ElapsedEventHandler(Timer_Tick);
        }
Beispiel #34
0
        public override void RunInterface(string pluginName)
        {
            Log = new OSAE.General.OSAELog(pluginName);
            //throw new NotImplementedException();
            this.Log.Info("Found Plugin Object: " + pluginName);
            this.Log.Info(pluginName + " is starting...");
            OSAEObject plugin  = OSAEObjectManager.GetObjectByName(pluginName);
            string     refresh = plugin.Property("Refresh").Value;
            int        refre   = Convert.ToInt16(refresh);

            Onlineupdatetime           = Onlineupdatetime * refre;
            OnlineUpdateTimer          = new System.Timers.Timer();
            OnlineUpdateTimer.Interval = Onlineupdatetime;
            OnlineUpdateTimer.Start();
            OnlineUpdateTimer.Elapsed += new ElapsedEventHandler(OnlineUpdateTime);
            this.updateOnlineThread    = new Thread(new ThreadStart(updateonline));
            this.updateOnlineThread.Start();
            Thread.Sleep(5000);
        }
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log   = new General.OSAELog(pName);
            Log.Info("Initializing Plugin");
            OSAEObjectType objt = OSAEObjectTypeManager.ObjectTypeLoad("SQUEEZEBOX");

            OSAEObjectTypeManager.ObjectTypeUpdate(objt.Name, objt.Name, objt.Description, pName, "SQUEEZEBOX", objt.Owner, objt.SysType, objt.Container, objt.HideRedundant);

            sbsAddress = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Server Address").Value;
            sbsPort    = Int32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "CLI Port").Value);
            ttsSave    = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "TTS Save Path").Value;
            ttsPlay    = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "TTS Play Path").Value;

            Log.Info("address: " + sbsAddress);
            Log.Info("port: " + sbsPort);
            sbs.mHost = sbsAddress;
            sbs.mPort = sbsPort;
            StringCollection     players = sbs.GetPlayers();
            OSAEObjectCollection objects = OSAEObjectManager.GetObjectsByType("SQUEEZEBOX");

            Log.Info("Found " + sbs.GetPlayerCount().ToString() + " players");
            foreach (string player in players)
            {
                Log.Info("Found player: " + player);
                string[] sb    = player.Split(' ');
                bool     found = false;
                foreach (OSAEObject obj in objects)
                {
                    if (obj.Address == sb[0])
                    {
                        Log.Info("Found matching object: " + obj.Name);
                        found = true;
                    }
                }

                if (!found)
                {
                    Log.Info("No object found.  Adding to OSA");
                    OSAEObjectManager.ObjectAdd(sb[1], "", sb[1], "SQUEEZEBOX", sb[0], "", 30, true);
                }
            }
        }
Beispiel #36
0
        public bool ActivatePlugin()
        {
            Log = new OSAE.General.OSAELog(PluginName);
            try
            {
                Log.Info(PluginName + ":  Starting Plugin...");
                _plugin = (OSAEPluginBase)_domain.CreateInstanceAndUnwrap(_assemblyName, _assemblyType);
                _plugin.InitializeLifetimeService();
                _running = true;

                _domain.UnhandledException += Domain_UnhandledException;
                return(true);
            }
            catch (Exception ex)
            {
                Log.Error("Error Starting Plugin (" + PluginName + ")", ex);
                _enabled = false;
                return(false);
            }
        }
 public override void RunInterface(string pluginName)
 {
     Log.Info("Loading COSMUpdater..");
     cosmTest = new COSMWriter();
     pName    = pluginName;
     Log      = new General.OSAELog(pName);
     try
     {
         pollInterval = int.Parse("0" + OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "PollRate").Value);
         if (!ReportAndCheckUsage())
         {
             return;
         }
         SetUpPoller();
         enabled = true;
         Log.Info("Started COSMUpdater...");
     }
     catch (Exception ex)
     { Log.Error("COSMUpdater Exception in RunInterface. ", ex); }
 }
        /// <summary>
        /// OSA Plugin Interface - called on start up to allow plugin to do any tasks it needs
        /// </summary>
        /// <param name="pluginName">The name of the plugin from the system</param>
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log   = new General.OSAELog(pName);
            try
            {
                Log.Info("Starting EventGhost...");

                OwnTypes();

                // on startup ensure that there is at least one computer setup to receive eventghost commands
                OSAEObjectCollection computers = OSAEObjectManager.GetObjectsByType("COMPUTER");

                // check to make sure that the Compuer Objecttype has the needed property
                //add eventghost property to the computer object type
                // need to implement check before i use the method below
                // OSAEObjectTypeManager.ObjectTypePropertyAdd("EventGhost Port", "String", "", "Computer", false);

                foreach (OSAEObject acomputer in computers)
                {
                    string computerName   = acomputer.Name;
                    string IPAddress      = acomputer.Address;
                    string eventGhostPort = (OSAEObjectPropertyManager.GetObjectPropertyValue(computerName, "EventGhost Port").Value);

                    //if no port for property indicate that the default port of 333333 will be used
                    if (eventGhostPort.Equals("", StringComparison.Ordinal))
                    {
                        Log.Info("There is no port information for " + acomputer.Name + " the default port of 33333 will be used when this computer is called");
                    }

                    //check to see if computer has address, if no log that "local host will be used"
                    if ((acomputer.Address).Equals("", StringComparison.Ordinal))
                    {
                        Log.Info("There is no address information for " + acomputer.Name + "localhost will be used for this location");
                    }
                }
            }
            catch (Exception ex)
            { Log.Error("Error during RunInterface!", ex); }
        }
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log = new General.OSAELog(pName);
            Log.Info("Current Environment Version: " + Environment.Version.Major.ToString());
            if (Environment.Version.Major >= 4)
            {
                string folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), @"Microsoft.NET\Framework64\v2.0.50727");
                if (!Directory.Exists(folder))
                    folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), @"Microsoft.NET\Framework\v2.0.50727");

                Log.Debug("vjsnativ.dll path: " + folder);
                folder = Path.GetFullPath(folder);
                LoadLibrary(Path.Combine(folder, "vjsnativ.dll"));
            }

            string adapterProp = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Adapter").Value;
            string port = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Port").Value;
            uom = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Unit of Measure").Value;
            Log.Debug("adapterProp: " + adapterProp + ", port: " + port + ", uom: " + uom);
            try
            {
                adapter = OneWireAccessProvider.getAdapter(adapterProp, "COM" + port);
            }
            catch (Exception ex)
            { Log.Error("Failed to GetAdapter ", ex); }

            if (adapter.adapterDetected())
            {
                Log.Info("Adapter Detected");
                adapter.setSearchAllDevices();

                Clock = new System.Threading.Timer(poll, null, 0, 10000);

                if (restarting) restarting = false;
            }
            else
                Log.Info("Adapter(" + adapterProp + ") not found on port " + port);
        }
        public ClientService()
        {
            serviceObject = "SERVICE-" + Common.ComputerName;
            Log           = new OSAE.General.OSAELog(serviceObject);
            bool found = OSAEObjectManager.ObjectExists(serviceObject);

            if (!found)
            {
                OSAEObjectManager.ObjectAdd(serviceObject, "", "SERVICE", "SERVICE", "", Common.ComputerName, 50, true);
            }
            else
            {
                OSAEObject obj = OSAEObjectManager.GetObjectByName(serviceObject);
                OSAEObjectManager.ObjectUpdate(serviceObject, serviceObject, "", obj.Description, obj.Type, "", Common.ComputerName, obj.MinTrustLevel, obj.Enabled);
            }

            OSAE.OSAEObjectStateManager.ObjectStateSet(serviceObject, "ON", serviceObject);

            Log.Info("ClientService Starting");

            try
            {
                if (!EventLog.SourceExists("OSAEClient"))
                {
                    EventLog.CreateEventSource("OSAEClient", "Application");
                }
            }
            catch (Exception ex)
            { Log.Error("CreateEventSource error", ex); }
            ServiceName     = "OSAEClient";
            EventLog.Source = "OSAEClient";
            EventLog.Log    = "Application";

            // These Flags set whether or not to handle that specific
            //  type of event. Set to true if you need it, false otherwise.
            CanStop = true;
        }
        public ClientService()
        {
            Log = new OSAE.General.OSAELog();

            this.Log.Info("ClientService Starting");

            try
            {
                if (!EventLog.SourceExists("OSAEClient"))
                    EventLog.CreateEventSource("OSAEClient", "Application");
            }
            catch (Exception ex)
            {
                this.Log.Error("CreateEventSource error", ex);
            }
            this.ServiceName = "OSAEClient";
            this.EventLog.Source = "OSAEClient";
            this.EventLog.Log = "Application";

            // These Flags set whether or not to handle that specific
            //  type of event. Set to true if you need it, false otherwise.

            this.CanStop = true;
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Load_App_Name();
            Log = new OSAE.General.OSAELog(gAppName);
            Common.CheckComputerObject(gAppName);
            Uri uri = new Uri("pack://siteoforigin:,,,/OSA.png");
            var bitmapImage = new BitmapImage(uri);

            canGUI.Background = new ImageBrush(bitmapImage);
            canGUI.Height = bitmapImage.Height;
            canGUI.Width = bitmapImage.Width;
            this.Height = bitmapImage.Height;
            this.Width = bitmapImage.Width;

            menuEditMode.IsChecked = false;
            menuEditMode.IsEnabled = false;
            menuShowControlList.IsChecked = false;
            menuShowControlList.IsEnabled = false;
            menuCreateScreen.IsEnabled = false;
            menuAddControl.IsEnabled = false;

            _timer = new System.Timers.Timer(1000);
            _timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed);
            _timer.Enabled = true; // Enable it

            gCurrentScreen = OSAEObjectPropertyManager.GetObjectPropertyValue(gAppName, "Default Screen").Value;
            gDebug = Convert.ToBoolean(OSAEObjectPropertyManager.GetObjectPropertyValue(gAppName, "Debug").Value);

            // uh maybe this should have code for no screens here, since the resize code went it.  if above fix dont work
            if (gCurrentScreen == "") Set_Default_Screen();

            Load_Screen(gCurrentScreen);

            OSAE.OSAEObjectStateManager.ObjectStateSet(gAppName, "ON", gAppName);

            canGUI.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(DragSource_PreviewMouseLeftButtonDown);
            canGUI.Drop += new DragEventHandler(DragSource_Drop);
        }
        public override void RunInterface(string pluginName)
        {
            gAppName = pluginName;
            Log = new General.OSAELog(gAppName);

            try
            {
                gDebug = Convert.ToBoolean(OSAEObjectPropertyManager.GetObjectPropertyValue(gAppName, "Debug").Value);
            }
            catch
            { Log.Info("The JABBER Object Type seems to be missing the Debug Property!"); }
            Log.Info("Debug Mode Set to " + gDebug);

            OwnTypes();

            OSAE.OSAEObject tempAlias = OSAE.OSAEObjectManager.GetObjectByName(gSystemName);
            if (tempAlias.Alias.Length > 0) gSystemName = tempAlias.Alias;

            try
            {
                oRecognizer.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(oRecognizer_SpeechRecognized);
                //oRecognizer.AudioStateChanged += new EventHandler<AudioStateChangedEventArgs>(oRecognizer_StateChanged);
            }
            catch (Exception ex)
            { Log.Error("Unable to configure oRecognizer", ex); }

            oRecognizer = OSAEGrammar.Load_Direct_Grammar(oRecognizer);
            Log.Info("Load_Direct_Grammar completed");
            oRecognizer = OSAEGrammar.Load_Voice_Grammars(oRecognizer);
            Log.Info("Load_Voice_Grammars completed");
            oRecognizer = OSAEGrammar.Load_Text_Only_Grammars(oRecognizer);
            Log.Info("Load_Text_Only_Grammars completed");
            // Subscribe to Events
            xmppCon.OnLogin += new ObjectHandler(xmppCon_OnLogin);
            xmppCon.OnRosterStart += new ObjectHandler(xmppCon_OnRosterStart);
            xmppCon.OnRosterEnd += new ObjectHandler(xmppCon_OnRosterEnd);
            xmppCon.OnRosterItem += new XmppClientConnection.RosterHandler(xmppCon_OnRosterItem);
            xmppCon.OnPresence += new agsXMPP.protocol.client.PresenceHandler(xmppCon_OnPresence);
            xmppCon.OnAuthError += new XmppElementHandler(xmppCon_OnAuthError);
            xmppCon.OnError += new ErrorHandler(xmppCon_OnError);
            xmppCon.OnClose += new ObjectHandler(xmppCon_OnClose);
            xmppCon.OnMessage += new agsXMPP.protocol.client.MessageHandler(xmppCon_OnMessage);

            connect();
        }
Beispiel #44
0
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log   = new General.OSAELog(pName);
            Log.Debug("Running interface");

            OSAEObjectType objt = OSAEObjectTypeManager.ObjectTypeLoad("ONKYO RECEIVER");

            OSAEObjectTypeManager.ObjectTypeUpdate(objt.Name, objt.Name, objt.Description, pName, "THING", objt.Owner, objt.SysType, objt.Container, objt.HideRedundant);

            _UDPListen              = new UDPListen();
            _UDPSend                = new UDPSend();
            _UDPListen.OnkyoDevice += new DelegateOnkyoReply(OnkyoMessageHandler);

            _UDPListen.Listen();
            _UDPSend.Send();

            OSAEObjectCollection objects = OSAEObjectManager.GetObjectsByType("ONKYO RECEIVER");

            foreach (OSAEObject obj in objects)
            {
                Receiver r = new Receiver(obj.Name);
                foreach (OSAEObjectProperty prop in obj.Properties)
                {
                    switch (prop.Name)
                    {
                    case "Communication Type":
                        r.Type = prop.Value;
                        break;

                    case "IP":
                        r.IP = prop.Value;
                        break;

                    case "Network Port":
                        try
                        { r.NetworkPort = Int32.Parse(prop.Value); }
                        catch
                        { r.NetworkPort = 0; }
                        break;

                    case "COM Port":
                        try
                        { r.ComPort = Int32.Parse(prop.Value); }
                        catch
                        { r.ComPort = 0; }
                        break;
                    }
                }

                receivers.Add(r);
                Log.Debug("Added receiver to list: " + r.Name);

                try
                {
                    if (r.Type == "Network" && r.IP != "" && r.NetworkPort != 0)
                    {
                        Log.Debug("Creating TCP Client: ip-" + r.IP + " port-" + r.NetworkPort);
                        r.tcpClient = new TcpClient(r.IP, r.NetworkPort);

                        //get a network stream from server
                        r.clientSockStream = r.tcpClient.GetStream();

                        // create new writer and reader stream to send and receive
                        r.clientStreamWriter = new StreamWriter(r.clientSockStream);
                        r.clientStreamReader = new StreamReader(r.clientSockStream);

                        //Start listening
                        r.Connect();
                    }
                    else if (r.Type == "Serial" && r.ComPort != 0)
                    { //not implemented
                    }
                    else
                    {
                        Log.Info(r.Name + " - Properties not set");
                    }
                }
                catch (Exception ex)
                { Log.Error("Error creating connection to receiver", ex); }
            }
            Log.Info("Run Interface Complete");
        }
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log = new General.OSAELog(pName);

            RSInit("COM" + OSAEObjectPropertyManager.GetObjectPropertyValue(pluginName,"Port").Value, 38400);
            if(RSOpen()) gRecComPortEnabled = true;

            recbuf[0] = 0;
            maxticks = 0;

            tmrRead.Elapsed += new System.Timers.ElapsedEventHandler(tmrRead_Tick);
            tmrRead.Enabled = true;

            RESETtrx();
        }
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log = new General.OSAELog(pName);
            Log.Debug("Running interface");

            OSAEObjectType objt = OSAEObjectTypeManager.ObjectTypeLoad("ONKYO RECEIVER");
            OSAEObjectTypeManager.ObjectTypeUpdate(objt.Name, objt.Name, objt.Description, pName, "THING", objt.Owner, objt.SysType, objt.Container, objt.HideRedundant);

            _UDPListen = new UDPListen();
            _UDPSend = new UDPSend();
            _UDPListen.OnkyoDevice += new DelegateOnkyoReply(OnkyoMessageHandler);

            _UDPListen.Listen();
            _UDPSend.Send();

            OSAEObjectCollection objects = OSAEObjectManager.GetObjectsByType("ONKYO RECEIVER");

            foreach (OSAEObject obj in objects)
            {
                Receiver r = new Receiver(obj.Name);
                foreach (OSAEObjectProperty prop in obj.Properties)
                {
                    switch (prop.Name)
                    {
                        case "Communication Type":
                            r.Type = prop.Value;
                            break;
                        case "IP":
                            r.IP = prop.Value;
                            break;
                        case "Network Port":
                            try
                            { r.NetworkPort = Int32.Parse(prop.Value); }
                            catch
                            { r.NetworkPort = 0; }
                            break;
                        case "COM Port":
                            try
                            { r.ComPort = Int32.Parse(prop.Value); }
                            catch
                            { r.ComPort = 0; }
                            break;
                    }
                }

                receivers.Add(r);
                Log.Debug("Added receiver to list: " + r.Name);

                try
                {
                    if (r.Type == "Network" && r.IP != "" && r.NetworkPort != 0)
                    {
                        Log.Debug("Creating TCP Client: ip-" + r.IP + " port-" + r.NetworkPort);
                        r.tcpClient = new TcpClient(r.IP, r.NetworkPort);

                        //get a network stream from server
                        r.clientSockStream = r.tcpClient.GetStream();

                        // create new writer and reader stream to send and receive
                        r.clientStreamWriter = new StreamWriter(r.clientSockStream);
                        r.clientStreamReader = new StreamReader(r.clientSockStream);

                        //Start listening
                        r.Connect();
                    }
                    else if (r.Type == "Serial" && r.ComPort != 0)
                    { //not implemented
                    }
                    else
                        Log.Info(r.Name + " - Properties not set");
                }
                catch (Exception ex)
                { Log.Error("Error creating connection to receiver", ex); }
            }
            Log.Info("Run Interface Complete");
        }
        private OSAE.General.OSAELog Log; // = new General.OSAELog();

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="PluginFinder"/> class.
        /// </summary>
        public PluginFinder()
        {
            Log = new General.OSAELog("Plugin Finder");
            _pluginBaseType = typeof(OSAEPluginBase);
        }
        /// <summary>
        /// OSA Plugin Interface - called on start up to allow plugin to do any tasks it needs
        /// </summary>
        /// <param name="pluginName">The name of the plugin from the system</param>
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log = new General.OSAELog(pName);
            try
            {
                Log.Info("Starting EventGhost...");

                OwnTypes();

                // on startup ensure that there is at least one computer setup to receive eventghost commands
                OSAEObjectCollection computers = OSAEObjectManager.GetObjectsByType("COMPUTER");

                // check to make sure that the Compuer Objecttype has the needed property
                //add eventghost property to the computer object type
                // need to implement check before i use the method below
                // OSAEObjectTypeManager.ObjectTypePropertyAdd("EventGhost Port", "String", "", "Computer", false);

                foreach (OSAEObject acomputer in computers)
                {
                    string computerName = acomputer.Name;
                    string IPAddress = acomputer.Address;
                    string eventGhostPort = (OSAEObjectPropertyManager.GetObjectPropertyValue(computerName, "EventGhost Port").Value);

                    //if no port for property indicate that the default port of 333333 will be used
                    if (eventGhostPort.Equals("", StringComparison.Ordinal))
                        Log.Info("There is no port information for " + acomputer.Name + " the default port of 33333 will be used when this computer is called");

                    //check to see if computer has address, if no log that "local host will be used"
                    if ((acomputer.Address).Equals("", StringComparison.Ordinal))
                    Log.Info("There is no address information for " + acomputer.Name + "localhost will be used for this location");
                }
            }
            catch (Exception ex)
            { Log.Error("Error during RunInterface!", ex); }
        }
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log = new General.OSAELog(pName);
            Log.Info("Starting J-Works plugin");
            if (OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Polling Inverval").Value != "")
                pollInterval = UInt32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Polling Interval").Value);

            // point subobject classes at this instance (I think)
            OSAEObjectTypeManager.ObjectTypeUpdate("JWORKS INPUT", "JWORKS INPUT", "J-Works Input", pName, "JWORKS INPUT", false, false, false, true);
            OSAEObjectTypeManager.ObjectTypeUpdate("JWORKS OUTPUT", "JWORKS OUTPUT", "J-Works Output", pName, "JWORKS OUTPUT", false, false, false, true);

            // enumerate JSB34x inputs and outputs
            short numDevs = Jsb34xNumberOfModules();
            StringBuilder sb = new StringBuilder(32);
            Jsb34xDllVersion(sb, 32);
            string DllVersion = sb.ToString();
            for (short dev = 1; dev <= numDevs; ++dev)
            {
                sb.Clear();
                Jsb34xSerialNumber(dev, sb, 32);
                String serial = sb.ToString();
                sb.Clear();
                Jsb34xFirmwareVersion(serial, sb, 32);
                string firmwareVersion = sb.ToString();
                sb.Clear();
                Jsb34xDriverVersion(serial, sb, 32);
                string driverVersion = sb.ToString();

                Jsb34xOpenAllRelays(serial);
                JSB34Xs.Add(serial);
                JSB34XState.Add(0);

                byte numInputs = Jsb34xMaxInputs(serial);
                byte numOutputs = Jsb34xMaxRelays(serial);
                Log.Info("Found JSB34x device " + serial + " " + driverVersion + " " + DllVersion + " " + firmwareVersion + " with " + numInputs + " inputs, " + numOutputs + " outputs.");
                for (byte inp = 1; inp <= numInputs; ++inp)
                    AddIO(serial + "_I" + inp, Direction.Input, serial, inp);
                for (byte outp = 1; outp <= numOutputs; ++outp)
                    AddIO(serial + "_O" + outp, Direction.Output, serial, outp);
            }

            // enumerate JSB38x /39x inputs
            numDevs = Jsb383NumberOfModules();
            sb.Clear();
            Jsb383DllVersion(sb, 32);
            DllVersion = sb.ToString();
            for (short dev = 1; dev <= numDevs; ++dev)
            {
                sb.Clear();
                Jsb383SerialNumber(dev, sb, 32);
                String serial = sb.ToString();
                sb.Clear();
                Jsb383FirmwareVersion(serial, sb, 32);
                string firmwareVersion = sb.ToString();
                sb.Clear();
                Jsb383DriverVersion(serial, sb, 32);
                string driverVersion = sb.ToString();

                JSB383s.Add(serial);
                JSB383State.Add(0);

                byte numInputs = Jsb383MaxInputs(serial);
                Log.Info("Found JSB38x / JSB39x device " + serial + " " + driverVersion + " " + DllVersion + " " + firmwareVersion + " with " + numInputs + " inputs.");
                for (byte inp = 1; inp <= numInputs; ++inp)
                    AddIO(serial + "_I" + inp, Direction.Input, serial, inp);
            }

            if (pollInterval > 0)
            {
                timer.Interval = pollInterval;
                timer.Elapsed += new ElapsedEventHandler(Poll);
                timer.Start();
            }
        }
        public override void RunInterface(string pluginName)
        {
            gAppName = pluginName;
            Log = new General.OSAELog(gAppName);

            Log.Info("Email Plugin is Starting...");

            OwnTypes();
        }
 public override async void RunInterface(string pluginName)
 {
     pName = pluginName;
     Log = new General.OSAELog(pName);
     await StartOpenzwaveAsync();
 }
        /// <summary>
        /// OSA Plugin Interface - called on start up to allow plugin to do any tasks it needs
        /// </summary>
        /// <param name="pluginName">The name of the plugin from the system</param>
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log = new General.OSAELog(pName);

            //make sure object types are owned by the Nest Plugin
            OSAEObjectTypeManager.ObjectTypeUpdate("NEST STRUCTURE", "NEST STRUCTURE", "Nest Structure", pluginName, "NEST STRUCTURE", false, false, false, true);
            OSAEObjectTypeManager.ObjectTypeUpdate("NEST THERMOSTAT", "NEST THERMOSTAT", "Nest Thermostat", pluginName, "NEST THERMOSTAT", false, false, false, true);
            OSAEObjectTypeManager.ObjectTypeUpdate("NEST PROTECT", "NEST PROTECT", "Nest Protect", pluginName, "NEST PROTECT", false, false, false, true);

            Log.Info("Starting Nest...");

            Ititialize("startup");

            //heartbeat to check online devices
            int interval = 10; //in minutes

            //bool isNum = Int32.TryParse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Poll Interval").Value, out interval);
            Clock = new System.Timers.Timer();
            //if (isNum)
            Clock.Interval = interval * 60 * 1000;
            //else
            //    Clock.Interval = 60000;
            Clock.Start();
            Clock.Elapsed += new ElapsedEventHandler(Timer_Tick);
            updateThread = new Thread(new ThreadStart(update));
        }
        public override void RunInterface(string pluginName)
        {
            Log.Info("Running interface");
            gAppName = pluginName;
            Log      = new General.OSAELog(gAppName);
            if (OSAEObjectManager.ObjectExists(gAppName))
            {
                Log.Info("Found the XBMC plugin's Object (" + gAppName + ")");
            }
            else
            {
                Log.Info("Could Not Find the XBMC plugin's Object!!! (" + gAppName + ")");
            }

            try
            {
                gDebug = Convert.ToBoolean(OSAEObjectPropertyManager.GetObjectPropertyValue(gAppName, "Debug").Value);
            }
            catch
            { Log.Info("The XBMC Object Type seems to be missing the Debug Property!"); }
            Log.Info("Debug Mode Set to " + gDebug);


            OwnTypes();
            //OSAEObjectTypeManager.ObjectTypeUpdate("XBMC SYSTEM", "XBMC SYSTEM", "XBMC System", pluginName, "XBMC SYSTEM", 0, 0, 0, 1);

            OSAEObjectCollection XBMCInstances = OSAEObjectManager.GetObjectsByType("XBMC System");

            foreach (OSAEObject obj in XBMCInstances)
            {
                string ip = "", username = "", password = "";
                int    port = 0;

                foreach (OSAEObjectProperty p in obj.Properties)
                {
                    switch (p.Name)
                    {
                    case "IP":
                        ip = p.Value;
                        break;

                    case "Port":
                        port = Int32.Parse(p.Value);
                        break;

                    case "Username":
                        username = p.Value;
                        break;

                    case "Password":
                        password = p.Value;
                        break;
                    }
                }
                Log.Info("Creating new XBMC System connection: " + obj.Name + " (" + ip + ":" + port + ", user="******")");
                try
                {
                    XBMCSystem system = new XBMCSystem(obj.Name, ip, port, username, password);
                    if (system.Connect())
                    {
                        Systems.Add(system);
                        Log.Info("XBMC System connection Successfull for: " + obj.Name);
                    }
                }
                catch (Exception ex)
                { Log.Error("Error connecting to XBMC system", ex); }
            }

            try
            {
                Clock          = new System.Timers.Timer();
                Clock.Interval = 10000;

                Clock.Elapsed += new ElapsedEventHandler(Timer_Tick);
                Clock.Start();
                if (gDebug)
                {
                    Log.Debug("Timers Started");
                }
            }
            catch (Exception ex)
            { Log.Error("Error starting timers ", ex); }
        }
        /// <summary>
        /// Searches the passed Path for Plugins
        /// </summary>
        /// <param name="Path">Directory to search for Plugins in</param>
        public void FindPlugins(string Path)
        {
            Log2 = new OSAE.General.OSAELog("Plugins");
            try {
                //First empty the collection, we're reloading them all
                colAvailablePlugins.Clear();

                //Go through all the files in the plugin directory
                foreach (var fileOn in Directory.GetFiles(Path, "*.dll", SearchOption.AllDirectories))
                {
                    FileInfo file = new FileInfo(fileOn);

                    //Preliminary check, must be .dll
                    if (file.Extension.Equals(".dll"))
                    {
                        //Add the 'plugin'
                        AddPlugin(fileOn);
                    }
                }
            }
            catch (Exception ex)
            {
                Log2.Error("Find Plugins Error!", ex);
            }
        }
Beispiel #55
0
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log   = new General.OSAELog(pName);
            Log.Info("Starting J-Works plugin");
            if (OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Polling Inverval").Value != "")
            {
                pollInterval = UInt32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Polling Interval").Value);
            }

            // point subobject classes at this instance (I think)
            OSAEObjectTypeManager.ObjectTypeUpdate("JWORKS INPUT", "JWORKS INPUT", "J-Works Input", pName, "JWORKS INPUT", false, false, false, true);
            OSAEObjectTypeManager.ObjectTypeUpdate("JWORKS OUTPUT", "JWORKS OUTPUT", "J-Works Output", pName, "JWORKS OUTPUT", false, false, false, true);

            // enumerate JSB34x inputs and outputs
            short         numDevs = Jsb34xNumberOfModules();
            StringBuilder sb      = new StringBuilder(32);

            Jsb34xDllVersion(sb, 32);
            string DllVersion = sb.ToString();

            for (short dev = 1; dev <= numDevs; ++dev)
            {
                sb.Clear();
                Jsb34xSerialNumber(dev, sb, 32);
                String serial = sb.ToString();
                sb.Clear();
                Jsb34xFirmwareVersion(serial, sb, 32);
                string firmwareVersion = sb.ToString();
                sb.Clear();
                Jsb34xDriverVersion(serial, sb, 32);
                string driverVersion = sb.ToString();

                Jsb34xOpenAllRelays(serial);
                JSB34Xs.Add(serial);
                JSB34XState.Add(0);

                byte numInputs  = Jsb34xMaxInputs(serial);
                byte numOutputs = Jsb34xMaxRelays(serial);
                Log.Info("Found JSB34x device " + serial + " " + driverVersion + " " + DllVersion + " " + firmwareVersion + " with " + numInputs + " inputs, " + numOutputs + " outputs.");
                for (byte inp = 1; inp <= numInputs; ++inp)
                {
                    AddIO(serial + "_I" + inp, Direction.Input, serial, inp);
                }
                for (byte outp = 1; outp <= numOutputs; ++outp)
                {
                    AddIO(serial + "_O" + outp, Direction.Output, serial, outp);
                }
            }

            // enumerate JSB38x /39x inputs
            numDevs = Jsb383NumberOfModules();
            sb.Clear();
            Jsb383DllVersion(sb, 32);
            DllVersion = sb.ToString();
            for (short dev = 1; dev <= numDevs; ++dev)
            {
                sb.Clear();
                Jsb383SerialNumber(dev, sb, 32);
                String serial = sb.ToString();
                sb.Clear();
                Jsb383FirmwareVersion(serial, sb, 32);
                string firmwareVersion = sb.ToString();
                sb.Clear();
                Jsb383DriverVersion(serial, sb, 32);
                string driverVersion = sb.ToString();

                JSB383s.Add(serial);
                JSB383State.Add(0);

                byte numInputs = Jsb383MaxInputs(serial);
                Log.Info("Found JSB38x / JSB39x device " + serial + " " + driverVersion + " " + DllVersion + " " + firmwareVersion + " with " + numInputs + " inputs.");
                for (byte inp = 1; inp <= numInputs; ++inp)
                {
                    AddIO(serial + "_I" + inp, Direction.Input, serial, inp);
                }
            }

            if (pollInterval > 0)
            {
                timer.Interval = pollInterval;
                timer.Elapsed += new ElapsedEventHandler(Poll);
                timer.Start();
            }
        }
 public override void RunInterface(string pluginName)
 {
     pName = pluginName;
     Log = new OSAE.General.OSAELog(pName);
     Log.Info(pluginName + " is starting...");
     Log.Info("===================================================");
     OwnTypes();
 }
 /// <summary>
 /// Standard OSA Plugin architecture see Wiki Docs
 /// </summary>
 /// <param name="method">Standard Architecture parameter see Wiki Docs</param>
 public override void RunInterface(string pluginName)
 {
     pName = pluginName;
     Log = new General.OSAELog(pName);
     OwnTypes();
 }
        public override void RunInterface(string pluginName)
        {
            try
            {
                pName = pluginName;
                Log = new General.OSAELog(pName);
                FirstUpdateRun = true;
                FirstForcastRun = true;
                Log.Info("Running Interface");
                OwnTypes();

                OSAEObjectCollection objects = OSAEObjectManager.GetObjectsByType("WEATHER");
                if (objects.Count == 0)
                {
                    OSAEObjectManager.ObjectAdd("Weather", "", "Weather Data", "WEATHER", "", "", 30, true);
                    WeatherObjName = "Weather";
                }
                else
                    WeatherObjName = objects[0].Name;

                Log.Info("Linked to Weather object to store data.");
                try
                {
                    if (bool.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Metric").Value))
                    {
                        Metric = true;
                        Log.Info("Using metric units");
                    }
                }
                catch {}

                try
                {
                    gDebug = Convert.ToBoolean(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Debug").Value);
                }
                catch
                { Log.Info("The WUnderground Object Type seems to be missing the Debug Property!"); }
                Log.Info("Debug Mode Set to " + gDebug);

                try
                {
                    pKey = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Key").Value;
                    if (pKey.Length < 1)
                        Log.Info("!!! You need an WUnderground Key for full weather feeds !!!");
                    else
                        Log.Info("Found WUnderground Key (" + pKey + ")");
                }
                catch (Exception ex)
                { Log.Error("Error reading your Key.", ex); }

                try
                {
                    pCity = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "City").Value;
                    if (pCity.Length < 1)
                        Log.Info("!!! You need a City for full weather feeds !!!");
                    else
                        Log.Info("Found WUnderground City (" + pCity + ")");
                }
                catch (Exception ex)
                { Log.Error("Error reading your City.", ex); }

                try
                {
                    pState = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "State").Value;
                    if (pState.Length < 1)
                        Log.Info("!!! You need a State for full weather feeds !!!");
                    else
                        Log.Info("Found State (" + pState + ")");
                }
                catch (Exception ex)
                { Log.Error("Error reading your State.", ex); }

                Conditionsupdatetime = Int32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Conditions Interval").Value);
                if (Conditionsupdatetime > 0)
                {
                    ConditionsUpdateTimer = new System.Timers.Timer();
                    ConditionsUpdateTimer.Interval = Conditionsupdatetime * 60000;
                    ConditionsUpdateTimer.Start();
                    ConditionsUpdateTimer.Elapsed += new ElapsedEventHandler(ConditionsUpdateTime);

                    updateConditionsThread = new Thread(new ThreadStart(updateconditions));
                    updateConditionsThread.Start();

                  //  Thread.Sleep(10000);
                }
                else
                {
                    latitude = OSAEObjectPropertyManager.GetObjectPropertyValue(WeatherObjName, "latitude").Value;
                    longitude = OSAEObjectPropertyManager.GetObjectPropertyValue(WeatherObjName, "longitude").Value;
                    if (gDebug) Log.Debug("Read in properties: Lat=" + latitude + ", Long=" + longitude);
                }

                do
                {
                    Thread.Sleep(5000);
                } while (FirstUpdateRun);

                Forecastupdatetime = Int32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Forecast Interval").Value);
                if (Forecastupdatetime > 0)
                {
                    ForecastUpdateTimer = new System.Timers.Timer();
                    ForecastUpdateTimer.Interval = Forecastupdatetime * 60000;
                    ForecastUpdateTimer.Start();
                    ForecastUpdateTimer.Elapsed += new ElapsedEventHandler(ForecastUpdateTime);

                    updateForecastThread = new Thread(new ThreadStart(updateforecast));
                    updateForecastThread.Start();
                }

                do
                {
                    Thread.Sleep(5000);
                } while (FirstForcastRun);

                Log.Info("Updated " + WeatherObjName + ", setting Weather object to Updated.");
                OSAE.OSAEMethodManager.MethodQueueAdd(WeatherObjName, "Updated", "", "", pName);

                DayNightUpdateTimer = new System.Timers.Timer();
                DayNightUpdateTimer.Interval = DayNightupdatetime;
                DayNightUpdateTimer.Start();
                DayNightUpdateTimer.Elapsed += new ElapsedEventHandler(DayNightUpdateTime);

                updateDayNightThread = new Thread(new ThreadStart(updateDayNight));
                updateDayNightThread.Start();
            }
            catch (Exception ex)
            { Log.Error("Error initializing the plugin ", ex); }
        }
        /// <summary>
        ///  RunInterface will be called everytime the plugin starts. Will discover all devices existing in Telldus center.
        ///  New OSA objects will be created for each device if they are not already existing, unless the property AddDevices is set to FALSE. 
        /// </summary>
        /// <param name="pluginName">Name of the plugin, i.e. Tellstick</param>
        public override void RunInterface(string pluginName)
        {
            pos = 0;
            //            // ### Code to make it possible to debug RunInterface. Put breakpoint on line with Sleep(0), then manually move execution out of the loop.
            //            Name = "debug";
            //            while (Name == "debug")
            //            {
            //                System.Threading.Thread.Sleep(0);
            //            }
            //            // ### Until here
            Name = pluginName;
            logger = new General.OSAELog(Name);
            //oldLogger = OSAE.Logging.GetLogger("Tellstick");
            OSAEObject obj = null;
            pos = 2;
            log("RunInterface", "", "********** Starting... **********");
            initPlugin(Name);

            try
            {
                // Initialise the plugin
                // TelldusNETWrapper.tdInit();   // Initialise the Telldus dll
                int NumberOfDevices = TelldusNETWrapper.tdGetNumberOfDevices();
                pos = 3;
                log("RunInterface", "", "********** " + pluginName + " started, found " + NumberOfDevices + " devices **********");
                log("RunInterface", "", "*****************************");
                pos = 4;
                if (OSAEObjectPropertyManager.ObjectPropertyExists(Name, propNoDev))
                    OSAEObjectManager.GetObjectByName(pluginName).SetProperty(propNoDev, NumberOfDevices.ToString(), pluginName);
                else
                    logW("RunInterface", pluginName, propNoDev + " Property is missing. (Integer)");
                log("RunInterface", addrPrefix, "AddressPrefix for devices set. ");
                log("RunInterface", addrPrefixSensor, "AddressPrefix for sensors set. ");

                // All old devices to DISABLED
                log("RunInterface",  "OFF", "Updating all old devices to status 'OFF' or 'UNKNOWN'.");
                pos = 5;
                OSAEObjectCollection devices = OSAEObjectManager.GetObjectsByOwner(objOwner);
                devices.ToList().ForEach(StatusDefault);

                // Initialise all current devices
                log("RunInterface", "", "Initialise all current devices.");
                for (int i = 0; i < NumberOfDevices; i++)
                {
                    try
                    {
                        pos = 6;
                        int deviceId = TelldusNETWrapper.tdGetDeviceId(i);
                        string name = TelldusNETWrapper.tdGetName(deviceId);
                        pos = 7;
                        obj = getObject(deviceId);
                        pos = 8;
                        obj.LastUpd = DateTime.Now.ToString();
                        logD("RunInterface", obj.Name, obj.Address.PadRight(v) + "Id-" + deviceId + "/Cont-" + obj.Container +
                                      "/Enab-" + obj.Enabled +
                                      "/Metd-" + TelldusNETWrapper.tdMethods(deviceId, TelldusNETWrapper.TELLSTICK_ALL) +
                                      "/Stat-" + obj.State + "/Typ-" + obj.Type, obj);
                        pos = 9;
                        setOSAProperties(obj, deviceId);
                        pos = 10;
                        setLastProperties(obj, deviceId, TelldusNETWrapper.tdLastSentCommand(deviceId, TelldusNETWrapper.TELLSTICK_ALL));
                        pos = 11;
                    }
                    catch (Exception ex)
                    {
                        logE("RunInterface", obj.Name, "RunInterface Exception", ex);
                        // Exception for one device, continue with the other devices
                    }
                } //for

                pos = 12;
                // Create a timer for creation of average sensor values.
                avgTimer = new System.Timers.Timer(60000 * sensorAverageTime);  //
                avgTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnAverageEvent);  // Hook up the Elapsed event for the timer.
                pos = 13;

                avgTimer.Enabled = true;
                logD("RunInterface", sensorAverageTime.ToString(),"Timer event for average sensors values added.");

                // Register callback functions
                log("RunInterface", "", "Registering callback functions. ");
                eventIdEvents = ts.tdRegisterDeviceEvent(decodeEvent, null);
                log("RunInterface", "decodeEvent", "Registered.");
                eventIdDeviceEvents = ts.tdRegisterDeviceChangeEvent(decodeChangeEvent, null);
                log("RunInterface", "decodeChangeEvent", "Registered.");
                eventIdSensorEvents = ts.tdRegisterDeviceSensorEvent(decodeSensorEvent, null);
                log("RunInterface", "decodeSensorEvent", "Registered.");
                if (rawEvents)
                {
                    eventIdRawEvents = ts.tdRegisterRawDeviceEvent(decodeRawEvent, null);
                    log("RunInterface", "decodeRawEvent", "Registered.");
                }
                log("RunInterface", "", "**********      Running!      **********");
            }
            catch (Exception ex)
            {
                logE("RunInterface", obj.Name, "RunInterface Exception", ex);
                throw; // Do not continue execution, fatal problem
            }
        }
 /// <summary>
 /// Standard OSA Plugin architecture see Wiki Docs
 /// </summary>
 /// <param name="method">Standard Architecture parameter see Wiki Docs</param>
 public override void RunInterface(string pluginName)
 {
     pName = pluginName;
     Log   = new General.OSAELog(pName);
     OwnTypes();
 }