Example #1
0
 private static Runner CreateRunner(int id, string firstName, string lastName, string club, string Class, int start, int time, RunnerStatus status, List<ResultStruct> splits)
 {
     Runner r = new Runner()
     {
         ID = id,
         FirstName = firstName,
         LastName = lastName,
         ClassName = Class,
         ClubName = club,
         Time = time,
         Status = status,
         StartTime = start,
         RadioTimes = splits == null ? null : splits.ToDictionary(x => x.ControlCode, x => x.Time)
     };
     return r;
 }
Example #2
0
        /// <summary>
        /// Check if otherRunner differs regarding definition or results
        /// </summary>
        /// <param name="otherRunner"></param>
        /// <returns></returns>
        public bool DefinitionEquals(Runner otherRunner)
        {
            if (ID != otherRunner.ID || FirstName != otherRunner.FirstName || LastName != otherRunner.LastName
                || ClassName != otherRunner.ClassName || ClubName != otherRunner.ClubName
                || StartTime != otherRunner.StartTime || Time != otherRunner.Time
                || Status != otherRunner.Status)
            {
                return false;
            }

            /*Check radio passings*/

            if (otherRunner.RadioTimes.Count != RadioTimes.Count)
                return false;

            Dictionary<int, int> processedControls = new Dictionary<int, int>();
            foreach (KeyValuePair<int, int> kvp in otherRunner.RadioTimes)
            {
                processedControls.Add(kvp.Key, 0);
                if (!RadioTimes.ContainsKey(kvp.Key))
                {
                    return false;
                }
                else
                {
                    if (RadioTimes[kvp.Key] != kvp.Value)
                        return false;
                }
            }

            foreach (int id in RadioTimes.Keys)
            {
                if (!processedControls.ContainsKey(id))
                    return false;
            }

            return true;
        }
Example #3
0
        public Dictionary<string, EventClass> ParseIOFXmlFile(string filename)
        {
            bool processed = false;
            Dictionary<string, EventClass> ret = new Dictionary<string, EventClass>();
            for (int i = 0; i < 10; i++)
            {
                try
                {
                    StreamReader sr = null;
                    if (!File.Exists(filename))
                    {
                        return null;
                    }
                    else
                    {
                        sr = new StreamReader(filename, Encoding.Default);
                    }
                    string tmp = sr.ReadToEnd();
                    sr.Close();
                    File.Delete(filename);
                    tmp = tmp.Replace("<!DOCTYPE ResultList SYSTEM \"IOFdata.dtd\">", "");
                    processed = true;
                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(tmp);

                    foreach (XmlNode classNode in xmlDoc.GetElementsByTagName("ClassResult"))
                    {
                        XmlNode classNameNode = classNode.SelectSingleNode("ClassShortName");
                        string className = classNameNode.InnerText;

                        EventClass eventClass = null;
                        if (ret.ContainsKey(className))
                        {
                            eventClass = ret[className];
                        }
                        else
                        {
                            eventClass = new EventClass();
                            ret.Add(className, eventClass);
                            eventClass.ClassName = className;
                        }

                        foreach (XmlNode personNode in classNode.SelectNodes("PersonResult"))
                        {
                            XmlNode personNameNode = personNode.SelectSingleNode("Person/PersonName");
                            string familyname = personNameNode.SelectSingleNode("Family").InnerText;
                            string givenname = personNameNode.SelectSingleNode("Given").InnerText;
                            string id = personNode.SelectSingleNode("Person/PersonId").InnerText;
                            long pid = 0;
                            if (id.Trim().Length > 0)
                            {
                                pid = Convert.ToInt64(id);
                            }
                            string club = personNode.SelectSingleNode("Club/ShortName").InnerText;
                            string status = personNode.SelectSingleNode("Result/CompetitorStatus").Attributes["value"].Value;
                            string time = personNode.SelectSingleNode("Result/Time").InnerText;
                            string si = personNode.SelectSingleNode("Result/CCard/CCardId").InnerText;
                            int iSi;
                            if (!Int32.TryParse(si, out iSi))
                            {
                                //NO SICARD!
                                FireLogMsg("No SICard for Runner: " + familyname + " " + givenname);
                            }
                            int dbid = 0;
                            if (pid < Int32.MaxValue && pid > 0)
                            {
                                dbid = (int)pid;
                            }
                            else if (iSi > 0)
                            {
                                dbid = -1 * iSi;
                            }
                            else
                            {
                                FireLogMsg("Cant generate DBID for runner: " + givenname + " " + familyname);
                            }
                            int itime = -1;
                            itime = ParseTime(time);

                            RunnerStatus istatus = RunnerStatus.STARTED;

                            switch (status)
                            {
                                case "MisPunch":
                                    istatus = RunnerStatus.MISSING_PUNCH;
                                    break;

                                case "Disqualified":
                                    istatus = RunnerStatus.DISQUALIFIED;
                                    break;
                                case "DidNotFinish":
                                    istatus = RunnerStatus.MISSING_PUNCH;
                                    itime = -2;
                                    break;
                                case "DidNotStart":
                                    istatus = RunnerStatus.DID_NOT_START;
                                    itime = -3;
                                    break;
                                case "Overtime":
                                    istatus = RunnerStatus.OVERTIME;
                                    break;
                                case "OK":
                                    istatus = RunnerStatus.OK;
                                    break;
                            }

                            Runner r = new Runner();
                            r.ClassName = className;
                            r.ClubName = club;
                            r.FirstName = givenname;
                            r.ID = dbid;
                            r.LastName = familyname;
                            r.Status = istatus;
                            r.Time = itime;

                            eventClass.Runners.Add(dbid, r);

                            List<int> lsplitCodes = new List<int>();
                            List<int> lsplitTimes = new List<int>();

                            XmlNodeList splittimes = personNode.SelectNodes("Result/SplitTime");
                            List<ResultStruct> splits = new List<ResultStruct>();
                            if (splittimes != null)
                            {
                                foreach (XmlNode splitNode in splittimes)
                                {
                                    XmlNode splitcode = splitNode.SelectSingleNode("ControlCode");
                                    XmlNode splittime = splitNode.SelectSingleNode("Time");
                                    int i_splitcode;
                                    string s_splittime = splittime.InnerText;
                                    if (int.TryParse(splitcode.InnerText, out i_splitcode) && s_splittime.Length > 0)
                                    {
                                        if (i_splitcode == 999)
                                        {
                                            if (istatus == 0 && itime == -1)
                                            {
                                                //Målstämpling
                                                itime = ParseTime(s_splittime);
                                            }
                                        }
                                        else
                                        {
                                            i_splitcode += 1000;
                                            while (lsplitCodes.Contains(i_splitcode))
                                            {
                                                i_splitcode += 1000;
                                            }

                                            int i_splittime = ParseTime(s_splittime);
                                            lsplitCodes.Add(i_splitcode);
                                            lsplitTimes.Add(i_splittime);

                                            ResultStruct rs = new ResultStruct();
                                            rs.ControlCode = i_splitcode;
                                            rs.Time = i_splittime;
                                            splits.Add(rs);
                                        }
                                    }
                                }
                            }

                            for (int c = 0; c < splits.Count; c++)
                            {
                                r.RadioTimes.Add(splits[c].ControlCode, splits[c].Time);
                            }
                        }
                    }
                }
                catch (Exception ee)
                {
                    FireLogMsg(ee.Message);
                }

                if (!processed)
                {
                    System.Threading.Thread.Sleep(1000);
                }
                else
                {
                    break;
                }
            }
            if (!processed)
            {
                FireLogMsg("Could not open " + filename + " for processing");
                return null;
            }
            else
            {
                return ret;
            }
        }
Example #4
0
 public void FireRunnerChanged(Runner r)
 {
     RunnerChangedHandler h = RunnerChanged;
     if (h != null)
         h(r);
 }
Example #5
0
 void m_ModelEvent_RunnerChanged(Runner r)
 {
     m_Logger("Runner changed: " + r.FirstName + " " + r.LastName);
     m_Server.QueueUpload(r.OnlineResult);
 }