示例#1
0
        public async Task <List <Toy> > RequestToysListAsync()
        {
            List <Toy> Toys = new List <Toy>();

            foreach (var connection in PluginConfig.Instance.GetActiveConnections())
            {
                try
                {
                    if (!connection.Key.Equals("Default"))
                    {
                        ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };
                    }
                    var responseString = await client.GetStringAsync(connection.Value.CreateBaseUrl() + "/GetToys");

                    JObject toysString = JObject.Parse(responseString);
                    if (!toysString["type"].ToString().Equals("ok"))
                    {
                        Plugin.Log.Info("Lovense Connect not active/running for connection: " + connection.Key);
                        continue;
                    }
                    foreach (JProperty dataToy in (JToken)toysString["data"])
                    {
                        JToken toyDetails = dataToy.Value;
                        Toy    newToy     = new Toy(toyDetails["id"].ToString().ToUpper(), toyDetails["name"].ToString(), toyDetails["status"].ToString().Equals("1"), toyDetails["version"].ToString(), toyDetails["nickName"].ToString());
                        if (toyDetails["battery"] is null || toyDetails["battery"].ToString().Equals(""))
                        {
                            newToy.SetBattery(0);
                        }
                        else
                        {
                            newToy.SetBattery(Int32.Parse(toyDetails["battery"].ToString()));
                        }

                        newToy.SetConnection(connection.Key);
                        Toys.Add(newToy);
                    }
                }
示例#2
0
 public void updateBattery(Toy toy)
 {
     this.Request.updateBattery(toy);
 }