/// <summary> /// Tries to deserialize the EveIDToName file. /// </summary> private static void TryDeserializeCacheFile() { SerializableEveIDToName cache = null; // Deserialize the file cache = Util.DeserializeXML <SerializableEveIDToName>(s_file); // Reset the cache if anything went wrong if (cache.Entities.Any(x => x.ID == 0) || cache.Entities.Any(x => x.Name == String.Empty)) { cache = null; } if (cache == null) { EveClient.Trace("Deserializing EveIDToName failed. File may be corrupt. Deleting file."); File.Delete(s_file); return; } // Add the data to the dictionary foreach (var entity in cache.Entities) { s_cacheList.Add(entity.ID, entity.Name); } }
private static void LogException(Exception e, string header) { Trace.WriteLine(""); EveClient.Trace(header); Trace.Indent(); Trace.WriteLine(e.ToString()); Trace.WriteLine(""); Trace.Unindent(); }
/// <summary> /// Triggers on when a SMTP client has finished (success or failure) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void SendCompleted(object sender, AsyncCompletedEventArgs e) { if (e.Cancelled) { EveClient.Trace("Emailer.SendCompleted - The last message was cancelled"); } if (e.Error != null) { EveClient.Trace("Emailer.SendCompleted - An error occurred"); ExceptionHandler.LogException(e.Error, false); } else { EveClient.Trace("Emailer.SendCompleted - Message sent."); } }
/// <summary> /// Imports the serialized accounts. /// </summary> /// <param name="serial"></param> internal void Import(IEnumerable <SerializableAccount> serial) { m_items.Clear(); foreach (var serialAccount in serial) { try { m_items.Add(serialAccount.ID, new Account(serialAccount)); } catch (ArgumentException ex) { EveClient.Trace("GlobalAccountCollection.Import - An account with id {0} already existed; additional instance ignored.", serialAccount.ID); ExceptionHandler.LogException(ex, true); } } EveClient.OnAccountCollectionChanged(); }
/// <summary> /// Performs the sending of the mail /// </summary> /// <param name="settings">Settings object to use when sending</param> /// <param name="subject">Subject of the message</param> /// <param name="body">Body of the message</param> /// <returns>True if no exceptions thrown, otherwise false</returns> /// <remarks> /// NotificationSettings object is required to support /// alternative settings from Tols -> Options. Use /// Settings.Notifications unless using an alternative /// configuration. /// </remarks> private static bool SendMail(NotificationSettings settings, string subject, string body) { // trace something to the logs so we can identify the time the message was sent. EveClient.Trace("Emailer.SendMail: Subject - {0}; Server - {1}:{2}", subject, settings.EmailSmtpServer, settings.EmailPortNumber ); try { // Set up message MailMessage msg = new MailMessage(settings.EmailFromAddress, settings.EmailToAddress, subject, body); // Set up client SmtpClient client = new SmtpClient(settings.EmailSmtpServer); client.SendCompleted += new SendCompletedEventHandler(SendCompleted); if (settings.EmailPortNumber > 0) { client.Port = settings.EmailPortNumber; } // Enter crendtials if (settings.EmailAuthenticationRequired) { client.UseDefaultCredentials = false; client.Credentials = new NetworkCredential( settings.EmailAuthenticationUserName, settings.EmailAuthenticationPassword); } // SSL client.EnableSsl = settings.EmailServerRequiresSSL; // Send message client.SendAsync(msg, null); return(true); } catch (Exception e) { ExceptionHandler.LogException(e, true); return(false); } }
/// <summary> /// loads the settings file, or the backup, prompting the user for errors. /// </summary> /// <returns><c>Null</c> if we have been unable to load anything from files, the generated settings otherwise</returns> private static SerializableSettings TryDeserializeSettings() { SerializableSettings settings = null; string settingsFile = EveClient.SettingsFileNameFullPath; string backupFile = settingsFile + ".bak"; // Check that a settings file or backup exists if (File.Exists(settingsFile)) { EveClient.Trace("Settings.TryDeserializeSettings() - begin"); // Check settings file length FileInfo settingsInfo = new FileInfo(settingsFile); if (settingsInfo.Length > 0) { // Gets the revision number of the assembly which generated this file int revision = Util.GetRevisionNumber(settingsFile); // Try to load from a file if (revision == 0) { // Old format settings = DeserializeOldFormat(settingsFile); } else { // New format settings = Util.DeserializeXML <SerializableSettings>(settingsFile); } // If the settings loaded OK, make a backup as 'last good settings' and return if (settings != null) { CheckSettingsVersion(settings); FileHelper.OverwriteOrWarnTheUser(settingsFile, backupFile); EveClient.Trace("Settings.TryDeserializeSettings() - done"); return(settings); } } } // Try to recover from the backup return(TryDeserializeBackup(backupFile, settingsFile, true)); }
/// <summary> /// Update the datafiles list /// </summary> public void Refresh() { try { m_items.Clear(); m_items.Add(new Datafile(DatafileConstants.PropertiesDatafile)); m_items.Add(new Datafile(DatafileConstants.ItemsDatafile)); m_items.Add(new Datafile(DatafileConstants.SkillsDatafile)); m_items.Add(new Datafile(DatafileConstants.CertificatesDatafile)); m_items.Add(new Datafile(DatafileConstants.GeographyDatafile)); m_items.Add(new Datafile(DatafileConstants.ReprocessingDatafile)); m_items.Add(new Datafile(DatafileConstants.BlueprintsDatafile)); } // Don't worry if we cant create MD5 maybe they have FIPS enforced. catch (Exception) { EveClient.Trace("Couldn't compute datafiles checksums. FIPS was enforced, the datafiles were missing, or we couldn't copy to %APPDATA%."); } }
/// <summary> /// Gets the station of an order. /// </summary> /// <param name="src"></param> /// <returns></returns> private static Station GetStationByID(long id) { // Look for the station in datafile Station station = StaticGeography.GetStation(id); // We failed ? Then it's a conquerable outpost station if (station == null) { station = ConquerableStation.GetStation(id); } // We failed again ? It's not in any data we can access // We set it to a fixed one and notify about it in the trace file if (station == null) { station = StaticGeography.GetStation(60013747); EveClient.Trace("Could not find station id {0}", id); EveClient.Trace("Setting to {0}", station.Name); } return(station); }
/// <summary> /// Performs the check asynchronously. /// </summary> /// <remarks>Invoked on the UI thread the first time and on some background thread the rest of the time.</remarks> /// <returns></returns> private static void BeginCheck() { // If update manager has been disabled since the last // update was triggered quit out here if (!s_enabled) { s_checkScheduled = false; return; } // No connection ? Recheck in one minute if (!NetworkMonitor.IsNetworkAvailable) { ScheduleCheck(TimeSpan.FromMinutes(1)); return; } EveClient.Trace("UpdateManager.BeginCheck()"); // Otherwise, query Batlleclinic Util.DownloadXMLAsync <SerializablePatch>(Settings.Updates.UpdatesUrl, null, OnCheckCompleted); }
/// <summary> /// Import the query result list. /// </summary> private static void Import(IEnumerable <SerializableOutpost> outposts) { EveClient.Trace("ConquerableStationList.Import() - begin"); s_conqStationsByID.Clear(); try { foreach (var outpost in outposts) { s_conqStationsByID.Add(outpost.StationID, new ConquerableStation(outpost)); } } catch (Exception exc) { ExceptionHandler.LogException(exc, true); } finally { s_loaded = true; EveClient.Trace("ConquerableStationList.Import() - done"); } }
private static void OnCheckCompleted(SerializablePatch result, string errorMessage) { // If update manager has been disabled since the last // update was triggered quit out here if (!s_enabled) { s_checkScheduled = false; return; } // Was there an error ? if (!String.IsNullOrEmpty(errorMessage)) { // Logs the error and reschedule EveClient.Trace("UpdateManager: {0}", errorMessage); ScheduleCheck(s_frequency); return; } // No error, let's try to deserialize try { ScanUpdateFeed(result); } // An error occurred during the deserialization catch (InvalidOperationException exc) { ExceptionHandler.LogException(exc, true); } finally { // Reschedule ScheduleCheck(s_frequency); } EveClient.Trace("UpdateManager.OnCheckCompleted()"); }
/// <summary> /// Schedules a check a specified time period in the future. /// </summary> /// <param name="time">Time period in the future to start check.</param> private static void ScheduleCheck(TimeSpan time) { s_checkScheduled = true; Dispatcher.Schedule(time, () => BeginCheck()); EveClient.Trace("UpdateManager.ScheduleCheck() in {0}", time); }
/// <summary> /// Updates from the provided serialization object /// </summary> /// <param name="serial">The serializable version of the new settings. May be null (acts as a reset)</param> /// <param name="preferencesOnly">When true, only the user preferences will be reimported, not plans, characters, accounts and such.</param> public static void Import(SerializableSettings serial, bool preferencesOnly) { // When null, we just reset if (serial == null) { Reset(); return; } IsRestoringSettings = true; try { EveClient.Trace("Settings.Import() - begin"); // Import the characters, accounts and plans if (!preferencesOnly) { // The above check prevents the settings form to trigger a // characters updates since the last queried infos would be lost. EveClient.Characters.Import(serial.Characters); EveClient.Characters.ImportPlans(serial.Plans); EveClient.MonitoredCharacters.Import(serial.MonitoredCharacters); EveClient.Accounts.Import(serial.Accounts); } // Global settings Settings.Compatibility = serial.Compatibility; // API providers EveClient.APIProviders.Import(serial.APIProviders); // Scheduler Scheduler.Import(serial.Scheduler); // User settings Settings.UI = serial.UI.Clone(); Settings.G15 = serial.G15.Clone(); Settings.IGB = serial.IGB.Clone(); Settings.Proxy = serial.Proxy.Clone(); Settings.Updates = serial.Updates.Clone(); Settings.Notifications = serial.Notifications.Clone(); Settings.Exportation = serial.Exportation.Clone(); Settings.Calendar = serial.Calendar.Clone(); // Trim the data OnImportCompleted(); // Save SaveImmediate(); // Updates the data right now EveClient.UpdateOnOneSecondTick(); EveClient.OnSettingsChanged(); EveClient.Trace("Settings.Import() - done"); } finally { IsRestoringSettings = false; } }
/// <summary> /// Try to deserialize from the backup file. /// </summary> /// <param name="backupFile"></param> /// <returns></returns> private static SerializableSettings TryDeserializeBackup(string backupFile, string settingsFile, bool recover) { SerializableSettings settings = null; // Load failed, so check for backup if (File.Exists(backupFile)) { EveClient.Trace("Settings.TryDeserializeBackup() - begin"); FileInfo backupInfo = new FileInfo(backupFile); if (backupInfo.Length > 0) { if (recover) { // Prompts the user to use the backup String fileDate = String.Format("{0} at {1}", backupInfo.LastWriteTime.ToLocalTime().ToShortDateString(), backupInfo.LastWriteTime.ToLocalTime().ToCustomShortTimeString()); DialogResult dr = MessageBox.Show(String.Format(CultureConstants.DefaultCulture, "Your settings file is missing or corrupt. There is a backup available from {0}. Do you want to use the backup file?", fileDate), "Corrupt Settings", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (dr == DialogResult.No) { MessageBox.Show("Your settings file is corrupt, and no backup is available. A new settings file will be created." + " You may wish to close down EVEMon and restore a saved copy of your file.", "Corrupt Settings", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(null); } } // Gets the revision number of the assembly which generated this file int revision = Util.GetRevisionNumber(backupFile); // Try to load from a backup file if (revision == 0) { // Old format settings = DeserializeOldFormat(backupFile); } else { // New format settings = Util.DeserializeXML <SerializableSettings>(backupFile); } // If the settings loaded OK, copy to the main settings file, then copy back to stamp date if (settings != null) { CheckSettingsVersion(settings); FileHelper.OverwriteOrWarnTheUser(backupFile, settingsFile); FileHelper.OverwriteOrWarnTheUser(settingsFile, backupFile); EveClient.Trace("Settings.TryDeserializeBackup() - done"); return(settings); } // Backup failed too, notify the user we have a problem MessageBox.Show("Load from backup failed. A new settings file will be created." + " You may wish to close down EVEMon and restore a saved copy of your file.", "Corrupt Settings", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(null); } } return(null); }