protected virtual void OnDispose(bool disposing) { if (_TownXml != null) { XmlTools.Save <TownXml>(TownXml.FILENAME, _TownXml); } }
public static T Load <T>(string filename) where T : class, new() { T instance = null; try { System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(T)); using (System.IO.TextReader reader = new System.IO.StreamReader(filename, System.Text.Encoding.Unicode)) { instance = serializer.Deserialize(reader) as T; reader.Close(); } } catch { instance = new T(); XmlTools.Save(filename, instance); } return(instance); }
public string ArgumentParser(string[] split) { try { if (split.Length < 2) { return("ERROR_TOWN_SPLIT_LENGTH"); } if (split[1].ToLower() == "load") { #region load try { if (split.Length < 3) { return("ERROR_TOWN_LOAD_SPLIT_LENGTH"); } TownXml.Town town = Find(split[2].ToLower()); return(town.ToArmaArray()); } catch (Exception ex) { Arma2Net.Utils.Log("ERROR: Town.Load failed: " + ex.Message); return("ERROR_TOWN_LOAD_EXCEPTION"); } #endregion } else if (split[1].ToLower() == "update") { #region update try { if (split.Length < 12) { return("ERROR_TOWN_UPDATE_SPLIT_LENGTH"); } Update(split[2].ToLower(), split[3].ToLower(), split[4].ToLower(), split[5].ToLower(), split[6].ToLower(), split[7].ToLower(), split[8].ToLower(), split[9].ToLower(), split[10].ToLower(), split[11].ToLower()); return("OK"); } catch (Exception ex) { Arma2Net.Utils.Log("ERROR: Town.Update failed: " + ex.Message); return("ERROR_TOWN_UPDATE_EXCEPTION"); } #endregion } else if (split[1].ToLower() == "save") { #region save try { XmlTools.Save <TownXml>(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "Towns.xml"), this); return("OK"); } catch (Exception ex) { Arma2Net.Utils.Log("ERROR: Town.Save failed: " + ex.Message); return("ERROR_TOWN_SAVE_EXCEPTION"); } #endregion } else { return("ERROR_TOWN_INVALID_COMMAND"); } } catch (Exception ex) { Arma2Net.Utils.Log("ERROR: Town-Exception: " + ex.Message); return("ERROR_TOWN_EXCEPTION"); } }
public string ArgumentParser(string[] split) { try { if (split.Length < 2) { return("ERROR_VEHICLE_SPLIT_LENGTH"); } if (split[1].ToLower() == "read") { #region read try { if (split.Length < 3) { return("ERROR_VEHICLE_READ_SPLIT_LENGTH"); } int index = Convert.ToInt32(split[2]); if ((Vehicles == null) || (Vehicles.Length <= index)) { return("ERROR_VEHICLE_READ_INDEX"); } return(Vehicles[index].ToArmaArray()); } catch (Exception ex) { Arma2Net.Utils.Log("ERROR: Vehicle.Read failed: " + ex.Message); return("ERROR_VEHICLE_READ_EXCEPTION: " + ex.Message); } #endregion } else if (split[1].ToLower() == "beginwrite") { #region beginwrite try { _TmpVehicles = new List <Vehicle>(); return("OK"); } catch (Exception ex) { Arma2Net.Utils.Log("ERROR: Vehicle.BeginWrite failed: " + ex.Message); return("ERROR_VEHICLE_BEGINWRITE_EXCEPTION"); } #endregion } else if (split[1].ToLower() == "write") { #region write try { if (split.Length < 7) { return("ERROR_VEHICLE_WRITE_SPLIT_LENGTH"); } Vehicle vehicle = new Vehicle(); vehicle.Classname = split[2]; vehicle.Position = split[3]; vehicle.Orientation = split[4]; vehicle.Damage = split[5]; vehicle.Content = split[6]; _TmpVehicles.Add(vehicle); return("OK"); } catch (Exception ex) { Arma2Net.Utils.Log("ERROR: Vehicle.Write failed: " + ex.Message); return("ERROR_VEHICLE_WRITE_EXCEPTION:" + ex.Message); } #endregion } else if (split[1].ToLower() == "endwrite") { #region endwrite try { Vehicles = _TmpVehicles.ToArray(); _TmpVehicles = null; XmlTools.Save <VehicleXml>(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "Vehicle.xml"), this); return("OK"); } catch (Exception ex) { Arma2Net.Utils.Log("ERROR: Vehicle.EndWrite failed: " + ex.Message); return("ERROR_VEHICLE_ENDWRITE_EXCEPTION"); } #endregion } else { return("ERROR_VEHICLE_INVALID_COMMAND"); } } catch (Exception ex) { Arma2Net.Utils.Log("ERROR: Vehicle-Exception: " + ex.Message); return("ERROR_VEHICLE_EXCEPTION"); } }