/// <summary> /// Load using an explicit configuration. /// </summary> /// <typeparam name="TModel"></typeparam> /// <param name="config"></param> /// <returns></returns> public static Engine <TModel> Load <TModel>(EngineConfiguration config = null) where TModel : Model { config = config ?? EngineConfiguration.Create(); if (!config.Location.HasJournal) { config.Location.SetLocationFromType <TModel>(); } var model = (TModel) new ModelLoader(config).LoadModel(); return(new Engine <TModel>(model, config)); }
/// <summary> /// Load an engine from a location specified by the provided EngineConfiguration /// </summary> /// <param name="config"></param> /// <returns>A non generic Engine</returns> public static Engine Load(EngineConfiguration config) { if (config.JournalPath == null) { throw new InvalidOperationException("Specify location to load from in non-generic load"); } var model = new ModelLoader(config).LoadModel(); return(new Engine(model, config)); }
/// <summary> /// Create from an existing model by writing a snapshot /// </summary> /// <typeparam name="TModel"></typeparam> /// <param name="model"></param> /// <param name="config"></param> /// <returns></returns> public static Engine <TModel> Create <TModel>(TModel model, EngineConfiguration config = null) where TModel : Model { config = config ?? EngineConfiguration.Create(); if (!config.Location.HasJournal) { config.Location.SetLocationFromType <TModel>(); } ISnapshotStore store = config.CreateSnapshotStore(); store.WriteSnapshot(model); return(Load <TModel>(config)); }
/// <summary> /// Create by writing a ModelCreated entry to the journal /// </summary> /// <typeparam name="TModel"></typeparam> /// <param name="config"></param> /// <returns></returns> public static Engine <TModel> Create <TModel>(EngineConfiguration config = null) where TModel : Model, new() { config = config ?? new EngineConfiguration(); config.ModelType = typeof(TModel); var commandStore = config.CreateCommandStore(); if (!commandStore.IsEmpty) { throw new InvalidOperationException("Cannot Create(): empty CommandStore required"); } if (!config.CreateSnapshotStore().IsEmpty) { throw new InvalidOperationException("Can't Create(): empty SnapshotStore required"); } var appender = JournalAppender.Create(0, commandStore); appender.AppendModelCreated <TModel>(); appender.Dispose(); return(Load <TModel>(config)); }
/// <summary> /// Create by writing a ModelCreated entry to the journal /// </summary> /// <typeparam name="TModel"></typeparam> /// <param name="config"></param> /// <returns></returns> public static Engine <TModel> Create <TModel>(EngineConfiguration config = null) where TModel : Model, new() { config = config ?? EngineConfiguration.Create(); if (!config.Location.HasJournal) { config.Location.SetLocationFromType <TModel>(); } var commandStore = config.CreateCommandStore(); if (!commandStore.IsEmpty) { throw new InvalidOperationException("Cannot Create(): empty CommandStore required"); } if (!config.CreateSnapshotStore().IsEmpty) { throw new InvalidOperationException("Can't Create(): empty SnapshotStore required"); } JournalAppender.Create(0, commandStore).AppendModelCreated <TModel>(); return(Load <TModel>(config)); }
/// <summary> /// Load or create the specified type from the /// location according to EngineConfiguration.Location /// </summary> /// <typeparam name="TModel">The type of the model</typeparam> /// <param name="config">The configuration to use</param> /// <returns>A running engine</returns> public static Engine <TModel> LoadOrCreate <TModel>(EngineConfiguration config = null) where TModel : Model, new() { config = config ?? new EngineConfiguration(); config.ModelType = typeof(TModel); Engine <TModel> result = null; var commandStore = config.CreateCommandStore(); var snapshotStore = config.CreateSnapshotStore(); if (commandStore.IsEmpty && snapshotStore.IsEmpty) { result = Create <TModel>(config); Logger.Debug("Engine Created"); } else { result = Load <TModel>(config); Logger.Debug("Engine Loaded"); } return(result); }
static ClientConfiguration CreateConfigFromConnectionString(string connectionstring) { var configDictionary = ConfigDictionary.FromDelimitedString(connectionstring); var mode = configDictionary.Get("mode", () => Mode.Embedded); Func <string, bool> keyFilter = key => key.ToLowerInvariant() != "mode"; if (mode == Mode.Embedded) { var config = new EngineConfiguration(); configDictionary.MapTo(config, keyFilter: keyFilter); return(new LocalClientConfiguration(config)); } else //Mode.Remote { var config = new RemoteClientConfiguration(); configDictionary.MapTo(config, keyFilter: keyFilter); return(new FailoverClusterClientConfiguration(config)); } }
/// <summary> /// Load or create the specified type from the /// location according to EngineConfiguration.Location /// </summary> /// <typeparam name="TModel">The type of the model</typeparam> /// <param name="config">The configuration to use</param> /// <returns>A running engine</returns> public static Engine <TModel> LoadOrCreate <TModel>(EngineConfiguration config = null) where TModel : Model, new() { config = config ?? EngineConfiguration.Create(); if (!config.Location.HasJournal) { config.Location.SetLocationFromType <TModel>(); } Engine <TModel> result = null; var store = config.CreateCommandStore(); if (store.IsEmpty) { result = Create(new TModel(), config); _log.Debug("Engine Created"); } else { result = Load <TModel>(config); _log.Debug("Engine Loaded"); } return(result); }
public static ClientConfiguration Create(string clientIdentifier = null) { if (string.IsNullOrEmpty(clientIdentifier)) { return(new LocalClientConfiguration(EngineConfiguration.Create())); } var isConnectionString = clientIdentifier.Contains("="); if (isConnectionString) { return(CreateConfigFromConnectionString(clientIdentifier)); } if (ConfigurationManager.AppSettings[clientIdentifier] != null) { return(Create(ConfigurationManager.AppSettings[clientIdentifier])); } var config = EngineConfiguration.Create(); config.Location.OfJournal = clientIdentifier; return(new LocalClientConfiguration(config)); }
public static Engine Create(Model model, string location) { var config = new EngineConfiguration(location); return(Create(model, config)); }
/// <summary> /// Get a proxy for a given type T based on same conventions as Engine.For<T> /// </summary> public static T For <T>(EngineConfiguration config) where T : Model, new() { var instance = Engine.For <T>(config); return((T) new Proxy <T>(instance).GetTransparentProxy()); }
public static ClientConfiguration Create(EngineConfiguration config) { return(new LocalClientConfiguration(config)); }
public Engine(TModel model, EngineConfiguration config) : base(model, config) { }
public OptimisticKernel(EngineConfiguration config, Model model) : base(config, model) { }
/// <summary> /// Load if exists, otherwise Create and Load. /// </summary> /// <typeparam name="TModel">The type of the model</typeparam> /// <param name="location">The absolute or relative location</param> /// <returns></returns> public static Engine <TModel> LoadOrCreate <TModel>(string location) where TModel : Model, new() { var config = new EngineConfiguration(location); return(LoadOrCreate <TModel>(config)); }
public FileSnapshotStore(EngineConfiguration config) : base(config) { }
public ImmutabilityKernel(EngineConfiguration config, Model model) : base(config, model) { }
public StreamJournalWriter(EngineConfiguration config, Func <ulong, Stream> streamFactory) { _streamProvider = streamFactory; _journalFormatter = config.CreateFormatter(FormatterUsage.Journal); _rolloverStrategy = config.CreateRolloverStrategy(); }
protected Kernel(EngineConfiguration config, Model model) { Synchronizer = config.CreateSynchronizer(); _model = model; Isolation = config.Isolation; }
public RoyalFoodTaster(EngineConfiguration config, Model model) : base(config, model) { _formatter = config.CreateFormatter(FormatterUsage.Snapshot); _foodTaster = _formatter.Clone(_model); }
public static Engine Create(Model model, EngineConfiguration config = null) { config = config ?? new EngineConfiguration(); config.ModelType = model.GetType(); return(Create <Model>(model, config)); }
public FileCommandStore(EngineConfiguration config) : base(config) { }
protected Kernel(EngineConfiguration config, Model model) { _resultFormatter = config.CreateFormatter(FormatterUsage.Results); _synchronizer = config.CreateSynchronizer(); _model = model; }