/// <summary> /// Initialize the library. /// Be careful : this method is mandatory for the good work of the application. /// </summary> /// <param name="ConfigFile">The name of the config file</param> /// <param name="Prefix">The prefix of the config file</param> /// <param name="defaultLevel">The default level of loggin</param> public static void InitializeLibrary(string ConfigFile, string Prefix, LogType defaultLevel) { if (ConfigFile == null) { throw new ArgumentNullException("ConfigFile"); } if (ConfigFile.Trim() == "") { throw new ArgumentException("Cannot be blank", "ConfigFile"); } _config = new Config(); _configFileName = ConfigFile; _log = new Logger(Prefix, defaultLevel); EventLog ev = new EventLog(); ev.Source = "ActiveQ"; string path = GetImagePath(Assembly.GetExecutingAssembly().Location); // Create the error directory _pathDirError = path + @"\Error"; Directory.CreateDirectory(_pathDirError); // Create the processed directory _pathDirProcessed = path + @"\Processed"; Directory.CreateDirectory(_pathDirProcessed); try { // loading library _activeMail = null; _activeCommon = null; _activeSmtp = null; try { _activeMail = Assembly.LoadFrom(_libraryMailFile); _activeCommon = Assembly.LoadFrom(_libraryCommonFile); _activeSmtp = Assembly.LoadFrom(_librarySmtpFile); } catch (FileNotFoundException fe) { } if (_activeMail == null) { String dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); _activeMail = Assembly.LoadFrom(Path.Combine(dir, _libraryMailFile)); } if (_activeCommon == null) { String dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); _activeCommon = Assembly.LoadFrom(Path.Combine(dir, _libraryCommonFile)); } if (_activeSmtp == null) { String dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); _activeSmtp = Assembly.LoadFrom(Path.Combine(dir, _librarySmtpFile)); } object _message = Activator.CreateInstance(_activeCommon.GetType("ActiveUp.Net.Mail.Message", true)); _smtpServers = Activator.CreateInstance(_activeCommon.GetType("ActiveUp.Net.Mail.ServerCollection", true)); LoadConfig(); //_activeMail.GetType("ActiveUp.Mail.Common.LicenseInfo").GetProperty("License").SetValue(typeof(string),_config.ActiveMailLicense,null); string imageDir = GetImagePath(Assembly.GetExecutingAssembly().Location); if (imageDir.Trim() != "") { _libraryMailFile = imageDir + @"\" + _libraryMailFile; } } catch (FileNotFoundException) { Log.WriteError(string.Format("[INITIALIZE] Unable to find '{0}'.", _libraryMailFile)); Log.WriteError(string.Format("[INITIALIZE] Mailing operation are disabled")); ev.WriteEntry(string.Format("Unable to find '{0}'.\nMailing operation are disabled.", _libraryMailFile), EventLogEntryType.Error); string keyString = @"SOFTWARE\Active Up\ActiveQ"; RegistryKey key = Registry.LocalMachine.OpenSubKey(keyString); if (key != null) { if ((string)key.GetValue("ActiveMailNotFound") == (string)"True") { PageActiveMailNotFound pageMailNotFound = new PageActiveMailNotFound(); pageMailNotFound.ShowDialog(); } key.Close(); } else { PageActiveMailNotFound pageMailNotFound = new PageActiveMailNotFound(); pageMailNotFound.ShowDialog(); } } catch (Exception ex) { Type trialExpired = _activeMail.GetType("ActiveUp.Licensing.TrialException", true); if (ex.InnerException.GetType() == trialExpired) { Log.WriteError(string.Format("[INITIALIZE] Trial version of ActiveMail has expired, please register at www.activeup.com.")); Log.WriteError(string.Format("[INITIALIZE] Mailing operation are disabled.")); ev.WriteEntry("Trial version of ActiveMail has expired, please register at www.activeup.com.\nMailing operation are disabled.", EventLogEntryType.Error); PageActiveMailExpired pageMailExpired = new PageActiveMailExpired(); pageMailExpired.ShowDialog(); _activeMail = null; } else { if (ex.InnerException != null) { Log.WriteError(string.Format("[INITIALIZE] Error loading '{0}'", _libraryMailFile)); Log.WriteError("[INITIALIZE] " + ex.InnerException.Message); Log.WriteError("[INITIALIZE] " + ex.InnerException.StackTrace); } else { Log.WriteError(string.Format("[INITIALIZE] Error loading '{0}'", _libraryMailFile)); Log.WriteError("[INITIALIZE] " + ex.Message); Log.WriteError("[INITIALIZE] " + ex.StackTrace); } } } // Initalization for the midnigth event DateTime now = DateTime.Now; DateTime midnight = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0, 0); midnight = midnight.AddDays(1); TimeSpan t = midnight - now; Log.WriteEvent(LogType.normal, string.Format("[INITIALIZE] Midnigth event occurs in {0}", t)); _timeMidnight.Change(t, new TimeSpan(-1)); _reader = new Reader(); _processer = new Processer(); ActiveQLibrary.Form.ManageForm.Initialize(); }
/// <summary> /// Initialize the library. /// Be careful : this method is mandatory for the good work of the application. /// </summary> /// <param name="ConfigFile">The name of the config file</param> /// <param name="Prefix">The prefix of the config file</param> /// <param name="defaultLevel">The default level of loggin</param> public static void InitializeLibrary(string ConfigFile, string Prefix, LogType defaultLevel) { if (ConfigFile == null) throw new ArgumentNullException("ConfigFile"); if (ConfigFile.Trim() == "") throw new ArgumentException("Cannot be blank","ConfigFile"); _config = new Config(); _configFileName = ConfigFile; _log = new Logger(Prefix,defaultLevel); EventLog ev = new EventLog(); ev.Source = "ActiveQ"; string path = GetImagePath(Assembly.GetExecutingAssembly().Location); // Create the error directory _pathDirError = path + @"\Error"; Directory.CreateDirectory(_pathDirError); // Create the processed directory _pathDirProcessed = path + @"\Processed"; Directory.CreateDirectory(_pathDirProcessed); try { // loading library _activeMail = null; _activeCommon = null; _activeSmtp = null; try { _activeMail = Assembly.LoadFrom(_libraryMailFile); _activeCommon = Assembly.LoadFrom(_libraryCommonFile); _activeSmtp = Assembly.LoadFrom(_librarySmtpFile); } catch (FileNotFoundException fe) { } if (_activeMail == null) { String dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); _activeMail = Assembly.LoadFrom(Path.Combine(dir, _libraryMailFile)); } if (_activeCommon == null) { String dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); _activeCommon = Assembly.LoadFrom(Path.Combine(dir, _libraryCommonFile)); } if (_activeSmtp == null) { String dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); _activeSmtp = Assembly.LoadFrom(Path.Combine(dir, _librarySmtpFile)); } object _message = Activator.CreateInstance(_activeCommon.GetType("ActiveUp.Net.Mail.Message",true)); _smtpServers = Activator.CreateInstance(_activeCommon.GetType("ActiveUp.Net.Mail.ServerCollection",true)); LoadConfig(); //_activeMail.GetType("ActiveUp.Mail.Common.LicenseInfo").GetProperty("License").SetValue(typeof(string),_config.ActiveMailLicense,null); string imageDir = GetImagePath(Assembly.GetExecutingAssembly().Location); if (imageDir.Trim() != "") _libraryMailFile = imageDir + @"\" + _libraryMailFile; } catch(FileNotFoundException) { Log.WriteError(string.Format("[INITIALIZE] Unable to find '{0}'.",_libraryMailFile)); Log.WriteError(string.Format("[INITIALIZE] Mailing operation are disabled")); ev.WriteEntry(string.Format("Unable to find '{0}'.\nMailing operation are disabled.",_libraryMailFile),EventLogEntryType.Error); string keyString = @"SOFTWARE\Active Up\ActiveQ"; RegistryKey key = Registry.LocalMachine.OpenSubKey(keyString); if (key != null) { if ((string)key.GetValue("ActiveMailNotFound") == (string)"True") { PageActiveMailNotFound pageMailNotFound = new PageActiveMailNotFound(); pageMailNotFound.ShowDialog(); } key.Close(); } else { PageActiveMailNotFound pageMailNotFound = new PageActiveMailNotFound(); pageMailNotFound.ShowDialog(); } } catch(Exception ex) { Type trialExpired = _activeMail.GetType("ActiveUp.Licensing.TrialException",true); if (ex.InnerException.GetType() == trialExpired) { Log.WriteError(string.Format("[INITIALIZE] Trial version of ActiveMail has expired, please register at www.activeup.com.")); Log.WriteError(string.Format("[INITIALIZE] Mailing operation are disabled.")); ev.WriteEntry("Trial version of ActiveMail has expired, please register at www.activeup.com.\nMailing operation are disabled.",EventLogEntryType.Error); PageActiveMailExpired pageMailExpired = new PageActiveMailExpired(); pageMailExpired.ShowDialog(); _activeMail = null; } else { if (ex.InnerException != null) { Log.WriteError(string.Format("[INITIALIZE] Error loading '{0}'",_libraryMailFile)); Log.WriteError("[INITIALIZE] " + ex.InnerException.Message); Log.WriteError("[INITIALIZE] " + ex.InnerException.StackTrace); } else { Log.WriteError(string.Format("[INITIALIZE] Error loading '{0}'",_libraryMailFile)); Log.WriteError("[INITIALIZE] " + ex.Message); Log.WriteError("[INITIALIZE] " + ex.StackTrace); } } } // Initalization for the midnigth event DateTime now = DateTime.Now; DateTime midnight = new DateTime(now.Year,now.Month,now.Day,0,0,0,0); midnight = midnight.AddDays(1); TimeSpan t = midnight - now; Log.WriteEvent(LogType.normal,string.Format("[INITIALIZE] Midnigth event occurs in {0}",t)); _timeMidnight.Change(t,new TimeSpan(-1)); _reader = new Reader(); _processer = new Processer(); ActiveQLibrary.Form.ManageForm.Initialize(); }