Пример #1
0
        /// <summary>
        /// Loads a folder or document given its corpus path.
        /// </summary>
        /// <param name="objectPath"></param>
        /// <param name="forceReload"></param>
        /// <param name="resOpt"></param>
        /// <param name="indexing"></param>
        /// <returns></returns>
        internal Task <CdmContainerDefinition> LoadFolderOrDocument(string objectPath, bool forceReload = false, ResolveOptions resOpt = null)
        {
            lock (this.allDocuments)
            {
                // If the document is already loaded and the user do not want to force a reload, return the document previously loaded.
                if (!forceReload && this.pathLookup.ContainsKey(objectPath))
                {
                    CdmContainerDefinition doc = this.pathLookup[objectPath].Item2;
                    return(Task.FromResult(doc));
                }

                // Mark as loading.
                this.docsCurrentlyLoading.Add(objectPath);
            }

            // The document needs to be loaded. Create a task to load it and add to the list of documents currently loading.
            var task = Task.Run(async() =>
            {
                var result = await this._LoadFolderOrDocument(objectPath, forceReload, resOpt);
                this.MarkAsLoadedOrFailed(objectPath, result);
                return(result);
            });

            return(task);
        }
Пример #2
0
        /// <summary>
        /// Marks a document for indexing if it has loaded successfully, or adds it to the list of documents not found if it failed to load.
        /// </summary>
        /// <param name="docPath">The document path.</param>
        /// <param name="doc">The document that was loaded.</param>
        /// <returns>Returns true if the document has loaded, false if it failed to load.</returns>
        private void MarkAsLoadedOrFailed(string docPath, CdmContainerDefinition doc)
        {
            lock (this.allDocuments)
            {
                // Doc is no longer loading.
                this.docsCurrentlyLoading.Remove(docPath);

                if (doc == null)
                {
                    // The doc failed to load, so set doc as not found.
                    this.docsNotFound.Add(docPath);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Takes a corpus path (relative or absolute) and creates a valid relative corpus path with namespace.
        /// <paramref name="objectPath"/> The path that should be made relative, if possible
        /// <paramref name="relativeTo"/> The object that the path should be made relative with respect to.
        /// </summary>
        public string CreateRelativeCorpusPath(string objectPath, CdmContainerDefinition relativeTo = null)
        {
            string newPath = this.CreateAbsoluteCorpusPath(objectPath, relativeTo);

            string namespaceString = relativeTo != null ? $"{relativeTo.Namespace}:" : "";

            if (!string.IsNullOrWhiteSpace(namespaceString) && !string.IsNullOrWhiteSpace(newPath) && newPath.StartsWith(namespaceString))
            {
                newPath = newPath.Substring(namespaceString.Length);

                if (relativeTo?.FolderPath != null && newPath.StartsWith(relativeTo.FolderPath))
                {
                    newPath = newPath.Substring(relativeTo.FolderPath.Length);
                }
            }
            return(newPath);
        }