Exemplo n.º 1
0
 public void Setup()
 {
     _platform       = new TestPlatform();
     _session        = new Session(_platform, "/");
     _collectionFile = _session["articles"];
     _products       = _collectionFile.Collection <Product, Guid>("products", p => p.Id);
 }
Exemplo n.º 2
0
 public void Setup()
 {
     _platform       = new TestPlatform();
     _session        = new Session(_platform, "/");
     _provider       = (InMemoryStreamProvider)_session.StreamProvider;
     _collectionFile = _session["articles"];
     _articles       = _collectionFile.Collection <Article, int>("articles", a => a.ID);
 }
Exemplo n.º 3
0
    public async Task Add(CollectionFile collectionFile)
    {
        var entity = _mapper.Map <CollectionFileEntity>(collectionFile);

        _collectionFileCacheService.AddToFilter(collectionFile.CollectionId, entity.Path);

        await _roomDbContext.CollectionFiles.AddAsync(entity);
    }
Exemplo n.º 4
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         database = null;
         session.Dispose();
     }
 }
Exemplo n.º 5
0
 public Collection <T, string> GetCollection <T>() where T : IObjectIdentifier
 {
     try
     {
         var collectionName = $"{typeof(T).Name}s";
         return(CollectionFile.Collection <T, string>(collectionName, x => x.Identifier));
     }
     catch (Exception ex)
     {
         throw new Exception($"Error getting collection {ex.Message}");
     }
 }
Exemplo n.º 6
0
    public async Task <Guid> SaveNew(
        MovedInformation movedInformation,
        Guid collectionId)
    {
        var newFile = new CollectionFile(Guid.NewGuid(),
                                         collectionId,
                                         movedInformation.MovedFileInfo.FullName,
                                         movedInformation.SystemFile.Md5,
                                         movedInformation.SystemFile.Size,
                                         movedInformation.SystemFile.File.FullName);

        await _collectionFileRepository.Add(newFile);

        return(newFile.Id);
    }
Exemplo n.º 7
0
 public void Setup()
 {
     _platform       = new TestPlatform();
     _session        = new Session(_platform, "/");
     _collectionFile = _session["indexables"];
 }
        public CollectionFile Create(
            [NotNull] ISMAPlugin requester,
            int elementId,
            [NotNull] Action <Stream> streamWriter,
            string extension,
            string crc32 = null)
        {
            if (elementId <= 0)
            {
                return(null);
            }

            CollectionFSFile dbFile = null;

            try
            {
                extension = extension?.TrimStart('.');

                dbFile = new CollectionFSFile
                {
                    ElementId = elementId,
                    Extension = extension ?? string.Empty,
                    PluginId  = requester.Id
                };

                dbFile.Id = DbFiles.Insert(dbFile).AsInt32;

                CollectionFile colFile = FromDbFile(dbFile);

                DirectoryEx.EnsureExists(Path.GetDirectoryName(colFile.Path));

                using (var stream = File.Open(colFile.Path,
                                              System.IO.FileMode.Create,
                                              FileAccess.ReadWrite))
                    streamWriter(stream);

                if (crc32 != null)
                {
                    var fsCrc32 = FileEx.GetCrc32(colFile.Path);

                    if (fsCrc32 != crc32)
                    {
                        throw new IOException($"CRC32 did not match for file {colFile.Path}. Expected {crc32}, got {fsCrc32}");
                    }
                }

                return(colFile);
            }
            catch (Exception ex)
            {
                LogTo.Error(ex,
                            "CollectionFS: Create threw an exception.");

                try
                {
                    if (dbFile != null)
                    {
                        DbFiles.Delete(dbFile.Id);
                    }
                }
                catch (Exception dbEx)
                {
                    LogTo.Error(dbEx,
                                "CollectionFS: Create threw an exception. Exception's DB cleanup code threw an exception");
                }

                throw;
            }
        }
Exemplo n.º 9
0
 public TileManagerDialogButtonClickedEventArgs(CollectionFile <Tile> tileFile, DialogResult dialogResult) : base(dialogResult)
 {
     this.tileFile = tileFile;
 }
Exemplo n.º 10
0
 public Database(IPlatform platform, string path)
 {
     this.platform = platform;
     session       = new Session(platform, path);
     database      = session[SessionName];
 }