/// <summary> /// Finds an object attached to this star, using its name /// </summary> /// <param name="name">The objet name to look for</param> /// <param name="comparisonOptions">The options used when comparing names</param> /// <returns>The <see cref="AstronomicalObject"/> instance that was found, or null if this name does not exist.</returns> public AstronomicalObject FindObjectByName(string name, AstronomicalObjectType type, StringComparison comparisonOptions = StringComparison.InvariantCultureIgnoreCase) { if (name == null) { throw new ArgumentNullException("name", "A station name cannot be null"); } return(ObjectsInternal.Where(o => o.Name.Equals(name, comparisonOptions) && o.Type == type).FirstOrDefault()); }
/// <summary> /// Saves this environment's data into the specified stream /// </summary> /// <param name="s">The stream to save the data to</param> /// <seealso cref="Load"/> public void Save(Stream s) { if (s == null) { throw new ArgumentNullException("s"); } if (!s.CanWrite) { throw new ArgumentException("The stream must be writable"); } XmlWriterSettings xmlSettings = new XmlWriterSettings() { CloseOutput = false, Encoding = Encoding.UTF8, Indent = true, IndentChars = " ", NewLineHandling = NewLineHandling.Entitize, }; using (XmlWriter writer = XmlWriter.Create(s, xmlSettings)) { writer.WriteStartElement("environment"); writer.WriteAttributeDate("date", DateTime.Now); //writer.WriteAttributeBool("autodistance", AutoDistanceEnabled); if (CurrentSituation.CurrentLocation != null) { writer.WriteAttributeString("current", CurrentSituation.CurrentLocation.Name); } writer.WriteStartElement("commodities"); foreach (Commodity c in CommoditiesInternal) { c.Save(writer); } writer.WriteEndElement(); writer.WriteStartElement("objects"); // Stars first foreach (AstronomicalObject star in StarsInternal) { star.Save(writer); } // Others next foreach (AstronomicalObject ao in ObjectsInternal.Where(ao => ao.Type != AstronomicalObjectType.Star)) { ao.Save(writer); } writer.WriteEndElement(); writer.WriteStartElement("trades"); foreach (AstronomicalObject station in StationsInternal) { foreach (Trade t in station.Trades) { t.Save(writer); } } writer.WriteEndElement(); writer.WriteEndElement(); writer.Flush(); } }