Example #1
0
        public async Task RunAsync()
        {
            ShowHelp(true);
            while (true)
            {
                var command = System.Console.ReadLine();
                if (command == null)
                {
                    continue;
                }
                if (command == "/help")
                {
                    ShowHelp();
                }
                else if (command == "/quit")
                {
                    await _host.StopAsync();
                }
                else if (command.StartsWith("/login"))
                {
                    var match = Regex.Match(command, @"/login (?<userId>\w{1,100})");
                    if (match.Success)
                    {
                        _userId    = match.Groups["userId"].Value;
                        _userGrain = _client.GetGrain <IUserGrain>(_userId);
                        if (_viewer == null)
                        {
                            _viewer = await _client.CreateObjectReference <IMessageViewer>(new MessageConsoleViewer());
                        }

                        await _userGrain.LoginAsync(_viewer);

                        System.Console.WriteLine($"The current user is now [{_userId}]");
                        var offlineMessages = await _userGrain.GetOfflineMessages();

                        System.Console.WriteLine($"Receive offline messages: {offlineMessages.Count}");
                        foreach (var message in offlineMessages)
                        {
                            System.Console.WriteLine($"Receive {message.TargetId}: {message.Content}");
                        }
                    }
                }
                else if (command.StartsWith("/send"))
                {
                    var match = Regex.Match(command, @"/send (?<userId>\w{1,100}) (?<message>.+)");
                    if (match.Success)
                    {
                        var targetUserId = match.Groups["userId"].Value;
                        var message      = match.Groups["message"].Value;
                        await _userGrain.SendMessageAsync(new TextMessage(_userId, targetUserId, message));

                        System.Console.WriteLine($"Send {targetUserId} the new message!");
                    }
                    else
                    {
                        System.Console.WriteLine("Invalid send. Try again or type /help for a list of commands.");
                    }
                }
            }
        }
 public DeleteEmployeeViewModel()
 {
     dataSource = new LocalDataSource();
     _viewer    = new MessageViewer();
     AffirmativeDeleteDelegateCommand = new DelegateCommand(canDeleteEmployee, DeleteEmployee);
     NegativeDeleteDelegateCommand    = new DelegateCommand(canGoBackToMainWindow, GoToMainWindow);
 }
Example #3
0
        public EmployeeViewModel()
        {
            dataSource = new LocalDataSource();
            _viewer    = new MessageViewer();

            empList = dataSource.GetAllItems();
        }
Example #4
0
        public async Task LoginAsync(IMessageViewer viewer)
        {
            State.Logined = true;
            State.Viewer  = viewer;
            await WriteStateAsync();

            Console.WriteLine($"{UserId} login success.");
        }
 void IMessageViewerPlugin.Create(MessageBase message, IMessageViewer messageViewer)
 {
     if (mvc == null)
     {
         mvc = new MessageViewerControl();
     }
     mvc.LoadData(message);
 }
Example #6
0
        public async Task LoginAsync(IMessageViewer viewer)
        {
            State.IsLogin = true;
            State.Viewer  = viewer;
            Console.WriteLine($"{UserId} login success, start dispatch unread messages.");
            while (State.UnReadMessages.Count > 0)
            {
                viewer.NewMessageAsync(State.UnReadMessages.Dequeue());
            }
            await WriteStateAsync();

            Console.WriteLine($"{UserId} login success.");
        }
Example #7
0
 public MsgHub()
 {
     this.Biz = ServiceLocator.Current.GetInstance <IMessageViewer>();
 }
Example #8
0
        public async Task RunAsync()
        {
            ShowHelp(true);
            while (true)
            {
                var command = System.Console.ReadLine();
                if (command == null)
                {
                    continue;
                }
                if (command == "/help")
                {
                    ShowHelp();
                }
                else if (command == "/quit")
                {
                    await _host.StopAsync();
                }
                else if (command == "/exit")
                {
                    System.Console.WriteLine($"Exit chat with {_targetUserId} =====================================================");
                    _targetUserId = string.Empty;
                    System.Console.ForegroundColor = ConsoleColor.White;
                }
                else if (command.StartsWith("/chat"))
                {
                    if (!IsLogin())
                    {
                        System.Console.ForegroundColor = ConsoleColor.Red;
                        System.Console.WriteLine("You need to login first");
                        System.Console.ForegroundColor = ConsoleColor.White;
                    }
                    var match = Regex.Match(command, @"/chat (?<userId>\w{1,100})");
                    if (match.Success)
                    {
                        _targetUserId = match.Groups["userId"].Value;
                        System.Console.WriteLine($"Start chat with {_targetUserId} =====================================================");
                    }
                }
                else if (command.StartsWith("/login"))
                {
                    if (IsLogin())
                    {
                        System.Console.ForegroundColor = ConsoleColor.Red;
                        System.Console.WriteLine("You have already login");
                        System.Console.ForegroundColor = ConsoleColor.White;
                        continue;
                    }
                    var match = Regex.Match(command, @"/login (?<userId>\w{1,100})");
                    if (match.Success)
                    {
                        _userId    = match.Groups["userId"].Value;
                        _userGrain = _client.GetGrain <IUserGrain>(_userId);
                        if (_viewer == null)
                        {
                            _viewer = await _client.CreateObjectReference <IMessageViewer>(new MessageConsoleViewer());
                        }
                        await _userGrain.LoginAsync(_viewer);

                        System.Console.Title = _userId;
                        System.Console.WriteLine($"The current user is now [{_userId}]");
                    }
                }
                else
                {
                    if (IsInChat())
                    {
                        await _userGrain.SendMessageAsync(Message.CreateText(_userId, _targetUserId, command));

                        System.Console.ForegroundColor = ConsoleColor.Yellow;
                        System.Console.WriteLine($"{_userId}: {command}");
                        System.Console.ForegroundColor = ConsoleColor.White;
                    }
                }
            }
        }
Example #9
0
 public ConsoleFileManager(IDirectory currentDirectory, IMessageViewer messageViewer)
     : base(currentDirectory, messageViewer)
 {
 }
Example #10
0
 protected FileManager(IDirectory currentDirectory, IMessageViewer messageViewer)
 {
     _currentDirectory = currentDirectory;
     _messageViewer    = messageViewer;
 }
Example #11
0
 public MsgHub() {
     this.Biz = ServiceLocator.Current.GetInstance<IMessageViewer>();
 }
 public EditEmployeeViewModel()
 {
     dataSource            = new LocalDataSource();
     _viewer               = new MessageViewer();
     UpdateDelegateCommand = new DelegateCommand(canEditEmployee, UpdateEmployee);
 }
 private void Init()
 {
     Employee            = new Employee();
     _viewer             = new MessageViewer();
     SaveDelegateCommand = new DelegateCommand(canAddEmployee, AddEmployee);
 }