예제 #1
0
        protected override void Seed(PlayoutDbContext context)
        {
            base.Seed(context);
            var nullApp = new ApplicationInfo {
                Name = PlayoutDbContext.DefaultName
            };

            context.Applications.Add(nullApp);

            var nullMachine = new MachineInfo {
                Name = PlayoutDbContext.DefaultName
            };

            context.Machines.Add(nullMachine);

            context.SettingGroups.Add(new SettingGroup {
                Name = PlayoutDbContext.DefaultName
            });
            context.SettingScopes.Add(new SettingScope {
                ApplicationName = PlayoutDbContext.DefaultName, MachineName = PlayoutDbContext.DefaultName
            });

            //context.ChannelInfos.Add(new ChannelInfo { Title = PlayoutDbContext.DefaultName, Special = true });

            Role adminRole = null;

            foreach (var roleName in RoleNames.AllRoleNames)
            {
                var role = new Role {
                    Name = roleName
                };
                if (roleName == RoleNames.Admin)
                {
                    adminRole = role;
                }
                context.Roles.Add(role);
            }

            context.Users.Add(new UserEntity
            {
                Name     = "admin",
                Password = "******",
                Locked   = false,
                Roles    = new List <Role> {
                    adminRole
                }
            });
        }
예제 #2
0
        public static void Register(string machineName, string applicationName)
        {
            using (var context = new PlayoutDbContext())
            {
                bool        changed    = false;
                var         machines   = context.Machines.ToList();
                var         machine    = machines.SingleOrDefault(m => m.Name == machineName);
                MachineInfo newMachine = null;
                if (machine == null)
                {
                    newMachine = new MachineInfo {
                        Name = machineName
                    };
                    context.Machines.Add(newMachine);

                    foreach (var app in context.Applications)
                    {
                        context.SettingScopes.Add(new SettingScope {
                            ApplicationName = app.Name, MachineName = machineName
                        });
                    }
                    changed = true;
                }

                var application = context.Applications.SingleOrDefault(a => a.Name == applicationName);
                if (application == null)
                {
                    context.Applications.Add(new ApplicationInfo {
                        Name = applicationName
                    });
                    bool found = false;
                    foreach (var mac in context.Machines.Local)
                    {
                        if (mac == newMachine)
                        {
                            found = true;
                        }
                        context.SettingScopes.Add(new SettingScope {
                            ApplicationName = applicationName, MachineName = mac.Name
                        });
                    }

                    if (newMachine != null && !found)
                    {
                        Debug.WriteLine("未发现新的MachineName");

                        context.SettingScopes.Add(new SettingScope {
                            ApplicationName = applicationName, MachineName = machineName
                        });
                    }
                    else
                    {
                        Debug.WriteLine("已发现新的MachineName");
                    }
                    changed = true;
                }

                if (changed)
                {
                    context.SaveChanges();
                }
            }
        }