Пример #1
0
        /// <summary>
        /// Get a user from storage by its given user principal
        /// </summary>
        /// <param name="iUserPrincipal">User principal of the user to get</param>
        /// <returns>The requested user, if found in storage, otherwise null</returns>
        public async Task <User> GetUserAsync(ClaimsPrincipal iUserPrincipal)
        {
            Boolean pBlnCreatedTable = await UsersTable.CreateIfNotExistsAsync();

            TableResult pTRtResult = new TableResult()
            {
                HttpStatusCode = 404
            };

            if (pBlnCreatedTable)
            {
                return(null);
            }
            else
            {
                String         pStrPartitionKey = iUserPrincipal.GetUserPartitionKey(ClaimsPrincipalExtensions.KeySource.email);
                String         pStrRowKey       = iUserPrincipal.GetUserRowKey(ClaimsPrincipalExtensions.KeySource.email);
                TableOperation pTOnRetrieve     = TableOperation.Retrieve <User>(pStrPartitionKey, pStrRowKey);
                pTRtResult = UsersTable.Execute(pTOnRetrieve);
                switch (pTRtResult.HttpStatusCode)
                {
                case 200:
                {
                    return((User)pTRtResult.Result);
                }
                }
                return(null);
            }
        }
Пример #2
0
        public AManager()
        {
            CloudStorageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
            CloudTableClient    = CloudStorageAccount.CreateCloudTableClient();

            UsersTable = CloudTableClient.GetTableReference("UsersTable");
            UsersTable.CreateIfNotExistsAsync();

            VPackagesTable = CloudTableClient.GetTableReference("VPackagesTable");
            VPackagesTable.CreateIfNotExistsAsync();

            PackagesTable = CloudTableClient.GetTableReference("PackagesTable");
            PackagesTable.CreateIfNotExistsAsync();

            UsersRequests     = new UsersRequests(this);
            VPackagesRequests = new VPackageRequests(this);
            PackagesRequests  = new VPackageRequests(this);
        }
Пример #3
0
        /// <summary>
        /// Insert an instance of User into storage asynchronously
        /// </summary>
        /// <param name="iUser">The instance of user to insert</param>
        /// <returns>True if the insert was successful</returns>
        public async Task <Boolean> InsertUserAsync(User iUser)
        {
            Boolean pBlnCreatedTable = await UsersTable.CreateIfNotExistsAsync();

            if (pBlnCreatedTable)
            {
                return(false);
            }
            else
            {
                TableOperation pTOnInsert = TableOperation.Insert(iUser);
                TableResult    pTRtResult;
                try
                {
                    pTRtResult = await UsersTable.ExecuteAsync(pTOnInsert);

                    switch (pTRtResult.HttpStatusCode)
                    {
                    case 200:
                    case 204:
                    {
                        Boolean pBlnRetVal;
                        pBlnRetVal = CreateDefaultUserProfile(iUser);
                        return(pBlnRetVal);
                    }

                    default:
                    {
                        return(false);
                    }
                    }
                }
                catch
                {
                    return(false);
                }
            }
        }