本文整理汇总了C#中IParameterCollection类的典型用法代码示例。如果您正苦于以下问题:C# IParameterCollection类的具体用法?C# IParameterCollection怎么用?C# IParameterCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IParameterCollection类属于命名空间,在下文中一共展示了IParameterCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NewToken
object NewToken(RestVerbs verbs, IParameterCollection parameters)
{
var user = verbs["username"];
var pass = verbs["password"];
RestObject obj = null;
if (Verify != null)
obj = Verify(user, pass);
if (obj == null)
obj = new RestObject("401") { Error = "Invalid username/password combination provided. Please re-submit your query with a correct pair." };
if (obj.Error != null)
return obj;
string hash;
var rand = new Random();
var randbytes = new byte[32];
do
{
rand.NextBytes(randbytes);
hash = randbytes.Aggregate("", (s, b) => s + b.ToString("X2"));
} while (Tokens.ContainsKey(hash));
Tokens.Add(hash, user);
obj["token"] = hash;
return obj;
}
示例2: Assign
/// <summary>
/// Assign properties in the specified object.
/// </summary>
/// <param name="instance">Object to fill.</param>
/// <param name="parameters">Contains all parameters that should be assigned to the properties.</param>
/// <exception cref="PropertyException">Properties was not found or value could not be converted.</exception>
/// <exception cref="ArgumentNullException">Any parameter is <c>null</c>.</exception>
public static void Assign(object instance, IParameterCollection parameters)
{
if (instance == null)
throw new ArgumentNullException("instance");
if (parameters == null)
throw new ArgumentNullException("parameters");
var errors = new Dictionary<string, Exception>();
ICachedType type = PropertyProvider.Get(instance.GetType());
foreach (IParameter parameter in parameters)
{
try
{
object value = parameter.Value;
if (_handler != null && !_handler(instance, parameter.Name, ref value))
continue;
type.SetConvertedValue(instance, parameter.Name, value);
}
catch (Exception err)
{
errors[parameter.Name] = err;
}
}
if (errors.Count != 0)
throw new PropertyException(errors);
}
示例3: Parse
/// <summary>
/// Parse a query string
/// </summary>
/// <param name="reader">string to parse</param>
/// <param name="parameters">Parameter collection to fill</param>
/// <returns>A collection</returns>
/// <exception cref="ArgumentNullException"><c>reader</c> is <c>null</c>.</exception>
public void Parse(TextReader reader, IParameterCollection parameters)
{
if (reader == null)
throw new ArgumentNullException("reader");
var canRun = true;
while (canRun)
{
var result = reader.ReadToEnd("&=");
var name = Uri.UnescapeDataString(result.Value);
switch (result.Delimiter)
{
case '&':
parameters.Add(name, string.Empty);
break;
case '=':
result = reader.ReadToEnd("&");
parameters.Add(name, Uri.UnescapeDataString(result.Value));
break;
case char.MinValue:
// EOF = no delimiter && no value
if (!string.IsNullOrEmpty(name))
parameters.Add(name, string.Empty);
break;
}
canRun = result.Delimiter != char.MinValue;
}
}
示例4: Parse
public void Parse(string value, IParameterCollection target)
{
int index = 0;
var lastCh = char.MinValue;
var name = "";
int oldPos = 0;
while (index < value.Length)
{
var ch = value[index];
switch (ch)
{
case '=':
if (lastCh != '\\')
{
name = value.Substring(oldPos, index - oldPos).Trim(' ');
oldPos = index + 1;
}
break;
case ',':
if (lastCh != '\\')
{
target.Add(name, value.Substring(oldPos, index - oldPos).Trim(' ', '"'));
oldPos = index + 1;
}
break;
}
lastCh = value[index];
++index;
}
}
示例5: DataConverter
public DataConverter(IParameterCollection queryString, IParameterCollection form)
{
_queryString = queryString;
_form = form;
_formArray = new ArrayParameterCollection(form);
_queryStringArray = new ArrayParameterCollection(_queryString);
}
示例6: RestRequestArgs
public RestRequestArgs(RestVerbs verbs, IParameterCollection param, IRequest request, SecureRest.TokenData tokenData, IHttpContext context)
{
Verbs = verbs;
Parameters = param;
Request = request;
TokenData = tokenData;
Context = context;
}
示例7: ArrayParameterCollection
/// <summary>
/// Initializes a new instance of the <see cref="ArrayParameterCollection"/> class.
/// </summary>
/// <param name="collection">Parse parameters from the this collection.</param>
public ArrayParameterCollection(IParameterCollection collection)
: base("root", string.Empty)
{
foreach (var item in collection)
{
foreach (var value in item)
Add(item.Name, value);
}
}
示例8: ProcessBefore
// TODO: Break in to Supporting Objects, User, Object, and Field Level Security Processing
public void ProcessBefore(IParameterCollection inputs, IList<CustomAttributeNamedArgument> customAttributeNamedArguments)
{
if (_validationContext.EnableValidation)
{
var parameters = customAttributeNamedArguments.FirstOrDefault(x => x.MemberName == "Parameters").TypedValue.Value as string;
if (parameters == null)
{
parameters = string.Empty;
}
var parameterList = parameters.Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries);
var validationMessages = new List<string>();
var isValid = true;
if (parameterList.Length == 0 && inputs.Count > 0)
{
var flaggedInput = inputs[0];
if (flaggedInput != null)
{
var response = Validate(flaggedInput);
isValid = response.IsValid;
validationMessages.AddRange(response.ValidationErrors);
}
}
else
{
foreach (var parameter in parameterList)
{
if (!String.IsNullOrWhiteSpace(parameter) && inputs.ContainsParameter(parameter))
{
var flaggedInput = inputs[parameter];
if (flaggedInput != null)
{
var response = Validate(flaggedInput);
isValid = isValid && response.IsValid;
validationMessages.AddRange(response.ValidationErrors);
}
}
else
{
throw new ConfigurationErrorsException(string.Format("Incorrect Parameter Specified {0}, Parameter Does Not Exist!", parameter));
}
}
}
if (!isValid)
{
var validationMessageStringBuilder = new StringBuilder();
foreach (var validationMessage in validationMessages)
{
validationMessageStringBuilder.Append(validationMessage);
validationMessageStringBuilder.Append(" ");
}
throw new ValidationException(validationMessageStringBuilder.ToString());
}
}
}
示例9: ProcessBefore
public void ProcessBefore(IParameterCollection inputs, IEnumerable<CustomAttributeData> customAttributeDatas)
{
InitializeDictionary();
foreach (var customAttributeData in customAttributeDatas)
{
if (_strategyHash.ContainsKey(customAttributeData.AttributeType))
{
_strategyHash[customAttributeData.AttributeType].ProcessBefore(inputs, customAttributeData.NamedArguments);
}
}
}
示例10: Create
/*----------------------------------------------------------------------------------------*/
/// <summary>
/// Creates a new root context.
/// </summary>
/// <param name="service">The type that was requested.</param>
/// <param name="scope">The scope in which the activation is occurring.</param>
/// <param name="parameters">A collection of transient parameters to apply to the context.</param>
/// <returns>The root context.</returns>
public IContext Create(Type service, IScope scope, IParameterCollection parameters)
{
Ensure.ArgumentNotNull(service, "service");
Ensure.ArgumentNotNull(scope, "scope");
Ensure.ArgumentNotNull(parameters, "parameters");
IContext context = CreateRootContext(service, scope);
context.Parameters = parameters;
return context;
}
示例11: DestroyToken
object DestroyToken(RestVerbs verbs, IParameterCollection parameters)
{
var token = verbs["token"];
try
{
Tokens.Remove(token);
}
catch (Exception)
{
return new Dictionary<string, string> { { "status", "400" }, { "error", "The specified token queued for destruction failed to be deleted." } };
}
return new Dictionary<string, string> { { "status", "200" }, { "response", "Requested token was successfully destroyed." } };
}
示例12: GetUserNameFromInputs
public string GetUserNameFromInputs(IParameterCollection inputs)
{
foreach (var requestInput in inputs)
{
Request = requestInput as RequestBase;
if (Request != null)
{
UserName = Request.UserName;
break;
}
}
return UserName;
}
示例13: ExecuteCommand
protected override object ExecuteCommand(RestCommand cmd, RestVerbs verbs, IParameterCollection parms)
{
if (cmd.RequiresToken)
{
var strtoken = parms["token"];
if (strtoken == null)
return new Dictionary<string, string> { { "status", "401" }, { "error", "Not authorized. The specified API endpoint requires a token." } };
object token;
if (!Tokens.TryGetValue(strtoken, out token))
return new Dictionary<string, string> { { "status", "403" }, { "error", "Not authorized. The specified API endpoint requires a token, but the provided token was not valid." } };
}
return base.ExecuteCommand(cmd, verbs, parms);
}
示例14: GetInventory
private object GetInventory(RestVerbs verbs, IParameterCollection parameters, SecureRest.TokenData tokenData)
{
List<TSPlayer> players = TShock.Utils.FindPlayer(verbs["user"]);
if (players.Count > 1)
{
return new RestObject("400") {Response = "Found more than one match."};
}
else if (players.Count < 1)
{
return new RestObject("400") {Response = "Found no matches."};
}
string inventory = players[0].PlayerData.inventory.ToString();
return new RestObject{{"inventory", inventory}};
}
示例15: Post
public string Post(IParameterCollection form)
{
if (form["page"] == "settings.htm")
{
if (!Persistance.API.ContainsKey(form["var"]))
{
Persistance.API.Add(form["var"], form["value"]);
}
else
{
Persistance.API[form["var"]] = form["value"];
}
return "Return to <a href='settings.htm'>settings.htm</a>";
}
return "";
}