示例#1
0
        public void OnToken(object s, DTMFTokenBuildedEventArgs t_evt)
        {
            var debug_text = FindViewById <EditText>(Resource.Id.editText_Debug);

            RunOnUiThread(() => {
                debug_text.Text += "T" + t_evt.Token;
            });
        }
示例#2
0
        private void OnNewToken(object sender, DTMFTokenBuildedEventArgs edt)
        {
            lock (sync_object)
            {
                DAL dal = new DAL();
                List <Partition> particiones = dal.GetAllPartitions();
                if (edt.Token == prefs_model.Pin)
                {
                    prefs_model.Ready = !prefs_model.Ready;

                    if (prefs_model.Ready)
                    {
                        /*if(speech_engine_inited)
                         *                                              speech_synt.Speak("Alarma activada",QueueMode.Flush,null);*/
                        particiones.ForEach((p) => dal.UpdatePartitionState(p.Id, true));
                        NotifyEvent("Alarma Activada", "Todas las particiones activadas");
                        var h = new HistoryItem
                        {
                            Time          = DateTime.Now,
                            State         = Action.ACTION_ID_ACTIVATED,
                            PartitionName = "TODAS",
                            Detail        = "TODAS LAS PARTICIONES ACTIVADAS"
                        };
                        dal.RegiterEvent(h);
                        NotifyNewEvent(h);
                        //Ready=true;
                    }
                    else
                    {
                        /*if(speech_engine_inited)
                         *                                              speech_synt.Speak("Alarma desactivada",QueueMode.Flush,null);*/
                        particiones.ForEach((p) => dal.UpdatePartitionState(p.Id, false));
                        NotifyEvent("Alarma Desactivada", "Todas las particiones desactivadas");
                        var h = new HistoryItem
                        {
                            Time          = DateTime.Now,
                            State         = Action.ACTION_ID_DESACTIVATED,
                            PartitionName = "TODAS",
                            Detail        = "TODAS LAS PARTICIONES DESACTIVADAS"
                        };
                        dal.RegiterEvent(h);
                        NotifyNewEvent(h);
                    }
                }
                else
                {
                    var p = particiones.Find((part) => part.Code == edt.Token);
                    if (p != null)
                    {
                        string detail = "";
                        p.Zones = dal.GetPartitionsZones(p.Id);
                        if (p.Activated)
                        {
                            detail = "Particion Desactivada:" + "Particion " + p.Name + " Desactivada";
                            NotifyEvent("Particion Desactivada", "Particion " + p.Name + " Desactivada");
                            var h = new HistoryItem {
                                Time = DateTime.Now, State = Action.ACTION_ID_DESACTIVATED, PartitionName = p.Name, Detail = detail
                            };
                            dal.RegiterEvent(h);
                            NotifyNewEvent(h);
                            p.Activated = false;
                            dal.UpdatePartitionState(p.Id, false);
                            if (particiones.Find((part) => part.Activated) == null)
                            {
                                prefs_model.Ready = false;
                            }
                        }
                        else
                        {
                            detail = "Particion Activada:" + "Particion " + p.Name + " Activada";
                            NotifyEvent("Particion Activada", "Particion " + p.Name + " Activada");
                            p.Activated = true;
                            dal.UpdatePartitionState(p.Id, false);
                            var h = new HistoryItem {
                                Time = DateTime.Now, State = Action.ACTION_ID_ACTIVATED, PartitionName = p.Name, Detail = detail
                            };
                            dal.RegiterEvent(h);
                            NotifyNewEvent(h);
                            prefs_model.Ready = false;
                        }
                    }
                    else
                    {
                        var z = (edt.Token.All(cp => cp == edt.Token[0])) ? dal.GetZoneByCode(edt.Token[0].ToString()) : null;
                        if (z != null)
                        {
                            p = particiones.Find((part) => part.Id == z.PartitionId);
                            if (!z.Fired && p.Activated)
                            {
                                if ((DateTime.Now - p.ChangeStateTime) >= new TimeSpan(0, 0, prefs_model.Time_To_GO))
                                {
                                    var due_time = (z.Inmediate ? 0 : prefs_model.Time_To_IN * 1000);
                                    var timer    = new System.Threading.Timer((o) => {
                                        Partition particion = o as Partition;
                                        var zone            = particion.Zones[0];

                                        particion = dal.GetPartitionByName(p.Name);
                                        if (particion.Activated)
                                        {
                                            prefs_model.Fired = true;
                                            zone.Fired        = true;
                                            dal.UpdateZoneState(zone.Id, true);
                                            string message = "Sensor: " + z.Name + ".Partición: " + particion.Name + ".Hora:" + DateTime.Now.ToShortTimeString();
                                            var h          = new HistoryItem {
                                                Time = DateTime.Now, State = Action.ACTION_ID_FIRED, PartitionName = particion.Name, Detail = message
                                            };
                                            dal.RegiterEvent(h);
                                            NotifyNewEvent(h);
                                            Intent intent = new Intent("DroidVigia.DroidVigia.DroidVigia.ToneDetected");
                                            intent.PutExtra("message", message);
                                            SendBroadcast(intent);
                                            if (!Notificando)
                                            {
                                                Notificando = true;
                                            }
                                        }
                                    }, new Partition {
                                        Id = p.Id, Name = p.Name, Activated = p.Activated, ChangeStateTime = p.ChangeStateTime, Zones = new List <Zone> {
                                            z
                                        }
                                    }, due_time, -1);
                                }
                            }
                        }
                    }
                }
            }
            if (NewToken != null)
            {
                try
                {
                    NewToken.BeginInvoke(null, edt, null, null);
                }
                catch { }
            }
        }