예제 #1
0
        /// <summary>
        /// Send emails
        /// This method is called by windows service after evert 1 min.
        /// This method is responsible for checking notification from database,
        /// and send notification for each task if valid as per time.
        /// </summary>
        public static void SendEmails(string HostAddress, string FromEmailid, string Pass, string databaseConnectionString)
        {
            DbCommunicator db = DbCommunicator.CreateInstance(databaseConnectionString);

            try
            {
                db.OpenConnection();
                DataSet data = db.ExecuteQuery(DBQuery.GET_EMAIL_DETAILS, "taskDetails");
                // Iterate data from dataset and send email as notification which contains title, description.
                foreach (DataRow item in data.Tables["taskDetails"].Rows)
                {
                    string email = item["email"].ToString();
                    string title = item["title"].ToString();
                    string desc  = item["description"].ToString();
                    if (false == String.IsNullOrEmpty(email))
                    {
                        // send email
                        Send(email, title, desc, HostAddress, FromEmailid, Pass);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (db != null)
                {
                    db.CloseConnection();
                }
            }
        }
 /// <summary>
 /// Method to get instance using singlton pattern. Create instance only once.
 /// </summary>
 /// <param name="connectionString"></param>
 /// <returns></returns>
 public static DbCommunicator CreateInstance(string connectionString)
 {
     if (null == _instance)
     {
         _instance = new DbCommunicator(connectionString);
     }
     else
     {
         // Do nothing
     }
     return(_instance);
 }