public bool Save(EmailQueue email)
 {
     if (email.id > 0)
         return _emailQueueDao.Update(email) > 0;
     else
         return _emailQueueDao.Insert(email) > 0;
 }
 private void SendWarningHtml(string lang, int pid, string pname, string email, int uid)
 {
     string url = string.Format("{0}/plant/warningfilter/?pid={1}&uid={2}", domainUrl, pid, uid);
     string html = Tool.LoadContent(url, lang);
     EmailQueue queue = new EmailQueue();
     queue.title = pname + " Warning Report";
     queue.content = html;
     queue.receiver = email;
     queue.state = 0;
     queue.sender = "*****@*****.**";
     EmailQueueService.GetInstance().Save(queue);
 }
Beispiel #3
0
        public void Run()
        {
            InitData();
            foreach (DefineReport report in normalReport)
            {
                if (string.IsNullOrEmpty(report.config.email))
                    continue;
                if (string.IsNullOrEmpty(report.config.sendMode))
                    continue;
                bool isSuccess = false;
                switch (report.config.sendMode.ToLower())//报告发送模式 1循环 2定时
                {
                    case "1":
                        Console.WriteLine("处理模式1运行时报告" + report.config.id);
                        //if ((DateTime.Now - report.config.lastSendTime).TotalHours > Convert.ToDouble(report.config.tinterval))
                        if ((DateTime.Now > report.config.lastSendTime))
                        {
                            //report.config.lastSendTime = DateTime.Now.AddSeconds(0 - DateTime.Now.Second);
                            report.config.lastSendTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, 0).AddHours(Convert.ToDouble(report.config.tinterval));
                            isSuccess = true;
                        }
                        //Console.WriteLine("处理模式1运行时报告,isSuccess is " + isSuccess);
                        break;
                    case "2":
                        string[] para = new string[6];//年 月 日 时  分 周
                        string[] t = null;
                        t = report.config.fixedTime.Split(',');
                        switch (report.ReportType)
                        {
                            case 1://日报表
                                para[3] = t[0];
                                para[4] = t[1];
                                break;
                            case 2://周报表
                                para[3] = t[1];
                                para[5] = t[0];
                                break;
                            case 3://月报表
                                para[2] = t[0];
                                para[3] = t[1];
                                break;
                            case 4://年报表
                            case 5:
                                para[1] = t[0];
                                para[2] = t[1];
                                para[3] = t[2];
                                break;
                            default:
                                break;
                        }
                        if (para == null || para.Length < 6)
                            para = new string[6];
                        DateTime update = DateTime.Now;
                        Console.WriteLine("处理模式2运行时报告" + report.config.id);
                        if (Tool.DateEquals(para[0], para[1], para[2], para[3], para[4], para[5], report.config.lastSendTime, report.ReportType, ref update))
                        {
                            report.config.lastSendTime = update;
                            isSuccess = true;
                        }
                        //Console.WriteLine("处理模式2运行时报告,isSuccess is " + isSuccess);
                        break;
                }
                if (isSuccess)
                {

                    string culture = "en-us";
                    if (report.user == null)
                    {
                        Plant plant = PlantService.GetInstance().GetPlantInfoById(report.PlantId);
                        if (plant != null)
                            report.user = UserService.GetInstance().Get(Convert.ToInt32(plant.userID));
                    }
                    if (report.user != null && report.user.Language != null && (string.IsNullOrEmpty(report.user.Language.codename) == false))
                        culture = report.user.Language.codename;

                    string url = string.Format("{5}/reports/viewreport?rId={0}&cTime={1}&tId={2}&pId={3}&type=email&lang={4}", report.Id, DateTime.Now.ToString("yyyy-MM-dd"), report.ReportType, report.config.plantId == 0 ? "" : report.config.plantId.ToString(), culture.ToLower(), domainUrl);
                    string html = Tool.LoadContent(url, culture);
                    EmailQueue queue = new EmailQueue();
                    queue.title = report.ReportName;
                    queue.content = html;
                    if (string.IsNullOrEmpty(queue.content)) continue;
                    queue.receiver = report.config.email;
                    queue.state = 0;
                    queue.sender = "*****@*****.**";
                    EmailQueueService.GetInstance().Save(queue);
                    ReportConfigService.GetInstance().UPdateReportLastSendTime(report.config);//更新最后发送时间
                    Console.WriteLine(string.Format("{0}-({1})-{2}", url, report.ReportName, DateTime.Now));
                }
            }
        }
Beispiel #4
0
        public ActionResult AddUser(User user, bool mail, string role)
        {
            string plants = Request.Form["plants"];
            user.ParentUserId = UserUtil.getCurUser().id;
            user.TemperatureType = "C";
            user.currencies = "$";
            user.languageId = 1;
            user.sex = "0";
            string password = user.password;
            user.password = EncryptUtil.EncryptDES(user.password, EncryptUtil.defaultKey);
            int id = userservice.save(user);
            if (string.IsNullOrEmpty(plants) == false)
                foreach (string p in plants.Split(','))
                {
                    if (string.IsNullOrEmpty(p))
                        continue;
                    plantUserService.AddPlantUser(new PlantUser() { userID = id, plantID = int.Parse(p) });
                }
            UserRoleService.GetInstance().Insert(new UserRole() { userId = id, roleId = int.Parse(role) });

            if (mail)
            {
                try
                {
                    EmailQueue queue = new EmailQueue();
                    queue.content = string.Format(Resources.SunResource.USER_CONTROLLER_FINDPASSWORD_EMAIL_BODY, user.username, password);
                    queue.receiver = user.email;
                    queue.title = Resources.SunResource.USER_CONTROLLER_FINDPASSWORD_EMAIL_SUBJECT;
                    SendUserMail(queue);
                }
                catch { }

            }
            return Redirect("/user/plantuser");
        }
Beispiel #5
0
        private void SendUserMail(EmailQueue queue)
        {
            MailServerPoolObject obj = EmailService.EmailConnectionPool.getMailServerPoolObject();

            try
            {
                Message message = new Message();
                message.BodyText = queue.content;
                message.From.Email = obj.accountName;
                message.To.Add(queue.receiver);
                message.Subject = queue.title;
                obj.SendMail(message);
                obj.close();
            }
            catch
            {
                obj.close();
            }
        }
Beispiel #6
0
        public ActionResult UserEdit(User user, string role, bool mail)
        {
            user.password = EncryptUtil.EncryptDES(user.password, EncryptUtil.defaultKey);
            int roleId = 0;
            int.TryParse(role, out roleId);
            UserRoleService.GetInstance().Save(new UserRole() { userId = user.id, roleId = roleId });
            user.TemperatureType = "C";
            user.currencies = "$";
            user.languageId = 1;
            user.sex = "0";
            userservice.save(user);
            userservice.UpdatePassword(user.id, user.password);

            if (mail)
            {
                try
                {
                    EmailQueue queue = new EmailQueue();
                    queue.content = string.Format(Resources.SunResource.USER_CONTROLLER_FINDPASSWORD_EMAIL_BODY, user.username, user.depassword);
                    queue.receiver = user.email;
                    queue.title = Resources.SunResource.USER_CONTROLLER_FINDPASSWORD_EMAIL_SUBJECT;
                    SendUserMail(queue);
                }
                catch { }
            }
            return Redirect("/user/plantuser");
        }
Beispiel #7
0
 /// <summary>
 /// 邮件
 /// </summary>
 /// <param name="queue"></param>
 private bool SendUserMail(EmailQueue queue)
 {
     MailServerPoolObject obj = EmailConnectionPool.getMailServerPoolObject();
     bool successed = false;
     try
     {
         Message message = new Message();
         message.BodyText = queue.content;
         message.From.Email = obj.accountName;
         message.To.Add(queue.receiver);
         message.Subject = queue.title;
         successed = obj.SendMail(message);
         obj.close();
     }
     catch
     {
         successed = false;
         obj.close();
     }
     return successed;
 }
Beispiel #8
0
        public ActionResult SaveSharePlant()
        {
            User curr = UserUtil.getCurUser();
            string pids = Request.Form["pids"];
            string ut = Request.Form["ut"];
            string role = Request.Form["role"];
            //将角色转换为整形,由于先保留角色功能,所以目前是取不到值的
            int roleId = 0;
            int.TryParse(role, out roleId);
            string uname = Request.Form["uname"];
            string upwd = Request.Form["upwd"];
            string email = Request.Form["email"];
            string sendmail = Request.Form["sendmail"];
            int uid = 0;
            User user = userservice.GetUserByName(uname.Trim());
            switch (ut)
            {
                case "1"://已有用户
                    if (user == null) return Content("error:该用户不存在");
                    if (user.depassword.Equals(upwd) == false)
                        return Content("error:用户名密码不正确");
                    if (user.ParentUserId.Equals(curr.id) == false)
                        return Content("error:该用户不是您创建的用户,不能分配电站");

                    uid = user.id;

                    break;
                case "2"://新建用户
                    if (user != null)
                        return Content("error:已存在此用户");
                    else
                        uid = userservice.save(new User { ParentUserId = curr.id, username = uname, password = EncryptUtil.EncryptDES(upwd, EncryptUtil.defaultKey), email = email, sex = "1" });

                    if (sendmail.ToLower().Equals("true"))
                    {
                        try
                        {
                            EmailQueue queue = new EmailQueue();
                            queue.content = string.Format(Resources.SunResource.USER_CONTROLLER_FINDPASSWORD_EMAIL_BODY, user.username, upwd);
                            queue.receiver = user.email;
                            queue.title = Resources.SunResource.USER_CONTROLLER_FINDPASSWORD_EMAIL_SUBJECT;
                            SendUserMail(queue);
                        }
                        catch { }
                    }

                    break;
                default:
                    break;
            }
            string singlemark = Request.Form["singlemark"];
            //如果不是分配单个电站,那么要先清空改用户的已分配电站
            if (singlemark_false.Equals(singlemark))
            {
                plantPortalUserService.DelPlantUserByUserId(uid);
            }

            string[] pid_array = pids.Split(',');
            for (int i = 0; i < pid_array.Length; i++)
            {

                if (string.IsNullOrEmpty(pid_array[i])) continue;
                int pid = int.Parse(pid_array[i]);
                //如果关系已经存在即不在建立关系
                PlantPortalUser pu = plantPortalUserService.GetPlantUserByPlantIDUserID(new PlantPortalUser() { plantID = pid, userID = uid });
                if (pu == null)
                    plantPortalUserService.AddPlantPortalUser(new PlantPortalUser { userID = uid, plantID = pid });
            }
            return Content("ok");
        }
Beispiel #9
0
        public void Run()
        {
            Init();
            IList<Fault> faults = null;
            foreach (ReportConfig config in eventConfigs)
            {
                if (string.IsNullOrEmpty(config.email)) {
                    Console.WriteLine("event report email is empty!");
                    continue;
                }
                //if ((DateTime.Now - config.lastSendTime).TotalMinutes < 30)
                //    continue;
                Plant plant = PlantService.GetInstance().GetPlantInfoById(config.plantId);
                if (plant == null)
                    continue;
                Console.WriteLine("start handle event report of "+plant.name+" last send time is :"+config.lastSendTime);
                //取出lastSendTime时间之后的日志
                faults = LoadEventLogs(config.plantId, config.lastSendTime);
                //Console.WriteLine("fault count is :"+faults.Count);
                //if (faults == null || faults.Count < logLength)
                if (faults == null || faults.Count == 0)
                {
                    continue;
                }
                string lang = "en-us";
                User user = UserService.GetInstance().Get(int.Parse(config.sendMode));
                if (user!=null&&user.Language != null && string.IsNullOrEmpty(user.Language.codename) == false)
                {
                    lang = user.Language.codename.ToLower();
                }
                Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(lang);

                int count=faults.Count;
                int index = 0;
                Console.WriteLine("start handle " + faults.Count+" fault");
                while (true)
                {
                    IList<Fault> temp = null;
                    if (count >= logLength * (index + 1))
                    {
                        temp = faults.Skip((index * logLength)).Take(logLength).ToList<Fault>();
                        index++;
                        //Console.WriteLine("count >50 ");
                    }
                    else
                    {
                        temp = faults.Skip(index * logLength).Take((count % logLength)).ToList<Fault>();
                       // Console.WriteLine("get  "+temp.Count+" record");
                    }
                    EmailQueue queue = new EmailQueue();
                    object[] resArr = BulidContent(plant.name, temp, config.sendFormat == null ? "html" : config.sendFormat);
                    queue.content = (string)resArr[0];

                    if (string.IsNullOrEmpty(queue.content)) {
                        //Console.WriteLine("queue.content is empty ");
                        continue;
                    }
                    //Console.WriteLine("put .content into queue ");
                    queue.receiver = config.email;
                    queue.state = 0;
                    queue.title = plant.name + " event report " + CalenderUtil.formatDate(DateTime.Now, "yyyy-MM-dd");
                    queue.sender = "*****@*****.**";
                    if (Save(queue))
                    {
                        Console.WriteLine(string.Format("a event report has been created {0}", DateTime.Now));
                    }
                    else
                    {
                        Console.WriteLine("fail insert");
                    }
                    config.lastSendTime = (DateTime)resArr[1];//将最近的一个日志时间作为上次处理时间,后续再从这个时间之后的日志处理
                    Thread.Sleep(1000);
                    if(faults.Last().id.Equals(temp.Last().id))
                    {
                        UPdateReportLastSendTime (config);
                        break;
                    }
                }
            }
        }
Beispiel #10
0
 private bool Save(EmailQueue queue)
 {
     return EmailQueueService.GetInstance().Save(queue);
 }