Ejemplo n.º 1
0
        ///<exception cref = "ArgumentNullException" >Thrown if path or storagePath is null</exception >
        public void CreateRepository(string path, string storagePath, string name = "")
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (storagePath == null)
            {
                throw new ArgumentNullException(nameof(storagePath));
            }
            if (_db.Repositories.Any(r => r.Path == path))
            {
                throw new ArgumentException("such path exist", nameof(path));
            }

            System.IO.Directory.CreateDirectory(storagePath);
            var newRepo = new Repository
            {
                Path        = path,
                StoragePath = storagePath,
                Name        = !string.IsNullOrEmpty(name)?name:$"Repository {_db.Repositories.Count()+1}"
            };
            var initVersion = new Version
            {
                Date  = DateTime.Now,
                Label = "Initial commit",
                Files = StorageManager.GetFilesFromDirectory(path).ToList()
            };

            StorageManager.InitialDirectoryToStorage(path, storagePath);
            newRepo.Versions.Add(initVersion);
            _db.Repositories.Add(newRepo);
            _db.SaveChanges();
        }
Ejemplo n.º 2
0
        public void CreateVersion(Repository repository, string label = "")
        {
            List <File> latestFiles = new List <File>();
            var         repo        = _db.Repositories.Include(r => r.Versions).ThenInclude(v => v.Files).Single(r => r.Id == repository.Id);

            foreach (var repoVersion in repo.Versions)
            {
                foreach (var versionFile in repoVersion.Files)
                {
                    switch (versionFile.State)
                    {
                    case State.New:
                        latestFiles.Add(versionFile);
                        break;

                    case State.Deleted:
                        latestFiles.RemoveAll(file => file.Id == versionFile.Id);
                        break;

                    case State.Changed:
                        //replace file
                        latestFiles.RemoveAll(file => file.Id == versionFile.Id);
                        latestFiles.Add(versionFile);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }
            var actualFiles = StorageManager.GetActualForNewVersionFiles(latestFiles, repo.Path, repo.StoragePath);

            if (actualFiles.Count == 0)
            {
                throw new InvalidOperationException("No changes in repository yet");
            }
            StorageManager.MoveFilesToStorage(actualFiles, repo.Path, repo.StoragePath, repo.Versions.Count + 1);
            var newversion = new Version
            {
                Date  = DateTime.Now,
                Label = !string.IsNullOrEmpty(label) ? label : $"Version {repo.Versions.Count + 1}",
                Files = actualFiles
            };

            repo.Versions.Add(newversion);
            _db.Repositories.Update(repo);
            _db.SaveChanges();
        }
Ejemplo n.º 3
0
 public void RenameVersion(Version renamedVersion)
 {
     _db.Versions.Update(renamedVersion);
     _db.SaveChanges();
 }