コード例 #1
0
        private List <HashEntry> ConvertToHashEntryList(TeamResult result)
        {
            var propertiesInHashEntryList = new List <HashEntry>();


            propertiesInHashEntryList.Add(new HashEntry("Name", result.Name));

            propertiesInHashEntryList.Add(new HashEntry("PassRate", result.PassRate.ToString()));
            propertiesInHashEntryList.Add(new HashEntry("FailTest", result.FailTest));
            propertiesInHashEntryList.Add(new HashEntry("UpdateTime", result.UpdateTime));
            var executionTime = "NA";

            if (result.ExecutionTime != null)
            {
                executionTime = string.Format("{0} {1}", result.ExecutionTime,
                                              ConfigurationManager.AppSettings["TimeDurationUnit"]);
            }
            propertiesInHashEntryList.Add(new HashEntry("ExecutionTime", executionTime));

            propertiesInHashEntryList.Add(new HashEntry("Rank", result.Rank.ToString()));

            propertiesInHashEntryList.Add(new HashEntry("Change", result.Change));

            return(propertiesInHashEntryList);
        }
コード例 #2
0
        private void ParseFileToDic(string file)
        {
            var strTimeDurationUnit = ConfigurationManager.AppSettings["TimeDurationUnit"].ToLower();

            try
            {
                var lines  = File.ReadLines(file);
                var result = new TeamResult();
                foreach (var line in lines)
                {
                    var lineValue = line.Trim();
                    if (String.IsNullOrWhiteSpace(lineValue) || String.IsNullOrEmpty(lineValue))
                    {
                        continue;
                    }

                    var separator = lineValue.IndexOf(":");

                    if (separator >= lineValue.Length - 1)
                    {
                        continue;
                    }

                    var key   = lineValue.Substring(0, separator);
                    var value = lineValue.Substring(separator + 1);

                    if (key.ToLower().Contains("name"))
                    {
                        result.Name = value;
                    }
                    else if (key.ToLower().Contains("passrate"))
                    {
                        float pass = 0.0f;
                        if (float.TryParse(value, out pass))
                        {
                            result.PassRate = pass;
                        }
                    }
                    else if (key.ToLower().Contains("failtest"))
                    {
                        result.FailTest = value;
                    }
                    else if (key.ToLower().Contains("updatetime"))
                    {
                        result.UpdateTime = value;
                    }
                    else if (key.ToLower().Contains("executiontime"))
                    {
                        if (value.ToLower().Contains(strTimeDurationUnit))
                        {
                            value = value.ToLower().Replace(strTimeDurationUnit, "");
                        }

                        int time = 0;
                        if (Int32.TryParse(value, out time))
                        {
                            result.ExecutionTime = time;
                        }
                    }
                }

                if (!string.IsNullOrEmpty(result.Name))
                {
                    results[result.Name] = result;
                }
            }
            catch (Exception e)
            {
                eventLog.WriteEntry(
                    String.Format("Parse result from {0} failed. Details:{1}", file,
                                  e.Message), EventLogEntryType.Error);
            }
        }