Exemplo n.º 1
0
    public async void CreateStronglyTypedAsset()
    {
        // Remove next line in codesample
        var client = _fileSystemFixture.CreateMockClientWithResponse("FileReferenceResponse.json");

        var stream = new MemoryStream(Encoding.UTF8.GetBytes("Hello world from CM API .NET SDK"));
        var fileName = "Hello.txt";
        var contentType = "text/plain";

        // Returns a reference that you can later use to create an asset
        var fileResult = await client.UploadFileAsync(new FileContentSource(stream, fileName, contentType));

        // Defines the content elements to create
        var stronglyTypedTaxonomyElements = new AssetMetadataModel
        {
            TaxonomyCategories = new TaxonomyElement()
            {
                Value = new[] { "hello", "SDK" }.Select(Reference.ByCodename)
            },
        };

        // Defines the asset to create
        var asset = new AssetCreateModel<AssetMetadataModel>
        {
            FileReference = fileResult,
            Elements = stronglyTypedTaxonomyElements
        };

        // Remove next line in codesample
        client = _fileSystemFixture.CreateMockClientWithResponse("AssetResponse.json");
        // Creates an asset
        var response = await client.CreateAssetAsync(asset);
    }
        public async Task Add(AssetMetadataModel metadata)
        {
            var model = new MongoAssetMetadataModel {
                Metadata = metadata
            };
            await _collection.InsertOneAsync(model);

            _logger.LogTrace($"Metadata added: {model}");
        }