private object BindTemplateInstance(Type type, IConfiguration config) { lock (Sync) { var template = Instancing.CreateInstance(type); if (!_empties.TryGetValue(type, out _)) { _empties.Add(type, ValueHash.ComputeHash(template)); } config.FastBind(template, _customBinders); return(ValueHash.ComputeHash(template) == _empties[type] ? null : template); } }
public async Task <ApplicationVersion> DeriveApplicationVersion(string applicationId) { var current = await _schemas.GetByApplicationId(applicationId); // make a dictionary to order the hash lookup var manifest = current.OrderBy(x => x.Name).ToDictionary(k => k.Name, v => v.Fingerprint); // create a new application version that can be associated with an API version var hashes = current.Select(x => x.Fingerprint).ToList(); var version = new ApplicationVersion { ApplicationId = applicationId, Fingerprint = ValueHash.ComputeHash(new { Fingerprints = hashes }), Manifest = manifest }; return(version); }
public async Task <ulong> TrySaveRevisionAsync(string applicationId, IReadOnlyList <S> revisionSet) { var revisions = 0; foreach (var schema in revisionSet.OrderByTopology(GetSchemaDependents)) { var hash = ValueHash.ComputeHash(schema); var notModified = await _schemas.GetByFingerprintAsync(hash); if (notModified != null) { continue; } var lastRevision = await _schemas.GetLastRevisionAsync(schema.Type, schema.Namespace, schema.Name); var revision = lastRevision?.Revision + 1 ?? 1; var schemaVersion = new SchemaVersion { Fingerprint = hash, ApplicationId = applicationId, Type = schema.Type, Namespace = schema.Namespace, Name = schema.Name, Revision = revision, Data = schema }; await _schemas.CreateAsync(schemaVersion); revisions++; } var version = await DeriveApplicationVersion(applicationId); if (revisions > 0) { await _applications.CreateAsync(version); } return(revisions == 0 ? 0 : version.Fingerprint); }
private static VersionContext MatchedContext(SchemaVersion version) { var context = new VersionContext { Group = new VersionGroup($"{version.Revision}"), Map = new Dictionary <string, Version>() }; context.Map.Add(version.Data.Name, new Version { Major = version.Fingerprint, Minor = 0 }); foreach (var entry in version.Data.GetMap()) { context.Map.Add(entry.Value.Name, new Version { Major = ValueHash.ComputeHash(entry.Value), Minor = 0 }); } context.Identifiers = new string[0]; return(context); }