当前位置: 首页>>代码示例>>C#>>正文


C# IDictionary.GetCompleted方法代码示例

本文整理汇总了C#中IDictionary.GetCompleted方法的典型用法代码示例。如果您正苦于以下问题:C# IDictionary.GetCompleted方法的具体用法?C# IDictionary.GetCompleted怎么用?C# IDictionary.GetCompleted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDictionary的用法示例。


在下文中一共展示了IDictionary.GetCompleted方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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});
        }
开发者ID:half-ogre,项目名称:qed,代码行数:59,代码来源:PostForceEvent.cs

示例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);
        }
开发者ID:half-ogre,项目名称:qed,代码行数:26,代码来源:GetBuilds.cs

示例3: DeleteSession

        public static Task DeleteSession(
            IDictionary<string, object> environment,
            Func<IDictionary<string, object>, Task> next)
        {
            var owinContext = new OwinContext(environment);

            owinContext.Authentication.SignOut(new [] { "Session" });

            environment.SetRedirect("/");
            return environment.GetCompleted();
        }
开发者ID:half-ogre,项目名称:qed,代码行数:11,代码来源:DeleteSession.cs

示例4: 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();
        }
开发者ID:half-ogre,项目名称:qed,代码行数:53,代码来源:PutSession.cs

示例5: 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();
        }
开发者ID:half-ogre,项目名称:qed,代码行数:51,代码来源:PostUsers.cs

示例6: 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();
        }
开发者ID:half-ogre,项目名称:qed,代码行数:24,代码来源:PatchUser.cs

示例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)
            });
        }
开发者ID:half-ogre,项目名称:qed,代码行数:37,代码来源:GetBuild.cs

示例8: 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();
        }
开发者ID:half-ogre,项目名称:qed,代码行数:77,代码来源:PostPushEvent.cs

示例9: 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});
        }
开发者ID:half-ogre,项目名称:qed,代码行数:74,代码来源:PostBuild.cs


注:本文中的IDictionary.GetCompleted方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。