OSAE.XBMC.XBMCSystem.Connect C# (CSharp) Method

Connect() public method

public Connect ( ) : bool
return bool
        public bool Connect()
        {
            Log.Info("Attempting connection: " + Name + " (" + _ip + ":" + _port + ", user=" + _username + ")");
            try
            {
                _pinging = true;
                _xbmcSystem = new Client(_ip, _port, _username, _password);
                var task = Task.Run(async () =>
                {
                    return await _xbmcSystem.JSONRPC.Ping();
                });
                if (task.Result == "pong")
                {
                    Log.Info("Client connected");

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

                    _xbmcSystem.Player.OnPlay += Player_OnPlay;
                    _xbmcSystem.Player.OnStop += Player_OnStop;
                    _xbmcSystem.Player.OnPause += Player_OnPause;

                    _xbmcSystem.StartNotificationListener();
                    if (_Debug) Log.Debug("Events wired up");
                    _pinging = false;
                    return true;
                }
                else
                {
                    _pinging = false;
                    return false;
                }
            }
            catch(Exception ex)
            {
                Log.Error("Error connecting to XBMC system" + Name + " (" + _ip + ":" + _port + ", user=" + _username + ")", ex);
                _pinging = false;
                return false;
            }
        }

Usage Example

        public override void RunInterface(string pluginName)
        {
            this.Log.Debug("Running interface");
            pName = pluginName;
            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;
                    }
                }
                this.Log.Debug("Creating new XBMC System connection: " + obj.Name + " - " + ip);
                try
                {
                    XBMCSystem system = new XBMCSystem(obj.Name, ip, port, username, password);
                    if (system.Connect())
                    {
                        Systems.Add(system);
                    }
                }
                catch (Exception ex)
                {
                    this.Log.Error("Error connecting to XBMC system: " + ex.Message + " - " + ex.InnerException.Message);
                }
            }

            Clock          = new System.Timers.Timer();
            Clock.Interval = 5000;

            Clock.Elapsed += new ElapsedEventHandler(Timer_Tick);
            Clock.Start();
        }
All Usage Examples Of OSAE.XBMC.XBMCSystem::Connect