コード例 #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.");
                    }
                }
            }
        }
コード例 #2
0
 public DeleteEmployeeViewModel()
 {
     dataSource = new LocalDataSource();
     _viewer    = new MessageViewer();
     AffirmativeDeleteDelegateCommand = new DelegateCommand(canDeleteEmployee, DeleteEmployee);
     NegativeDeleteDelegateCommand    = new DelegateCommand(canGoBackToMainWindow, GoToMainWindow);
 }
コード例 #3
0
        public EmployeeViewModel()
        {
            dataSource = new LocalDataSource();
            _viewer    = new MessageViewer();

            empList = dataSource.GetAllItems();
        }
コード例 #4
0
ファイル: UserGrain.cs プロジェクト: qq804127638/Chang-Fei
        public async Task LoginAsync(IMessageViewer viewer)
        {
            State.Logined = true;
            State.Viewer  = viewer;
            await WriteStateAsync();

            Console.WriteLine($"{UserId} login success.");
        }
コード例 #5
0
 void IMessageViewerPlugin.Create(MessageBase message, IMessageViewer messageViewer)
 {
     if (mvc == null)
     {
         mvc = new MessageViewerControl();
     }
     mvc.LoadData(message);
 }
コード例 #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.");
        }
コード例 #7
0
 public MsgHub()
 {
     this.Biz = ServiceLocator.Current.GetInstance <IMessageViewer>();
 }
コード例 #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;
                    }
                }
            }
        }
コード例 #9
0
 public ConsoleFileManager(IDirectory currentDirectory, IMessageViewer messageViewer)
     : base(currentDirectory, messageViewer)
 {
 }
コード例 #10
0
 protected FileManager(IDirectory currentDirectory, IMessageViewer messageViewer)
 {
     _currentDirectory = currentDirectory;
     _messageViewer    = messageViewer;
 }
コード例 #11
0
ファイル: MsgHub.cs プロジェクト: gruan01/MessageCenter
 public MsgHub() {
     this.Biz = ServiceLocator.Current.GetInstance<IMessageViewer>();
 }
コード例 #12
0
 public EditEmployeeViewModel()
 {
     dataSource            = new LocalDataSource();
     _viewer               = new MessageViewer();
     UpdateDelegateCommand = new DelegateCommand(canEditEmployee, UpdateEmployee);
 }
コード例 #13
0
 private void Init()
 {
     Employee            = new Employee();
     _viewer             = new MessageViewer();
     SaveDelegateCommand = new DelegateCommand(canAddEmployee, AddEmployee);
 }