Encode() 공개 정적인 메소드

Encode a string to ensure that it can safely be used as a PartitionKey or RowKey in an AzureTable
public static Encode ( string unsafeForUseAsAKey ) : string
unsafeForUseAsAKey string A string that may contain characters that are forbidden for use in an AzureTable PartitionKey or RowKey.
리턴 string
예제 #1
0
        public override async Task <bool> AddIncorrectPhaseTwoHashAsync(
            DbUserAccount userAccount,
            string phase2Hash, DateTime?whenSeenUtc = null,
            CancellationToken cancellationToken     = default(CancellationToken))
        {
            // Retrieve a reference to the table.
            CloudTable table = await GetTableAsync(TableName_RecentIncorrectPhase2Hashes, cancellationToken);

            TableOperation retriveOperation =
                TableOperation.Retrieve <IncorrectPhaseTwoHashEntity>(TableKeyEncoding.Encode(phase2Hash),
                                                                      TableKeyEncoding.Encode(userAccount.UsernameOrAccountId));

            TableResult retrievedResult = await table.ExecuteAsync(retriveOperation, getTableRequestOptions(200), getOperationContext(), cancellationToken);

            if (retrievedResult.Result != null)
            {
                return(true);
            }

            // Write the hash to azure tables in the background.
            TaskHelper.RunInBackground(
                table.ExecuteAsync(
                    TableOperation.InsertOrReplace(new IncorrectPhaseTwoHashEntity(userAccount.UsernameOrAccountId, phase2Hash, whenSeenUtc)),
                    getTableRequestOptions(), getOperationContext(), cancellationToken)
                );

            return(false);
        }
예제 #2
0
        public override async Task <bool> HasClientWithThisHashedCookieSuccessfullyLoggedInBeforeAsync(
            DbUserAccount userAccount,
            string hashOfCookie,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            // Retrieve a reference to the table.
            CloudTable table = await GetTableAsync(TableName_SuccessfulLoginCookie, cancellationToken);

            //TableQuery<IncorrectPhaseTwoHashEntity> query = new TableQuery<IncorrectPhaseTwoHashEntity>().Where(TableQuery.CombineFilters(
            //        TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, TableKeyEncoding.Encode(hashOfCookie)),
            //        TableOperators.And,
            //        TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, TableKeyEncoding.Encode(UsernameOrAccountId))));

            var query =
                (from e in table.CreateQuery <SuccessfulLoginCookieEntity>()
                 where e.PartitionKey == TableKeyEncoding.Encode(hashOfCookie) &&
                 e.RowKey == TableKeyEncoding.Encode(userAccount.UsernameOrAccountId)
                 select e).AsTableQuery();

            int count = 0;

            TableContinuationToken continuationToken = null;

            do
            {
                var partialResult = await query.ExecuteSegmentedAsync(continuationToken, cancellationToken);

                count            += partialResult.Results.Count;
                continuationToken = partialResult.ContinuationToken;
            } while (continuationToken != null);

            return(count > 0);
        }
예제 #3
0
        public override async Task <bool> HasClientWithThisHashedCookieSuccessfullyLoggedInBeforeAsync(
            DbUserAccount userAccount,
            string hashOfCookie,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            // Retrieve a reference to the table.
            CloudTable table = await GetTableAsync(TableName_SuccessfulLoginCookie, cancellationToken);

            TableOperation retriveOperation =
                TableOperation.Retrieve <SuccessfulLoginCookieEntity>(TableKeyEncoding.Encode(hashOfCookie),
                                                                      TableKeyEncoding.Encode(userAccount.UsernameOrAccountId));

            TableResult retrievedResult = await table.ExecuteAsync(retriveOperation, getTableRequestOptions(200), getOperationContext(), cancellationToken);

            return(retrievedResult.Result != null);
        }
예제 #4
0
        public override async Task <bool> AddIncorrectPhaseTwoHashAsync(
            DbUserAccount userAccount,
            string phase2Hash, DateTime?whenSeenUtc = null,
            CancellationToken cancellationToken     = default(CancellationToken))
        {
            // Retrieve a reference to the table.
            CloudTable table = await GetTableAsync(TableName_RecentIncorrectPhase2Hashes, cancellationToken);

            //TableQuery<IncorrectPhaseTwoHashEntity> query = new TableQuery<IncorrectPhaseTwoHashEntity>().Where(TableQuery.CombineFilters(
            //        TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, TableKeyEncoding.Encode(phase2Hash)),
            //        TableOperators.And,
            //        TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.Equal, TableKeyEncoding.Encode(UsernameOrAccountId)) ));

            var query =
                (from e in table.CreateQuery <IncorrectPhaseTwoHashEntity>()
                 where e.PartitionKey == TableKeyEncoding.Encode(phase2Hash) &&
                 e.RowKey == TableKeyEncoding.Encode(userAccount.UsernameOrAccountId)
                 select e).AsTableQuery();

            int count = 0;

            TableContinuationToken continuationToken = null;

            do
            {
                var partialResult = await query.ExecuteSegmentedAsync(continuationToken, cancellationToken);

                count            += partialResult.Results.Count;
                continuationToken = partialResult.ContinuationToken;
            } while (continuationToken != null);

            if (count > 0)
            {
                // This phase2 hash already exists.
                return(true);
            }

            // Write the hash to azure tables in the background.
            TaskHelper.RunInBackground(
                table.ExecuteAsync(
                    TableOperation.InsertOrReplace(new IncorrectPhaseTwoHashEntity(userAccount.UsernameOrAccountId, phase2Hash, whenSeenUtc)),
                    cancellationToken)
                );

            return(false);
        }
예제 #5
0
 public SuccessfulLoginCookieEntity(string usernameOrAccountId, string hashOfCookie, DateTime?lastSeenUtc = null)
 {
     PartitionKey = TableKeyEncoding.Encode(hashOfCookie);
     RowKey       = TableKeyEncoding.Encode(usernameOrAccountId);
     LastSeenUtc  = lastSeenUtc ?? DateTime.UtcNow;
 }
 public IncorrectPhaseTwoHashEntity(string usernameOrAccountId, string hashValue, DateTime?lastSeenUtc = null)
 {
     PartitionKey = TableKeyEncoding.Encode(hashValue);
     RowKey       = TableKeyEncoding.Encode(usernameOrAccountId);
     LastSeenUtc  = lastSeenUtc ?? DateTime.UtcNow;
 }