コード例 #1
0
        /// <summary>
        /// Checks a BoxMessage and processes any errors occurred
        /// </summary>
        /// <param name="msg">The BoxMessage returned by the server</param>
        /// <returns>True if the message is OK, false if errors have been found</returns>
        public bool CheckErrors(BoxMessage msg)
        {
            if (msg == null)
            {
                return(true); // null message means no error
            }
            if (msg is ErrorMessage)
            {
                // Generic error message
                MessageBox.Show(string.Format(Pandora.Localization.TextProvider["Errors.GenServErr"], (msg as ErrorMessage).Message));
                return(false);
            }
            else if (msg is LoginError)
            {
                LoginError logErr = msg as LoginError;

                string err = null;

                switch (logErr.Error)
                {
                case AuthenticationResult.AccessLevelError:

                    err = Pandora.Localization.TextProvider["Errors.LoginAccess"];
                    break;

                case AuthenticationResult.OnlineMobileRequired:

                    err = Pandora.Localization.TextProvider["Errors.NotOnline"];
                    break;

                case AuthenticationResult.UnregisteredUser:

                    err = Pandora.Localization.TextProvider["Errors.LogUnregistered"];
                    break;

                case AuthenticationResult.WrongCredentials:

                    err = Pandora.Localization.TextProvider["Errors.WrongCredentials"];
                    break;

                case AuthenticationResult.Success:

                    return(true);
                }

                MessageBox.Show(err);
                return(false);
            }
            else if (msg is FeatureNotSupported)
            {
                MessageBox.Show(Pandora.Localization.TextProvider["Errors.NotSupported"]);
                return(false);
            }

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Handles incoming messages
        /// </summary>
        /// <param name="typeName">The name of the type of the message</param>
        /// <param name="data">The byte array representing the message</param>
        /// <param name="answerType">Will hold the name of the type of the answer message</param>
        /// <returns>A stream of bytes</returns>
        private byte[] BoxRemote_OnMessage(string typeName, byte[] data, out string answerType)
        {
            answerType = null;
            BoxMessage inMsg  = null;
            BoxMessage outMsg = null;

            Type type = Type.GetType(typeName);

            if (type != null)
            {
                inMsg = BoxMessage.Decompress(data, type);

                if (inMsg != null)
                {
                    // Authenticate
                    AuthenticationResult auth = Authentication.Authenticate(inMsg);

                    if (auth == AuthenticationResult.Success)
                    {
                        // Perform message
                        outMsg = inMsg.Perform();
                    }
                    else
                    {
                        // Return authentication error
                        outMsg = new LoginError(auth);
                    }
                }
                else
                {
                    // Send generic server error
                    outMsg = new ErrorMessage("An error occurred when decompressing the incoming message.");
                }
            }
            else
            {
                outMsg = new FeatureNotSupported();
            }

            if (outMsg != null)
            {
                answerType = outMsg.GetType().FullName;
                return(outMsg.Compress());
            }
            else
            {
                // Actions that don't require an answer
                answerType = null;
                return(null);
            }
        }
コード例 #3
0
ファイル: BoxServer.cs プロジェクト: aj9251/pandorasbox3
		/// <summary>
		/// Handles incoming messages
		/// </summary>
		/// <param name="typeName">The name of the type of the message</param>
		/// <param name="data">The byte array representing the message</param>
		/// <param name="answerType">Will hold the name of the type of the answer message</param>
		/// <returns>A stream of bytes</returns>
		private byte[] BoxRemote_OnMessage( string typeName, byte[] data, out string answerType )
		{
			answerType = null;
			BoxMessage inMsg = null;
			BoxMessage outMsg = null;

			Type type = Type.GetType( typeName );

			if ( type != null )
			{
				inMsg = BoxMessage.Decompress( data, type );

				if ( inMsg != null )
				{
					// Authenticate
					AuthenticationResult auth = Authentication.Authenticate( inMsg );

					if ( auth == AuthenticationResult.Success )
					{
						// Perform message
						outMsg = inMsg.Perform();
					}
					else
					{
						// Return authentication error
						outMsg = new LoginError( auth );
					}
				}
				else
				{
					// Send generic server error
					outMsg = new ErrorMessage( "An error occurred when decompressing the incoming message." );
				}
			}
			else
			{
				outMsg = new FeatureNotSupported();
			}

			if ( outMsg != null )
			{
				answerType = outMsg.GetType().FullName;
				return outMsg.Compress();
			}
			else
			{
				// Actions that don't require an answer
				answerType = null;
				return null;
			}
		}