public static FileDownloader GetInstance() { FileDownloader instance; try { instance = DoGetInstance(_defaultType); } catch (Exception e) { Logger.GetInstance(typeof(FileDownloader)).Fatal("Instance initialization error: " + e); Logger.GetInstance(typeof(FileDownloader)).Info("Initializing " + typeof(FileDownloader).FullName + "..."); instance = new HttpFileDownloader(); } return(instance); }
private static FileDownloader DoGetInstance(Type type) { if (type == null) { throw new ArgumentException("Invalid arguments to get file downloader instance"); } var key = type.FullName + "_"; FileDownloader instance = null; if (Instances.ContainsKey(key)) { instance = Instances[key]; } if (instance == null) { Logger.GetInstance(typeof(FileDownloader)).Info("Initializing " + key + "..."); var constructor = type.GetConstructor(new Type[] { }); if (constructor != null) { instance = (FileDownloader)constructor.Invoke(new object[] { }); } } if (instance == null) { Logger.GetInstance(typeof(FileDownloader)).Info("Initializing " + typeof(HttpFileDownloader).FullName + "..."); instance = new HttpFileDownloader(); } lock (InstanceLock) { if (!Instances.ContainsKey(key)) { Instances.Add(key, instance); } } return(instance); }