Пример #1
0
        public async Task <Error> interactTryToReply(string query)
        {
            InteractReply = "";
            var        jsonrpc    = new JsonRpcClient();
            Parameters parameters = new Parameters();

            parameters.query = query;
            jsonrpc.SetParameters(parameters);
            if (await jsonrpc.SendRequest("interact::tryToReply"))
            {
                var response = jsonrpc.GetRequestResponseDeserialized <Response <string> >();
                if (response != null)
                {
                    InteractReply = response.result;
                }
            }

            return(jsonrpc.Error);
        }
Пример #2
0
        public async Task <Error> SynchMobilePlugin()
        {
            var        jsonrpc    = new JsonRpcClient();
            Parameters parameters = new Parameters();

            parameters.plugin = "mobile";
            jsonrpc.SetParameters(parameters);
            EqLogicList.Clear();
            CommandList.Clear();

            if (await jsonrpc.SendRequest("sync"))
            {
                // Récupère la liste de tous les eqLogics
                var EqLogics = jsonrpc.GetRequestResponseDeserialized <Response <JeedomObject> >();
                if (EqLogics != null)
                {
                    foreach (Model.EqLogic eq in EqLogics.result.eqLogics)
                    {
                        EqLogicList.Add(eq);
                    }
                }

                // Récupère la liste de toutes les cmds
                var Cmds = jsonrpc.GetRequestResponseDeserialized <Response <Model.EqLogic> >();
                if (Cmds.result.Cmds != null)
                {
                    foreach (Model.Command cmd in Cmds.result.Cmds)
                    {
                        // AJoute la cmd à son eqLogic
                        var eq = (from e in EqLogicList where e.Id == cmd.EqLogic_id select e).FirstOrDefault();
                        if (eq.Cmds == null)
                        {
                            eq.Cmds = new ObservableCollectionEx <Model.Command>();
                        }
                        eq.Cmds.Add(cmd);

                        /*if (EqLogicList.Where(o => o.Id.Equals(cmd.EqLogic_id)).FirstOrDefault().Cmds == null)
                         * EqLogicList.Where(o => o.Id.Equals(cmd.EqLogic_id)).FirstOrDefault().Cmds = new ObservableCollectionEx<Command>();
                         * EqLogicList.Where(o => o.Id.Equals(cmd.EqLogic_id)).FirstOrDefault().Cmds.Add(cmd);*/

                        // Ajoute la commande à la liste globale des cmds
                        CommandList.Add(cmd);
                    }
                }

                // Suppression des eqLogics sans cmds
                for (int i = EqLogicList.Count - 1; i >= 0; i--)
                {
                    if (EqLogicList[i].Cmds == null)
                    {
                        EqLogicList.RemoveAt(i);
                    }
                }

                // Affecte les eqLogics à leurs objects correspondants
                foreach (EqLogic eq in EqLogicList)
                {
                    var ob = (from o in ObjectList where o.id == eq.object_id select o).FirstOrDefault();

                    if (ob.eqLogics == null)
                    {
                        ob.eqLogics = new List <EqLogic>();
                    }
                    ob.eqLogics.Add(eq);
                }

                // Suppression des objects sans eqLogics
                for (int i = ObjectList.Count - 1; i >= 0; i--)
                {
                    //todo review eqlogics
                    //if (ObjectList[i].EqLogics == null)
                    //	ObjectList.RemoveAt(i);
                }

                // Mise à jour des favoris
                PopulateFavoriteList();
            }

            return(jsonrpc.Error);
        }
Пример #3
0
        /*public async Task<Error> DownloadCommands()
        {
            var jsonrpc = new JsonRpcClient();
            if (await jsonrpc.SendRequest("cmd::all"))
            {
                CommandList.Clear();
                var response = jsonrpc.GetRequestResponseDeserialized<ResponseCommandList>();
                if (response != null)
                    CommandList = response.result;
                foreach (Command cmd in CommandList)
                {
                    var eqlist = from eq in EqLogicList where eq.id == cmd.eqLogic_id select eq;
                    var parenteq = eqlist.First();
                    if (parenteq.cmds == null)
                        parenteq.cmds = new ObservableCollection<Command>();
                    parenteq.cmds.Add(cmd);
                    cmd.Parent = parenteq;
                    if (cmd.name == "On")
                        parenteq.OnVisibility = true;

                    if (cmd.type == "info")
                        await ExecuteCommand(cmd);
                }
            }

            return jsonrpc.Error;
        }*/

        public async Task<Error> interactTryToReply(string query)
        {
            InteractReply = "";
            var jsonrpc = new JsonRpcClient();
            Parameters parameters = new Parameters();
            parameters.query = query;
            jsonrpc.SetParameters(parameters);
            if (await jsonrpc.SendRequest("interact::tryToReply"))
            {
                var response = jsonrpc.GetRequestResponseDeserialized<Response<string>>();
                if (response != null)
                    InteractReply = response.result;
            }

            return jsonrpc.Error;
        }
Пример #4
0
        /// <summary>
        /// Télécharge les informations sur les JdObject, les EqLogic et les Command (sans les value)
        /// </summary>
        /// <returns>Le code et le message d'erreur de Jeedom</returns>
        public async Task<Error> DownloadObjects()
        {
            var jsonrpc = new JsonRpcClient();
            EqLogicList.Clear();
            CommandList.Clear();
            ObjectList.Clear();

            if (await jsonrpc.SendRequest("object::full"))
            {
                //List<string> idList = new List<string>();
                var response = jsonrpc.GetRequestResponseDeserialized<Response<ObservableCollection<JdObject>>>();
                if (response != null)
                {
                    foreach (JdObject o in response.result)
                    {
                        ObjectList.Add(o);
                        //idList.Add("dmj" + o.id);
                        //UpdateObjectImage(o);
                        if (o.eqLogics != null)
                        {
                            foreach (EqLogic eq in o.eqLogics)
                            {
                                EqLogicList.Add(eq);
                                if (eq.cmds != null)
                                {
                                    foreach (Command cmd in eq.cmds)
                                    {
                                        cmd.Parent = eq;
                                        CommandList.Add(cmd);
                                    }
                                }
                                else
                                    eq.cmds = new ObservableCollection<Command>();
                            }
                        }
                    }

                    JdObject fakeobj = new JdObject();
                    fakeobj.name = "Autres";
                    //UpdateObjectImage(fakeobj);
                    ObjectList.Add(fakeobj);
                    fakeobj.eqLogics = new ObservableCollection<EqLogic>();

                    // Récupère les EqLogic du fake (object_id==null)
                    if (await jsonrpc.SendRequest("eqLogic::byObjectId"))
                    {
                        var responseEqLogic = jsonrpc.GetRequestResponseDeserialized<Response<ObservableCollection<EqLogic>>>();
                        if (responseEqLogic != null)
                        {
                            foreach (EqLogic eq in responseEqLogic.result)
                            {
                                var param = new Parameters();
                                param.id = eq.id;
                                jsonrpc.SetParameters(param);
                                if (await jsonrpc.SendRequest("eqLogic::fullById"))
                                {
                                    var responseEq = jsonrpc.GetRequestResponseDeserialized<Response<EqLogic>>();
                                    if (responseEq.result?.cmds != null)
                                        eq.cmds = responseEq.result.cmds;
                                    else
                                        eq.cmds = new ObservableCollection<Command>();
                                    fakeobj.eqLogics.Add(eq);
                                    EqLogicList.Add(eq);
                                    foreach (Command cmd in eq.cmds)
                                    {
                                        CommandList.Add(cmd);
                                    }
                                }
                            }
                        }
                    }

                    // Efface les images inutiles
                    /*var files = await ImageFolder.GetFilesAsync();
                    foreach (StorageFile f in files)
                    {
                        if (!idList.Contains(f.DisplayName))
                        {
                            await f.DeleteAsync();
                        }
                    }*/
                }
            }

            return jsonrpc.Error;
        }