Esempio n. 1
0
 public Document GetDocument(DocumentIdentifier id)
 {
     InMemoryDocument doc;
     lock (list)
         doc = FindDoc(id);
     return doc == null ? null : doc.Clone();
 }
Esempio n. 2
0
        public Document GetDocument(DocumentIdentifier id)
        {
            var blob = container.GetBlobReference(id.FileName());
            try {
                blob.FetchAttributes();
            } catch (StorageClientException) { return null; }	//If the blob was deleted

            return new BlobDocument(blob);
        }
Esempio n. 3
0
        public void DeleteDocument(DocumentIdentifier id)
        {
            var doc = (BlobDocument)GetDocument(id);

            foreach (var alternateStream in doc.AlternateStreamNames) {
                doc.CreateAlternateBlob(alternateStream).Delete();
            }

            doc.Blob.Delete();
        }
Esempio n. 4
0
        public Guid UploadDocument(Guid userId, string name, string mimeType, Stream document, long length)
        {
            var id = new DocumentIdentifier(userId, Guid.NewGuid());
            var doc = new BlobDocument(id, name, CreateBlob(id));

            doc.UpdateMetadata();
            doc.Blob.Properties.ContentType = mimeType;

            doc.Blob.UploadFromStream(document);

            return id.DocumentId;
        }
Esempio n. 5
0
        public void Execute(DocumentIdentifier id)
        {
            try {
                using (var reporter = new AsyncProgressReporter(StorageClient, id)) {
                    reporter.StartReporter();

                    var document = StorageClient.GetDocument(id);
                    if (document == null) return;
                    document.State = DocumentState.Scanning;
                    document.ScanProgress = 0;
                    StorageClient.UpdateDocument(document);

                    var stream = new MemoryStream();
                    using (var source = document.OpenRead())
                        source.CopyTo(stream);
                    var results = new ReadOnlyCollection<RecognizedSegment>(
                        Recognizer.Recognize(stream, reporter).ToList()
                    );
                    reporter.StopReporter();

                    document = StorageClient.GetDocument(document.Id);	//Refresh properties before saving them (eg, if it was renamed)
                    if (document == null) return;

                    foreach (var converter in ResultConverters) {
                        var convertedStream = converter.Convert(document.OpenRead(), results);
                        document.UploadStream(converter.OutputFormat.ToString(), convertedStream, convertedStream.Length);
                    }

                    document.ScanProgress = 100;
                    document.State = DocumentState.Scanned;
                    StorageClient.UpdateDocument(document);
                }
            } catch (Exception ex) {
                var document = StorageClient.GetDocument(id);
                if (document == null) return;

                document.State = DocumentState.Error;
                document.UploadString("Error", ex.ToString());
                StorageClient.UpdateDocument(document);
            }
        }
Esempio n. 6
0
        public void Execute(DocumentIdentifier id)
        {
            var doc = StorageClient.GetDocument(id);
            if (doc == null) return;

            try {
                doc.State = DocumentState.Scanning;
                doc.ScanProgress = 0;
                StorageClient.UpdateDocument(doc);

                var stream = new MemoryStream();
                using (var source = doc.OpenRead())
                    source.CopyTo(stream);
                var results = new ReadOnlyCollection<RecognizedSegment>(
                    Recognizer.Recognize(stream, new StorageProgressReporter(this, id)).ToList()
                );

                doc = StorageClient.GetDocument(doc.Id);
                if (doc == null) return;
                foreach (var converter in ResultConverters) {
                    var convertedStream = converter.Convert(doc.OpenRead(), results);
                    doc.UploadStream(converter.OutputFormat.ToString(), convertedStream, convertedStream.Length);
                }

                doc.ScanProgress = 100;
                doc.State = DocumentState.Scanned;
                StorageClient.UpdateDocument(doc);
            } catch (Exception ex) {
                doc = StorageClient.GetDocument(id);
                if (doc == null) return;

                doc.State = DocumentState.Error;
                doc.UploadString("Error", ex.ToString());
                StorageClient.UpdateDocument(doc);
            }
        }
Esempio n. 7
0
 CloudBlob CreateBlob(DocumentIdentifier id)
 {
     return new CloudBlob(container.Name + "/" + id.FileName(), client);
 }
Esempio n. 8
0
 ///<summary>Creates a new BlobDocument.</summary>
 internal BlobDocument(DocumentIdentifier id, string name, CloudBlob emptyBlob)
     : base(id)
 {
     this.Blob = emptyBlob;
     this.Name = name;
     SetInitialValues();
 }
Esempio n. 9
0
 public void CancelProcessing(DocumentIdentifier id)
 {
     canceledDocuments.TryAdd(id, true);
 }
Esempio n. 10
0
 public StorageProgressReporter(SimpleDocumentExecutor executor, DocumentIdentifier id)
 {
     this.executor = executor;
     this.id = id;
 }
Esempio n. 11
0
 public void CancelProcessing(DocumentIdentifier id)
 {
 }
Esempio n. 12
0
 public AsyncProgressReporter(IStorageClient storage, DocumentIdentifier documentId)
 {
     this.storage = storage; this.documentId = documentId;
 }
Esempio n. 13
0
 ///<summary>Creates a new Document with the specified ID.</summary>
 protected Document(DocumentIdentifier id)
 {
     Id = id;
 }
Esempio n. 14
0
 public void Execute(DocumentIdentifier id)
 {
     queue.AddMessage(new CloudQueueMessage(id.FileName()));
 }
Esempio n. 15
0
 ///<summary>Finds the document with the given ID.</summary>
 ///<remarks>Must be called inside lock(list).</remarks>
 InMemoryDocument FindDoc(DocumentIdentifier id)
 {
     return list.SingleOrDefault(d => d.Id == id);
 }
Esempio n. 16
0
 public void DeleteDocument(DocumentIdentifier id)
 {
     lock (list)
         list.RemoveAll(d => d.Id == id);
 }