示例#1
0
        static void Main(string[] args)
        {
            TcpChannel channel = new TcpChannel();
            ChannelServices.RegisterChannel(channel, false);

            ClientApp clientApp = new ClientApp();

            PadiDstm.Init();
            //clientApp.PadiDstm.Fail("tcp://localhost:8089/Server");
            //clientApp.PadiDstm.Fail("tcp://localhost:8089/Server");
            //clientApp.PadiDstm.Recover("tcp://localhost:8089/Server");
            //clientApp.PadiDstm.Fail("tcp://localhost:8089/Server");
            //Console.WriteLine("About to recover");
            //clientApp.PadiDstm.Recover("tcp://localhost:8089/Server");
            //clientApp.PadiDstm.Recover("tcp://localhost:8089/Server");

            //clientApp.PadiDstm.Status();

            //clientApp.PadiDstm.Recover("tcp://localhost:8089/Server");
            //clientApp.PadiDstm.Freeze("tcp://localhost:8089/Server");
            //clientApp.PadiDstm.Freeze("tcp://localhost:8089/Server");
            //clientApp.PadiDstm.Fail("tcp://localhost:8089/Server");
            //clientApp.PadiDstm.Fail("tcp://localhost:8089/Server");
            //Console.WriteLine("After fail");

            //Console.ReadLine();
            //clientApp.transaction1();
            //clientApp.transaction2();

            Console.ReadLine();
            PadiDstm.Status();
            Console.ReadLine();
        }
示例#2
0
        private void CreateChat_Click(object sender, EventArgs e)
        {
            List <ActiveUser> users = new List <ActiveUser>();

            var  selectedUsers = listView1.SelectedItems;
            bool groupChat     = selectedUsers.Count > 1;

            for (var index = 0; index < selectedUsers.Count; index++)
            {
                foreach (var contact in _onlineUsers)
                {
                    if (contact.Username.Equals(selectedUsers[index].Text))
                    {
                        users.Add(contact);

                        break;
                    }
                }
            }


            string id     = CreateID(users);
            bool   exists = ClientApp.GetInstance().GetPendingChats().Contains(id) || ClientApp.GetInstance().GetChats().ContainsKey(id);

            if (users.Count == 1 && !exists)
            {
                IClientRem friend = (IClientRem)RemotingServices.Connect(typeof(IClientRem), users[0].Address);
                ClientApp.GetInstance().GetPendingChats().Add(id);
                RemoteChat chat = new RemoteChat();

                Task.Factory.StartNew(() =>
                {
                    try
                    {
                        friend.Invite(new ControlMessage(ClientApp.GetLoggedUser(), Client.ClientApp.GetLoggedUser().Username, chat, id));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Invitation Failed");
                        Console.WriteLine(e);
                    }
                    Console.WriteLine("success");
                });
            }
            else if (users.Count > 1 && !exists)
            {
                Form1 chatNameForm = new Form1();
                chatNameForm.ShowDialog();
                RemoteChat chat = new RemoteChat();

                foreach (var user in users)
                {
                    IClientRem friend = (IClientRem)RemotingServices.Connect(typeof(IClientRem), user.Address);

                    Task.Factory.StartNew(() =>
                    {
                        Console.WriteLine(@"Invitation sent to " + user.Username + " to join " + chatNameForm.GetText);
                        try
                        {
                            friend.Invite(new ControlMessage(ClientApp.GetLoggedUser(), chatNameForm.GetText, chat, id));
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Invitation Failed");
                            Console.WriteLine(e);
                        }
                        Console.WriteLine("success");
                    });
                }
            }
            else if (users.Count < 1)
            {
                MessageBox.Show("Please select a user of a group of users",
                                "No user was selected",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Chat already created or Invites sent", "Already Created",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
示例#3
0
 private void LogoutSession()
 {
     UnsubscribeServerNotifications();
     ClientApp.GetServer().LogoutUser(ClientApp.GetLoggedUser());
 }
示例#4
0
 private void UnsubscribeServerNotifications()
 {
     ClientApp.GetServer().NewUserHandler    -= new NewActiveUser(_newUserRepeater.Repeater);
     ClientApp.GetServer().LogoutUserHandler -= new LogoutActiveUser(_logoutUserRepeater.Repeater);
     Console.WriteLine(@"Client App unsubscribed with success");
 }
示例#5
0
 private void registerButton_Click(object sender, EventArgs e)
 {
     try
     {
         if (passwordBox.Text != textBox2.Text)
         {
             MessageBox.Show("Passwords do not match!", "Password", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else if (ClientApp.GetServer().RegisterUser(nicknameBox.Text, textBox2.Text, passwordBox.Text))
         {
             Console.WriteLine(@"Registration worked");
             ActiveUser newUser = ClientApp.GetServer().LoginUser(nicknameBox.Text, passwordBox.Text, ClientApp.GetInstance().Address);
             if (newUser != null)
             {
                 ClientApp.SetLoggedUser(newUser);
                 Console.WriteLine(@"Login worked");
                 this.Hide();
                 ClientApp.SetMainWindow(new MainWindow(newUser));
                 ClientApp.GetMainWindow().ShowDialog();
             }
         }
         else
         {
             MessageBox.Show("8 characters minimum;" + Environment.NewLine + "Can not have white spaces, <, >, \' or \"", "Password Rules", MessageBoxButtons.OK);
         }
     }
     catch (Exception ex)
     {
         ClientApp.LaunchServerError(ex.Message);
     }
 }
示例#6
0
 private void loginButton_Click(object sender, EventArgs e)
 {
     try
     {
         ActiveUser newUser = ClientApp.GetServer().LoginUser(nicknameBox.Text, passwordBox.Text, ClientApp.GetInstance().Address);
         if (newUser != null)
         {
             ClientApp.SetLoggedUser(newUser);
             Console.WriteLine(@"Login worked");
             this.Hide();
             ClientApp.SetMainWindow(new MainWindow(newUser));
             ClientApp.GetMainWindow().ShowDialog();
         }
         else
         {
             MessageBox.Show("Login Failed: Be sure that you were registred with those credentials",
                             "Login Failed",
                             MessageBoxButtons.OK, MessageBoxIcon.Information);
             nicknameBox.Text = "";
             passwordBox.Text = "";
         }
     }
     catch (Exception ex)
     {
         ClientApp.LaunchServerError(ex.Message);
     }
 }
示例#7
0
 public void RejectChat(ActiveUser user, string chatName, string id)
 {
     ClientApp.GetInstance().GetPendingChats().Remove(id);
     ClientApp.GetMainWindow().RejectedChat(user, chatName);
 }