예제 #1
0
        public async Task <List <DocumentTaskEntity> > ListGroup(string group)
        {
            TableQuery <DocumentTaskGroupEntity> query  = new TableQuery <DocumentTaskGroupEntity>().Where(TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, group));
            List <DocumentTaskGroupEntity>       result = documentTaskGroupTable.ExecuteQuery(query).ToList();

            if (result == null)
            {
                throw new InvalidOperationException("table lookup failed");
            }
            List <DocumentTaskEntity> list = new List <DocumentTaskEntity>();

            foreach (DocumentTaskGroupEntity x in result)
            {
                Guid g = new Guid(x.DocumentId);
                try
                {
                    DocumentTaskEntity document = await GetTask(g);

                    list.Add(document);
                }
                catch
                {
                }
            }
            return(list);
        }
예제 #2
0
        // Add a new document to the database prior to creating its task in Batch
        // pass null for group if no group should be assigned, not ""
        // returns the Guid to query the task with
        public async Task <Guid> AddNewDocument(string group, string callback, List <UrlUploadFile> uploadFiles, List <BatchBlobUrlInput> inputFiles)
        {
            Guid document = Guid.NewGuid();
            DocumentTaskEntity documentTask = new DocumentTaskEntity(document.ToString());

            //documentTask.Timestamp = DateTime.UtcNow;
            documentTask.CallbackUrl = callback;
            documentTask.Ts          = XmlConvert.ToString(DateTime.UtcNow, XmlDateTimeSerializationMode.Utc);
            if (uploadFiles.Count > 0)
            {
                documentTask.State = "uploading";
            }
            else
            {
                documentTask.State = "creating";
            }
            documentTask.UploadFiles = uploadFiles;
            documentTask.InputFiles  = inputFiles;
            documentTask.ResultFiles = new List <BatchBlobUrlInput>();

            DocumentTaskGroupEntity documentTaskGroup = null;

            if (group != null)
            {
                documentTaskGroup = new DocumentTaskGroupEntity(document.ToString(), group);
                TableOperation taskGroupTableOp     = TableOperation.Insert(documentTaskGroup);
                TableResult    taskGroupTableResult = await documentTaskGroupTable.ExecuteAsync(taskGroupTableOp);
            }


            TableOperation taskTableOp     = TableOperation.Insert(documentTask);
            TableResult    taskTableResult = await documentTaskTable.ExecuteAsync(taskTableOp);

            return(document);
        }
예제 #3
0
        public async Task <DocumentTaskEntity> GetTask(Guid guid)
        {
            TableOperation retrieveOperation = TableOperation.Retrieve <DocumentTaskEntity>(guid.ToString(), guid.ToString());
            TableResult    taskTableResult   = await documentTaskTable.ExecuteAsync(retrieveOperation);

            if (taskTableResult.HttpStatusCode != 200)
            {
                throw new InvalidOperationException("not_found");
            }
            DocumentTaskEntity document = (DocumentTaskEntity)taskTableResult.Result;

            return(document);
        }
예제 #4
0
 public static JObject GetStatus(DocumentTaskEntity document)
 {
     JObject respObject = new JObject();
     JArray outputList = new JArray();
     if (document.ResultFiles != null)
     {
         foreach (BatchBlobUrlInput x in document.ResultFiles)
         {
             JObject obj = new JObject();
             obj["part"] = x.Part;
             obj["url"] = x.Url;
             outputList.Add(obj);
         }
     }
     respObject["id"] = document.DocumentId.ToString();
     respObject["status"] = document.State;
     if (document.State == "complete")
     {
         respObject["output"] = outputList;
     }
     return respObject;
 }
예제 #5
0
 public async Task UpdateTask(DocumentTaskEntity document)
 {
     TableOperation taskTableOp     = TableOperation.Replace(document);
     TableResult    taskTableResult = await documentTaskTable.ExecuteAsync(taskTableOp);
 }