internal static void BuildReport(Library library, List <PDFDocument> pdf_documents) { FeatureTrackingManager.Instance.UseFeature(Features.Library_JSONAnnotationReport); AnnotationReportOptions annotation_report_options = new AnnotationReportOptions(); List <AnnotationWorkGenerator.AnnotationWork> annotation_works = AnnotationWorkGenerator.GenerateAnnotationWorks(library, pdf_documents, annotation_report_options); IEnumerable <AnnotationJSON> annotation_jsons = annotation_works.Select(annotation_work => new AnnotationJSON { fingerprint = annotation_work.pdf_document.Fingerprint, title = annotation_work.pdf_document.TitleCombined, page = annotation_work.pdf_annotation.Page, left = annotation_work.pdf_annotation.Left, top = annotation_work.pdf_annotation.Top, width = annotation_work.pdf_annotation.Width, height = annotation_work.pdf_annotation.Height, tags = annotation_work.pdf_annotation.Tags, text = annotation_work.pdf_annotation.Text, } ); string json = JsonConvert.SerializeObject(annotation_jsons, Formatting.Indented); string filename = Path.GetTempFileName() + ".json.txt"; File.WriteAllText(filename, json); Process.Start(filename); }
public void WriteMasterList() { Logging.Info("+WriteMasterList"); string filename_temp = Path.GetTempFileName(); Utilities.LockPerfTimer l1_clk = Utilities.LockPerfChecker.Start(); lock (locker) { l1_clk.LockPerfTimerStop(); FlushAllWords_LOCK(); PurgeAllWords_LOCK(); using (FileStream fs = File.Open(filename_temp, FileMode.Create)) { Headers headers = new Headers(); // First the documents { headers.documents = new List <DocumentMapHeader>(); foreach (var pair in fingerprint_to_document_ids) { DocumentMapHeader header = new DocumentMapHeader { Fingerprint = pair.Key, DocumentId = pair.Value }; headers.documents.Add(header); } } // Then the words { headers.words = new List <WordMapHeader>(); foreach (WordInWordIndex word_in_word_index in word_in_word_indexes) { WordMapHeader header = new WordMapHeader { Word = word_in_word_index.Word, WordId = word_in_word_index.WordId, DocCount = word_in_word_index.DocumentCount }; headers.words.Add(header); } } Serializer.Serialize <Headers>(fs, headers); } } Logging.Info("-WriteMasterList"); // Move the temp file over the library filename Directory.CreateDirectory(Path.GetDirectoryName(GetFilename_MasterList())); FileTools.MoveSafelyWithOverwriting(filename_temp, GetFilename_MasterList()); // Write the version of the index File.WriteAllText(VersionFilename, INDEX_VERSION); }
internal static void BuildReport(WebLibraryDetail web_library_detail, List <PDFDocument> pdf_documents) { WPFDoEvents.AssertThisCodeIs_NOT_RunningInTheUIThread(); FeatureTrackingManager.Instance.UseFeature(Features.Library_LinkedDocsAnnotationReport); StringBuilder sb_o2o = new StringBuilder(); StringBuilder sb_o2m = new StringBuilder(); foreach (var pdf_document in pdf_documents) { var citations = pdf_document.PDFDocumentCitationManager.GetLinkedDocuments(); if (null == citations || 0 == citations.Count) { continue; } // o2m { sb_o2m.AppendFormat("{0}", pdf_document.Fingerprint); sb_o2m.AppendFormat(","); foreach (var citation in citations) { sb_o2m.AppendFormat("{0}", citation.fingerprint_outbound); sb_o2m.AppendFormat(","); } sb_o2m.AppendLine(); } // o2o { foreach (var citation in citations) { sb_o2o.AppendFormat("{0}", pdf_document.Fingerprint); sb_o2o.AppendFormat(","); sb_o2o.AppendFormat("{0}", citation.fingerprint_inbound); sb_o2o.AppendLine(); } } } string filename_o2o = Path.GetTempFileName() + ".o2o.txt"; string filename_o2m = Path.GetTempFileName() + ".o2m.txt"; File.WriteAllText(filename_o2o, sb_o2o.ToString()); File.WriteAllText(filename_o2m, sb_o2m.ToString()); Process.Start(filename_o2o); Process.Start(filename_o2m); }
internal static void Install(BundleLibraryManifest manifest, byte[] library_bundle_binary) { string temp_filename = Path.GetTempFileName(); try { File.WriteAllBytes(temp_filename, library_bundle_binary); Install(manifest, temp_filename); } finally { try { File.Delete(temp_filename); } catch (Exception ex) { Logging.Error(ex, "There was a problem deleting the temporary library bundle file."); } } }
/// <summary> /// Flushes the record for the keyword (and its entire gang) out to disk. You must call this from inside a lock. /// </summary> /// <param name="wiwi"></param> /// <param name="create_directory_first"></param> private void FlushKeyword_LOCK(WordInWordIndex wiwi, bool create_directory_first) { // If this is not loaded, there is nothing to do if (!wiwi.IsLoaded) { return; } // If this one doesnt need flushing, don't do it if (!wiwi.needs_flushing) { return; } try { // Build up the gangs int gang_start = GangStart(wiwi.WordId); List <WordEntry> word_entrys = new List <WordEntry>(); string filename_temp = Path.GetTempFileName(); using (FileStream fs = File.Open(filename_temp, FileMode.Create)) { { for (int i = 0; i < GANG_SIZE; ++i) { // If this is the last gang, there may be too few words if (word_in_word_indexes.Count <= gang_start + i) { break; } if (null == word_in_word_indexes[gang_start + i].DocumentIds) { throw new Exception("Document ids should not be null"); } WordEntry word_entry = new WordEntry { Word = word_in_word_indexes[gang_start + i].Word, DocumentIds = word_in_word_indexes[gang_start + i].DocumentIds, DocumentIdsCount = word_in_word_indexes[gang_start + i].DocumentIdsCount }; word_entrys.Add(word_entry); } Serializer.Serialize <List <WordEntry> >(fs, word_entrys); } } // Move the temp file into place string filename = Filename_GangList(wiwi.WordId); // Create the directory for the file if (create_directory_first) { Directory.CreateDirectory(Path.GetDirectoryName(filename)); } FileTools.MoveSafelyWithOverwriting(filename_temp, filename); // Mark the gang as flushed for (int i = 0; i < GANG_SIZE; ++i) { // If this is the last gang, there may be too few words if (word_in_word_indexes.Count <= gang_start + i) { break; } word_in_word_indexes[gang_start + i].last_flushed = DateTime.UtcNow; word_in_word_indexes[gang_start + i].needs_flushing = false; } } catch (Exception ex) { // If we have an exception, it is probably because we have not created the directory, so try that if (!create_directory_first) { FlushKeyword_LOCK(wiwi, true); } else { // If we have created the directory before, then there must be some other problem throw ex; } } }
public override string GetTempFileName() { return(AfsPath.GetTempFileName()); }