예제 #1
0
        public void Bootstrap()
        {
            var _fs = new Filesystem(Directory.GetCurrentDirectory());

            Console.WriteLine("[I] Bootstrap...");
            AccessProvider.ProviderResponse     += Handle_Provider_Event;
            ServerProvider.ProviderResponse     += Handle_Provider_Event;
            ClientProvider.ProviderResponse     += Handle_Provider_Event;
            UserProvider.ProviderResponse       += Handle_Provider_Event;
            NewsProvider.ProviderResponse       += Handle_Provider_Event;
            NavigationProvider.ProviderResponse += Handle_Provider_Event;

            if (!Directory.Exists(Path.Combine(_fs.Root, "Providers")))
            {
                Directory.CreateDirectory(Path.Combine(_fs.Root, "Providers"));
                Console.WriteLine("[I] Provider installation needed..., Bootstrapping them...");
            }

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "System",
                Level    = ulong.MaxValue,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "Server-Administratoren",
                Level    = byte.MaxValue,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "Server-Operatoren",
                Level    = 250,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "Seiten-Administroren",
                Level    = 245,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "Seiten-Operatoren",
                Level    = 240,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "News-Administratoren",
                Level    = 235,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "News-Operatoren",
                Level    = 230,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "Sendeplan-Administratoren",
                Level    = 225,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "Sendeplan-Operatoren",
                Level    = 220,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "Stream-Administratoren",
                Level    = 215,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "Stream-Operatoren",
                Level    = 210,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "Seiten-Mitglied",
                Level    = 1,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            AccessProvider.Add(Guid.NewGuid(), new GroupEntry <Guid>()
            {
                Active   = true,
                Name     = "Unregistriert",
                Level    = byte.MinValue,
                Locked   = true,
                Provider = AccessProvider.Name,
            });

            #region "News Provider - Installation"


            var news_user = Guid.Empty;
            var xmlDoc    = new XmlDocument();
            xmlDoc.Load(NewsProvider.InstallScript);
            var newsEntries = xmlDoc.SelectNodes("Namiono/Install/Users/User");

            for (var i = 0; i < newsEntries.Count; i++)
            {
                var res_level = ulong.MinValue;


                var user = new UserEntry <Guid>
                {
                    Id                                 = newsEntries[i].Attributes["Id"] == null?Guid.NewGuid() : Guid.Parse(newsEntries[i].Attributes["Id"].Value),
                                             Name      = newsEntries[i].Attributes["Name"].Value,
                                             Service   = bool.Parse(newsEntries[i].Attributes["Service"].Value == "0" ? "false" : "true"),
                                             Moderator = bool.Parse(newsEntries[i].Attributes["Moderator"].Value == "0" ? "false" : "true"),
                                             Locked    = bool.Parse(newsEntries[i].Attributes["Locked"].Value == "0" ? "false" : "true"),
                                             Password  = MD5.GetMD5Hash(newsEntries[i].Attributes["Password"].Value),
                                             Provider  = UserProvider.Name
                };

                if (newsEntries[i].Attributes["Level"] != null)
                {
                    ulong.TryParse(newsEntries[i].Attributes["Level"].Value, out res_level);
                    user.Level = res_level;
                }

                news_user = user.Id;

                UserProvider.Add(user.Id, user);
            }

            newsEntries = xmlDoc.SelectNodes("Namiono/Install/Entries/Entry");

            for (var i = 0; i < newsEntries.Count; i++)
            {
                var res_level = ulong.MinValue;

                var news = new NewsEntry <Guid>
                {
                    Name      = newsEntries[i].Attributes["Name"].Value,
                    Service   = bool.Parse(newsEntries[i].Attributes["Service"].Value == "0" ? "false" : "true"),
                    Moderator = bool.Parse(newsEntries[i].Attributes["Moderator"].Value == "0" ? "false" : "true"),
                    Locked    = bool.Parse(newsEntries[i].Attributes["Locked"].Value == "0" ? "false" : "true"),
                    OutPut    = newsEntries[i].Attributes["Output"].Value.Replace("[[NL]]", "<br />"),
                    Url       = newsEntries[i].Attributes["Url"].Value,
                    Author    = news_user
                };

                if (newsEntries[i].Attributes["Level"] != null)
                {
                    ulong.TryParse(newsEntries[i].Attributes["Level"].Value, out res_level);
                    news.Level = res_level;
                }


                NewsProvider.Add(Guid.NewGuid(), news);
            }

            #endregion

            #region "Navigation Provider - Installation"
            xmlDoc.Load(NavigationProvider.InstallScript);

            var navEntries = xmlDoc.SelectNodes("Namiono/Install/Entries/Entry");

            for (var i = 0; i < navEntries.Count; i++)
            {
                var res_level = ulong.MinValue;

                var nav = new NavigationEntry <Guid>
                {
                    Name      = navEntries[i].Attributes["Name"].Value,
                    Service   = bool.Parse(navEntries[i].Attributes["Service"].Value == "0" ? "false" : "true"),
                    Moderator = bool.Parse(navEntries[i].Attributes["Moderator"].Value == "0" ? "false" : "true"),
                    Locked    = bool.Parse(navEntries[i].Attributes["Locked"].Value == "0" ? "false" : "true"),
                    OutPut    = navEntries[i].Attributes["Output"].Value.Replace("[[NL]]", "<br />"),
                    Url       = navEntries[i].Attributes["Url"].Value,
                    Author    = Guid.Empty
                };

                if (navEntries[i].Attributes["Level"] != null)
                {
                    ulong.TryParse(navEntries[i].Attributes["Level"].Value, out res_level);
                    nav.Level = res_level;
                }


                NavigationProvider.Add(Guid.NewGuid(), nav);
            }


            NavigationProvider.Add(Guid.NewGuid(), new NavigationEntry <Guid>()
            {
                Name = "Mitglieder", Active = true, Locked = false, Level = 1, Frame = "#content", Provider = UserProvider.Name, Action = "show"
            });
            NavigationProvider.Add(Guid.NewGuid(), new NavigationEntry <Guid>()
            {
                Name = "News", Active = true, Locked = false, Level = 1, Frame = "#content", Provider = NewsProvider.Name, Action = "show"
            });

            #endregion
            AccessProvider.Bootstrap();
            ServerProvider.Bootstrap();
            ClientProvider.Bootstrap();
            UserProvider.Bootstrap();
            NewsProvider.Bootstrap();
            NavigationProvider.Bootstrap();



            Console.WriteLine("[I] Starting ...");
        }