public static IValidator Create(UpdaterConfiguration configuration) { IValidator validator = null; #region Create the IValidator provider // use generic Factory to create instance of Validator with config type/asm info validator = (IValidator)GenericFactory.Create(configuration.Validator.Assembly, configuration.Validator.Type); try { validator.Init(configuration.Validator.Config); } catch (Exception e) { string error = ApplicationUpdateManager.TraceWrite(e, "[ValidatorFactory.Create]", "RES_ErrorInitializingValidator", configuration.Validator.Type, configuration.Validator.Assembly); ApplicationUpdaterException theException = new ApplicationUpdaterException(error, e); ExceptionManager.Publish(theException); throw theException; } #endregion return(validator); }
public static IDownloader Create(UpdaterConfiguration configuration) { IDownloader downloader = null; #region Create the IDownloader provider // use the GenericFactory to actually create the instance downloader = (IDownloader)GenericFactory.Create(configuration.Downloader.Assembly, configuration.Downloader.Type); try { downloader.Init(configuration.Downloader.Config); } catch (Exception e) { string error = ApplicationUpdateManager.TraceWrite(e, "[DownloaderFactory.Create]", "RES_ErrorInitializingDownloader", configuration.Downloader.Type, configuration.Downloader.Assembly); ApplicationUpdaterException theException = new ApplicationUpdaterException(error, e); ExceptionManager.Publish(theException); throw theException; } #endregion return(downloader); }
private static void Init() { #region Get the configuration instance try { if (null == _configuration) { _configuration = (UpdaterConfiguration)ConfigurationSettings.GetConfig("appUpdater"); } } catch (ApplicationUpdaterException aex) { string error = ApplicationUpdateManager.TraceWrite(aex, "[UpdaterConfiguration.cctor]", "RES_UnableToLoadConfiguration", AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); ApplicationUpdaterException theException = new ApplicationUpdaterException(error, aex); ExceptionManager.Publish(theException); throw theException; } catch (ConfigurationException configEx) { string error = ApplicationUpdateManager.TraceWrite(configEx, "[UpdaterConfiguration.cctor]", "RES_UnableToLoadConfiguration", AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); ConfigurationException plusConfEx = new ConfigurationException(error, configEx); ExceptionManager.Publish(plusConfEx); throw plusConfEx; } catch (Exception exception) { // for general exception, just publish and throw no more is reasonable to add ExceptionManager.Publish(exception); throw exception; } if (_configuration == null) { string error = ApplicationUpdateManager.TraceWrite("[UpdaterConfiguration.cctor]", "RES_UnableToLoadConfiguration", AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); ApplicationUpdaterException theException = new ApplicationUpdaterException(error); ExceptionManager.Publish(theException); throw theException; } #endregion }
object IConfigurationSectionHandler.Create(object parent, object configContext, XmlNode section) { XmlSerializer serializer = null; serializer = new XmlSerializer(typeof(UpdaterConfiguration)); // first pass the node to our validation helper to catch serious errors before we even try deserialization: ValidateConfiguration(section); // now try for deserialization--remember, each of the config property classes is decorated with xml deserialization // attributes which will "automatically" put elements/attributes in class fields UpdaterConfiguration config = (UpdaterConfiguration)serializer.Deserialize( new XmlNodeReader(section.SelectSingleNode(@"UpdaterConfiguration"))); // uses default XML serialization to populate the strong-typed classes used to describe configuration data. // see the XML serialization attributes on the configuration classes. config.Downloader.Config = section.SelectSingleNode( @"./UpdaterConfiguration/downloader"); config.Validator.Config = section.SelectSingleNode( @"./UpdaterConfiguration/validator"); return(config); }
/// <summary> /// Default constructor /// </summary> public ApplicationUpdateManager() { DnldMgrHolder holder; // initialize the hybriddict we're using to hold DnldMgrHolder structs _dnldHolders = new HybridDictionary(); #region Configuration Testing // attempt to load configuration first. If there is an error, throw here and go no further--config is essential try { UpdaterConfiguration config = UpdaterConfiguration.Instance; } catch (Exception e) { // throw right away after logging, we cannot continue ExceptionManager.Publish(e); throw e; } #endregion #region Set Up File-Based Logging SetupLogging(); #endregion #region Create Managers, Create Validator + Downloader, Construct Managers with their respective objects (downloader + validator) // iterate through applications array (which in turn uses config to get this info) // at each application, create a new DownloaderManager + its objects + attendant thread foreach (ApplicationConfiguration application in UpdaterConfiguration.Instance.Applications) { // use helper function to create + package a complete DnldMgrHolder + the inner DownloaderManager and all its parts holder = SetupDownloadManager(application); // check if app of this name exists already; CANNOT HAVE two apps of same name being updated if (_dnldHolders.Contains(application.Name)) { string error = ApplicationUpdateManager.TraceWrite("[ApplicationUpdateManager.ctor]", "RES_EXCEPTION_DuplicateApplicationName", application.Name); ConfigurationException configE = new ConfigurationException(error); ExceptionManager.Publish(configE); throw configE; } // add the holder to the hashtable for starting later _dnldHolders.Add(application.Name, holder); } #endregion #region Hook ProcessExit // wrap in try in case security not allowing us to hook this, log and continue it's not crucial try { // hook the AppDomain.ProcessExit event so that we can gracefully interrupt threads and clean up if // process is killed AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit); } catch (SecurityException se) { // log and continue ApplicationUpdateManager.TraceWrite(se, "[ApplicationUpdateManager.CTOR]", "RES_EXCEPTION_ConfigCantLoadInAUConstructor"); ExceptionManager.Publish(se); } #endregion }