本文整理汇总了C#中IDictionary.Render方法的典型用法代码示例。如果您正苦于以下问题:C# IDictionary.Render方法的具体用法?C# IDictionary.Render怎么用?C# IDictionary.Render使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDictionary
的用法示例。
在下文中一共展示了IDictionary.Render方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: GetBuilds
public static Task GetBuilds(
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 responseModel = new
{
owner = buildConfiguration.Owner,
name = buildConfiguration.Name,
builds = CreateBuildsResponseModel(buildConfiguration)
};
return environment.Render(
"builds",
responseModel);
}
示例3: 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});
}
示例4: 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();
}
示例5: GetUsers
public static Task GetUsers(
IDictionary<string, object> environment,
Func<IDictionary<string, object>, Task> next)
{
var users = fn.GetUsers();
return environment.Render("users", new
{
users = users.Select(user => new
{
administrator = user.IsAdministrator ? " (Administrator)" : null,
isMe = user.Username == environment.GetUser().Username,
username = user.Username
})
});
}
示例6: GetHome
public static Task GetHome(
IDictionary<string, object> environment,
Func<IDictionary<string, object>, Task> next)
{
var buildConfigurations = fn.GetBuildConfigurations();
var configuredRepos = buildConfigurations
.Select(bc =>
new
{
owner = bc.Owner,
name = bc.Name,
lastBuild = fn.GetLastFinishedBuild(bc.Owner, bc.Name).To(build => new
{
id = build.Id,
description = fn.GetBuildDescription(build),
status = GetBuildStatus(build)
}),
currentBuild = fn.GetCurrentBuild(bc.Owner, bc.Name).To(build => new
{
id = build.Id,
description = fn.GetBuildDescription(build),
status = GetBuildStatus(build)
}),
nextBuild = fn.GetNextBuild(bc.Owner, bc.Name).To(build => new
{
id = build.Id,
description = fn.GetBuildDescription(build),
status = GetBuildStatus(build)
})
})
.ToList();
return environment.Render("home", new
{
configuredRepos
});
}
示例7: GetBuild
public static Task GetBuild(
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 id = int.Parse(@params.id as string);
var buildConfiguration = fn.GetBuildConfiguration(owner, name);
if (buildConfiguration == null)
{
environment.SetStatusCode(400);
return environment.GetCompleted();
}
var build = fn.GetBuild(id);
var sha = (string)null;
if (build.Revision != null)
sha = build.Revision.Substring(0, 7);
return environment.Render("build", new
{
id = build.Id,
description = fn.GetBuildDescription(build, includeRefDescription: true),
name = build.RepositoryName,
owner = build.RepositoryOwner,
@ref = build.Ref,
refDescription = fn.GetRefDescription(build),
revision = build.Revision,
sha,
failed = !build.Succeeded,
output = fn.Redact(build.Ouput),
status = GetBuildStatus(build)
});
}
示例8: 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});
}
示例9: GetSignInForm
public static Task GetSignInForm(
IDictionary<string, object> environment,
Func<IDictionary<string, object>, Task> next)
{
return environment.Render("sign-in-form", null);
}