private LoadSourcesResult LoadSourcesWithUpdate(SourceControlVersion sourceControlVersion, string path, SvnClient client)
        {
            SvnUpdateResult result;

            try
            {
                client.Update(path, out result);
            }
            catch (SvnInvalidNodeKindException e)
            {
                Directory.Delete(path, true);
                return(this.LoadSourcesFromScratch(sourceControlVersion, path, client));
            }
            catch (SvnWorkingCopyException e)
            {
                client.CleanUp(path);
                client.Update(path, out result);
            }

            SvnInfoEventArgs info;

            client.GetInfo(path, out info);

            return(new LoadSourcesResult
            {
                RevisionId = info.LastChangeRevision.ToString(CultureInfo.InvariantCulture)
            });
        }
 public void Archive(SourceControlVersion sourceControlVersion, string path)
 {
     if (Directory.Exists(path))
     {
         Directory.Delete(path, true);
     }
 }
        private ActionResult CreateNewVersionInternal(CreateNewSourceControlVersion model,
                                                      Action <SourceControlVersion> fillProperties)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.RedirectToAction("CreateNewVersion", new { id = model.FromSourceControlVersionId }));
            }

            SourceControlVersion sourceControlVersion = this.Entities.SourceControlVersion
                                                        .Include("SourceControl.Properties")
                                                        .Include("Properties")
                                                        .First(sc => sc.Id == model.FromSourceControlVersionId);

            SourceControlVersion newSourceControlVersion = new SourceControlVersion();

            newSourceControlVersion.SourceControl = sourceControlVersion.SourceControl;
            newSourceControlVersion.Name          = model.NewVersionName;
            newSourceControlVersion.ArchiveState  = SourceControlVersionArchiveState.Normal;

            fillProperties(newSourceControlVersion);

            newSourceControlVersion.ParentSourceControlVersion = sourceControlVersion;

            if (sourceControlVersion.IsHead)
            {
                sourceControlVersion.IsHead    = false;
                newSourceControlVersion.IsHead = true;
            }

            this.Entities.SourceControlVersion.Add(newSourceControlVersion);
            this.Entities.SaveChanges();

            return(this.RedirectToAction("Details", new { id = sourceControlVersion.SourceControl.Id }));
        }
 public LoadSourcesInfoResult LoadSourcesInfo(SourceControlVersion sourceControlVersion, string path)
 {
     return(new LoadSourcesInfoResult
     {
         SourcesInfos = new List <SourcesInfo>()
     });
 }
        public LoadSourcesResult LoadSources(SourceControlVersion sourceControlVersion, string path)
        {
            NetworkCredential credentials = new NetworkCredential(
                sourceControlVersion.SourceControl.GetStringProperty("Login"),
                sourceControlVersion.SourceControl.GetStringProperty("Password"));

            try
            {
                using (SvnClient client = new SvnClient())
                {
                    client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true);

                    client.Authentication.DefaultCredentials = credentials;

                    if (!Directory.Exists(path))
                    {
                        return(this.LoadSourcesFromScratch(sourceControlVersion, path, client));
                    }

                    return(this.LoadSourcesWithUpdate(sourceControlVersion, path, client));
                }
            }
            catch (SvnException e)
            {
                throw new AspNetDeployException("SvnClient failed to load sources", e);
            }
        }
        public TestSourceResult TestConnection(SourceControlVersion sourceControlVersion)
        {
            NetworkCredential credentials = new NetworkCredential(
                sourceControlVersion.SourceControl.GetStringProperty("Login"),
                sourceControlVersion.SourceControl.GetStringProperty("Password"));

            using (SvnClient client = new SvnClient())
            {
                client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true);

                client.Authentication.DefaultCredentials = credentials;

                try
                {
                    SvnInfoEventArgs info;
                    client.GetInfo(new Uri(this.GetVersionURI(sourceControlVersion)), out info);
                }
                catch (SvnException e)
                {
                    return(new TestSourceResult()
                    {
                        IsSuccess = false,
                        ErrorMessage = e.Message
                    });
                }

                return(new TestSourceResult()
                {
                    IsSuccess = true,
                });
            }
        }
Beispiel #7
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 LoadSourcesInfoResult LoadSourcesInfo(SourceControlVersion sourceControlVersion, string path)
        {
            NetworkCredential credentials = new NetworkCredential(
                sourceControlVersion.SourceControl.GetStringProperty("Login"),
                sourceControlVersion.SourceControl.GetStringProperty("Password"));

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

            if (latestRevision == null)
            {
                return(new LoadSourcesInfoResult
                {
                    SourcesInfos = new List <SourcesInfo>()
                });
            }

            SvnRevisionRange range = new SvnRevisionRange(long.Parse(latestRevision.Name), long.Parse(latestRevision.Name));

            if (latestRevision.ParentRevision != null)
            {
                range = new SvnRevisionRange(long.Parse(latestRevision.ParentRevision.Name) + 1, long.Parse(latestRevision.Name));
            }

            try
            {
                using (SvnClient client = new SvnClient())
                {
                    client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true);

                    client.Authentication.DefaultCredentials = credentials;

                    Collection <SvnLogEventArgs> logEventArgs;

                    client.GetLog(path, new SvnLogArgs
                    {
                        Range = range
                    }, out logEventArgs);

                    return(new LoadSourcesInfoResult
                    {
                        SourcesInfos = logEventArgs.Select(e => new SourcesInfo
                        {
                            CreatedDate = e.Time,
                            Author = e.Author,
                            Message = e.LogMessage
                        }).ToList()
                    });
                }
            }
            catch (SvnException e)
            {
                throw new AspNetDeployException("SvnClient failed to load sources", e);
            }
        }
        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()
            });
        }
        public bool CreateNewVersion(SourceControlVersion from, SourceControlVersion to)
        {
            NetworkCredential credentials = new NetworkCredential(
                from.SourceControl.GetStringProperty("Login"),
                from.SourceControl.GetStringProperty("Password"));

            using (SvnClient client = new SvnClient())
            {
                client.Authentication.DefaultCredentials = credentials;

                SvnTarget svnTarget = new SvnPathTarget(this.GetVersionURI(from));

                client.RemoteCopy(svnTarget, new Uri(this.GetVersionURI(to)));

                return(true);
            }
        }
        private LoadSourcesResult LoadSourcesFromScratch(SourceControlVersion sourceControlVersion, string path, SvnClient client)
        {
            SvnUpdateResult result;

            Directory.CreateDirectory(path);

            string uriString = this.GetVersionURI(sourceControlVersion);

            client.CheckOut(new Uri(uriString), path, out result);

            SvnInfoEventArgs info;

            client.GetInfo(path, out info);

            return(new LoadSourcesResult
            {
                RevisionId = info.LastChangeRevision.ToString(CultureInfo.InvariantCulture)
            });
        }
Beispiel #12
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
            });
        }
Beispiel #13
0
        public void Initialize(int sourceControlVersionId)
        {
            this.entities = new AspNetDeployEntities();

            this.sourceControlVersion = this.entities.SourceControlVersion
                                        .Include("Properties")
                                        .Include("SourceControl.Properties")
                                        .First(svc => svc.Id == sourceControlVersionId);

            this.existingProjects = this.entities.Project
                                    .Include("ProjectVersions")
                                    .Where(p => p.SourceControlId == sourceControlVersion.SourceControlId)
                                    .ToList();

            this.existingProjectVersions = existingProjects
                                           .SelectMany(p => p.ProjectVersions)
                                           .Where(pv => pv.SourceControlVersionId == sourceControlVersion.Id)
                                           .ToList();
        }
Beispiel #14
0
        public void Build(int sourceControlVersionId, int projectVersionId, Action <int> projectBuildStarted, Action <int, bool> projectBuildComplete)
        {
            AspNetDeployEntities entities = new AspNetDeployEntities();

            SourceControlVersion sourceControlVersion = entities.SourceControlVersion.Include("SourceControl").First(scv => scv.Id == sourceControlVersionId);
            ProjectVersion       projectVersion       = entities.ProjectVersion.Include("Properties").First(pv => pv.Id == projectVersionId);

            string        sourcesFolder = this.pathServices.GetSourceControlVersionPath(sourceControlVersion.SourceControl.Id, sourceControlVersion.Id);
            IBuildService buildService  = buildServiceFactory.Create(projectVersion.ProjectType);

            BuildSolutionResult buildSolutionResult = buildService.Build(
                sourcesFolder,
                projectVersion,
                projectFileName =>
            {
                ProjectVersion projectVersionBuild = entities.ProjectVersion
                                                     .Where(p => p.SourceControlVersionId == sourceControlVersionId)
                                                     .ToList()
                                                     .FirstOrDefault(p => !p.IsDeleted && Path.Combine(sourcesFolder, p.ProjectFile).ToLowerInvariant() == projectFileName.ToLowerInvariant());

                if (projectVersionBuild != null)
                {
                    projectBuildStarted(projectVersionBuild.Id);
                }
            },
                (projectFileName, success, message) =>
            {
                ProjectVersion projectVersionBuild = entities.ProjectVersion
                                                     .Where(p => p.SourceControlVersionId == sourceControlVersionId)
                                                     .ToList()
                                                     .FirstOrDefault(p => !p.IsDeleted && Path.Combine(sourcesFolder, p.ProjectFile).ToLowerInvariant() == projectFileName.ToLowerInvariant());

                if (projectVersionBuild != null)
                {
                    projectBuildComplete(projectVersionBuild.Id, success);
                }
            },
                (projectFile, exception) =>
            {
                this.loggingService.Log(new AspNetDeployException("Project build failed: " + projectFile, exception), null);
            });
        }
        public ActionResult ArchiveVersion(int id)
        {
            this.CheckPermission(UserRoleAction.SourceVersionsManage);

            SourceControlVersion sourceControlVersion = this.Entities.SourceControlVersion
                                                        .Include("Properties")
                                                        .Include("ProjectVersions.BundleVersions")
                                                        .First(sc => sc.Id == id);

            if (sourceControlVersion.ArchiveState == SourceControlVersionArchiveState.Archived ||
                sourceControlVersion.ArchiveState == SourceControlVersionArchiveState.Archiving)
            {
                return(this.RedirectToAction("Details", new { id = sourceControlVersion.SourceControl.Id }));
            }

            sourceControlVersion.ArchiveState = SourceControlVersionArchiveState.Archiving;
            this.Entities.SaveChanges();

            return(this.RedirectToAction("Details", new { id = sourceControlVersion.SourceControl.Id }));
        }
        public ActionResult AddSvn(AddSvnModel model)
        {
            this.CheckPermission(UserRoleAction.SourceVersionsManage);

            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            SourceControl sourceControl = new SourceControl
            {
                Type       = SourceControlType.Svn,
                Name       = model.Name,
                IsDeleted  = false,
                OrderIndex = this.Entities.SourceControl.Count()
            };

            sourceControl.SetStringProperty("URL", model.Url.Trim());
            sourceControl.SetStringProperty("Login", model.Login.Trim());
            sourceControl.SetStringProperty("Password", model.Password.Trim());

            SourceControlVersion sourceControlVersion = new SourceControlVersion();

            sourceControlVersion.SourceControl = sourceControl;
            sourceControlVersion.SetStringProperty("URL", "/");

            TestSourceResult testSourceResult = this.sourceControlManager.TestConnection(sourceControlVersion);

            if (!testSourceResult.IsSuccess)
            {
                this.ModelState.AddModelError("URL", testSourceResult.ErrorMessage);
                return(this.View(model));
            }

            sourceControlVersion.SourceControl = null;

            this.Entities.SourceControl.Add(sourceControl);
            this.Entities.SaveChanges();

            return(this.RedirectToAction("List"));
        }
        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();
        }
        public ArhiveResult Archive(int sourceControlVersionId)
        {
            AspNetDeployEntities entities = new AspNetDeployEntities();

            SourceControlVersion sourceControlVersion = entities.SourceControlVersion
                                                        .Include("Properties")
                                                        .First(sc => sc.Id == sourceControlVersionId);

            ISourceControlRepository repository = this.sourceControlRepositoryFactory.Create(sourceControlVersion.SourceControl.Type);
            string sourcesFolder = this.pathServices.GetSourceControlVersionPath(sourceControlVersion.SourceControlId, sourceControlVersion.Id);

            repository.Archive(sourceControlVersion, sourcesFolder);

            sourceControlVersion.ArchiveState = SourceControlVersionArchiveState.Archived;
            entities.SaveChanges();

            return(new ArhiveResult()
            {
                IsSuccess = true
            });
        }
        public TestSourceResult TestConnection(SourceControlVersion sourceControlVersion)
        {
            ISourceControlRepository repository = this.sourceControlRepositoryFactory.Create(sourceControlVersion.SourceControl.Type);

            return(repository.TestConnection(sourceControlVersion));

            /*string sourcesFolder = this.pathServices.GetSourceControlVersionPath(sourceControlVersion.SourceControl.Id, sourceControlVersion.Id);
             * string revisionId = null;
             * string exceptionMessage = null;
             *
             * ISourceControlRepository repository = this.sourceControlRepositoryFactory.Create(sourceControlVersion.SourceControl.Type);
             * repository.Archive(sourceControlVersion, sourcesFolder);
             *
             * Task.Run(() =>
             * {
             *  try
             *  {
             *      LoadSourcesResult loadSourcesResult = this.LoadSources(sourceControlVersion, sourcesFolder);
             *      revisionId = loadSourcesResult.RevisionId;
             *  }
             *  catch (AspNetDeployException e)
             *  {
             *      exceptionMessage = e.InnerException.Message;
             *  }
             * }).Wait(1000);
             *
             *
             *
             *
             * return new TestSourceResult()
             * {
             *  IsSuccess = revisionId != null,
             *  ErrorMessage = exceptionMessage
             * };*/

            return(new TestSourceResult
            {
                IsSuccess = true
            });
        }
        public ActionResult CreateNewVersion(int id)
        {
            this.CheckPermission(UserRoleAction.SourceVersionsManage);

            SourceControlVersion sourceControlVersion = this.Entities.SourceControlVersion
                                                        .Include("SourceControl.Properties")
                                                        .Include("Properties")
                                                        .First(sc => sc.Id == id);

            this.ViewBag.SourceControlVersion = sourceControlVersion;

            if (sourceControlVersion.SourceControl.Type == SourceControlType.Svn)
            {
                return(this.View("CreateNewVersionSVN"));
            }

            if (sourceControlVersion.SourceControl.Type == SourceControlType.FileSystem)
            {
                return(this.View("CreateNewVersionFileSystem"));
            }

            throw new NotSupportedException();
        }
 public void Archive(SourceControlVersion sourceControlVersion, string path)
 {
     throw new NotImplementedException();
 }
 public TestSourceResult TestConnection(SourceControlVersion sourceControlVersion)
 {
     throw new NotImplementedException();
 }
        private LoadSourcesInfoResult LoadSourcesInfo(SourceControlVersion sourceControlVersion, string sourcesFolder)
        {
            ISourceControlRepository repository = this.sourceControlRepositoryFactory.Create(sourceControlVersion.SourceControl.Type);

            return(repository.LoadSourcesInfo(sourceControlVersion, sourcesFolder));
        }
        public ActionResult List()
        {
            IList <Bundle> bundles = this.bundleRepository.List();

            List <Environment> environments = this.Entities.Environment
                                              .Include("NextEnvironment")
                                              .ToList();

            int[] array = bundles.SelectMany(b => b.BundleVersions).Select(bv => bv.Id).Distinct().ToArray();

            IDictionary <int, List <int> > bundleVersionProjects = this.projectRepository.ListBundleVersionProjects(array);

            IList <ProjectVersion> projectVersions = projectRepository.ListForBundles(array);
            IList <Publication>    publications    = this.publicationRepository.ListForBundles(array);

            IDictionary <SourceControlVersion, SourceControl> sourceControls = new Dictionary <SourceControlVersion, SourceControl>();

            foreach (SourceControl sourceControl in this.sourceRepository.List(excludeArchived: false))
            {
                foreach (SourceControlVersion sourceControlVersion in sourceControl.SourceControlVersions)
                {
                    sourceControls.Add(sourceControlVersion, sourceControl);
                }
            }

            this.ViewBag.Bundles = bundles.Select(b => new BundleInfo
            {
                Bundle             = b,
                BundleVersionsInfo = b.BundleVersions
                                     .Where(bv => !bv.IsDeleted)
                                     .OrderByDescending(bv => bv.Id)
                                     .Take(2)
                                     .Select(bv =>
                {
                    BundleVersionInfo bundleVersionInfo = new BundleVersionInfo()
                    {
                        BundleVersion        = bv,
                        State                = this.taskRunner.GetBundleState(b.Id),
                        ProjectsVersionsInfo = bundleVersionProjects.ContainsKey(bv.Id)
                                ? bundleVersionProjects[bv.Id]
                                               .Select(pvId =>
                        {
                            ProjectVersion projectVersion = projectVersions.FirstOrDefault(pv => pv.Id == pvId);
                            SourceControlVersion version  = sourceControls.Keys.FirstOrDefault(scv => scv.Id == projectVersion.SourceControlVersionId);

                            return(new ProjectVersionInfo
                            {
                                ProjectVersion = projectVersion,
                                SourceControlVersion = version,
                                SourceControl = sourceControls[version]
                            });
                        })
                                               .ToList()
                                : new List <ProjectVersionInfo>(),
                        Publications = publications.Where(p => p.Package.BundleVersionId == bv.Id).GroupBy(p => p.Environment.Id).ToDictionary(k => k.Key, v => v.ToList())
                    };

                    bundleVersionInfo.Environments = new List <Environment>();
                    int homeEnvironmentId          = bv.GetIntProperty("HomeEnvironment");

                    if (homeEnvironmentId > 0)
                    {
                        bundleVersionInfo.Environments = environments.First(e => e.Id == homeEnvironmentId).GetNextEnvironments();
                    }

                    return(bundleVersionInfo);
                }).ToList()
            }).ToList();

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