/// <summary> /// Imports data from a serialization object /// </summary> /// <param name="serial"></param> public void Import(SerializableUriCharacter serial) { Import((SerializableSettingsCharacter)serial); m_uri = new Uri(serial.Uri); EveClient.OnCharacterChanged(this); }
/// <summary> /// Create a serializable character sheet for this character /// </summary> /// <returns></returns> public override SerializableSettingsCharacter Export() { var serial = new SerializableUriCharacter(); Export(serial); serial.Uri = m_uri.ToString(); return(serial); }
/// <summary> /// Create a serializable character sheet for this character. /// </summary> /// <returns></returns> public override SerializableSettingsCharacter Export() { SerializableUriCharacter serial = new SerializableUriCharacter(); Export(serial); serial.Address = m_uri.AbsoluteUri; return(serial); }
/// <summary> /// Imports data from a serialization object. /// </summary> /// <param name="serial">The serial.</param> /// <exception cref="System.ArgumentNullException">serial</exception> public void Import(SerializableUriCharacter serial) { serial.ThrowIfNull(nameof(serial)); Import((SerializableSettingsCharacter)serial); m_uri = new Uri(serial.Address); EveMonClient.OnCharacterUpdated(this); }
/// <summary> /// Asynchronously adds a character from the given uri, adding a new identity when needed. /// </summary> /// <param name="uri">The uri to load the character sheet from</param> /// <exception cref="System.ArgumentNullException">uri</exception> public static async Task <UriCharacterEventArgs> TryAddOrUpdateFromUriAsync(Uri uri) { uri.ThrowIfNull(nameof(uri)); // It's a web address, let's do it in an async way if (!uri.IsFile) { CCPAPIResult <SerializableAPICharacterSheet> result = await Util.DownloadAPIResultAsync <SerializableAPICharacterSheet>(uri, false, null, APIProvider.RowsetsTransform); return(new UriCharacterEventArgs(uri, result)); } // We have a file, let's just deserialize it synchronously string xmlRootElement = Util.GetXmlRootElement(uri); switch (xmlRootElement.ToLower(CultureConstants.DefaultCulture)) { case "eveapi": CCPAPIResult <SerializableAPICharacterSheet> apiResult = Util.DeserializeAPIResultFromFile <SerializableAPICharacterSheet>(uri.LocalPath, APIProvider.RowsetsTransform); return(new UriCharacterEventArgs(uri, apiResult)); case "serializableccpcharacter": try { SerializableCCPCharacter ccpResult = Util.DeserializeXmlFromFile <SerializableCCPCharacter>(uri.LocalPath); return(new UriCharacterEventArgs(uri, ccpResult)); } catch (NullReferenceException ex) { return(new UriCharacterEventArgs(uri, $"Unable to load file (SerializableCCPCharacter). ({ex.Message})")); } case "serializableuricharacter": try { SerializableUriCharacter uriCharacterResult = Util.DeserializeXmlFromFile <SerializableUriCharacter>(uri.LocalPath); return(new UriCharacterEventArgs(uri, uriCharacterResult)); } catch (NullReferenceException ex) { return(new UriCharacterEventArgs(uri, $"Unable to load file (SerializableUriCharacter). ({ex.Message})")); } default: return(new UriCharacterEventArgs(uri, "Format Not Recognized")); } }
/// <summary> /// Adds a character from a deserialization object /// </summary> /// <param name="serial"></param> internal void Add(SerializableUriCharacter serial) { var uriCharacter = this[new Uri(serial.Uri)]; if (uriCharacter == null) { m_uriCharacters.Add(new UriCharacter(m_characterID, serial)); EveClient.OnCharacterCollectionChanged(); } else { uriCharacter.Import(serial); } }
/// <summary> /// Imports the character identities from a serialization object. /// </summary> /// <param name="serial"></param> internal void Import(IEnumerable <SerializableSettingsCharacter> serial) { // Clear the API key on every identity foreach (CharacterIdentity id in EveMonClient.CharacterIdentities) { id.APIKeys.Clear(); } // Unsubscribe any event handlers in character foreach (Character character in Items) { character.Dispose(); } // Import the characters, their identies, etc Items.Clear(); foreach (SerializableSettingsCharacter serialCharacter in serial) { // Gets the identity or create it CharacterIdentity id = EveMonClient.CharacterIdentities[serialCharacter.ID] ?? EveMonClient.CharacterIdentities.Add(serialCharacter.ID, serialCharacter.Name, serialCharacter.CorporationID, serialCharacter.CorporationName, serialCharacter.AllianceID, serialCharacter.AllianceName, serialCharacter.FactionID, serialCharacter.FactionName); // Imports the character SerializableCCPCharacter ccpCharacter = serialCharacter as SerializableCCPCharacter; if (ccpCharacter != null) { Items.Add(new CCPCharacter(id, ccpCharacter)); } else { SerializableUriCharacter uriCharacter = serialCharacter as SerializableUriCharacter; Items.Add(new UriCharacter(id, uriCharacter)); } } // Notify the change EveMonClient.OnCharacterCollectionChanged(); }
/// <summary> /// Deserialization constructor /// </summary> /// <param name="identity"></param> /// <param name="serial"></param> internal UriCharacter(CharacterIdentity identity, SerializableUriCharacter serial) : base(identity, serial.Guid) { Import(serial); }