コード例 #1
0
        public void Start(Int32 pollingTimeInMs)
        {
            var jobDataMap = context.JobDetail.JobDataMap;
            PipelineId = new PipelineId(jobDataMap.GetString(JobKeys.PipelineId));

            InputDocumentId = new DocumentId(jobDataMap.GetString(JobKeys.DocumentId));
            InputBlobId = new BlobId(jobDataMap.GetString(JobKeys.BlobId));
            InputDocumentFormat = new DocumentFormat(jobDataMap.GetString(JobKeys.Format));

            if (TenantId == null)
                throw new Exception("tenant not set!");

            _workingFolder = Path.Combine(
                ConfigService.GetWorkingFolder(TenantId, InputBlobId),
                GetType().Name
            );

            OnExecute(context);

            try
            {
                if (Directory.Exists(_workingFolder))
                    Directory.Delete(_workingFolder, true);
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat(ex, "Error deleting {0}", _workingFolder);
            }

            pollingTimer = new Timer(pollingTimeInMs);
            pollingTimer.Elapsed += pollingTimer_Elapsed;
            pollingTimer.Start();
        }
コード例 #2
0
 public AddFormatToDocumentDescriptor(
     DocumentDescriptorId aggregateId, 
     DocumentFormat documentFormat, 
     BlobId blobId,
     PipelineId createdById) : base(aggregateId)
 {
     if (aggregateId == null) throw new ArgumentNullException("aggregateId");
     DocumentFormat = documentFormat;
     BlobId = blobId;
     CreatedBy = createdById;
 }
 BlobId AddFormatToDocument(int id, string handle, DocumentFormat format, PipelineId pipelineId, string pathToFile)
 {
     var fname = Path.GetFileName(pathToFile);
     var info = new DocumentHandleInfo(new DocumentHandle(handle), new FileNameWithExtension(fname));
     var blobId = _filestore.Upload(format, pathToFile);
     _bus.Send(new AddFormatToDocumentDescriptor(
         new DocumentDescriptorId(id),
         format,
         blobId,
         pipelineId
     ));
     Thread.Sleep(50);
     return blobId;
 }
コード例 #4
0
        public async Task<HttpResponseMessage> AddFormatToDocument(TenantId tenantId, DocumentFormat format)
        {
            var errorMessage = await AddFormatFromHttpContent(Request.Content, format);
            Logger.DebugFormat("File {0} processed with message {1}", _blobId, errorMessage);

            if (errorMessage != null)
            {
                Logger.Error("Error Adding format To Document: " + errorMessage);
                return Request.CreateErrorResponse(
                    HttpStatusCode.BadRequest,
                    errorMessage
                );
            }

            String queueName = _customData[AddFormatToDocumentParameters.QueueName] as String;
            String jobId = _customData[AddFormatToDocumentParameters.JobId] as String;
            DocumentDescriptorId documentId;
            if (String.IsNullOrEmpty(queueName))
            {
                //user ask for handle, we need to grab the handle
                var documentHandle = new DocumentHandle(_customData[AddFormatToDocumentParameters.DocumentHandle] as String);
                var handle = _handleWriter.FindOneById(documentHandle);
                documentId = handle.DocumentDescriptorId;
                if (documentId == null)
                {
                    Logger.ErrorFormat("Trying to add a format for Handle {0} with a null DocumentId", documentHandle);
                    return Request.CreateErrorResponse(
                       HttpStatusCode.BadRequest,
                       ""
                   );
                }
                Logger.DebugFormat("Add format {0} to handle {1} and document id {2}", format, handle, documentId);
            }
            else
            {
                var job = _queueDispatcher.GetJob(queueName, jobId);

                if (job == null)
                {
                    Logger.WarnFormat("Job id {0} not found in queue {1}", jobId, queueName);
                    return Request.CreateErrorResponse(
                        HttpStatusCode.BadRequest,
                        String.Format("Job id {0} not found in queue {1}", jobId, queueName));
                }
                documentId = job.DocumentDescriptorId;
                if (documentId == null)
                {
                    Logger.ErrorFormat("Trying to add a format for Job Id {0} queue {1} - Job has DocumentDescriptorId null", jobId, queueName);
                    return Request.CreateErrorResponse(
                       HttpStatusCode.BadRequest,
                       ""
                   );
                }
                //need to check if the descriptor is deleted
                var exists = _documentDescriptorReader
                    .AllUnsorted
                    .Where(d => d.Id == documentId)
                    .Any();
                if (!exists)
                {
                    Logger.ErrorFormat("Trying to add a format for Job Id {0} queue {1} - DocumentDescriptor does not exists or was deleted!", jobId, queueName);
                    return Request.CreateErrorResponse(
                       HttpStatusCode.BadRequest,
                       ""
                   );
                }
                Logger.DebugFormat("Add format {0} to job id {1} and document id {2}", format, job.Id, documentId);
            }

            if (format == "null")
            {
                var formatFromFileName = _documentFormatTranslator.GetFormatFromFileName(_fileName);
                if (formatFromFileName == null)
                {
                    String error = "Format not specified and no known format for file: " + _fileName;
                    Logger.Error(error);
                    return Request.CreateErrorResponse(
                        HttpStatusCode.BadRequest,
                        error
                    );
                }
                format = new DocumentFormat(formatFromFileName);
            }

            var createdById = new PipelineId(_customData[AddFormatToDocumentParameters.CreatedBy] as String);
            Logger.DebugFormat("Incoming new format for documentId {0}", documentId);

            var command = new AddFormatToDocumentDescriptor(documentId, format, _blobId, createdById);
            CommandBus.Send(command, "api");

            return Request.CreateResponse(
                HttpStatusCode.OK,
                new AddFormatToDocumentResponse
                {
                    Result = true,
                }
            );
        }
コード例 #5
0
 public DocumentFormatHasBeenUpdated(DocumentFormat documentFormat, BlobId blobId, PipelineId createdBy)
 {
     DocumentFormat = documentFormat;
     BlobId = blobId;
     CreatedBy = createdBy;
 }
 public FormatAddedToDocumentDescriptor(DocumentFormat documentFormat, BlobId blobId, PipelineId createdBy)
 {
     DocumentFormat = documentFormat;
     BlobId = blobId;
     CreatedBy = createdBy;
 }