当前位置: 首页>>代码示例>>C#>>正文


C# Main.SubmitChanges方法代码示例

本文整理汇总了C#中Main.SubmitChanges方法的典型用法代码示例。如果您正苦于以下问题:C# Main.SubmitChanges方法的具体用法?C# Main.SubmitChanges怎么用?C# Main.SubmitChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Main的用法示例。


在下文中一共展示了Main.SubmitChanges方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ImportFile

        public void ImportFile(FileInfo file, Main db)
        {
            using (StreamReader sr = file.OpenText())
            {
                string s;
                var count = 0;
                QuizQuestion question = null;
                while ((s = sr.ReadLine()) != null)
                {
                    s = s.Trim();
                    ++count;

                    // Skip Header
                    if (count < 4) { continue; }

                    if (count % 3 == 1)
                    {
                        question = new QuizQuestion();
                        db.QuizQuestions.InsertOnSubmit(question);

                        // Line 1: Question
                        question.Question = s;
                        if (Language != null)
                        {
                            question.Language = Language;
                        }
                        if (Author != null)
                        {
                            question.Author = Author;
                        }
                    }

                    if (count % 3 == 2 && question != null)
                    {
                        // Line 2: Answer (manual work needed)
                        question.Answer = s;
                        db.SubmitChanges();
                    }

                    if (count % 3 == 0 && question != null && question.ID.HasValue && !s.IsNullOrEmpty())
                    {
                        // Line 3: A Hint
                        var hint = new Hint();
                        db.Hints.InsertOnSubmit(hint);

                        hint.Message = s;
                        hint.QuizQuestionID = question.ID.Value;

                        db.SubmitChanges();
                    }
                }

                db.SubmitChanges();
            }
        }
开发者ID:Avatarchik,项目名称:huffelpuff-irc-bot,代码行数:55,代码来源:KewlQuizImport.cs

示例2: ImportFile

        public void ImportFile(FileInfo file, Main db)
        {
            using (StreamReader sr = file.OpenText())
            {
                string s;
                QuizQuestion question = null;
                bool category = false;
                while ((s = sr.ReadLine()) != null)
                {
                    s = s.Trim();
                    if (s.StartsWith("#") || s.IsNullOrEmpty()) { continue; }

                    if (s.StartsWith("Category:"))
                    {
                        question = new QuizQuestion();
                        db.QuizQuestions.InsertOnSubmit(question);

                        question.Category = s.Substring(9);
                        category = true;
                    }

                    if (s.StartsWith("Question:") && question != null)
                    {
                        if (!category)
                        {
                            question = new QuizQuestion();
                            db.QuizQuestions.InsertOnSubmit(question);
                        }
                        category = false;
                        question.Question = s.Substring(9).Trim();
                    }

                    if (s.StartsWith("Answer:") && question != null)
                    {
                        question.Answer = s.Substring(7).Trim();
                        db.SubmitChanges();
                    }

                    if (s.StartsWith("Regexp:") && question != null)
                    {
                        question.AnswerRegExp = s.Substring(7).Trim();
                    }

                    if (s.StartsWith("Author:") && question != null)
                    {
                        question.Author = s.Substring(7).Trim();
                    }

                    if (s.StartsWith("Level:") && question != null)
                    {
                        switch (s.Substring(6).Trim())
                        {
                            case "baby":
                                question.Difficulty = 0;
                                break;
                            case "easy":
                                question.Difficulty = 3;
                                break;
                            case "normal":
                                question.Difficulty = 5;
                                break;
                            case "hard":
                                question.Difficulty = 8;
                                break;
                            case "extreme":
                                question.Difficulty = 10;
                                break;

                        }
                    }

                    if (s.StartsWith("Comment:") && question != null)
                    {
                        question.Comment = s.Substring(8).Trim();
                    }

                    if (s.StartsWith("Score:") && question != null)
                    {
                        question.Score = int.Parse(s.Substring(6).Trim());
                    }

                    if (s.StartsWith("Tip:") && question != null && question.ID.HasValue && !s.IsNullOrEmpty())
                    {
                        var hint = new Hint();
                        db.Hints.InsertOnSubmit(hint);

                        hint.Message = s.Substring(4).Trim();
                        hint.QuizQuestionID = question.ID.Value;

                        db.SubmitChanges();
                    }
                }
            }
        }
开发者ID:Avatarchik,项目名称:huffelpuff-irc-bot,代码行数:94,代码来源:MoxxQuizImport.cs

示例3: SetupOnce

        private void SetupOnce()
        {
            if (isSetup) return;
            isSetup = true;

            MainBotData = new Main(DatabaseConnection.Create("Huffelpuff"));

            if (MainBotData.Channels.Count() == 0 && !Settings.Default.Channel.IsNullOrEmpty())
            {
                foreach (var channelName in Settings.Default.Channel.Split(','))
                {
                    var channel = new Channel { ChannelName = channelName };
                    MainBotData.Channels.InsertOnSubmit(channel);
                }
            }
            MainBotData.SubmitChanges();

            Encoding = System.Text.Encoding.UTF8;
            SendDelay = 3000;
            PingInterval = 120;
            ActiveChannelSyncing = true;
            OnRawMessage += RawMessageHandler;
            AutoRejoin = true;
            AutoRetry = true;
            AutoRetryDelay = 5;
            SupportNonRfc = true;
            OnChannelMessage += CommandDispatcher;
            OnQueryMessage += CommandDispatcher;
            OnConnected += OnBotConnected;

            CtcpVersion = VersionString + " (SharpIRC " + Assembly.GetAssembly(typeof(IrcFeatures)).GetName(false).Version + ")";
            CtcpUrl = "https://github.com/FreeApophis/huffelpuff-irc-bot";
            CtcpSource = "https://github.com/FreeApophis/huffelpuff-irc-bot";

            // DCC Setup

            /* todo: find NAT / or our IP / sharp-IRC should be able to do that -> implement there */

            //Setting up Access Control
            Acl = new AccessControlList(this);
            Acl.Init();

            // Add Identify Plugin suitable (or all)
            Acl.AddIdentifyPlugin(new NickServIdentify(this));
            Acl.AddIdentifyPlugin(new HostIdentify(this));
            Acl.AddIdentifyPlugin(new PasswordIdentify(this));
            Acl.AddIdentifyPlugin(new NickIdentify(this));

            // Plugin needs the Handlers from IRC we load the plugins after we set everything up
            PlugManager = new BotPluginManager(this, "plugins");
            PlugManager.PluginLoadEvent += PlugManagerPluginLoadEvent;
            PlugManager.StartUp();

            //Basic Commands
            AddCommand(new Commandlet("!join", "The command !join <channel> lets the bot join Channel <channel>", JoinCommand, this, CommandScope.Both, "engine_join"));
            AddCommand(new Commandlet("!part", "The command !part <channel> lets the bot part Channel <channel>", PartCommand, this, CommandScope.Both, "engine_part"));
            AddCommand(new Commandlet("!channels", "The command !channels lists all channels where the bot resides", ListChannelCommand, this));
            AddCommand(new Commandlet("!quit", "The command !quit lets the bot quit himself", QuitCommand, this, CommandScope.Both, "engine_quit"));

            //Plugin Commands
            AddCommand(new Commandlet("!plugins", "The command !plugins lists all the plugins", PluginsCommand, this));
            AddCommand(new Commandlet("!activate", "The command !activate <plugin> activates the Plugin <plugin>", ActivateCommand, this, CommandScope.Both, "engine_activate"));
            AddCommand(new Commandlet("!deactivate", "The command !deactivate <plugin> deactivates the Plugin <plugin>", DeactivateCommand, this, CommandScope.Both, "engine_deactivate"));

            //Helper Commands (!commands)
            AddCommand(new Commandlet("!help", "The command !help <topic> gives you help about <topic> (special topics: commands, more)", HelpCommand, this));

            //Settings Commands
            new SettingCommands(this);
        }
开发者ID:Avatarchik,项目名称:huffelpuff-irc-bot,代码行数:70,代码来源:IrcBot.cs


注:本文中的Main.SubmitChanges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。