/// <summary> /// Event handler for the web client's requestion completed event. Reads /// the request's result information and subsequently triggers /// the UpdateDataAvailable event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ReadResult(object sender, OpenReadCompletedEventArgs e) { try { if (null == e || e.Error != null) { Error = "Unspecified error"; if (null != e && (null != e.Error)) { Error = e.Error.Message; } } using (var sr = new StreamReader(e.Result)) { Data = sr.ReadToEnd(); } } catch (Exception ex) { Error = string.Empty; Data = string.Empty; manager.OnLog(new LogEventArgs("The update request could not be completed.", LogLevel.File)); manager.OnLog(new LogEventArgs(ex, LogLevel.File)); } //regardless of the success of the above logic //invoke the completion callback OnRequestCompleted.Invoke(this); }
/// <summary> /// Saves this configuration to a given file in xml format. /// </summary> /// <param name="filePath">File path to save this configuration.</param> /// <param name="updateManager"></param> public void Save(string filePath, IUpdateManager updateManager) { try { var serializer = new XmlSerializer(typeof(UpdateManagerConfiguration)); using (var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write)) { serializer.Serialize(fs, this); } } catch (Exception ex) { if (null != updateManager) { updateManager.OnLog( new LogEventArgs( string.Format( Properties.Resources.FailedToSave, filePath, ex.Message), LogLevel.Console)); } else { throw; } } }
/// <summary> /// Loads the configurations from given xml file. /// </summary> /// <param name="filePath">Xml file path that contains configuration details.</param> /// <param name="updateManager"></param> /// <returns>UpdateManagerConfiguration</returns> public static UpdateManagerConfiguration Load(string filePath, IUpdateManager updateManager) { if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath)) { return(null); } try { var serializer = new XmlSerializer(typeof(UpdateManagerConfiguration)); using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { return(serializer.Deserialize(fs) as UpdateManagerConfiguration); } } catch (Exception ex) { if (null != updateManager) { updateManager.OnLog( new LogEventArgs( string.Format( Properties.Resources.FailedToLoad, filePath, ex.Message), LogLevel.Console)); } else { throw; } } return(null); }
/// <summary> /// Saves this configuration to a given file in xml format. /// </summary> /// <param name="filePath">File path to save this configuration.</param> /// <param name="updateManager"></param> public void Save(string filePath, IUpdateManager updateManager) { try { var serializer = new XmlSerializer(typeof(UpdateManagerConfiguration)); using (var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write)) { serializer.Serialize(fs, this); } } catch (Exception ex) { if (null != updateManager) updateManager.OnLog( new LogEventArgs( string.Format( Properties.Resources.FailedToSave, filePath, ex.Message), LogLevel.Console)); else throw; } }
/// <summary> /// Loads the configurations from given xml file. /// </summary> /// <param name="filePath">Xml file path that contains configuration details.</param> /// <param name="updateManager"></param> /// <returns>UpdateManagerConfiguration</returns> public static UpdateManagerConfiguration Load(string filePath, IUpdateManager updateManager) { if(string.IsNullOrEmpty(filePath) || !File.Exists(filePath)) return null; try { var serializer = new XmlSerializer(typeof(UpdateManagerConfiguration)); using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { var config = serializer.Deserialize(fs) as UpdateManagerConfiguration; if(null != config) config.ConfigFilePath = filePath; return config; } } catch (Exception ex) { if (null != updateManager) updateManager.OnLog( new LogEventArgs( string.Format( Properties.Resources.FailedToLoad, filePath, ex.Message), LogLevel.Console)); else throw; } return null; }
/// <summary> /// Loads the configurations from given xml file. /// </summary> /// <param name="filePath">Xml file path that contains configuration details.</param> /// <param name="updateManager"></param> /// <returns>UpdateManagerConfiguration</returns> public static UpdateManagerConfiguration Load(string filePath, IUpdateManager updateManager) { if(string.IsNullOrEmpty(filePath) || !File.Exists(filePath)) return null; try { var serializer = new XmlSerializer(typeof(UpdateManagerConfiguration)); using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { return serializer.Deserialize(fs) as UpdateManagerConfiguration; } } catch (Exception ex) { if (null != updateManager) updateManager.OnLog( new LogEventArgs( string.Format( "Failed to load {0}\n, Exception: {1}", filePath, ex.Message), LogLevel.Console)); else throw; } return null; }