Пример #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);
            }
Пример #2
0
 private static void Map(string key, DocumentOption option)
 {
     if (Options.ContainsKey(key))
     {
         Options[key] = option;
     }
     else
     {
         Options.TryAdd(key, option);
     }
 }
Пример #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();
            }
Пример #4
0
        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);
            }
        }
Пример #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));
            }
Пример #6
0
 public static void Initialize(DocumentOption option)
 {
     Initialize(new DocumentProvider(), option);
 }
Пример #7
0
 public static void Initialize(IDbConnection connection, DocumentOption option = null)
 {
     Initialize(new DocumentProvider(connection), option);
 }
Пример #8
0
 public static void Initialize(string baseDirectory, DocumentOption option = null)
 {
     Initialize(new DocumentProvider(baseDirectory), option);
 }
Пример #9
0
            public static void Map(Type type, DocumentOption option)
            {
                var key = type.Name;

                Map(key, option);
            }
Пример #10
0
 public ObjectiksOf(IDbConnection connection, DocumentOption options = null)
 {
     Engine = Core.Get(new DocumentProvider(connection), options);
 }
Пример #11
0
 public ObjectiksOf(DocumentProvider documentProvider, DocumentOption options = null)
 {
     Engine = Core.Get(documentProvider, options);
 }
Пример #12
0
 public ObjectiksOf(string baseDirectory, DocumentOption options = null)
 {
     Engine = Core.Get(new DocumentProvider(baseDirectory), options);
 }
Пример #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;
 }