コード例 #1
0
ファイル: Program.cs プロジェクト: LYP951018/FunnyThings
        public static void Main(string[] args)
        {
            var client = new ChatClient();
            client.OnGotInfo += (o, e) =>
            {
                foreach (var f in e.OnlineUsers)
                    Console.WriteLine(f);
            };
            client.OnGotMessage += (o, e) =>
                Console.WriteLine($"Got message fron {e.SourceId}! {e.ChatContent}");
            client.OnGotError += (o, e) =>
            {
                if (e.Error == ErrorKind.DuplicateId)
                    Console.WriteLine("Duplicated ID!");
            };
            client.Start();
            while(true)
            {
                try
                {
                    Console.WriteLine("Input ID!");
                    var idStr = Console.ReadLine();
                    var id = Int32.Parse(idStr);
                    client.LogOn(id).Wait();
                    break;
                }
                catch(AggregateException e)
                {
                    e.Handle(ex => ex is DuplicateIdException);
                }
            }

            while (true)
            {
                var input = Console.ReadLine();
                try
                {
                    var m = Regex.Match(input, @"^\s*(?<command>\S*)");
                    if (m.Success)
                    {
                        var collection = m.Groups["command"];
                        switch (collection.ToString())
                        {
                            case "sendto":
                                var subStr = input.Substring(m.Index + "sendto".Length);
                                var m2 = Regex.Match(subStr, @"\s*(?<id>\d+)\s+(?<message>.*)");
                                if (m2.Success)
                                {
                                    client.Chat(Int32.Parse(m2.Groups["id"].ToString()), m2.Groups["message"].ToString());
                                }
                                break;
                            default:
                                Console.WriteLine("Unsupported!");
                                break;
                        }
                    }
                }
                finally { }
            }
        }
コード例 #2
0
        public Window1()
        {
            InitializeComponent();
            txtLog.Document.Blocks.Clear();
            _client = new ChatClient();
            ChatClient.StatusChanged += new StatusChangedEventHandler(mainServer_StatusChanged);

            addSmileyWindow = new AddSmileyWindow(this);
            addSmileyWindow.addSmileysToGrid(smileyClass.getAllSmileys());
        }
コード例 #3
0
 private async void OnLogOn()
 {
     var client = new ChatClient();
     await client.StartAsync();
     try
     {
         var info = await client.LogOn(int.Parse(_userIdInput));
         var current = Application.Current.MainWindow;
         var mainVM = new MainViewModel(client, info);
         var mainWindow = new MainWindow();
         Application.Current.MainWindow = mainWindow;
         mainWindow.DataContext = mainVM;
         current.Close();
         mainWindow.Show();
     }
     catch (DuplicateIdException)
     {
     }
 }
コード例 #4
0
        public MainViewModel(ChatClient client, LogOnRequestResult result)
        {
            _client = client;
            UserId = client.UserId;

            foreach (var u in result.OnlineUsers)
                if (u != UserId)
                    Messages.Add(new ChatMessages(u));

            _client.OnGotMessage += (o, e) =>
            {
                Action del = () =>
                {
                    foreach (var item in Messages)
                    {
                        if (item.DestUserId == e.SourceId)
                            item.Messages.Add(new Message(e.SourceId, e.ChatContent));
                    }
                };

                Application.Current.Dispatcher.BeginInvoke(del);
            };

            _client.OnGotNewBody += (o, e) =>
            {
                Action del = () =>
                Messages.Add(new ChatMessages(e.NewUserId));
                Application.Current.Dispatcher.BeginInvoke(del);
            };

            SendCommand = new DelegateCommand(() =>
            {
                var current = Messages[CurrentIndex];
                _client.Chat(current.DestUserId, MessageToSend);
                current.Messages.Add(new Message(UserId, MessageToSend));
            },
                () => MessageToSend != string.Empty);
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: 20chan/SimpleChat
 public Form1()
 {
     InitializeComponent();
     this.Client             = new ChatClient();
     this.Client.ChatUpdate += new ChatClient.ChatboxUpdate(listBox1_Update);
 }
コード例 #6
0
 public MainWindow()
 {
     InitializeComponent();
     Client = new ChatClient();
 }