示例#1
0
文件: Engine.cs 项目: quanhb/OrigoDB
        /// <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));
        }
示例#2
0
        /// <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));
        }
示例#3
0
文件: Engine.cs 项目: quanhb/OrigoDB
        /// <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));
        }
示例#4
0
        /// <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));
        }
示例#5
0
文件: Engine.cs 项目: quanhb/OrigoDB
        /// <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));
        }
示例#6
0
        /// <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);
        }
示例#7
0
        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));
            }
        }
示例#8
0
文件: Engine.cs 项目: quanhb/OrigoDB
        /// <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);
        }
示例#9
0
        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));
        }
示例#10
0
        public static Engine Create(Model model, string location)
        {
            var config = new EngineConfiguration(location);

            return(Create(model, config));
        }
示例#11
0
        /// <summary>
        /// Get a proxy for a given type T based on same conventions as Engine.For&lt;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());
        }
示例#12
0
 public static ClientConfiguration Create(EngineConfiguration config)
 {
     return(new LocalClientConfiguration(config));
 }
示例#13
0
 public Engine(TModel model, EngineConfiguration config) : base(model, config)
 {
 }
示例#14
0
 public OptimisticKernel(EngineConfiguration config, Model model)
     : base(config, model)
 {
 }
示例#15
0
        /// <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));
        }
示例#16
0
 public FileSnapshotStore(EngineConfiguration config)
     : base(config)
 {
 }
示例#17
0
 public ImmutabilityKernel(EngineConfiguration config, Model model) :
     base(config, model)
 {
 }
示例#18
0
 public StreamJournalWriter(EngineConfiguration config, Func <ulong, Stream> streamFactory)
 {
     _streamProvider   = streamFactory;
     _journalFormatter = config.CreateFormatter(FormatterUsage.Journal);
     _rolloverStrategy = config.CreateRolloverStrategy();
 }
示例#19
0
 protected Kernel(EngineConfiguration config, Model model)
 {
     Synchronizer = config.CreateSynchronizer();
     _model       = model;
     Isolation    = config.Isolation;
 }
示例#20
0
 public RoyalFoodTaster(EngineConfiguration config, Model model)
     : base(config, model)
 {
     _formatter  = config.CreateFormatter(FormatterUsage.Snapshot);
     _foodTaster = _formatter.Clone(_model);
 }
示例#21
0
 public static Engine Create(Model model, EngineConfiguration config = null)
 {
     config           = config ?? new EngineConfiguration();
     config.ModelType = model.GetType();
     return(Create <Model>(model, config));
 }
示例#22
0
 public FileCommandStore(EngineConfiguration config) : base(config)
 {
 }
示例#23
0
文件: Kernel.cs 项目: quanhb/OrigoDB
 protected Kernel(EngineConfiguration config, Model model)
 {
     _resultFormatter = config.CreateFormatter(FormatterUsage.Results);
     _synchronizer    = config.CreateSynchronizer();
     _model           = model;
 }