private bool SaveScore() { if (tvwScores.SelectedNode == null || tvwScores.SelectedNode.Tag == null) { return(true); } bool res = true; BaseScoreEditor editor = GetEditor(); if (editor != null) { BaseScore score = tvwScores.SelectedNode.Tag as BaseScore; if (!editor.SaveScore(ref score)) { // errors while saving Cancel selection res = false; } else { if (tvwScores.SelectedNode.Text != score.Name) { tvwScores.SelectedNode.Text = score.Name; } } } return(res); }
private void tsbMoveBack_Click(object sender, EventArgs e) { TreeNode node = tvwScores.SelectedNode; if (node == null || node.Parent == null) { return; } BaseScore parentScore = node.Parent.Tag as BaseScore; BaseScore currScore = node.Tag as BaseScore; currScore.Parent = parentScore.Parent; var gpNode = node.Parent.Parent; node.Parent.Nodes.Remove(node); if (gpNode == null) { tvwScores.Nodes.Add(node); currScore.Order = tvwScores.Nodes.Count + 1; } else { gpNode.Nodes.Add(node); currScore.Order = gpNode.Nodes.Count + 1; } ReorderNodes(node.PrevNode); tvwScores.Sort(); tvwScores.SelectedNode = node; }
/// <summary> /// Compares 2 scores. /// </summary> /// <param name="score">The score definition.</param> /// <param name="oldScore">The previous score.</param> /// <param name="newScore">The new score.</param> /// <returns>A message with the differences between scores.</returns> private string CompareScores(BaseScore score, string[][] oldScore, string[][] newScore) { if (oldScore == null || newScore == null) { return(String.Format("ERROR {0} {1}", oldScore == null, newScore == null)); } string message = ""; try { string scoreFormat = ""; if (!String.IsNullOrEmpty(score.LiveConfig.Value) && score.LiveConfig.Value.Contains("{")) { scoreFormat = score.LiveConfig.Value; } string[] filters = score.LiveConfig.filter.Split(','); string sep = m_center.GetParameterValue("DiffSeparator", "*"); // for all row of old score for (int iRow = 0; iRow < oldScore.Length; iRow++) { // ignore missing row in new score if (newScore.Length <= iRow || newScore[iRow] == null) { continue; } // format the row string newRow = BuildScore(scoreFormat, newScore[iRow]); // if old score is missing then new is new if (oldScore[iRow] == null) { message = AddToMessage(message, newRow, filters); continue; } // format the old row the same way string oldRow = BuildScore(scoreFormat, oldScore[iRow]); // compare old and new if (!String.Equals(oldRow, newRow)) { Tools.LogMessage("OLD = {0}", oldRow); Tools.LogMessage("NEW = {0}", newRow); var zz = score.GetDifferences(oldRow, newRow); message = AddToMessage(message, ScoreDifference.StringFromList(zz, sep), filters); } } } catch (Exception exc) { Tools.LogError("CompareScore", exc); message = "ERROR"; } return(message); }
public int Compare(GUIListItem x, GUIListItem y) { int res = 0; if (x.Label == ".." && y.Label == "..") { res = 0; } else if (x.Label == "..") { res = -1; } else if (y.Label == "..") { res = 1; } else { BaseScore scx = x.TVTag as BaseScore; BaseScore scy = y.TVTag as BaseScore; if (scx == null || scy == null) { res = String.Compare(x.Label, y.Label); } else { res = scx.CompareTo(scy); } } return(res); }
private string FindBackdrop(BaseScore score) { //Tools.LogMessage("SetBackdrop for '{0}'", score == null ? "NULL" : score.Name); string bd = ""; if (score != null) { if (m_center.Setup != null && !String.IsNullOrEmpty(m_center.Setup.BackdropDir)) { string name = Path.Combine(m_center.Setup.BackdropDir, m_center.GetFullName(score, ".")); // score.Name; var bds = Directory.GetFiles(m_center.Setup.BackdropDir, "*.jpg").Where(x => x.StartsWith(name)); if (bds != null && bds.Count() > 0) { int index = m_randomizer.Next(1, bds.Count()) - 1; bd = Path.GetFileNameWithoutExtension(bds.ElementAt(index)); } } if (bd.Length == 0) { bd = FindBackdrop(m_center.FindScore(score.Parent)); } } return(bd); }
private void tsbMoveRight_Click(object sender, EventArgs e) { TreeNode node = tvwScores.SelectedNode; if (node == null || node.PrevNode == null) { return; } TreeNode prevNode = node.PrevNode; BaseScore prevScore = prevNode.Tag as BaseScore; BaseScore currScore = node.Tag as BaseScore; ReorderNodes(node.PrevNode.FirstNode); currScore.Parent = prevScore.Id; currScore.Order = prevNode.Nodes.Count + 1; if (node.Parent == null) { tvwScores.Nodes.Remove(node); } else { node.Parent.Nodes.Remove(node); } prevNode.Nodes.Add(node); tvwScores.Sort(); tvwScores.SelectedNode = node; }
private void btnSetIcon_Click(object sender, EventArgs e) { if (tvwScores.SelectedNode == null) { return; } BaseScore score = tvwScores.SelectedNode.Tag as BaseScore; if (score == null) { return; } if (ofdSelectIcon.ShowDialog() == DialogResult.OK) { string file = ofdSelectIcon.FileName; FileInfo imgFile = new FileInfo(file); string root = Config.GetFile(Config.Dir.Thumbs, "ScoreCenter", ""); string newFile = file; if (!imgFile.DirectoryName.StartsWith(root, StringComparison.OrdinalIgnoreCase)) { // copy newFile = Tools.GenerateFileName(root, imgFile.Name, imgFile.Extension); File.Copy(file, newFile); } FileInfo newFI = new FileInfo(newFile); string iconName = newFI.FullName.Substring(root.Length + 1, newFI.FullName.Length - newFI.Extension.Length - root.Length - 1); SetIcon(iconName); score.Image = iconName; } }
private void SetIcons(BaseScore score, int level) { //Tools.LogMessage(">>> {0}: Icon = {1}", level, score == null ? "" : score.Image); BaseScore curr = score; for (int i = level; i >= 0; i--) { if (curr == null) { continue; } string image = Tools.GetThumbs(curr.Image); GUIPropertyManager.SetProperty(String.Format("#ScoreCenter.Ico{0}", i), image); //Tools.LogMessage(">>>> SetProperties Ico{0} = {1}", i, image); if (i == 1) { GUIPropertyManager.SetProperty("#ScoreCenter.CatIco", image); } else if (i == 2) { GUIPropertyManager.SetProperty("#ScoreCenter.LeagueIco", image); } curr = m_center.FindScore(curr.Parent); } }
private void tsbCopyScore_Click(object sender, EventArgs e) { if (tvwScores.SelectedNode == null) { return; } BaseScore source = tvwScores.SelectedNode.Tag as BaseScore; BaseScore copy = source.Clone(Tools.GenerateId()); // add the new item and refresh m_center.AddScore(copy); // create node ThreeStateTreeNode node = new ThreeStateTreeNode(copy.Name); node.Tag = copy; if (tvwScores.SelectedNode.Parent != null) { tvwScores.SelectedNode.Parent.Nodes.Add(node); } else { tvwScores.Nodes.Add(node); } }
private void tsbNewItem_Click(object sender, EventArgs e) { TreeNode parentNode = null; BaseScore parent = null; if (tvwScores.SelectedNode != null) { parentNode = tvwScores.SelectedNode; parent = parentNode.Tag as BaseScore; } using (var dlg = new CreateScoreDlg(parent)) { if (dlg.ShowDialog() == DialogResult.OK) { BaseScore score = dlg.NewScore; m_center.AddScore(score); // create the tree node ThreeStateTreeNode newNode = new ThreeStateTreeNode(score.Name); newNode.Checked = true; newNode.State = CheckBoxState.Checked; newNode.Tag = score; if (String.IsNullOrEmpty(score.Parent)) { tvwScores.Nodes.Add(newNode); } else { parentNode.Nodes.Add(newNode); } } } }
private void tsbCopySettings_Click(object sender, EventArgs e) { if (tvwScores.SelectedNode != null && tvwScores.SelectedNode.Tag != null) { m_scoreSettings = tvwScores.SelectedNode.Tag as BaseScore; tsbApplySettings.Enabled = true; } }
private void tvwScores_AfterCheck(object sender, TreeViewEventArgs e) { if (e.Node.Tag != null) { BaseScore score = e.Node.Tag as BaseScore; score.enable = e.Node.Checked; } }
public BaseScore CreateScore(Type scoreType) { BaseScore score = (BaseScore)Activator.CreateInstance(scoreType); score.Id = Tools.GenerateId(); score.SetDefaultIcon(); return(score); }
private void lbxTest_SelectedIndexChanged(object sender, System.EventArgs e) { BaseScore sc = lbxTest.SelectedItem as BaseScore; string path = Config.GetFile(Config.Dir.Thumbs, "ScoreCenter", sc.Image + ".png"); if (File.Exists(path)) { pictureBox1.Image = new Bitmap(path); } }
public int CompareToNoLoc(BaseScore other) { int diff = this.Order - other.Order; if (diff == 0) { diff = String.Compare(this.Name, other.Name); } return(diff); }
/// <summary> /// Get the score level. /// </summary> /// <param name="score">The score.</param> /// <returns>The score level.</returns> public int GetLevel(BaseScore score) { int level = 0; if (score != null) { level = 1 + GetLevel(FindScore(score.Parent)); } return(level); }
public override IList <T> Build(BaseScore score, string[][] labels, int startLine, int startColumn, int startX, int startY, int pnlWidth, int pnlHeight, CreateControlDelegate <T> createControl, out bool overRight, out bool overDown, out int lineNumber, out int colNumber) { overRight = false; overDown = false; lineNumber = -1; colNumber = -1; return(null); }
public Parser.IScoreParser GetParser(BaseScore score) { string parserType = GetParserType(score); if (!m_parsers.ContainsKey(parserType)) { var t = Type.GetType("MediaPortal.Plugin.ScoreCenter.Parser." + parserType); m_parsers[parserType] = (Parser.IScoreParser)Activator.CreateInstance(t, this.CacheExpiration); } return(m_parsers[parserType]); }
/// <summary> /// Import a list of scores in an existing center. /// </summary> /// <param name="center">The existing center.</param> /// <param name="imported">The center to import.</param> /// <param name="mergeOptions">The merge options.</param> /// <returns>The number of scores imported.</returns> public static int Import(ScoreCenter center, ScoreCenter imported, ImportOptions mergeOptions) { int result = 0; if (imported.Scores.Items == null) { return(result); } bool isnew = center.Scores.Items != null; List <BaseScore> toImport = new List <BaseScore>(); foreach (BaseScore score in imported.Scores.Items) { BaseScore exist = center.FindScore(score.Id); if (exist != null) { // merge (or not) bool merged = exist.Merge(score, mergeOptions); if (merged) { result++; } } else { // import new if ((mergeOptions & ImportOptions.New) == ImportOptions.New) { toImport.Add(score); result++; score.SetNew(isnew); score.enable = true; } } } if (toImport.Count > 0) { if (center.Scores.Items == null) { center.Scores.Items = toImport.ToArray(); } else { center.Scores.Items = center.Scores.Items.Concat(toImport).ToArray(); } } // import parameters ExchangeManager.ImportParameters(center, imported); return(result); }
private void SetBackdrop(BaseScore score) { string bd = FindBackdrop(score); if (bd.Length == 0) { bd = GetDefaultBackdrop(); } //Tools.LogMessage("==> BD={0}", bd); GUIPropertyManager.SetProperty("#ScoreCenter.bd", Path.Combine(m_center.Setup.BackdropDir, bd)); }
internal override void ApplySettings(BaseScore score) { WorldFootballScore settings = score as WorldFootballScore; if (settings != null) { this.LiveConfig = settings.LiveConfig; this.Details = settings.Details; this.Levels = settings.Levels; this.Highlights = settings.Highlights; } }
private void editor_SetIcon(object sender, BaseScoreEditor.SetIconIconEventArgs e) { if (tvwScores.SelectedNode == null) { return; } BaseScore score = tvwScores.SelectedNode.Tag as BaseScore; score.Image = e.Path; SetIcon(e.Path); }
private void tvwScores_AfterSelect(object sender, TreeViewEventArgs e) { if (tvwScores.SelectedNode == null) { return; } // always clear ClearIcon(); BaseScore bscore = tvwScores.SelectedNode.Tag as BaseScore; BaseScoreEditor prevEditor = GetEditor(); BaseScoreEditor editor = null; string editorType = ScoreFactory.Instance.GetEditorType(bscore); if (prevEditor != null) { if (editorType != prevEditor.GetType().Name) { pnlEditor.Controls.Clear(); prevEditor.SetIcon -= new EventHandler <BaseScoreEditor.SetIconIconEventArgs>(editor_SetIcon); (prevEditor as Control).Dispose(); } else { editor = prevEditor; } } if (editor == null) { var zeditor = ScoreFactory.Instance.CreateEditor(editorType, pnlTest); zeditor.SetIcon += new EventHandler <BaseScoreEditor.SetIconIconEventArgs>(editor_SetIcon); pnlEditor.Controls.Add(zeditor); zeditor.Dock = DockStyle.Fill; editor = zeditor as BaseScoreEditor; } editor.LoadScore(bscore, m_center); SetIcon(bscore.Image); ClearTestGrid(); btnTest.Enabled = editor.HasTest; tsbMoveUp.Enabled = tvwScores.SelectedNode.PrevNode != null; tsbMoveDown.Enabled = tvwScores.SelectedNode.NextNode != null; tsbMoveBack.Enabled = tvwScores.SelectedNode.Parent != null; tsbMoveRight.Enabled = tsbMoveUp.Enabled; tsbCopySettings.Enabled = bscore.CanApplySettings(); tsbApplySettings.Enabled = tsbCopySettings.Enabled && m_scoreSettings != null && bscore.GetType() == m_scoreSettings.GetType(); }
private void tvwScores_AfterLabelEdit(object sender, NodeLabelEditEventArgs e) { if (String.IsNullOrEmpty(e.Label)) { e.CancelEdit = true; return; } BaseScore score = e.Node.Tag as BaseScore; score.Name = e.Label; //TODO tbxScore.Text = e.Label; }
public void SetLiveScore(BaseScore score, bool enable) { if (score.IsVirtual()) { BaseScore sc = FindScore(score.Parent); if (sc != null) { sc.SetLive(enable); } } score.SetLive(enable); }
public void DisableScore(BaseScore score) { if (score == null) { return; } score.enable = false; foreach (BaseScore sc in this.Scores.Items.Where(s => s.enable && s.Parent == score.Id)) { DisableScore(sc); } }
public override bool Merge(BaseScore newBaseScore, ImportOptions option) { GenericScore newScore = newBaseScore as GenericScore; if (newScore == null) { return(false); } bool result = base.Merge(newBaseScore, option); if ((option & ImportOptions.Parsing) == ImportOptions.Parsing) { result |= (String.Compare(this.Url, newScore.Url, true) != 0) || (String.Compare(this.XPath, newScore.XPath, true) != 0) || (String.Compare(this.XPathRow, newScore.XPathRow, true) != 0) || (String.Compare(this.XPathCol, newScore.XPathCol, true) != 0) || (this.Skip != newScore.Skip) || (this.MaxLines != newScore.MaxLines) || (String.Compare(this.Encoding, newScore.Encoding, true) != 0) || (String.Compare(this.Element, newScore.Element, true) != 0); this.Url = newScore.Url; this.XPath = newScore.XPath; this.XPathRow = newScore.XPathRow; this.XPathCol = newScore.XPathCol; this.Skip = newScore.Skip; this.MaxLines = newScore.MaxLines; this.Sizes = newScore.Sizes; this.Element = newScore.Element; this.BetweenElts = newScore.BetweenElts; this.Encoding = newScore.Encoding; this.ParseOptions = newScore.ParseOptions; if (newScore.Headers.Length > 0 || this.Headers.Length == 0) { this.Headers = newScore.Headers; result = true; } } if ((option & ImportOptions.Rules) == ImportOptions.Rules) { if (newScore.Rules != null && newScore.Rules.Length > 0) { this.Rules = newScore.Rules; result = true; } } return(result); }
private void DeleteScore(TreeNode node) { BaseScore score = node.Tag as BaseScore; if (score != null) { m_center.RemoveScore(score); } foreach (TreeNode sub in node.Nodes) { DeleteScore(sub); } }
public IEnumerable <BaseScore> ReadChildren(BaseScore parent) { if (parent != null && parent.IsVirtualFolder() && !parent.IsVirtualResolved()) { IList <BaseScore> scores = parent.GetVirtualScores(this.Parameters); parent.SetVirtualResolved(); this.Scores.Items = this.Scores.Items.Concat(scores).ToArray(); return(scores); } else { string id = parent == null ? "" : parent.Id; return(this.Scores.Items.Where(score => score.enable && score.Parent == id)); } }
/// <summary> /// Merge this score with newScore using given options. /// </summary> /// <param name="newScore">The score to merge with.</param> /// <param name="type">Merge options.</param> /// <returns>True if the score changed.</returns> public virtual bool Merge(BaseScore newScore, ImportOptions option) { bool result = false; if ((option & ImportOptions.Names) == ImportOptions.Names) { result |= (String.Compare(this.Name, newScore.Name, true) != 0); this.Name = newScore.Name; this.Parent = newScore.Parent; this.Image = newScore.Image; } return(result); }