コード例 #1
0
        /// <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);
        }
コード例 #2
0
ファイル: ScoreDifference.cs プロジェクト: mbekoe/scorecenter
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            ScoreDifference other = obj as ScoreDifference;

            if (other == null)
            {
                return(false);
            }

            return(String.Equals(this.Word, other.Word) &&
                   String.Equals(this.Separator, other.Separator));
        }
コード例 #3
0
        public virtual List <ScoreDifference> GetDifferences(string oldScore, string newScore)
        {
            List <ScoreDifference> res = ScoreDifference.ListFromString(newScore);
            List <ScoreDifference> old = ScoreDifference.ListFromString(oldScore);

            for (int i = 0; i < res.Count(); i++)
            {
                if (old.Count() <= i)
                {
                    res[i].IsNew = true;
                }
                else
                {
                    res[i].IsNew = !String.Equals(res[i].Word, old[i].Word);
                }
            }

            return(res);
        }
コード例 #4
0
ファイル: ScoreDifference.cs プロジェクト: mbekoe/scorecenter
        public static List <ScoreDifference> ListFromString(string score)
        {
            List <ScoreDifference> list = new List <ScoreDifference>();

            string curr = "";

            foreach (char c in score)
            {
                if (!C_SEPARATORS.Contains(c))
                {
                    curr += c;
                }
                else
                {
                    ScoreDifference d = new ScoreDifference(curr, c.ToString());
                    list.Add(d);
                    curr = "";
                }
            }
            list.Add(new ScoreDifference(curr, ""));

            return(list);
        }