public static async Task <Dictionary <long, long> > FetchFileDuplicateToFileByMasterFile( List <long> masterFileIds) { Dictionary <long, long> masterFileToMapperIds = new Dictionary <long, long>(); var query = Query.CreateQuery(entities => from e in entities where e.DefinitionName == "M.File" && e.Id.In(masterFileIds) select e); var entityLoadConfig = new EntityLoadConfiguration { PropertyLoadOption = PropertyLoadOption.None, CultureLoadOption = CultureLoadOption.Default, RelationLoadOption = new RelationLoadOption("FileDuplicateToFile") }; var queryResult = await MConnector.Client().Querying.QueryAsync(query, entityLoadConfig); var entities = queryResult.Items; foreach (var entity in entities) { var relation = entity?.GetRelation("FileDuplicateToFile")?.GetIds(); if (relation != null && relation.Count > 0) { masterFileToMapperIds.Add(entity.Id.Value, relation.First()); } } return(masterFileToMapperIds); }
private static async Task CreateFetchJob(long?assetId, Uri resource) { var fetchJobRequest = new WebFetchJobRequest("File", assetId.Value); fetchJobRequest.Urls.Add(resource); await MConnector.Client().Jobs.CreateFetchJobAsync(fetchJobRequest).ConfigureAwait(false); }
public static async Task <IEntity> GetEntityById(long entityId) { var query = Query.CreateQuery(entities => from e in entities where e.Id == entityId select e); return(await MConnector.Client().Querying.SingleAsync(query, EntityLoadConfiguration.Full)); }
public static long?GetEntityIdByIdentifier(string identifier) { var query = Query.CreateQuery(entities => from e in entities where e.Identifier == identifier select e); return(MConnector.Client().Querying.SingleIdAsync(query).Result); }
public static async Task <IEntityQueryResult> GetAssetsByAssetType(long assetTypeId) { var query = Query.CreateQuery(entities => from e in entities where e.DefinitionName == "M.Asset" && e.Parent("AssetTypeToAsset") == assetTypeId select e); return(await MConnector.Client().Querying.QueryAsync(query, EntityLoadConfiguration.Default)); }
public static async Task <IEntityQueryResult> GetEntitiesByTitle(string title) { var query = Query.CreateQuery(entities => from e in entities where e.DefinitionName == "M.Asset" && e.Property("Title") == title select e); return(await MConnector.Client().Querying.QueryAsync(query, EntityLoadConfiguration.Default)); }
internal static async Task <List <Asset> > GetDuplicateAssetsAsync() { Dictionary <long, long> masterFileToMapperIds = new Dictionary <long, long>(); EntityLoadConfiguration loadConfiguration = new EntityLoadConfiguration() { CultureLoadOption = CultureLoadOption.Default, PropertyLoadOption = new PropertyLoadOption("FileName"), RelationLoadOption = new RelationLoadOption("MasterFile") }; List <Asset> duplicateAssets = new List <Asset>(); List <IEntity> entities = new List <IEntity>(); var query = Query.CreateQuery(entities => from e in entities where e.DefinitionName == "M.Asset" && e.Parent("ContentRepositoryToAsset") == 734 && //Standard (DAM) e.Parent("FinalLifeCycleStatusToAsset") == 544 && // Approved e.Property("HasDuplicate") == true select e); var queryResult = await MConnector.Client().Querying.QueryAsync(query, loadConfiguration); foreach (var entity in queryResult.Items) { var entityId = entity.Id; var fileName = entity.GetPropertyValue <string>("Filename"); var masterFile = entity.GetRelation("MasterFile")?.GetIds(); duplicateAssets.Add( new Asset() { EntityId = entityId.Value, FileName = fileName, MasterFile = masterFile.First() }); } entities.AddRange(queryResult.Items); List <long> masterFileIds = duplicateAssets.Select(f => f.MasterFile).ToList(); masterFileToMapperIds = Task.Run(async() => await FetchFileDuplicateToFileByMasterFile(masterFileIds)).Result; if (masterFileToMapperIds != null) { foreach (var asset in duplicateAssets) { if (masterFileToMapperIds.TryGetValue(asset.MasterFile, out long mapperId)) { asset.DuplicateFileMapperId = mapperId.ToString(); } } } return(duplicateAssets); }
public static async void ArchiveAssetById(long entityId) { try { await MConnector.Client().Assets.FinalLifeCycleManager.ArchiveAsync(entityId); } catch (Exception ex) { throw ex; } }
public static async void DeleteEntityById(long entityId) { try { await MConnector.Client().Entities.DeleteAsync(entityId); } catch (Exception ex) { throw ex; } }
public static async Task <IEntityQueryResult> GetEntitiesByDefinition(string definitionName) { var query = Query.CreateQuery(entities => from e in entities where e.DefinitionName == definitionName && e.Parent("ContentRepositoryToAsset") == 734 select e); query.Take = 150; return(await MConnector.Client().Querying.QueryAsync(query, EntityLoadConfiguration.Default)); }
internal static async Task TrashAssetAsync(IEntity assetEntity) { if (assetEntity != null) { var finalLifeCycleDeleted = ReadEntity.GetEntityIdByIdentifier("M.Final.LifeCycle.Status.Deleted"); var finalLifeCycleRelation = assetEntity. GetRelation <IChildToOneParentRelation>("FinalLifeCycleStatusToAsset"); finalLifeCycleRelation.Parent = finalLifeCycleDeleted.Value; await MConnector.Client().Entities.SaveAsync(assetEntity).ConfigureAwait(false); } }
public static async Task <long> CreateAssetEntity() { // Create the entity resource IEntity asset = await MConnector.Client().EntityFactory .CreateAsync(Constants.Asset.DefinitionName, CultureLoadOption.Default).ConfigureAwait(false); asset.Identifier = "unique_identifier_2"; asset.SetPropertyValue("Title", "Sample Asset from SDK"); //var standardContentRepository = await MConnector.Client().Entities.GetAsync("M.Content.Repository.Standard").ConfigureAwait(false); //var contentRepositoryRelation = asset.GetRelation<IChildToManyParentsRelation>("ContentRepositoryToAsset"); //contentRepositoryRelation.Parents.Add(standardContentRepository.Id.Value); var standardContentRepository = ReadEntity.GetEntityIdByIdentifier("M.Content.Repository.Standard"); var contentRepositoryRelation = asset.GetRelation <IChildToManyParentsRelation>("ContentRepositoryToAsset"); contentRepositoryRelation.Parents.Add(standardContentRepository.Value); //var finalLifeCycleCreated = await MConnector.Client().Entities.GetAsync("M.Final.LifeCycle.Status.Approved").ConfigureAwait(false); //var finalLifeCycleRelation = asset.GetRelation<IChildToOneParentRelation>("FinalLifeCycleStatusToAsset"); //finalLifeCycleRelation.Parent = finalLifeCycleCreated.Id.Value; var finalLifeCycleCreated = ReadEntity.GetEntityIdByIdentifier("M.Final.LifeCycle.Status.Approved"); var finalLifeCycleRelation = asset.GetRelation <IChildToOneParentRelation>("FinalLifeCycleStatusToAsset"); finalLifeCycleRelation.Parent = finalLifeCycleCreated.Value; //var assetType = await MConnector.Client().Entities // .GetAsync("M.AssetType.BrandingAsset").ConfigureAwait(false); //var assetTypeRelation = asset.GetRelation<IChildToOneParentRelation>("AssetTypeToAsset"); //assetTypeRelation.Parent = assetType.Id.Value; var assetType = ReadEntity.GetEntityIdByIdentifier("M.AssetType.BrandingAsset"); var assetTypeRelation = asset.GetRelation <IChildToOneParentRelation>("AssetTypeToAsset"); assetTypeRelation.Parent = assetType.Value; // Create the asset var assetId = await MConnector.Client().Entities.SaveAsync(asset).ConfigureAwait(false); //Create a fetch job to associate a file Uri file = new Uri("https://images.unsplash.com/photo-1504674900247-0877df9cc836?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1050&q=80"); if (file != null) { await CreateFetchJob(assetId, file); } return(assetId); }
public static async Task <List <IEntity> > GetEntitiesByDefinitionByIterator(string definitionName) { List <IEntity> entities = new List <IEntity>(); var query = Query.CreateQuery(entities => from e in entities where e.DefinitionName == definitionName && e.Parent("ContentRepositoryToAsset") == 734 //Standard (DAM) select e); var iterator = MConnector.Client().Querying.CreateEntityIterator(query, EntityLoadConfiguration.Default); while (await iterator.MoveNextAsync().ConfigureAwait(false)) { entities.AddRange(iterator.Current.Items); } return(entities); }
internal static async Task UpdateAssetAsync(IEntity assetEntity) { if (assetEntity != null) { //property update example assetEntity.SetPropertyValue("Title", "Update from the SDK"); //relation update example var assetType = await MConnector.Client().Entities .GetAsync("M.AssetType.BrandingAsset").ConfigureAwait(false); var assetTypeRelation = assetEntity.GetRelation <IChildToOneParentRelation>("AssetTypeToAsset"); assetTypeRelation.Parent = assetType.Id.Value; await MConnector.Client().Entities.SaveAsync(assetEntity).ConfigureAwait(false); } }
public static async Task <List <IEntity> > GetEntitiesByDefinitionByScroller(string definitionName) { List <IEntity> entities = new List <IEntity>(); var query = Query.CreateQuery(entities => from e in entities where e.DefinitionName == definitionName && e.Parent("ContentRepositoryToAsset") == 734 select e); var scroller = MConnector.Client().Querying.CreateEntityScroller(query, TimeSpan.FromSeconds(30), EntityLoadConfiguration.DefaultCultureFull); scroller.Reset(); while (await scroller.MoveNextAsync().ConfigureAwait(false)) { entities.AddRange(scroller.Current.Items); } return(entities); }