public static string ToTitleCaseInvariant(this string Input) { string output = ""; if (Input == null) { return(""); } foreach (string ThisString in Input.Split(' ')) { if (output.Length > 0) { output += " "; } if (ThisString.Length > 0) { output += ThisString.Substring(0, 1).ToUpperInvariant(); } if (ThisString.Length > 1) { output += ThisString.Substring(1).ToLowerInvariant(); } } return(output); }
public static bool Register(CommandDescriptor ThisCmdDescriptor) { //This is called WHEN initialised, NOT automatically! hooray for static class huh? :/ //if (_Name == null | _Version == 0 | _Date == null | _Author == null | _Descrption == null | _Usage == null | _Commands == null | _Handler == null) //{ // return false; //} foreach (var ThisFieldVar in ThisCmdDescriptor.GetType().GetFields(System.Reflection.BindingFlags.Public).ToArray()) { if (ThisFieldVar.GetValue(ThisCmdDescriptor) == null) { Console.WriteLine("&cERROR: &eFailure to register command: \"" + ThisCmdDescriptor._Name + "\". The Field " + ThisFieldVar.Name + " is left Null."); return(false); } } if (ThisCmdDescriptor._Disabled) { return(false); } foreach (string ThisString in ThisCmdDescriptor._Commands.ToArray()) { if (ThisString.StartsWith("//") | ThisString.StartsWith("@") | ThisString.StartsWith("@@") | ThisString.EndsWith(".")) { Console.WriteLine("&cERROR: &eFailure to register command: \"" + ThisCmdDescriptor._Name + "\". There is an alias that uses illegal characters, that would conflict with the way OpenYS handles user chat (for example, stating with \"@\")."); return(false); } if (!ThisString.StartsWith("/")) { Console.WriteLine("&cERROR: &eFailure to register command: \"" + ThisCmdDescriptor._Name + "\". There is an alias that does not start with the Command designator character: \"/\"."); return(false); } } if (Commands.List.Select(x => x._Name).Contains(ThisCmdDescriptor._Name)) { foreach (double ThisDouble in Commands.List.Where(x => x._Name == ThisCmdDescriptor._Name).Select(y => y._Version).ToArray()) { if (ThisDouble > ThisCmdDescriptor._Version) { Console.WriteLine("&cERROR: &eFailure to register command: \"" + ThisCmdDescriptor._Name + "\". There is already a command by this name and it is of a newer version."); return(false); } } //Console.WriteLine("&aSucessfully updated registered command: \"" + ThisCmdDescriptor._Name + "\"."); } //Console.WriteLine("&eSucessfully registered command: \"" + ThisCmdDescriptor._Name + "\"."); Commands.List.RemoveAll(x => x._Name == ThisCmdDescriptor._Name); Commands.List.Add(ThisCmdDescriptor); return(true); }
public void StringScenarioShouldFail() { Verify.ShouldFail(() => ThisString.ShouldBe(ThisOtherString, "Some additional context"), errorWithSource: @"ThisString should be ""this other string"" but was ""this string"" difference Difference | | | | | | | | | | | | | \|/ \|/ \|/ \|/ \|/ \|/ \|/ \|/ \|/ \|/ \|/ Index | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Expected Value | t h i s \s o t h e r \s s t r i n g Actual Value | t h i s \s s t r i n g Expected Code | 116 104 105 115 32 111 116 104 101 114 32 115 116 114 105 110 103 Actual Code | 116 104 105 115 32 115 116 114 105 110 103 Additional Info: Some additional context", errorWithoutSource: @"""this string"" should be ""this other string"" but was not difference Difference | | | | | | | | | | | | | \|/ \|/ \|/ \|/ \|/ \|/ \|/ \|/ \|/ \|/ \|/ Index | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Expected Value | t h i s \s o t h e r \s s t r i n g Actual Value | t h i s \s s t r i n g Expected Code | 116 104 105 115 32 111 116 104 101 114 32 115 116 114 105 110 103 Actual Code | 116 104 105 115 32 115 116 114 105 110 103 Additional Info: Some additional context"); }
public static int LoadAll() { int LoadedCount = 0; if (Directories.DirectoryExists("./Sequencers")) { //Console.WriteLine("!"); string[] Filenames = Directories.DirectoryGetFilenames("./Sequencers"); string[] SequencerLists = Filenames.Where(x => x.ToUpperInvariant().StartsWith("SEQ") && x.ToUpperInvariant().EndsWith(".DAT")).ToArray(); foreach (string ThisFileName in SequencerLists) { string[] SequencerStrings = Files.FileReadAllLines("./Sequencers/" + ThisFileName); string SequencerTitle = ThisFileName; List <string> SequencerCommands = new List <string>(); foreach (string ThisString in SequencerStrings) { if (ThisString.ToUpperInvariant().StartsWith("REM")) { continue; } if (ThisString.ToUpperInvariant() == "") { continue; } try { SequencerCommands.Add(ThisString); } catch (Exception e) { Log.Error(e); } } Sequencers.List.Add(new Sequencer(SequencerTitle, SequencerCommands)); LoadedCount++; } } return(LoadedCount); }
public static void Process(Client ThisClient, string RawCommand) { #region TRY: #if RELEASE try { #endif #endregion if (RawCommand == "/") { //Repeat Last Command. RawCommand = ThisClient.MessagesTyped.Last().Message; } Commands.CommandReader Cmd = new Commands.CommandReader(RawCommand); #region Private Messaging /* * if (Cmd._CmdString.ToUpperInvariant().StartsWith("@@")) * { * Cmd._CmdString = Cmd._CmdString.Remove(0, 1); * Messaging.GroupChatMessage(ThisClient, Cmd); * return; * } * if (Cmd._CmdString.ToUpperInvariant().StartsWith("@")) * { * Cmd._CmdString = Cmd._CmdString.Remove(0, 1); * Messaging.PrivateChatMessage(ThisClient, Cmd); * return; * } */ #endregion #region // (Escape-Key'd Commands) if (Cmd._CmdString.ToUpperInvariant().StartsWith("//")) { Cmd._CmdComplete = Cmd._CmdComplete.Remove(0, 1); Clients.AllClients.SendMessage("&2(" + ThisClient.Username + ")&f" + Cmd._CmdComplete); //Messaging.StandardChatMessage(ThisClient, Cmd); return; } #endregion #region /Help if (Cmd._CmdString.ToUpperInvariant() == "/HELP") { #region "/Help" if (Cmd._CmdArguments.Count() < 1) { //show help usage ThisClient.SendMessage("&eWelcome To OpenYS!"); ThisClient.SendMessage("&e For more information on commands available, type \"&a/Help Commands&e\"."); return; } #endregion #region "/Help /..." if (Cmd._CmdArguments[0].StartsWith("/")) { Cmd._CmdRawArguments = Cmd._CmdRawArguments.Substring(1, Cmd._CmdRawArguments.Length - 1); } if (Cmd._CmdArguments[0].ToUpperInvariant() == "COMMANDS") { ThisClient.SendMessage("&eUsage: &a" + "/Commands [Category]"); ThisClient.SendMessage("&e" + " " + "Lists the Command categories available\n\n If a category is specified, lists the commands in that category."); ThisClient.SendMessage("&e" + " Aliases: " + "&cNone."); return; } List <Commands.CommandDescriptor> MatchingCommands = Commands.FindCommand("/" + Cmd._CmdArguments[0]); if (MatchingCommands.Count() == 0) { if (OpenYS.BuildType == OpenYS._BuildType.Server) { ThisClient.SendMessage("&cCommand not found: \"" + Cmd._CmdArguments[0] + "\"."); return; } //ThisClient.YSFServer.SendMessage("&2(" + ThisClient.Username + ")&f" + Cmd._CmdComplete); return; } if (MatchingCommands.OneMatchingCommand()) { ThisClient.SendMessage("&eUsage: &a" + MatchingCommands[0]._Usage); ThisClient.SendMessage("&e" + " " + MatchingCommands[0]._Descrption); ThisClient.SendMessage("&e" + " Aliases: " + MatchingCommands[0]._Commands.Take(3).ToList().ToStringList()); } else { ThisClient.SendMessage("&cERROR: &eMore then one matching command found: \"" + Cmd._CmdArguments[0] + "\"."); } return; #endregion } #endregion #region /Commands if (Cmd._CmdString.ToUpperInvariant() == "/COMMANDS") { #region "/Commands" if (Cmd._CmdArguments.Count() < 1) { //show help usage List <string> Categories = new List <string>(); foreach (Commands.CommandDescriptor ThisCommand in Commands.List) { if (ThisCommand._Category == null) { continue; } if (ThisCommand._Hidden) { continue; } if (Categories.Contains(ThisCommand._Category.ToTitleCaseInvariant())) { continue; } Categories.Add(ThisCommand._Category.ToTitleCaseInvariant()); } Categories.Sort((x, y) => string.Compare(x, y)); string output = ""; foreach (string ThisString in Categories) { string Category = ThisString; if (ThisString.Length > 32) { Category = ThisString.Substring(0, 32); } output += "\n"; output += " &a" + Category + Strings.Repeat(" ", 32 - Category.Length); } if (output == "") { output = "\n &cNo commands categories found."; } ThisClient.SendMessage("&eCommand Categories: " + output); return; } #endregion #region "/Commands ..." List <Commands.CommandDescriptor> MatchingCommands = Commands.List.Where(x => x._Category.ToTitleCaseInvariant().Contains(Cmd._CmdArguments[0].ToTitleCaseInvariant())).ToList(); if (MatchingCommands.Count() == 0) { if (OpenYS.BuildType == OpenYS._BuildType.Server) { ThisClient.SendMessage("&cCommand Category not found: \"" + Cmd._CmdArguments[0] + "\"."); return; } //ThisClient.YSFServer.SendMessage("&2(" + ThisClient.Username + ")&f" + Cmd._CmdComplete); return; } else { string output = ""; MatchingCommands.Sort((x, y) => string.Compare(x._Name, y._Name)); foreach (Commands.CommandDescriptor ThisCmd in MatchingCommands) { if (ThisCmd._Hidden) { continue; } string Name = ThisCmd._Name; if (Name.Length > 24) { Name = ThisCmd._Name.Substring(0, 21) + "..."; } output += "\n"; output += " &a" + Name + Strings.Repeat(" ", 24 - Name.Length); string Description = ThisCmd._Descrption; if (Description.Length > (System.Console.WindowWidth - 24 - 4 - 1 - 3 - 1)) { Description = ThisCmd._Descrption.Substring(0, (System.Console.WindowWidth - 24 - 4 - 1 - 3 - 1)) + "..."; } output += " &e" + Description + Strings.Repeat(" ", (System.Console.WindowWidth - 24 - 4 - 1 - 1) - Description.Length); } if (output == "") { output = "\n &cNo commands found."; } ThisClient.SendMessage("&e" + MatchingCommands[0]._Category + " Commands: " + output); return; } #endregion } #endregion #region /... if (Cmd._CmdString.ToUpperInvariant().StartsWith("/")) { List <Commands.CommandDescriptor> MatchingCommands = Commands.FindCommand(Cmd._CmdString); if (MatchingCommands.Count() == 0) { if (OpenYS.BuildType == OpenYS._BuildType.Server) { ThisClient.SendMessage("&cCommand not found: \"" + Cmd._CmdComplete.Split(' ')[0] + "\"."); return; } //ThisClient.YSFServer.SendMessage("&2(" + ThisClient.Username + ")&f" + Cmd._CmdComplete); return; } if (MatchingCommands.OneMatchingCommand()) { MatchingCommands[0]._PreProcess(ThisClient, Cmd); } else { ThisClient.SendMessage("&cERROR: &eMore then one matching command found: \"" + Cmd._CmdString + "\"."); } return; } #endregion #region "BLAH BLAH BLAH" if (OpenYS.BuildType == OpenYS._BuildType.Server) { if (ThisClient.IsOP()) { Clients.AllClients.SendMessage("&c(&6" + ThisClient.Username + "&c)&f" + Cmd._CmdComplete); Log.Chat("&c(&6" + ThisClient.Username + "&c)&f" + Cmd._CmdComplete); } else { Clients.AllClients.SendMessage("&2(" + ThisClient.Username + "&2)&f" + Cmd._CmdComplete); Log.Chat("&2(" + ThisClient.Username + "&2)&f" + Cmd._CmdComplete); } } else { //ThisClient.YSFServer.SendMessage("(" + ThisClient.Username + ")" + Cmd._CmdComplete); } ////ThisClient.YSFServer.SendMessage("&2(" + ThisClient.Username + ")&f" + Cmd._CmdComplete); return; #endregion #region CATCH #if RELEASE } catch (Exception e) { ThisClient.BugReport(e); Log.Error(e); } #endif #endregion }
public static Aircraft Cache(this MetaData.Aircraft ThisAircraft) { Aircraft Output = CachedData._Aircraft.None; #region DAT File Exists? if (!Files.FileExists(Settings.Loading.YSFlightDirectory + ThisAircraft.AircraftPath0Dat)) { Log.Warning("Can't find .DAT File: \"" + Settings.Loading.YSFlightDirectory + ThisAircraft.AircraftPath0Dat + "\". Can't Cache!"); return(Output); } #endregion #region Load DAT File string[] DatFileContents = Files.FileReadAllLines(Settings.Loading.YSFlightDirectory + ThisAircraft.AircraftPath0Dat); List <string[]> SplitLines = new List <string[]>(); #endregion #region Process DAT File into Arguments foreach (string ThisLine in DatFileContents) { string[] ReadyToAdd = ThisLine.SplitPreservingQuotes(' '); if (ReadyToAdd.Length < 1) { continue; } if (ReadyToAdd[0].ToUpperInvariant() == "REM") { if (ReadyToAdd.Length < 2) { continue; } if (ReadyToAdd[1].ToUpperInvariant() != "OPENYS") { continue; } if (ReadyToAdd.Length < 4) { continue; } ReadyToAdd = ReadyToAdd.Skip(2).ToArray(); } List <string> Out = new List <string>(); foreach (string ThisString in ReadyToAdd) { if (ThisString.StartsWith("#")) { break; } if (ThisString.StartsWith(";")) { break; } Out.Add(ThisString); } SplitLines.Add(Out.ToArray()); } #endregion #region Set Cached Values from Arguments Output = new Aircraft(); foreach (FieldInfo ThisField in typeof(Aircraft).GetFields()) { //Foreach Field in Class... foreach (string[] ThisArgumentStack in SplitLines) { //compare against each line in dat file... if (ThisArgumentStack[0].ToUpperInvariant() == ThisField.Name) { //If DAT file command = field name... //2 VALUES: if (ThisArgumentStack.Length < 2) { Log.Warning("Bad .DAT Line in .DAT File: " + Settings.Loading.YSFlightDirectory + ThisAircraft.AircraftPath0Dat + ". " + ThisArgumentStack.ToStringList()); Debug.WriteLine("Bad .DAT Line - Break here to investigate."); } #region String if (ThisField.FieldType == typeof(string)) { ThisField.SetValue(Output, ThisArgumentStack[1]); continue; } #endregion #region Bool if (ThisField.FieldType == typeof(bool)) { bool Value = false; bool Failed = !Boolean.TryParse(ThisArgumentStack[1].ToUpperInvariant(), out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Int if (ThisField.FieldType == typeof(int)) { int Value = 0; bool Failed = !Int32.TryParse(ThisArgumentStack[1].ToUpperInvariant(), out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Double if (ThisField.FieldType == typeof(double)) { double Value = 0; bool Failed = !Double.TryParse(ThisArgumentStack[1].ToUpperInvariant(), out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Velocity.Knots if (ThisField.FieldType == typeof(Numbers.Velocity.Knots)) { Numbers.Velocity.Knots Value = 0; bool Failed = !ThisArgumentStack[1].AsKnots(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Velocity.MetersPerSecond if (ThisField.FieldType == typeof(Numbers.Velocity.MetersPerSecond)) { Numbers.Velocity.MetersPerSecond Value = 0; bool Failed = !ThisArgumentStack[1].AsMetersPerSecond(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Velocity.MilesPerHour if (ThisField.FieldType == typeof(Numbers.Velocity.MilesPerHour)) { Numbers.Velocity.MilesPerHour Value = 0; bool Failed = !ThisArgumentStack[1].AsMilesPerHour(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Velocity.KilometersPerHour if (ThisField.FieldType == typeof(Numbers.Velocity.KilometersPerHour)) { Numbers.Velocity.KilometersPerHour Value = 0; bool Failed = !ThisArgumentStack[1].AsKilometersPerHour(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Velocity.FeetPerSecond if (ThisField.FieldType == typeof(Numbers.Velocity.FeetPerSecond)) { Numbers.Velocity.FeetPerSecond Value = 0; bool Failed = !ThisArgumentStack[1].AsFeetPerSecond(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Velocity.MachAtSeaLevel if (ThisField.FieldType == typeof(Numbers.Velocity.MachAtSeaLevel)) { Numbers.Velocity.MachAtSeaLevel Value = 0; bool Failed = !ThisArgumentStack[1].AsMachAtSeaLevel(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Length.Kilometers if (ThisField.FieldType == typeof(Numbers.Length.Kilometers)) { Numbers.Length.Kilometers Value = 0; bool Failed = !ThisArgumentStack[1].AsKilometers(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Length.Meters if (ThisField.FieldType == typeof(Numbers.Length.Meters)) { Numbers.Length.Meters Value = 0; bool Failed = !ThisArgumentStack[1].AsMeters(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Length.Centimeters if (ThisField.FieldType == typeof(Numbers.Length.Centimeters)) { Numbers.Length.Centimeters Value = 0; bool Failed = !ThisArgumentStack[1].AsCentimeters(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Length.Miles if (ThisField.FieldType == typeof(Numbers.Length.Miles)) { Numbers.Length.Miles Value = 0; bool Failed = !ThisArgumentStack[1].AsMiles(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Length.NauticalMiles if (ThisField.FieldType == typeof(Numbers.Length.NauticalMiles)) { Numbers.Length.NauticalMiles Value = 0; bool Failed = !ThisArgumentStack[1].AsNauticalMiles(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Length.Yards if (ThisField.FieldType == typeof(Numbers.Length.Yards)) { Numbers.Length.Yards Value = 0; bool Failed = !ThisArgumentStack[1].AsYards(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Length.Feet if (ThisField.FieldType == typeof(Numbers.Length.Feet)) { Numbers.Length.Feet Value = 0; bool Failed = !ThisArgumentStack[1].AsFeet(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Length.Inches if (ThisField.FieldType == typeof(Numbers.Length.Inches)) { Numbers.Length.Inches Value = 0; bool Failed = !ThisArgumentStack[1].AsInches(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Mass.Tonnes if (ThisField.FieldType == typeof(Numbers.Mass.Tonnes)) { Numbers.Mass.Tonnes Value = 0; bool Failed = !ThisArgumentStack[1].AsTonnes(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Mass.Kilograms if (ThisField.FieldType == typeof(Numbers.Mass.Kilograms)) { Numbers.Mass.Kilograms Value = 0; bool Failed = !ThisArgumentStack[1].AsKilograms(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Mass.Grams if (ThisField.FieldType == typeof(Numbers.Mass.Grams)) { Numbers.Mass.Grams Value = 0; bool Failed = !ThisArgumentStack[1].AsGrams(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Mass.Pounds if (ThisField.FieldType == typeof(Numbers.Mass.Pounds)) { Numbers.Mass.Pounds Value = 0; bool Failed = !ThisArgumentStack[1].AsPounds(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Mass.Ounces if (ThisField.FieldType == typeof(Numbers.Mass.Ounces)) { Numbers.Mass.Ounces Value = 0; bool Failed = !ThisArgumentStack[1].AsOunces(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Mass.Stones if (ThisField.FieldType == typeof(Numbers.Mass.Stones)) { Numbers.Mass.Stones Value = 0; bool Failed = !ThisArgumentStack[1].AsStones(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Angles.Degrees if (ThisField.FieldType == typeof(Numbers.Angles.Degrees)) { Numbers.Angles.Degrees Value = 0; bool Failed = ThisArgumentStack[1].AsDegrees(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Angles.Radians if (ThisField.FieldType == typeof(Numbers.Angles.Radians)) { Numbers.Angles.Radians Value = 0; bool Failed = ThisArgumentStack[1].AsRadians(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion #region Angles.Gradians if (ThisField.FieldType == typeof(Numbers.Angles.Gradians)) { Numbers.Angles.Gradians Value = 0; bool Failed = ThisArgumentStack[1].AsGradians(out Value); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ", " + ThisArgumentStack[0] + ": " + ThisArgumentStack[1]); Debug.WriteLine("Failed to convert value."); } ThisField.SetValue(Output, Value); continue; } #endregion //3 VALUES: if (ThisArgumentStack.Length < 3) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ": " + ThisArgumentStack.ToArray().ToStringList()); Debug.WriteLine("Bad .DAT Line - Break here to investigate."); } //4 VALUES: if (ThisArgumentStack.Length < 4) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ": " + ThisArgumentStack.ToArray().ToStringList()); Debug.WriteLine("Bad .DAT Line - Break here to investigate."); } #region Math3D.Point3 if (ThisField.FieldType == typeof(Math3D.Point3)) { Math3D.Point3 Value = new Math3D.Point3(0, 0, 0); Numbers.Length.Meters _X = 0; Numbers.Length.Meters _Y = 0; Numbers.Length.Meters _Z = 0; bool Failed = !ThisArgumentStack[1].AsMeters(out _X); Failed |= !ThisArgumentStack[2].AsMeters(out _Y); Failed |= !ThisArgumentStack[3].AsMeters(out _Z); if (Failed) { Log.Warning("Failed to Convert Dat Variable for " + ThisAircraft.Identify + ": " + ThisArgumentStack.Skip(1).ToArray().ToStringList()); Debug.WriteLine("Failed to convert value."); } Value.X = _X; Value.Y = _Y; Value.Z = _Z; ThisField.SetValue(Output, Value); continue; } #endregion Log.Warning("Dat Variable Not Recognised for " + ThisAircraft.Identify + "?: " + ThisArgumentStack.ToArray().ToStringList()); Debug.WriteLine("Value not recognised."); } } //Debug.WriteLine(ThisField.ToString()); } #endregion #region Post-Conversion Integrity Checks if (Output.WEIGFUEL <= 0) { Log.Warning("Something went wrong in conversion of fuel? " + ThisAircraft.Identify); } #endregion return(Output); }
public static int LoadAll() { int LoadedCount = 0; if (Directories.DirectoryExists("./Schedulers")) { string[] Filenames = Directories.DirectoryGetFilenames("./Schedulers"); string[] SchedulerLists = Filenames.Where(x => x.ToUpperInvariant().StartsWith("SCHED") && x.ToUpperInvariant().EndsWith(".DAT")).ToArray(); foreach (string ThisFileName in SchedulerLists) { string[] SchedulerStrings = Files.FileReadAllLines("./Schedulers/" + ThisFileName); foreach (string ThisString in SchedulerStrings) { if (ThisString.ToUpperInvariant().StartsWith("REM")) { continue; } if (ThisString.ToUpperInvariant() == "") { continue; } try { string temp = ThisString; temp = ThisString.ReplaceAll("\t", " "); string Date = temp.Split(new char[] { ' ' }, 2)[0]; string Message = temp.Split(new char[] { ' ' }, 2)[1]; //YYYYMMDD(HH:mm:ss) DateTime TargetDateTime = new DateTime(0); int Year = 0; int Month = 0; int Day = 0; int Hour = 0; int Minute = 0; int Second = 0; bool Failed = false; Failed |= !Int32.TryParse(Date.Substring(0, 4), out Year); Failed |= !Int32.TryParse(Date.Substring(4, 2), out Month); Failed |= !Int32.TryParse(Date.Substring(6, 2), out Day); Failed |= !Int32.TryParse(Date.Substring(9, 2), out Hour); Failed |= !Int32.TryParse(Date.Substring(12, 2), out Minute); Failed |= !Int32.TryParse(Date.Substring(15, 2), out Second); string dateString = Date; CultureInfo enUS = new CultureInfo("en-US"); if (!Failed) { DateTime.TryParseExact(dateString, "yyyyMMdd(hh:mm:ss)", enUS, DateTimeStyles.None, out TargetDateTime); } if ((TargetDateTime - DateTime.Now).TotalMinutes > 15) { //Console.WriteLine(DateTime.Now.Second + " TOO FAR!"); //This scheduler will not happen in the next fifteen minutes, //we will attempt to reload it in the next 10 minute cycle tick! //We set the timer to 15 just as a safeguard to ensure the thread will happen! //(RARE race condition that the scheduler lines up perfectly, and doesn't load it!) continue; } if ((TargetDateTime - DateTime.Now).TotalMinutes < 0) { //Console.WriteLine(DateTime.Now.Second + " TOO EARLY!"); //This scheduler is already overdue, it will be ignored! continue; } //Console.WriteLine(DateTime.Now.Second + " OK!"); Schedulers.List.Add(new Scheduler(TargetDateTime, Message)); LoadedCount++; } catch (Exception e) { Log.Error(e); return(0); } } } } return(LoadedCount); }