// POST: /KnowledgeItems /// <summary> /// Support for creating knowledge item /// </summary> public async Task <IActionResult> Post([FromBody] KnowledgeItem knowledge) { if (!ModelState.IsValid) { foreach (var value in ModelState.Values) { foreach (var err in value.Errors) { System.Diagnostics.Debug.WriteLine(err.Exception?.Message); } } return(BadRequest(ModelState)); } String usrId = ControllerUtil.GetUserID(this); if (String.IsNullOrEmpty(usrId)) { return(new UnauthorizedResult()); } knowledge.CreatedAt = DateTime.Now; _context.KnowledgeItems.Add(knowledge); await _context.SaveChangesAsync(); return(Created(knowledge)); }
public static void ExportQuickReferenceAsBookmark(Annotation annotation, Document document) { KnowledgeItem quickReference = (KnowledgeItem)annotation.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).FirstOrDefault().Source; string bookmarkTitle = quickReference.CoreStatement; pdftron.PDF.Bookmark bookmark = pdftron.PDF.Bookmark.Create(document, bookmarkTitle); Quad firstQuad = annotation.Quads.FirstOrDefault(); int page = firstQuad.PageIndex; double left = firstQuad.MinX; double top = firstQuad.MaxY; Destination destination = Destination.CreateXYZ(document.GetPage(page), left, top, 0); pdftron.PDF.Bookmark foo = document.GetFirstBookmark().Find(bookmarkTitle); if (foo.IsValid() && foo.GetAction().GetDest().GetPage().GetIndex() == page) { foo.SetAction(pdftron.PDF.Action.CreateGoto(destination)); return; } document.AddRootBookmark(bookmark); bookmark.SetAction(pdftron.PDF.Action.CreateGoto(destination)); }
// PUT: /KnowledgeItems(5) /// <summary> /// Support for updating Knowledge items /// </summary> public async Task <IActionResult> Put([FromODataUri] int key, [FromBody] KnowledgeItem update) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (key != update.ID) { return(NotFound()); } String usrId = ControllerUtil.GetUserID(this); if (String.IsNullOrEmpty(usrId)) { return(new UnauthorizedResult()); } var isexist = await _context.KnowledgeItems.Where(p => p.ID == key).CountAsync(); if (isexist <= 0) { return(NotFound()); } update.ModifiedAt = DateTime.Now; _context.Entry(update).State = EntityState.Modified; //knowitem.UpdateData(update); var tagsindb = _context.KnowledgeTags.Where(p => p.RefID == update.ID).AsNoTracking().ToList(); foreach (var ditem in update.Tags) { var itemindb = tagsindb.Find(p => p.TagTerm == ditem.TagTerm); if (itemindb == null) { _context.KnowledgeTags.Add(ditem); } } foreach (var ditem in tagsindb) { var nitem = update.Tags.FirstOrDefault(p => p.TagTerm == ditem.TagTerm); if (nitem == null) { _context.KnowledgeTags.Remove(ditem); } } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(Updated(update)); }
void QuotationSmartRepeater_ActiveListItemChanged(object o, EventArgs a) { if (Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().Count == 0) { return; } KnowledgeItem activeQuotation = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().FirstOrDefault(); if (activeQuotation.EntityLinks == null) { return; } if (activeQuotation.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() == 0) { return; } Annotation annotation = activeQuotation.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).FirstOrDefault().Target as Annotation; PreviewControl previewControl = PreviewMethods.GetPreviewControl(); if (previewControl == null) { return; } SwissAcademic.Citavi.Controls.Wpf.PdfViewControl pdfViewControl = previewControl.GetPdfViewControl(); if (pdfViewControl == null) { return; } pdfViewControl.GoToAnnotation(annotation); }
public static void MergeQuotations(List <KnowledgeItem> quotations) { // Static Variables Project project = Program.ActiveProjectShell.Project; if (project == null) { return; } Reference reference = quotations.FirstOrDefault().Reference; if (reference == null) { return; } List <Annotation> annotations = quotations.Where ( q => q.EntityLinks.Any() && q.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication && e.Target is Annotation).Count() > 0 ) .Select ( q => ((Annotation) q.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication && e.Target is Annotation).FirstOrDefault().Target) ) .ToList(); // The Magic List <QuotationType> quotationTypes = quotations.Select(q => q.QuotationType).Distinct().ToList(); var itemToRemove = quotationTypes.SingleOrDefault(q => q == QuotationType.Highlight); quotationTypes.Remove(itemToRemove); if (quotationTypes.Count > 1) { MessageBox.Show("Can't merge quotations, more than one type of quotation is selected."); return; } KnowledgeItem newQuotation = CombineQuotations(quotations); Annotation newAnnotation = CombineAnnotations(annotations); EntityLink newEntityLink = new EntityLink(project); newEntityLink.Source = newQuotation; newEntityLink.Target = newAnnotation; newEntityLink.Indication = EntityLink.PdfKnowledgeItemIndication; project.EntityLinks.Add(newEntityLink); reference.Quotations.RemoveRange(quotations); Program.ActiveProjectShell.ShowKnowledgeItemFormForExistingItem(Program.ActiveProjectShell.PrimaryMainForm, newQuotation); }
public async Task TestCase2() { var context = this.fixture.GetCurrentDataContext(); KnowledgeItemsController control = new KnowledgeItemsController(context); var dbkis = context.KnowledgeItems.ToList <KnowledgeItem>(); if (dbkis.Count <= 0) { var ki = new KnowledgeItem() { Category = KnowledgeItemCategory.Concept, Title = "Test 1", Content = "Test 1 Content", }; var rst = await control.Post(ki); Assert.NotNull(rst); var rst2 = Assert.IsType <CreatedODataResult <KnowledgeItem> >(rst); Assert.Equal(rst2.Entity.Title, ki.Title); Assert.Equal(rst2.Entity.Content, ki.Content); var firstid = rst2.Entity.ID; Assert.True(firstid > 0); objectsCreated.Add(firstid); } // Step 1. Read it again via OData way var httpContext = new DefaultHttpContext(); // or mock a `HttpContext` httpContext.Request.Path = "/api/KnowledgeItems"; httpContext.Request.QueryString = new QueryString("?$select=ID,Title"); httpContext.Request.Method = "GET"; var routeData = new RouteData(); routeData.Values.Add("odataPath", "KnowledgeItems"); routeData.Values.Add("action", "GET"); // Controller needs a controller context var controllerContext = new ControllerContext() { RouteData = routeData, HttpContext = httpContext, }; // Assign context to controller control = new KnowledgeItemsController(context) { ControllerContext = controllerContext, }; var rstOdata = control.Get(); Assert.NotNull(rstOdata); var rstOdata2 = (from dt in rstOdata select dt).ToList(); await context.DisposeAsync(); }
static void MoveToBottom(this CategoryKnowledgeItemCollection knowledgeItemCollection, KnowledgeItem knowledgeItem) { if (knowledgeItemCollection == null || knowledgeItemCollection.Count <= 1) { return; } KnowledgeItem lastKnowledgeItem = knowledgeItemCollection.Last <KnowledgeItem>(); knowledgeItemCollection.Move(knowledgeItem, lastKnowledgeItem); }
public static void LinkQuotations(List <KnowledgeItem> quotations) { Control quotationSmartRepeater = Program.ActiveProjectShell.PrimaryMainForm.Controls.Find("quotationSmartRepeater", true).FirstOrDefault(); SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater quotationSmartRepeaterAsQuotationSmartRepeater = quotationSmartRepeater as SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater; List <KnowledgeItem> quotesOrSummaries = quotations.Where(q => q.QuotationType == QuotationType.DirectQuotation || q.QuotationType == QuotationType.IndirectQuotation || q.QuotationType == QuotationType.Summary).ToList(); List <KnowledgeItem> comments = quotations.Where(q => q.QuotationType == QuotationType.Comment).ToList(); if (quotesOrSummaries.Count != 1 || comments.Count != 1) { MessageBox.Show("Please select exactly one direct or indirect quote or summary and exactly one comment.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Project project = Program.ActiveProjectShell.Project; if (project == null) { return; } KnowledgeItem comment = comments.FirstOrDefault(); KnowledgeItem quoteOrSummary = quotesOrSummaries.FirstOrDefault(); if (comment.EntityLinks.Where(e => e.Indication == EntityLink.CommentOnQuotationIndication).Count() > 0) { DialogResult dialogResult = MessageBox.Show("The selected comment is already linked to a knowledge item. Do you want to reset the comment's core statement?", "Comment Already Linked", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { comment.CoreStatement = ((KnowledgeItem)comment.EntityLinks.Where(e => e.Indication == EntityLink.CommentOnQuotationIndication).FirstOrDefault().Target).CoreStatement + " (Comment)"; } else if (dialogResult == DialogResult.No) { quotationSmartRepeaterAsQuotationSmartRepeater.SelectAndActivate((KnowledgeItem)comment.EntityLinks.Where(e => e.Indication == EntityLink.CommentOnQuotationIndication).FirstOrDefault().Target, true); } return; } EntityLink commentDirectQuoteLink = new EntityLink(project); commentDirectQuoteLink.Source = comment; commentDirectQuoteLink.Target = quoteOrSummary; commentDirectQuoteLink.Indication = EntityLink.CommentOnQuotationIndication; project.EntityLinks.Add(commentDirectQuoteLink); comment.CoreStatement = quoteOrSummary.CoreStatement + " (Comment)"; return; }
void KnowledgeItemPreviewSmartRepeater_ActiveListItemChanged(object o, EventArgs a) { if (Program.ActiveProjectShell.PrimaryMainForm.GetSelectedKnowledgeItems().Count == 0) { return; } KnowledgeItem activeQuotation = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedKnowledgeItems().FirstOrDefault(); if (activeQuotation.EntityLinks == null) { return; } if (activeQuotation.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() == 0) { return; } Annotation annotation = activeQuotation.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).FirstOrDefault().Target as Annotation; PreviewControl previewControl = PreviewMethods.GetPreviewControl(); if (previewControl == null) { return; } PdfViewControl pdfViewControl = previewControl.GetPdfViewControl(); if (pdfViewControl == null) { return; } Document document = pdfViewControl.Document; if (document == null) { return; } if (previewControl.ActiveLocation != annotation.Location) { Program.ActiveProjectShell.ShowPreviewFullScreenForm(annotation.Location, previewControl, null); } pdfViewControl.GoToAnnotation(annotation); Program.ActiveProjectShell.PrimaryMainForm.Activate(); }
public static void LinkWithKnowledgeItemIndicationAnnotation(this KnowledgeItem quotation, Annotation annotation) { Project project = Program.ActiveProjectShell.Project; if (project == null) { return; } EntityLink newEntityLink = new EntityLink(project); newEntityLink.Indication = EntityLink.PdfKnowledgeItemIndication; newEntityLink.Source = quotation; newEntityLink.Target = annotation; project.EntityLinks.Add(newEntityLink); }
public static KnowledgeItem CreateNewQuickReferenceFromAnnotationContent(this TextContent textContent, string pageRangeString, Reference reference, QuotationType quotationType) { Project project = Program.ActiveProjectShell.Project; if (project == null) { return(null); } KnowledgeItem newQuotation = new KnowledgeItem(reference, quotationType); newQuotation.CoreStatement = textContent.Text; newQuotation.PageRange = pageRangeString; return(newQuotation); }
public static KnowledgeItem CreateNewQuotationFromHighlightContents(this string highlightContents, string pageRangeString, Reference reference, QuotationType quotationType) { Project project = Program.ActiveProjectShell.Project; if (project == null) { return(null); } KnowledgeItem newQuotation = new KnowledgeItem(reference, quotationType); newQuotation.Text = highlightContents; newQuotation.PageRange = pageRangeString; return(newQuotation); }
/// <summary> /// /// </summary> public List <KnowledgeItem> ToKnowledgeItems() { List <KnowledgeItem> list = new List <KnowledgeItem>(); foreach (KeyValuePair <RelationKey, List <Relationship> > item in _knowledge) { foreach (Relationship r in item.Value) { if (!r.IsWildcard) { KnowledgeItem ki = new KnowledgeItem(r.ID); foreach (SetItem si in r.Set) { ki.Set.Add(string.Format("{0}", si.Value)); } list.Add(ki); } } } return(list); }
// POST: /KnowledgeItems /// <summary> /// Support for creating knowledge item /// </summary> public async Task <IActionResult> Post([FromBody] KnowledgeItem knowledge) { if (!ModelState.IsValid) { foreach (var value in ModelState.Values) { foreach (var err in value.Errors) { System.Diagnostics.Debug.WriteLine(err.Exception?.Message); } } return(BadRequest()); } knowledge.CreatedAt = DateTime.Now; _context.KnowledgeItems.Add(knowledge); await _context.SaveChangesAsync(); return(Created(knowledge)); }
static KnowledgeItem FindKnowledgeItem(this IEnumerable <KnowledgeItem> knowledgeItemCollection, KnowledgeItem knowledgeItem) { if (knowledgeItem == null) { return(null); } if (knowledgeItem.StaticIds == null || !knowledgeItem.StaticIds.Any()) { return(null); } if (knowledgeItemCollection == null || !knowledgeItemCollection.Any()) { return(null); } foreach (KnowledgeItem item in knowledgeItemCollection) { if (item.StaticIds == null || !item.StaticIds.Any()) { continue; } if (item.StaticIds.Intersect(knowledgeItem.StaticIds).Any()) { return(item); } } //still here, try full path return(null); }
public async Task TestCase_CRUD() { var context = fixture.GetCurrentDataContext(); KnowledgeItemsController control = new KnowledgeItemsController(context); var userclaim = DataSetupUtility.GetClaimForUser(DataSetupUtility.UserA); control.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = userclaim } }; // Step 1. Read all - 0 var rsts = control.Get(); var rstscnt = await rsts.CountAsync(); var existcnt = context.KnowledgeItems.Count(); Assert.Equal(existcnt, rstscnt); // Step 2. Create one know ledge item var ki = new KnowledgeItem() { Category = KnowledgeItemCategory.Concept, Title = "New Test 1", Content = "New Test 1 Content", }; var rst = await control.Post(ki); Assert.NotNull(rst); var rst2 = Assert.IsType <CreatedODataResult <KnowledgeItem> >(rst); Assert.Equal(rst2.Entity.Title, ki.Title); Assert.Equal(rst2.Entity.Content, ki.Content); var firstid = rst2.Entity.ID; Assert.True(firstid > 0); objectsCreated.Add(firstid); // Step 3. Read all - 1 rsts = control.Get(); rstscnt = await rsts.CountAsync(); Assert.Equal(existcnt + 1, rstscnt); // Step 3a. Read single var getrst = control.Get(firstid); Assert.NotNull(getrst); var getrstresult = Assert.IsType <SingleResult <KnowledgeItem> >(getrst); var readitem = getrstresult.Queryable.ToList().ElementAtOrDefault(0); Assert.NotNull(readitem); Assert.Equal(firstid, readitem.ID); Assert.Equal(ki.Category, readitem.Category); Assert.Equal(ki.Title, readitem.Title); Assert.Equal(ki.Content, readitem.Content); // Step 4. Change the exist one by Put readitem.Content += "Updated by PUT"; if (readitem.Tags == null) { readitem.Tags = new List <KnowledgeTag>(); } readitem.Tags.Add(new KnowledgeTag { RefID = firstid, TagTerm = DataSetupUtility.Tag1 }); var rstPut = await control.Put(firstid, readitem); Assert.NotNull(rstPut); // Due to the fact that updated result is empty // Check the result in database directly var dbkis = context.KnowledgeItems.Where(p => p.ID == firstid).ToList <KnowledgeItem>(); Assert.NotEmpty(dbkis); Assert.Equal(readitem.Content, dbkis[0].Content); // Check content only! // Check the tags view var tagcontrol = new KnowledgeTagsController(context); var tagsread = tagcontrol.Get(); Assert.NotNull(tagsread); var tagsreadresult = tagsread.ToList(); var findtag = tagsreadresult.Find(p => p.RefID == firstid && p.TagTerm == DataSetupUtility.Tag1); Assert.NotNull(findtag); // Step 5. PATCH . var delta = new Delta <KnowledgeItem>(); delta.UpdatableProperties.Clear(); delta.UpdatableProperties.Add("Content"); readitem.Content += "Changed for PATCH"; delta.TrySetPropertyValue("Content", readitem.Content); var patchresult = await control.Patch(firstid, delta); Assert.NotNull(patchresult); dbkis = context.KnowledgeItems.Where(p => p.ID == firstid).ToList <KnowledgeItem>(); Assert.NotEmpty(dbkis); Assert.Equal(readitem.Content, dbkis[0].Content); // Check content only! // Step 5. Delete rst = await control.Delete(firstid); Assert.NotNull(rst); this.objectsCreated.Remove(firstid); rsts = control.Get(); rstscnt = await rsts.CountAsync(); Assert.Equal(existcnt, rstscnt); await context.DisposeAsync(); }
public static void CreateCommentOnQuotation(List <KnowledgeItem> quotations) { Control quotationSmartRepeater = Program.ActiveProjectShell.PrimaryMainForm.Controls.Find("quotationSmartRepeater", true).FirstOrDefault(); SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater quotationSmartRepeaterAsQuotationSmartRepeater = quotationSmartRepeater as SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater; PreviewControl previewControl = Program.ActiveProjectShell.PrimaryMainForm.PreviewControl; if (previewControl == null) { return; } PdfViewControl pdfViewControl = previewControl.GetPdfViewControl(); if (pdfViewControl == null) { return; } Annotation lastAnnotation = null; KnowledgeItem lastComment = null; foreach (KnowledgeItem quotation in quotations) { Reference reference = quotation.Reference; if (reference == null) { return; } Project project = reference.Project; if (project == null) { return; } Annotation mainQuotationAnnotation = quotation.EntityLinks.Where(link => link.Target is Annotation).FirstOrDefault().Target as Annotation; if (mainQuotationAnnotation == null) { return; } Location location = mainQuotationAnnotation.Location; if (location == null) { return; } KnowledgeItem comment = new KnowledgeItem(reference, QuotationType.Comment); comment.PageRange = quotation.PageRange; comment.PageRange.Update(quotation.PageRange.NumberingType); comment.PageRange.Update(quotation.PageRange.NumeralSystem); comment.CoreStatement = quotation.CoreStatement + " (Comment)"; comment.CoreStatementUpdateType = UpdateType.Manual; reference.Quotations.Add(comment); EntityLink commentQuotationLink = new EntityLink(project); commentQuotationLink.Source = comment; commentQuotationLink.Target = quotation; commentQuotationLink.Indication = EntityLink.CommentOnQuotationIndication; project.EntityLinks.Add(commentQuotationLink); Annotation newAnnotation = new Annotation(location); newAnnotation.OriginalColor = System.Drawing.Color.FromArgb(255, 255, 255, 0); newAnnotation.Quads = mainQuotationAnnotation.Quads; newAnnotation.Visible = false; location.Annotations.Add(newAnnotation); EntityLink commentAnnotationLink = new EntityLink(project); commentAnnotationLink.Source = comment; commentAnnotationLink.Target = newAnnotation; commentAnnotationLink.Indication = EntityLink.PdfKnowledgeItemIndication; project.EntityLinks.Add(commentAnnotationLink); lastComment = comment; lastAnnotation = newAnnotation; } quotationSmartRepeaterAsQuotationSmartRepeater.SelectAndActivate(lastComment, true); pdfViewControl.GoToAnnotation(lastAnnotation); Program.ActiveProjectShell.ShowKnowledgeItemFormForExistingItem(Program.ActiveProjectShell.PrimaryMainForm, lastComment); }
protected override void OnBeforePerformingCommand(SwissAcademic.Controls.BeforePerformingCommandEventArgs e) { switch (e.Key) { #region Annotation-based menus case "ImportComments": { e.Handled = true; Reference reference = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedReferences().FirstOrDefault(); AnnotationsImporter.AnnotationsImport(QuotationType.Comment); } break; case "ImportDirectQuotations": { e.Handled = true; Reference reference = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedReferences().FirstOrDefault(); AnnotationsImporter.AnnotationsImport(QuotationType.DirectQuotation); } break; case "ImportIndirectQuotations": { e.Handled = true; Reference reference = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedReferences().FirstOrDefault(); AnnotationsImporter.AnnotationsImport(QuotationType.IndirectQuotation); } break; case "ImportQuickReferences": { e.Handled = true; Reference reference = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedReferences().FirstOrDefault(); AnnotationsImporter.AnnotationsImport(QuotationType.QuickReference); } break; case "ImportSummaries": { e.Handled = true; Reference reference = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedReferences().FirstOrDefault(); AnnotationsImporter.AnnotationsImport(QuotationType.Summary); } break; case "MergeAnnotations": { e.Handled = true; AnnotationsAndQuotationsMerger.MergeAnnotations(); } break; case "SimplifyAnnotations": { e.Handled = true; AnnotationSimplifier.SimplifyAnnotations(); } break; #endregion #region Reference-based commands case "ExportAnnotations": { e.Handled = true; List <Reference> references = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedReferences().ToList(); AnnotationsExporter.ExportAnnotations(references); } break; case "ExportBookmarks": { e.Handled = true; List <Reference> references = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedReferences().ToList(); QuickReferenceBookmarkExporter.ExportBookmarks(references); } break; case "MoveAttachment": { e.Handled = true; LocationMover.MoveAttachment(); } break; #endregion #region Quotations Pop-Up Menu case "CleanQuotationsText": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); QuotationTextCleaner.CleanQuotationsText(quotations); } break; case "ConvertDirectQuoteToRedHighlight": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); QuotationTypeConverter.ConvertDirectQuoteToRedHighlight(quotations); } break; case "CreateCommentOnQuotation": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); CommentCreator.CreateCommentOnQuotation(quotations); } break; case "CreateSummaryOnQuotations": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); SummaryCreator.CreatesummaryOnQuotations(quotations); } break; case "KnowledgeItemsSortInReference": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); QuotationsSorter.SortQuotations(quotations); } break; case "CommentAnnotation": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); CommentAnnotationCreator.CreateCommentAnnotation(quotations); } break; case "LinkQuotations": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); QuotationLinker.LinkQuotations(quotations); } break; case "PageAssignFromPositionInPDF": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); PageRangeFromPositionInPDFAssigner.AssignPageRangeFromPositionInPDF(quotations); } break; case "PageAssignFromPreviousQuotation": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); PageRangeFromPrecedingQuotationAssigner.AssignPageRangeFromPrecedingQuotation(quotations); } break; case "QuotationsMerge": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); AnnotationsAndQuotationsMerger.MergeQuotations(quotations); } break; case "QuickReferenceTitleCase": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); QuickReferenceTitleCaser.TitleCaseQuickReference(quotations); } break; case "ShowQuotationAndSetPageRangeManually": { e.Handled = true; List <KnowledgeItem> quotations = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedQuotations().ToList(); PageRangeManualAssigner.AssignPageRangeManuallyAfterShowingAnnotation(); } break; #endregion #region ReferenceEditorUriLocationsPopupMenu #endregion #region KnowledgeOrganizerKnowledgeItemsContextMenu case "OpenKnowledgeItemAttachment": { e.Handled = true; MainForm mainForm = Program.ActiveProjectShell.PrimaryMainForm; if (mainForm.ActiveWorkspace == MainFormWorkspace.KnowledgeOrganizer) { KnowledgeItem knowledgeItem = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedKnowledgeItems().FirstOrDefault(); if (knowledgeItem.EntityLinks.FirstOrDefault() == null) { break; } Annotation annotation = knowledgeItem.EntityLinks.FirstOrDefault().Target as Annotation; if (annotation == null) { break; } Location location = annotation.Location; SwissAcademic.Citavi.Shell.Controls.Preview.PreviewControl previewControl = Program.ActiveProjectShell.PrimaryMainForm.PreviewControl; Program.ActiveProjectShell.ShowPreviewFullScreenForm(location, previewControl, null); } } break; case "SelectLinkedKnowledgeItem": { e.Handled = true; MainForm mainForm = Program.ActiveProjectShell.PrimaryMainForm; KnowledgeItem target; KnowledgeItem knowledgeItem; if (mainForm.ActiveWorkspace == MainFormWorkspace.ReferenceEditor) { knowledgeItem = mainForm.GetSelectedQuotations().FirstOrDefault(); } else if (mainForm.ActiveWorkspace == MainFormWorkspace.KnowledgeOrganizer) { knowledgeItem = mainForm.ActiveKnowledgeItem; } else { return; } if (knowledgeItem == null) { return; } if (knowledgeItem.EntityLinks.Where(el => el.Indication == EntityLink.CommentOnQuotationIndication).Count() == 0) { return; } if (knowledgeItem.QuotationType == QuotationType.Comment) { target = knowledgeItem.EntityLinks.ToList().Where(n => n != null && n.Indication == EntityLink.CommentOnQuotationIndication && n.Target as KnowledgeItem != null).ToList().FirstOrDefault().Target as KnowledgeItem; } else { target = knowledgeItem.EntityLinks.ToList().Where(n => n != null && n.Indication == EntityLink.CommentOnQuotationIndication && n.Target as KnowledgeItem != null).ToList().FirstOrDefault().Source as KnowledgeItem; } if (target == null) { return; } if (mainForm.ActiveWorkspace == MainFormWorkspace.ReferenceEditor) { Control quotationSmartRepeater = Program.ActiveProjectShell.PrimaryMainForm.Controls.Find("quotationSmartRepeater", true).FirstOrDefault(); SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater quotationSmartRepeaterAsQuotationSmartRepeater = quotationSmartRepeater as SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater; Reference reference = target.Reference; if (reference == null) { return; } List <KnowledgeItem> quotations = reference.Quotations.ToList(); int index = quotations.FindIndex(q => q == target); quotationSmartRepeaterAsQuotationSmartRepeater.SelectAndActivate(quotations[index]); } else if (mainForm.ActiveWorkspace == MainFormWorkspace.KnowledgeOrganizer) { mainForm.ActiveKnowledgeItem = target; } else { return; } return; } case "SortKnowledgeItemsInSelection": { e.Handled = true; var mainForm = (MainForm)e.Form; if (mainForm.KnowledgeOrganizerFilterSet.Filters.Count() != 1 || mainForm.KnowledgeOrganizerFilterSet.Filters[0].Name == "Knowledge items without categories") { MessageBox.Show("You must select one category."); return; } KnowledgeItemInSelectionSorter.SortSelectedKnowledgeItems(mainForm); } break; case "SortKnowledgeItemsInCategory": { e.Handled = true; var mainForm = (MainForm)e.Form; if (mainForm.KnowledgeOrganizerFilterSet.Filters.Count() != 1 || mainForm.KnowledgeOrganizerFilterSet.Filters[0].Name == "Knowledge items without categories") { MessageBox.Show("You must select one category."); return; } KnowledgeItemInCategorySorter.SortKnowledgeItemsInCategorySorter(mainForm); } break; #endregion } base.OnBeforePerformingCommand(e); }
public static void CreatesummaryOnQuotations(List <KnowledgeItem> quotations) { Reference reference = Program.ActiveProjectShell.PrimaryMainForm.ActiveReference; if (reference == null) { return; } Project project = reference.Project; if (project == null) { return; } PreviewControl previewControl = Program.ActiveProjectShell.PrimaryMainForm.PreviewControl; if (previewControl == null) { return; } PdfViewControl pdfViewControl = previewControl.GetPdfViewControl(); if (pdfViewControl == null) { return; } Document document = pdfViewControl.Document; if (document == null) { return; } Location location = reference.Locations.Where ( l => l.LocationType == LocationType.ElectronicAddress && l.Address.Resolve().LocalPath.EndsWith(".pdf") && l.Address.Resolve().LocalPath == document.GetFileName() ) .FirstOrDefault(); if (location == null) { return; } Control quotationSmartRepeater = Program.ActiveProjectShell.PrimaryMainForm.Controls.Find("quotationSmartRepeater", true).FirstOrDefault(); SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater quotationSmartRepeaterAsQuotationSmartRepeater = quotationSmartRepeater as SwissAcademic.Citavi.Shell.Controls.SmartRepeaters.QuotationSmartRepeater; List <PageRange> pageRanges = new List <PageRange>(); List <Quad> quads = new List <Quad>(); Annotation newAnnotation = new Annotation(location); KnowledgeItem summary = new KnowledgeItem(reference, QuotationType.Summary); reference.Quotations.Add(summary); foreach (KnowledgeItem quotation in quotations) { pageRanges.Add(quotation.PageRange); EntityLink summaryQuotationLink = new EntityLink(project); summaryQuotationLink.Source = summary; summaryQuotationLink.Target = quotation; summaryQuotationLink.Indication = EntityLink.CommentOnQuotationIndication; project.EntityLinks.Add(summaryQuotationLink); Annotation quotationAnnotation = quotation.EntityLinks.Where(link => link.Target is Annotation).FirstOrDefault().Target as Annotation; if (quotationAnnotation == null) { continue; } quads.AddRange(quotationAnnotation.Quads); } newAnnotation.OriginalColor = System.Drawing.Color.FromArgb(255, 255, 255, 0); newAnnotation.Quads = quads; newAnnotation.Visible = false; location.Annotations.Add(newAnnotation); summary.PageRange = PageRangeMerger.PageRangeListToString(pageRanges); summary.CoreStatementUpdateType = UpdateType.Automatic; EntityLink summaryAnnotationLink = new EntityLink(project); summaryAnnotationLink.Source = summary; summaryAnnotationLink.Target = newAnnotation; summaryAnnotationLink.Indication = EntityLink.PdfKnowledgeItemIndication; project.EntityLinks.Add(summaryAnnotationLink); quotationSmartRepeaterAsQuotationSmartRepeater.SelectAndActivate(summary, true); pdfViewControl.GoToAnnotation(newAnnotation); }
public static bool UpdateExistingQuotation(this Highlight highlight, QuotationType quotationType, Location location) { // Static Variables Reference reference = location.Reference; List <Annotation> annotationsAtThisLocation = location.Annotations.ToList(); List <KnowledgeItem> quotations = reference.Quotations.Where(q => q.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() > 0).ToList(); List <KnowledgeItem> quotationsOfRelevantQuotationType = quotations.Where(q => q.QuotationType == quotationType && q.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() > 0).ToList(); List <KnowledgeItem> quotationsOfRelevantQuotationTypeAtThisLocation = quotationsOfRelevantQuotationType.Where(d => ((Annotation)d.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).ToList().FirstOrDefault().Target).Location == location).ToList(); List <Annotation> annotationsOfRelevantTypeAtThisLocation = quotationsOfRelevantQuotationTypeAtThisLocation.Select(d => (Annotation)d.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).ToList().FirstOrDefault().Target).ToList(); List <Annotation> equivalentAnnotationsWithQuotation = highlight.EquivalentAnnotations().Where(a => a.EntityLinks != null && a.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() > 0).ToList(); if (equivalentAnnotationsWithQuotation == null) { return(false); } Annotation existingAnnotation = equivalentAnnotationsWithQuotation.Intersect(annotationsOfRelevantTypeAtThisLocation).FirstOrDefault(); if (existingAnnotation == null) { return(false); } // Dynamic Variables string highlightContents = highlight.GetContents(); // The Magic if (!string.IsNullOrEmpty(highlightContents)) { if (existingAnnotation != null) { if (existingAnnotation.EntityLinks != null && existingAnnotation.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() > 0) { KnowledgeItem existingQuotation = (KnowledgeItem)existingAnnotation.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).FirstOrDefault().Source; switch (quotationType) { case QuotationType.QuickReference: existingQuotation.CoreStatement = highlightContents; break; default: existingQuotation.Text = highlightContents; break; } return(true); } } } else { return(true); } return(false); }
public static void AssignPageRangeFromPrecedingQuotation(List <KnowledgeItem> quotations) { Reference reference = quotations.FirstOrDefault().Reference; if (reference == null) { return; } List <KnowledgeItem> referenceQuotations = reference.Quotations.ToList(); if (referenceQuotations == null) { return; } var pdfLocations = reference.GetPDFLocations(); List <PageWidth> store = new List <PageWidth>(); if (pdfLocations != null) { foreach (Location location in pdfLocations) { Document document = null; var address = location.Address.Resolve().LocalPath; document = new Document(address); if (document != null) { for (int i = 1; i <= document.GetPageCount(); i++) { pdftron.PDF.Page page = document.GetPage(i); if (page.IsValid()) { var re = page.GetCropBox(); store.Add(new PageWidth(location, i, re.Width())); } else { store.Add(new PageWidth(location, i, 0.00)); } } } } } referenceQuotations.Sort(new KnowledgeItemComparer(store)); foreach (KnowledgeItem quotation in quotations) { int index = referenceQuotations.FindIndex(q => q == quotation); if (index <= 1) { continue; } KnowledgeItem previousQuotation = referenceQuotations[index - 1]; if (previousQuotation == null) { continue; } quotation.PageRange = previousQuotation.PageRange; quotation.PageRange = quotation.PageRange.Update(previousQuotation.PageRange.NumberingType); quotation.PageRange = quotation.PageRange.Update(previousQuotation.PageRange.NumeralSystem); } }
public static bool CreateNewQuotationAndAnnotationFromHighlight(this Highlight highlight, QuotationType quotationType, bool ImportEmptyAnnotations, bool RedrawAnnotations, List <Annotation> temporaryAnnotations) { string highlightContents = highlight.GetContents(); if (string.IsNullOrEmpty(highlightContents) && !ImportEmptyAnnotations) { return(false); } Project project = Program.ActiveProjectShell.Project; if (project == null) { return(false); } PreviewControl previewControl = PreviewMethods.GetPreviewControl(); if (previewControl == null) { return(false); } PdfViewControl pdfViewControl = previewControl.GetPdfViewControl(); if (pdfViewControl == null) { return(false); } Document document = pdfViewControl.Document; if (document == null) { return(false); } Location location = previewControl.ActiveLocation; if (location == null) { return(false); } Reference reference = location.Reference; if (reference == null) { return(false); } // Dynamic variables KnowledgeItem newQuotation = null; KnowledgeItem newDirectQuotation = null; TextContent textContent = null; // Does any other annotation with the same quads already exist? Annotation existingAnnotation = highlight.EquivalentAnnotations().FirstOrDefault(); if ((string.IsNullOrEmpty(highlightContents) && ImportEmptyAnnotations) || quotationType == QuotationType.Comment) { Annotation temporaryAnnotation = temporaryAnnotations.Where(a => !highlight.AsAnnotationQuads().TemporaryQuads().Except(a.Quads.ToList()).Any()).FirstOrDefault(); if (temporaryAnnotation != null) { pdfViewControl.GoToAnnotation(temporaryAnnotation); textContent = (TextContent)pdfViewControl.GetSelectedContentFromType(pdfViewControl.GetSelectedContentType(), -1, false, true); location.Annotations.Remove(temporaryAnnotation); } else { return(false); } } int startPage = 1; if (reference.PageRange.StartPage.Number != null) { startPage = reference.PageRange.StartPage.Number.Value; } string pageRangeString = (startPage + highlight.GetPage().GetIndex() - 1).ToString(); Annotation knowledgeItemIndicationAnnotation = highlight.CreateKnowledgeItemIndicationAnnotation(RedrawAnnotations); switch (quotationType) { case QuotationType.Comment: if (!string.IsNullOrEmpty(highlightContents)) { newQuotation = highlightContents.CreateNewQuotationFromHighlightContents(pageRangeString, reference, quotationType); reference.Quotations.Add(newQuotation); project.AllKnowledgeItems.Add(newQuotation); newQuotation.LinkWithKnowledgeItemIndicationAnnotation(knowledgeItemIndicationAnnotation); if (AnnotationsImporterColorPicker.ImportDirectQuotationLinkedWithCommentSelected) { Annotation newDirectQuotationIndicationAnnotation = highlight.CreateKnowledgeItemIndicationAnnotation(RedrawAnnotations); newDirectQuotation = textContent.CreateNewQuotationFromAnnotationContent(pageRangeString, reference, QuotationType.DirectQuotation); reference.Quotations.Add(newDirectQuotation); project.AllKnowledgeItems.Add(newDirectQuotation); newDirectQuotation.LinkWithKnowledgeItemIndicationAnnotation(newDirectQuotationIndicationAnnotation); EntityLink commentDirectQuotationLink = new EntityLink(project); commentDirectQuotationLink.Source = newQuotation; commentDirectQuotationLink.Target = newDirectQuotation; commentDirectQuotationLink.Indication = EntityLink.CommentOnQuotationIndication; project.EntityLinks.Add(commentDirectQuotationLink); newQuotation.CoreStatement = newDirectQuotation.CoreStatement + " (Comment)"; newQuotation.CoreStatementUpdateType = UpdateType.Manual; } } else if (string.IsNullOrEmpty(highlightContents) && ImportEmptyAnnotations) { newQuotation = textContent.CreateNewQuotationFromAnnotationContent(pageRangeString, reference, quotationType); reference.Quotations.Add(newQuotation); project.AllKnowledgeItems.Add(newQuotation); newQuotation.LinkWithKnowledgeItemIndicationAnnotation(knowledgeItemIndicationAnnotation); if (AnnotationsImporterColorPicker.ImportDirectQuotationLinkedWithCommentSelected) { Annotation newDirectQuotationIndicationAnnotation = highlight.CreateKnowledgeItemIndicationAnnotation(RedrawAnnotations); newDirectQuotation = textContent.CreateNewQuotationFromAnnotationContent(pageRangeString, reference, QuotationType.DirectQuotation); reference.Quotations.Add(newDirectQuotation); project.AllKnowledgeItems.Add(newDirectQuotation); newDirectQuotation.LinkWithKnowledgeItemIndicationAnnotation(newDirectQuotationIndicationAnnotation); EntityLink commentDirectQuotationLink = new EntityLink(project); commentDirectQuotationLink.Source = newQuotation; commentDirectQuotationLink.Target = newDirectQuotation; commentDirectQuotationLink.Indication = EntityLink.CommentOnQuotationIndication; project.EntityLinks.Add(commentDirectQuotationLink); newQuotation.CoreStatement = newDirectQuotation.CoreStatement + " (Comment)"; newQuotation.CoreStatementUpdateType = UpdateType.Manual; } } break; case QuotationType.QuickReference: if (!string.IsNullOrEmpty(highlightContents)) { newQuotation = highlightContents.CreateNewQuickReferenceFromHighlightContents(pageRangeString, reference, quotationType); } else if (string.IsNullOrEmpty(highlightContents) && ImportEmptyAnnotations) { newQuotation = textContent.CreateNewQuickReferenceFromAnnotationContent(pageRangeString, reference, quotationType); } reference.Quotations.Add(newQuotation); project.AllKnowledgeItems.Add(newQuotation); newQuotation.LinkWithKnowledgeItemIndicationAnnotation(knowledgeItemIndicationAnnotation); break; default: if (!string.IsNullOrEmpty(highlightContents)) { newQuotation = highlightContents.CreateNewQuotationFromHighlightContents(pageRangeString, reference, quotationType); reference.Quotations.Add(newQuotation); project.AllKnowledgeItems.Add(newQuotation); newQuotation.LinkWithKnowledgeItemIndicationAnnotation(knowledgeItemIndicationAnnotation); } else if (string.IsNullOrEmpty(highlightContents) && ImportEmptyAnnotations) { newQuotation = textContent.CreateNewQuotationFromAnnotationContent(pageRangeString, reference, quotationType); reference.Quotations.Add(newQuotation); project.AllKnowledgeItems.Add(newQuotation); newQuotation.LinkWithKnowledgeItemIndicationAnnotation(knowledgeItemIndicationAnnotation); } break; } if (existingAnnotation != null) { existingAnnotation.LinkWithKnowledgeItemIndicationAnnotation(knowledgeItemIndicationAnnotation); existingAnnotation.Visible = false; } return(true); }
public void Article(KnowledgeItem item) { (uiMng.PushPanel(UIPanelType.Article) as ArticlePanel).Set(item.Title, item.Content, item.Date); }
public static void MergeAnnotations() { PreviewControl previewControl = PreviewMethods.GetPreviewControl(); if (previewControl == null) { return; } PdfViewControl pdfViewControl = previewControl.GetPdfViewControl(); if (pdfViewControl == null) { return; } Document document = pdfViewControl.Document; if (document == null) { return; } Project project = Program.ActiveProjectShell.Project; if (project == null) { return; } Location location = previewControl.ActiveLocation; if (location == null) { return; } Reference reference = location.Reference; if (reference == null) { return; } List <Annotation> annotations = pdfViewControl.GetSelectedAnnotations().ToList(); List <KnowledgeItem> quotations = annotations .Where ( a => a.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Count() > 0 ) .Select ( a => (KnowledgeItem)a.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).FirstOrDefault().Source ) .ToList(); List <QuotationType> quotationTypes = quotations.Select(q => q.QuotationType).Distinct().ToList(); var itemToRemove = quotationTypes.SingleOrDefault(q => q == QuotationType.Highlight); quotationTypes.Remove(itemToRemove); if (quotations.Count() > 0) { if (quotationTypes.Count > 1) { MessageBox.Show("Can't merge quotations, more than one type of quotation is selected."); return; } } // Dynamic Variables // The Magic KnowledgeItem newQuotation = CombineQuotations(quotations); Annotation newAnnotation = CombineAnnotations(annotations); if (quotations.Count() > 1) { EntityLink newEntityLink = new EntityLink(project); newEntityLink.Source = newQuotation; newEntityLink.Target = newAnnotation; newEntityLink.Indication = EntityLink.PdfKnowledgeItemIndication; project.EntityLinks.Add(newEntityLink); newAnnotation.Visible = false; reference.Quotations.RemoveRange(quotations); } else if (quotations.Count == 1) { EntityLink newEntityLink = new EntityLink(project); newEntityLink.Source = quotations.FirstOrDefault(); newEntityLink.Target = newAnnotation; newEntityLink.Indication = EntityLink.PdfKnowledgeItemIndication; project.EntityLinks.Add(newEntityLink); newAnnotation.Visible = false; } if (quotations.Count > 1 && quotationTypes.Count > 0) { Program.ActiveProjectShell.ShowKnowledgeItemFormForExistingItem(Program.ActiveProjectShell.PrimaryMainForm, newQuotation); } }
public async Task Knowlege_Create_Update_Delete_Test() { string token = await IdentityServerSetup.Instance.GetAccessTokenForUser("user", "password"); var client = _factory.CreateClient(); client.SetBearerToken(token); // _client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Test"); List <Int32> listCreatedIds = new List <Int32>(); // Step 1. Metadata request var metadata = await client.GetAsync("/odata/$metadata"); Assert.Equal(HttpStatusCode.OK, metadata.StatusCode); var content = await metadata.Content.ReadAsStringAsync(); if (content.Length > 0) { // How to verify metadata? // TBD. } // Step 2a. Get all knowledges - with non-authorized user var req1 = await _client.GetAsync("/odata/KnowledgeItems"); Assert.Equal(HttpStatusCode.Unauthorized, req1.StatusCode); // Step 2b. Get all knowledges - empty req1 = await client.GetAsync("/odata/KnowledgeItems"); Assert.Equal(HttpStatusCode.OK, req1.StatusCode); content = await req1.Content.ReadAsStringAsync(); if (content.Length > 0) { JToken outer = JToken.Parse(content); JArray inner = outer["value"].Value <JArray>(); Assert.Empty(inner); } // Step 3. Get all knowledge with count - zero and empty var req2 = await client.GetAsync("/odata/KnowledgeItems?$count=true"); Assert.Equal(HttpStatusCode.OK, req2.StatusCode); content = await req2.Content.ReadAsStringAsync(); if (content.Length > 0) { JToken outer = JToken.Parse(content); Int32 odatacount = outer["@odata.count"].Value <Int32>(); Assert.Equal(0, odatacount); JArray inner = outer["value"].Value <JArray>(); Assert.Empty(inner); } // Prepare the data for creation var nmod = new KnowledgeItem() { Title = "Test 1", Category = KnowledgeItemCategory.Concept, Content = "My test 1" }; var jsetting = new JsonSerializerSettings(); jsetting.Converters.Add(new StringEnumConverter()); var kjson = JsonConvert.SerializeObject(nmod, jsetting); HttpContent inputContent = new StringContent(kjson, Encoding.UTF8, "application/json"); // Step 4a. Create first knowledge - without authority var req3 = await _client.PostAsync("/odata/KnowledgeItems", inputContent); Assert.Equal(HttpStatusCode.Unauthorized, req3.StatusCode); // Step 4b. Create first knowledge req3 = await client.PostAsync("/odata/KnowledgeItems", inputContent); Assert.Equal(HttpStatusCode.Created, req3.StatusCode); content = await req3.Content.ReadAsStringAsync(); if (content.Length > 0) { var nmod2 = JsonConvert.DeserializeObject <KnowledgeItem>(content); Assert.Equal(nmod.Title, nmod2.Title); Assert.Equal(nmod.Content, nmod2.Content); listCreatedIds.Add(nmod2.ID); } // Step 5. Get all knowledge with count - one and an array with single item req2 = await client.GetAsync("/odata/KnowledgeItems?$count=true"); Assert.Equal(HttpStatusCode.OK, req2.StatusCode); content = await req2.Content.ReadAsStringAsync(); if (content.Length > 0) { JToken outer = JToken.Parse(content); Int32 odatacount = outer["@odata.count"].Value <Int32>(); Assert.Equal(1, odatacount); JArray inner = outer["value"].Value <JArray>(); Assert.Single(inner); foreach (var id in inner) { JObject dv = id.Value <JObject>(); foreach (var prop in dv.Properties().Select(p => p.Name).ToList()) { switch (prop) { case "ID": int nid = dv[prop].Value <Int32>(); Assert.Equal(listCreatedIds[0], nid); break; case "Title": string dv_t = dv[prop].Value <string>(); Assert.Equal(nmod.Title, dv_t); break; case "Content": string dv_c = dv[prop].Value <string>(); Assert.Equal(nmod.Content, dv_c); break; default: break; } } } } // Step 6: Create second knowledge nmod = new KnowledgeItem() { Title = "Test 2", Category = KnowledgeItemCategory.Formula, Content = "My test 2" }; kjson = JsonConvert.SerializeObject(nmod, jsetting); inputContent = new StringContent(kjson, Encoding.UTF8, "application/json"); var req6 = await client.PostAsync("/odata/KnowledgeItems", inputContent); Assert.Equal(HttpStatusCode.Created, req6.StatusCode); content = await req6.Content.ReadAsStringAsync(); if (content.Length > 0) { var nmod2 = JsonConvert.DeserializeObject <KnowledgeItem>(content); Assert.Equal(nmod.Title, nmod2.Title); Assert.Equal(nmod.Content, nmod2.Content); listCreatedIds.Add(nmod2.ID); } }
public static KnowledgeItem CombineQuotations(List <KnowledgeItem> quotations) { if (quotations.Count() == 1) { return(quotations.FirstOrDefault()); } if (quotations.Count == 0) { return(null); } // Static Variables PreviewControl previewControl = PreviewMethods.GetPreviewControl(); if (previewControl == null) { return(null); } PdfViewControl pdfViewControl = previewControl.GetPdfViewControl(); if (pdfViewControl == null) { return(null); } Document document = pdfViewControl.Document; if (document == null) { return(null); } Reference reference = quotations.FirstOrDefault().Reference; if (reference == null) { return(null); } Project project = Program.ActiveProjectShell.Project; if (project == null) { return(null); } List <Location> locations = quotations.GetPDFLocations().Distinct().ToList(); if (locations.Count != 1) { return(null); } Location location = locations.FirstOrDefault(); List <QuotationType> quotationTypes = quotations.Select(q => q.QuotationType).Distinct().ToList(); var itemToRemove = quotationTypes.SingleOrDefault(q => q == QuotationType.Highlight); quotationTypes.Remove(itemToRemove); QuotationType quotationType = quotationTypes.FirstOrDefault(); if (quotationTypes.Count == 0) { quotationType = QuotationType.Highlight; } // Dynamic Variables KnowledgeItem newQuotation = new KnowledgeItem(reference, quotationType); string text = string.Empty; List <Quad> quads = new List <Quad>(); List <PageRange> pageRangesList = new List <PageRange>(); string pageRangeText = string.Empty; List <PageWidth> store = new List <PageWidth>(); // The Magic if (document != null) { for (int i = 1; i <= document.GetPageCount(); i++) { pdftron.PDF.Page page = document.GetPage(i); if (page.IsValid()) { var re = page.GetCropBox(); store.Add(new PageWidth(location, i, re.Width())); } else { store.Add(new PageWidth(location, i, 0.00)); } } } quotations.Sort(new KnowledgeItemComparer(store)); foreach (KnowledgeItem quotation in quotations) { if (!string.IsNullOrEmpty(quotation.Text)) { text = MergeRTF(text, quotation.TextRtf); } if (!string.IsNullOrEmpty(quotation.PageRange.OriginalString)) { pageRangesList.Add(quotation.PageRange); } } pageRangesList = PageRangeMerger.MergeAdjacent(pageRangesList); pageRangeText = PageRangeMerger.PageRangeListToString(pageRangesList); newQuotation.TextRtf = text; newQuotation.PageRange = pageRangeText; newQuotation.PageRange = newQuotation.PageRange.Update(quotations[0].PageRange.NumberingType); newQuotation.PageRange = newQuotation.PageRange.Update(quotations[0].PageRange.NumeralSystem); reference.Quotations.Add(newQuotation); project.AllKnowledgeItems.Add(newQuotation); return(newQuotation); }
public static void Main() { ProjectShell activeProjectShell = Program.ActiveProjectShell; if (activeProjectShell == null) { return; //no open project shell } Project targetProject = Program.ActiveProjectShell.Project; if (targetProject == null) { return; } Form primaryMainForm = activeProjectShell.PrimaryMainForm; if (primaryMainForm == null) { return; } string sourceCTV6File = string.Empty; string initialDirectory = Program.Engine.DesktopEngineConfiguration.GetFolderPath(CitaviFolder.Projects); DebugMacro.WriteLine(initialDirectory); //System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop var openFileDialog = new OpenFileDialog() { Filter = "Citavi Project Files|*.ctv6", CheckFileExists = true, CheckPathExists = true, Multiselect = false, InitialDirectory = initialDirectory }; if (openFileDialog.ShowDialog(primaryMainForm) != DialogResult.OK) { return; } string sourceProjectFile = openFileDialog.FileName; DebugMacro.WriteLine(sourceProjectFile); Project sourceProject = GetProject(sourceProjectFile).Result; if (sourceProject == null) { return; } IEnumerable <Category> targetCategories = targetProject.AllCategories.AsEnumerable <Category>(); IEnumerable <Category> sourceCategories = sourceProject.AllCategories.AsEnumerable <Category>(); foreach (Category targetCategory in targetCategories) { Category sourceCategory = sourceCategories.FindCategory(targetCategory); if (sourceCategory == null) { continue; } IEnumerable <KnowledgeItem> sourceCategoryKnowledgeItems = sourceCategory.KnowledgeItems.AsEnumerable <KnowledgeItem>(); foreach (KnowledgeItem sourceKnowledgeItem in sourceCategoryKnowledgeItems) { //if exists in target KI collection, then move to bottom KnowledgeItem targetKnowledgeItem = targetCategory.KnowledgeItems.FindKnowledgeItem(sourceKnowledgeItem); if (targetKnowledgeItem == null) { continue; } targetCategory.KnowledgeItems.MoveToBottom(targetKnowledgeItem); } } MessageBox.Show("Done"); }
// PUT: /KnowledgeItems(5) /// <summary> /// Support for updating Knowledge items /// </summary> public async Task <IActionResult> Put([FromODataUri] int key, [FromBody] KnowledgeItem update) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (key != update.ID) { return(BadRequest()); } var knowitem = await _context.KnowledgeItems .Include(i => i.Tags) .SingleOrDefaultAsync(x => x.ID == key); if (knowitem == null) { return(NotFound()); } knowitem.UpdateData(update); if (knowitem.Tags.Count > 0) { if (update.Tags.Count > 0) { knowitem.Tags.Clear(); foreach (var tag in update.Tags) { var newtag = new KnowledgeTag(tag); newtag.CurrentKnowledgeItem = knowitem; knowitem.Tags.Add(newtag); } } else { // Delete all knowitem.Tags.Clear(); } } else { if (update.Tags != null && update.Tags.Count > 0) { foreach (var tag in update.Tags) { var newtag = new KnowledgeTag(tag); newtag.CurrentKnowledgeItem = knowitem; knowitem.Tags.Add(newtag); } } } try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { throw; } return(Updated(update)); }
public static void CreateCommentAnnotation(List <KnowledgeItem> quotations) { PreviewControl previewControl = PreviewMethods.GetPreviewControl(); if (previewControl == null) { return; } PdfViewControl pdfViewControl = previewControl.GetPdfViewControl(); if (pdfViewControl == null) { return; } Annotation lastAnnotation = null; foreach (KnowledgeItem quotation in quotations) { if (quotation.EntityLinks.Any() && quotation.EntityLinks.Where(link => link.Target is KnowledgeItem).FirstOrDefault() != null) { Reference reference = quotation.Reference; if (reference == null) { return; } Project project = reference.Project; if (project == null) { return; } KnowledgeItem mainQuotation = quotation.EntityLinks.ToList().Where(n => n != null && n.Indication == EntityLink.CommentOnQuotationIndication && n.Target as KnowledgeItem != null).ToList().FirstOrDefault().Target as KnowledgeItem; Annotation mainQuotationAnnotation = mainQuotation.EntityLinks.Where(link => link.Target is Annotation && link.Indication == EntityLink.PdfKnowledgeItemIndication).FirstOrDefault().Target as Annotation; if (mainQuotationAnnotation == null) { return; } Location location = mainQuotationAnnotation.Location; if (location == null) { return; } List <Annotation> oldAnnotations = quotation.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).Select(e => (Annotation)e.Target).ToList(); foreach (Annotation oldAnnotation in oldAnnotations) { location.Annotations.Remove(oldAnnotation); } Annotation newAnnotation = new Annotation(location); newAnnotation.OriginalColor = System.Drawing.Color.FromArgb(255, 255, 255, 0); newAnnotation.Quads = mainQuotationAnnotation.Quads; newAnnotation.Visible = false; location.Annotations.Add(newAnnotation); EntityLink newEntityLink = new EntityLink(project); newEntityLink.Source = quotation; newEntityLink.Target = newAnnotation; newEntityLink.Indication = EntityLink.PdfKnowledgeItemIndication; project.EntityLinks.Add(newEntityLink); lastAnnotation = newAnnotation; } pdfViewControl.GoToAnnotation(lastAnnotation); } }
static void CreateHighlightAnnots(Annotation annotation, System.Drawing.Color highlightColor, Document document, List <Rect> coveredRectsBefore, out List <Rect> coveredRectsAfter) { List <Quad> quads = annotation.Quads.Where(q => q.IsContainer == false).ToList(); List <int> pages = quads.Select(q => q.PageIndex).ToList().Distinct().ToList(); pages.Sort(); KnowledgeItem quotation = (KnowledgeItem)annotation.EntityLinks.Where(e => e.Indication == EntityLink.PdfKnowledgeItemIndication).FirstOrDefault().Source; string quotationText = quotation.Text; if (string.IsNullOrEmpty(quotationText)) { quotationText = quotation.CoreStatement; } bool TextAlreadyWrittenToAnAnnotation = false; coveredRectsAfter = coveredRectsBefore; double currentR = highlightColor.R; double currentG = highlightColor.G; double currentB = highlightColor.B; double currentA = highlightColor.A; ColorPt colorPt = new ColorPt( currentR / 255, currentG / 255, currentB / 255 ); double highlightOpacity = currentA / 255; foreach (int pageIndex in pages) { pdftron.PDF.Page page = document.GetPage(pageIndex); if (page == null) { continue; } if (!page.IsValid()) { continue; } List <Quad> quadsOnThisPage = annotation.Quads.Where(q => q.PageIndex == pageIndex && q.IsContainer == false).Distinct().ToList(); List <Rect> boxes = new List <Rect>(); foreach (Quad quad in quadsOnThisPage) { boxes.Add(new Rect(quad.MinX, quad.MinY, quad.MaxX, quad.MaxY)); } Annot newAnnot = null; // If we want to make the later annotation invisible, we should uncomment the following if then else, and comment out the line after that if (boxes.Select(b => new { b.x1, b.y1, b.x2, b.y2 }).Intersect(coveredRectsAfter.Select(b => new { b.x1, b.y1, b.x2, b.y2 })).Count() == boxes.Count()) { newAnnot = CreateSingleHighlightAnnot(document, boxes, colorPt, 0); } else { newAnnot = CreateSingleHighlightAnnot(document, boxes, colorPt, highlightOpacity); } // newAnnot = CreateSingleHighlightAnnot(document, boxes, colorPt, highlightOpacity); if (!TextAlreadyWrittenToAnAnnotation) { newAnnot.SetContents(quotationText); TextAlreadyWrittenToAnAnnotation = true; } page.AnnotPushBack(newAnnot); if (newAnnot.IsValid() == false) { continue; } if (newAnnot.GetAppearance() == null) { newAnnot.RefreshAppearance(); } coveredRectsAfter.AddRange(boxes); } }