Exemplo n.º 1
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);
            }
        }
Exemplo n.º 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;
			}
		}