private void ChatClient_CallRecieved(object sender, EventArgs e)
        {
            if (!Dispatcher.CheckAccess())
            {
                Dispatcher.Invoke(delegate { ChatClient_CallRecieved(sender, e); });
                return;
            }
            var address = (string)sender;
            var args = e as ServerEventArgs;
            if (args == null)
                return;

            callForm = new CallForm(args.Message, FormType.Incoming);
            var dialogResult = callForm.ShowDialog() == true
                ? Command.AcceptCall : Command.CancelCall;
            ChatClient.AnswerIncomingCall(args.Message, address, dialogResult);
            switch (dialogResult)
            {
                case Command.AcceptCall:
                    callForm = new CallForm(args.Message, FormType.Conversation);
                    StartConversation();
                    break;
                case Command.CancelCall:
                    callForm.Close();
                    break;
            }
        }
        private void ChatClient_FileRecieved(object sender, EventArgs e)
        {
            if (!Dispatcher.CheckAccess())
            {
                RecieveMessage r = ChatClient_FileRecieved;
                Dispatcher.Invoke(r, sender, e);
            }
            else
            {
                var args = (FileEventArgs) e;

                var page = FindTabPage(args.From) ?? AddTabPage(args.From);
                var time = DateTime.Now.ToString("HH:mm:ss");

                var window = new CallForm(args.From, FormType.File);
                var result = window.ShowDialog();
                string strResult;

                if (result == true)
                {
                    strResult = string.Format(ChatHelper.TRANSFERED,args.FileName);

                    var saveDialog = new SaveFileDialog
                    {
                        FileName = args.FileName,
                        AddExtension = true,
                        DefaultExt = args.Extenstion,
                        Filter = ChatHelper.FILE_FILTER_ALL
                    };

                    if (saveDialog.ShowDialog(this) == true)
                    {
                        File.WriteAllBytes(saveDialog.FileName, args.File);
                    }
                }
                else
                {
                    strResult = ChatHelper.TRANSFER_CANCELED;
                }
                page.DialogBox.AppendText(string.Format("[{0}] {1}", time, strResult));
                page.DialogBox.AppendText(Environment.NewLine);
            }
        }
 private void call_Click(object sender, RoutedEventArgs e)
 {
     var currentTabPage = tbChat.SelectedItem as ChatTabItem;
     if (currentTabPage != null && (string) currentTabPage.Header != ChatHelper.GLOBAL)
     {
         var user = (string) currentTabPage.Header;
         callForm = new CallForm(user, FormType.Outcoming);
         ChatClient.SendChatRequest(user);
     }
     callForm.ShowDialog();
     if (callForm.DialogResult == true)
         ChatClient.SendResponse(Command.EndCall);
 }