コード例 #1
0
ファイル: Metadata.cs プロジェクト: cbries/railessentials
 public Metadata()
 {
     Occ                     = new OccData(this);
     LocomotivesData         = new LocomotivesData(this);
     LocomotivesDurationData = new DurationsData(this);
     FeedbacksData           = new FeedbacksData(this);
 }
コード例 #2
0
        public void TestDurationWithSpeedCurve()
        {
            var testSeconds = 5.0;

            var instance = new DurationsData(null);
            var data1004 = instance.GetData(1004);

            data1004.Should().BeNull();
            const string blockName = "B01[+]";

            for (var i = 0; i < 100; ++i)
            {
                instance.AddDecelerateDuration(1004, blockName, DateTime.Now, DateTime.Now + TimeSpan.FromSeconds(testSeconds)).Should().BeTrue();
            }

            var avrDuration = instance.GetAverageDecelerationSeconds(1004, blockName);

            avrDuration.Should().BeInRange((testSeconds - 0.001), testSeconds + 0.001);

            var locdata = new LocomotivesData(null);

            locdata.Load(@"Testmodels\locomotives.speedCurve.json").Should().BeTrue();
            var locdata1004 = locdata.GetData(1004);

            locdata1004.Should().NotBeNull();
            var speedCurve = locdata1004.SpeedCurve;

            speedCurve.Should().NotBeNull();
            speedCurve.MaxTime.Should().Be(10);
        }
コード例 #3
0
ファイル: Metadata.cs プロジェクト: cbries/railessentials
 public bool LoadLocomotives(string pathToLocomotivesmodel)
 {
     if (string.IsNullOrEmpty(pathToLocomotivesmodel))
     {
         return(false);
     }
     if (!File.Exists(pathToLocomotivesmodel))
     {
         File.WriteAllText(pathToLocomotivesmodel, "{}", Encoding.UTF8);
     }
     LocomotivesData = new LocomotivesData(this);
     return(LocomotivesData.Load(pathToLocomotivesmodel));
 }
コード例 #4
0
ファイル: Metadata.cs プロジェクト: cbries/railessentials
        public void Save(SaveModelType type)
        {
            switch (type)
            {
            case SaveModelType.MetamodelData:
                var strJson0 = Metamodel.ToString(Formatting.Indented);
                strJson0.FixBomIfNeeded();
                StringUtilities.WriteAllTextNoBom(_metamodelPath, strJson0, out _);
                break;

            case SaveModelType.OccData:
                Occ.Save();
                break;

            case SaveModelType.RouteData:
                var strJson2 = Routes.ToString(Formatting.Indented);
                strJson2.FixBomIfNeeded();
                StringUtilities.WriteAllTextNoBom(_routePath, strJson2, out _);
                break;

            case SaveModelType.LocomotivesData:
                var strJson3 = LocomotivesData.ToJsonString();
                strJson3.FixBomIfNeeded();
                StringUtilities.WriteAllTextNoBom(LocomotivesData.LocomotivesPath, strJson3, out _);
                break;

            case SaveModelType.FeedbacksData:
                var strJson4 = FeedbacksData.ToJsonString();
                strJson4.FixBomIfNeeded();
                StringUtilities.WriteAllTextNoBom(FeedbacksData.FeedbacksPath, strJson4, out _);
                break;

            case SaveModelType.LocomotivesDurationsData:
                var strJson5 = LocomotivesDurationData.ToJsonString();
                strJson5.FixBomIfNeeded();
                StringUtilities.WriteAllTextNoBom(LocomotivesDurationData.DurationsPath, strJson5, out _);
                break;
            }
        }