Пример #1
0
        // Helper that fixes a path from local to absolute.
        // Gets the object from that path then looks at the document where the object is found.
        // If dirty, the document is saved with the original name.
        private async Task <bool> SaveDirtyLink(string relative, CopyOptions options)
        {
            // get the document object from the import
            string docPath = Ctx.Corpus.Storage.CreateAbsoluteCorpusPath(relative, this);

            if (docPath == null)
            {
                Logger.Error(nameof(CdmManifestDefinition), this.Ctx as ResolveContext, $"Invalid corpus path {relative}`, `saveDirtyLink", "saveDirtyLink");
                return(false);
            }
            CdmObject objAt = await Ctx.Corpus.FetchObjectAsync <CdmObject>(docPath);

            if (objAt == null)
            {
                Logger.Error(nameof(CdmManifestDefinition), this.Ctx as ResolveContext, $"Couldn't get object from path {docPath}", "saveDirtyLink");
                return(false);
            }

            CdmDocumentDefinition docImp = objAt.InDocument as CdmDocumentDefinition;

            if (docImp != null)
            {
                if (docImp.IsDirty)
                {
                    // save it with the same name
                    if (await docImp.SaveAsAsync(docImp.Name, true, options) == false)
                    {
                        Logger.Error(nameof(CdmManifestDefinition), this.Ctx as ResolveContext, $"failed saving document {docImp.Name}", "saveDirtyLink");
                        return(false);
                    }
                }
            }

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Helper that fixes a path from local to absolute.
        /// Gets the object from that path then looks at the document where the object is found.
        /// If dirty, the document is saved with the original name.
        /// </summary>
        /// <param name="relative"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        private async Task <bool> SaveDirtyLink(string relative, CopyOptions options)
        {
            // get the document object from the import
            string docPath = Ctx.Corpus.Storage.CreateAbsoluteCorpusPath(relative, this);

            if (docPath == null)
            {
                Logger.Error(this.Ctx as ResolveContext, Tag, nameof(SaveDirtyLink), this.AtCorpusPath, CdmLogCode.ErrValdnInvalidCorpusPath, relative);
                return(false);
            }
            CdmObject objAt = await Ctx.Corpus.FetchObjectAsync <CdmObject>(docPath);

            if (objAt == null)
            {
                Logger.Error(this.Ctx as ResolveContext, Tag, nameof(SaveDirtyLink), this.AtCorpusPath, CdmLogCode.ErrPersistObjectNotFound, docPath);
                return(false);
            }

            CdmDocumentDefinition docImp = objAt.InDocument;

            if (docImp != null && docImp.IsDirty)
            {
                // save it with the same name
                if (await docImp.SaveAsAsync(docImp.Name, true, options) == false)
                {
                    Logger.Error(this.Ctx as ResolveContext, Tag, nameof(SaveDirtyLink), this.AtCorpusPath, CdmLogCode.ErrDocEntityDocSavingFailure, docImp.Name);
                    return(false);
                }
            }
            return(true);
        }
Пример #3
0
        virtual internal async Task <bool> SaveLinkedDocuments(CopyOptions options = null)
        {
            List <CdmDocumentDefinition> docs = new List <CdmDocumentDefinition>();

            if (options == null)
            {
                options = new CopyOptions();
            }

            if (this.Imports != null)
            {
                // the only linked documents would be the imports
                foreach (CdmImport imp in this.Imports)
                {
                    // get the document object from the import
                    string docPath = Ctx.Corpus.Storage.CreateAbsoluteCorpusPath(imp.CorpusPath, this);
                    if (docPath == null)
                    {
                        Logger.Error((ResolveContext)this.Ctx, Tag, nameof(SaveLinkedDocuments), this.AtCorpusPath, CdmLogCode.ErrValdnInvalidCorpusPath, imp.CorpusPath);
                        return(false);
                    }
                    try
                    {
                        CdmObject objAt = await Ctx.Corpus.FetchObjectAsync <CdmObject>(docPath);

                        if (objAt == null)
                        {
                            Logger.Error((ResolveContext)this.Ctx, Tag, nameof(SaveLinkedDocuments), this.AtCorpusPath, CdmLogCode.ErrPersistObjectNotFound, imp.CorpusPath);
                            return(false);
                        }
                        CdmDocumentDefinition docImp = objAt.InDocument;
                        if (docImp != null && docImp.IsDirty)
                        {
                            docs.Add(docImp);
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.Error((ResolveContext)this.Ctx, Tag, nameof(SaveLinkedDocuments), this.AtCorpusPath, CdmLogCode.ErrPersistObjectNotFound, imp.CorpusPath + " " + e.Message);
                        return(false);
                    }
                }
                foreach (var docImp in docs)
                {
                    if (await docImp.SaveAsAsync(docImp.Name, true, options) == false)
                    {
                        Logger.Error((ResolveContext)this.Ctx, Tag, nameof(SaveLinkedDocuments), this.AtCorpusPath, CdmLogCode.ErrDocImportSavingFailure, docImp.Name);
                        return(false);
                    }
                }
            }
            return(true);
        }
Пример #4
0
 /// <summary>
 /// Saves CdmDocumentDefinition if dirty.
 /// Was created from SaveDirtyLink in order to be able to save docs in parallel.
 /// Represents the part of SaveDirtyLink that could be parallelized.
 /// </summary>
 /// <param name="docImp"></param>
 /// <param name="options"></param>
 /// <returns></returns>
 private async Task <bool> SaveDocumentIfDirty(CdmDocumentDefinition docImp, CopyOptions options)
 {
     if (docImp != null && docImp.IsDirty)
     {
         // save it with the same name
         if (await docImp.SaveAsAsync(docImp.Name, true, options) == false)
         {
             Logger.Error(this.Ctx as ResolveContext, Tag, nameof(SaveDocumentIfDirty), this.AtCorpusPath, CdmLogCode.ErrDocEntityDocSavingFailure, docImp.Name);
             return(false);
         }
     }
     return(true);
 }