public void Setup()
        {
            this.folder = new Folder(Guid.NewGuid(), null, null)
            {
                Name = "path"
            };

            this.filerev      = new FileRevision(Guid.NewGuid(), null, null);
            this.filerev.Name = "filerev";

            this.filerev.FileType.Add(new FileType(Guid.NewGuid(), null, null)
            {
                Extension = "ext1"
            });
            this.filerev.FileType.Add(new FileType(Guid.NewGuid(), null, null)
            {
                Extension = null
            });
            this.filerev.FileType.Add(new FileType(Guid.NewGuid(), null, null)
            {
                Extension = ""
            });
            this.filerev.FileType.Add(new FileType(Guid.NewGuid(), null, null)
            {
                Extension = "ext2"
            });

            this.filerev.ContainingFolder = this.folder;
        }
Esempio n. 2
0
        /// <summary>
        /// <inheritdoc cref="ISourceControlProvider.ExportFileHistory"/>
        /// </summary>
        public List <FileRevision> ExportFileHistory(string localFile)
        {
            var result = new List <FileRevision>();

            var log = _gitCli.Log(localFile);

            var historyOfSingleFile = ParseLogString(log);

            foreach (var cs in historyOfSingleFile.ChangeSets)
            {
                var changeItem = cs.Items.First();

                var fi         = new FileInfo(localFile);
                var exportFile = GetPathToExportedFile(fi, cs.Id);

                if (!changeItem.IsDelete())
                {
                    // Download if not already in cache
                    if (!File.Exists(exportFile))
                    {
                        // If item is deleted we won't find it in this changeset.
                        _gitCli.ExportFileRevision(changeItem.ServerPath, cs.Id, exportFile);
                    }

                    var revision = new FileRevision(changeItem.LocalPath, cs.Id, cs.Date, exportFile);
                    result.Add(revision);
                }
            }

            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the corresponding file path in the <see cref="StorageDirectoryPath"/>
        /// </summary>
        /// <param name="fileRevision"></param>
        /// <returns>Full file path with pattern [StorageDirectoryPath]\\[name]_rev[RevisionNumber][extension]</returns>
        public string GetPath(FileRevision fileRevision)
        {
            var storageName     = this.GetName(fileRevision);
            var destinationPath = Path.Combine(StorageDirectoryPath, storageName);

            return(destinationPath);
        }
        public void Setup()
        {
            this.npgsqlTransaction = null;
            this.fileService       = new Mock <IFileService>();
            this.fileRevision      = new FileRevision(Guid.NewGuid(), 0);
            this.file = new File(Guid.NewGuid(), 0);

            this.fileStore = new DomainFileStore
            {
                Iid  = Guid.NewGuid(),
                File =
                {
                    this.file.Iid
                }
            };

            this.fileService = new Mock <IFileService>();

            this.domainFileStoreService = new Mock <IDomainFileStoreService>();

            this.sideEffect = new FileRevisionSideEffect
            {
                DomainFileStoreService = this.domainFileStoreService.Object,
                FileService            = this.fileService.Object,
            };
        }
Esempio n. 5
0
        public List <FileRevision> ExportFileHistory(string localFile)
        {
            var result = new List <FileRevision>();

            var xml = _gitCli.Log(localFile);

            var historyOfSingleFile = ParseLogString(xml);

            foreach (var cs in historyOfSingleFile.ChangeSets)
            {
                var changeItem = cs.Items.First();

                var fi         = new FileInfo(localFile);
                var exportFile = GetPathToExportedFile(fi, cs.Id);

                // Download if not already in cache
                if (!File.Exists(exportFile))
                {
                    _gitCli.ExportFileRevision(changeItem.ServerPath, cs.Id, exportFile);
                }

                var revision = new FileRevision(changeItem.LocalPath, cs.Id, cs.Date, exportFile);
                result.Add(revision);
            }

            return(result);
        }
Esempio n. 6
0
        public void GetCvsRevision_ReturnsExistingFileIfPresent()
        {
            var f = new FileRevision(new FileInfo("file.txt"), Revision.Create("1.1"),
                                     mergepoint: Revision.Empty,
                                     time: DateTime.Now,
                                     author: "fred",
                                     commitId: "c1");

            var contents = new FileContentData(new byte[] { 1, 2, 3, 4 }, 4);
            var repo1    = MockRepository.GenerateStub <ICvsRepository>();

            repo1.Stub(r => r.GetCvsRevision(f)).Return(new FileContent("file.txt", contents));
            var cache1 = new CvsRepositoryCache(m_temp.Path, repo1);

            cache1.GetCvsRevision(f);

            // create a second cache
            var repo2  = MockRepository.GenerateMock <ICvsRepository>();
            var cache2 = new CvsRepositoryCache(m_temp.Path, repo1);
            var data   = cache2.GetCvsRevision(f);

            repo2.AssertWasNotCalled(r => r.GetCvsRevision(f));
            Assert.AreNotSame(data.Data, contents);
            Assert.IsTrue(data.Data.Equals(contents));
        }
Esempio n. 7
0
        /// <summary>
        /// Update the properties of this row
        /// </summary>
        private void UpdateProperties()
        {
            // check if there is a new file revision
            var lastCreatedDate = this.Thing.FileRevision.Select(x => x.CreatedOn).Max();

            if (this.fileRevision == null)
            {
                this.fileRevision = this.Thing.FileRevision.First(x => x.CreatedOn == lastCreatedDate);
                this.UpdateFileRevisionProperties();
            }

            if (this.fileRevision.CreatedOn != lastCreatedDate)
            {
                this.fileRevision = this.Thing.FileRevision.First(x => x.CreatedOn == lastCreatedDate);
                ((IFileStoreRow)this.fileStoreRow).UpdateFileRowPosition(this.Thing, this.fileRevision);
                this.UpdateFileRevisionProperties();
            }

            this.IsLocked = this.Thing.LockedBy != null;
            if (this.IsLocked)
            {
                this.Locker = this.Thing.LockedBy.Name;
            }
            else
            {
                this.locker = string.Empty;
            }
        }
        /// <summary>
        /// Update the properties
        /// </summary>
        protected override void UpdateProperties()
        {
            base.UpdateProperties();

            this.currentPerson = null;

            var iteration = this.Container.GetContainerOfType <Iteration>();

            if (iteration != null)
            {
                if (this.Session.OpenIterations.TryGetValue(iteration, out var tuple))
                {
                    this.currentPerson = tuple?.Item2.Person;
                }
            }

            this.IsLocked = this.SelectedLockedBy != null;
            this.LockedBy = this.SelectedLockedBy?.Name;

            this.SelectedOwner =
                this.SelectedOwner ??
                (iteration == null ? null : this.Session.QuerySelectedDomainOfExpertise(iteration));

            this.CurrentFileRevision = this.Thing.CurrentFileRevision;
        }
        public void Setup()
        {
            this.Session           = new Mock <ISession>();
            this.fileDialogService = new Mock <IOpenSaveFileDialogService>();
            this.ServiceLocator    = new Mock <IServiceLocator>();
            Microsoft.Practices.ServiceLocation.ServiceLocator.SetLocatorProvider(() => this.ServiceLocator.Object);
            this.ServiceLocator.Setup(x => x.GetInstance <IOpenSaveFileDialogService>()).Returns(this.fileDialogService.Object);

            this.fileDialogService.Setup(
                x => x.GetSaveFileDialog(
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <string>(),
                    It.IsAny <int>()))
            .Returns(FileName);

            this.Session.Setup(x => x.ReadFile(It.IsAny <FileRevision>())).ReturnsAsync(Encoding.ASCII.GetBytes(FileContent));

            this.FileRevision = new FileRevision(Guid.NewGuid(), null, null)
            {
                Name             = "File",
                Creator          = new Participant(),
                ContainingFolder = new Folder(),
                CreatedOn        = DateTime.UtcNow.AddHours(-1),
                ContentHash      = "DOESNOTMATTER"
            };

            this.FileRevision.FileType.Add(new FileType());
        }
        public void SetUp()
        {
            this.fileExtensionMethodsTestFixture = new FileExtensionMethodsTestFixture();
            this.fileExtensionMethodsTestFixture.Setup();

            this.serviceLocator = this.fileExtensionMethodsTestFixture.ServiceLocator;
            ServiceLocator.SetLocatorProvider(() => this.serviceLocator.Object);

            this.messageBoxService = new Mock <IMessageBoxService>();
            this.serviceLocator.Setup(x => x.GetInstance <IMessageBoxService>()).Returns(this.messageBoxService.Object);

            this.session      = this.fileExtensionMethodsTestFixture.Session;
            this.fileRevision = this.fileExtensionMethodsTestFixture.FileRevision;

            this.file = new File();
            this.file.FileRevision.Add(this.fileRevision);

            this.downloadFileViewModel = new Mock <IDownloadFileViewModel>();
            this.downloadFileViewModel.Setup(x => x.Session).Returns(this.session.Object);

            this.session.Setup(x => x.ReadFile(this.fileRevision))
            .Callback(() =>
            {
                this.downloadFileViewModel.VerifySet(x => x.IsBusy         = true, Times.Once);
                this.downloadFileViewModel.VerifySet(x => x.IsBusy         = false, Times.Never);
                this.downloadFileViewModel.VerifySet(x => x.LoadingMessage = It.IsAny <string>(), Times.Once);
                System.Threading.Thread.Sleep(500);
                this.session.Verify(x => x.CanCancel(), Times.AtLeastOnce);
            })
            .ReturnsAsync(new byte[1]);

            this.service = new DownloadFileService();
        }
Esempio n. 11
0
        private static FileContent CreateMockContent(FileRevision f)
        {
            var data    = Encoding.UTF8.GetBytes(String.Format("{0} r{1}", f.File.Name, f.Revision.ToString()));
            var content = new FileContentData(data, data.Length);

            return(new FileContent(f.File.Name, content));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FileRevisionDialogViewModel"/> class.
        /// </summary>
        /// <param name="fileRevision">
        /// The <see cref="FileRevision"/> that is the subject of the current view-model. This is the object
        /// that will be either created, or edited.
        /// </param>
        /// <param name=""></param>
        /// <param name="transaction">
        /// The <see cref="ThingTransaction"/> that contains the log of recorded changes.
        /// </param>
        /// <param name="session">
        /// The <see cref="ISession"/> in which the current <see cref="Thing"/> is to be added or updated
        /// </param>
        /// <param name="isRoot">
        /// Assert if this <see cref="FileRevisionDialogViewModel"/> is the root of all <see cref="IThingDialogViewModel"/>
        /// </param>
        /// <param name="dialogKind">
        /// The kind of operation this <see cref="FileRevisionDialogViewModel"/> performs
        /// </param>
        /// <param name="thingDialogNavigationService">
        /// The <see cref="IThingDialogNavigationService"/>
        /// </param>
        /// <param name="container">
        /// The Container <see cref="Thing"/> of the created <see cref="Thing"/>
        /// </param>
        /// <param name="chainOfContainers">
        /// The optional chain of containers that contains the <paramref name="container"/> argument
        /// </param>
        public FileRevisionDialogViewModel(FileRevision fileRevision, IThingTransaction transaction, ISession session, bool isRoot, ThingDialogKind dialogKind,
                                           IThingDialogNavigationService thingDialogNavigationService, Thing container = null, IEnumerable <Thing> chainOfContainers = null)
            : base(fileRevision, transaction, session, isRoot, dialogKind, thingDialogNavigationService, container, chainOfContainers)
        {
            if (dialogKind == ThingDialogKind.Update)
            {
                throw new InvalidOperationException($"{nameof(ThingDialogKind.Update)} on a {nameof(FileRevision)} is not allowed.");
            }

            this.Disposables.Add(
                this.WhenAnyValue(x => x.Name, x => x.ContentHash)
                .Subscribe(_ =>
            {
                this.UpdateOkCanExecute();
                this.UpdatePath();
            }));

            this.Disposables.Add(
                this.WhenAnyValue(x => x.SelectedFileType, x => x.FileType)
                .Subscribe(_ =>
            {
                this.CanDeleteFileType = !this.IsReadOnly && (this.SelectedFileType != null);
                this.AfterUpdateFileType();
            }));

            this.Disposables.Add(this.FileType.Changed.Subscribe(_ => this.AfterUpdateFileType()));

            this.Disposables.Add(this.WhenAnyValue(x => x.SelectedContainingFolder).Subscribe(_ => this.UpdatePath()));

            this.Disposables.Add(this.WhenAnyValue(x => x.LocalPath).Subscribe(async _ =>
            {
                this.UpdateOkCanExecute();
                this.SetContentHash();
            }));
        }
Esempio n. 13
0
        public ActionResult Details(long?id)
        {
            FileRevision    file   = _db.FileRevision.Find(id);
            string          userId = User.Identity.GetUserId();
            ApplicationUser user   = _db.Users.Find(userId);


            if (file == null)
            {
                return(HttpNotFound());
            }
            else
            {
                //if (useDocu && DataFeeder.DocuCompatible(file.Extension))
                //{
                //    return View(file);
                //}
                //else
                //{
                string mimeType = MimeTypeMap.GetMimeType(file.Extension);
                string fileName = file.MasterFile.Number + "-" + file.Draft + "-" + file.MasterFile.Name + "-" + file.Name;
                Response.AddHeader("Content-Disposition", "inline; filename=" + fileName);

                return(File(file.FullPath, mimeType));
                //}
            }
        }
Esempio n. 14
0
        public void SetUp()
        {
            this.session = new Mock <ISession>();

            this.person = new Person(Guid.NewGuid(), this.cache, this.uri)
            {
                ShortName = "person",
                GivenName = "John",
                Surname   = "Doe"
            };
            this.participant = new Participant(Guid.NewGuid(), this.cache, this.uri)
            {
                Person   = this.person,
                IsActive = true,
            };

            this.store = new CommonFileStore(Guid.NewGuid(), this.cache, this.uri);

            this.store = new CommonFileStore(Guid.NewGuid(), this.cache, this.uri);
            this.file  = new File(Guid.NewGuid(), this.cache, this.uri);

            this.fileRevision1 = new FileRevision(Guid.NewGuid(), this.cache, this.uri)
            {
                Name      = "1",
                Creator   = this.participant,
                CreatedOn = new DateTime(1, 1, 1)
            };
            this.fileRevision2 = new FileRevision(Guid.NewGuid(), this.cache, this.uri)
            {
                Name      = "1.1",
                Creator   = this.participant,
                CreatedOn = new DateTime(1, 1, 2)
            };
        }
        public void VerifyOkButtonWorks()
        {
            var vm = new FileDialogViewModel(this.file, this.thingTransaction, this.session.Object, true, ThingDialogKind.Update, this.thingDialogNavigationService.Object, this.store);

            Assert.IsFalse(vm.OkCanExecute);

            vm.SelectedOwner = this.domain;
            Assert.IsFalse(vm.OkCanExecute);

            var fileRevision   = new FileRevision(Guid.NewGuid(), null, null);
            var fileRevisionVm = new FileRevisionRowViewModel(fileRevision, this.session.Object, vm);

            vm.FileRevision.Add(fileRevisionVm);
            Assert.IsTrue(vm.OkCanExecute);

            vm.IsLocked = true;
            Assert.IsTrue(vm.OkCanExecute);

            vm.IsLocked = false;
            Assert.IsTrue(vm.OkCanExecute);

            var otherPerson = new Person(Guid.NewGuid(), this.assembler.Cache, this.uri)
            {
                ShortName = "otherperson",
                GivenName = "otherperson",
            };

            vm.IsLocked         = true;
            vm.SelectedLockedBy = otherPerson;
            Assert.IsFalse(vm.OkCanExecute);
        }
Esempio n. 16
0
        // <summary>
        // Create new a new file within the specified project and give it the specified name.
        // Also create a file revision in the process with the given contents.
        // </summary>
        public int Create(string fileName, int projectID, string userID, string contents)
        {
            var node = new Node()
            {
                Name            = fileName,
                ParentNodeID    = -1,
                ProjectID       = projectID,
                CreatedByUserID = userID,
                Type            = NodeType.File,
                CreatedDate     = DateTime.Now
            };

            _context.Nodes.Add(node);
            _context.SaveChanges();

            var fileRevision = new FileRevision()
            {
                NodeID          = node.ID,
                Description     = "Revision of " + fileName + " saved " + DateTime.Now.ToString(),
                Contents        = System.Text.Encoding.UTF8.GetBytes(contents),
                CreatedByUserID = userID,
                CreatedDate     = DateTime.Now
            };

            _context.FileRevisions.Add(fileRevision);
            _context.SaveChanges();

            return(node.ID);
        }
Esempio n. 17
0
        private void ProcessXmlFile(string pathToFile, int sourceRepositoryId)
        {
            using (var input = new StreamReader(pathToFile))
            {
                var formatter = new XmlSerializer(typeof(RepositoryImage));
                var result    = (RepositoryImage)formatter.Deserialize(input);
                foreach (var inputRevision in result.Changesets)
                {
                    int revisionId;
                    using (var repository = new ExpertiseDBEntities())
                    {
                        var idString = inputRevision.Id.ToString();
                        var revision = repository.Revisions.SingleOrDefault(r => r.SourceRepositoryId == sourceRepositoryId && r.ID == idString);
                        if (revision == null)
                        {
                            revision = repository.Revisions.Add(
                                new Revision
                            {
                                Description        = inputRevision.Description,
                                ID                 = inputRevision.Id.ToString(),
                                Parent             = inputRevision.Parents,
                                SourceRepositoryId = sourceRepositoryId,
                                Tag                = inputRevision.Tag,
                                Time               = inputRevision.Date,
                                User               = inputRevision.User
                            });

                            repository.SaveChanges();
                            revisionId = revision.RevisionId;
                        }
                        else
                        {
                            Debug.WriteLine("Skipping Revison: " + revision.ID);
                            continue;
                        }
                    }

                    foreach (var fileChange in inputRevision.Files)
                    {
                        var file = new FileRevision
                        {
                            Diff =
                                fileChange.IsBinary
                                    ? null
                                    : System.Text.Encoding.ASCII.GetString(
                                    Convert.FromBase64String(fileChange.RawDiff)),
                            IsNew              = fileChange.IsNew,
                            LinesAdded         = fileChange.LinesAdded,
                            LinesDeleted       = fileChange.LinesDeleted,
                            RevisionId         = revisionId,
                            SourceRepositoryId = sourceRepositoryId
                        };

                        AddFileRevision(file, fileChange.Name);
                    }
                }
            }
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="fileRevision">The <see cref="FileRevision"/> of this representation</param>
        public HubFile(FileRevision fileRevision)
        {
            FileRev = fileRevision;

            FilePath        = FileRev.Path;
            RevisionNumber  = FileRev.RevisionNumber;
            CreatedOn       = FileRev.CreatedOn;
            CreatorFullName = $"{FileRev.Creator.Person.GivenName} {FileRev.Creator.Person.Surname.ToUpper()}";
        }
Esempio n. 19
0
        /// <summary>
        /// Gets the corresponding file name in the <see cref="StorageDirectoryPath"/>
        /// </summary>
        /// <param name="fileRevision"></param>
        /// <returns>The file name with pattern [name]_rev[RevisionNumber][extension]</returns>
        public string GetName(FileRevision fileRevision)
        {
            var fileName  = Path.GetFileNameWithoutExtension(fileRevision.Path);
            var extension = Path.GetExtension(fileRevision.Path);

            var storageName = $"{fileName}_rev{fileRevision.RevisionNumber}{extension}";

            return(storageName);
        }
        private static IEnumerable <FileStore> GetFileStores()
        {
            var fileStores = new List <FileStore>
            {
                new DomainFileStore(Guid.NewGuid(), null, null),
                new CommonFileStore(Guid.NewGuid(), null, null)
            };

            foreach (var fileStore in fileStores)
            {
                var folders = new List <Folder>();

                folders.Add(new Folder(Guid.NewGuid(), null, null));

                folders.Add(new Folder(Guid.NewGuid(), null, null)
                {
                    ContainingFolder = folders.First()
                });

                folders.Add(new Folder(Guid.NewGuid(), null, null));

                var participant = new Participant(Guid.NewGuid(), null, null)
                {
                    Person = new Person
                    {
                        GivenName = "test",
                        Surname   = "test"
                    }
                };

                File CreateFile(Folder folder)
                {
                    var file = new File(Guid.NewGuid(), null, null);

                    var fileRevision = new FileRevision(Guid.NewGuid(), null, null)
                    {
                        Name             = "File",
                        CreatedOn        = DateTime.UtcNow,
                        Creator          = participant,
                        ContainingFolder = folder
                    };

                    file.FileRevision.Add(fileRevision);
                    return(file);
                }

                var files = folders.Select(CreateFile).ToList();
                files.Add(CreateFile(null));

                fileStore.Folder.AddRange(folders);
                fileStore.File.AddRange(files);

                yield return(fileStore);
            }
        }
Esempio n. 21
0
        public ActionResult GetFile(long id)
        {
            FileRevision rev = _db.FileRevision.Find(id);

            string path = rev.FullPath;

            byte[] fileBytes = System.IO.File.ReadAllBytes(path);
            string fileName  = rev.MasterFile.Number + "-" + rev.Draft + "-" + rev.MasterFile.Name + "-" + rev.Name;

            return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName));
        }
Esempio n. 22
0
        public void patchFile(String path, FileRevision fr)
        {
            FileStream fs = File.OpenWrite(path);

            WebClient wc = new WebClient();
            wc.DownloadFileCompleted += new AsyncCompletedEventHandler(delegate(object source, AsyncCompletedEventArgs args){
                DownloadCompleted(fr);
            });
            wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(delegate(object source, DownloadProgressChangedEventArgs args)
            {
                DownloadProgress(fr, args);
            });
        }
Esempio n. 23
0
        public ActionResult Create([Bind(Include = "MasterFileId,Revision,Name,Comment")] FileRevision item, HttpPostedFileBase file, long pid)
        {
            if (ModelState.IsValid)
            {
                //double tmp;
                var    prev      = _db.FileRevision.Where(a => a.MasterFileId == item.MasterFileId).OrderByDescending(b => b.Id).Take(1).FirstOrDefault();
                string prefDraft = prev == null ? "" : prev.Draft;
                string draft     = _is.Increment(prefDraft);

                var rootPath = _is.GetRoot().Path;

                if (file != null)
                {
                    // vars
                    var    actionDate = DateTime.Now;
                    string extension  = Path.GetExtension(file.FileName).Replace(".", "").ToUpper();
                    var    filname    = System.IO.Path.GetFileNameWithoutExtension(file.FileName) + "_v" + item.Revision + "." + extension.ToLower();
                    string icon       = DataFeeder.GetIcon(extension);
                    // MasterFile setup
                    MasterFile parent    = _db.MasterFile.Find(item.MasterFileId);
                    var        fullpath  = Path.Combine(rootPath, parent.Number, filname);
                    var        changelog = parent.Changelog + string.Format("{0} - Revision added : {1} \n", actionDate, filname);
                    parent.Changelog = changelog;
                    parent.Edited    = actionDate;

                    //Revision setup
                    item.Added     = actionDate;
                    item.Name      = file.FileName;
                    item.FullPath  = fullpath;
                    item.Draft     = draft;
                    item.Type      = "draft";
                    item.Extension = extension;
                    item.Icon      = icon;
                    file.SaveAs(fullpath);

                    var    md5  = MD5.Create();
                    string hash = _is.GetMd5Hash(md5, fullpath);
                    item.Md5hash = hash;

                    _db.FileRevision.Add(item);
                    _db.SaveChanges();

                    return(Json(new { success = true, responseText = "Draft added", id = item.MasterFileId, parentId = pid }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { success = false, responseText = "File could not be loaded", id = item.MasterFileId, parentId = pid }, JsonRequestBehavior.AllowGet));
                }
            }
            return(Json(new { success = false, responseText = "Invalid model", id = item.MasterFileId, parentId = pid }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 24
0
        private void AddFileRevision(FileRevision fileRevision, string name)
        {
            using (var repository = new ExpertiseDBEntities())
            {
                var filename = repository.Filenames.SingleOrDefault(a => a.Name == name && a.SourceRepositoryId == fileRevision.SourceRepositoryId)
                               ??
                               new Filename {
                    Name = name, SourceRepositoryId = fileRevision.SourceRepositoryId
                };

                fileRevision.Filename = filename;
                repository.FileRevisions.Add(fileRevision);
                repository.SaveChanges();
            }
        }
Esempio n. 25
0
        public void Setup()
        {
            this.file    = new File(Guid.NewGuid(), null, null);
            this.folder1 = new Folder(Guid.NewGuid(), null, null);
            this.folder2 = new Folder(Guid.NewGuid(), null, null);

            this.oldFileRevision = new FileRevision(Guid.NewGuid(), null, null)
            {
                CreatedOn = DateTime.UtcNow.AddHours(-1), ContainingFolder = this.folder1
            };
            this.newFileRevision = new FileRevision(Guid.NewGuid(), null, null)
            {
                CreatedOn = DateTime.UtcNow, ContainingFolder = this.folder2
            };
        }
Esempio n. 26
0
        /// <summary>
        /// Creates a copy of this <see cref="FileRevision"/> that can be used to add as a new <see cref="FileRevision"/>
        /// </summary>
        /// <param name="fileRevision">The <see cref="FileRevision"/> to be copied</param>
        /// <param name="creator">The <see cref="Participant"/> that created this copy</param>
        /// <returns>The copy <see cref="FileRevision"/></returns>
        public static FileRevision CopyToNew(this FileRevision fileRevision, Participant creator)
        {
            var newFileRevision = new FileRevision
            {
                Name             = fileRevision.Name,
                CreatedOn        = DateTime.UtcNow,
                ContainingFolder = fileRevision.ContainingFolder,
                ContentHash      = fileRevision.ContentHash,
                Creator          = creator
            };

            newFileRevision.FileType.AddRange(fileRevision.FileType);

            return(newFileRevision);
        }
Esempio n. 27
0
        public void SetUp()
        {
            this.fileRevisionRuleChecker = new FileRevisionRuleChecker();

            this.modelReferenceDataLibrary = new ModelReferenceDataLibrary();
            this.engineeringModelSetup     = new EngineeringModelSetup();
            this.engineeringModel          = new EngineeringModel();
            this.commonFileStore           = new CommonFileStore();
            this.file         = new File();
            this.fileRevision = new FileRevision();

            this.engineeringModelSetup.RequiredRdl.Add(this.modelReferenceDataLibrary);
            this.engineeringModel.EngineeringModelSetup = this.engineeringModelSetup;
            this.engineeringModel.CommonFileStore.Add(commonFileStore);
            this.commonFileStore.File.Add(this.file);
            this.file.FileRevision.Add(this.fileRevision);
        }
Esempio n. 28
0
        public void GetCvsRevision_CallsUnderlyingIfFileMissing()
        {
            var f = new FileRevision(new FileInfo("file.txt"), Revision.Create("1.1"),
                                     mergepoint: Revision.Empty,
                                     time: DateTime.Now,
                                     author: "fred",
                                     commitId: "c1");

            var repo = MockRepository.GenerateMock <ICvsRepository>();

            repo.Expect(r => r.GetCvsRevision(f)).Return(new FileContent("file.txt", FileContentData.Empty));
            var cache = new CvsRepositoryCache(m_temp.Path, repo);

            cache.GetCvsRevision(f);

            repo.VerifyAllExpectations();
        }
Esempio n. 29
0
        /// <summary>
        /// Download a physical file from a <see cref="FileRevision"/> to the users' computer
        /// </summary>
        /// <param name="fileRevision">The <see cref="FileRevision"/></param>
        /// <param name="session">The <see cref="ISession"/></param>
        /// <returns>An awaitable task</returns>
        public static async Task DownloadFile(this FileRevision fileRevision, ISession session)
        {
            var fileName  = System.IO.Path.GetFileNameWithoutExtension(fileRevision.Path);
            var extension = System.IO.Path.GetExtension(fileRevision.Path);
            var filter    = string.IsNullOrWhiteSpace(extension) ? "All files (*.*)|*.*" : $"{extension.Replace(".", "")} files|*{extension}";

            var destinationPath = FileDialogService.GetSaveFileDialog(fileName, extension, filter, string.Empty, 1);

            if (!string.IsNullOrWhiteSpace(destinationPath))
            {
                var fileContent = await session.ReadFile(fileRevision);

                if (fileContent != null)
                {
                    System.IO.File.WriteAllBytes(destinationPath, fileContent);
                }
            }
        }
        /// <summary>
        /// Serialize the <see cref="FileRevision"/>
        /// </summary>
        /// <param name="fileRevision">The <see cref="FileRevision"/> to serialize</param>
        /// <returns>The <see cref="JObject"/></returns>
        private JObject Serialize(FileRevision fileRevision)
        {
            var jsonObject = new JObject();

            jsonObject.Add("classKind", this.PropertySerializerMap["classKind"](Enum.GetName(typeof(CDP4Common.CommonData.ClassKind), fileRevision.ClassKind)));
            jsonObject.Add("containingFolder", this.PropertySerializerMap["containingFolder"](fileRevision.ContainingFolder));
            jsonObject.Add("contentHash", this.PropertySerializerMap["contentHash"](fileRevision.ContentHash));
            jsonObject.Add("createdOn", this.PropertySerializerMap["createdOn"](fileRevision.CreatedOn));
            jsonObject.Add("creator", this.PropertySerializerMap["creator"](fileRevision.Creator));
            jsonObject.Add("excludedDomain", this.PropertySerializerMap["excludedDomain"](fileRevision.ExcludedDomain.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("excludedPerson", this.PropertySerializerMap["excludedPerson"](fileRevision.ExcludedPerson.OrderBy(x => x, this.guidComparer)));
            jsonObject.Add("fileType", this.PropertySerializerMap["fileType"](fileRevision.FileType.OrderBy(x => x, this.orderedItemComparer)));
            jsonObject.Add("iid", this.PropertySerializerMap["iid"](fileRevision.Iid));
            jsonObject.Add("modifiedOn", this.PropertySerializerMap["modifiedOn"](fileRevision.ModifiedOn));
            jsonObject.Add("name", this.PropertySerializerMap["name"](fileRevision.Name));
            jsonObject.Add("revisionNumber", this.PropertySerializerMap["revisionNumber"](fileRevision.RevisionNumber));
            jsonObject.Add("thingPreference", this.PropertySerializerMap["thingPreference"](fileRevision.ThingPreference));
            return(jsonObject);
        }
Esempio n. 31
0
        public void SetUp()
        {
            this.session = new Mock <ISession>();

            this.person             = new Person(Guid.NewGuid(), null, null);
            this.participant        = new Participant(Guid.NewGuid(), null, null);
            this.participant.Person = this.person;

            this.folder = new Folder(Guid.NewGuid(), null, null)
            {
                Name = "test"
            };
            this.file = new File(Guid.NewGuid(), null, null);

            this.fileRevision         = new FileRevision(Guid.NewGuid(), null, null);
            this.fileRevision.Creator = this.participant;
            this.file.FileRevision.Add(this.fileRevision);

            this.fileRevision.ContainingFolder = this.folder;
        }
Esempio n. 32
0
 void DownloadProgress(FileRevision fr, DownloadProgressChangedEventArgs args)
 {
     updateStatus(fr, (uint)args.ProgressPercentage);
 }
Esempio n. 33
0
 void DownloadCompleted(FileRevision fr)
 {
     updateStatus(fr, 100);
 }