/// <summary> /// Load document based on id /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task LoadDocument(Guid id) { IsLoading = true; var sum = DocumentList.Where(x => x.Id == id).FirstOrDefault(); if (sum != null) { CurrentDocument = await GetDocument(sum); } IsLoading = false; }
void DoSearchCommand(string searchText) { if (string.IsNullOrEmpty(searchText)) { SearchDocumentList.Clear(); SearchDocumentList.AddRange(DocumentList); } else { SearchDocumentList.Clear(); SearchDocumentList.AddRange(DocumentList.Where(x => x.nomDocument.Contains(searchText))); } }
public static bool TryGetXrefDocument(this IExecutionContext context, string xref, out IDocument document, out string error) { _ = context ?? throw new ArgumentNullException(nameof(context)); DocumentList <IDocument> documents = context.Outputs[nameof(Pipelines.Content)].Flatten(); List <(NormalizedPath, string, IDocument)> xrefs = documents.Select(x => (x.Source, x.GetString(WebKeys.Xref), x)).ToList(); ImmutableArray <IDocument> matches = documents .Where(x => x.GetString(WebKeys.Xref)?.Equals(xref, StringComparison.OrdinalIgnoreCase) == true) .ToImmutableDocumentArray(); if (matches.Length == 1) { document = matches[0]; error = default; return(true); } document = default; error = matches.Length > 1 ? $"Multiple ambiguous matching documents found for xref \"{xref}\"" : $"Couldn't find document with xref \"{xref}\""; return(false); }
public void AddDocumentSummary(Guid docId, byte[] pubKey, byte[]?privKey, string contentSeed, StorageSource storageSource) { var existing = DocumentList.Where(x => x.Id == docId).FirstOrDefault(); if (existing != null) { return; } DocumentSummary sum = new DocumentSummary() { Id = docId, PublicKey = pubKey, PrivateKey = privKey, ContentSeed = contentSeed, CreatedDate = DateTimeOffset.UtcNow, ModifiedDate = DateTimeOffset.UtcNow, Title = "Shared document", StorageSource = storageSource }; DocumentList.Add(sum); }
public async Task DeleteCurrentDocument() { Error = null; if (CurrentDocument != null) { var existing = DocumentList.Where(x => x.Id == CurrentDocument.Id).FirstOrDefault(); if (existing != null) { DocumentList.Remove(existing); } //Save updated document list bool success = await SaveDocumentList(DocumentList); if (success) { CurrentDocument = null; } else { Error = "Unable to delete document. Please try again."; } } }
/// <summary> /// Save current document /// </summary> /// <param name="fallbackTitle"></param> /// <returns></returns> public async Task SaveCurrentDocument(string fallbackTitle, byte[] img) { Error = null; if (CurrentDocument != null) { var existing = DocumentList.Where(x => x.Id == CurrentDocument.Id).FirstOrDefault(); if (existing != null) { DocumentList.Remove(existing); } var created = existing?.CreatedDate ?? DateTimeOffset.UtcNow; //Fix title if there is no title var title = CurrentDocument.Title; if (string.IsNullOrWhiteSpace(title)) { title = fallbackTitle; } if (string.IsNullOrWhiteSpace(title)) { title = "Untitled document " + created; } CurrentDocument.Title = title; DocumentSummary sum = new DocumentSummary() { Id = CurrentDocument.Id, Title = CurrentDocument.Title, CreatedDate = created, ModifiedDate = DateTimeOffset.UtcNow }; DocumentList.Add(sum); string?imgLink = null; if (img != null) { using (Stream stream = new MemoryStream(img)) { //Save preview image to Skynet file var response = await client.UploadFileAsync("document.jpg", stream); imgLink = response.Skylink; } } sum.PreviewImage = imgLink; bool success = await SaveDocument(CurrentDocument); if (success) { CurrentDocument = null; } else { Error = "Unable to save document to Skynet. Please try again."; } //Save updated document list await SaveDocumentList(DocumentList); } }