private void ButtonCreateSection_Click(object sender, RoutedEventArgs e) { try { if (ValidateInput()) { Section section = new Section { Name = name.Text, ProjectId = projectID, DueDate = DateTime.Parse(deadline.Text) }; SectionDAO sectionDAO = new SectionDAO(); int sectionID = sectionDAO.CreateSection(section); if (sectionDAO.Read(sectionID) != null) { SectionElement sectionElement = new SectionElement(sectionList); sectionElement.SectionID.Name = "Section" + sectionID; sectionElement.SectionName.Text = name.Text; sectionList.Children.Insert(sectionList.Children.Count - 1, sectionElement); this.Close(); } } } catch (Exception exception) { utilities.GetNotifier().ShowError(utilities.HandleException(exception)); } }
private static void SetSectionDependencies(SectionElement[] sections, SectionElement section, DependentModuleInfo dmi) { if (section.Dependencies == null) { return; } foreach (DependencyElement dep in section.Dependencies) { bool dependentSectionFound = false; foreach (SectionElement sec in sections) { if (sec.Name == dep.Name) { dependentSectionFound = true; foreach (ModuleInfoElement mod in sec.Modules) { dmi.Dependencies.Add(mod.Name); } break; } } if (!dependentSectionFound) { throw new InvalidOperationException(string.Format(Properties.Resources.DependencyNotFound, section.Name, dep.Name)); } } }
private bool Write(SectionElement section) { if (section == null) { return(false); } float sizeChange = ((((2f - section.Depth) / 2f) * 0.5f) + 1f); if (!ShowSectionHeadings) { return(true); } string[] lines = BreakIntoLines(section.Value, _settings.EffectiveCharWidth * sizeChange, _settings.WritablePageWidth()); if (!HaveRoomFor(lines.Length)) { NewPage(); } _page.SetFont(_courierBold, _settings.FontSize * sizeChange); foreach (string line in lines) { WriteLine(line); MoveDown(-1); MoveDownPoints(-_settings.EffectiveCharHeight * sizeChange); } _page.SetFont(_courier, _settings.FontSize); EmptyLine(); return(true); }
public void EmptySection() { XapFile file = new XapFile(); file.Open(XactEmptySection); SectionElement root = file["Section"] as SectionElement; Assert.NotNull(root); }
public void EmptySectionWithEmptyChild() { XapFile file = new XapFile(); file.Open(XactEmptySectionWithEmptyChild); SectionElement root = file["Section"] as SectionElement; SectionElement child = root.Value["SubSection"] as SectionElement; Assert.NotNull(child); }
public void SectionWithScalarsAndSubSections() { XapFile file = new XapFile(); file.Open(XactSectionWithScalarsAndSubSections); SectionElement root = file["Section"] as SectionElement; Assert.NotNull(root); Assert.Equal(3, root.Value.ElementCount); Assert.IsType(typeof(ScalarElement), root.Value["Foo"]); Assert.IsType(typeof(ScalarElement), root.Value["Baz"]); Assert.IsType(typeof(SectionElement), root.Value["SubSection"]); }
void WriteSection(Section section, Stream stream, ref StringBuilder sb, int indent) { String indentChars = "".PadLeft(4 * indent); foreach (IElement element in section) { ScalarElement scalar = element as ScalarElement; if (scalar != null) { sb.AppendFormat("{0}{1} = {2};\r\n", indentChars, element.Name, scalar.Value); } SectionElement se = element as SectionElement; if (se != null) { Section subSection = se.Value; sb.AppendFormat("\r\n{0}{1}\r\n{0}{{\r\n", indentChars, element.Name); WriteSection(subSection, stream, ref sb, indent + 1); sb.AppendFormat("{0}}}\r\n", indentChars); } } WriteStringBuilder(stream, ref sb); }
private void ParsePanelAnimatedNode(XElement Element, string FileName, string TrainPath, TrainBase Train, int Car, CarSection CarSection, int GroupIndex) { System.Globalization.CultureInfo Culture = System.Globalization.CultureInfo.InvariantCulture; int currentSectionElement = 0; int numberOfSectionElements = Element.Elements().Count(); double invfac = numberOfSectionElements == 0 ? 1.0 : 1.0 / (double)numberOfSectionElements; foreach (XElement SectionElement in Element.Elements()) { Plugin.CurrentProgress = Plugin.CurrentProgress + invfac * (double)currentSectionElement; if ((currentSectionElement & 4) == 0) { System.Threading.Thread.Sleep(1); if (Plugin.Cancel) { return; } } string Section = SectionElement.Name.LocalName; switch (SectionElement.Name.LocalName.ToLowerInvariant()) { case "group": if (GroupIndex == 0) { int n = 0; foreach (XElement KeyNode in SectionElement.Elements()) { string Key = KeyNode.Name.LocalName; string Value = KeyNode.Value; int LineNumber = ((IXmlLineInfo)KeyNode).LineNumber; switch (Key.ToLowerInvariant()) { case "number": if (Value.Length != 0 && !NumberFormats.TryParseIntVb6(Value, out n)) { Plugin.currentHost.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; } } if (n + 1 >= CarSection.Groups.Length) { Array.Resize(ref CarSection.Groups, n + 2); CarSection.Groups[n + 1] = new ElementsGroup(ObjectType.Overlay); } ParsePanelAnimatedNode(SectionElement, FileName, TrainPath, Train, Car, CarSection, n + 1); } break; case "touch": if (GroupIndex > 0) { Vector3 Position = Vector3.Zero; Vector3 Size = Vector3.Zero; int JumpScreen = GroupIndex - 1; List <int> SoundIndices = new List <int>(); List <CommandEntry> CommandEntries = new List <CommandEntry>(); CommandEntry CommandEntry = new CommandEntry(); foreach (XElement KeyNode in SectionElement.Elements()) { string Key = KeyNode.Name.LocalName; string Value = KeyNode.Value; int LineNumber = ((IXmlLineInfo)KeyNode).LineNumber; switch (Key.ToLowerInvariant()) { case "position": if (!Vector3.TryParse(KeyNode.Value, ',', out Position)) { Plugin.currentHost.AddMessage(MessageType.Error, false, "Position is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; case "size": if (!Vector3.TryParse(KeyNode.Value, ',', out Size)) { Plugin.currentHost.AddMessage(MessageType.Error, false, "Size is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; case "jumpscreen": if (Value.Length != 0 && !NumberFormats.TryParseIntVb6(Value, out JumpScreen)) { Plugin.currentHost.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; case "soundindex": if (Value.Length != 0) { int SoundIndex; if (!NumberFormats.TryParseIntVb6(Value, out SoundIndex)) { Plugin.currentHost.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } SoundIndices.Add(SoundIndex); } break; case "command": { if (!CommandEntries.Contains(CommandEntry)) { CommandEntries.Add(CommandEntry); } if (string.Compare(Value, "N/A", StringComparison.InvariantCultureIgnoreCase) == 0) { break; } int i; for (i = 0; i < Translations.CommandInfos.Length; i++) { if (string.Compare(Value, Translations.CommandInfos[i].Name, StringComparison.OrdinalIgnoreCase) == 0) { break; } } if (i == Translations.CommandInfos.Length || Translations.CommandInfos[i].Type != Translations.CommandType.Digital) { Plugin.currentHost.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } else { CommandEntry.Command = Translations.CommandInfos[i].Command; } } break; case "commandoption": if (!CommandEntries.Contains(CommandEntry)) { CommandEntries.Add(CommandEntry); } if (Value.Length != 0 && !NumberFormats.TryParseIntVb6(Value, out CommandEntry.Option)) { Plugin.currentHost.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; case "soundentries": if (!KeyNode.HasElements) { Plugin.currentHost.AddMessage(MessageType.Error, false, $"An empty list of touch sound indices was defined at line {((IXmlLineInfo)KeyNode).LineNumber} in XML file {FileName}"); break; } ParseTouchSoundEntryNode(FileName, KeyNode, SoundIndices); break; case "commandentries": if (!KeyNode.HasElements) { Plugin.currentHost.AddMessage(MessageType.Error, false, $"An empty list of touch commands was defined at line {((IXmlLineInfo)KeyNode).LineNumber} in XML file {FileName}"); break; } ParseTouchCommandEntryNode(FileName, KeyNode, CommandEntries); break; } } CreateTouchElement(CarSection.Groups[GroupIndex], Position, Size, JumpScreen, SoundIndices.ToArray(), CommandEntries.ToArray()); } break; case "include": { foreach (XElement KeyNode in SectionElement.Elements()) { string Key = KeyNode.Name.LocalName; string Value = KeyNode.Value; int LineNumber = ((IXmlLineInfo)KeyNode).LineNumber; switch (Key.ToLowerInvariant()) { case "filename": { string File = OpenBveApi.Path.CombineFile(TrainPath, Value); if (System.IO.File.Exists(File)) { System.Text.Encoding e = TextEncoding.GetSystemEncodingFromFile(File); UnifiedObject currentObject; Plugin.currentHost.LoadObject(File, e, out currentObject); var a = currentObject as AnimatedObjectCollection; if (a != null) { for (int i = 0; i < a.Objects.Length; i++) { Plugin.currentHost.CreateDynamicObject(ref a.Objects[i].internalObject); } CarSection.Groups[GroupIndex].Elements = a.Objects; } else { Plugin.currentHost.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } } } break; } } } break; } } }
private static void ParsePanelAnimatedNode(XElement Element, string FileName, string TrainPath, TrainManager.Train Train, int Car, TrainManager.CarSection CarSection, int GroupIndex) { System.Globalization.CultureInfo Culture = System.Globalization.CultureInfo.InvariantCulture; int currentSectionElement = 0; int numberOfSectionElements = Element.Elements().Count(); double invfac = numberOfSectionElements == 0 ? Loading.TrainProgressCurrentWeight : Loading.TrainProgressCurrentWeight / (double)numberOfSectionElements; foreach (XElement SectionElement in Element.Elements()) { Loading.TrainProgress = Loading.TrainProgressCurrentSum + invfac * (double)currentSectionElement; if ((currentSectionElement & 4) == 0) { System.Threading.Thread.Sleep(1); if (Loading.Cancel) { return; } } string Section = SectionElement.Name.LocalName; switch (SectionElement.Name.LocalName.ToLowerInvariant()) { case "group": if (GroupIndex == 0) { int n = 0; foreach (XElement KeyNode in SectionElement.Elements()) { string Key = KeyNode.Name.LocalName; string Value = KeyNode.Value; int LineNumber = ((IXmlLineInfo)KeyNode).LineNumber; switch (Key.ToLowerInvariant()) { case "number": if (Value.Length != 0 && !NumberFormats.TryParseIntVb6(Value, out n)) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; } } if (n + 1 >= CarSection.Groups.Length) { Array.Resize(ref CarSection.Groups, n + 2); CarSection.Groups[n + 1] = new TrainManager.ElementsGroup { Elements = new ObjectManager.AnimatedObject[] { }, Overlay = true }; } ParsePanelAnimatedNode(SectionElement, FileName, TrainPath, Train, Car, CarSection, n + 1); } break; case "touch": if (GroupIndex > 0) { Vector3 Position = Vector3.Zero; Vector3 Size = Vector3.Zero; int JumpScreen = GroupIndex - 1; int SoundIndex = -1; Translations.Command Command = Translations.Command.None; int CommandOption = 0; foreach (XElement KeyNode in SectionElement.Elements()) { string Key = KeyNode.Name.LocalName; string Value = KeyNode.Value; int LineNumber = ((IXmlLineInfo)KeyNode).LineNumber; switch (Key.ToLowerInvariant()) { case "position": { string[] s = Value.Split(','); if (s.Length == 3) { if (s[0].Length != 0 && !NumberFormats.TryParseDoubleVb6(s[0], out Position.X)) { Interface.AddMessage(MessageType.Error, false, "X is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } if (s[1].Length != 0 && !NumberFormats.TryParseDoubleVb6(s[1], out Position.Y)) { Interface.AddMessage(MessageType.Error, false, "Y is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } if (s[2].Length != 0 && !NumberFormats.TryParseDoubleVb6(s[2], out Position.Z)) { Interface.AddMessage(MessageType.Error, false, "Z is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } } else { Interface.AddMessage(MessageType.Error, false, "Three arguments are expected in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } } break; case "size": { string[] s = Value.Split(','); if (s.Length == 3) { if (s[0].Length != 0 && !NumberFormats.TryParseDoubleVb6(s[0], out Size.X)) { Interface.AddMessage(MessageType.Error, false, "X is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } if (s[1].Length != 0 && !NumberFormats.TryParseDoubleVb6(s[1], out Size.Y)) { Interface.AddMessage(MessageType.Error, false, "Y is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } if (s[2].Length != 0 && !NumberFormats.TryParseDoubleVb6(s[2], out Size.Z)) { Interface.AddMessage(MessageType.Error, false, "Z is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } } else { Interface.AddMessage(MessageType.Error, false, "Three arguments are expected in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } } break; case "jumpscreen": if (Value.Length != 0 && !NumberFormats.TryParseIntVb6(Value, out JumpScreen)) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; case "soundindex": if (Value.Length != 0 && !NumberFormats.TryParseIntVb6(Value, out SoundIndex)) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; case "command": { int i; for (i = 0; i < Translations.CommandInfos.Length; i++) { if (string.Compare(Value, Translations.CommandInfos[i].Name, StringComparison.OrdinalIgnoreCase) == 0) { break; } } if (i == Translations.CommandInfos.Length || Translations.CommandInfos[i].Type != Translations.CommandType.Digital) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } else { Command = Translations.CommandInfos[i].Command; } } break; case "commandoption": if (Value.Length != 0 && !NumberFormats.TryParseIntVb6(Value, out CommandOption)) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; } } CreateTouchElement(CarSection.Groups[GroupIndex], Position, Size, JumpScreen, SoundIndex, Command, CommandOption); } break; case "include": { foreach (XElement KeyNode in SectionElement.Elements()) { string Key = KeyNode.Name.LocalName; string Value = KeyNode.Value; int LineNumber = ((IXmlLineInfo)KeyNode).LineNumber; switch (Key.ToLowerInvariant()) { case "filename": { string File = OpenBveApi.Path.CombineFile(TrainPath, Value); if (System.IO.File.Exists(File)) { System.Text.Encoding e = TextEncoding.GetSystemEncodingFromFile(File); ObjectManager.AnimatedObjectCollection a = AnimatedObjectParser.ReadObject(File, e); if (a != null) { for (int i = 0; i < a.Objects.Length; i++) { a.Objects[i].ObjectIndex = ObjectManager.CreateDynamicObject(); } CarSection.Groups[GroupIndex].Elements = a.Objects; } else { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } } } break; } } } break; } } }
/// <summary>Parses a base track following object node</summary> /// <param name="Element">The XElement to parse</param> /// <param name="FileName">The filename of the containing XML file</param> /// <param name="Path">The path of the containing XML file</param> /// <param name="Train">The track following object to parse this node into</param> private static void ParseTrackFollowingObjectNode(XElement Element, string FileName, string Path, string ObjectPath, TrainManager.TrackFollowingObject Train) { System.Globalization.CultureInfo Culture = System.Globalization.CultureInfo.InvariantCulture; string TrainDirectory = string.Empty; bool consistReversed = false; List <Game.TravelData> Data = new List <Game.TravelData>(); foreach (XElement SectionElement in Element.Elements()) { string Section = SectionElement.Name.LocalName; switch (SectionElement.Name.LocalName.ToLowerInvariant()) { case "stops": ParseStopNode(SectionElement, FileName, Data); break; case "train": foreach (XElement KeyNode in SectionElement.Elements()) { string Key = KeyNode.Name.LocalName; string Value = KeyNode.Value; int LineNumber = ((IXmlLineInfo)KeyNode).LineNumber; switch (Key.ToLowerInvariant()) { case "directory": { string trainDirectory = OpenBveApi.Path.CombineDirectory(Path, Value); if (!System.IO.Directory.Exists(trainDirectory)) { trainDirectory = OpenBveApi.Path.CombineFile(Program.FileSystem.InitialTrainFolder, Value); } if (!System.IO.Directory.Exists(trainDirectory)) { trainDirectory = OpenBveApi.Path.CombineFile(Program.FileSystem.TrainInstallationDirectory, Value); } if (!System.IO.Directory.Exists(trainDirectory)) { trainDirectory = OpenBveApi.Path.CombineFile(ObjectPath, Value); } if (!System.IO.Directory.Exists(trainDirectory)) { Interface.AddMessage(MessageType.Error, false, "Directory was not found in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } else { TrainDirectory = trainDirectory; } } break; case "reversed": int n; NumberFormats.TryParseIntVb6(Value, out n); if (n == 1 || Value.ToLowerInvariant() == "true") { consistReversed = true; } break; } } break; case "definition": foreach (XElement KeyNode in SectionElement.Elements()) { string Key = KeyNode.Name.LocalName; string Value = KeyNode.Value; int LineNumber = ((IXmlLineInfo)KeyNode).LineNumber; switch (Key.ToLowerInvariant()) { case "appearancetime": if (Value.Length != 0 && !Interface.TryParseTime(Value, out Train.AppearanceTime)) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; case "appearancestartposition": if (Value.Length != 0 && !NumberFormats.TryParseDoubleVb6(Value, out Train.AppearanceStartPosition)) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; case "appearanceendposition": if (Value.Length != 0 && !NumberFormats.TryParseDoubleVb6(Value, out Train.AppearanceEndPosition)) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; case "leavetime": if (Value.Length != 0 && !Interface.TryParseTime(Value, out Train.LeaveTime)) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; } } break; } } if (!Data.Any() || string.IsNullOrEmpty(TrainDirectory)) { return; } /* * First check for a train.ai file- Functionally identical, but allows for differently configured AI * trains not to show up as driveable */ string TrainData = OpenBveApi.Path.CombineFile(TrainDirectory, "train.ai"); if (!System.IO.File.Exists(TrainData)) { // Check for the standard driveable train.dat TrainData = OpenBveApi.Path.CombineFile(TrainDirectory, "train.dat"); } string ExteriorFile = OpenBveApi.Path.CombineFile(TrainDirectory, "extensions.cfg"); if (!System.IO.File.Exists(TrainData) || !System.IO.File.Exists(ExteriorFile)) { Interface.AddMessage(MessageType.Error, true, "The supplied train folder in TrackFollowingObject " + FileName + " did not contain a complete set of data."); return; } TrainDatParser.ParseTrainData(TrainData, TextEncoding.GetSystemEncodingFromFile(TrainData), Train); SoundCfgParser.ParseSoundConfig(TrainDirectory, Train); Train.AI = new Game.TrackFollowingObjectAI(Train, Data); UnifiedObject[] CarObjects = new UnifiedObject[Train.Cars.Length]; UnifiedObject[] BogieObjects = new UnifiedObject[Train.Cars.Length * 2]; UnifiedObject[] CouplerObjects = new UnifiedObject[Train.Cars.Length - 1]; ExtensionsCfgParser.ParseExtensionsConfig(System.IO.Path.GetDirectoryName(ExteriorFile), TextEncoding.GetSystemEncodingFromFile(ExteriorFile), ref CarObjects, ref BogieObjects, ref CouplerObjects, Train, true); int currentBogieObject = 0; for (int i = 0; i < Train.Cars.Length; i++) { if (CarObjects[i] == null) { // load default exterior object string file = OpenBveApi.Path.CombineFile(Program.FileSystem.GetDataFolder("Compatibility"), "exterior.csv"); StaticObject so = ObjectManager.LoadStaticObject(file, System.Text.Encoding.UTF8, false); if (so == null) { CarObjects[i] = null; } else { double sx = Train.Cars[i].Width; double sy = Train.Cars[i].Height; double sz = Train.Cars[i].Length; so.ApplyScale(sx, sy, sz); CarObjects[i] = so; } } if (CarObjects[i] != null) { // add object Train.Cars[i].LoadCarSections(CarObjects[i]); } //Load bogie objects if (BogieObjects[currentBogieObject] != null) { Train.Cars[i].FrontBogie.LoadCarSections(BogieObjects[currentBogieObject]); } currentBogieObject++; if (BogieObjects[currentBogieObject] != null) { Train.Cars[i].RearBogie.LoadCarSections(BogieObjects[currentBogieObject]); } currentBogieObject++; } // door open/close speed foreach (var Car in Train.Cars) { if (Car.Specs.DoorOpenFrequency <= 0.0) { if (Car.Doors[0].OpenSound.Buffer != null & Car.Doors[1].OpenSound.Buffer != null) { Program.Sounds.LoadBuffer(Car.Doors[0].OpenSound.Buffer); Program.Sounds.LoadBuffer(Car.Doors[1].OpenSound.Buffer); double a = Car.Doors[0].OpenSound.Buffer.Duration; double b = Car.Doors[1].OpenSound.Buffer.Duration; Car.Specs.DoorOpenFrequency = a + b > 0.0 ? 2.0 / (a + b) : 0.8; } else if (Car.Doors[0].OpenSound.Buffer != null) { Program.Sounds.LoadBuffer(Car.Doors[0].OpenSound.Buffer); double a = Car.Doors[0].OpenSound.Buffer.Duration; Car.Specs.DoorOpenFrequency = a > 0.0 ? 1.0 / a : 0.8; } else if (Car.Doors[1].OpenSound.Buffer != null) { Program.Sounds.LoadBuffer(Car.Doors[0].OpenSound.Buffer); double b = Car.Doors[1].OpenSound.Buffer.Duration; Car.Specs.DoorOpenFrequency = b > 0.0 ? 1.0 / b : 0.8; } else { Car.Specs.DoorOpenFrequency = 0.8; } } if (Car.Specs.DoorCloseFrequency <= 0.0) { if (Car.Doors[0].CloseSound.Buffer != null & Car.Doors[1].CloseSound.Buffer != null) { Program.Sounds.LoadBuffer(Car.Doors[0].CloseSound.Buffer); Program.Sounds.LoadBuffer(Car.Doors[1].CloseSound.Buffer); double a = Car.Doors[0].CloseSound.Buffer.Duration; double b = Car.Doors[1].CloseSound.Buffer.Duration; Car.Specs.DoorCloseFrequency = a + b > 0.0 ? 2.0 / (a + b) : 0.8; } else if (Car.Doors[0].CloseSound.Buffer != null) { Program.Sounds.LoadBuffer(Car.Doors[0].CloseSound.Buffer); double a = Car.Doors[0].CloseSound.Buffer.Duration; Car.Specs.DoorCloseFrequency = a > 0.0 ? 1.0 / a : 0.8; } else if (Car.Doors[1].CloseSound.Buffer != null) { Program.Sounds.LoadBuffer(Car.Doors[0].CloseSound.Buffer); double b = Car.Doors[1].CloseSound.Buffer.Duration; Car.Specs.DoorCloseFrequency = b > 0.0 ? 1.0 / b : 0.8; } else { Car.Specs.DoorCloseFrequency = 0.8; } } const double f = 0.015; const double g = 2.75; Car.Specs.DoorOpenPitch = Math.Exp(f * Math.Tan(g * (Program.RandomNumberGenerator.NextDouble() - 0.5))); Car.Specs.DoorClosePitch = Math.Exp(f * Math.Tan(g * (Program.RandomNumberGenerator.NextDouble() - 0.5))); Car.Specs.DoorOpenFrequency /= Car.Specs.DoorOpenPitch; Car.Specs.DoorCloseFrequency /= Car.Specs.DoorClosePitch; /* * Remove the following two lines, then the pitch at which doors play * takes their randomized opening and closing times into account. * */ Car.Specs.DoorOpenPitch = 1.0; Car.Specs.DoorClosePitch = 1.0; } foreach (var Car in Train.Cars) { Car.FrontAxle.Follower.TrackIndex = Data[0].RailIndex; Car.RearAxle.Follower.TrackIndex = Data[0].RailIndex; Car.FrontBogie.FrontAxle.Follower.TrackIndex = Data[0].RailIndex; Car.FrontBogie.RearAxle.Follower.TrackIndex = Data[0].RailIndex; Car.RearBogie.FrontAxle.Follower.TrackIndex = Data[0].RailIndex; Car.RearBogie.RearAxle.Follower.TrackIndex = Data[0].RailIndex; } if (consistReversed) { Train.Reverse(); } Train.PlaceCars(Data[0].StopPosition); }
/// <summary>Parses a train travel stop node</summary> /// <param name="Element">The XElement to parse</param> /// <param name="FileName">The filename of the containing XML file</param> /// <param name="Data">The list of travel data to add this to</param> private static void ParseStopNode(XElement Element, string FileName, List <Game.TravelData> Data) { System.Globalization.CultureInfo Culture = System.Globalization.CultureInfo.InvariantCulture; foreach (XElement SectionElement in Element.Elements()) { string Section = SectionElement.Name.LocalName; switch (SectionElement.Name.LocalName.ToLowerInvariant()) { case "stop": { Game.TravelData NewData = new Game.TravelData(); double Decelerate = 0.0; double Accelerate = 0.0; double TargetSpeed = 0.0; foreach (XElement KeyNode in SectionElement.Elements()) { string Key = KeyNode.Name.LocalName; string Value = KeyNode.Value; int LineNumber = ((IXmlLineInfo)KeyNode).LineNumber; switch (Key.ToLowerInvariant()) { case "decelerate": if (Value.Length != 0 && !NumberFormats.TryParseDoubleVb6(Value, out Decelerate)) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; case "stopposition": if (Value.Length != 0 && !NumberFormats.TryParseDoubleVb6(Value, out NewData.StopPosition)) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; case "stoptime": if (Value.Length != 0 && !Interface.TryParseTime(Value, out NewData.StopTime)) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; case "doors": { int door = 0; bool doorboth = false; switch (Value.ToLowerInvariant()) { case "l": case "left": door = -1; break; case "r": case "right": door = 1; break; case "n": case "none": case "neither": door = 0; break; case "b": case "both": doorboth = true; break; default: if (Value.Length != 0 && !NumberFormats.TryParseIntVb6(Value, out door)) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); door = 0; } break; } NewData.OpenLeftDoors = door < 0.0 | doorboth; NewData.OpenRightDoors = door > 0.0 | doorboth; } break; case "accelerate": if (Value.Length != 0 && !NumberFormats.TryParseDoubleVb6(Value, out Accelerate)) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; case "targetspeed": if (Value.Length != 0 && !NumberFormats.TryParseDoubleVb6(Value, out TargetSpeed)) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; case "direction": { int d = 0; switch (Value.ToLowerInvariant()) { case "f": d = 1; break; case "r": d = -1; break; default: if (Value.Length != 0 && !NumberFormats.TryParseIntVb6(Value, out d)) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; } if (d == 1 || d == -1) { NewData.Direction = (Game.TravelDirection)d; } } break; case "rail": if (Value.Length != 0 && !NumberFormats.TryParseIntVb6(Value, out NewData.RailIndex)) { Interface.AddMessage(MessageType.Error, false, "Value is invalid in " + Key + " in " + Section + " at line " + LineNumber.ToString(Culture) + " in " + FileName); } break; } } NewData.Decelerate = Decelerate / 3.6; NewData.Accelerate = Accelerate / 3.6; NewData.TargetSpeed = TargetSpeed / 3.6; Data.Add(NewData); } break; } } }
private static void SetSectionDependencies(SectionElement[] sections, SectionElement section, DependentModuleInfo dmi) { if (section.Dependencies == null) return; foreach (DependencyElement dep in section.Dependencies) { bool dependentSectionFound = false; foreach (SectionElement sec in sections) { if (sec.Name == dep.Name) { dependentSectionFound = true; foreach (ModuleInfoElement mod in sec.Modules) dmi.Dependencies.Add(mod.Name); break; } } if (!dependentSectionFound) throw new InvalidOperationException(string.Format(Properties.Resources.DependencyNotFound, section.Name, dep.Name)); } }
public bool LoadBin(byte[] binContent) { m_mapElements.Clear(); m_vecAllElements.Clear(); int nCol, nRow; int readPos = 0; readPos += GameAssist.ReadInt32Variant(binContent, readPos, out nCol); readPos += GameAssist.ReadInt32Variant(binContent, readPos, out nRow); List <string> vecLine = new List <string>(nCol); List <int> vecHeadType = new List <int>(nCol); string tmpStr; int tmpInt; for (int i = 0; i < nCol; i++) { readPos += GameAssist.ReadString(binContent, readPos, out tmpStr); readPos += GameAssist.ReadInt32Variant(binContent, readPos, out tmpInt); vecLine.Add(tmpStr); vecHeadType.Add(tmpInt); } if (vecLine.Count != 5) { Ex.Logger.Log("Section.csv中列数量与生成的代码不匹配!"); return(false); } if (vecLine[0] != "SectionID") { Ex.Logger.Log("Section.csv中字段[SectionID]位置不对应"); return(false); } if (vecLine[1] != "Name") { Ex.Logger.Log("Section.csv中字段[Name]位置不对应"); return(false); } if (vecLine[2] != "SystemID") { Ex.Logger.Log("Section.csv中字段[SystemID]位置不对应"); return(false); } if (vecLine[3] != "Team") { Ex.Logger.Log("Section.csv中字段[Team]位置不对应"); return(false); } if (vecLine[4] != "BackGround") { Ex.Logger.Log("Section.csv中字段[BackGround]位置不对应"); return(false); } for (int i = 0; i < nRow; i++) { SectionElement member = new SectionElement(); readPos += GameAssist.ReadInt32Variant(binContent, readPos, out member.SectionID); readPos += GameAssist.ReadString(binContent, readPos, out member.Name); readPos += GameAssist.ReadInt32Variant(binContent, readPos, out member.SystemID); readPos += GameAssist.ReadInt32Variant(binContent, readPos, out member.Team); readPos += GameAssist.ReadString(binContent, readPos, out member.BackGround); member.IsValidate = true; m_vecAllElements.Add(member); m_mapElements[member.SectionID] = member; } return(true); }
private SectionTable() { m_mapElements = new Dictionary <int, SectionElement>(); m_emptyItem = new SectionElement(); m_vecAllElements = new List <SectionElement>(); }
public bool LoadCsv(string strContent) { if (strContent.Length == 0) { return(false); } m_mapElements.Clear(); m_vecAllElements.Clear(); int contentOffset = 0; List <string> vecLine; vecLine = GameAssist.readCsvLine(strContent, ref contentOffset); if (vecLine.Count != 5) { Ex.Logger.Log("Section.csv中列数量与生成的代码不匹配!"); return(false); } if (vecLine[0] != "SectionID") { Ex.Logger.Log("Section.csv中字段[SectionID]位置不对应"); return(false); } if (vecLine[1] != "Name") { Ex.Logger.Log("Section.csv中字段[Name]位置不对应"); return(false); } if (vecLine[2] != "SystemID") { Ex.Logger.Log("Section.csv中字段[SystemID]位置不对应"); return(false); } if (vecLine[3] != "Team") { Ex.Logger.Log("Section.csv中字段[Team]位置不对应"); return(false); } if (vecLine[4] != "BackGround") { Ex.Logger.Log("Section.csv中字段[BackGround]位置不对应"); return(false); } while (true) { vecLine = GameAssist.readCsvLine(strContent, ref contentOffset); if ((int)vecLine.Count == 0) { break; } if ((int)vecLine.Count != (int)5) { return(false); } SectionElement member = new SectionElement(); member.SectionID = Convert.ToInt32(vecLine[0]); member.Name = vecLine[1]; member.SystemID = Convert.ToInt32(vecLine[2]); member.Team = Convert.ToInt32(vecLine[3]); member.BackGround = vecLine[4]; member.IsValidate = true; m_vecAllElements.Add(member); m_mapElements[member.SectionID] = member; } return(true); }
private bool Write(SectionElement section) { if (section == null) return false; float sizeChange = ((((2f - section.Depth) / 2f) * 0.5f) + 1f); if (!ShowSectionHeadings) return true; string[] lines = BreakIntoLines(section.Value, _settings.EffectiveCharWidth * sizeChange , _settings.WritablePageWidth()); if (!HaveRoomFor(lines.Length)) NewPage(); _page.SetFont(_courierBold, _settings.FontSize * sizeChange); foreach (string line in lines) { WriteLine(line); MoveDown(-1); MoveDownPoints(-_settings.EffectiveCharHeight * sizeChange); } _page.SetFont(_courier, _settings.FontSize); EmptyLine(); return true; }
public Board() { InitializeComponent(); try { MainController mainController = MainController.Instance; SectionDAO sectionDAO = new SectionDAO(); if (mainController.Project != null) { List <Section> sections = sectionDAO.GetAll(mainController.Project.Id); StackPanel sectionList = (StackPanel)FindName("SectionList"); WorkLogDAO workLogDAO = new WorkLogDAO(); foreach (Section section in sections) { SectionElement sectionElement = new SectionElement(sectionList); StackPanel taskList = (StackPanel)sectionElement.SectionID; StackPanel completedTaskList = (StackPanel)sectionElement.CompletedTaskList; foreach (Task task in section.TaskList) { TaskElement taskElement = new TaskElement(task.Id); taskElement.TaskID.Name = "Task" + task.Id; taskElement.title.Text = task.Name; taskElement.description.Text = task.Description; if (task.AssignedUser != null) { taskElement.avatar.ImageSource = new BitmapImage(new Uri(task.AssignedUser.Picture)); taskElement.UserButton.ToolTip = task.AssignedUser.Firstname + " " + task.AssignedUser.Lastname; } taskElement.UpdateProgress((workLogDAO.GetWorkSum(task.Id) / task.EstimatedTime) * 100); if (task.Completed) { taskElement.Opacity = 0.5; completedTaskList.Children.Add(taskElement); } else { taskList.Children.Insert(taskList.Children.Count - 1, taskElement); } } sectionElement.SectionID.Name = "Section" + section.Id; sectionElement.SectionName.Text = section.Name; sectionElement.Name = "Section" + section.Id; sectionList.Children.Add(sectionElement); } sectionList.Children.Add(new NewSectionElement(sectionList)); } } catch (Exception exception) { utilities.GetNotifier().ShowError(utilities.HandleException(exception)); } }
static void ConvertProject(String input, String output) { XapFile xapFile = new XapFile(); String content = File.ReadAllText(input); xapFile.Open(content); xapFile.ContentVersion = "44"; xapFile.Release = "March 2008"; ElementCollection presets = xapFile.GetElements("Compression Preset"); if (presets.Count > 0) { /* * Change * Compression Preset * { * Name = Compression Preset; * Xbox Format Tag = 357; * Target Sample Rate = 48000; * Quality = 65; * Find Best Quality = 0; * High Freq Cut = 0; * Loop = 0; * PC Format Tag = 2; * Samples Per Block = 128; * } * to * Compression Preset * { * Name = Compression Preset; * Xbox Format Tag = 357; * Target Sample Rate = 48000; * XMA Quality = 65; * Find Best Quality = 0; * High Freq Cut = 0; * Loop = 0; * PC Format Tag = 353; * WMA Quality = 65; * } */ // Add WMA format to all compression presets that define XMA compression, // using the same quality setting for (int c = 0; c < presets.Count; c++) { SectionElement preset = presets[c] as SectionElement; ScalarElement xboxFormatTag = preset.Value["Xbox Format Tag"] as ScalarElement; int xboxFormatTagValue = 0; if (Int32.TryParse(xboxFormatTag.Value, out xboxFormatTagValue) == true && (CompressionFormat)xboxFormatTagValue == CompressionFormat.XMA) { preset.Value["PC Format Tag"].Value = String.Format("{0}", (int)CompressionFormat.WMA); ScalarElement xmaQuality = preset.Value["Quality"] as ScalarElement; preset.Value["Samples Per Block"] = null; preset.Value.Add(new ScalarElement("WMA Quality", xmaQuality.Value)); //REVIEW: Check Wave size: file too small to encode, must have at least 352256 bytes of data //REVIEW: Rename "Quality" element to "XMA Quality"? } } } using (FileStream outputStream = new FileStream(output, FileMode.Create)) { xapFile.Save(outputStream); } }