Ejemplo n.º 1
0
        internal static Activity FromPath(string filePath, Folder folder, Route route)
        {
            Activity result;

            try
            {
                ActivityFile activityFile = new ActivityFile(filePath);
                ServiceFile  srvFile      = new ServiceFile(route.RouteFolder.ServiceFile(activityFile.Activity.PlayerServices.Name));
                Consist      consist      = Consist.GetConsist(folder, srvFile.TrainConfig, false);
                Path         path         = new Path(route.RouteFolder.PathFile(srvFile.PathId));
                if (!path.IsPlayerPath)
                {
                    return(null);

                    // Not nice to throw an error now. Error was originally thrown by new Path(...);
                    throw new InvalidDataException("Not a player path");
                }
                else if (!activityFile.Activity.Header.RouteID.Equals(route.RouteID, StringComparison.OrdinalIgnoreCase))
                {
                    //Activity and route have different RouteID.
                    result = new Activity($"<{catalog.GetString("Not same route:")} {System.IO.Path.GetFileNameWithoutExtension(filePath)}>", filePath, null, null, null);
                }
                else
                {
                    result = new Activity(string.Empty, filePath, activityFile, consist, path);
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch
#pragma warning restore CA1031 // Do not catch general exception types
            {
                result = new Activity($"<{catalog.GetString("load error:")} {System.IO.Path.GetFileNameWithoutExtension(filePath)}>", filePath, null, null, null);
            }
            return(result);
        }
Ejemplo n.º 2
0
 public void UpdateActivity(string startTime, SeasonType season, WeatherType weather, Consist consist, Path path)
 {
     if (!TimeSpan.TryParse(startTime, out TimeSpan result))
     {
         result = new TimeSpan(12, 0, 0);
     }
     StartTime = result;
     Season    = season;
     Weather   = weather;
     Consist   = consist;
     Path      = path;
 }
Ejemplo n.º 3
0
 protected Activity(string name, string filePath, ActivityFile activityFile, Consist consist, Path path)
 {
     if (filePath == null && this is DefaultExploreActivity)
     {
         Name = catalog.GetString("- Explore Route -");
     }
     else if (filePath == null && this is ExploreThroughActivity)
     {
         Name = catalog.GetString("+ Explore in Activity Mode +");
     }
     else if (null != activityFile)
     {
         // ITR activities are excluded.
         Name = activityFile.Activity.Header.Name;
         if (activityFile.Activity.Header.Mode == ActivityMode.Introductory)
         {
             Name = "Introductory Train Ride";
         }
         Description = activityFile.Activity.Header.Description;
         Briefing    = activityFile.Activity.Header.Briefing;
         StartTime   = activityFile.Activity.Header.StartTime;
         Season      = activityFile.Activity.Header.Season;
         Weather     = activityFile.Activity.Header.Weather;
         Difficulty  = activityFile.Activity.Header.Difficulty;
         Duration    = activityFile.Activity.Header.Duration;
         Consist     = consist;
         Path        = path;
     }
     else
     {
         Name = name;
     }
     if (string.IsNullOrEmpty(Name))
     {
         Name = $"<{catalog.GetString("unnamed:")} {System.IO.Path.GetFileNameWithoutExtension(filePath)}>";
     }
     if (string.IsNullOrEmpty(Description))
     {
         Description = null;
     }
     if (string.IsNullOrEmpty(Briefing))
     {
         Briefing = null;
     }
     FilePath = filePath;
 }
Ejemplo n.º 4
0
        internal static Consist FromFile(string fileName, Folder folder, bool reverseConsist)
        {
            Consist result;

            try
            {
                ConsistFile conFile    = new ConsistFile(fileName);
                Locomotive  locomotive = GetLocomotive(conFile, folder, reverseConsist);
                result = new Consist(conFile, locomotive, fileName);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch
#pragma warning restore CA1031 // Do not catch general exception types
            {
                result = new Consist($"<{catalog.GetString("load error:")} {System.IO.Path.GetFileNameWithoutExtension(fileName)}>", fileName);
            }
            return(result);
        }