Show / Hide Table of Contents

Class WMAssetBaseDTO<T>

Data Transfer Object base class for all WMAssetBase DTOs. This class was implemented to centralize all of the common traits of asset DTOs, and prevent the increase of duplicated code as we add more assets to the file system.

Inheritance
object
DataTransferObject<T>
WMAssetBaseDTO<T>
WMDataReaderDTO
WMDataSourceBaseDTO
WMAssetDirectoryDTO
WMDocumentDTO
WMDocumentIndexDTO
WMLLMConnectionDTO
WMLLMDTO
WMModelBaseDTO
WMHTTPRequestDTO
WMHTTPConnectionDTO
DecisionModelDTO
Implements
IWMAssetBaseDTO
IWMVersionableAsset
IWMOwnableResource
IWMResource
IDbEntity
IWMEntity
Inherited Members
DataTransferObject<T>.ModelObject
DataTransferObject<T>.SetID(string)
DataTransferObject<T>.CreateModel(WMPrincipal, DbContext, object[])
DataTransferObject<T>.FromModel()
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Quantellia.WMServer.Asset.Base
Assembly: WMServer.dll
Syntax
[PrimaryKey("ID", new string[] { "Version" })]
public abstract class WMAssetBaseDTO<T> : DataTransferObject<T>, IWMAssetBaseDTO, IWMVersionableAsset, IWMOwnableResource, IWMResource, IDbEntity, IWMEntity where T : WMAssetBase, new()
Type Parameters
Name Description
T

Constructors

WMAssetBaseDTO()

Constructor for WMAssetBaseDTO<T>

Declaration
public WMAssetBaseDTO()

WMAssetBaseDTO(string)

Constructor for WMAssetBaseDTO<T> specifying ID

Declaration
public WMAssetBaseDTO(string id)
Parameters
Type Name Description
string id

Properties

CreatedBy

ID of the user that created this entity.

Declaration
public string CreatedBy { get; set; }
Property Value
Type Description
string

CreatedDate

Date and time this entity was last updated.

Declaration
public DateTime CreatedDate { get; set; }
Property Value
Type Description
DateTime

Documentation

Longer, formatted description of this entity.

Declaration
public string? Documentation { get; set; }
Property Value
Type Description
string

DocumentationMIMEType

MIME type of Documentation.

Declaration
public string? DocumentationMIMEType { get; set; }
Property Value
Type Description
string

FullPathName

The unique directory for this WMAssetDirectoryDTO

Declaration
public string FullPathName { get; set; }
Property Value
Type Description
string

ID

The ID of this entity.

Declaration
[Key]
[Column(Order = 0)]
public string ID { get; set; }
Property Value
Type Description
string

IsDeleted

A flag on whether the asset is deleted (recoverable, but not found in searches)

Declaration
public int IsDeleted { get; set; }
Property Value
Type Description
int

LastUpdatedBy

ID of the user that last updated this entity.

Declaration
public string LastUpdatedBy { get; set; }
Property Value
Type Description
string

LastUpdatedDate

Date and time at which this entity was last updated.

Declaration
public DateTime LastUpdatedDate { get; set; }
Property Value
Type Description
DateTime

Name

Name of this entity

Declaration
public string? Name { get; set; }
Property Value
Type Description
string

OwnerID

Owner of this entity

Declaration
public string OwnerID { get; set; }
Property Value
Type Description
string

OwnerType

Type of the owner that owns this entity

Declaration
public string OwnerType { get; set; }
Property Value
Type Description
string

ParentID

ID for the Parent

Declaration
public string ParentID { get; set; }
Property Value
Type Description
string

Properties

Custom properties defined by the user

Declaration
[NotMapped]
public Dictionary<string, string> Properties { get; }
Property Value
Type Description
Dictionary<string, string>

PropertiesSerialized

Custom properties defined by the user. Serializes to and from Properties

Declaration
public string PropertiesSerialized { get; set; }
Property Value
Type Description
string

Status

The status of this version.

Declaration
public IWMVersionableAsset.StatusType Status { get; set; }
Property Value
Type Description
IWMVersionableAsset.StatusType

Summary

Short summary of this entity.

Declaration
public string? Summary { get; set; }
Property Value
Type Description
string

Version

The version number of this asset.

Declaration
[Key]
[Column(Order = 1)]
public int Version { get; set; }
Property Value
Type Description
int

VersionName

The name of this version.

Declaration
public string? VersionName { get; set; }
Property Value
Type Description
string

Methods

CloneDTO<A, B>(WMPrincipal, WMAssetIdentifier, DbSet<A>, VersionCreateArgs?, WMAppDbContext, Func<A, Task>)

Clones the specified WMAssetBaseDTO<T> with an iterated name "AssetName (1), etc... ", iterates the version number. Validates against all WMAssetBase criteria. Calls callBeforeClone after validation, but before creating the clone. This means that all asset specific validation (data readers, etc...) should be called in callBeforeClone, instead of after CloneDTO<A, B>(WMPrincipal, WMAssetIdentifier, DbSet<A>, VersionCreateArgs?, WMAppDbContext, Func<A, Task>). If callBeforeClone throws an exception, no changes will be saved.

Declaration
public static Task<A> CloneDTO<A, B>(WMPrincipal principal, WMAssetIdentifier identifier, DbSet<A> dbSet, VersionCreateArgs? args, WMAppDbContext context, Func<A, Task> callBeforeClone = null) where A : WMAssetBaseDTO<B>, new() where B : WMAssetBase, new()
Parameters
Type Name Description
WMPrincipal principal

The owner of the directory

WMAssetIdentifier identifier

The identifier of the directory

DbSet<A> dbSet

The connection object to the table storing the WMAssetBaseDTO<T> to be updated

VersionCreateArgs args

Arguments for creating a version.

WMAppDbContext context

The DbContext

Func<A, Task> callBeforeClone

An optional function accepting a WMAssetBaseDTO<T> and returning a Task that is called and awaited after the asset is verified to be cloneable, but before the asset is cloned.

Returns
Type Description
Task<A>
Type Parameters
Name Description
A
B
Exceptions
Type Condition
Exception

CommitDTO<A, B>(WMPrincipal, WMAssetIdentifier, DbSet<A>, WMAppDbContext)

Commit the specified WMAssetBaseDTO<T> as Head, sets the previous Head as superseded.

Declaration
public static Task CommitDTO<A, B>(WMPrincipal principal, WMAssetIdentifier identifier, DbSet<A> dbSet, WMAppDbContext context) where A : WMAssetBaseDTO<B>, new() where B : WMAssetBase, new()
Parameters
Type Name Description
WMPrincipal principal

The owner of the directory

WMAssetIdentifier identifier

The identifier of the directory

DbSet<A> dbSet

The connection object to the table storing the WMAssetBaseDTO<T> to be updated

WMAppDbContext context

The DbContext

Returns
Type Description
Task
Type Parameters
Name Description
A
B
Exceptions
Type Condition
Exception

CreateDTO<A, B>(WMPrincipal, A, DbSet<A>, WMAppDbContext, Func<A, Task>)

Creates the specified WMAssetBaseDTO<T>. Validates against all WMAssetBase criteria. Calls callBeforeCreation after validation, but before creating the asset. This means that all asset specific validation (data readers, etc...) should be called in callBeforeCreation, instead of after CreateDTO<A, B>(WMPrincipal, A, DbSet<A>, WMAppDbContext, Func<A, Task>). If callBeforeCreation throws an exception, the asset will not be saved.

Declaration
public static Task CreateDTO<A, B>(WMPrincipal principal, A a_dto, DbSet<A> dbSet, WMAppDbContext context, Func<A, Task> callBeforeCreation = null) where A : WMAssetBaseDTO<B>, new() where B : WMAssetBase, new()
Parameters
Type Name Description
WMPrincipal principal

The owner of the directory

A a_dto

The WMAssetBaseDTO<T> to be created.

DbSet<A> dbSet

The connection object to the table storing the WMAssetBaseDTO<T> to be updated

WMAppDbContext context

The DbContext

Func<A, Task> callBeforeCreation

An optional function accepting a WMAssetBaseDTO<T> and returning a Task that is called and awaited after the asset is verified to be creatable, but before the asset is created.

Returns
Type Description
Task
Type Parameters
Name Description
A
B
Exceptions
Type Condition
Exception

DTOVersions<A, B>(WMPrincipal, WMAssetIdentifier, DbSet<A>, WMAppDbContext)

Returns every available version of the specified WMAssetBaseDTO<T>.

Declaration
public static Task<IEnumerable<VersionArgs>> DTOVersions<A, B>(WMPrincipal principal, WMAssetIdentifier identifier, DbSet<A> dbSet, WMAppDbContext context) where A : WMAssetBaseDTO<B>, new() where B : WMAssetBase, new()
Parameters
Type Name Description
WMPrincipal principal

The owner of the directory

WMAssetIdentifier identifier

The identifier of the directory

DbSet<A> dbSet

The connection object to the table storing the WMAssetBaseDTO<T> to be updated

WMAppDbContext context

The DbContext

Returns
Type Description
Task<IEnumerable<VersionArgs>>
Type Parameters
Name Description
A
B
Exceptions
Type Condition
Exception

DeleteDTO<A, B>(WMPrincipal, WMAssetIdentifier, DbSet<A>, WMAppDbContext, Func<A, Task>)

Deletes the specified WMAssetBaseDTO<T>. Validates against all WMAssetBase criteria. Calls callBeforeDeletion after validation, but before deleting the asset. This means that all asset specific validation (data readers, etc...) should be called in callBeforeDeletion, instead of after DeleteDTO<A, B>(WMPrincipal, WMAssetIdentifier, DbSet<A>, WMAppDbContext, Func<A, Task>). If callBeforeDeletion throws an exception, the asset will not be deleted.

Declaration
public static Task DeleteDTO<A, B>(WMPrincipal principal, WMAssetIdentifier identifier, DbSet<A> dbSet, WMAppDbContext context, Func<A, Task> callBeforeDeletion = null) where A : WMAssetBaseDTO<B>, new() where B : WMAssetBase, new()
Parameters
Type Name Description
WMPrincipal principal

The owner of the directory

WMAssetIdentifier identifier

The identifier of the directory

DbSet<A> dbSet

The connection object to the table storing the WMAssetBaseDTO<T> to be updated

WMAppDbContext context

The DbContext

Func<A, Task> callBeforeDeletion

An optional function accepting a WMAssetBaseDTO<T> and returning a Task that is called and awaited after the asset is verified to be deletable, but before the asset is deleted.

Returns
Type Description
Task
Type Parameters
Name Description
A
B
Exceptions
Type Condition
Exception

GetAuthorizedAssetIQueryable<A>(WMPrincipal, IQueryable<A>, WMAppDbContext)

Builds an IQueryable that makes up all assets the user has authorization to view. This IQueryable should be built before all other querying actions to ensure that no user has access to assets outside of their authorization. This IQueryable is equivalent to the following SQL Query:

Select v1.* from
   (Select * from WMLLM
    Where OwnerType LIKE '%WMOrganization')  v1
join
   (Select* from JoinWMUserWMOrganization
    Where WMUserID = @userID)                v2
    on v1.OwnerID = v2.WMOrganizationID
Union
   (Select * from WMLLM
    Where OwnerType LIKE '%WMUser'
    AND OwnerID = @userID)
...
WHERE
... parent exists
Declaration
public static Task<IQueryable<A>> GetAuthorizedAssetIQueryable<A>(WMPrincipal principal, IQueryable<A> dbSet, WMAppDbContext context) where A : IWMAssetBaseDTO, new()
Parameters
Type Name Description
WMPrincipal principal

The user.

IQueryable<A> dbSet

An IQueryable representing the table of all assets of type A. Must be .AsNoTracking()

WMAppDbContext context
Returns
Type Description
Task<IQueryable<A>>
Type Parameters
Name Description
A

The type of asset DTO to return.

GetDTOFromDirectory<A>(WMPrincipal, WMAssetIdentifier, int, DbSet<A>, WMAppDbContext, Expression<Func<A, A>>?)

Centralizes the process of querying the database into a single function, accounting for ownership, ID, FullPathName, and version. This function builds an EntityFramework IQueryable, which is a deferred execution interface that builds an expression tree and translates into SQL during runtime. Because the query isn't actually executed until the final line when ToListAsync is called, we have greater control on what data we want to be sent from the database, without the insecurity and poor maintainability of calling raw SQL. This method returns an IEnumerable of records which can all be found in the directory matching the identifier as well as in child directories, to the recursion depth specified.

Declaration
public static Task<IEnumerable<A>> GetDTOFromDirectory<A>(WMPrincipal principal, WMAssetIdentifier identifier, int recursionDepth, DbSet<A> dbSet, WMAppDbContext context, Expression<Func<A, A>>? propertySelector = null) where A : class, IWMAssetBaseDTO, new()
Parameters
Type Name Description
WMPrincipal principal

The user retrieving the asset.

WMAssetIdentifier identifier

The identifier of the asset directory. An object that combines the ID, FullPathName, and Version.

int recursionDepth

Depth to which the directory subtrees under the specified directory should be traversed. If 0 is given, only records in the identified directory will be returned. If 1 then a single layer of child directories will also be traversed. If -1 then all child directories will be traversed.

DbSet<A> dbSet

The EntityFramework DbSet representing the connection to the table being queried.

WMAppDbContext context

The WMAppDbContext

Expression<Func<A, A>> propertySelector

An optional expression that allows additional mapping of the database DTO objects to instance DTO objects. (i.e. excluding DocumentData and DocumentEditedText from WMDocumentDTO, which requires excessive time and bandwidth. An example of this can be found in Get(WMPrincipal, WMAssetIdentifier, WMAppDbContext?, Expression<Func<WMDocumentDTO, WMDocumentDTO>>))

Returns
Type Description
Task<IEnumerable<A>>
Type Parameters
Name Description
A

The class of the DTO object being retrieved.

GetDTO<A>(WMPrincipal, WMAssetIdentifier, IQueryable<A>, WMAppDbContext, Expression<Func<A, A>>?)

Centralizes the process of querying the database into a single function, accounting for ownership, ID, FullPathName, and version. This function builds an EntityFramework IQueryable, which is a deferred execution interface that builds an expression tree and translates into SQL during runtime. Because the query isn't actually executed until the final line when SingleOrDefaultAsync is called, we have greater control on what data we want to be sent from the database, without the insecurity and poor maintainability of calling raw SQL. This function returns a single record matching the identifier

Declaration
public static Task<A> GetDTO<A>(WMPrincipal principal, WMAssetIdentifier identifier, IQueryable<A> dbSet, WMAppDbContext context, Expression<Func<A, A>>? propertySelector = null) where A : class, IWMAssetBaseDTO, new()
Parameters
Type Name Description
WMPrincipal principal

The user retrieving the asset.

WMAssetIdentifier identifier

The identifier of the asset. An object that combines the ID, FullPathName, and Version.

IQueryable<A> dbSet

The EntityFramework DbSet representing the connection to the table being queried.

WMAppDbContext context

The WMAppDbContext

Expression<Func<A, A>> propertySelector

An optional expression that allows additional mapping of the database DTO object to the instance DTO object. (i.e. excluding DocumentData and DocumentEditedText from WMDocumentDTO, which requires excessive time and bandwidth. An example of this can be found in Get(WMPrincipal, WMAssetIdentifier, WMAppDbContext?, Expression<Func<WMDocumentDTO, WMDocumentDTO>>))

Returns
Type Description
Task<A>
Type Parameters
Name Description
A

The class of the DTO object being retrieved.

GetEveryAuthorizedAssetIQueryable(WMPrincipal, WMAppDbContext)

Returns an IQueryable<T> containing all authorized asset types.

Declaration
public static Task<IQueryable<IWMAssetBaseDTO>> GetEveryAuthorizedAssetIQueryable(WMPrincipal principal, WMAppDbContext context)
Parameters
Type Name Description
WMPrincipal principal
WMAppDbContext context
Returns
Type Description
Task<IQueryable<IWMAssetBaseDTO>>

GetIdentifier(bool)

Returns this asset DTO's identifier. (i.e. Root/A/B/C/D;Ver# or abcde-12345-.....;ver#)

Declaration
public WMAssetIdentifier GetIdentifier(bool UseFullPathName = false)
Parameters
Type Name Description
bool UseFullPathName

If true, uses the asset's fullPathName, otherwise uses the ID.

Returns
Type Description
WMAssetIdentifier

ResourceDefinition()

This defines the default operations for an asset, with placeholder resource name and description.

Declaration
public static WMResourceOperationsDefinition ResourceDefinition()
Returns
Type Description
WMResourceOperationsDefinition

UpdateDTO<A, B>(WMPrincipal, WMAssetIdentifier, A, DbSet<A>, WMAppDbContext, Func<A, Task>)

Updates the specified WMAssetBaseDTO<T>. Validates against all WMAssetBase criteria. Calls callBeforeUpdate after validation, but before saving changes. This means that all asset specific validation (data readers, etc...) should be called in callBeforeUpdate, instead of after UpdateDTO<A, B>(WMPrincipal, WMAssetIdentifier, A, DbSet<A>, WMAppDbContext, Func<A, Task>). If callBeforeUpdate throws an exception, no changes will be saved.

Declaration
public static Task UpdateDTO<A, B>(WMPrincipal principal, WMAssetIdentifier identifier, A a_dto, DbSet<A> dbSet, WMAppDbContext context, Func<A, Task> callBeforeUpdate = null) where A : WMAssetBaseDTO<B>, new() where B : WMAssetBase, new()
Parameters
Type Name Description
WMPrincipal principal

The owner of the directory

WMAssetIdentifier identifier

The identifier of the directory

A a_dto

The WMAssetBaseDTO<T> to be updated.

DbSet<A> dbSet

The connection object to the table storing the WMAssetBaseDTO<T> to be updated

WMAppDbContext context

The DbContext

Func<A, Task> callBeforeUpdate

An optional function accepting a WMAssetBaseDTO<T> and returning a Task that is called and awaited after the asset is verified to be updatable, but before the asset is updated.

Returns
Type Description
Task
Type Parameters
Name Description
A
B
Exceptions
Type Condition
Exception

UpdateModel(WMPrincipal, DbContext, object[]?)

Updates the contained WMAssetBase with all base properties..

Declaration
public override Task<T> UpdateModel(WMPrincipal principal, DbContext context, object[]? data = null)
Parameters
Type Name Description
WMPrincipal principal
DbContext context
object[] data
Returns
Type Description
Task<T>
Overrides
DataTransferObject<T>.UpdateModel(WMPrincipal, DbContext, object[])

ValidateDirectory<T_Asset>(WMPrincipal, WMAssetBaseDTO<T_Asset>, WMAssetBaseDTO<T_Asset>?, WMAppDbContext)

Validates the uniqueness and name correctness of an asset DTO. Throws an exception otherwise.

Declaration
protected static Task ValidateDirectory<T_Asset>(WMPrincipal principal, WMAssetBaseDTO<T_Asset> a_dto, WMAssetBaseDTO<T_Asset>? a_dto_original, WMAppDbContext context) where T_Asset : WMAssetBase, new()
Parameters
Type Name Description
WMPrincipal principal

The owner of the asset

WMAssetBaseDTO<T_Asset> a_dto

The asset to be validated

WMAssetBaseDTO<T_Asset> a_dto_original

The not updated version of this asset. Null indicates that the asset is new.

WMAppDbContext context

The DbContext

Returns
Type Description
Task
Type Parameters
Name Description
T_Asset

Implements

IWMAssetBaseDTO
IWMVersionableAsset
IWMOwnableResource
IWMResource
IDbEntity
IWMEntity
In this article
Back to top Copyright © 2025 Quantellia LLC.    Version 2.0.0 Revision 399     Last Updated 1/15/2025    DRAFT DOCUMENTATION. SUBJECT TO CHANGE