Esempio n. 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 User GetUser(ClaimsPrincipal iUserPrincipal)
        {
            Boolean     pBlnCreatedTable = UsersTable.CreateIfNotExists();
            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);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Insert an instance of User into storage
        /// </summary>
        /// <param name="iUser">The instance of user to insert</param>
        /// <returns>True if the insert was successful</returns>
        public Boolean InsertUser(User iUser)
        {
            Boolean pBlnCreatedTable = UsersTable.CreateIfNotExists();

            try
            {
                TableOperation pTOnInsert = TableOperation.Insert(iUser);
                TableResult    pTRtResult = UsersTable.Execute(pTOnInsert);
                switch (pTRtResult.HttpStatusCode)
                {
                case 200:
                case 204:
                {
                    Boolean pBlnRetVal;
                    pBlnRetVal = CreateDefaultUserProfile(iUser);
                    return(pBlnRetVal);
                }

                default:
                {
                    return(false);
                }
                }
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 3
0
        public static void Initialize()
        {
            PapersTable = getTable("vtPapers");
            if (PapersTable != null)
            {
                PapersTable.CreateIfNotExists();
            }

            TalliesTable = getTable("vtTallies");
            if (TalliesTable != null)
            {
                TalliesTable.CreateIfNotExists();
            }

            UsersTable = getTable("vtUsers");
            if (UsersTable != null)
            {
                UsersTable.CreateIfNotExists();
            }

            TotalsTable = getTable("vtTotals");
            if (TotalsTable != null)
            {
                TotalsTable.CreateIfNotExists();
            }

            RecordsTable = getTable("vtRecords");
            if (RecordsTable != null)
            {
                RecordsTable.CreateIfNotExists();
            }

            TagScrollsTable = getTable("vtTagScrolls");
            if (TagScrollsTable != null)
            {
                TagScrollsTable.CreateIfNotExists();
            }

            PictureContainer = getContainer("picture1");

            TalliesPartitionPond = new TablePartitionPond <TallyInfo>(TalliesTable);
            TotalsPartitionPond  = new TablePartitionPond2 <TallyInfo>(TotalsTable);
            TagScrollsPond       = new TablePartitionPond2 <TaggedVoteInfo>(TagScrollsTable);

            Random = new Random();
        }