Example #1
0
        protected override void ValidateRequest(string requestId)
        {
            base.ValidateRequest(requestId);

            _queryParameters = ParseQueryParameters(_dataRequest.Parameters, out _queryServiceName);
        }
Example #2
0
        protected virtual ByIndexOrNameDictionary <string> ParseQueryParameters(ByIndexOrNameDictionary <string> parameters, out string serviceName)
        {
            ByIndexOrNameDictionary <string> queryParameters = null;

            serviceName = null;

            if (CollectionUtils.IsNullOrEmpty(parameters))
            {
                throw new ArgumentException(string.Format("No parameters were passed to the service.  You must pass at least the \"{0}\" parameter.",
                                                          PARAM_SERVICE_NAME_KEY));
            }
            if (!parameters.IsByName)
            {
                throw new ArgumentException("The parameters to the service are \"by-index,\" but they must be \"by-name\"");
            }

            queryParameters = new ByIndexOrNameDictionary <string>(true);

            StringBuilder sb = new StringBuilder();

            foreach (KeyValuePair <string, string> pair in parameters.NameValuePairs)
            {
                if (string.Equals(pair.Key, PARAM_SERVICE_NAME_KEY, StringComparison.OrdinalIgnoreCase))
                {
                    if (serviceName != null)
                    {
                        throw new ArgumentException(string.Format("More than one \"{0}\" parameter was passed to the service: \"{1}\" and \"{2}\"",
                                                                  PARAM_SERVICE_NAME_KEY, serviceName, pair.Key));
                    }
                    if (string.IsNullOrEmpty(pair.Value))
                    {
                        throw new ArgumentException(string.Format("The \"{0}\" parameter passed to the service is empty",
                                                                  PARAM_SERVICE_NAME_KEY));
                    }
                    if (!IsValidServiceName(pair.Value))
                    {
                        throw new ArgumentException(string.Format("The \"{0}\" parameter value is not supported: \"{1}\"",
                                                                  PARAM_SERVICE_NAME_KEY, pair.Value));
                    }
                    serviceName = pair.Value;
                }
                else
                {
                    if (CollectionUtils.Contains(DATE_PARAMETER_NAMES, pair.Key, StringComparison.OrdinalIgnoreCase))
                    {
                        DateTime dateTime;
                        if (TryParseNowDate(pair.Value, out dateTime))
                        {
                            queryParameters.Add(pair.Key, dateTime.ToString("yyyy-MM-dd"));
                        }
                        else
                        {
                            throw new ArgumentException(string.Format("The \"{0}\" parameter value cannot be parsed: \"{1}\"",
                                                                      PARAM_SERVICE_NAME_KEY, pair.Value));
                        }
                    }
                    else
                    {
                        queryParameters.Add(pair.Key, pair.Value);
                    }
                    if (sb.Length > 0)
                    {
                        sb.Append(", ");
                    }
                    int index = queryParameters.Count - 1;
                    sb.AppendFormat("{0} ({1})", pair.Key, queryParameters[pair.Key]);
                }
            }
            if (serviceName == null)
            {
                throw new ArgumentException(string.Format("A \"{0}\" parameter was not passed to the service", PARAM_SERVICE_NAME_KEY));
            }
            if (!CollectionUtils.IsNullOrEmpty(queryParameters))
            {
                AppendAuditLogEvent("Query parameters: {0}", sb.ToString());
            }
            else
            {
                AppendAuditLogEvent("No query parameters were specified");
            }

            return(queryParameters);
        }