コード例 #1
0
 private TableResult AddCommandStatusIndex(Guid commandId, CommandProcessingStatus status, string ccid)
 {
     var statusIndex = new CommandProcessingAuditStatusIndexTable
         {
             PartitionKey = status.ToString(),
             RowKey = commandId.ToString(),
             CostCentreId = new Guid(ccid)
         };
     TableOperation to3 = TableOperation.Insert(statusIndex);
     TableResult r3 = _commandStatus.Execute(to3);
     return r3;
 }
コード例 #2
0
        public void SetCommandStatus(Guid commandId, CommandProcessingStatus status)
        {
            _logger.InfoFormat("#### ---> Command {0} SetCommandStatus {1} ", commandId.ToString(), status.ToString());

            string existingStatus = null;
            //update command
            TableResult commandAudit = CommandAuditTableLookup(commandId);
            if (commandAudit == null)
                return;

            CommandProcessingAuditTable command = (CommandProcessingAuditTable)commandAudit.Result;
            existingStatus = ((CommandProcessingStatus)command.Status).ToString();

            var tasks = new List<Task<TableResult>>();

            tasks.Add(Task.Run(() =>
                {
                    command.Status = (int)status;
                    TableOperation updateOperation = TableOperation.Replace(command);
                    return _commandTable.Execute(updateOperation);
                }));


            //add to command status
            if (status == CommandProcessingStatus.Complete) //should not need to index complete??
                return;
            tasks.Add(Task.Run(() =>
                {
                    //remove existing
                    var csFC = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal,commandId.ToString());
                    var csQry = new TableQuery<CommandProcessingAuditStatusIndexTable>().Where(csFC);
                    var csResults = _commandStatus.ExecuteQuery(csQry);
                    foreach (var csResult in csResults)
                    {
                        TableOperation deleteOperation = TableOperation.Delete(csResult);
                        _commandStatus.Execute(deleteOperation);
                    }
                    //add new
                    string ccid = command.PartitionKey;
                    return AddCommandStatusIndex(commandId, status, ccid);
                }));

            Task.WaitAll(tasks.ToArray());
        }