Ejemplo n.º 1
0
        public bool ReconnectTask()
        {
            try
            {
                var ip = Connection.CurrentGroup.hostIp;

                InstanceContext instanceContext = new InstanceContext(this);
                client = new SharePClient(instanceContext);
                string servicePath = client.Endpoint.ListenUri.AbsolutePath;


                client.Endpoint.Address = new EndpointAddress("net.tcp://" + ip + ":8000" + servicePath);

                client.Open();

                Log.LogInfo("Connection reopened");

                client.InnerDuplexChannel.Faulted +=
                    new EventHandler(InnerDuplexChannel_FaultedAsync);

                ConnectionResult connectionResult = client.Reconnect(Connection.CurrentUser);
                if (connectionResult == ConnectionResult.Success)
                {
                    Log.LogInfo("Successfuly reconnected to " + ip);
                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
                client = null;
                Log.LogException(e, "Error during reconnection.");
                return(false);
            }
        }
Ejemplo n.º 2
0
        public ConnectionResult EstablishClientConnection(string ip, byte[] password = null)
        {
            if (client == null)
            {
                try
                {
                    InstanceContext instanceContext = new InstanceContext(this);
                    client = new SharePClient(instanceContext);
                    string servicePath = client.Endpoint.ListenUri.AbsolutePath;


                    client.Endpoint.Address = new EndpointAddress("net.tcp://" + ip + ":8000" + servicePath);

                    client.Open();

                    Log.LogInfo("Connection opened");

                    client.InnerDuplexChannel.Faulted +=
                        new EventHandler(InnerDuplexChannel_FaultedAsync);

                    ConnectionResult connectionResult = client.Connect(Connection.CurrentUser, password);
                    if (connectionResult == ConnectionResult.Success)
                    {
                        Log.LogInfo("Successfuly connected to " + ip);
                        faulted = false;
                        Connection.CurrentPresentation = client.RequestCurrentPresentation();
                        var messageHistory = client.RequestMessageHistory();
                        if (messageHistory != null)
                        {
                            foreach (var message in messageHistory)
                            {
                                ChatController.RecieveMessage(message, false, true);
                            }
                        }
                    }
                    else
                    {
                        client = null;
                    }
                    return(connectionResult);
                }
                catch (Exception e)
                {
                    client = null;
                    Log.LogException(e, "Error during connection.");
                    return(ConnectionResult.Error);
                }
            }
            return(ConnectionResult.Error);
        }
Ejemplo n.º 3
0
        public void Disconnect()
        {
            if (!CheckBeforeRequest())
            {
                client = null;
                return;
            }

            try
            {
                client.DisconnectAsync(Connection.CurrentUser);
            }
            catch { }

            client = null;
        }
Ejemplo n.º 4
0
        public Dictionary <string, string> GetServiceOnIP(string ip)
        {
            try
            {
                InstanceContext instanceContext = new InstanceContext(this);
                var             temp            = new SharePClient(instanceContext);
                string          servicePath     = temp.Endpoint.ListenUri.AbsolutePath;


                temp.Endpoint.Address = new EndpointAddress("net.tcp://" + ip + ":8000" + servicePath);

                temp.Open();

                var serviceData = temp.RequestServerInfo();

                temp.Close();

                return(serviceData);
            }
            catch
            {
                return(null);
            }
        }