Exemplo n.º 1
0
        /// <summary>
        ///     Tries to connect to the BoxServer
        /// </summary>
        /// <param name="ProcessErrors">Specifies whether to process errors and display them to the user</param>
        /// <returns>True if succesful</returns>
        public bool Connect(bool ProcessErrors)
        {
            try
            {
                var ConnectionString = string.Format(
                    "tcp://{0}:{1}/BoxRemote",
                    Pandora.Profile.Server.Address,
                    Pandora.Profile.Server.Port);

                m_Remote = Activator.GetObject(typeof(BoxRemote), ConnectionString) as BoxRemote;

                // Perform Login
                BoxMessage msg = new LoginMessage();

                msg.Username = Pandora.Profile.Server.Username;
                msg.Password = Pandora.Profile.Server.Password;
                var    data    = msg.Compress();
                string outType = null;

                var result = m_Remote.PerformRemoteRequest(msg.GetType().FullName, data, out outType);

                if (result == null)
                {
                    MessageBox.Show(Pandora.Localization.TextProvider["Errors.ServerError"]);
                    Connected = false;
                    return(false);
                }

                var t = Type.GetType(outType);

                var outcome = BoxMessage.Decompress(result, t);

                if (ProcessErrors)
                {
                    if (!CheckErrors(outcome))
                    {
                        Connected = false;
                        return(false);
                    }
                }

                if (outcome is LoginSuccess)
                {
                    Connected = true;
                    return(true);
                }
                Connected = false;
                return(false);
            }
            catch (Exception err)
            {
                Pandora.Log.WriteError(err, "Connection failed to box server");
                Connected = false;
            }

            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Sends a message to the server. Processes errors too.
        /// </summary>
        /// <param name="msg">The message to send to the server</param>
        /// <returns>A BoxMessage if there is one</returns>
        public BoxMessage ProcessMessage(BoxMessage msg)
        {
            BoxMessage outcome = null;

            if (!Connected)
            {
                Connect();
            }

            if (!Connected)
            {
                return(null);
            }

            var    data    = msg.Compress();
            string outType = null;

            try
            {
                var result = m_Remote.PerformRemoteRequest(msg.GetType().FullName, data, out outType);

                if (result == null)
                {
                    return(null);
                }

                var t = Type.GetType(outType);
                outcome = BoxMessage.Decompress(result, t);

                if (!CheckErrors(outcome))
                {
                    outcome = null;
                }
            }
            catch (Exception err)
            {
                Pandora.Log.WriteError(err, "Error when processing a BoxMessage of type: {0}", msg.GetType().FullName);
                MessageBox.Show(Pandora.Localization.TextProvider["Errors.ConnectionLost"]);
                Connected = false;
                outcome   = null;
            }

            return(outcome);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Tries to connect to the BoxServer
        /// </summary>
        /// <param name="ProcessErrors">Specifies whether to process errors and display them to the user</param>
        /// <returns>True if succesful</returns>
        public bool Connect(bool ProcessErrors)
        {
            try
            {
                string ConnectionString = string.Format("tcp://{0}:{1}/BoxRemote", Pandora.Profile.Server.Address, Pandora.Profile.Server.Port);

                m_Remote = Activator.GetObject(typeof(BoxRemote), ConnectionString) as BoxRemote;

                // Perform Login
                BoxMessage msg = new LoginMessage();

                msg.Username = Pandora.Profile.Server.Username;
                msg.Password = Pandora.Profile.Server.Password;
                byte[] data = msg.Compress();
                string outType = null;

                byte[] result = m_Remote.PerformRemoteRequest(msg.GetType().FullName, data, out outType);

                if (result == null)
                {
                    MessageBox.Show(Pandora.Localization.TextProvider["Errors.ServerError"]);
                    Connected = false;
                    return false;
                }

                Type t = Type.GetType(outType);

                BoxMessage outcome = BoxMessage.Decompress(result, t);

                if (ProcessErrors)
                {
                    if (!CheckErrors(outcome))
                    {
                        Connected = false;
                        return false;
                    }
                }

                if (outcome is LoginSuccess)
                {
                    Connected = true;
                    return true;
                }
                else
                {
                    Connected = false;
                    return false;
                }
            }
            catch (Exception err)
            {
                Pandora.Log.WriteError(err, "Connection failed to box server");
                Connected = false;
            }

            return false;
        }