当前位置: 首页>>代码示例>>C#>>正文


C# IProgress.WriteStatus方法代码示例

本文整理汇总了C#中IProgress.WriteStatus方法的典型用法代码示例。如果您正苦于以下问题:C# IProgress.WriteStatus方法的具体用法?C# IProgress.WriteStatus怎么用?C# IProgress.WriteStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IProgress的用法示例。


在下文中一共展示了IProgress.WriteStatus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CopyImageMetadataToWholeBook

        public static void CopyImageMetadataToWholeBook(string folderPath, HtmlDom dom, Metadata metadata, IProgress progress)
        {
            progress.WriteStatus("Starting...");

            //First update the images themselves

            int completed = 0;
            var imgElements = GetImagePaths(folderPath);
            foreach (string path in imgElements)
            {
                progress.ProgressIndicator.PercentCompleted = (int)(100.0 * (float)completed / imgElements.Count());
                progress.WriteStatus("Copying to " + Path.GetFileName(path));
                using (var image = PalasoImage.FromFile(path))
                {
                    image.Metadata = metadata;
                    image.SaveUpdatedMetadataIfItMakesSense();
                }
                ++completed;
            }

            //Now update the html attributes which echo some of it, and is used by javascript to overlay displays related to
            //whether the info is there or missing or whatever.

            foreach (XmlElement img in dom.SafeSelectNodes("//img"))
            {
                UpdateImgMetdataAttributesToMatchImage(folderPath, img, progress, metadata);
            }
        }
开发者ID:JohnThomson,项目名称:testBloom,代码行数:28,代码来源:ImageUpdater.cs

示例2: CopyImageMetadataToWholeBook

        public static void CopyImageMetadataToWholeBook(string folderPath, HtmlDom dom, Metadata metadata, IProgress progress)
        {
            progress.WriteStatus("Starting...");

            //First update the images themselves

            int completed = 0;
            var imgElements = GetImagePaths(folderPath);
            foreach (string path in imgElements)
            {
                progress.ProgressIndicator.PercentCompleted = (int)(100.0 * (float)completed / imgElements.Count());
                progress.WriteStatus("Copying to " + Path.GetFileName(path));

                try
                {
                    metadata.WriteIntellectualPropertyOnly(path);
                }
                catch (TagLib.CorruptFileException e)
                {
                    NonFatalProblem.Report(ModalIf.Beta, PassiveIf.All,"Image metadata problem", "Bloom had a problem accessing the metadata portion of this image " + path+ "  ref(BL-3214)", e);
                }

                ++completed;
            }

            //Now update the html attributes which echo some of it, and is used by javascript to overlay displays related to
            //whether the info is there or missing or whatever.

            foreach (XmlElement img in dom.SafeSelectNodes("//img"))
            {
                UpdateImgMetdataAttributesToMatchImage(folderPath, img, progress, metadata);
            }
        }
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:33,代码来源:ImageUpdater.cs

示例3: CompressImage

 public static void CompressImage(string path, IProgress progress)
 {
     progress.WriteStatus("Compressing image: " + Path.GetFileName(path));
     var pngoutPath = FileLocator.GetFileDistributedWithApplication("optipng.exe");
     var result = CommandLineRunner.Run(pngoutPath, "\"" + path + "\"", Encoding.UTF8, Path.GetDirectoryName(path), 300, progress,
                                        (s) => progress.WriteMessage(s));
 }
开发者ID:JohnThomson,项目名称:testBloom,代码行数:7,代码来源:ImageUpdater.cs

示例4: CanConnect

        public override bool CanConnect(HgRepository localRepository, string projectName, IProgress progress)
        {
            var path = GetPotentialRepoUri(localRepository.Identifier, projectName, progress);
            if (URI.StartsWith(_networkMachineSpecifier) || URI.StartsWith(_alternativeMachineSpecifier))
            {
                progress.WriteStatus("Checking to see if we can connect with {0}...", path);
                if (!NetworkInterface.GetIsNetworkAvailable())
                {
                    progress.WriteWarning("This machine does not have a live network connection.");
                    return false;
                }
            }

            var result = Directory.Exists(path);
            if (!result)
            {
                progress.WriteWarning("Cannot find the specified file folder.");
            }
            return result;
        }
开发者ID:sillsdev,项目名称:chack,代码行数:20,代码来源:RepositoryAddress.cs

示例5: UploadBook

        public string UploadBook(string bookFolder, IProgress progress, out string parseId, string pdfToInclude = null)
        {
            // Books in the library should generally show as locked-down, so new users are automatically in localization mode.
            // Occasionally we may want to upload a new authoring template, that is, a 'book' that is suitableForMakingShells.
            // Such books must never be locked.
            // So, typically we will try to lock it. What we want to do is Book.RecordedAsLockedDown = true; Book.Save().
            // But all kinds of things have to be set up before we can create a Book. So we duplicate a few bits of code.
            var htmlFile = BookStorage.FindBookHtmlInFolder(bookFolder);
            bool wasLocked = false;
            bool allowLocking = false;
            HtmlDom domForLocking = null;
            var metaDataText = MetaDataText(bookFolder);
            var metadata = BookMetaData.FromString(metaDataText);
            if (!string.IsNullOrEmpty(htmlFile))
            {
                var xmlDomFromHtmlFile = XmlHtmlConverter.GetXmlDomFromHtmlFile(htmlFile, false);
                domForLocking = new HtmlDom(xmlDomFromHtmlFile);
                wasLocked = Book.Book.HtmlHasLockedDownFlag(domForLocking);
                allowLocking = !metadata.IsSuitableForMakingShells;
                if (allowLocking && !wasLocked)
                {
                    Book.Book.RecordAsLockedDown(domForLocking, true);
                    XmlHtmlConverter.SaveDOMAsHtml5(domForLocking.RawDom, htmlFile);
                }
            }
            string s3BookId;
            try
            {
                // In case we somehow have a book with no ID, we must have one to upload it.
                if (string.IsNullOrEmpty(metadata.Id))
                {
                    metadata.Id = Guid.NewGuid().ToString();
                }
                // And similarly it should have SOME title.
                if (string.IsNullOrEmpty(metadata.Title))
                {
                    metadata.Title = Path.GetFileNameWithoutExtension(bookFolder);
                }
                metadata.SetUploader(UserId);
                s3BookId = S3BookId(metadata);
                metadata.DownloadSource = s3BookId;
                // Any updated ID at least needs to become a permanent part of the book.
                // The file uploaded must also contain the correct DownloadSource data, so that it can be used
                // as an 'order' to download the book.
                // It simplifies unit testing if the metadata file is also updated with the uploadedBy value.
                // Not sure if there is any other reason to do it (or not do it).
                // For example, do we want to send/receive who is the latest person to upload?
                metadata.WriteToFolder(bookFolder);
                // The metadata is also a book order...but we need it on the server with the desired file name,
                // because we can't rename on download. The extension must be the one Bloom knows about,
                // and we want the file name to indicate which book, so use the name of the book folder.
                var metadataPath = BookMetaData.MetaDataPath(bookFolder);
                var orderPath = Path.Combine(bookFolder, Path.GetFileName(bookFolder) + BookOrderExtension);
                RobustFile.Copy(metadataPath, orderPath, true);
                parseId = "";
                try
                {
                    _s3Client.UploadBook(s3BookId, bookFolder, progress, pdfToInclude: pdfToInclude);
                    metadata.BaseUrl = _s3Client.BaseUrl;
                    metadata.BookOrder = _s3Client.BookOrderUrlOfRecentUpload;
                    progress.WriteStatus(LocalizationManager.GetString("PublishTab.Upload.UploadingBookMetadata", "Uploading book metadata", "In this step, Bloom is uploading things like title, languages, and topic tags to the BloomLibrary.org database."));
                    // Do this after uploading the books, since the ThumbnailUrl is generated in the course of the upload.
                    var response = _parseClient.SetBookRecord(metadata.WebDataJson);
                    parseId = response.ResponseUri.LocalPath;
                    int index = parseId.LastIndexOf('/');
                    parseId = parseId.Substring(index + 1);
                    if (parseId == "books")
                    {
                        // For NEW books the response URL is useless...need to do a new query to get the ID.
                        var json = _parseClient.GetSingleBookRecord(metadata.Id);
                        parseId = json.objectId.Value;
                    }
                    //   if (!UseSandbox) // don't make it seem like there are more uploads than their really are if this a tester pushing to the sandbox
                    {
                        Analytics.Track("UploadBook-Success", new Dictionary<string, string>() { { "url", metadata.BookOrder }, { "title", metadata.Title } });
                    }
                }
                catch (WebException e)
                {
                    DisplayNetworkUploadProblem(e, progress);
                    if (!UseSandbox) // don't make it seem like there are more upload failures than their really are if this a tester pushing to the sandbox
                        Analytics.Track("UploadBook-Failure", new Dictionary<string, string>() { { "url", metadata.BookOrder }, { "title", metadata.Title }, { "error", e.Message } });
                    return "";
                }
                catch (AmazonS3Exception e)
                {
                    if (e.Message.Contains("The difference between the request time and the current time is too large"))
                    {
                        progress.WriteError(LocalizationManager.GetString("PublishTab.Upload.TimeProblem",
                            "There was a problem uploading your book. This is probably because your computer is set to use the wrong timezone or your system time is badly wrong. See http://www.di-mgt.com.au/wclock/help/wclo_setsysclock.html for how to fix this."));
                        if (!UseSandbox)
                            Analytics.Track("UploadBook-Failure-SystemTime");
                    }
                    else
                    {
                        DisplayNetworkUploadProblem(e, progress);
                        if (!UseSandbox)
                            // don't make it seem like there are more upload failures than their really are if this a tester pushing to the sandbox
                            Analytics.Track("UploadBook-Failure",
                                new Dictionary<string, string>() { { "url", metadata.BookOrder }, { "title", metadata.Title }, { "error", e.Message } });
//.........这里部分代码省略.........
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:101,代码来源:BookTransfer.cs

示例6: Save

 //        public void SaveAs(string path)
 //        {
 //            _doc.Save(path);
 //        }
 public void Save(IProgress progress)
 {
     try
     {
         if (string.IsNullOrEmpty(AnnotationFilePath))
         {
             throw new InvalidOperationException("Cannot save if the repository was created from a string");
         }
         progress.WriteStatus("Saving Chorus Notes...");
         using (var writer = XmlWriter.Create(AnnotationFilePath, CanonicalXmlSettings.CreateXmlWriterSettings())
             )
         {
             _doc.Save(writer);
         }
         progress.WriteStatus("");
         _isDirty = false;
     }
     catch(Exception e)
     {
         SIL.Reporting.ErrorReport.NotifyUserOfProblem(e, "Chorus has a problem saving notes for {0}.",
                                                          _annotationFilePath);
     }
 }
开发者ID:regnrand,项目名称:chorus,代码行数:27,代码来源:AnnotationRepository.cs

示例7: UploadDirectory

        /// <summary>
        /// THe weird thing here is that S3 doesn't really have folders, but you can give it a key like "collection/book2/file3.htm"
        /// and it will name it that, and gui client apps then treat that like a folder structure, so you feel like there are folders.
        /// </summary>
        private void UploadDirectory(string prefix, string directoryPath, IProgress progress)
        {
            if (!Directory.Exists(directoryPath))
            {
                throw new DirectoryNotFoundException(
                    "Source directory does not exist or could not be found: "
                    + directoryPath);
            }
            prefix = prefix + Path.GetFileName(directoryPath) + kDirectoryDelimeterForS3;

            var filesToUpload = Directory.GetFiles(directoryPath);

            // Remember the url that can be used to download files like thumbnails and preview.pdf. This seems to work but I wish
            // I could find a way to get a definitive URL from the response to UploadPart or some similar way.
            // This method gets called for the root directory (ending in guid), the main directory (ending in book name), and subdirectories.
            // We want to keep the one that ends in the book name...the main root directory.
            // This should be the first non-empty directory we are passed (the root only has a folder in it)
            if (BaseUrl == null && filesToUpload.Length > 0)
                BaseUrl = "https://s3.amazonaws.com/" + _bucketName + "/" + HttpUtility.UrlEncode(prefix);;

            using(var transferUtility = new TransferUtility(_amazonS3))
            {
                foreach(string file in filesToUpload)
                {
                    var fileName = Path.GetFileName(file);
                    if(excludedFileExtensionsLowerCase.Contains(Path.GetExtension(fileName.ToLowerInvariant())))
                        continue; // BL-2246: skip uploading this one

                    var request = new TransferUtilityUploadRequest()
                    {
                        BucketName = _bucketName,
                        FilePath = file,
                        Key = prefix + fileName
                    };
                    // The effect of this is that navigating to the file's URL is always treated as an attempt to download the file.
                    // This is definitely not desirable for the PDF (typically a preview) which we want to navigate to in the Preview button
                    // of BloomLibrary.
                    // I'm not sure whether there is still any reason to do it for other files.
                    // It was temporarily important for the BookOrder file when the Open In Bloom button just downloaded it.
                    // However, now the download link uses the bloom: prefix to get the URL passed directly to Bloom,
                    // it may not be needed for anything. Still, at least for the files a browser would not know how to
                    // open, it seems desirable to download them with their original names, if such a thing should ever happen.
                    // So I'm leaving the code in for now except in cases where we know we don't want it.
                    // It is possible to also set the filename ( after attachment, put ; filename='" + Path.GetFileName(file) + "').
                    // In principle this would be a good thing, since the massive AWS filenames are not useful.
                    // However, AWSSDK can't cope with setting this for files with non-ascii names.
                    // It seems that the header we insert here eventually becomes a header for a web request, and these allow only ascii.
                    // There may be some way to encode non-ascii filenames to get the effect, if we ever want it again. Or AWS may fix the problem.
                    // If you put setting the filename back in without such a workaround, be sure to test with a non-ascii book title.
                    if(Path.GetExtension(file).ToLowerInvariant() != ".pdf")
                        request.Headers.ContentDisposition = "attachment";
                    request.CannedACL = S3CannedACL.PublicRead; // Allows any browser to download it.

                    progress.WriteStatus(LocalizationManager.GetString("PublishTab.Upload.UploadingStatus", "Uploading {0}"),
                        fileName);
                    if (progress.CancelRequested)
                        return;

                    try
                    {
                        transferUtility.Upload(request);

                    }
                    catch(Exception e)
                    {
                        throw;
                    }
                    if(fileName.EndsWith(BookTransfer.BookOrderExtension))
                    {
                        // Remember the url that can be used to download the book. This seems to work but I wish
                        // I could find a way to get a definitive URL from the response to UploadPart or some similar way.
                        BookOrderUrlOfRecentUpload = BloomLinkArgs.kBloomUrlPrefix + BloomLinkArgs.kOrderFile + "=" + _bucketName + "/" +
                                                     HttpUtility.UrlEncode(prefix + fileName);
                    }
                }

                foreach(string subdir in Directory.GetDirectories(directoryPath))
                {
                    UploadDirectory(prefix, subdir, progress);
                    if (progress.CancelRequested)
                        return;
                }
            }
        }
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:88,代码来源:BloomS3Client.cs

示例8: UploadSingleFile

 /// <summary>
 /// Allows a file to be put into the root of the bucket.
 /// Could be enhanced to specify a sub folder path, but I don't need that for the current use.
 /// </summary>
 /// <returns>url to the uploaded file</returns>
 public string UploadSingleFile(string pathToFile, IProgress progress)
 {
     using(var transferUtility = new TransferUtility(GetAmazonS3(_bucketName)))
     {
         var request = new TransferUtilityUploadRequest
         {
             BucketName = _bucketName,
             FilePath = pathToFile,
             Key = Path.GetFileName(pathToFile),
             CannedACL = S3CannedACL.PublicRead // Allows any browser to download it.
         };
         progress.WriteStatus("Uploading book to Bloom Support...");
         transferUtility.Upload(request);
         return "https://s3.amazonaws.com/" + _bucketName + "/" + HttpUtility.UrlEncode(request.Key);
     }
 }
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:21,代码来源:BloomS3Client.cs

示例9: RemoveTransparency

 private static void RemoveTransparency(Image original, string path, IProgress progress)
 {
     progress.WriteStatus("RemovingTransparency from image: " + Path.GetFileName(path));
     using (var b = new Bitmap(original.Width, original.Height))
     {
         DrawImageWithWhiteBackground(original, b);
         SIL.IO.RobustIO.SaveImage(b, path, ImageFormat.Png);
     }
 }
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:9,代码来源:ImageUtils.cs

示例10: UpdateImgMetdataAttributesToMatchImage

        public static void UpdateImgMetdataAttributesToMatchImage(string folderPath, XmlElement imgElement, IProgress progress, Metadata metadata)
        {
            //see also PageEditingModel.UpdateMetadataAttributesOnImage(), which does the same thing but on the browser dom
            var fileName = imgElement.GetOptionalStringAttribute("src", string.Empty).ToLower();

            var end = fileName.IndexOf('?');
            if (end > 0)
            {
                fileName = fileName.Substring(0, end);
            }
            if (fileName == "placeholder.png" || fileName == "license.png")
                return;
            if (string.IsNullOrEmpty(fileName))
            {
                Logger.WriteEvent("Book.UpdateImgMetdataAttributesToMatchImage() Warning: img has no or empty src attribute");
                //Debug.Fail(" (Debug only) img has no or empty src attribute");
                return; // they have bigger problems, which aren't appropriate to deal with here.
            }
            if (metadata == null)
            {
                progress.WriteStatus("Reading metadata from " + fileName);
                var path = folderPath.CombineForPath(fileName);
                if (!File.Exists(path)) // they have bigger problems, which aren't appropriate to deal with here.
                {
                    imgElement.RemoveAttribute("data-copyright");
                    imgElement.RemoveAttribute("data-creator");
                    imgElement.RemoveAttribute("data-license");
                    Logger.WriteEvent("Book.UpdateImgMetdataAttributesToMatchImage()  Image " + path + " is missing");
                    Debug.Fail(" (Debug only) Image " + path + " is missing");
                    return;
                }
                using (var image = PalasoImage.FromFile(path))
                {
                    metadata = image.Metadata;
                }
            }

            progress.WriteStatus("Writing metadata to HTML for " + fileName);

            imgElement.SetAttribute("data-copyright",
                             String.IsNullOrEmpty(metadata.CopyrightNotice) ? "" : metadata.CopyrightNotice);
            imgElement.SetAttribute("data-creator", String.IsNullOrEmpty(metadata.Creator) ? "" : metadata.Creator);
            imgElement.SetAttribute("data-license", metadata.License == null ? "" : metadata.License.ToString());
        }
开发者ID:JohnThomson,项目名称:testBloom,代码行数:44,代码来源:ImageUpdater.cs

示例11: UpdatePageFromFactoryTemplates

        private void UpdatePageFromFactoryTemplates(HtmlDom bookDom, IProgress progress)
        {
            var originalLayout = Layout.FromDom(bookDom, Layout.A5Portrait);

            var templatePath = BloomFileLocator.GetFactoryBookTemplateDirectory( "Basic Book");

            var templateDom = XmlHtmlConverter.GetXmlDomFromHtmlFile(templatePath.CombineForPath("Basic Book.html"), false);

            progress.WriteStatus("Updating pages that were based on Basic Book...");
            foreach (XmlElement templatePageDiv in templateDom.SafeSelectNodes("//body/div"))
            {
                if (templatePageDiv.GetOptionalStringAttribute("class", "").Contains("customPage"))
                    continue; // we sure don't want to revert this page to its blank custom state

                var templateId = templatePageDiv.GetStringAttribute("id");
                if (string.IsNullOrEmpty(templateId))
                    continue;

                var templatePageClasses = templatePageDiv.GetAttribute("class");
                //note, lineage is a series of guids separated by a semicolon
                foreach (XmlElement pageDiv in bookDom.SafeSelectNodes("//body/div[contains(@data-pagelineage, '" + templateId + "')]"))
                {
                    pageDiv.SetAttribute("class", templatePageClasses);

                    //now for all the editable elements within the page
                    int count = 0;
                    foreach (XmlElement templateElement in templatePageDiv.SafeSelectNodes("div/div"))
                    {
                        UpdateDivInsidePage(count, templateElement, pageDiv, progress);
                        ++count;
                    }
                }
            }

            //custom layout gets messed up when we copy classes over from, for example, Basic Book
            SetLayout(originalLayout);

            //Likewise, the multilingual settings (e.g. bloom-bilingual) get messed up, so restore those
            UpdateMultilingualSettings(bookDom);
        }
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:40,代码来源:Book.cs

示例12: BringBookUpToDate

        /// <summary>
        /// As the bloom format evolves, including structure and classes and other attributes, this
        /// makes changes to old books. It needs to be very fast, because currently we dont' have
        /// a real way to detect the need for migration. So we do it all the time.
        ///
        /// Yes, we have format version number, but, for example, one overhaul of the common xmatter
        /// html introduced a new class, "frontCover". Hardly enough to justify bumping the version number
        /// and making older Blooms unable to read new books. But because this is run, the xmatter will be
        /// migrated to the new template.
        /// </summary>
        /// <param name="bookDOM"></param>
        /// <param name="progress"></param>
        private void BringBookUpToDate(HtmlDom bookDOM /* may be a 'preview' version*/, IProgress progress)
        {
            if (Title.Contains("allowSharedUpdate"))
            {
                // Original version of this code that suffers BL_3166
                progress.WriteStatus("Updating Front/Back Matter...");
                BringXmatterHtmlUpToDate(bookDOM);

                progress.WriteStatus("Gathering Data...");
                TranslationGroupManager.PrepareElementsInPageOrDocument(bookDOM.RawDom, _collectionSettings);
                progress.WriteStatus("Updating Data...");

                InjectStringListingActiveLanguagesOfBook();

                //hack
                if (bookDOM == OurHtmlDom) //we already have a data for this
                {
                    _bookData.SynchronizeDataItemsThroughoutDOM();

                    // I think we should only mess with tags if we are updating the book for real.
                    var oldTagsPath = Path.Combine(_storage.FolderPath, "tags.txt");
                    if (RobustFile.Exists(oldTagsPath))
                    {
                        ConvertTagsToMetaData(oldTagsPath, BookInfo);
                        RobustFile.Delete(oldTagsPath);
                    }
                }
                else //used for making a preview dom
                {
                    var bd = new BookData(bookDOM, _collectionSettings, UpdateImageMetadataAttributes);
                    bd.SynchronizeDataItemsThroughoutDOM();
                }
                // get any license info into the json and restored in the replaced front matter.
                BookCopyrightAndLicense.SetMetadata(GetLicenseMetadata(), bookDOM, FolderPath, CollectionSettings);

                bookDOM.RemoveMetaElement("bloomBookLineage", () => BookInfo.BookLineage, val => BookInfo.BookLineage = val);
                bookDOM.RemoveMetaElement("bookLineage", () => BookInfo.BookLineage, val => BookInfo.BookLineage = val);
                // BookInfo will always have an ID, the constructor makes one even if there is no json file.
                // To allow migration, pretend it has no ID if there is not yet a meta.json.
                bookDOM.RemoveMetaElement("bloomBookId", () => (RobustFile.Exists(BookInfo.MetaDataPath) ? BookInfo.Id : null),
                    val => BookInfo.Id = val);

                // Title should be replicated in json
                //if (!string.IsNullOrWhiteSpace(Title)) // check just in case we somehow have more useful info in json.
                //    bookDOM.Title = Title;
                // Bit of a kludge, but there's no way to tell whether a boolean is already set in the JSON, so we fake that it is not,
                // thus ensuring that if something is in the metadata we use it.
                // If there is nothing there the default of true will survive.
                bookDOM.RemoveMetaElement("SuitableForMakingVernacularBooks", () => null,
                    val => BookInfo.IsSuitableForVernacularLibrary = val == "yes" || val == "definitely");

                UpdateTextsNewlyChangedToRequiresParagraph(bookDOM);

                //we've removed and possible added pages, so our page cache is invalid
                _pagesCache = null;
            }
            else
            {
                // New version that we hope prevents BL_3166
                if (_doingBookUpdate)
                    MessageBox.Show("Caught Bloom doing two updates at once! Possible BL-3166 is being prevented");
                lock (_updateLock)
                {
                    _doingBookUpdate = true;
                    progress.WriteStatus("Updating Front/Back Matter...");
                    // Nothing in the update process should change the license info, so save what is current before we mess with
                    // anything (may fix BL-3166).
                    var licenseMetadata = GetLicenseMetadata();
                    BringXmatterHtmlUpToDate(bookDOM);

                    progress.WriteStatus("Gathering Data...");
                    TranslationGroupManager.PrepareElementsInPageOrDocument(bookDOM.RawDom, _collectionSettings);
                    progress.WriteStatus("Updating Data...");

                    InjectStringListingActiveLanguagesOfBook();

                    //hack
                    if (bookDOM == OurHtmlDom) //we already have a data for this
                    {
                        _bookData.SynchronizeDataItemsThroughoutDOM();

                        // I think we should only mess with tags if we are updating the book for real.
                        var oldTagsPath = Path.Combine(_storage.FolderPath, "tags.txt");
                        if (RobustFile.Exists(oldTagsPath))
                        {
                            ConvertTagsToMetaData(oldTagsPath, BookInfo);
                            RobustFile.Delete(oldTagsPath);
                        }
//.........这里部分代码省略.........
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:101,代码来源:Book.cs

示例13: UpdateImgMetdataAttributesToMatchImage

        public static void UpdateImgMetdataAttributesToMatchImage(string folderPath, XmlElement imgElement, IProgress progress, Metadata metadata)
        {
            //see also PageEditingModel.UpdateMetadataAttributesOnImage(), which does the same thing but on the browser dom
            var url = HtmlDom.GetImageElementUrl(new ElementProxy(imgElement));
            var end = url.NotEncoded.IndexOf('?');
            string fileName = url.NotEncoded;
            if (end > 0)
            {
                fileName = fileName.Substring(0, end);
            }
            if (fileName.ToLowerInvariant() == "placeholder.png" || fileName.ToLowerInvariant() == "license.png")
                return;
            if (string.IsNullOrEmpty(fileName))
            {
                Logger.WriteEvent("Book.UpdateImgMetdataAttributesToMatchImage() Warning: img has no or empty src attribute");
                //Debug.Fail(" (Debug only) img has no or empty src attribute");
                return; // they have bigger problems, which aren't appropriate to deal with here.
            }

            if (metadata == null)
            {
                // The fileName might be URL encoded.  See https://silbloom.myjetbrains.com/youtrack/issue/BL-3901.
                var path = UrlPathString.GetFullyDecodedPath(folderPath, ref fileName);
                progress.WriteStatus("Reading metadata from " + fileName);
                if (!RobustFile.Exists(path)) // they have bigger problems, which aren't appropriate to deal with here.
                {
                    imgElement.RemoveAttribute("data-copyright");
                    imgElement.RemoveAttribute("data-creator");
                    imgElement.RemoveAttribute("data-license");
                    Logger.WriteEvent("Book.UpdateImgMetdataAttributesToMatchImage()  Image " + path + " is missing");
                    //Debug.Fail(" (Debug only) Image " + path + " is missing");
                    return;
                }
                metadata = RobustIO.MetadataFromFile(path);
            }

            progress.WriteStatus("Writing metadata to HTML for " + fileName);

            imgElement.SetAttribute("data-copyright",
                             String.IsNullOrEmpty(metadata.CopyrightNotice) ? "" : metadata.CopyrightNotice);
            imgElement.SetAttribute("data-creator", String.IsNullOrEmpty(metadata.Creator) ? "" : metadata.Creator);
            imgElement.SetAttribute("data-license", metadata.License == null ? "" : metadata.License.ToString());
        }
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:43,代码来源:ImageUpdater.cs

示例14: BringBookUpToDate

        private void BringBookUpToDate(HtmlDom bookDOM /* may be a 'preview' version*/, IProgress progress)
        {
            progress.WriteStatus("Gathering Data...");

            //by default, this comes from the collection, but the book can select one, including "null" to select the factory-supplied empty xmatter
            var nameOfXMatterPack = OurHtmlDom.GetMetaValue("xMatter", _collectionSettings.XMatterPackName);

            var helper = new XMatterHelper(bookDOM, nameOfXMatterPack, _storage.GetFileLocator());
            XMatterHelper.RemoveExistingXMatter(bookDOM);
            Layout layout = Layout.FromDom(bookDOM, Layout.A5Portrait);			//enhance... this is currently just for the whole book. would be better page-by-page, somehow...
            progress.WriteStatus("Injecting XMatter...");

            helper.InjectXMatter(_bookData.GetWritingSystemCodes(), layout);
            TranslationGroupManager.PrepareElementsInPageOrDocument(bookDOM.RawDom, _collectionSettings);
            progress.WriteStatus("Updating Data...");

            //hack
            if(bookDOM == OurHtmlDom)//we already have a data for this
            {
                _bookData.SynchronizeDataItemsThroughoutDOM();

                // I think we should only mess with tags if we are updating the book for real.
                var oldTagsPath = Path.Combine(_storage.FolderPath, "tags.txt");
                if (File.Exists(oldTagsPath))
                {
                    ConvertTagsToMetaData(oldTagsPath, BookInfo);
                    File.Delete(oldTagsPath);
                }
            }
            else //used for making a preview dom
            {
                var bd = new BookData(bookDOM, _collectionSettings, UpdateImageMetadataAttributes);
                bd.SynchronizeDataItemsThroughoutDOM();
            }

            bookDOM.RemoveMetaElement("bloomBookLineage", () => BookInfo.BookLineage, val => BookInfo.BookLineage = val);
            bookDOM.RemoveMetaElement("bookLineage", () => BookInfo.BookLineage, val => BookInfo.BookLineage = val);
            // BookInfo will always have an ID, the constructor makes one even if there is no json file.
            // To allow migration, pretend it has no ID if there is not yet a meta.json.
            bookDOM.RemoveMetaElement("bloomBookId", () => (File.Exists(BookInfo.MetaDataPath) ? BookInfo.Id : null), val => BookInfo.Id = val);

            // Title should be replicated in json
            //if (!string.IsNullOrWhiteSpace(Title)) // check just in case we somehow have more useful info in json.
            //    bookDOM.Title = Title;
            // Bit of a kludge, but there's no way to tell whether a boolean is already set in the JSON, so we fake that it is not,
            // thus ensuring that if something is in the metadata we use it.
            bookDOM.RemoveMetaElement("SuitableForMakingShells", () => null, val => BookInfo.IsSuitableForMakingShells = val == "yes" || val == "definitely");
            // If there is nothing there the default of true will survive.
            bookDOM.RemoveMetaElement("SuitableForMakingVernacularBooks", () => null, val => BookInfo.IsSuitableForVernacularLibrary = val == "yes" || val == "definitely");
        }
开发者ID:jorik041,项目名称:BloomDesktop,代码行数:50,代码来源:Book.cs

示例15: BringBookUpToDate

        private void BringBookUpToDate(HtmlDom bookDOM /* may be a 'preview' version*/, IProgress progress)
        {
            progress.WriteStatus("Gathering Data...");

            //by default, this comes from the collection, but the book can select one, inlucing "null" to select the factory-supplied empty xmatter
            var nameOfXMatterPack = OurHtmlDom.GetMetaValue("xMatter", _collectionSettings.XMatterPackName);

            var helper = new XMatterHelper(bookDOM, nameOfXMatterPack, _storage.GetFileLocator());
            XMatterHelper.RemoveExistingXMatter(bookDOM);
            Layout layout = Layout.FromDom(bookDOM, Layout.A5Portrait);			//enhance... this is currently just for the whole book. would be better page-by-page, somehow...
            progress.WriteStatus("Injecting XMatter...");

            helper.InjectXMatter(_bookData.GetWritingSystemCodes(), layout);
            TranslationGroupManager.PrepareElementsInPageOrDocument(bookDOM.RawDom, _collectionSettings);
            progress.WriteStatus("Updating Data...");

            //hack
            if(bookDOM == OurHtmlDom)//we already have a data for this
            {
                _bookData.SynchronizeDataItemsThroughoutDOM();
            }
            else //used for making a preview dom
            {
                var bd = new BookData(bookDOM, _collectionSettings, UpdateImageMetadataAttributes);
                bd.SynchronizeDataItemsThroughoutDOM();
            }

            bookDOM.RenameMetaElement("bookLineage", "bloomBookLineage");
        }
开发者ID:JohnThomson,项目名称:testBloom,代码行数:29,代码来源:Book.cs


注:本文中的IProgress.WriteStatus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。