示例#1
0
文件: Engine.cs 项目: quanhb/OrigoDB
        public static Engine Create(Model model, string location)
        {
            var config = EngineConfiguration.Create();

            config.Location.OfJournal = location;
            return(Create(model, config));
        }
示例#2
0
文件: Engine.cs 项目: quanhb/OrigoDB
        /// <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));
        }
示例#3
0
文件: Engine.cs 项目: quanhb/OrigoDB
        /// <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));
        }
示例#4
0
文件: Engine.cs 项目: quanhb/OrigoDB
 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));
 }
示例#5
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));
        }
示例#6
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));
        }
示例#7
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));
        }
示例#8
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)
            {
                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));
            }
        }
示例#9
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);
        }
示例#10
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));
        }