Example #1
0
            public static DocumentOption GetOption(DocumentProvider provider)
            {
                var key = provider.Key;

                if (!Options.TryGetValue(key, out DocumentOption option))
                {
                    key = provider.Connection != null?provider.Connection.GetType().Name : typeof(DocumentProvider).Name;

                    Options.TryGetValue(key, out option);
                }

                if (option == null)
                {
                    option = new DocumentOption();
                    option.RegisterDefaults();

                    if (option.CacheInstance == null)
                    {
                        option.CacheInstance = new DocumentInMemory(option.Name, new DocumentBsonSerializer());
                    }
                }

                if (Options.ContainsKey(key))
                {
                    Options[key] = option;
                }
                else
                {
                    Options.TryAdd(key, option);
                }

                return(option);
            }
Example #2
0
 private static void Map(string key, DocumentOption option)
 {
     if (Options.ContainsKey(key))
     {
         Options[key] = option;
     }
     else
     {
         Options.TryAdd(key, option);
     }
 }
Example #3
0
            public static void Initialize(DocumentProvider provider, DocumentOption option = null)
            {
                Provider = provider;

                if (option == null)
                {
                    option = GetOption(provider);
                }
                else
                {
                    Map(provider.Key, option);
                }

                var engine = Get(provider, option).Initialize();
            }
        public DocumentEngine(DocumentProvider documentProvider, DocumentOption option)
        {
            Option   = option;
            Provider = documentProvider;
            Cache    = option.CacheInstance;
            Logger   = option.DocumentLogger;
            Watcher  = option.DocumentWatcher;
            ParseOf  = option.ParserOfTypes;
            Monitor  = new DocumentMonitor();

            if (Option.SupportDocumentWatcher)
            {
                Watcher?.WaitForChanged(this);
            }
        }
Example #5
0
            internal static IDocumentEngine Get(DocumentProvider documentProvider, DocumentOption option)
            {
                if (documentProvider == null)
                {
                    throw new Exception("DocumentProvider is null");
                }

                if (option == null)
                {
                    option = GetOption(documentProvider);
                }

                if (option.CacheInstance == null)
                {
                    option.CacheInstance = new DocumentInMemory(option.Name, new DocumentBsonSerializer());
                }

                if (option.EngineProvider == null)
                {
                    throw new Exception("Engine undefined..");
                }

                return((DocumentEngine)Activator.CreateInstance(option.EngineProvider, documentProvider, option));
            }
Example #6
0
 public static void Initialize(DocumentOption option)
 {
     Initialize(new DocumentProvider(), option);
 }
Example #7
0
 public static void Initialize(IDbConnection connection, DocumentOption option = null)
 {
     Initialize(new DocumentProvider(connection), option);
 }
Example #8
0
 public static void Initialize(string baseDirectory, DocumentOption option = null)
 {
     Initialize(new DocumentProvider(baseDirectory), option);
 }
Example #9
0
            public static void Map(Type type, DocumentOption option)
            {
                var key = type.Name;

                Map(key, option);
            }
Example #10
0
 public ObjectiksOf(IDbConnection connection, DocumentOption options = null)
 {
     Engine = Core.Get(new DocumentProvider(connection), options);
 }
Example #11
0
 public ObjectiksOf(DocumentProvider documentProvider, DocumentOption options = null)
 {
     Engine = Core.Get(documentProvider, options);
 }
Example #12
0
 public ObjectiksOf(string baseDirectory, DocumentOption options = null)
 {
     Engine = Core.Get(new DocumentProvider(baseDirectory), options);
 }
Example #13
0
 public DocumentMeta(string typeOf, DocumentType documentType, DocumentProvider fileProvider, DocumentOption option)
 {
     TypeOf             = typeOf;
     ParseOf            = documentType.ParseOf;
     WorkOf             = documentType.WorkOf;
     PrimaryOf          = documentType.PrimaryOf;
     UserOf             = documentType.UserOf;
     KeyOfNames         = documentType.KeyOf;
     Cache              = documentType.Cache;
     Keys               = new DocumentKeyIndex();
     Partitions         = new DocumentPartitions();
     Partitions.Current = 0;
     Partitions.Next    = 0;
     Directory          = Path.Combine(fileProvider.BaseDirectory, DocumentDefaults.Documents, typeOf);
     Extention          = option.Extention;
     Exists             = true;
 }