Exemplo n.º 1
0
        public void Start(int projectVersionId, Action <int> projectBuildStarted, Action <int, bool> projectBuildComplete)
        {
            AspNetDeployEntities entities = new AspNetDeployEntities();

            ProjectVersion projectVersion = entities.ProjectVersion
                                            .Include("Properties")
                                            .First(pv => pv.Id == projectVersionId);


            SourceControlVersion sourceControlVersion = entities.SourceControlVersion
                                                        .Include("Properties")
                                                        .First(scv => scv.Id == projectVersion.SourceControlVersionId);

            IDictionary <int, DateTime> buildTiming = new Dictionary <int, DateTime>();

            BuildManager buildManager = Factory.GetInstance <BuildManager>();

            buildManager.Build(
                sourceControlVersion.Id,
                projectVersionId,
                projectVersionBuildId =>
            {
                projectBuildStarted(projectVersionBuildId);

                if (buildTiming.ContainsKey(projectVersionBuildId))
                {
                    buildTiming.Remove(projectVersionBuildId);
                }

                ProjectVersion projectVersionBuild = entities.ProjectVersion
                                                     .Include("Properties")
                                                     .First(pv => pv.Id == projectVersionBuildId);

                projectVersionBuild.SetStringProperty("LastBuildStartDate", DateTime.UtcNow.ToString(CultureInfo.InvariantCulture));
                entities.SaveChanges();

                buildTiming[projectVersionBuildId] = DateTime.UtcNow;
            },
                (projectVersionBuildId, isSuccess) =>
            {
                projectBuildComplete(projectVersionBuildId, isSuccess);

                ProjectVersion projectVersionBuild = entities.ProjectVersion
                                                     .Include("Properties")
                                                     .First(pv => pv.Id == projectVersionBuildId);

                projectVersionBuild.SetStringProperty("LastBuildRevision", sourceControlVersion.GetStringProperty("Revision"));
                projectVersionBuild.SetStringProperty("LastBuildDate", DateTime.UtcNow.ToString(CultureInfo.InvariantCulture));
                projectVersionBuild.SetStringProperty("LastBuildResult", isSuccess ? "Done" : "Error");
                projectVersionBuild.SetStringProperty("LastBuildDuration", (DateTime.UtcNow - buildTiming[projectVersionBuildId]).TotalSeconds.ToString(CultureInfo.InvariantCulture));

                entities.SaveChanges();
            });



            entities.SaveChanges();
        }
        public UpdateAndParseResult UpdateAndParse(int sourceControlVersionId)
        {
            AspNetDeployEntities entities             = new AspNetDeployEntities();
            SourceControlVersion sourceControlVersion = entities.SourceControlVersion
                                                        .Include("Properties")
                                                        .Include("Revisions")
                                                        .Include("SourceControl.Properties")
                                                        .First(svc => svc.Id == sourceControlVersionId);

            SourceControl sourceControl = sourceControlVersion.SourceControl;

            string            sourcesFolder     = this.pathServices.GetSourceControlVersionPath(sourceControl.Id, sourceControlVersion.Id);
            LoadSourcesResult loadSourcesResult = this.LoadSources(sourceControlVersion, sourcesFolder);

            if (loadSourcesResult.RevisionId == sourceControlVersion.GetStringProperty("Revision"))
            {
                return(new UpdateAndParseResult());
            }

            sourceControlVersion.SetStringProperty("Revision", loadSourcesResult.RevisionId);

            Revision previousRevision = sourceControlVersion.Revisions.OrderByDescending(r => r.CreatedDate).FirstOrDefault();

            Revision newRevision = new Revision
            {
                CreatedDate    = DateTime.UtcNow,
                Name           = loadSourcesResult.RevisionId,
                ParentRevision = previousRevision
            };

            sourceControlVersion.Revisions.Add(newRevision);

            LoadSourcesInfoResult loadSourcesInfoResult = this.LoadSourcesInfo(sourceControlVersion, sourcesFolder);

            newRevision.RevisionInfos = loadSourcesInfoResult.SourcesInfos.Select(i => new RevisionInfo
            {
                Author      = i.Author,
                CreatedDate = i.CreatedDate,
                Message     = i.Message
            }).ToList();

            entities.SaveChanges();

            this.projectParsingService.UpdateProjects(sourceControlVersionId);

            return(new UpdateAndParseResult
            {
                HasChanges = true,
                Projects = entities.Project.Where(p => p.SourceControlId == sourceControlVersion.Id).Select(p => p.Id).ToList()
            });
        }
Exemplo n.º 3
0
        public LoadSourcesResult LoadSources(SourceControlVersion sourceControlVersion, string path)
        {
            string workingDirectory;

            if (sourceControlVersion.SourceControl.GetBoolProperty("IsRelativeMode"))
            {
                workingDirectory = Path.Combine(sourceControlVersion.SourceControl.GetStringProperty("Path"), sourceControlVersion.GetStringProperty("Path"));
            }
            else
            {
                workingDirectory = sourceControlVersion.SourceControl.GetStringProperty("Path");
            }

            List <string> filePaths = Directory.GetFiles(workingDirectory, "*.zip", SearchOption.TopDirectoryOnly).ToList();

            string revisionId = string.Join(
                ";",
                filePaths
                .Select(f =>
                        f.GetHashCode().ToString(CultureInfo.InvariantCulture) +
                        File.GetLastWriteTimeUtc(f).ToString(CultureInfo.InvariantCulture)))
                                .GetHashCode()
                                .ToString(CultureInfo.InvariantCulture);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            if (sourceControlVersion.GetStringProperty("Revision") != revisionId) // yeah, dirty
            {
                DeleteContents(path);
                foreach (string filePath in filePaths)
                {
                    File.Copy(filePath, Path.Combine(path, Path.GetFileName(filePath)));
                }
            }

            return(new LoadSourcesResult
            {
                RevisionId = revisionId
            });
        }
        public LoadSourcesResult LoadSources(SourceControlVersion sourceControlVersion, string path)
        {
            Repository repository;

            if (Repository.IsValid(path))
            {
                repository = new Repository(path);
            }
            else
            {
                CloneCommand command = new CloneCommand
                {
                    Source       = sourceControlVersion.SourceControl.GetStringProperty("URL") + "/" + sourceControlVersion.GetStringProperty("URL"),
                    GitDirectory = path,
                };

                command.Execute();
            }

            throw new NotImplementedException();
        }
 private string GetVersionURI(SourceControlVersion sourceControlVersion)
 {
     return(sourceControlVersion.SourceControl.GetStringProperty("URL") + "/" + sourceControlVersion.GetStringProperty("URL").TrimStart('/'));
 }