SourceSettings Class
Assembly: CodeEffects.Rule.Repository.dll
Namespace: CodeEffects.Rule.Repository
Summary
Tells Context.SyncSources(..) which source definitions to check and how to handle the ones that are new or have changed.
Syntax
public class SourceSettings
Create an instance, list your source objects in SourceXmls, SourceTypes, SourceProviders, or a mix of them, and pass it to Context.SyncSources(..). Each source object is converted to a Source XML document, identified by the alias of its main source object, compared with the versions the repository already stores, and written as a new source, a new version, a label update, or not at all. See SourceOutcome.
Every list is optional and every property has a default, so new SourceSettings { SourceTypes = { typeof(Order) } } is a complete set of settings. Passing every source on every call is safe: a definition that matches what is stored costs a read and a comparison and writes nothing.
Do not pass more than one definition of the same source object in a single call, for example the same class both as a type and as a document.
Constructors
SourceSettings()
Initializes a new instance of the SourceSettings class with the default values of all properties.
Example
using System;
using System.Collections.Generic;
using System.Linq;
using CodeEffects.Rule.Connection;
using CodeEffects.Rule.Repository;
using CodeEffects.Rule.Repository.Common;
var settings = new SourceSettings
{
SourceTypes = new List<Type> { typeof(Order), typeof(Patient) },
NewVersionsGoLive = true,
TestsHandling = TestsHandlingType.CopyTestsFromProductionVersion
};
try
{
SyncResult result = Context.SyncSources(dbProvider, settings);
foreach(SourceResult source in result.Sources)
Console.WriteLine(source.AliasName + ": " + source.Outcome);
}
catch(RepositoryException ex) when(ex.SyncResult != null)
{
foreach(SourceResult failed in ex.SyncResult.Sources.Where(s => s.Outcome == SourceOutcome.Failed))
Console.WriteLine(failed.AliasName + " " + failed.ControlNumber + " " + failed.Message);
}
Properties
ComparisonType
Type: CodeEffects.Rule.Repository.Common.SourceVersionComparisonType
Gets or sets which stored versions an incoming definition is compared with. The default is CompareToLastVersion.
NewVersionsGoLive
Type: System.Boolean
Gets or sets whether a new version that this sync creates for a source object that is already stored becomes the live version straight away. The default is false: the new version is stored, and the version that was live stays live until a person makes the new one live in the Rule Repository.
The live version of a source object is the one the repository treats as current: new rules and tests are built on it, CompareToProductionVersion compares with it, and the "from production version" choices of TestsHandling take tests from it. It does not change what your application executes; your application runs whatever its own code and data are.
Set it to true when the application that syncs is the application that evaluates: the types it syncs are the types its rules run against, so the newest definition is what runs the moment it is deployed, and the repository should say so.
Leave it false when rules run somewhere else, such as another service, another environment, or a later deployment, that may still be fed data shaped like the previous version. There, making the new version live is a decision someone makes in the Rule Repository when that other place is ready.
The first version of a new source object is always live, whatever this property says. A version that a sync makes live is recorded in the activity log as the work of the user that UserId names, or of the system when it is empty.
SourceProviders
Type: System.Collections.Generic.IList<CodeEffects.Rule.Editor.Models.ISourceProvider>
Gets or sets the Adaptive Sources to check, one per source object, alongside SourceXmls and SourceTypes. The repository converts each provider to a Source XML document, enumerations with their members, and handles it like a document: it is identified by the provider's SourceObjectTypeOrAliasName. The default is an empty list.
Only ISourceProvider is accepted.
SourceTypes
Type: System.Collections.Generic.IList<System.Type>
Gets or sets the source object types to check, one per source object, alongside SourceXmls. The repository converts each type to a Source XML document exactly as the rule editor converts a type, using TypeResolver, and handles it like a document: it is identified by its alias, compared, and versioned. The default is an empty list.
SourceXmls
Type: System.Collections.Generic.IList<System.String>
Gets or sets the Source XML documents to check, one per source object. Each is identified by the alias of its main source object. Use Context.GetAliasNames(..) to supply only the ones that you know are new or updated. The default is an empty list.
TestsHandling
Type: CodeEffects.Rule.Repository.Common.TestsHandlingType
Gets or sets what happens to existing tests when a new source version is created. The default is CopyTestsFromProductionVersion.
TypeResolver
Type: CodeEffects.Rule.Common.Models.GetTypeDelegate
Gets or sets the type resolver used to load the enumerations and data source classes that the definitions reference. Set it when those types are named by alias or live in assemblies your application does not load by name: a definition whose types cannot be loaded fails when no resolver is supplied. The default is null.
UserId
Type: System.String
Gets or sets the ID of the user who asked for this sync. Optional, and normally left out: a sync that runs at startup or on a schedule was asked for by nobody, and the sources it writes are shown as the work of the system. The default is null.
Set it when a person triggered the sync, for example an administration screen with a button on it, and the sources that this call writes are shown as theirs. The same rules apply as to CurrentUserId of IRepositoryConfiguration: the ID is whatever your application calls its users, your application is responsible for it being right, and a user that the repository has not seen is stored on first use.
UserName
Type: System.String
Gets or sets the display name of the user who asked for this sync. Optional, and ignored when UserId is empty. When it is supplied, it is stored the first time that user is seen and refreshed whenever it has changed; when it is left out, whatever is already stored is kept. The default is null.
UserType
Type: CodeEffects.Rule.Repository.Common.UserType
Gets or sets what UserId is: a person, an AI agent, or a service such as a deployment pipeline that runs the sync. Ignored when UserId is empty. The default is UserType.User. See CurrentUserType of IRepositoryConfiguration.