Ejemplo n.º 1
0
        public void LaunchDemo()
        {
            Updating = true;
            // Active le mode démo
            config.SetDemoMode();

            // Charger les données json
            Version        = "Démo";
            LoadingMessage = "Chargement des Objets";
            var assembly = GetType().GetTypeInfo().Assembly;
            var stream   = assembly.GetManifestResourceStream("Jeedom.Demo.object.json");
            var sr       = new StreamReader(stream);

            ObjectList = JsonConvert.DeserializeObject <ObservableCollection <JeedomObject> >(sr.ReadToEnd());

            // Populate EqlogicList and CmdList
            EqLogicList.Clear();
            CommandList.Clear();
            //foreach (var obj in ObjectList)
            //{
            //	foreach (var eq in obj.EqLogics)
            //	{
            //		EqLogicList.Add(eq);
            //		foreach (var cmd in eq.Cmds)
            //		{
            //			CommandList.Add(cmd);
            //		}
            //	}
            //}

            LoadingMessage = "Chargement des Scénarios";
            stream         = assembly.GetManifestResourceStream("Jeedom.Demo.scenario.json");
            sr             = new StreamReader(stream);
            SceneList      = JsonConvert.DeserializeObject <ObservableCollection <Scene> >(sr.ReadToEnd());

            LoadingMessage = "Chargement des Messages";
            stream         = assembly.GetManifestResourceStream("Jeedom.Demo.message.json");
            sr             = new StreamReader(stream);
            MessageList    = JsonConvert.DeserializeObject <ObservableCollection <Message> >(sr.ReadToEnd());

            // Mise à jour des favoris
            PopulateFavoriteList();

            LoadingMessage = "Prêt";
            Updating       = false;
        }
Ejemplo n.º 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);
        }