Beispiel #1
0
        public static bool Load(bool forceCompilation = false)
        {
            Logger.LogOperationStart("Loading chat channels");

            NormalChannels  = new Dictionary <ushort, ChatChannel>();
            PrivateChannels = new Dictionary <ushort, PrivateChatChannel>();
            PartyChannels   = new Dictionary <ushort, ChatChannel>();
            GuildChannels   = new Dictionary <uint, ChatChannel>();

            Assembly      chatAssembly;
            List <string> externalAssemblies = new List <string>();

            externalAssemblies.Add(Assembly.GetExecutingAssembly().Location);
            bool redFromCache;

            if (!ScriptManager.CompileCsScripts("Data/ChatChannels", "ChatChannels.*.dll", externalAssemblies, out chatAssembly, out redFromCache, forceCompilation))
            {
                return(false);
            }

            try
            {
                Dictionary <ushort, ChatChannel> channels = new Dictionary <ushort, ChatChannel>();
                foreach (Type chatChannel in chatAssembly.GetTypes())
                {
                    if (chatChannel.BaseType == typeof(ChatChannel))
                    {
                        ChatChannel channel = (ChatChannel)Activator.CreateInstance(chatChannel);
                        channel.Setup();
                        channels.Add(channel.Id, channel);
                    }
                }
                NormalChannels.Clear();
                NormalChannels = channels;
            }
            catch (Exception e)
            {
                if (!forceCompilation)
                {
                    return(Load(true));
                }

                Logger.LogOperationFailed(e.ToString());
                return(false);
            }

            if (redFromCache)
            {
                Logger.LogOperationCached();
            }
            else
            {
                Logger.LogOperationDone();
            }
            return(true);
        }