Esempio n. 1
0
        private Profile(Guid id, string name, int generation, Guid?parentA, Guid?parentB, MetricWeights startMetricWeights, MetricWeights endMetricWeights)
        {
            if (generation < 0)
            {
                throw new ArgumentOutOfRangeException("generation");
            }

            if (!parentA.HasValue)
            {
                throw new ArgumentNullException(nameof(parentA));
            }

            if (!parentB.HasValue)
            {
                throw new ArgumentNullException(nameof(parentB));
            }

            Id = id;

            Name = name;

            Generation = generation;

            ParentA = parentA;
            ParentB = parentB;

            Records = ProfileRecord.CreateRecords();

            StartMetricWeights = startMetricWeights ?? throw new ArgumentNullException(nameof(startMetricWeights));
            EndMetricWeights   = endMetricWeights ?? throw new ArgumentNullException(nameof(endMetricWeights));

            CreationTimestamp    = DateTime.Now;
            LastUpdatedTimestamp = DateTime.Now;
        }
Esempio n. 2
0
 public static ProfileRecord[] CreateRecords()
 {
     ProfileRecord[] records = new ProfileRecord[EnumUtils.NumGameTypes];
     for (int i = 0; i < records.Length; i++)
     {
         records[i] = new ProfileRecord();
     }
     return(records);
 }
Esempio n. 3
0
        public Profile(Guid id, string name, MetricWeights startMetricWeights, MetricWeights endMetricWeights)
        {
            Id = id;

            Name = name;

            Records = ProfileRecord.CreateRecords();

            StartMetricWeights = startMetricWeights ?? throw new ArgumentNullException(nameof(startMetricWeights));
            EndMetricWeights   = endMetricWeights ?? throw new ArgumentNullException(nameof(endMetricWeights));

            CreationTimestamp    = DateTime.Now;
            LastUpdatedTimestamp = DateTime.Now;
        }
Esempio n. 4
0
        public static Profile ReadXml(Stream inputStream)
        {
            if (null == inputStream)
            {
                throw new ArgumentNullException(nameof(inputStream));
            }

            Guid   id         = Guid.Empty;
            string name       = null;
            int    generation = 0;

            Guid?parentA = null;
            Guid?parentB = null;

            ProfileRecord[] records = ProfileRecord.CreateRecords();

            MetricWeights startMetricWeights = null;
            MetricWeights endMetricWeights   = null;

            DateTime creationTimestamp   = DateTime.Now;
            DateTime lastUpdateTimestamp = creationTimestamp;

            using (XmlReader reader = XmlReader.Create(inputStream))
            {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        switch (reader.Name)
                        {
                        case "Id":
                            id = Guid.Parse(reader.ReadElementContentAsString());
                            break;

                        case "Name":
                            name = reader.ReadElementContentAsString();
                            break;

                        case "Generation":
                            generation = reader.ReadElementContentAsInt();
                            break;

                        case "ParentA":
                            parentA = Guid.Parse(reader.ReadElementContentAsString());
                            break;

                        case "ParentB":
                            parentB = Guid.Parse(reader.ReadElementContentAsString());
                            break;

                        case "Record":
                        {
                            if (EnumUtils.TryParseExpansionPieces(reader["GameType"], out ExpansionPieces ep))
                            {
                                int.TryParse(reader["EloRating"], out records[(int)ep].EloRating);
                                int.TryParse(reader["Wins"], out records[(int)ep].Wins);
                                int.TryParse(reader["Losses"], out records[(int)ep].Losses);
                                int.TryParse(reader["Draws"], out records[(int)ep].Draws);
                                int.TryParse(reader["AutoTrains"], out records[(int)ep].AutoTrains);
                            }
                        }
                        break;

                        case "Creation":
                            creationTimestamp = reader.ReadElementContentAsDateTime();
                            break;

                        case "LastUpdated":
                            lastUpdateTimestamp = reader.ReadElementContentAsDateTime();
                            break;

                        case "MetricWeights":
                        case "StartMetricWeights":
                            startMetricWeights = MetricWeights.ReadMetricWeightsXml(reader.ReadSubtree());
                            break;

                        case "EndMetricWeights":
                            endMetricWeights = MetricWeights.ReadMetricWeightsXml(reader.ReadSubtree());
                            break;
                        }
                    }
                }
            }

            return(new Profile(id, name ?? GenerateName(id), generation, parentA, parentB, records, startMetricWeights, endMetricWeights ?? startMetricWeights, creationTimestamp, lastUpdateTimestamp));
        }