LicenseTemplateRepository

Namespace: Babel.Data Assembly: Babel.Data.dll

A license template repository.

public class LicenseTemplateRepository : GenericRepository<LicenseTemplate>, ILicenseTemplateRepository, IGenericRepository<LicenseTemplate>

Inheritance

objectGenericRepository<LicenseTemplate>LicenseTemplateRepository

Implements

ILicenseTemplateRepository, IGenericRepository<LicenseTemplate>

Inherited Members

GenericRepository<LicenseTemplate>.Get(Expression<Func<LicenseTemplate, bool>>, Func<IQueryable<LicenseTemplate>, IOrderedQueryable<LicenseTemplate>>, string, string, int?, int?), GenericRepository<LicenseTemplate>.GetAsync(Expression<Func<LicenseTemplate, bool>>, Func<IQueryable<LicenseTemplate>, IOrderedQueryable<LicenseTemplate>>, string, string, int?, int?, CancellationToken), GenericRepository<LicenseTemplate>.QueryAsync(string, string, string, string, int?, int?, CancellationToken), GenericRepository<LicenseTemplate>.GetById(params object[]), GenericRepository<LicenseTemplate>.GetByIdAsync(params object[]), GenericRepository<LicenseTemplate>.GetByIdAsync(object[], CancellationToken), GenericRepository<LicenseTemplate>.CountAsync(Expression<Func<LicenseTemplate, bool>>, CancellationToken), GenericRepository<LicenseTemplate>.CountAsync(string, CancellationToken), GenericRepository<LicenseTemplate>.Insert(LicenseTemplate), GenericRepository<LicenseTemplate>.InsertAsync(LicenseTemplate, CancellationToken), GenericRepository<LicenseTemplate>.Update(LicenseTemplate), GenericRepository<LicenseTemplate>.Delete(params object[]), GenericRepository<LicenseTemplate>.Delete(LicenseTemplate), GenericRepository<LicenseTemplate>.Save(), GenericRepository<LicenseTemplate>.SaveAsync(CancellationToken), GenericRepository<LicenseTemplate>.DbSet, GenericRepository<LicenseTemplate>.Context, object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Constructors

LicenseTemplateRepository(BabelDbContext)

Initializes a new instance of the LicenseTemplateRepository class.

public LicenseTemplateRepository(BabelDbContext context)

Parameters

NameDescription

The context.

Methods

Delete(IEnumerable<int>)

Deletes a list of templates with the given primary key values. Begins tracking the given entities in the Detached state such that they will be deleted in the database when SaveChanges() is called.

public void Delete(IEnumerable<int> templateIds)

Parameters

NameDescription

templateIds IEnumerable<int>

The template primary key ids to delete.

GetTemplateSignatureKeysAsync(int)

Asynchronously gets the signature keys for a given template.

public Task<Resource> GetTemplateSignatureKeysAsync(int templateId)

Parameters

NameDescription

templateId int

The template primary key.

Returns

NameDescription

An asynchronous result that yields the template signature keys.

Insert(LicenseTemplate)

Inserts the given template entity in the repository. Begins tracking the given entity, and any other reachable entities that are not already being tracked, in the Added state such that they will be inserted into the database when SaveChanges() is called.

public override void Insert(LicenseTemplate template)

Parameters

NameDescription

The template entity.

Examples

using Babel.Data;
using Babel.Licensing;

// Configure database connection
// See UnitOfWork.Configure for more details
UnitOfWork.Configure(uwc => {
    string connection = "server=localhost;database=licenses;user=babel;password=<database password>;"
    options.UseMySql(connection, ServerVersion.AutoDetect(connection), 
        x => x.MigrationsAssembly("Babel.Data.MySQL"));
});

// Create a license template assuming Program is
var rsa = RSASignature.CreateFromKeyFile("Keys.snk");
var template = new XmlLicense();

string templateKey = template.WithUniqueId()
        .ForAssembly("ACME, version=1.0.0.0, culture=neutral, publickeytoken=null")
        .SignWith(rsa)
        .ToReadableString();

// Store license template in database
using UnitOfWork db = new UnitOfWork();

var licenseTemplate = new Babel.Data.LicenseTemplate {
    Name = "ACME License Template",
    Format = "XML",
    Template = templateKey
};

await db.LicenseTemplateRepository.InsertAsync(licenseTemplate);
await db.SaveAsync();

InsertAsync(LicenseTemplate, CancellationToken)

Asynchronously inserts the given template entity in the repository. Begins tracking the given entity, and any other reachable entities that are not already being tracked, in the Added state such that they will be inserted into the database when SaveChanges() is called.

public override Task<EntityEntry<LicenseTemplate>> InsertAsync(LicenseTemplate template, CancellationToken cancellationToken = default)

Parameters

NameDescription

The template entity.

cancellationToken CancellationToken

(Optional) A token that allows processing to be cancelled.

Returns

NameDescription

An asynchronous result that yields the insert.

QueryAsync(int, int?, string, string, string, string, int?, int?, CancellationToken)

Asynchronously queries a list of LicenseTemplate objects for a given license from this repository.

public Task<List<LicenseTemplate>> QueryAsync(int productId, int? releaseId = null, string select = null, string filter = null, string orderBy = null, string includeProperties = "", int? skip = null, int? take = null, CancellationToken cancellationToken = default)

Parameters

NameDescription

productId int

The ID of the product to retrieve templates for.

releaseId int?

(Optional) The ID of the release to retrieve templates for.

select string

(Optional) Specifies a select expression.

filter string

(Optional) Specifies the filter expression.

orderBy string

(Optional) Order by expression.

includeProperties string

(Optional) A comma separated list of nested entity names to retrieve.

skip int?

(Optional) The number of records to skip before the first record found.

take int?

(Optional) The number of records to take after the first record found.

cancellationToken CancellationToken

(Optional) A token that allows processing to be cancelled.

Returns

NameDescription

A task that represents the asynchronous get operation, containing a list of LicenseTemplate objects.

Update(LicenseTemplate)

Updates the given license template in the repository. Begins tracking the given entity in the Modified state such that it will be updated in the database when SaveChanges() is called.

public override void Update(LicenseTemplate template)

Parameters

NameDescription

The template to update.

Last updated