Пример #1
0
        public Task <Guid> OrderAttack(IBatchOperationHandle batchOperationHandleInterface, Guid sessionId, Guid phaseId, Guid sourceRegion, String sourceRegionEtag, Guid targetRegion, UInt32 numberOfTroops)
        {
            BatchOperationHandle batchOperationHandle = batchOperationHandleInterface as BatchOperationHandle;
            CloudTable           commandQueueTable    = GetCommandQueueTableForSession(sessionId);
            Guid operationId = Guid.NewGuid();

            TableOperation operation       = TableOperation.Retrieve <CommandQueueTableEntry>(sessionId.ToString(), "Command_" + sourceRegion.ToString() + "_" + targetRegion.ToString());
            var            orderAttackTask = commandQueueTable.ExecuteAsync(operation)
                                             .ContinueWith(getExistingTask =>
            {
                TableResult getExistingResult = getExistingTask.Result;
                if (getExistingResult.Result != null)
                {
                    // Update existing entry
                    CommandQueueTableEntry existingCommand = getExistingResult.Result as CommandQueueTableEntry;
                    existingCommand.OperationId            = operationId;
                    existingCommand.RawNumberOfTroops     += (int)numberOfTroops;

                    // Kick off update operation
                    batchOperationHandle.BatchOperation.Replace(existingCommand);
                }
                else
                {
                    // Create a new table entry
                    CommandQueueTableEntry newCommand = CommandQueueTableEntry.CreateAttackMessage(operationId, sessionId, phaseId, sourceRegion, sourceRegionEtag, targetRegion, numberOfTroops);

                    // Kick off the insert operation
                    batchOperationHandle.BatchOperation.Insert(newCommand);
                }
            });

            batchOperationHandle.AddPrerequisite(orderAttackTask, 1);

            return(Task.FromResult(operationId));
        }
Пример #2
0
        public void AssignRegionOwnership(IBatchOperationHandle batchOperationHandleInterface, Guid sessionId, Dictionary <Guid, OwnershipChange> ownershipChanges)
        {
            BatchOperationHandle batchOperationHandle = batchOperationHandleInterface as BatchOperationHandle;

            // Get the session data table
            CloudTable sessionDataTable = SessionRepository.GetTableForSessionData(TableClient, sessionId);

            // Fetch all regions (quicker than fetching only what we need, one by one)
            var updateRegionOwnershipTask = GetRegions(sessionId)
                                            .ContinueWith(regionTask => { AssignRegionOwnership(batchOperationHandleInterface, regionTask.Result, ownershipChanges); });

            batchOperationHandle.AddPrerequisite(updateRegionOwnershipTask, ownershipChanges.Count);
        }