Beispiel #1
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);
        }
Beispiel #2
0
        public void SetAvailableReinforcements(IBatchOperationHandle batchOperationHandleInterface, Guid sessionId, String userId, String currentEtag, UInt32 reinforcements)
        {
            BatchOperationHandle batchOperationHandle = batchOperationHandleInterface as BatchOperationHandle;

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

            // Create a DynamicTableEntity so that we can do a partial update of this table (a merge)
            DynamicTableEntity nationEntry = NationTableEntry.CreateDynamicTableEntity(sessionId, userId, currentEtag);

            NationTableEntry.SetAvailableReinforcements(nationEntry, reinforcements);
            batchOperationHandle.BatchOperation.Merge(nationEntry);
        }
Beispiel #3
0
        private void SetCardInternal(IBatchOperationHandle batchOperationHandleInterface, Guid sessionId, Guid regionId, CardTableEntry.State newState, String newOwnerId, String currentEtag)
        {
            BatchOperationHandle batchOperationHandle = batchOperationHandleInterface as BatchOperationHandle;

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

            // Create a DynamicTableEntity so that we can do a partial update of this table (a merge)
            DynamicTableEntity cardEntry = CardTableEntry.CreateDynamicTableEntity(sessionId, regionId, currentEtag);

            CardTableEntry.SetOwner(cardEntry, newState, newOwnerId);
            batchOperationHandle.BatchOperation.Merge(cardEntry);
        }
Beispiel #4
0
        public async Task <IEnumerable <ICardData> > GetCards(Guid sessionId, String userId)
        {
            // Get the session data table
            CloudTable sessionDataTable = SessionRepository.GetTableForSessionData(TableClient, sessionId);

            var rowKeyCondition = TableQuery.CombineFilters(
                TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, "Card_"),
                TableOperators.And,
                TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThan, "Card`")
                );
            var ownerIdCondition = TableQuery.CombineFilters(
                rowKeyCondition,
                TableOperators.And,
                TableQuery.GenerateFilterCondition("OwnerId", QueryComparisons.Equal, userId)
                );
            var ownerStateCondition = TableQuery.CombineFilters(
                ownerIdCondition,
                TableOperators.And,
                TableQuery.GenerateFilterConditionForInt("OwnerStateRaw", QueryComparisons.Equal, (Int32)CardTableEntry.State.Owned)
                );

            List <ICardData>            results = new List <ICardData>();
            TableQuery <CardTableEntry> query   = new TableQuery <CardTableEntry>()
                                                  .Where(TableQuery.CombineFilters(
                                                             TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, sessionId.ToString()),
                                                             TableOperators.And,
                                                             ownerStateCondition
                                                             ));

            // Initialize the continuation token to null to start from the beginning of the table.
            TableContinuationToken continuationToken = null;

            // Loop until the continuation token comes back as null
            do
            {
                var queryResults = await sessionDataTable.ExecuteQuerySegmentedAsync(query, continuationToken);

                continuationToken = queryResults.ContinuationToken;
                results.AddRange(queryResults.Results);
            }while (continuationToken != null);

            foreach (CardTableEntry entry in results)
            {
                entry.IsValid();
            }

            return(results);
        }
Beispiel #5
0
        public async Task <IRegionData> GetRegion(Guid sessionId, Guid regionId)
        {
            // Get the session data table
            CloudTable sessionDataTable = SessionRepository.GetTableForSessionData(TableClient, sessionId);

            TableOperation operation = TableOperation.Retrieve <RegionTableEntry>(sessionId.ToString(), "Region_" + regionId.ToString());
            TableResult    result    = await sessionDataTable.ExecuteAsync(operation);

            var typedResult = result.Result as RegionTableEntry;

            if (typedResult != null)
            {
                typedResult.IsValid();
            }
            return(typedResult);
        }
Beispiel #6
0
        public async Task <INationData> GetNation(Guid sessionId, string userId)
        {
            // Get the session data table
            CloudTable sessionDataTable = SessionRepository.GetTableForSessionData(TableClient, sessionId);

            var operation = TableOperation.Retrieve <NationTableEntry>(sessionId.ToString(), "Nation_" + userId);
            var result    = await sessionDataTable.ExecuteAsync(operation);

            NationTableEntry typedResult = result.Result as NationTableEntry;

            if (typedResult != null)
            {
                typedResult.IsValid();
            }
            return(typedResult);
        }
Beispiel #7
0
        public async Task <IEnumerable <ICombat> > GetCombat(Guid sessionId, UInt32 round, CombatType type)
        {
            CloudTable dataTable = SessionRepository.GetTableForSessionData(TableClient, sessionId);

            TableQuery <CombatTableEntry> query = new TableQuery <CombatTableEntry>()
                                                  .Where(
                TableQuery.CombineFilters(
                    TableQuery.CombineFilters(
                        TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, sessionId.ToString()),
                        TableOperators.And,
                        TableQuery.GenerateFilterConditionForInt("ResolutionTypeRaw", QueryComparisons.Equal, (Int32)type)
                        ),
                    TableOperators.And,
                    TableQuery.GenerateFilterConditionForInt("Round", QueryComparisons.Equal, (Int32)round)
                    ));

            // Initialize the continuation token to null to start from the beginning of the table.
            TableContinuationToken continuationToken = null;

            // Loop until the continuation token comes back as null
            List <CombatTableEntry> results = new List <CombatTableEntry>();

            do
            {
                var queryResults = await dataTable.ExecuteQuerySegmentedAsync(query, continuationToken);

                continuationToken = queryResults.ContinuationToken;
                results.AddRange(queryResults.Results);
            }while (continuationToken != null);

            foreach (CombatTableEntry combat in results)
            {
                combat.IsValid();
            }

            return(results);
        }
Beispiel #8
0
        static public CloudTable GetCommandQueueTableForSession(CloudTableClient tableClient, Guid sessionId)
        {
            CloudTable commandQueueTable = SessionRepository.GetTableForSessionData(tableClient, sessionId);

            return(commandQueueTable);
        }