Ejemplo n.º 1
0
        private CommonResource()
        {
            this.Clients = new ObservableCollection <Client>();
            this.Actions = new ClientActionQueue();

            LoadPhones();

            // Load UnitPhone from database
            this.UnitPhones = new ObservableCollection <UnitPhoneViewModel>();
            this.UnitPhones.CollectionChanged += Resource_CollectionChanged;
            foreach (var item in NovaAlertCommon.LoadUnitPhones())
            {
                this.UnitPhones.Add(new UnitPhoneViewModel(item));
            }

            // Load PO list
            this.POes = new List <POViewModel>();
            foreach (var po in NovaAlertCommon.GetPOes())
            {
                this.POes.Add(new POViewModel(po));
            }

            // Connection
            this.Connetions    = new ObservableCollection <SwitchConnection>();
            this.SoundChannels = new List <SoundChannel>();
            this.SoundConfigVM = new SoundCardConfigViewModel(this.CreateSoundChannels);

            NovaAlertCommon.Instance.OnContactChanged += OnContactChanged;
        }
Ejemplo n.º 2
0
        public List <IResource> GetResource(eResourceType type, int id)
        {
            var list = new List <IResource>();

            if (type == eResourceType.Channel)
            {
                list.AddRange(this.Channels.Where(c => c.Id == id));
            }
            else if (type == eResourceType.UnitPhone)
            {
                list.AddRange(this.UnitPhones.Where(p => p.Id == id));
                if (list.Count == 0)
                {
                    var units = NovaAlertCommon.LoadUnitPhones(id);
                    if (units.Count > 0)
                    {
                        foreach (var p in units)
                        {
                            var vm = new UnitPhoneViewModel(p);
                            this.UnitPhones.Add(vm);
                            list.Add(vm);
                        }
                    }
                }
            }
            else if (type == eResourceType.Modem)
            {
                list.Add(this.Modem);
            }

            return(list);
        }
Ejemplo n.º 3
0
        // Load Channels from database
        public void LoadPhones()
        {
            bool isReload = false;

            if (this.Channels != null)
            {
                this.Channels.Clear();
                isReload = true;
            }
            else
            {
                this.Channels = new ObservableCollection <HostPhoneViewModel>();
                this.Channels.CollectionChanged += Resource_CollectionChanged;
            }

            foreach (var item in NovaAlertCommon.LoadPhones())
            {
                this.Channels.Add(new HostPhoneViewModel(item));
            }

            if (isReload)
            {
                SendReloadEvent();
            }
        }
Ejemplo n.º 4
0
        void INovaAlertService.UpdateTask(int unitId, Task task, long?duration, eTaskType taskType)
        {
            var unit = _resources.UnitPhones.FirstOrDefault(u => u.Id == unitId);

            if (unit != null)
            {
                unit.Task.TaskObj = task;

                NovaAlertCommon.UpdateTask(unit.UnitPhone, duration, taskType);

                // Cap nhat bang den
                if (GlobalSetting.Instance.UseSwitchPortForLP)
                {
                    SerialComm.SendAllResultBySwitchComm(unit.UnitPhone.PhoneNumberId);
                }
                else
                {
                    SerialComm.LPComm.SendAllResults(unit.UnitPhone.PhoneNumberId);
                }

                foreach (var c in _resources.GetActiveClients())
                {
                    try
                    {
                        c.Callback.OnTaskChanged(new TaskChangedEventArgs(unitId, task));
                    }
                    catch (CommunicationObjectAbortedException ex)
                    {
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
        }
Ejemplo n.º 5
0
        List <UnitPhone> INovaAlertService.GetUnitPhones(int?groupId, eTaskType taskType, bool includeTask)
        {
            if (groupId.HasValue)
            {
                List <UnitPhone> list = new List <UnitPhone>();
                var ids = NovaAlertCommon.GetUnitsInGroup(groupId.Value);
                foreach (var u in _resources.UnitPhones)
                {
                    var g = ids.FirstOrDefault(gu => gu.UnitId == u.Id);
                    if (g != null)
                    {
                        var up = new UnitPhone(u.Id, u.Name)
                        {
                            PhoneNumberId = u.PhoneNumberId,
                            AreaCode      = u.AreaCode,
                            Number        = u.Number,
                            Password      = u.Password,
                            ListOrder     = g.ListOrder,
                        };

                        if (includeTask)
                        {
                            up.Task = NovaAlertCommon.GetLastestTask(u.PhoneNumberId, taskType);
                        }

                        list.Add(up);
                    }
                }
                return(list);
            }
            else
            {
                return(_resources.UnitPhones.Select(vm => vm.Phone).OfType <UnitPhone>().ToList());
            }
        }
Ejemplo n.º 6
0
        void OnContactChanged(object sender, EntityChangedEventArgs e)
        {
            var list = this.UnitPhones.Where(u => u.Id == e.Id).ToList();

            foreach (var up in list)
            {
                this.UnitPhones.Remove(up);
            }

            foreach (var item in NovaAlertCommon.LoadUnitPhones(e.Id))
            {
                this.UnitPhones.Add(new UnitPhoneViewModel(item));
            }
        }
Ejemplo n.º 7
0
        public static void SendResults(IPresentation pre, byte address, eTaskType taskType, int phoneNumberId = 0)
        {
            lock (_staticSyncObj)
            {
                var dbResults = NovaAlertCommon.GetResults(taskType, phoneNumberId);

                for (int i = 0; i < dbResults.Count; i++)
                {
                    var item = dbResults[i];
                    var msg  = new LP_ResultMessage()
                    {
                        TypeDest = eDevice.LedPanel,
                        Address  = address,
                        Id       = (byte)item.DisplayId,
                        Alert    = (byte)item.Task,
                        Level    = (byte)item.Level
                    };

                    if (item.TimeReceive.HasValue && item.TimeChange.HasValue)
                    {
                        msg.Result = 3;
                    }
                    else
                    {
                        if (item.TimeChange.HasValue)
                        {
                            msg.Result = 2;
                        }
                        else
                        {
                            if (item.TimeReceive.HasValue)
                            {
                                msg.Result = 1;
                            }
                        }
                    }

                    pre.SendData(msg);
                    System.Threading.Thread.Sleep(51);
                }
            }
        }
Ejemplo n.º 8
0
        UnitPhone INovaAlertService.GetUnitPhone(int id, eTaskType taskType)
        {
            var item = _resources.UnitPhones.FirstOrDefault(u => u.Id == id);

            if (item != null)
            {
                var unit = item.UnitPhone;
                return(new UnitPhone(unit.Id, unit.Name)
                {
                    PhoneNumberId = unit.PhoneNumberId,
                    AreaCode = unit.AreaCode,
                    Number = unit.Number,
                    Password = unit.Password,
                    ListOrder = unit.ListOrder,
                    Task = NovaAlertCommon.GetLastestTask(unit.PhoneNumberId, taskType)
                });
            }

            return(null);
        }
 List <ResultData> INovaAlertConfigService.GetSubResults(int phoneNumberId, eTaskType type)
 {
     return(NovaAlertCommon.GetSubResults(phoneNumberId, type));
 }
 void INovaAlertConfigService.SaveDisplayData(List <DisplayData> list)
 {
     NovaAlertCommon.SaveDisplayData(list);
 }
 List <DisplayData> INovaAlertConfigService.GetDisplayData()
 {
     return(NovaAlertCommon.GetDisplayData());
 }
 List <ResultData> INovaAlertConfigService.GetResults(eTaskType taskType)
 {
     return(NovaAlertCommon.GetResults(taskType));
 }
Ejemplo n.º 13
0
        List <BaseEntity> INovaAlertService.GetAllGroups()
        {
            var list = NovaAlertCommon.GetAllGroups();

            return(list.Select(g => new BaseEntity(g.GroupId, g.Name)).ToList());
        }
Ejemplo n.º 14
0
        public void WaitAndReplyCommandFromServer(Func <bool> act)
        {
            this.Modem.SelectedPanelId = 255;

            LogService.Logger.Info("Client: start waiting for server");
            System.Diagnostics.Debug.WriteLine("Client start waiting command from server");
            var  ret      = this.Modem.WaitForTSLResult(TSL_WaitTime * 6);
            bool done     = false;
            int  curIndex = 0;

            while (ret != null && !done)
            {
                if (ret is TSL_Message)
                {
                    var r_msg = ret as TSL_Message;
                    LogService.Logger.Info(string.Format("Client: receive {0}", r_msg.Control));

                    if (r_msg.Control == eControl.TSL_ENQ)
                    {
                        ret = this.Modem.SendTSLMessageAndWaitForResult(new TSL_Message()
                        {
                            Control = eControl.ACK
                        }, TSL_WaitTime);
                    }
                    else if (r_msg.Control == eControl.TSL_Prepare)
                    {
                        bool ack = (act != null) ? act() : false;

                        if (ack)
                        {
                            this.SendMessage(eControl.ACK);
                        }
                        else
                        {
                            this.SendMessage(eControl.NAK);
                        }
                    }
                    else if (r_msg.Control == eControl.TSL_ResultRequest)
                    {
                        // send result
                        List <Entities.ResultData> results = null;
                        if (results == null)
                        {
                            results = NovaAlertCommon.GetResults(Entities.eTaskType.CTT);
                        }

                        if (curIndex < results.Count)
                        {
                            var obj = results[curIndex++];
                            this.Modem.SendMessage(obj);
                        }
                        else
                        {
                            this.SendMessage(eControl.TSL_ResultEnd);
                        }
                    }
                    else if (r_msg.Control == eControl.TSL_EOT)
                    {
                        done = true;
                    }

                    ret = this.Modem.WaitForTSLResult(TSL_WaitTime);
                }
                else
                {
                    LogService.Logger.Info("Client: receive undefined message");
                }
            }

            this.Modem.HangUp();
            this.Modem.ClearBuffer();
            this.Modem.SelectedPanelId = null;
        }
Ejemplo n.º 15
0
 public void TestGetSubResult()
 {
     var list = NovaAlertCommon.GetSubResults(1, NovaAlert.Entities.eTaskType.CTT);
 }