Beispiel #1
0
        public async Task Should_write_asset_urls()
        {
            var me = new RefToken(RefTokenType.Subject, "123");

            var assetsUrl    = "https://old.squidex.com/api/assets/";
            var assetsUrlApp = "https://old.squidex.com/api/assets/my-app";

            A.CallTo(() => urlGenerator.AssetContentBase())
            .Returns(assetsUrl);

            A.CallTo(() => urlGenerator.AssetContentBase(appId.Name))
            .Returns(assetsUrlApp);

            var writer = A.Fake <IBackupWriter>();

            var context = new BackupContext(appId.Id, new UserMapping(me), writer);

            await sut.BackupEventAsync(Envelope.Create(new AppCreated
            {
                Name = appId.Name
            }), context);

            A.CallTo(() => writer.WriteJsonAsync(A <string> ._,
                                                 A <BackupContents.Urls> .That.Matches(x =>
                                                                                       x.Assets == assetsUrl &&
                                                                                       x.AssetsApp == assetsUrlApp)))
            .MustHaveHappened();
        }
Beispiel #2
0
        public async Task BackupAsync(BackupContext context,
                                      CancellationToken ct)
        {
            var json = await appUISettings.GetAsync(context.AppId, null);

            await context.Writer.WriteJsonAsync(SettingsFile, json, ct);
        }
Beispiel #3
0
        public void Store_Directory()
        {
            var fileSystem = new MockFileSystem();

            fileSystem.RegisterDirectory(@"C:\dir");

            var dateTime = new MockDateTime(new DateTime(2010, 10, 1, 0, 0, 0));

            var serviceContainer = new ManualServiceContainer();

            serviceContainer.Register <IFileSystem>(fileSystem);
            serviceContainer.Register <IDateTimeService>(dateTime);

            var executionContext = new ExecutionContext(serviceContainer);

            var directory = new DirectoryObject(@"C:\dir", fileSystem);

            var storage         = new DirectoryStorage(@"C:\backup");
            var storageInstance = storage.CreateInstance(executionContext);

            var backupContext = new BackupContext(null, executionContext);
            var result        = storageInstance.Store(directory, backupContext).ToArray();

            var expected = new IOperation[] {
                new CreateDirectoryOperation(new DirectoryObject(@"C:\backup\2010-10-01 00-00-00\C\dir", fileSystem), fileSystem, executionContext)
            };

            CollectionAssert.AreEqual(expected, result);
        }
Beispiel #4
0
        public void GetObjects()
        {
            var fileSystem = new MockFileSystem();

            fileSystem.RegisterDirectory(@"C:\dir");
            fileSystem.RegisterDirectory(@"C:\dir\dir1");
            fileSystem.RegisterFile(@"C:\dir\file1");
            fileSystem.RegisterFile(@"C:\file2");

            var serviceContainer = new ManualServiceContainer();

            serviceContainer.Register <IFileSystem>(fileSystem);

            var executionContext = new ExecutionContext(serviceContainer);

            var roots = new IFileSystemRoot[] {
                new DirectoryRoot(@"C:\dir", fileSystem),
                new FileRoot(@"C:\file2", fileSystem)
            };

            var source         = new FileSystemSource(roots);
            var sourceInstance = source.CreateInstance(executionContext);

            var backupContext = new BackupContext(null, executionContext);
            var result        = sourceInstance.GetObjects(backupContext).ToArray();

            var expected = new IObject[] {
                new DirectoryObject(@"C:\dir", fileSystem),
                new FileObject(@"C:\dir\file1", fileSystem),
                new DirectoryObject(@"C:\dir\dir1", fileSystem),
                new FileObject(@"C:\file2", fileSystem)
            };

            CollectionAssert.AreEqual(expected, result);
        }
        /// <summary>
        /// Add entity to the repository
        /// </summary>
        /// <param name="entity">the entity to add</param>
        public void Add(ClientInfo entity)
        {
            BackupContext.ClientInfos.Add(entity);
            var scheduledBackups = GetScheduledBackupsForNewlyRegisteredClient(entity);

            BackupContext.ScheduledBackups.AddRange(scheduledBackups);
            BackupContext.SaveChanges();
        }
Beispiel #6
0
        public static DisposeWrapper <BackupContext> Create()
        {
            var tmpFile = new TempFile();
            var ctx     = BackupContext.FromFile(tmpFile.Filename);

            ctx.Database.EnsureCreated();
            return(new DisposeWrapper <BackupContext>(ctx, _ => tmpFile.Dispose()));
        }
Beispiel #7
0
        public async Task BackupEventAsync(Envelope <IEvent> @event, BackupContext context)
        {
            if (@event.Payload is AppCreated appCreated)
            {
                var urls = GetUrls(appCreated.Name);

                await context.Writer.WriteJsonAsync(UrlsFile, urls);
            }
        }
Beispiel #8
0
        public Task BackupEventAsync(Envelope <IEvent> @event, BackupContext context)
        {
            switch (@event.Payload)
            {
            case AssetCreated assetCreated:
                return(WriteAssetAsync(assetCreated.AssetId, assetCreated.FileVersion, context.Writer));

            case AssetUpdated assetUpdated:
                return(WriteAssetAsync(assetUpdated.AssetId, assetUpdated.FileVersion, context.Writer));
            }

            return(Task.CompletedTask);
        }
Beispiel #9
0
        public async Task BackupEventAsync(Envelope <IEvent> @event, BackupContext context)
        {
            switch (@event.Payload)
            {
            case AppContributorAssigned appContributorAssigned:
                context.UserMapping.Backup(appContributorAssigned.ContributorId);
                break;

            case AppImageUploaded _:
                await WriteAssetAsync(context.AppId, context.Writer);

                break;
            }
        }
Beispiel #10
0
        private async Task BackupTagsAsync(BackupContext context,
                                           CancellationToken ct)
        {
            var tags = await tagService.GetExportableTagsAsync(context.AppId, TagGroups.Assets);

            if (tags.Tags != null)
            {
                await context.Writer.WriteJsonAsync(TagsFile, tags.Tags, ct);
            }

            if (tags.Alias?.Count > 0)
            {
                await context.Writer.WriteJsonAsync(TagsAliasFile, tags.Alias, ct);
            }
        }
Beispiel #11
0
        public void Store_Drive()
        {
            var fileSystem = new MockFileSystem();

            fileSystem.RegisterDrive(@"C:");

            var dateTime = new MockDateTime(new DateTime(2010, 10, 1, 0, 0, 0));

            var serviceContainer = new ManualServiceContainer();

            serviceContainer.Register <IFileSystem>(fileSystem);
            serviceContainer.Register <IDateTimeService>(dateTime);

            var executionContext = new ExecutionContext(serviceContainer);

            var drive = new DriveObject(@"C:", fileSystem);

            var storage         = new DirectoryStorage(@"C:\backup");
            var storageInstance = storage.CreateInstance(executionContext);

            var backupContext = new BackupContext(null, executionContext);
            var result        = storageInstance.Store(drive, backupContext).ToArray();
        }
Beispiel #12
0
        private async Task BackupTagsAsync(BackupContext context)
        {
            var tags = await tagService.GetExportableTagsAsync(context.AppId, TagGroups.Assets);

            await context.Writer.WriteJsonAsync(TagsFile, tags);
        }
 /// <summary>
 /// Mark entity to be deleted within the repository
 /// </summary>
 /// <param name="entity">The entity to delete</param>
 public void Delete(ClientInfo entity)
 {
     BackupContext.ClientInfos.Remove(entity);
     BackupContext.SaveChanges();
 }
Beispiel #14
0
        public static DisposeWrapper <BackupContext> Create(IEnumerable <string> entries)
        {
            var tmpFile = new TempFile();
            var ctx     = BackupContext.FromFile(tmpFile.Filename);

            ctx.Database.EnsureCreated();

            var resErrors = entries.Select(Fs.ReadEntry).ToList();
            var res       = resErrors.Where(x => x.Stat)
                            .Select(x => (x.Path, x.Name, Stat: x.Stat.Value)).ToList();

            var dirs     = res.Where(x => x.Stat.IsDir()).ToList();
            var files    = res.Where(x => x.Stat.IsFile()).ToList();
            var symlinks = res.Where(x => x.Stat.IsSymlink()).ToList();

            var dms = dirs.Select(d =>
            {
                var(path, name, stat) = d;
                var dm = new DirectoryModel
                {
                    Attributes = new AttributesModel(),
                    Name       = name,
                    Path       = path
                };
                dm.Attributes.SetStat(stat);
                ctx.Directories.Add(dm);

                return(dm);
            }).ToList();

            foreach (var(path, name, stat) in files)
            {
                var parent = dms.FirstOrDefault(d => d.Path == Paths.Directory(path));
                if (parent == null)
                {
                    throw new FsException(path, "No parent directory found in context.", Errno.ENOENT);
                }

                var fm = new FileModel
                {
                    Attributes = new AttributesModel(),
                    Directory  = parent,
                    Filename   = name
                };
                fm.Attributes.SetStat(stat);
                ctx.Files.Add(fm);
            }

            foreach (var(path, name, stat) in symlinks)
            {
                var parent = dms.FirstOrDefault(d => d.Path == Paths.Directory(path));
                if (parent == null)
                {
                    throw new FsException(path, "No parent directory found in context.");
                }

                var sm = new SymlinkModel
                {
                    Attributes = new AttributesModel(),
                    Directory  = parent,
                    Filename   = name
                };
                sm.Attributes.SetStat(stat);
                ctx.Symlinks.Add(sm);
            }

            return(new DisposeWrapper <BackupContext>(ctx, _ => tmpFile.Dispose()));
        }
Beispiel #15
0
        public async Task BackupAsync(BackupContext context)
        {
            var json = await appUISettings.GetAsync(context.AppId, null);

            await context.Writer.WriteJsonAsync(SettingsFile, json);
        }
Beispiel #16
0
 public BackupRepository(BackupContext context)
 {
     _context = context;
 }
 /// <summary>
 /// Mark entity to be deleted within the repository
 /// </summary>
 /// <param name="entity">The entity to delete</param>
 public void Delete(ScheduledBackup entity)
 {
     BackupContext.ScheduledBackups.Remove(entity);
     BackupContext.SaveChanges();
 }
 /// <summary>
 /// Add entity to the repository
 /// </summary>
 /// <param name="entity">the entity to add</param>
 public void Add(ScheduledBackup entity)
 {
     BackupContext.ScheduledBackups.Add(entity);
     BackupContext.SaveChanges();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ScheduledBackupRepository"/> class.
 /// </summary>
 /// <param name="backupContext">The backup context.</param>
 internal ScheduledBackupRepository(BackupContext backupContext) : base(backupContext)
 {
 }
 /// <summary>
 /// Updates entity within the the repository
 /// </summary>
 /// <param name="entity">the entity to update</param>
 public void Update(ScheduledBackup entity)
 {
     BackupContext.Entry(entity).State = EntityState.Modified;
     BackupContext.SaveChanges();
 }
Beispiel #21
0
 /// <summary>
 /// Updates entity within the the repository
 /// </summary>
 /// <param name="entity">the entity to update</param>
 public void Update(ActivityInfo entity)
 {
     BackupContext.Entry(entity).State = EntityState.Modified;
     BackupContext.SaveChanges();
 }
Beispiel #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ActivityInfoRepository"/> class.
 /// </summary>
 /// <param name="backupContext">The backup context.</param>
 internal ActivityInfoRepository(BackupContext backupContext) : base(backupContext)
 {
 }
Beispiel #23
0
 public Task BackupAsync(BackupContext context)
 {
     return(BackupTagsAsync(context));
 }
Beispiel #24
0
 /// <summary>
 /// Add entity to the repository
 /// </summary>
 /// <param name="entity">the entity to add</param>
 public void Add(ActivityInfo entity)
 {
     BackupContext.ActivityInfos.Add(entity);
     BackupContext.SaveChanges();
 }
Beispiel #25
0
 /// <summary>
 /// Mark entity to be deleted within the repository
 /// </summary>
 /// <param name="entity">The entity to delete</param>
 public void Delete(ActivityInfo entity)
 {
     BackupContext.ActivityInfos.Remove(entity);
     BackupContext.SaveChanges();
 }
Beispiel #26
0
 protected BaseEntityFrameworkRepository(BackupContext backupContext)
 {
     BackupContext = backupContext;
 }
Beispiel #27
0
 public Task BackupAsync(BackupContext context,
                         CancellationToken ct)
 {
     return(BackupTagsAsync(context, ct));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ClientInfoRepository"/> class.
 /// </summary>
 /// <param name="backupContext">The backup context.</param>
 internal ClientInfoRepository(BackupContext backupContext) : base(backupContext)
 {
 }