Пример #1
0
        public async Task BackupDeployment(int deploymentId)
        {
            Deployment deployment = await _deploymentRepository.GetDeployment(deploymentId);

            if (deployment == null)
            {
                return;
            }

            Server server = await _serverRepository.GetServer(deployment.Server);

            IReadOnlyCollection <Deployment> deployments = await _deploymentRepository.GetServerDeployments(deployment.Server);

            IRemoteClient client = GetClient(server);

            string backupPath = await GetVersionedRemotePath(client, deployment, server.Paths.Backup);

            IReadOnlyCollection <string> skipPaths = deployments
                                                     .Except(new[] { deployment })
                                                     .Select(x => x.RemotePath)
                                                     .ToArray();

            await CopyRemoteFolder(client, deployment.RemotePath, backupPath, skipPaths);
        }
Пример #2
0
        public IndexModule(IGithubUserRepository githubUserRepository, IDeploymentRepository deploymentRepository, IRootPathProvider rootPathProvider)
        {
            this.githubUserRepository = githubUserRepository;
            this.rootPathProvider     = rootPathProvider;

            this.snowPreCompilerPath = rootPathProvider.GetRootPath() + "PreCompiler\\Sandra.Snow.Precompiler.exe";

            Post["/"] = parameters =>
            {
                var payloadModel = this.Bind <GithubHookModel.RootObject>();

                //Check if user is registered
                var githubhookfromUsername = payloadModel.repository.owner.name;
                var githubhookfromRepo     = payloadModel.repository.url;

                if (!githubUserRepository.UserRegistered(githubhookfromUsername, githubhookfromRepo))
                {
                    return(HttpStatusCode.Forbidden);
                }

                var deploymentModel = deploymentRepository.GetDeployment(githubhookfromUsername);

                DeployBlog(deploymentModel);

                return(200);
            };

            Get["/"] = parameters => { return(View["Index"]); };

            Get["/repos"] = parameters =>
            {
                return(View["Repos"]);
            };

            Get["getrepodata/{githubuser}"] = parameters =>
            {
                var githubUser = (string)parameters.githubuser;

                var client = new RestClient("https://api.github.com");

                var request = new RestRequest("users/" + githubUser + "/repos");
                request.AddHeader("Accept", "application/json");

                var response = client.Execute <List <GithubUserRepos.RootObject> >(request);

                var repoDetail =
                    response.Data
                    //.Where(x => x.fork == false)
                    .Select(
                        x =>
                        new RepoDetail
                {
                    Name        = x.name,
                    AvatarUrl   = x.owner.avatar_url,
                    Description = x.description,
                    HtmlUrl     = x.html_url,
                    UpdatedAt   = DateTime.Parse(x.pushed_at).ToRelativeTime(),
                    CloneUrl    = x.clone_url
                });

                var viewModel = new RepoModel {
                    Username = githubUser, Repos = repoDetail
                };

                return(viewModel);
            };

            Post["initializedeployment"] = parameters =>
            {
                var model = this.BindAndValidate <DeploymentModel>();
                if (!this.ModelValidationResult.IsValid)
                {
                    return(400);
                }

                DeployBlog(model);

                deploymentRepository.AddDeployment(model);

                Thread.Sleep(2500);

                return("deployed");
            };

            Post["/alreadyregistered"] = parameters =>
            {
                var model = this.Bind <AlreadyRegisteredModel>();

                var alreadyRegistered = deploymentRepository.IsUserAndRepoRegistered(model.AzureDeployment, model.Repo, model.Username);

                var keys = new List <string>();
                keys.Add(model.AzureDeployment ? "azurerepo" : "ftpserver");

                return(new { isValid = !alreadyRegistered, keys = keys });
            };
        }
Пример #3
0
        public IndexModule(IGithubUserRepository githubUserRepository, IDeploymentRepository deploymentRepository, IRootPathProvider rootPathProvider)
        {
            this.githubUserRepository = githubUserRepository;
            this.rootPathProvider = rootPathProvider;

            this.snowPreCompilerPath = rootPathProvider.GetRootPath() + "PreCompiler\\Sandra.Snow.Precompiler.exe";

            Post["/"] = parameters =>
                {
                    var payloadModel = this.Bind<GithubHookModel.RootObject>();

                    //Check if user is registered
                    var githubhookfromUsername = payloadModel.repository.owner.name;
                    var githubhookfromRepo = payloadModel.repository.url;

                    if (!githubUserRepository.UserRegistered(githubhookfromUsername, githubhookfromRepo))
                        return HttpStatusCode.Forbidden;

                    var deploymentModel = deploymentRepository.GetDeployment(githubhookfromUsername);

                    DeployBlog(deploymentModel);

                    return 200;
                };

            Get["/"] = parameters => { return View["Index"]; };

            Get["/repos"] = parameters =>
            {
                return View["Repos"];
            };

            Get["getrepodata/{githubuser}"] = parameters =>
                {
                    var githubUser = (string)parameters.githubuser;

                    var client = new RestClient("https://api.github.com");

                    var request = new RestRequest("users/" + githubUser + "/repos");
                    request.AddHeader("Accept", "application/json");

                    var response = client.Execute<List<GithubUserRepos.RootObject>>(request);

                    var repoDetail =
                        response.Data
                        //.Where(x => x.fork == false)
                        .Select(
                            x =>
                            new RepoDetail
                            {
                                Name = x.name,
                                AvatarUrl = x.owner.avatar_url,
                                Description = x.description,
                                HtmlUrl = x.html_url,
                                UpdatedAt = DateTime.Parse(x.pushed_at).ToRelativeTime(),
                                CloneUrl = x.clone_url
                            });

                    var viewModel = new RepoModel { Username = githubUser, Repos = repoDetail };

                    return viewModel;
                };

            Post["initializedeployment"] = parameters =>
                {
                    var model = this.BindAndValidate<DeploymentModel>();
                    if (!this.ModelValidationResult.IsValid)
                    {
                        return 400;
                    }

                    DeployBlog(model);

                    deploymentRepository.AddDeployment(model);

                    Thread.Sleep(2500);

                    return "deployed";
                };

            Post["/alreadyregistered"] = parameters =>
                {
                    var model = this.Bind<AlreadyRegisteredModel>();

                    var alreadyRegistered = deploymentRepository.IsUserAndRepoRegistered(model.AzureDeployment, model.Repo, model.Username);

                    var keys = new List<string>();
                    keys.Add(model.AzureDeployment ? "azurerepo" : "ftpserver");

                    return new { isValid = !alreadyRegistered, keys = keys };
                };
        }