Esempio n. 1
0
        /// <summary>
        /// Attempts to generate the key and returns the result.
        /// </summary>
        /// <param name="client">The remote client.</param>
        /// <param name="info">The full channel string.</param>
        /// <param name="message">The message to publish.</param>
        public static bool TryProcess(IClient client, EmitterChannel info, ArraySegment <byte> message)
        {
            // Is this a special api request?
            if (info.Key != EmitterConst.ApiPrefix)
            {
                return(false);
            }

            // The response to send out, default to bad request
            EmitterResponse response = EmitterError.BadRequest;

            try
            {
                switch (info.Target)
                {
                case 548658350:
                    // Handle the 'keygen' request.
                    response = HandleKeyGen.Process(client, info, message.As <KeyGenRequest>());
                    return(true);

                case 3869262148:
                    // Handle the 'presence' request.
                    response = HandlePresence.Process(client, info, message.As <PresenceRequest>());
                    return(true);

                default:
                    // We've got a bad request
                    response = EmitterError.BadRequest;
                    return(true);
                }
            }
            catch (NotImplementedException)
            {
                // We've got a not implemented exception
                response = EmitterError.NotImplemented;
                return(true);
            }
            catch (Exception ex)
            {
                // We've got a an internal error
                Service.Logger.Log(ex);
                response = EmitterError.ServerError;
                return(true);
            }
            finally
            {
                // Send the response, always
                if (response != null)
                {
                    SendResponse(client, "emitter/" + info.Channel, response);
                }
            }
        }