當前位置: 首頁>>代碼示例>>C#>>正文


C# Bot.Dispose方法代碼示例

本文整理匯總了C#中Bot.Dispose方法的典型用法代碼示例。如果您正苦於以下問題:C# Bot.Dispose方法的具體用法?C# Bot.Dispose怎麽用?C# Bot.Dispose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Bot的用法示例。


在下文中一共展示了Bot.Dispose方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main


//.........這裏部分代碼省略.........
            }

            // Add file logging
            FileTarget fileTarget = new FileTarget();
            fileTarget.Layout =
                "${longdate}|${level:uppercase=true}|${logger}|${message}|${exception:maxInnerExceptionLevel=5}";
            fileTarget.FileName = Path.Combine(BasePath, _logFile);
            LoggingRule fileRule = new LoggingRule("*", LogLevel.Warn, fileTarget);
            LogManager.Configuration.AddTarget("File", fileTarget);
            LogManager.Configuration.LoggingRules.Add(fileRule);
            LogManager.Configuration.Reload();

            // Bootstrap dependencies
            _bootstrapper = new AppBootstrapper();

            // Open configuration
            IStorageManager storage = CompositionManager.Get<IStorageManager>(new NamedParameter("path",
                Path.Combine(BasePath, _storagePath)), new NamedParameter("extension", _storageExtension),
                new NamedParameter("globalFile", _globalStorageFile));

            // Create command manager
            ICommandManager command = CompositionManager.Get<ICommandManager>();
            command.Add(CommandBuilder.CreateConverter<String, ICommand, ConversionContext>(
                (str, context) => context.Bot.Command.GetUnambigousCommand(str))
            );
            command.Add(CommandBuilder.CreateConverter<String, IEnumerable<ICommand>, ConversionContext>(
                (str, context) => context.Bot.Command.GetUnambigousCommands(str))
            );
            command.Add(CommandBuilder.CreateConverter<String, IPlugin, ConversionContext>(
                (str, context) => context.Bot.Plugin.Get(str))
            );
            command.Add(CommandBuilder.CreateConverter<String, IChannel, ConversionContext>(
                (str, context) => context.Message.Connection.GetExistingChannel(str))
            );
            command.Add(CommandBuilder.CreateConverter<String, IUser, ConversionContext>(
                (str, context) => context.Message.Connection.GetExistingUser(str))
            );
            command.Add(CommandBuilder.CreateConverter<String, IChannelUser, ConversionContext>(
                (str, context) => (context.Message.Receiver as IChannel).GetUser(str))
            );
            command.Add(CommandBuilder.CreateConverter<String, IdentityMask, ConversionContext>(
                (str, context) => IdentityMask.Parse(str))
            );
            command.Add(CommandBuilder.CreateConverter<String, IIdentity, ConversionContext>(
                (str, context) => Identity.Parse(str))
            );
            command.Add(CommandBuilder.CreateConverter<String, IBotGroup, ConversionContext>(
                (str, context) => context.Bot.Authentication.GetGroup(str))
            );
            command.Add(CommandBuilder.CreateConverter<String, IBotUser, ConversionContext>(
                (str, context) => context.Bot.Authentication.GetUser(str))
            );

            // Create authentication manager
            IAuthenticationManager authentication = CompositionManager.Get<IAuthenticationManager>();

            // Create permission manager
            IPermissionManager permission = CompositionManager.Get<IPermissionManager>();

            // Create plugin manager
            IPluginManager plugin = CompositionManager.Get<IPluginManager>();

            // Create bot
            IClient client = CompositionManager.Get<IClient>();
            Bot bot = new Bot(client, storage, command, plugin, authentication, permission);
            GetAssemblies().Do(x => plugin.Load(x, bot));
            bot.Init();
            if(bot.Connections.IsEmpty())
            {
                Console.WriteLine("No connections have been set up yet, adding a connection now.");

                Console.WriteLine("Server address?");
                String address = Console.ReadLine();
                Console.WriteLine("Server port?");
                ushort port = Convert.ToUInt16(Console.ReadLine());

                Console.WriteLine("Nickname?");
                String nickname = Console.ReadLine();
                Console.WriteLine("Username?");
                String username = Console.ReadLine();
                Console.WriteLine("Real name?");
                String realname = Console.ReadLine();
                Console.WriteLine("Password? (leave empty for no password)");
                String password = Console.ReadLine();

                bot.Connect(address, port, nickname, username, realname, password);
            }

            // Loop
            bool run = true;
            Console.CancelKeyPress += (s, e) => { e.Cancel = true; run = false; };
            while(run)
            {
                Thread.Sleep(50);
            }

            // Clean up
            bot.Dispose();
            storage.Dispose();
        }
開發者ID:Gohla,項目名稱:Veda,代碼行數:101,代碼來源:Program.cs


注:本文中的Bot.Dispose方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。