Ejemplo n.º 1
0
        public ConfigUserControlViewModel(IDataService dataService, IDlgService dialogService)
        {
            _dialogService = dialogService;
            _dataService   = dataService;
            _dataService.GetAppData((cfg, error) =>
            {
                JData = cfg;
            });

            CfgAdd = new RelayCommand(() => {
                _config.Nbxs.Add(new AppDataConfig.JSonNbxConfig()
                {
                    Ip = "127.0.0.1", RadioWp = 8000
                });
                RaisePropertyChanged("JData");
            });

            CfgDel = new RelayCommand(() => {
                Int32 iborrar = SelectedIndex;
                if (iborrar >= 0)
                {
                    _dialogService.Confirm("¿Desea eliminar el item seleccionado?", (res) =>
                    {
                        if (res)
                        {
                            _config.Nbxs.RemoveAt(iborrar);
                            RaisePropertyChanged("JData");
                        }
                    });
                }
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(IDataService dataService, IDlgService dlgService, ISipPresenceService sipPresenceService)
        {
            _dataService        = dataService;
            _dlgService         = dlgService;
            _sipPresenceService = sipPresenceService;
            _log = new LogService();

            _sipPresenceService.OptionsReceived += (from) =>
            {
                _log.From().Info($"Options received from {from}");
            };

            _sipPresenceService.SubscribeReceived += (from) =>
            {
                RaisePropertyChanged("UIUsers");
                _log.From().Info($"Subscribe received from {from}");
            };

            _sipPresenceService.Configure(_dataService, (data, err) =>
            {
                if (err != null)
                {
                    WelcomeTitle = err.Message;
                    return;
                }
                //dataConfig = data;

                _sipPresenceService.Start((err1) =>
                {
                    if (err1 != null)
                    {
                        WelcomeTitle = err.Message;
                    }
                    else
                    {
                        WelcomeTitle = $"SimPresenciaSip. Nucleo 2018. Listen at {data.ListenIp}:{data.ListenPort}";
                    }
                });
            });


            /** Programacion de los comandos UI */
            AppExit = new RelayCommand(() =>
            {
                _dlgService.Confirm("¿Desea Salir de la Aplicacion?", (res) =>
                {
                    if (res)
                    {
                        System.Windows.Application.Current.Shutdown();
                    }
                }, WelcomeTitle);
            });

            AppStartStop = new RelayCommand(() =>
            {
            });

            AppAddUser = new RelayCommand(() =>
            {
                if (NewUserName == string.Empty)
                {
                    Messenger.Default.Send <ModelEvent>(new ModelEvent(ModelEvents.Message)
                    {
                        Data = "El Nombre de Usuario no puede estar vacio"
                    });
                }
                else if (_dataService.UserExist(NewUserName) == true)
                {
                    Messenger.Default.Send <ModelEvent>(new ModelEvent(ModelEvents.Message)
                    {
                        Data = $"Nombre de Usuario <{NewUserName}> repetido..."
                    });
                }
                else
                {
                    _dlgService.Confirm($"¿Desea añadir el usuario {NewUserName}?", (res) =>
                    {
                        if (res)
                        {
                            UserInfo newuser = new UserInfo()
                            {
                                Id = NewUserName, Status = ""
                            };
                            Messenger.Default.Send <ModelEvent>(new ModelEvent(ModelEvents.Register)
                            {
                                Data = newuser
                            });
                        }
                    }, WelcomeTitle);
                }
            });

            /** Gestor de Mensajes... */
            Messenger.Default.Register <ModelEvent>(this, (ev) =>
            {
                switch (ev.Event)
                {
                case ModelEvents.Message:
                    Task.Factory.StartNew(() =>
                    {
                        var msg = ev.Data as string;
                        System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(() =>
                        {
                            SystemMessage = msg;
                            Task.Delay(5000).Wait();
                            SystemMessage = "";
                        });
                    });
                    break;

                case ModelEvents.Register:
                    _sipPresenceService.AddUser((ev.Data as UserInfo).Id);
                    RaisePropertyChanged("UIUsers");
                    break;

                case ModelEvents.Unregister:
                    _dlgService.Confirm($"¿Desea eliminar el usuario {(ev.Data as UserInfo).Id}?", (res) =>
                    {
                        if (res)
                        {
                            _sipPresenceService.RemoveUser((ev.Data as UserInfo).Id);
                            RaisePropertyChanged("UIUsers");
                        }
                    }, WelcomeTitle);
                    break;

                case ModelEvents.StatusChange:
                    break;

                case ModelEvents.SessionOpen:
                    break;

                case ModelEvents.SessionClose:
                    break;
                }
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel(IDataService dataService, IDlgService dlgService)
        {
            _dataService = dataService;
            _dlgService = dlgService; 

            /** */
            _dataService.GetAppConfig((cfg, x) =>
            {
                Title = $"Simulador WS Brekeke. Nucleo 2018. Listening at {cfg.Ip}:{cfg.Port}...";

                _wss = new BkkWebSocketServer(cfg.Ip, cfg.Port);
                _wss.Start();
                _wss.Activate(_dataService);
            });

            IsStarted = true;
            NewUserName = "";
            OpenSessions = 0;

            /** Programacion de los comandos UI */
            AppExit = new RelayCommand(() =>
            {
                _dlgService.Confirm("¿Desea Salir de la Aplicacion?", (res) =>
                {
                    if (res)
                    {
                        if (IsStarted)
                        {
                            _wss.Deactivate();
                            _wss.Stop();
                        }

                        _dataService.SaveWorkingUsers(null);
                        System.Windows.Application.Current.Shutdown();
                    }
                }, Title);
            });

            AppStartStop = new RelayCommand(() =>
            {
            });

            AppAddUser = new RelayCommand(() =>
            {
                if (NewUserName == string.Empty)
                {
                    Messenger.Default.Send<BkkSimEvent>(new BkkSimEvent(ModelEvents.Message) { Data = "El Nombre de Usuario no puede estar vacio"});
                }
                else if (_dataService.WorkingUserExist(NewUserName) == true)
                {
                    Messenger.Default.Send<BkkSimEvent>(new BkkSimEvent(ModelEvents.Message) { Data = $"Nombre de Usuario <{NewUserName}> repetido..."});
                }
                else
                {
                    _dlgService.Confirm($"¿Desea añadir el usuario {NewUserName}?", (res) =>
                    {
                        if (res)
                        {
                            WorkingUser newuser = new WorkingUser() { Name = NewUserName, /*Registered = true, */Status = UserStatus.Disconnect };
                            Messenger.Default.Send<BkkSimEvent>(new BkkSimEvent(ModelEvents.Register) { Data = newuser });
                        }
                    }, Title);
                }
            });

            /** Gestor de Mensajes... */
            Messenger.Default.Register<BkkSimEvent>(this, (ev) =>
            {
                switch (ev.Event)
                {
                    case ModelEvents.Message:
                        Task.Factory.StartNew(() =>
                        {
                            var msg = ev.Data as string;
                            System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(() =>
                            {
                                SystemMessage = msg;
                                Task.Delay(5000).Wait();
                                SystemMessage = "";
                            });
                        });
                        break;

                    case ModelEvents.Register:
                        _dataService.AddWorkingUser((ev.Data as WorkingUser).Name, null);
                        _wss.UpdateUser((ev.Data as WorkingUser).Name, true, false);
                        RaisePropertyChanged("UIUsers");
                        break;

                    case ModelEvents.Unregister:
                        _dlgService.Confirm($"¿Desea eliminar el usuario {(ev.Data as WorkingUser).Name}?", (res) =>
                        {
                            if (res)
                            {
                                _wss.InformUserUnregistered((ev.Data as WorkingUser).Name);
                                _dataService.DelWorkingUser((ev.Data as WorkingUser).Name, null);
                                RaisePropertyChanged("UIUsers");
                            }
                        }, Title);
                        break;

                    case ModelEvents.StatusChange:
                        _wss.UpdateUser((ev.Data as WorkingUser).Name, false, true);
                        break;

                    case ModelEvents.SessionOpen:
                        OpenSessions = OpenSessions + 1;
                        break;

                    case ModelEvents.SessionClose:
                        OpenSessions = OpenSessions - 1;
                        break;
                }
            });

        }