/// <summary> /// Serializes the target assignments. /// </summary> /// <returns>Serialized data.</returns> public SerializableSettings.BinaryData SerializeStuckVehicles() { if (this.StuckVehicles == null) { return(null); } if (Log.LogALot) { Log.DevDebug(this, "SerializeStuckVehicles", this.StuckVehicles.Count, String.Join(" | ", this.StuckVehicles.Values.OrderBy(v => v.VehicleId).SelectToArray(v => "[" + v.ToString() + "]"))); } SerializableSettings.BinaryData serializedData = new SerializableSettings.BinaryData(20 * 1024); // Version. serializedData.AddVersion(0); // Data. foreach (StuckVehicleInfo vehicle in this.StuckVehicles.Values) { vehicle.Serialize(serializedData); } if (Log.LogALot) { Log.DevDebug(this, "SerializeStuckVehicles", serializedData.Length); } return(serializedData); }
/// <summary> /// Deserializes the specified serialized data to this instance. /// </summary> /// <param name="serializedData">The serialized data.</param> /// <returns> /// The deserialization result. /// </returns> private SerializableSettings.DeserializationResult Deserialize(SerializableSettings.BinaryData serializedData) { if (serializedData == null || serializedData.Left == 0) { return(SerializableSettings.DeserializationResult.EndOfData); } serializedData.ResetLocalCheckSum(); ulong version = serializedData.GetVersion(); if (version > 0) { Log.Warning(this, "Deserialize", "Serialized data version too high!", version, 0); return(SerializableSettings.DeserializationResult.Error); } this.VehicleId = serializedData.GetUshort(); this.targetBuildingId = serializedData.GetUshort(); this.dispatcherType = serializedData.GetDispatcherType(); this.checkFlags = serializedData.GetVehicleFlags(); this.checkFlagPosition = serializedData.GetVector3(); this.checkFlagSinceFrame = serializedData.GetUint(); this.checkFlagSinceTime = serializedData.GetDouble(); this.confusedDeAssignedSinceFrame = serializedData.GetUint(); this.confusedSinceFrame = serializedData.GetUint(); this.confusedSinceTime = serializedData.GetDouble(); this.lostSinceFrame = serializedData.GetUint(); this.lostSinceTime = serializedData.GetDouble(); this.lostReason = serializedData.GetLostReason(); serializedData.CheckLocalCheckSum(); return(SerializableSettings.DeserializationResult.Success); }
/// <summary> /// Tries to deserialize the specified serialized data to this instance. /// </summary> /// <param name="serializedData">The serialized data.</param> /// <param name="stuckVehicleInfo">The stuck vehicle information.</param> /// <returns> /// The deserialization result. /// </returns> public static SerializableSettings.DeserializationResult Deserialize(SerializableSettings.BinaryData serializedData, out StuckVehicleInfo stuckVehicleInfo) { stuckVehicleInfo = new StuckVehicleInfo(); SerializableSettings.DeserializationResult result = stuckVehicleInfo.Deserialize(serializedData); if (result != SerializableSettings.DeserializationResult.Success) { stuckVehicleInfo = null; } return(result); }
/// <summary> /// Deserializes the automatic emptying building list. /// </summary> /// <param name="serializedData">The serialized data.</param> public void DeserializeStuckVehicles(SerializableSettings.BinaryData serializedData) { if (serializedData.Left == 0) { return; } try { ulong version = serializedData.GetVersion(); if (version > 0) { Log.Warning(this, "DeserializeStuckVehicles", "Serialized data version too high!", version, 0); return; } if (serializedData.Left == 0 || this.StuckVehicles == null) { return; } StuckVehicleInfo vehicle; SerializableSettings.DeserializationResult result; while ((result = StuckVehicleInfo.Deserialize(serializedData, out vehicle)) == SerializableSettings.DeserializationResult.Success) { this.StuckVehicles[vehicle.VehicleId] = vehicle; } if (result == SerializableSettings.DeserializationResult.Error) { this.StuckVehicles.Clear(); } else if (Log.LogALot) { Log.DevDebug(this, "DeserializeStuckVehicles", this.StuckVehicles.Count, String.Join(" | ", this.StuckVehicles.Values.OrderBy(v => v.VehicleId).SelectToArray(v => "[" + v.ToString() + "]"))); } } catch (Exception ex) { Log.Error(this, "DeserializeStuckVehicles", ex); if (this.StuckVehicles != null) { this.StuckVehicles.Clear(); } } }
/// <summary> /// Saves the serialized data. /// </summary> /// <param name="data">The data.</param> /// <param name="subIds">The sub identifiers.</param> private void SaveSerializedData(SerializableSettings.BinaryData data, params string[] subIds) { string id = this.GetDataId(subIds); if (data == null) { Log.DevDebug(this, "SaveSerializedData", id, "NoData"); data = new SerializableSettings.BinaryData(); } Log.Debug(this, "SaveSerializedData", id, data.Length); try { data.Save(this.serializableData, id); Log.Info(this, "SaveSerializedData", id, data.Length, "Saved"); } catch (Exception ex) { Log.Error(this, "SaveSerializedData", ex, id); } }
/// <summary> /// Loads the serialized data. /// </summary> /// <param name="Deserializer">The deserializer.</param> /// <param name="subIds">The sub identifiers.</param> private void LoadSerializedData(Action <SerializableSettings.BinaryData> Deserializer, params string[] subIds) { string id = this.GetDataId(subIds); Log.DevDebug(this, "LoadSerializedData", id); try { SerializableSettings.BinaryData data = new SerializableSettings.BinaryData(this.serializableData, id); if (!data.DeserializationError) { Log.Debug(this, "LoadSerializedData", id, data.Length); Deserializer(data); Log.Info(this, "LoadSerializedData", id, data.Length, "Loaded"); } } catch (Exception ex) { Log.Error(this, "LoadSerializedData", ex, id); } }
/// <summary> /// Serializes this instance. /// </summary> /// <returns>The serialized data.</returns> public void Serialize(SerializableSettings.BinaryData serializedData) { serializedData.ResetLocalCheckSum(); // Version. serializedData.AddVersion(0); // Data. serializedData.Add(this.VehicleId); serializedData.Add(this.targetBuildingId); serializedData.Add(this.dispatcherType); serializedData.Add(this.checkFlags); serializedData.Add(this.checkFlagPosition); serializedData.Add(this.checkFlagSinceFrame); serializedData.Add(this.checkFlagSinceTime); serializedData.Add(this.confusedDeAssignedSinceFrame); serializedData.Add(this.confusedSinceFrame); serializedData.Add(this.confusedSinceTime); serializedData.Add(this.lostSinceFrame); serializedData.Add(this.lostSinceTime); serializedData.Add(this.lostReason); serializedData.AddLocalCheckSum(); }
/// <summary> /// Adds the specified data. /// </summary> /// <param name="data">The data.</param> public void Add(BinaryData data) { this.Add(data.serializedData); }
/// <summary> /// Deserializes a standard service settings block. /// </summary> /// <param name="serializedData">The serialized data.</param> /// <param name="settings">The settings.</param> /// <returns>The deserialization result.</returns> private static DeserializationResult DeserializeStandardServiceSettings(BinaryData serializedData, Settings settings) { if (serializedData == null || serializedData.Left == 0) { return(DeserializationResult.EndOfData); } Log.DevDebug(typeof(BinarySettings), "DeserializeStandardServiceSettings", applySettings); serializedData.ResetLocalCheckSum(); SettingsType settingsType = serializedData.GetSettingsType(); if (settingsType != SettingsType.StandardService) { throw new InvalidOperationException("Not a standard service settings block"); } ulong version = serializedData.GetVersion(); if (version > 0) { Log.Warning(typeof(BinarySettings), "DeserializeStandardServiceSettings", "Serialized data version too high", version, 0); return(DeserializationResult.Error); } StandardServiceSettings serviceSettings; StandardServiceSettings serializedSettings; ServiceType service = serializedData.GetServiceType(); switch (service) { case ServiceType.DeathCare: serviceSettings = settings.DeathCare; break; case ServiceType.Garbage: serviceSettings = settings.Garbage; break; case ServiceType.HealthCare: serviceSettings = settings.HealthCare; break; default: Log.Warning(typeof(BinarySettings), "Not a standard service", service); serviceSettings = null; break; } serializedSettings = new StandardServiceSettings(serviceSettings); // Settings. serializedSettings.DispatchVehicles = serializedData.GetBool(); serializedSettings.DispatchByDistrict = serializedData.GetBool(); serializedSettings.DispatchByRange = serializedData.GetBool(); serializedSettings.AutoEmpty = serializedData.GetBool(); serializedSettings.LimitOpportunisticCollection = serializedData.GetBool(); serializedSettings.RemoveFromGrid = serializedData.GetBool(); serializedSettings.IgnoreRangeUseClosestBuildings = serializedData.GetByte(); serializedSettings.CreateSpares = serializedData.GetSpareVehiclesCreation(); serializedSettings.ChecksPreset = serializedData.GetBuildingCheckOrder(); serializedSettings.MinimumAmountForDispatch = serializedData.GetUshort(); serializedSettings.MinimumAmountForPatrol = serializedData.GetUshort(); serializedSettings.AutoEmptyStartLevelPercent = serializedData.GetByte(); serializedSettings.AutoEmptyStopLevelPercent = serializedData.GetByte(); // Custom check list. byte checksCustomLength = serializedData.GetByte(); serializedSettings.ChecksCustom = serializedData.GetBuildingCheckParametersArray(checksCustomLength); serializedData.CheckLocalCheckSum(); if (serviceSettings != null) { Log.Debug(typeof(BinarySettings), "DeserializeStandardServiceSettings", applySettings, service, serializedSettings.DispatchVehicles, serializedSettings.ChecksPreset, ServiceDispatcherSettings.BuildingChecksPresetInfo.ToString(serializedSettings.ChecksParameters), ServiceDispatcherSettings.BuildingChecksPresetInfo.ToString(serializedSettings.ChecksCustom)); if (applySettings) { serviceSettings.CopyFrom(serializedSettings); } } return(DeserializationResult.Success); }
/// <summary> /// Deserializes a hidden service settings block. /// </summary> /// <param name="serializedData">The serialized data.</param> /// <param name="settings">The settings.</param> /// <returns>The deserialization result.</returns> private static DeserializationResult DeserializeHiddenServiceSettings(BinaryData serializedData, Settings settings) { if (serializedData == null || serializedData.Left == 0) { return(DeserializationResult.EndOfData); } Log.DevDebug(typeof(BinarySettings), "DeserializeHiddenServiceSettings", applySettings); serializedData.ResetLocalCheckSum(); SettingsType settingsType = serializedData.GetSettingsType(); if (settingsType != SettingsType.HiddenService) { throw new InvalidOperationException("Not a hidden service settings block"); } ulong version = serializedData.GetVersion(); if (version > 0) { Log.Warning(typeof(BinarySettings), "DeserializeHiddenServiceSettings", "Serialized data version too high", version, 0); return(DeserializationResult.Error); } HiddenServiceSettings serviceSettings; HiddenServiceSettings serializedSettings; ServiceType service = serializedData.GetServiceType(); switch (service) { case ServiceType.WreckingCrews: serviceSettings = settings.WreckingCrews; break; case ServiceType.RecoveryCrews: serviceSettings = settings.RecoveryCrews; break; default: Log.Warning(typeof(BinarySettings), "Not a hidden service", service); serviceSettings = null; break; } serializedSettings = new HiddenServiceSettings(serviceSettings); // Settings. serializedSettings.DispatchVehicles = serializedData.GetBool(); serializedSettings.DelaySeconds = serializedData.GetDouble(); serializedData.CheckLocalCheckSum(); if (serviceSettings != null) { Log.Debug(typeof(BinarySettings), "DeserializeHiddenServiceSettings", applySettings, service, serializedSettings.DispatchVehicles, serializedSettings.DelaySeconds); if (applySettings) { serviceSettings.CopyFrom(serializedSettings); } } return(DeserializationResult.Success); }