コード例 #1
0
ファイル: MainForm.cs プロジェクト: madguy/nwhoisTimerExact
 public MainForm(NwhoisTimerExactData pluginData)
 {
     InitializeComponent();
     this.pluginData = pluginData;
     this.CallAlertSpinner.Value = pluginData.CallAlertTime;
     this.DoCommentCheckBox.Checked = pluginData.DoComment;
     this.PostCommentTextBox.Text = pluginData.PostComment;
     this.PostCommandTextBox.Text = pluginData.PostCommand;
     this.AsOwnerCheckBox.Checked = pluginData.AsOwner;
     var communityFilters = new string[pluginData.CommunityFilter.Count];
     for (var i = 0; i < pluginData.CommunityFilter.Count; i++) {
         communityFilters[i] = pluginData.CommunityFilter[i];
     }
     this.CommunityFilterTextBox.Text = String.Join(@"/", communityFilters);
     this.AnytimeWatchCheckBox.Checked = pluginData.AnytimeWatch;
 }
コード例 #2
0
        public static void Save(String folderPath, String fileName, NwhoisTimerExactData model)
        {
            try {
                var filePath = Path.Combine(folderPath, fileName);
                var xmlDoc = new XmlDocument();
                xmlDoc.AppendChild(xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes"));
                XmlNode root = xmlDoc.CreateElement("NwhoisTimerExactData");

                var CallAlertTime = xmlDoc.CreateElement("CallAlertTime");
                CallAlertTime.InnerText = model.CallAlertTime.ToString();
                root.AppendChild(CallAlertTime);

                var DoComment = xmlDoc.CreateElement("DoComment");
                DoComment.InnerText = model.DoComment.ToString();
                root.AppendChild(DoComment);

                var PostComment = xmlDoc.CreateElement("PostComment");
                PostComment.InnerText = model.PostComment;
                root.AppendChild(PostComment);

                var PostCommand = xmlDoc.CreateElement("PostCommand");
                PostCommand.InnerText = model.PostCommand;
                root.AppendChild(PostCommand);

                var AsOwner = xmlDoc.CreateElement("AsOwner");
                AsOwner.InnerText = model.AsOwner.ToString();
                root.AppendChild(AsOwner);

                var CommunityFilters = xmlDoc.CreateElement("CommunityFilters");
                foreach (var community in model.CommunityFilter) {
                    var CommunityFilter = xmlDoc.CreateElement("CommunityFilter");
                    CommunityFilter.InnerText = community;
                    CommunityFilters.AppendChild(CommunityFilter);
                }
                root.AppendChild(CommunityFilters);

                var AnytimeWatch = xmlDoc.CreateElement("AnytimeWatch");
                AnytimeWatch.InnerText = model.AnytimeWatch.ToString();
                root.AppendChild(AnytimeWatch);

                xmlDoc.AppendChild(root);
                xmlDoc.Save(filePath);
            } catch (InvalidOperationException e) {
                MessageBox.Show(SaveErrorMessage);
                Debug.WriteLine(e.StackTrace);
            }
        }
コード例 #3
0
        public static NwhoisTimerExactData Load(String folderPath, String fileName)
        {
            var filePath = Path.Combine(folderPath, fileName);
            if (File.Exists(filePath) == false) {
                return new NwhoisTimerExactData();
            }

            NwhoisTimerExactData model = new NwhoisTimerExactData();
            try {
                var xmlDoc = new XmlDocument();
                xmlDoc.Load(filePath);
                model.CallAlertTime = Decimal.Parse(xmlDoc.SelectSingleNode("/NwhoisTimerExactData/CallAlertTime").InnerText);
                model.DoComment = Boolean.Parse(xmlDoc.SelectSingleNode("/NwhoisTimerExactData/DoComment").InnerText);
                model.PostComment = xmlDoc.SelectSingleNode("/NwhoisTimerExactData/PostComment").InnerText;
                model.PostCommand = xmlDoc.SelectSingleNode("/NwhoisTimerExactData/PostCommand").InnerText;
                model.AsOwner = Boolean.Parse(xmlDoc.SelectSingleNode("/NwhoisTimerExactData/AsOwner").InnerText);
                IList<String> filterList = new List<string>();
                foreach (XmlNode filter in xmlDoc.SelectNodes("/NwhoisTimerExactData/CommunityFilters/CommunityFilter")) {
                    filterList.Add(filter.InnerText);
                }
                model.CommunityFilter = filterList;
                model.AnytimeWatch = Boolean.Parse(xmlDoc.SelectSingleNode("/NwhoisTimerExactData/AnytimeWatch").InnerText);
            } catch (InvalidOperationException e) {
                MessageBox.Show(LoadErrorMessage);
                Debug.WriteLine(e.StackTrace);
                model = new NwhoisTimerExactData();
            } catch (XmlException e) {
                MessageBox.Show(LoadErrorMessage);
                Debug.WriteLine(e.StackTrace);
                model = new NwhoisTimerExactData();
            } catch (FormatException e) {
                MessageBox.Show(LoadErrorMessage);
                Debug.WriteLine(e.StackTrace);
                model = new NwhoisTimerExactData();
            } catch (ArgumentNullException e) {
                MessageBox.Show(LoadErrorMessage);
                Debug.WriteLine(e.StackTrace);
                model = new NwhoisTimerExactData();
            }
            return model;
        }
コード例 #4
0
        private void Initialize()
        {
            Debug.WriteLine("プラグインの初期化を開始します。");
            this.pluginData = DataManager.Load(this.Host.ApplicationDataFolder, NwhoisTimerExact.FileName);
            var alertTimer = new Timer(p => {
                if (this.OnAlertCall != null) {
                    this.OnAlertCall(this.Host, EventArgs.Empty);
                }
            }, null, Timeout.Infinite, Timeout.Infinite);

            var nicoLiveTimer = new NicoLiveInfoIntervalTimer();
            nicoLiveTimer.OnSync += liveInfo => {
                var alertMinute = (Int32)this.pluginData.CallAlertTime;
                var alertTime = liveInfo.EndTime.AddMinutes(-1 * alertMinute);
                var callAlertMillisec = (Int32)alertTime.Subtract(liveInfo.ServerTime).TotalMilliseconds;
                if (callAlertMillisec > 0) {
                    alertTimer.Change(callAlertMillisec, Timeout.Infinite);
                    Debug.WriteLine(String.Format("アラートを設定しました。{0} ミリ秒後", callAlertMillisec));
                }
            };
            nicoLiveTimer.OnSyncEnd += (sender, e) => {
                alertTimer.Change(Timeout.Infinite, Timeout.Infinite);
            };

            this.pluginData.OnChangeCallAlertTime += param => {
                nicoLiveTimer.ResetSync();
            };

            this.Host.Disposed += (sender, e) => {
                alertTimer.Dispose();
                nicoLiveTimer.Dispose();
            };
            this.Host.UpdatedCommunityInfo += (sender, e) => {
                // 延長時にこのイベントが走るのならば、延長関連をもっとスマートに書けます。
                Debug.WriteLine("放送内容が更新されました。");
            };
            this.Host.LiveStart += (sender, e) => {
                Debug.WriteLine("放送に接続しました。");
                if (this.Host.IsArchive) {
                    Debug.WriteLine("アーカイブ放送です。");
                    return;
                }

                nicoLiveTimer.SyncStart(this.Host.LiveId, this.Host.CookieContainer);
            };
            this.Host.LiveStop += (sender, e) => {
                Debug.WriteLine("放送から切断されました。");
                if (nicoLiveTimer.IsStart) {
                    nicoLiveTimer.SyncStop();
                }
            };

            // 『常に監視』がオンになっている場合、最初から監視します。
            this.enableAlert = this.pluginData.AnytimeWatch;
        }
コード例 #5
0
 private NwhoisTimerExact_Accessor CreateTestInstance()
 {
     var host = new DummyPluginHost {
         CanPostMessage = true,
     };
     var data = new NwhoisTimerExactData {
         DoComment = true,
     };
     var target = new NwhoisTimerExact_Accessor {
         Host = host,
         pluginData = data,
         enableAlert = true,
     };
     return target;
 }