本文整理汇总了C#中IDictionary.ReadForm方法的典型用法代码示例。如果您正苦于以下问题:C# IDictionary.ReadForm方法的具体用法?C# IDictionary.ReadForm怎么用?C# IDictionary.ReadForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDictionary
的用法示例。
在下文中一共展示了IDictionary.ReadForm方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PostForceEvent
public static Task PostForceEvent(
IDictionary<string, object> environment,
Func<IDictionary<string, object>, Task> next)
{
var fail = new Func<int, string, Task>((statusCode, message) =>
{
environment.SetStatusCode(statusCode);
return environment.WriteAsync(message);
});
var form = environment.ReadForm();
var payload = form["payload"];
if (payload == null || payload.Count == 0)
{
fail(400, "Missing payload.");
return environment.GetCompleted();
}
var @event = payload[0];
var forceEvent = JsonConvert.DeserializeObject<ForceEvent>(@event);
// TODO: validate the event's properties
var buildConfiguration = fn.GetBuildConfiguration(forceEvent.Repository.Owner.Name, forceEvent.Repository.Name);
if (buildConfiguration == null)
{
fail(422, "No build configuraion matches the identified build.");
return environment.GetCompleted();
}
var newBuild = fn.CreateBuild(
buildConfiguration.Command,
buildConfiguration.CommandArguments,
forceEvent.Repository.Name,
forceEvent.Repository.Owner.Name,
forceEvent.Ref,
forceEvent.Revision,
"rebuild",
@event);
var location = String.Format(
"/{0}/{1}/builds/{2}",
newBuild.RepositoryOwner,
newBuild.RepositoryName,
newBuild.Id);
var absoluteLocation = String.Format(
"http://{0}{1}",
fn.GetHost(),
location);
environment.SetStatusCode(201);
var responseHeaders = environment.GetResponseHeaders();
responseHeaders.Add("Location", new [] { absoluteLocation });
return environment.Render("queued", new { id = newBuild.Id, location});
}
示例2: PutSession
public static Task PutSession(
IDictionary<string, object> environment,
Func<IDictionary<string, object>, Task> next)
{
var form = environment.ReadForm();
var username = form["username"].FirstOrDefault();
var password = form["password"].FirstOrDefault();
var errors = new List<string>();
var fail = new Func<Task>(() =>
{
environment.SetStatusCode(400);
return environment.Render("sign-in-form", new
{
errors = errors.Select(x => new {error = x}),
username
});
});
if (String.IsNullOrEmpty(username))
errors.Add("Username is required.");
if (String.IsNullOrEmpty(password))
errors.Add("Password is required.");
if (errors.Count > 0)
return fail();
var user = fn.GetUserByUsername(username);
if (user == null || !password.CompareToPasswordHash(user.PasswordHash))
{
errors.Add("Sign in failed.");
return fail();
}
if (errors.Count > 0)
{
environment.SetStatusCode(400);
return environment.Render("sign-in-form", new
{
errors = errors.Select(x => new { error = x }),
username
});
}
environment.SetUser(user);
environment.SetRedirect("/");
return environment.GetCompleted();
}
示例3: PostUsers
public static Task PostUsers(
IDictionary<string, object> environment,
Func<IDictionary<string, object>, Task> next)
{
var form = environment.ReadForm();
var username = form["username"].FirstOrDefault();
var password = form["password"].FirstOrDefault();
var emailAddress = form["email-address"].FirstOrDefault();
var errors = new List<string>();
if (String.IsNullOrEmpty(username))
errors.Add("Username is required.");
else
{
if (!Constants.UsernameRegex.IsMatch(username))
errors.Add("Username is invalid; must match regular expression '^[a-z][a-z0-9_-]+[a-z0-9]$'.");
var exustingUser = fn.GetUserByUsername(username);
if (exustingUser != null)
errors.Add("Username is not available; try another.");
}
if (String.IsNullOrEmpty(password))
errors.Add("Password is required.");
if (errors.Count > 0)
{
environment.SetStatusCode(400);
return environment.Render("sign-up-form", new
{
emailAddress,
errors = errors.Select(x => new { error = x }),
username
});
}
var user = fn.CreateUser(username, password, emailAddress);
var usersCount = fn.GetUsersCount();
if (usersCount == 0)
{
fn.SetUserIsAdministrator(user, true);
}
environment.SetRedirect("/");
return environment.GetCompleted();
}
示例4: PatchUser
public static Task PatchUser(
IDictionary<string, object> environment,
dynamic @params,
Func<IDictionary<string, object>, Task> next)
{
var username = @params.username as string;
var user = fn.GetUserByUsername(username);
if (user == null)
{
environment.SetStatusCode(404);
return environment.GetCompleted();
}
var form = environment.ReadForm();
var isAdministrator = form["isAdministrator"].FirstOrDefault() ?? "0";
fn.SetUserIsAdministrator(user, isAdministrator == "1");
environment.SetRedirect("/users");
return environment.GetCompleted();
}
示例5: PostPushEvent
public static Task PostPushEvent(
IDictionary<string, object> environment,
Func<IDictionary<string, object>, Task> next)
{
var fail = new Func<int, string, Task>((statusCode, message) =>
{
environment.SetStatusCode(statusCode);
return environment.WriteAsync(message);
});
var headers = environment.GetRequestHeaders();
if (!headers.ContainsKey("X-GitHub-Event"))
{
fail(400, "Missing X-GitHub-Event header.");
return environment.GetCompleted();
}
var eventTypes = headers["X-GitHub-Event"];
if (eventTypes != null)
{
var eventType = eventTypes.FirstOrDefault();
if (eventType == null || !eventType.Equals("push", StringComparison.OrdinalIgnoreCase))
{
fail(422, String.Concat("Unexpected X-GitHub-Event: ", eventType, "."));
return environment.GetCompleted();
}
}
var form = environment.ReadForm();
var payload = form["payload"];
if (payload == null || payload.Count == 0)
{
fail(400, "Missing payload.");
return environment.GetCompleted();
}
var @event = payload[0];
var pushEvent = JsonConvert.DeserializeObject<PushEvent>(@event);
// When a branch is deleted, GitHub sends a push event where after is 0000000.
// There's no need to do anything in this case.
if (pushEvent.After.StartsWith("0000000"))
{
environment.SetStatusCode(204);
return environment.GetCompleted();
}
var buildConfigurations = fn.GetBuildConfigurations();
var buildConfiguration = buildConfigurations.FirstOrDefault(bc =>
bc.Name.Equals(pushEvent.Repository.Name, StringComparison.OrdinalIgnoreCase) &&
bc.Owner.Equals(pushEvent.Repository.Owner.Name, StringComparison.OrdinalIgnoreCase));
if (buildConfiguration == null)
{
environment.SetStatusCode(204);
return environment.GetCompleted();
}
fn.CreateBuild(
buildConfiguration.Command,
buildConfiguration.CommandArguments,
pushEvent.Repository.Name,
pushEvent.Repository.Owner.Name,
pushEvent.Ref,
pushEvent.After,
"push",
@event);
environment.SetStatusCode(204);
return environment.GetCompleted();
}
示例6: PostBuild
public static Task PostBuild(
IDictionary<string, object> environment,
dynamic @params,
Func<IDictionary<string, object>, Task> next)
{
var owner = @params.owner as string;
var name = @params.name as string;
var buildConfiguration = fn.GetBuildConfiguration(owner, name);
if (buildConfiguration == null)
{
environment.SetStatusCode(400);
return environment.GetCompleted();
}
var fail = new Func<int, string, Task>((statusCode, errorMessage) =>
{
environment.SetStatusCode(statusCode);
var responseModel = new
{
owner = buildConfiguration.Owner,
name = buildConfiguration.Name,
builds = CreateBuildsResponseModel(buildConfiguration),
errorMessage
};
return environment.Render(
"builds",
responseModel);
});
var form = environment.ReadForm();
var branchOrPr = form["branch-or-pr"].FirstOrDefault();
if (String.IsNullOrEmpty(branchOrPr))
{
fail(400, "A branch or pull request number is required.");
return environment.GetCompleted();
}
string @ref;
if (branchOrPr.StartsWith("#"))
@ref = String.Concat("refs/pull/", branchOrPr.Substring(1), "/head");
else
@ref = String.Concat("refs/heads/", branchOrPr);
var newBuild = fn.CreateBuild(
buildConfiguration.Command,
buildConfiguration.CommandArguments,
name,
owner,
@ref,
null,
null,
null);
var location = String.Format(
"/{0}/{1}/builds/{2}",
newBuild.RepositoryOwner,
newBuild.RepositoryName,
newBuild.Id);
var absoluteLocation = String.Format(
"http://{0}{1}",
fn.GetHost(),
location);
environment.SetStatusCode(201);
var responseHeaders = environment.GetResponseHeaders();
responseHeaders.Add("Location", new [] { absoluteLocation });
return environment.Render("queued", new { id = newBuild.Id, location});
}