Esempio n. 1
0
        /// <summary>
        /// CreateParametersByName
        /// </summary>
        /// <param name="inParams"></param>
        /// <returns></returns>
        private static ByIndexOrNameDictionary <string> CreateParameters(string[] inParams)
        {
            ByIndexOrNameDictionary <string> parameters = new ByIndexOrNameDictionary <string>(false);

            if ((inParams != null) && (inParams.Length > 0))
            {
                for (int i = 0; i < inParams.Length; i++)
                {
                    parameters.Add(inParams[i]);
                }
            }
            return(parameters);
        }
Esempio n. 2
0
        /// <summary>
        /// Return the arguments for the data request with the specified request id, or null
        /// if the data request is not found.
        /// </summary>
        private void GetRequestArguments(DataRequest request, bool paramsByName)
        {
            ByIndexOrNameDictionary <string> parameters = new ByIndexOrNameDictionary <string>(paramsByName);

            if (paramsByName)
            {
                DoSimpleQueryWithRowCallbackDelegate(
                    ARGS_TABLE_NAME, "RequestId", request.Id, "ArgName",
                    "ArgName;ArgValue",
                    delegate(IDataReader reader) {
                    parameters.Add(reader.GetString(0), reader.GetString(1));
                });
            }
            else
            {
                DoSimpleQueryWithRowCallbackDelegate(
                    ARGS_TABLE_NAME, "RequestId", request.Id, "ArgName",
                    "ArgValue",
                    delegate(IDataReader reader) {
                    parameters.Add(reader.GetString(0));
                });
            }
            request.Parameters = parameters;
        }
Esempio n. 3
0
        public string BulkAddUsers(ICollection <string> usernames, bool createInNaas, string defaultPassword,
                                   SystemRoleType defaultRole, ICollection <FlowNameAndRole> accessFlows,
                                   bool isUserActive, NodeVisit visit)
        {
            ValidateByRole(visit, SystemRoleType.Admin);

            if (CollectionUtils.IsNullOrEmpty(usernames))
            {
                throw new ArgumentException("usernames cannot be empty");
            }

            // Create the parameter list:
            ByIndexOrNameDictionary <string> parameters = new ByIndexOrNameDictionary <string>(true);

            int i = 0;

            foreach (string username in usernames)
            {
                string key = string.Format("{0}{1}", BulkAddUsersConstants.PARAM_USERNAME_PREFIX, i.ToString());
                parameters.Add(key, username);
                ++i;
            }
            parameters.Add(BulkAddUsersConstants.PARAM_CREATE_IN_NAAS, createInNaas.ToString());
            if (!string.IsNullOrEmpty(defaultPassword))
            {
                parameters.Add(BulkAddUsersConstants.PARAM_DEFAULT_PASSWORD, defaultPassword);
            }
            parameters.Add(BulkAddUsersConstants.PARAM_DEFAULT_ROLE, defaultRole.ToString());
            parameters.Add(BulkAddUsersConstants.PARAM_IS_ACTIVE, isUserActive.ToString());
            if (!CollectionUtils.IsNullOrEmpty(accessFlows))
            {
                i = 0;
                foreach (FlowNameAndRole accessFlow in accessFlows)
                {
                    string key = string.Format("{0}{1}", BulkAddUsersConstants.PARAM_FLOW_NAME_PREFIX, i.ToString());
                    parameters.Add(key, accessFlow.FlowName + BulkAddUsersConstants.PARAM_VALUE_SEPARATOR + accessFlow.FlowRole);
                    ++i;
                }
            }
            // Create the task transaction and queue for running, the task will run asynchronously after
            // this method returns
            return(_transactionManager.QueueTask(_securityFlowName, _securityBulkAddUsersServiceName,
                                                 visit.Account.Id, parameters));
        }
        public static string ParseParams(string restParamsString, string propertyDisplayName, out ByIndexOrNameDictionary <string> parameterDictionary)
        {
            parameterDictionary = null;
            string errorMessage = null;

            if (!string.IsNullOrWhiteSpace(restParamsString))
            {
                ByIndexOrNameDictionary <string> parameters = new ByIndexOrNameDictionary <string>(true);
                List <string> keyValueParameters            = StringUtils.SplitAndReallyRemoveEmptyEntries(restParamsString, ';');
                int           count = 1;
                CollectionUtils.ForEachBreak(keyValueParameters, delegate(string keyValueParameter)
                {
                    int pipeIndex = keyValueParameter.IndexOf('|');
                    if (pipeIndex < 1)
                    {
                        errorMessage = string.Format("The query parameter \"{0}\" has invalid content for parameter {1}: \"{2}\"",
                                                     propertyDisplayName, count.ToString(), keyValueParameter);
                        return(false);
                    }
                    string key   = keyValueParameter.Substring(0, pipeIndex).Trim();
                    string value = string.Empty;
                    if (pipeIndex < (keyValueParameter.Length - 1))
                    {
                        value = keyValueParameter.Substring(pipeIndex + 1).Trim();
                    }
                    parameters.Add(key, value);
                    ++count;
                    return(true);
                });
                if (parameters.Count > 0)
                {
                    parameterDictionary = parameters;
                }
            }
            return(errorMessage);
        }
Esempio n. 5
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);
        }