Ejemplo n.º 1
0
        public Asset CreateAsset(object assetValue, string path)
        {
            path = Paths.GetProjectRelativePath(path);
            var asset = GetAsset(path);

            if (asset != null)
            {
                asset.Importer.Value = assetValue;
                asset.Importer.SaveAsset();
                asset.Update();
                AssetUpdated?.Invoke(path);
            }
            else
            {
                asset = new Asset(path);
                asset.Importer.Value = assetValue;
                asset.Importer.SaveAsset();
                asset.Update();
                AddAssetInternal(asset);
            }

            AssetGuidManager.AddNewGuid(asset.Guid, asset.Path, asset.Hash);
            if (!IsEditingAssets)
            {
                AssetGuidManager.Save();
            }

            return(asset);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Deletes a computer from the database.
        /// </summary>
        /// <param name="asset">The computer to be deleted.</param>
        public override void DeleteAsset(Computer asset)
        {
            Db.Remove(asset);
            Db.SaveChanges();

            AssetUpdated?.Invoke();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a new computer to the database.
        /// </summary>
        /// <param name="assets">The computer to be added</param>
        public override void AddAssets(IEnumerable <Computer> assets)
        {
            Db.AddRange(assets);
            Db.SaveChanges();

            AssetUpdated?.Invoke();
        }
Ejemplo n.º 4
0
 protected Task On(AssetUpdated @event, EnvelopeHeaders headers)
 {
     return(Collection.UpdateAsync(@event, headers, a =>
     {
         SimpleMapper.Map(@event, a);
     }));
 }
Ejemplo n.º 5
0
        public async Task Should_backup_updated_asset()
        {
            var @event = new AssetUpdated {
                AssetId = Guid.NewGuid(), FileVersion = 3
            };

            await TestBackupEventAsync(@event, @event.FileVersion);
        }
Ejemplo n.º 6
0
        public async Task Should_restore_updated_asset()
        {
            var @event = new AssetUpdated {
                AssetId = Guid.NewGuid(), FileVersion = 3
            };

            await TestRestoreAsync(@event, @event.FileVersion);
        }
Ejemplo n.º 7
0
        public async Task Should_backup_updated_asset_with_missing_file()
        {
            var @event = new AssetUpdated {
                AssetId = DomainId.NewGuid(), FileVersion = 3
            };

            await TestBackupFailedAsync(@event, @event.FileVersion);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// This should be called whenever asset value was modified on disk. Updates hashes and asset value while keeping the reference
        /// </summary>
        private void UpdateAssetInternal(Asset oldAsset)
        {
            oldAsset.UpdateValueFromDisk();

            GuidHashTable[oldAsset.Guid] = oldAsset.Hash;
            AssetGuidManager.AddNewGuid(oldAsset.Guid, oldAsset.Path, oldAsset.Hash);

            AssetUpdated?.Invoke(oldAsset.Path);
        }
Ejemplo n.º 9
0
        public override void AddAsset(Computer asset)
        {
            if (asset.AssetRecords.Count == 0)
            {
                asset.ComputerRecords.Add(InitialRecord(asset));
            }

            Db.Add(asset);
            Db.SaveChanges();

            AssetUpdated?.Invoke();
        }
Ejemplo n.º 10
0
        public void SaveExistngAsset(Asset existingAsset, object newValue)
        {
            existingAsset.Importer.Value = newValue;
            existingAsset.Importer.SaveAsset();
            existingAsset.Update();
            AssetUpdated?.Invoke(existingAsset.Path);

            AssetGuidManager.AddNewGuid(existingAsset.Guid, existingAsset.Path, existingAsset.Hash);
            if (!IsEditingAssets)
            {
                AssetGuidManager.Save();
            }
        }
Ejemplo n.º 11
0
        public async Task Should_not_repair_updated_asset_if_found()
        {
            var @event = new AssetUpdated {
                AppId = appId, AssetId = DomainId.NewGuid(), FileVersion = 3
            };

            SetupEvent(@event);

            A.CallTo(() => assetFileStore.GetFileSizeAsync(appId.Id, @event.AssetId, 3, default))
            .Returns(100);

            await sut.RepairAsync();

            A.CallTo(() => assetFileStore.UploadAsync(appId.Id, @event.AssetId, 3, A <Stream> ._, default))
            .MustNotHaveHappened();
        }
Ejemplo n.º 12
0
        public async Task Should_repair_updated_asset_if_not_found()
        {
            var @event = new AssetUpdated {
                AppId = appId, AssetId = DomainId.NewGuid(), FileVersion = 3
            };

            SetupEvent(@event);

            A.CallTo(() => assetFileStore.GetFileSizeAsync(appId.Id, @event.AssetId, 3, null, default))
            .Throws(new AssetNotFoundException("file"));

            await sut.RepairAsync();

            A.CallTo(() => assetFileStore.UploadAsync(appId.Id, @event.AssetId, 3, null, A <Stream> ._, true, default))
            .MustHaveHappened();
        }
 protected Task On(AssetUpdated @event, EnvelopeHeaders headers)
 {
     return(UpdateSizeAsync(@event.AppId.Id, headers.Timestamp().ToDateTimeUtc().Date, @event.FileSize, 0));
 }
Ejemplo n.º 14
0
        protected void On(AssetUpdated @event)
        {
            fileVersion = @event.FileVersion;

            totalSize += @event.FileSize;
        }
Ejemplo n.º 15
0
        protected void On(AssetUpdated @event)
        {
            SimpleMapper.Map(@event, this);

            TotalSize += @event.FileSize;
        }
Ejemplo n.º 16
0
        /// <summary>
        /// This method is invoked by a property change in a computer,
        /// which saves the changes to the database and invokes the AssetUpdated event.
        /// </summary>
        protected override void OnAssetUpdated()
        {
            Db.SaveChanges();

            AssetUpdated?.Invoke();
        }