Esempio n. 1
0
 public void CloseADocumentControl(IDocumentControl documentContorl)
 {
     if (DocumentList != null && DocumentList.Contains(documentContorl))
     {
         DocumentList.Remove(documentContorl);
     }
 }
Esempio n. 2
0
        public void UpdatePublishedCopyTest()
        {
            var retriever = new DocumentList();
            var list = new DocumentList();
            var item = new DocumentList();

            Mock.Arrange(() => item.IsChild).Returns(true);

            Mock.Arrange(() => DocumentList.GetDocumentList(Arg.IsAny<IEnumerable<SectionViewDocumentDto>>())).IgnoreInstance().Returns(item);

            new PrivateAccessor(retriever).CallMethod("Child_Fetch", new List<SectionViewDocumentDto> { new SectionViewDocumentDto() });
            new PrivateAccessor(list).CallMethod("Child_Fetch", new List<SectionViewDocumentDto> { new SectionViewDocumentDto() });

            Mock.Arrange(() => list.Remove(Arg.IsAny<DocumentEdit>())).DoNothing().MustBeCalled();
            Mock.Arrange(() => list.Add(Arg.IsAny<DocumentEdit>())).DoNothing().MustBeCalled();

            retriever.UpdatePublishedCopy(list);

            Mock.Assert(list);
        }
Esempio n. 3
0
        public async Task DeleteCurrentDocument()
        {
            Error = null;
            if (CurrentDocument != null)
            {
                var existing = CurrentSum;
                if (existing != null)
                {
                    DocumentList.Remove(existing);
                }

                //Save updated document list
                bool success = await SaveDocumentList(DocumentList);

                if (success)
                {
                    CurrentDocument = null;
                }
            }
        }
Esempio n. 4
0
        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.";
                }
            }
        }
Esempio n. 5
0
        /// <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);
            }
        }
Esempio n. 6
0
        protected override async Task <bool> OnSave()
        {
            try
            {
                this.Block();
                bool returnType = false;

                if (!this.ValidateEntries())
                {
                    this.ShowToast("Existem campos preenchidos de forma incorreta!");
                    this.Unblock();
                    return(false);
                }

                if (this.CurrentOperation == FormOperation.Editando)
                {
                    DocumentModel updatedDocument = await this.documentService.UpdateDocument(this.CurrentDocument);

                    if (updatedDocument != null)
                    {
                        DocumentModel documentToUpdate = this.DocumentList.Find(document => document.ID == updatedDocument.ID);
                        if (documentToUpdate == null)
                        {
                            await this.GetList();
                        }
                        else
                        {
                            DocumentList.Remove(documentToUpdate);
                            DocumentList.Add(updatedDocument);
                        }
                        this.ShowToast("Documento editado com sucesso!");
                    }
                }
                else
                {
                    var newDocument = await documentService.CreateDocument(CurrentDocument);

                    if (newDocument != null)
                    {
                        this.DocumentList.Add(newDocument);
                        this.ShowToast("Documento inserido com sucesso!");
                        returnType = true;
                    }
                    else
                    {
                        this.CurrentDocument = null;
                        this.ShowToast("Erro ao inserir categoria!");
                    }
                }

                this.CurrentOperation = FormOperation.Nenhum;
                this.SortList();
                this.ResetEntries();
                this.Unblock();
                return(returnType);
            }
            catch (Exception e)
            {
                this.ShowToast(e.Message);
                //this.CurrentOperation = FormOperation.Nenhum;
                //this.ResetEntries();
                this.Unblock();
                return(false);
            }
        }
Esempio n. 7
0
        /// <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 sum = CurrentSum;
                if (sum != null && sum.PrivateKey == null)
                {
                    DocumentList.Remove(sum);
                    sum = null;
                    CurrentDocument.Id = Guid.NewGuid();
                }

                if (sum == null)
                {
                    string contentSeed = Guid.NewGuid().ToString();
                    string fileSeed    = Guid.NewGuid().ToString();
                    string seedPhrase  = $"{fileSeed}-{salt}";
                    var    key         = SiaSkynetClient.GenerateKeys(seedPhrase);

                    sum = new DocumentSummary()
                    {
                        Id            = CurrentDocument.Id,
                        Title         = CurrentDocument.Title,
                        CreatedDate   = DateTimeOffset.UtcNow,
                        ModifiedDate  = DateTimeOffset.UtcNow,
                        ContentSeed   = contentSeed,
                        PrivateKey    = key.privateKey,
                        PublicKey     = key.publicKey,
                        StorageSource = this.IsDfinityLogin ? StorageSource.Dfinity : StorageSource.Skynet
                    };

                    DocumentList.Add(sum);
                }

                if (sum.PrivateKey == null)
                {
                }


                //Fix title if there is no title
                var title = CurrentDocument.Title;
                if (string.IsNullOrWhiteSpace(title))
                {
                    title = fallbackTitle;
                }
                if (string.IsNullOrWhiteSpace(title))
                {
                    title = "Untitled document " + sum.CreatedDate;
                }

                CurrentDocument.Title = title;
                sum.Title             = title;

                CurrentDocument.ModifiedDate = DateTimeOffset.UtcNow;
                sum.ModifiedDate             = DateTimeOffset.UtcNow;

                //Save image
                string?imgLink = null;
                try
                {
                    imgLink = await SaveDocumentImage(img);

                    sum.PreviewImage             = imgLink;
                    CurrentDocument.PreviewImage = imgLink;
                }
                catch { }

                //Save document
                bool success = await SaveDocument(CurrentDocument, sum);

                if (success)
                {
                    Console.WriteLine("Document saved");

                    //Save updated document list
                    await SaveDocumentList(DocumentList);

                    Console.WriteLine("Document list saved");
                }

                if (!success)
                {
                    Error = "Error saving document. Please try again";
                }
                else
                {
                    CurrentDocument = null;
                }
            }
        }