Example #1
0
 public void RebuildList()
 {
     if (rootuser is null)
     {
         AllUsers = new List <User>();
     }
     else
     {
         AllUsers = RootUser?.GetAllSubUsers();
     }
 }
        public async Task TestEnableRootUser()
        {
            IDatabaseService provider = CreateProvider();

            using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TestTimeout(TimeSpan.FromSeconds(600))))
            {
                ReadOnlyCollection <DatabaseFlavor> flavors = await provider.ListFlavorsAsync(cancellationTokenSource.Token);

                if (flavors.Count == 0)
                {
                    Assert.Inconclusive("The service did not report any flavors.");
                }

                DatabaseFlavor smallestFlavor = flavors.Where(i => i.Memory.HasValue).OrderBy(i => i.Memory).First();
                string         instanceName   = CreateRandomDatabaseInstanceName();
                DatabaseInstanceConfiguration configuration = new DatabaseInstanceConfiguration(smallestFlavor.Href, new DatabaseVolumeConfiguration(1), instanceName);
                DatabaseInstance instance = await provider.CreateDatabaseInstanceAsync(configuration, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null);

                bool?enabled = await provider.CheckRootEnabledStatusAsync(instance.Id, cancellationTokenSource.Token);

                Assert.IsNotNull(enabled);
                Assert.IsFalse(enabled.Value);

                RootUser rootUser = await provider.EnableRootUserAsync(instance.Id, cancellationTokenSource.Token);

                Assert.IsNotNull(rootUser);
                Assert.IsFalse(string.IsNullOrEmpty(rootUser.Name));
                Assert.IsFalse(string.IsNullOrEmpty(rootUser.Password));

                enabled = await provider.CheckRootEnabledStatusAsync(instance.Id, cancellationTokenSource.Token);

                RootUser anotherRootUser = await provider.EnableRootUserAsync(instance.Id, cancellationTokenSource.Token);

                Assert.IsNotNull(anotherRootUser);
                Assert.IsFalse(string.IsNullOrEmpty(rootUser.Name));
                Assert.IsFalse(string.IsNullOrEmpty(rootUser.Password));

                /* Cleanup
                 */
                await provider.RemoveDatabaseInstanceAsync(instance.Id, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null);
            }
        }
Example #3
0
        private bool LoadResponseUser(string response, object value)
        {
            if (response.Contains("{\"error\""))
            {
                return(ErrorResponse(response, "Error Load Response Fields"));
            }

            BaseRoot valueRoot = (BaseRoot)value;

            try
            {
                RootUser rootUser = JsonConvert.DeserializeObject <RootUser>(response);
                if (rootUser.users != null)
                {
                    Predicate <User> filter = s => s.email.Equals(valueRoot.Authentication.Email);
                    if (rootUser.users.user.Exists(e => filter(e)))
                    {
                        User user = rootUser.users.user.Where(w => filter(w)).First();
                        return(OnLoadReponseUser(user, value));
                    }
                }
            }
            catch (JsonSerializationException) { }

            try
            {
                RootUserSimple userSimple = JsonConvert.DeserializeObject <RootUserSimple>(response);
                if (userSimple.users != null)
                {
                    User user = userSimple.users.user;
                    if (user.email.Equals(valueRoot.Authentication.Email))
                    {
                        return(OnLoadReponseUser(userSimple.users.user, value));
                    }
                }
            }
            catch (JsonSerializationException) { }

            return(false);
        }
Example #4
0
 public Task EditAppUserAsync(RootUser rootUser)
 {
     _context.RootUsers.Update(rootUser);
     return(_context.SaveChangesAsync());
 }
Example #5
0
 public Task DeleteAppUserAsync(RootUser rootUser)
 {
     _context.RootUsers.Remove(rootUser);
     return(_context.SaveChangesAsync());
 }
Example #6
0
        public async Task AddAppUserAsync(RootUser rootUser)
        {
            await _context.RootUsers.AddAsync(rootUser);

            await _context.SaveChangesAsync();
        }
Example #7
0
        /// <summary>Generates the trace image. Caches it to TraceImage property before returning it</summary>
        /// <returns></returns>
        public Image GenerateTraceImage()
        {
            int BaseWidth;
            int BaseHeight;

            if (RootUser != null)
            {
                BaseWidth  = RootUser.TotalWidth();
                BaseHeight = RootUser.TotalHeight();
            }
            else
            {
                BaseWidth  = 0;
                BaseHeight = 0;
            }

            //now we're going to add like 100 to the left side, and 100 to the right, meaning the real width will be 200+BaseWidth
            //And we're going to add like 128 +10 + 10 to the top, not to the bottom, meaning the real height will be 148+BaseHeight
            //you know what +10 to the bottom because why not.

            traceImage = new Bitmap(Math.Max(200 + BaseWidth, 640), Math.Max(148 + BaseHeight + 10, 480));

            //Now let's throw in the tile background.
            int      x;
            int      y   = 0;
            Graphics GRD = Graphics.FromImage(traceImage);

            while (y < traceImage.Size.Height)
            {
                x = 0;
                while (x < traceImage.Size.Width)
                {
                    GRD.DrawImage(TileBackground, x, y);
                    x += TileBackground.Width;
                }
                y += TileBackground.Height;
            }

            //ok now let's add the server info
            Image SmolServerLogo = new Bitmap(ServerLogo, 128, 128);

            GRD.DrawImage(SmolServerLogo, 10, 10);

            Brush TheBrush = new SolidBrush(Color.White);

            FontFamily Arial = new FontFamily("Arial");

            Font BigText   = new Font(Arial, 48, FontStyle.Bold, GraphicsUnit.Point);
            Font SmallText = new Font(Arial, 16, FontStyle.Regular, GraphicsUnit.Point);

            string CreateDateString = "Created: " + ServerCreationDate.Month + "/" + ServerCreationDate.Day + "/" + ServerCreationDate.Year;

            SizeF ServerNameSize = GRD.MeasureString(ServerName, BigText);

            GRD.DrawString(ServerName, BigText, TheBrush, 128 + 10 + 10, 10 + 15);
            GRD.DrawString(CreateDateString, SmallText, TheBrush, 128 + 10 + 18, 10 + 15 + ServerNameSize.Height);

            //now we can kick off the drawing process.
            if (rootuser == null)
            {
                return(TraceImage);
            }
            DrawTrace(RootUser, 100, 148, GRD);


            return(traceImage);
        }