Beispiel #1
0
        public void PingPortals()
        {
            var  clientIps = ClientIpValues.GetClientIps();
            var  clientIp  = new ClientIp();
            Ping pinger    = new Ping();

            try
            {
                clientIps.ForEach(p => {
                    clientIp        = p;
                    var ip          = _context.ClientIp.FirstOrDefault(c => c.Ip.ToLower().Equals(clientIp.Ip.ToLower()));
                    PingReply reply = pinger.Send(p.Ip);
                    ip.Fails        = 0;
                });
                _context.SaveChanges();
            }
            catch (PingException)
            {
                var ip = _context.ClientIp.FirstOrDefault(c => c.Ip.ToLower().Equals(clientIp.Ip.ToLower()));
                if (ip.Fails < 2)
                {
                    ip.Fails = ip.Fails + 1;
                }
                else
                {
                    ip.Fails = 0;
                    //NotifyPortalDown(ip);
                }
                _context.SaveChanges();
            }
            pinger.Dispose();
        }
        public static void EnsureDatabaseSeeded(this PortalCoreContext context)
        {
            if (!context.UserGroups.Any())
            {
                context.Add(
                    new UserGroups
                {
                    GroupName = "AbnAdmin",
                    Role      = Role.Admin,
                    IsDefault = true,
                    Status    = true
                }
                    );
                context.SaveChanges();
            }

            var adminGroup = context.UserGroups.FirstOrDefault(k => k.Role == Role.Admin);
            var admin      = new User
            {
                EmailConfirmed = true,
                UserName       = "******",
                Email          = "*****@*****.**",
                UserGroupsId   = adminGroup.Id,
                PasswordHash   = "$SOL$V1$10000$JV1G9YBlnZ9xrEiX05eMGL8P1DBZsu+Vur2pt1o8IiyT4pfe",
                //PasswordHash = SecurePasswordHasher.Hash("123456"),
                Code        = "493ddc84-a8b4-47ff-a3b3-ecd07bf125fa",
                DateCreated = DateTime.Now,
                Role        = Role.Admin,
                Status      = true,
            };

            var adminExists = context.Users.FirstOrDefault(u => u.UserName == admin.UserName);

            if (adminExists == null)
            {
                context.Add(admin);
            }
            else
            {
                adminExists.Status = true;
                context.Update(adminExists);
            }

            var settings = context.Settings.FirstOrDefault();

            if (settings == null)
            {
                context.Add(
                    new Settings()
                {
                    Name                   = "University of ABNO",
                    LogoImageUrl           = "/assets/images/logo.jpg",
                    ThemeColor             = "#003472",
                    SecondaryColor         = "#003472",
                    LoginMessageTitle      = "Community of learners",
                    loginMessage           = "Login message here",
                    loginImageUrl          = "/assets/images/banner.jpg",
                    EmailUserName          = "******",
                    SmtpClient             = "smtp.office365.com",
                    Password               = "******",
                    Port                   = "587",
                    ClassStatus            = "Active",
                    LeaveRelieverMandatory = true,
                    IsGenesis              = true
                }
                    );
            }

            if (!context.UserGroupPrivileges.Any())
            {
                context.AddRange(
                    PrivilegeValues.AddPrivilegesList()
                    );
            }

            if (!context.PortalConfigs.Any())
            {
                context.AddRange(
                    StudentPortalConfigs.AddConfigsToList()
                    );
            }
            var clintIps = ClientIpValues.GetClientIps();

            clintIps.ForEach(i => {
                if (!context.ClientIp.Any(c => c.Ip.ToLower().Equals(i.Ip.ToLower())))
                {
                    context.ClientIp.Add(i);
                }
            });

            context.SaveChanges();
        }