public static Engine Create(Model model, string location) { var config = EngineConfiguration.Create(); config.Location.OfJournal = location; return(Create(model, config)); }
/// <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 = EngineConfiguration.Create(); config.Location.OfJournal = location; return(LoadOrCreate <TModel>(config)); }
/// <summary> /// Load an engine from the specified location /// </summary> /// <param name="location"></param> /// <returns></returns> public static Engine Load(string location) { var config = EngineConfiguration.Create(); config.Location.OfJournal = location; return(Load(config)); }
public static Engine Create(Model model, EngineConfiguration config = null) { config = config ?? EngineConfiguration.Create(); if (!config.Location.HasJournal) { config.Location.SetLocationFromType(model.GetType()); } return(Create <Model>(model, config)); }
/// <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> /// 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 ?? 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)); }
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) { Utils.Converters[typeof(StorageLocation)] = s => new FileStorageLocation(s); var config = EngineConfiguration.Create(); 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)); }