示例#1
0
        /// <summary>
        /// Create new user.
        /// </summary>
        /// <param name="user"></param>
        public int CreateUser(User user)
        {
            CanonDataContext db = Cdb.Instance;

            if (Business.User.IsLoginExists(user.UserName))
            {
                throw new LoginExistsException(user.UserName);
            }

            string cleanPassword = string.Empty;

            //insert a new user
            user.IsForbidden = false;
            cleanPassword    = user.Password;
            user.Password    = EncodePassword(cleanPassword);
            db.Users.InsertOnSubmit(user);
            db.SubmitChanges();

            if (!string.IsNullOrEmpty(user.Email))
            {
                EmailGateway.Send(
                    String.Empty,
                    user.Email,
                    Utilities.GetResourceString("Common", "EmailCredentialsSubject"),
                    String.Format(Utilities.GetResourceString("Common", "EmailCredentialsText"), user.UserName, cleanPassword),
                    new List <Attachment>());
            }

            return(user.UserId);
        }
        public void SendTest()
        {
            EmailGateway target = new EmailGateway(); // TODO: Initialize to an appropriate value

            target.Send();
            // Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
示例#3
0
        /// <summary>
        /// Send message with generated zip file (with selected log files) in attach.
        /// </summary>
        /// <param name="email"></param>
        /// <param name="subject"></param>
        /// <param name="text"></param>
        /// <param name="selectedFiles"></param>
        public static void SendLogFiles(string email, string subject, string text, FileInfo[] selectedFiles)
        {
            string zipFile = GenerateZipFile(selectedFiles);

            try
            {
                List <Attachment> attachments = new List <Attachment>();
                using (FileStream stream = File.OpenRead(zipFile))
                {
                    attachments.Add(new Attachment(stream, "Logs.zip"));

                    EmailGateway.Send(
                        String.Empty,
                        email,
                        subject,
                        text,
                        attachments,
                        true);

                    stream.Close();
                }
            }
            finally
            {
                File.Delete(zipFile);
            }
        }
示例#4
0
        // Send backup methods

        #region SendDatabaseBackup
        /// <summary>
        /// Send message with generated zip file (with database backup) in attach.
        /// </summary>
        /// <param name="email"></param>
        /// <param name="subject"></param>
        /// <param name="text"></param>
        /// <param name="connectionString"></param>
        /// <param name="databaseName"></param>
        public static void SendDatabaseBackup(string email, string subject, string text, string connectionString, string databaseName)
        {
            string zipFile = GenerateZipFile(connectionString, databaseName);

            try
            {
                List <Attachment> attachments = new List <Attachment>();
                using (FileStream stream = File.OpenRead(zipFile))
                {
                    attachments.Add(new Attachment(stream, String.Concat(databaseName, ".zip")));

                    EmailGateway.Send(
                        String.Empty,
                        email,
                        subject,
                        text,
                        attachments,
                        true);

                    stream.Close();
                }
            }
            finally
            {
                File.Delete(zipFile);
            }
        }
示例#5
0
文件: User.cs 项目: radtek/canon
        /// <summary>
        /// Change email with the password to the user.
        /// </summary>
        /// <param name="email"></param>
        public static bool SendRemindPasswordEmail(string email)
        {
            Canon.Data.User user = GetUserByEmail(email);

            if (user != null)
            {
                string password = ((CanonMembershipProvider)Membership.Provider).ChangePassword(user.UserId);

                string changePasswordUrl = String.Concat(
                    HttpContext.Current.Request.Url.Scheme,
                    "://",
                    HttpContext.Current.Request.Url.Host,
                    ":",
                    HttpContext.Current.Request.Url.Port,
                    HttpContext.Current.Request.ApplicationPath,
                    "/Default.aspx?changepassword=yes");

                try
                {
                    EmailGateway.Send(
                        String.Empty,
                        email,
                        Utilities.GetResourceString("Common", "EmailRemindEmailSubject"),
                        String.Format(Utilities.GetResourceString("Common", "EmailRemindEmailText"), password, changePasswordUrl, user.UserName),
                        new List <Attachment>(),
                        true);
                }
                catch
                {
                    return(false);
                }

                return(true);
            }

            return(false);
        }
示例#6
0
        /// <summary>
        /// Change password.
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="oldPassword"></param>
        /// <param name="newPassword"></param>
        /// <returns></returns>
        public void ChangePassword(int userID, string oldPassword, string newPassword)
        {
            CanonDataContext db = Cdb.Instance;

            var user = (from u in db.Users
                        where u.UserId == userID
                        select u).Single();

            if (!CheckPassword(oldPassword, user.Password))
            {
                throw new InvalidOldPasswordException(userID, oldPassword);
            }

            user.Password = EncodePassword(newPassword);

            db.SubmitChanges();

            EmailGateway.Send(
                String.Empty,
                user.Email,
                Utilities.GetResourceString("Common", "EmailPasswordChangingSubject"),
                String.Format(Utilities.GetResourceString("Common", "EmailPasswordChangingText"), newPassword),
                new List <Attachment>());
        }
示例#7
0
 public void Send(string from, string to, string subject, string message)
 {
     gateway.Send(from, to, subject, message);
 }
 public void TestSend()
 {
     EmailGateway service = new EmailGateway(HOST);
     service.From = FROM;
     service.To = TO;
     service.IsHtmlBody = true;
     service.Send("Send Test (Statefull)", "Success");
 }
示例#9
0
        private void MainTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            lock (padlock)
            {
                if (IsAlreadyWork)
                {
                    return;
                }
                IsAlreadyWork = true;
            }
            try
            {
                logger.Debug(string.Format("New elapsation started-{0}", DateTime.Now));

                //log maintainance
                this.DeleteOldLogs();

                //go through items in Manual Mapping Import Queue
                this.ProcessImportQueue();

                //check current time against defined in config
                if (!CanonConfigManager.ForceStart)
                {
                    DateTime start = CanonConfigManager.TimeToStart;
                    DateTime now   = DateTime.Now;

                    logger.Debug(string.Format("now-{0}, start-{1}", now, start));

                    if (start > now)
                    {
                        return;
                    }
                    else if ((now - start).TotalMinutes > 30)
                    {
                        return;
                    }
                }

                //Clear manual import queue and subsribers
                CanonDataContext db = Cdb.Instance;
                if (!CanonConfigManager.ForceStart)
                {
                    //delete all complete every night
                    var allManuals = db.ManualImportQueues.Where(p => p.Status == (int)ManualImportStatusEnum.ImportComplete ||
                                                                 p.Status == (int)ManualImportStatusEnum.InProgress);
                    db.ManualImportQueues.DeleteAllOnSubmit(allManuals);
                    db.SubmitChanges();
                }
                else
                {
                    //delete all old
                    var allManualsA = db.ManualImportQueues.Where(p => p.PostDate.Date < DateTime.Now.Date);
                    db.ManualImportQueues.DeleteAllOnSubmit(allManualsA);
                    db.SubmitChanges();
                }

                //application maintainance
                db.MaintainDatabase();

                //go through all channels
                foreach (Channel channel in db.Channels)
                {
                    try
                    {
                        if (!channel.IsActive)
                        {
                            logger.Info(string.Format("Channel is disabled: {0}, {1}, {2}",
                                                      channel.ChannelId, channel.ChannelName, channel.Url));
                            continue;
                        }

                        logger.Info(string.Format("Starting new export: {0}, {1}, {2}",
                                                  channel.ChannelId, channel.ChannelName, channel.Url));

                        if (!ShouldRun(channel))
                        {
                            logger.Info(string.Format("Data already imported today or there was a error during import."));
                            continue;
                        }

                        this.ProcessChannel(channel);
                    }
                    catch (Exception ex)
                    {
                        logger.Warn(string.Format("Import for channel {0} failed", channel.ChannelName), ex);
                    }
                }
                //send daily emails
                if (CanonImportService.LastEmailSent.Date < DateTime.Now.Date)
                {
                    List <User> users = db.Users.Where(u => u.IsDailyEmail && u.Email.Length > 0).ToList();
                    string      text  = this.CreateEmailText(null).Trim();
                    logger.Info("Email text:" + text);
                    if (!string.IsNullOrEmpty(text))
                    {
                        foreach (User user in users)
                        {
                            try
                            {
                                EmailGateway email = new EmailGateway(user.Email, "Daily Log", text);
                                email.Send();
                                CanonImportService.LastEmailSent = DateTime.Now;
                            }
                            catch (Exception ex)
                            {
                                logger.Fatal(ex);
                            }
                        }
                    }
                    //send daily email for users in channels
                    List <Channel> repChannels = db.Channels.ToList();
                    foreach (Channel repChannel in repChannels)
                    {
                        if (!repChannel.IsActive)
                        {
                            continue;
                        }
                        if (!string.IsNullOrEmpty(repChannel.ReportingTo))
                        {
                            string[] emails    = repChannel.ReportingTo.Split(';');
                            string   emailText = this.CreateEmailText(repChannel).Trim();
                            foreach (string email in emails)
                            {
                                try
                                {
                                    EmailGateway emailG = new EmailGateway(email, "Průzkum trhu", emailText);
                                    logger.Info(string.Format("Sending: {0}, text={1}", email, emailText));
                                    emailG.Send();
                                    CanonImportService.LastEmailSent = DateTime.Now;
                                }
                                catch (Exception ex)
                                {
                                    logger.Fatal(ex);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Fatal(ex);
            }
            finally
            {
                IsAlreadyWork = false;
            }
        }
 public void SendTest()
 {
     EmailGateway target = new EmailGateway(); // TODO: Initialize to an appropriate value
     target.Send();
        // Assert.Inconclusive("A method that does not return a value cannot be verified.");
 }