Ejemplo n.º 1
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
            {
                await Windows.UI.ViewManagement.StatusBar.GetForCurrentView().HideAsync();
            }

            if (Frame.CanGoBack)
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
            else
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;

            this.Object = e.Parameter as JdObject;

            EqLogicList = this.Object.eqLogics;
            ObjectName = this.Object.name;
            ImagePath = this.Object.Image;

            var taskFactory = new TaskFactory(TaskScheduler.FromCurrentSynchronizationContext());
            await taskFactory.StartNew(() => DoWork(tokenSource), tokenSource.Token);

            base.OnNavigatedTo(e);
        }
Ejemplo n.º 2
0
        public async Task UpdateObject(JdObject obj)
        {
            var parameters = new Parameters();
            parameters.object_id = obj.id;
            var jsonrpc = new JsonRpcClient(parameters);

            if (await jsonrpc.SendRequest("eqLogic::byObjectId"))
            {
                var response = jsonrpc.GetRequestResponseDeserialized<Response<ObservableCollection<EqLogic>>>();
                if (response.result != null)
                {
                    foreach (EqLogic eqnew in response.result)
                    {
                        var lst = from e in EqLogicList where e.id == eqnew.id select e;
                        if (lst.Count() != 0)
                        {
                            var eqold = lst.First();
                            eqnew.cmds = eqold.cmds;
                            eqold = eqnew;
                        }
                        else
                        {
                            EqLogicList.Add(eqnew);
                            obj.eqLogics.Add(eqnew);
                        }
                        await UpdateEqLogic(eqnew);
                    }
                }
            }
        }
Ejemplo n.º 3
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;
        }