Exemple #1
0
 public IActionResult Create(StoredDocument doc)
 {
     if (ModelState.IsValid)
     {
         int inx = _service.StoreDocument(doc);
         if (inx > 0)
         {
             return(RedirectToAction("Details", inx));
         }
     }
     return(View(doc));
 }
Exemple #2
0
 public object GetDocByApacheLucene(StoredDocument doc)
 {
     //TODO
     throw new NotImplementedException();
 }
Exemple #3
0
 public object GetDocByTikaondotner(StoredDocument doc)
 {
     //TODO
     throw new NotImplementedException();
 }
Exemple #4
0
 public object GetSepcyfiedDocument(StoredDocument doc)
 {
     throw new NotImplementedException();
 }
Exemple #5
0
 public int StoreDocument(StoredDocument doc)
 {
     _dbContext.Documents.Add(doc);
     _dbContext.SaveChanges();
     return(_dbContext.Documents.Find(doc).Id);
 }
Exemple #6
0
        public ActionResult StoreDocument(
            [FromBody] string Document,
            [FromBody] string UniqueId,
            [FromBody] string SignerName)
        {
            byte[] bPDF;

            // create temporary ServerTextControl
            using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl())
            {
                tx.Create();

                // load the document
                tx.Load(Convert.FromBase64String(Document),
                        TXTextControl.BinaryStreamType.InternalUnicodeFormat);

                TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings()
                {
                    CreatorApplication = "TX Text Control Sample Application",
                };

                // save the document as PDF
                tx.Save(out bPDF, TXTextControl.BinaryStreamType.AdobePDF, saveSettings);
            }

            // calculate the MD5 checksum of the binary data
            // and store in SignedDocument object
            SignedDocument document = new SignedDocument()
            {
                Checksum = Checksum.CalculateMD5(bPDF)
            };

            // define a Blockchain object
            Blockchain bcDocument;

            // if the blockchain exists, load it
            if (System.IO.File.Exists(
                    Server.MapPath("~/App_Data/Blockchains/" + UniqueId + ".bc")))
            {
                string bc = System.IO.File.ReadAllText(
                    Server.MapPath("~/App_Data/Blockchains/" + UniqueId + ".bc"));

                bcDocument = JsonConvert.DeserializeObject <Blockchain>(bc);
            }
            else
            {
                bcDocument = new Blockchain(true); // otherwise create a new blockchain
            }
            // add a new block to the blockchain and store the SignedDocument object
            bcDocument.AddBlock(new Block(DateTime.Now, null, JsonConvert.SerializeObject(document)));

            // store the blockchain as a file
            System.IO.File.WriteAllText(
                Server.MapPath("~/App_Data/Blockchains/" + UniqueId + ".bc"),
                JsonConvert.SerializeObject(bcDocument));

            // create and return a view model with the PDF and the unique document ID
            StoredDocument storedDocument = new StoredDocument()
            {
                PDF        = Convert.ToBase64String(bPDF),
                DocumentId = UniqueId
            };

            return(new JsonResult()
            {
                Data = storedDocument,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }