Пример #1
0
        ///// <summary>
        ///// Gets description of error
        ///// </summary>
        ///// <param name="error">ErrorCode</param>
        ///// <returns>Error description</returns>
        //private string GetErrorDescription(ErrorCode error)
        //{
        //    string errorDescription; 
        //    switch (error)
        //    {
        //        case ErrorCode.ERRORCODE_UNSPECIFIED: errorDescription = "Unknown/Unspecified error"; break;
        //        case ErrorCode.ERRORCODE_UNKNOWNCMD: errorDescription ="Unknown cmd param"; break;
        //        case ErrorCode.ERRORCODE_BADPARAMS: errorDescription = "Invalid parameters (e.g. missing cmd/s_redirectto param)"; break;
        //        case ErrorCode.ERRORCODE_BADPOLLID: errorDescription = "Invalid poll id"; break;
        //        case ErrorCode.ERRORCODE_NEEDUSER: errorDescription = "User required for operation (User not logged in)"; break;
        //        case ErrorCode.ERRORCODE_ACCESSDENIED: errorDescription = "Access denied/operation not allowed"; break;
        //        case ErrorCode.ERRORCODE_AUTHORCANNOTVOTE: errorDescription = "Page author cannot vote"; break;
        //        default: errorDescription = "Unknown/Unspecified error"; break;
        //    }

        //    return errorDescription;
        //}

        /// <summary>
        /// Tries to parse the request url to see what command has been sent through
        /// </summary>
        /// <param name="request">The request object</param>
        /// <returns>True if command found, false if not OR something went wrong</returns>
        public virtual bool ParseRequestURLForCommand(IRequest request)
        {
            // Get the command from the request
            string command = request.GetParamStringOrEmpty("cmd", "Get the command for the poll");
            if (command.Length > 0)
            {
                // See if we're adding a vote
                if (command == "vote")
                {
                    // Now get the response to the poll vote
                    int response = request.TryGetParamIntOrKnownValueOnError("response", ResponseMin - 1, "Try to get the response for the poll vote");
                    return Vote(response);
                }
                else if (command == "removevote")
                {
                    // We're wanting to remove a vote
                    return RemoveVote();
                }
                else if (command == "config")
                {
                    // Config command is meant to configure poll. For now
                    // we only have hide/unhide config feature. In the 
                    // future we may have more. When this happens it would
                    // be wise to refactor code below making it more extendible.
                    // E.g, throw it in a virtual Config() function.

                    // See if we want to hide/unhide
                    if (request.DoesParamExist("hide", _docSPollHideParam))
                    {
                        // Now see if we're trying to hide or unhide
                        bool hide;
                        if (request.GetParamIntOrZero("hide", _docSPollHideParam) > 0)
                        {
                            hide = true;
                        }
                        else
                        {
                            hide = false;
                        }

                        // Return the result form the hide
                        return HidePoll(hide);
                    }
                }
                else if (command == "hidepoll")
                {
                    // We're trying to hide a poll
                    return HidePoll(true);
                }
                else if (command == "unhidepoll")
                {
                    // We're trying to unhide a poll
                    return HidePoll(false);
                }
            }

            // Did not match the command given, or not given!
            return UnhandledCommand(command); 
        }
Пример #2
0
        /// <summary>
        /// Tries to parse the request url to see what command has been sent through
        /// </summary>
        /// <param name="request">The request object</param>
        /// <returns>True if command found, false if not OR something went wrong</returns>
        public override bool ParseRequestURLForCommand(IRequest request)
        {
            // Get the redirect from the url
            _redirectURL = request.GetParamStringOrEmpty("s_redirectto", "Check the redirect for the poll exists");
            if (RedirectURL.Length == 0)
            {
                // Add an error to the xml and logs
                _appContext.Diagnostics.WriteWarningToLog("PollContentRating", "'s_redirectto' parameter not found!");
                return AddErrorXml(ErrorCode.ERRORCODE_BADPARAMS.ToString(), "'s_redirectto' not set by skin", null);
            }

            // Now let the base class do it's stuff
            return base.ParseRequestURLForCommand(request);
        }