Пример #1
0
        /// <summary>
        /// botの初期化処理
        /// </summary>
        /// <remarks>各botのタイマーを設定する。</remarks>
        private void Initialize()
        {
            // メンバ変数の初期化
            botList         = new List <TwitterBot>();
            randomTimerList = new List <Timer>();
            replyTimerList  = new List <Timer>();

            /*
             * サービスの場合はカレントディレクトリがプログラムの配置場所と異なる。
             * 設定ファイルをカレントパスで指定できるようにプログラム配置場所を
             * カレントディレクトリに設定する。
             */
            string currPath =
                Directory.GetParent(System.Reflection.Assembly.GetEntryAssembly().Location).ToString();

            // 設定ファイルからbot情報一覧を抽出
            TwitterBotInfoList xmlData = new TwitterBotInfoList();

            System.Environment.CurrentDirectory = currPath;
            XmlReader.XmlReader.GetInstance.Read(@"Setting\TwitterBotSetting.xml", ref xmlData);

            try
            {
                foreach (TwitterBotInfo twitterBot in xmlData.TwitterBotList)
                {
                    // bot情報からTwitterBotインスタンスを生成
                    TwitterBot bot = TwitterBot.CreateTwitterBot(twitterBot.BotName,
                                                                 twitterBot.ConsumerKey,
                                                                 twitterBot.ConsumerSecret,
                                                                 twitterBot.AccessToken,
                                                                 twitterBot.AccessTokenSecret,
                                                                 Int32.Parse(twitterBot.RandomTimer),
                                                                 Int32.Parse(twitterBot.ReplyTimer));
                    botList.Add(bot);

                    // ランダムポストのタイマー生成
                    Timer randomTimer = new Timer();
                    randomTimer.Elapsed  += RandomExecute;
                    randomTimer.Enabled   = true;
                    randomTimer.AutoReset = true;
                    randomTimer.Interval  = bot.RandomTimer * 1000 * 60;
                    randomTimerList.Add(randomTimer);

                    // リプライタイマー生成
                    Timer replyTimer = new Timer();
                    replyTimer.Elapsed  += ReplyExecute;
                    replyTimer.Enabled   = true;
                    replyTimer.AutoReset = true;
                    replyTimer.Interval  = bot.ReplyTimer * 1000 * 60;
                    replyTimerList.Add(replyTimer);
                }
            }
            catch
            {
                // ボットの初期処理に失敗した場合はアプリケーションを落とす。
                OnStop();
            }
        }
Пример #2
0
        /// <summary>
        /// botの初期化処理
        /// </summary>
        /// <remarks>各botのタイマーを設定する。</remarks>
        private void Initialize()
        {
            // メンバ変数の初期化
            botList = new List<TwitterBot>();
            randomTimerList = new List<Timer>();
            replyTimerList = new List<Timer>();

            /*
            サービスの場合はカレントディレクトリがプログラムの配置場所と異なる。
            設定ファイルをカレントパスで指定できるようにプログラム配置場所を
            カレントディレクトリに設定する。
            */
                string currPath =
                Directory.GetParent(System.Reflection.Assembly.GetEntryAssembly().Location).ToString();

            // 設定ファイルからbot情報一覧を抽出
            TwitterBotInfoList xmlData = new TwitterBotInfoList();
            System.Environment.CurrentDirectory = currPath;
            XmlReader.XmlReader.GetInstance.Read(@"Setting\TwitterBotSetting.xml", ref xmlData);

            try
            {
                foreach (TwitterBotInfo twitterBot in xmlData.TwitterBotList)
                {
                    // bot情報からTwitterBotインスタンスを生成
                    TwitterBot bot = TwitterBot.CreateTwitterBot(twitterBot.BotName,
                        twitterBot.ConsumerKey,
                        twitterBot.ConsumerSecret,
                        twitterBot.AccessToken,
                        twitterBot.AccessTokenSecret,
                        Int32.Parse(twitterBot.RandomTimer),
                        Int32.Parse(twitterBot.ReplyTimer));
                    botList.Add(bot);

                    // ランダムポストのタイマー生成
                    Timer randomTimer = new Timer();
                    randomTimer.Elapsed += RandomExecute;
                    randomTimer.Enabled = true;
                    randomTimer.AutoReset = true;
                    randomTimer.Interval = bot.RandomTimer * 1000 * 60;
                    randomTimerList.Add(randomTimer);

                    // リプライタイマー生成
                    Timer replyTimer = new Timer();
                    replyTimer.Elapsed += ReplyExecute;
                    replyTimer.Enabled = true;
                    replyTimer.AutoReset = true;
                    replyTimer.Interval = bot.ReplyTimer * 1000 * 60;
                    replyTimerList.Add(replyTimer);

                }
            }
            catch
            {
                // ボットの初期処理に失敗した場合はアプリケーションを落とす。
                OnStop();
            }
        }