private IEnumerable <TableQuery <DynamicTableEntity> > GetTableQueries()
        {
            List <TableQuery <DynamicTableEntity> > tableQueryList = new List <TableQuery <DynamicTableEntity> >();

            for (int index = 0; index < this.regulatoryBodyList.Length; index++)
            {
                TableQuery <DynamicTableEntity> tableQuery = new TableQuery <DynamicTableEntity>();

                tableQuery.SelectColumns = new List <string>
                {
                    UserAccessRequestTracker.UserIdKey,
                    UserAccessRequestTracker.RegulatoryBodyKey,
                    UserAccessRequestTracker.RequestStatusKey,
                    UserAccessRequestTracker.CurrentAccessLevel,
                    UserAccessRequestTracker.RequestedAccessLevel,
                    UserAccessRequestTracker.JustificationText
                };

                string regulatory = this.regulatoryBodyList[index];

                //tableQuery = TableAzureQueryHelper.AddCondition(tableQuery, TableOperators.And, TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, string.Format("{0}-{1}", regulatory, (int)RequestStatus.Pending)));

                //[Temporary Fix:] The following query is full table scan. We have to re-design the schemal of "AccessEvelationRequest" table, so that it can queried efficiently on number of diff. fields.
                tableQuery = TableAzureQueryHelper.AddCondition(tableQuery, TableOperators.And, TableQuery.GenerateFilterConditionForInt("RequestStatus", QueryComparisons.Equal, (int)RequestStatus.Pending));
                tableQuery = TableAzureQueryHelper.AddCondition(tableQuery, TableOperators.And, TableQuery.GenerateFilterCondition("Regulatory", QueryComparisons.Equal, regulatory.ToLower()));

                tableQueryList.Add(tableQuery);
            }

            return(tableQueryList);
        }
示例#2
0
        private IEnumerable <TableQuery <DynamicTableEntity> > GetTableQueries(DateTime signalTime)
        {
            List <TableQuery <DynamicTableEntity> > tableQueryList = new List <TableQuery <DynamicTableEntity> >();

            for (int regionIndex = 0; regionIndex < this.regionIdList.Length; regionIndex++)
            {
                TableQuery <DynamicTableEntity> tableQuery = new TableQuery <DynamicTableEntity>();
                tableQuery.SelectColumns = new List <string> {
                    AuditTracker.AuditIdKey, AuditTracker.MessageKey, AuditTracker.TransactionIdKey
                };

                string regionPartitionKey = this.PartitionKeyFromDateTime(this.regionIdList[regionIndex], this.TrackingTimeStart);

                tableQuery = TableAzureQueryHelper.AddCondition(tableQuery, TableOperators.And, TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, regionPartitionKey));

                if (this.TrackingTimeStart.DayOfYear != signalTime.DayOfYear)
                {
                    // TODO: Case to handle start time belong a one date and end time belongs to next day data.
                    string regionPartitionKeyForEndTime = this.PartitionKeyFromDateTime(this.regionIdList[regionIndex], signalTime);

                    tableQuery = TableAzureQueryHelper.AddCondition(tableQuery, TableOperators.Or, TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, regionPartitionKeyForEndTime));
                }

                tableQuery = TableAzureQueryHelper.AddCondition(tableQuery, TableOperators.And, TableQuery.GenerateFilterConditionForInt("Status", QueryComparisons.Equal, AuditTracker.ErrorStatusCode));
                tableQuery = TableAzureQueryHelper.AddCondition(tableQuery, TableOperators.And, TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.GreaterThanOrEqual, this.TrackingTimeStart));
                tableQuery = TableAzureQueryHelper.AddCondition(tableQuery, TableOperators.And, TableQuery.GenerateFilterConditionForDate("Timestamp", QueryComparisons.LessThanOrEqual, signalTime));

                tableQueryList.Add(tableQuery);
            }

            return(tableQueryList);
        }
        public List <UserAccessRequest> GetUserAccessRequests(IEnumerable <TableQuery <DynamicTableEntity> > tableQueryList)
        {
            List <UserAccessRequest> accessRequests = new List <UserAccessRequest>();

            string userName = "******";
            string location = "City";

            try
            {
                Parallel.ForEach(
                    tableQueryList,
                    (tableQuery) =>
                {
                    IEnumerable <DynamicTableEntity> partialResult = this.azureTableOperation.GetTableEntityProjection(this.TableName, tableQuery);

                    if (partialResult != null)
                    {
                        foreach (var userRequest in partialResult)
                        {
                            string userId = userRequest[UserAccessRequestTracker.UserIdKey].StringValue;
                            TableQuery <DynamicTableEntity> query = new TableQuery <DynamicTableEntity>();

                            query.SelectColumns = new List <string> {
                                userName, location
                            };

                            query = TableAzureQueryHelper.AddCondition(query, QueryComparisons.Equal, TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, "1"));
                            query = TableAzureQueryHelper.AddCondition(query, QueryComparisons.Equal, TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, userId));

                            DynamicTableEntity user = this.azureTableOperation.GetTableEntityProjection(this.UserProfileTable, query).FirstOrDefault();

                            if (user != null)
                            {
                                lock (lockObj)
                                {
                                    string currentAccessLevel   = Enum.GetName(typeof(AccessLevels), userRequest[UserAccessRequestTracker.CurrentAccessLevel].Int32Value);
                                    string requestedAccessLevel = Enum.GetName(typeof(AccessLevels), userRequest[UserAccessRequestTracker.RequestedAccessLevel].Int32Value);

                                    accessRequests.Add(
                                        new UserAccessRequest(
                                            user[userName].StringValue,
                                            user[location].StringValue,
                                            currentAccessLevel,
                                            requestedAccessLevel,
                                            userRequest[UserAccessRequestTracker.RegulatoryBodyKey].StringValue,
                                            userRequest[UserAccessRequestTracker.JustificationText].StringValue));
                                }
                            }
                        }
                    }
                });
            }
            catch (System.AggregateException ex)
            {
                if (!(ex.InnerException is StorageException))
                {
                    throw;
                }

                System.Diagnostics.Trace.TraceError(ex.ToString());
            }

            return(accessRequests);
        }