示例#1
0
        public Friend acceptFriendRequest(Friend friend)
        {
            try
            {
                friend.SucessorSwarm = true;
                ServerApp._user.addFriend(friend);
                //ServerApp._user.PendingFriends.Remove(friend);
            }
            catch (DuplicatePendingFriendException ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                return null;
            }

            ClientServices client = (ClientServices)Activator.GetObject(typeof(ClientServices),
               ServerApp._clientUri + "/" + ServicesNames.ClientServicesName);

            RemoteAsyncFriendDelegate del = new RemoteAsyncFriendDelegate(client.acceptFriendRequest);

            del.BeginInvoke(friend, null, null);

            string[] myUris = { ServerApp._primaryURI };//, ServerApp._replicaOneURI, ServerApp._replicaTwoURI };

            return new Friend(ServerApp._user.Username, new List<string>(myUris));
        }
示例#2
0
        public Friend acceptFriendRequest(Friend friend)
        {
            ClientServices client;

            if (!ServerApp._serviceAvailable)
            {
                client = ((ClientServices)Activator.GetObject(typeof(ClientServices),
                    ServerApp._clientUri + "/" + ServicesNames.ClientServicesName));
                new RemoteAsyncServiceUnavailableDelegate(client.serviceUnavailable).BeginInvoke(null, null);
                return null;
            }

            string friendUri = friend.Uris.ElementAt(0);

            string[] myUris = { ServerApp._primaryURI};//, ServerApp._replicaOneURI, ServerApp._replicaTwoURI };

            Friend user = new Friend(ServerApp._user.Username, new List<string>(myUris));

            ServerToServerServices server = (ServerToServerServices)Activator.GetObject(
                                typeof(ServerToServerServices),
                                friendUri + "/" + ServicesNames.ServerToServerServicesName);

            AsyncCallback remoteCallback = new AsyncCallback(remoteAsyncAcceptFriendRequestCallback);
            RemoteAsyncFriendDelegate del = new RemoteAsyncFriendDelegate(server.acceptFriendRequest);
            del.BeginInvoke(user, remoteCallback, null);

            return null;
        }
示例#3
0
        public Friend sendFriendRequest(Friend friend)
        {
            MessageBox.Show(ServerApp._user.Username + " -> ServerToserver : sendFriendRequest(adds pending friend) : " + friend.Name + " %s" +friend.Uris.ElementAt(0));

            try
            {
                ServerApp._user.addPendingFriend(friend);
            }
            catch (DuplicatePendingFriendException ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                return null;
            }

            ClientServices client = (ClientServices)Activator.GetObject(typeof(ClientServices),
                ServerApp._clientUri + "/" + ServicesNames.ClientServicesName);

            RemoteAsyncFriendDelegate del = new RemoteAsyncFriendDelegate(client.sendFriendRequest);
            del.BeginInvoke(friend, null, null);

            return null;
        }
示例#4
0
        //TODO: falar com cliente
        private void remoteAsyncAcceptFriendRequestCallback(IAsyncResult ar)
        {
            //ReplicationServices replica;
            //RemoteAsyncFriendDelegate remoteDel;

            //string[] replicasURIs = { ServerApp._replicaOneURI, ServerApp._replicaTwoURI };

            try
            {
                RemoteAsyncFriendDelegate del = (RemoteAsyncFriendDelegate)((AsyncResult)ar).AsyncDelegate;

                Friend newFriend = del.EndInvoke(ar);

                if (newFriend == null)
                    return;

                //KLFK
                newFriend.SucessorSwarm = false;
                ServerApp._user.Friends.Add(newFriend);
                ServerApp._user.removePendingFriend(newFriend.Name);

                ClientServices client = (ClientServices)Activator.GetObject(typeof(ClientServices),
                ServerApp._clientUri + "/" + ServicesNames.ClientServicesName);

                del = new RemoteAsyncFriendDelegate(client.acceptFriendRequest);

                del.BeginInvoke(newFriend, null, null);

                /*foreach (string uri in replicasURIs)
                {
                    if (uri != null)
                    {
                        replica = ((ReplicationServices)Activator.GetObject(typeof(ReplicationServices),
                            uri + "/" + ServicesNames.ReplicationServicesName));
                        remoteDel = new RemoteAsyncFriendDelegate(replica.acceptFriendRequest);
                        remoteDel.BeginInvoke(newFriend, null, null);
                    }
                }*/
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.Message + " aqui1");
                return;
            }
        }
示例#5
0
        //TODO: depois tem que ter callback
        public void sendFriendRequest(string friendUri)
        {
            ClientServices client;

            if (!ServerApp._serviceAvailable)
            {
                client = ((ClientServices)Activator.GetObject(typeof(ClientServices),
                    ServerApp._clientUri + "/" + ServicesNames.ClientServicesName));
                new RemoteAsyncServiceUnavailableDelegate(client.serviceUnavailable).BeginInvoke(null, null);
                return;
            }

            try
            {
                List<String> replicasUri = new List<string>();
                replicasUri.Add(ServerApp._myUri);
                //string[] replicasURIs = new string[] { ServerApp._primaryURI };
                //                      //ServerApp._replicaOneURI,ServerApp._replicaTwoURI };

                MessageBox.Show(ServerApp._user.Username + " -> ClientToServer : sendFriendRequest : " + ServerApp._user.Username + " - " + replicasUri.ElementAt(0));
                Friend friend = new Friend(ServerApp._user.Username,replicasUri,true);

                ServerToServerServices server = (ServerToServerServices)Activator.GetObject(
                    typeof(ServerToServerServices),
                    friendUri + "/" + ServicesNames.ServerToServerServicesName);

                RemoteAsyncFriendDelegate del =
                    new RemoteAsyncFriendDelegate(server.sendFriendRequest);

                System.Windows.Forms.MessageBox.Show("vou adicionar pending friend " + friendUri);
                del.BeginInvoke(friend, null, null);
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.Message);
            }
        }
示例#6
0
        private void friendsPendingRejectButton_Click(object sender, EventArgs e)
        {
            RemoteAsyncFriendDelegate del;

            foreach (object checkedItem in friendsPendingBox.CheckedItems)
            {
                string removeFriendName = friendsPendingBox.GetItemText(checkedItem);

                Friend removeFriend = ClientApp._user.getPendingFriend(removeFriendName);

                del = new RemoteAsyncFriendDelegate(_server.removeFriendRequest);

                del.BeginInvoke(removeFriend, RemoteAsyncRemovePendingFriendCallBack, null);

            }
        }
示例#7
0
        private void friendsPendingAcceptButton_Click(object sender, EventArgs e)
        {
            RemoteAsyncFriendDelegate del;

            foreach (object checkedItem in friendsPendingBox.CheckedItems)
            {
                string acceptedFriendName = friendsPendingBox.GetItemText(checkedItem);

                Friend acceptedFriend = ClientApp._user.getPendingFriend(acceptedFriendName);

                //MessageBox.Show(acceptedFriend.Name);

                del = new RemoteAsyncFriendDelegate(_server.acceptFriendRequest);

                del.BeginInvoke(acceptedFriend, null, null);
            }
        }