Exemplo n.º 1
0
        /// <summary>
        /// Mounts a namespace to the specified adapter.
        /// </summary>
        public void Mount(string nameSpace, StorageAdapterBase adapter)
        {
            using (Logger.EnterScope(nameof(StorageManager), Ctx, nameof(Mount)))
            {
                if (string.IsNullOrEmpty(nameSpace))
                {
                    Logger.Error(this.Ctx, Tag, nameof(Mount), null, CdmLogCode.ErrStorageNullNamespace);
                    return;
                }

                if (adapter != null)
                {
                    if (adapter is StorageAdapterBase adapterBase)
                    {
                        adapterBase.Ctx = this.Ctx;
                    }

                    this.NamespaceAdapters[nameSpace] = adapter;
                    CdmFolderDefinition fd = new CdmFolderDefinition(this.Ctx, "");
                    fd.Corpus     = this.Corpus as CdmCorpusDefinition;
                    fd.Namespace  = nameSpace;
                    fd.FolderPath = "/";
                    this.NamespaceFolders[nameSpace] = fd;
                    this.systemDefinedNamespaces.Remove(nameSpace);
                }
                else
                {
                    Logger.Error(this.Ctx, Tag, nameof(Mount), null, CdmLogCode.ErrStorageNullAdapter);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Allow replacing a storage adapter with another one for testing, leaving folders intact.
        /// </summary>
        internal void SetAdapter(string nameSpace, StorageAdapterBase adapter)
        {
            if (string.IsNullOrEmpty(nameSpace))
            {
                Logger.Error(this.Ctx, Tag, nameof(SetAdapter), null, CdmLogCode.ErrStorageNullNamespace);
                return;
            }

            if (adapter != null)
            {
                this.NamespaceAdapters[nameSpace] = adapter;
            }
            else
            {
                Logger.Error(this.Ctx, Tag, nameof(SetAdapter), null, CdmLogCode.ErrStorageNullAdapter);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Takes a corpus path, figures out the right adapter to use and then returns an adapter domain path.
        /// </summary>
        public string CorpusPathToAdapterPath(string corpusPath)
        {
            using (Logger.EnterScope(nameof(StorageManager), Ctx, nameof(CorpusPathToAdapterPath)))
            {
                if (string.IsNullOrEmpty(corpusPath))
                {
                    Logger.Error(this.Ctx, Tag, nameof(CorpusPathToAdapterPath), null, CdmLogCode.ErrStorageNullCorpusPath);
                    return(null);
                }

                string result = "";
                // break the corpus path into namespace and ... path
                Tuple <string, string> pathTuple = StorageUtils.SplitNamespacePath(corpusPath);
                if (pathTuple == null)
                {
                    Logger.Error(this.Ctx, Tag, nameof(CorpusPathToAdapterPath), null, CdmLogCode.ErrStorageNullCorpusPath);
                    return(null);
                }
                string nameSpace = pathTuple.Item1;
                if (string.IsNullOrWhiteSpace(nameSpace))
                {
                    nameSpace = this.DefaultNamespace;
                }

                // get the adapter registered for this namespace
                StorageAdapterBase namespaceAdapter = this.FetchAdapter(nameSpace);
                if (namespaceAdapter == null)
                {
                    Logger.Error(this.Ctx, Tag, nameof(CorpusPathToAdapterPath), null, CdmLogCode.ErrStorageNamespaceNotRegistered, nameSpace);
                }
                else
                {
                    // ask the storage adapter to 'adapt' this path
                    result = namespaceAdapter.CreateAdapterPath(pathTuple.Item2);
                }

                return(result);
            }
        }
Exemplo n.º 4
0
 public CacheContext(StorageAdapterBase adapter)
 {
     this.adapter = adapter;
     this.adapter.activeCacheContexts.Add(this);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Saves adapters config into a file.
 /// </summary>
 /// <param name="name">The name of a file.</param>
 /// <param name="adapter">The adapter used to save the config to a file.</param>
 public async Task SaveAdaptersConfigAsync(string name, StorageAdapterBase adapter)
 {
     await adapter.WriteAsync(name, FetchConfig());
 }