public void TestSmtpServer(EmailServerInfo info, string email, string tenancy)
        {
            string body;
            var    subject = SendEmail.GetTemplateRendering("testEmail", out body,
                                                            tenancy,
                                                            email,
                                                            DateTime.UtcNow.ToString("F"));

            var smtpServer = new SmtpClient(info.SmtpServer, info.Port)
            {
                Credentials = new System.Net.NetworkCredential(info.Username, info.Password),
                EnableSsl   = info.IsSsl
            };

            var mail = new MailMessage {
                From = new MailAddress(info.ReplyAddress)
            };

            mail.To.Add(email);
            mail.Subject = subject;
            mail.Body    = body;
            mail.ReplyToList.Add(info.ReplyAddress);
            smtpServer.Send(mail);

            //var emailSender = SendEmail.CreateFromTemplateSMTP(
            //    info.ReplyAddress,
            //    new[] {email},
            //    "testEmail",
            //    TenantHelper.GetCurrentTenantFormUrl(HttpContext.Current),
            //    email,
            //    DateTime.UtcNow.ToString("F")
            //    );
            //emailSender.Send();
        }
 public bool TestNode(EmailServerInfo parameters, string email = null)
 {
     try
     {
         TestSmtpServer(parameters, email);
         return(true);
     }
     catch (Exception exception)
     {
         ExceptionHandler.Manage(exception, this, Layer.BusinessLogic);
         return(false);
     }
 }
Ejemplo n.º 3
0
        public bool TestEmailServerConnection(EmailServer data, string email = null)
        {
            var info = new EmailServerInfo
            {
                IsSsl        = data.IsSsl,
                Username     = data.Username,
                Password     = data.Password,
                SmtpServer   = data.SmtpServer,
                Port         = data.Port,
                ReplyAddress = data.ReplyAddress
            };

            return(_deployBusLogic.TestEmailServerConnection(info, email));
        }
 public void TestSmtpServer(EmailServerInfo info, string email)
 {
     try
     {
         TestSmtpServer(info, email, TenantHelper.GetCurrentTenantFormUrl(HttpContext.Current));
     }
     catch (Exception exception)
     {
         throw new ExceptionHandling.Exceptions.SmtpException(
                   string.Format(
                       "Email settings: recipient={0}, sender={1}, server={2}, port={3}, isSSL={4}, username={5}",
                       email, info.ReplyAddress, info.SmtpServer, info.Port, info.IsSsl, info.Username) +
                   Environment.NewLine + exception.Message, exception);
     }
 }
        public void TestSmtpServer1Test()
        {
            var provider = new EmailServerTestingProvider();
            var info     = new EmailServerInfo
            {
                SmtpServer   = "smtp.gmail.com",
                ReplyAddress = "*****@*****.**",
                Port         = 587,
                IsSsl        = true,
                Username     = "******",
                Password     = "******"
            };

            provider.TestSmtpServer(info, "*****@*****.**", "tenancy01");
        }
Ejemplo n.º 6
0
        public void SaveEmailServerConfiguration(EmailServerInfo info)
        {
            SaveGlobalConfigItem(
                new GlobalConfigItem {
                Name = GlobalConfigItemEnum.EmailServer.EnumName(), Value = info.SmtpServer
            },
                GlobalConfigItemEnum.EmailServer.EnumName());

            var emailReplyAddressEnum = GlobalConfigItemEnum.EmailReplyAddress.EnumName();

            SaveGlobalConfigItem(
                new GlobalConfigItem {
                Name = emailReplyAddressEnum, Value = info.ReplyAddress
            },
                emailReplyAddressEnum);

            SaveGlobalConfigItem(
                new GlobalConfigItem {
                Name = GlobalConfigItemEnum.EmailAccount.EnumName(), Value = info.Username
            },
                GlobalConfigItemEnum.EmailAccount.EnumName());

            SaveGlobalConfigItem(
                new GlobalConfigItem {
                Name = GlobalConfigItemEnum.EmailPassword.EnumName(), Value = info.Password
            },
                GlobalConfigItemEnum.EmailPassword.EnumName());

            SaveGlobalConfigItem(
                new GlobalConfigItem
            {
                Name  = GlobalConfigItemEnum.EmailPort.EnumName(),
                Value = info.Port.ToString(CultureInfo.InvariantCulture)
            },
                GlobalConfigItemEnum.EmailPort.EnumName());

            SaveGlobalConfigItem(
                new GlobalConfigItem {
                Name = GlobalConfigItemEnum.UseSSL.EnumName(), Value = info.IsSsl.ToString()
            },
                GlobalConfigItemEnum.UseSSL.EnumName());
        }
Ejemplo n.º 7
0
        public void RegisterServerConfig()
        {
            try
            {
                Catalog.Services.Register <IConfig>(SpecialFactoryContexts.Safe, _ => new ApplicationConfiguration());
                Catalog.Services.Register <IRecurrence <object> >(_AppDomain => new ThreadedRecurrence <object>());

                var globalConfig = Catalog.Preconfigure()
                                   .Add(ApplicationTopologyLocalConfig.CompanyKey, TopologyPath.Company)
                                   .Add(ApplicationTopologyLocalConfig.ApplicationKey, TopologyPath.Product)
                                   .ConfiguredCreate(() => new RavenGlobalConfig());

                Catalog.Services.Register <IConfig>(
                    _ => new AggregateConfiguration(globalConfig, new ApplicationConfiguration())).AsAssemblerSingleton();
                Catalog.Services.Register <IConfig>(SpecialFactoryContexts.Safe, _ => globalConfig);

                globalConfig.Start();

                using (var dc = DocumentStoreLocator.Resolve(DocumentStoreLocator.RootLocation))
                {
                    var db = dc.Load <DatabaseInfo>(TopologyPath.Product);
                    if (null == db)
                    {
                        db = new DatabaseInfo
                        {
                            Application           = TopologyPath.Product,
                            DatabaseSchemaVersion = TopologyPath.DBVersion,
                            InstallDate           = DateTime.UtcNow,
                            Url = "http://localhost:8080/raven/"
                        };
                        dc.Store(db);

                        var fc = new GlobalConfigItem
                        {
                            Name  = "DistributedFileShare",
                            Value = "C:\\Lok\\AppData"
                        };

                        dc.Store(fc);

                        var email = new EmailServerInfo()
                        {
                            Application    = TopologyPath.EmailServerShared,
                            ConfiguredDate = DateTime.UtcNow,
                            IsSsl          = false,
                            SmtpServer     = "localhost",
                            Username       = "******",
                            Password       = "******",
                            Port           = 10
                        };

                        dc.Store(email);

                        dc.SaveChanges();
                    }
                }

                var installer = Catalog.Preconfigure()
                                .Add(ApplicationTopologyLocalConfig.CompanyKey, TopologyPath.Company)
                                .Add(ApplicationTopologyLocalConfig.ApplicationKey, TopologyPath.Product)
                                .ConfiguredCreate(() => new RavenTopologyInstaller());

                installer.LocalInstall(
                    Guid.NewGuid().ToString(),
                    "Development Environment",
                    TopologyPath.Version,
                    TopologyPath.DBVersion,
                    "http://localhost:8080",
                    "Control",
                    "Admin",
                    "b1f08cc1-7130-49d4-bffa-cd1211d2a743");

                Console.WriteLine("Complete.");
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.TraceInformation());
            }
        }
Ejemplo n.º 8
0
        private void btn_generate_Click(object sender, EventArgs e)
        {
            Boolean msgsend = true;

            try
            {
                Dictionary <string, object> parameters = new Dictionary <string, object>();

                #region getEmailUserServerPasword

                string sEmailServer   = "";
                string sEmailUser     = "";
                string sEmailPassword = "";


                var getServerDet = (from emailSer in context.emrcorcmps
                                    where emailSer.emrcmpcpcd.Equals(txt_company.Text.TrimEnd())
                                    select emailSer).SingleOrDefault();
                if (getServerDet != null)
                {
                    sEmailServer   = Utility.NullToString(getServerDet.emrcmpemsr);
                    sEmailUser     = Utility.NullToString(getServerDet.emrcmpesur);
                    sEmailPassword = Utility.NullToString(getServerDet.emrcmpespd);
                }

                if (String.IsNullOrWhiteSpace(sEmailServer))
                {
                    sEmailServer   = Settings.Default.DefaultEmailServerName;
                    sEmailUser     = Settings.Default.DefaultEmailServerLogin;
                    sEmailPassword = Settings.Default.DefaultEmailServerPasword;
                }

                /* Local Testing Only */
#if DEBUG
                sEmailServer = "mail13.infoware.com.hk";
#endif

                #endregion

                string email     = txt_email.Text;
                string sEmail    = "";
                string sEmailMsg = "";

                if (Utility.NullToString(txt_email.Text) != "")
                {
                    sEmail = Utility.NullToString(txt_email.Text);
                }
                else
                {
                    sEmail = GetAllMailByGroupCode(txt_company.Text.TrimEnd(), txt_branch.Text.TrimEnd(), txt_GroupCode.Text.TrimEnd());
                }

                sEmailMsg = "Dear user,\n\n" + "Here is the background job reporting process, and find the attached report.\n\n" + "Regards,\n" + "webmaster\n";


                String sFileDirectory = Settings.Default.OutputFilePath + Path.DirectorySeparatorChar + txt_rptJobId.Text.TrimEnd();
                if (!Directory.Exists(sFileDirectory))
                {
                    Directory.CreateDirectory(sFileDirectory);
                }

                String sFilePath = sFileDirectory + Path.DirectorySeparatorChar + txt_filename.Text + "." + cbx_fileformat.SelectedItem.ToString();


                String sModuleID  = txt_module.Text.Trim();
                String sProgramID = txt_program.Text.Trim();

                Type       reportType = Type.GetType("IS21DotNet.Reports." + sModuleID + "." + sProgramID + "Report");
                BaseReport xrreport   = (BaseReport)Activator.CreateInstance(reportType);


                Dictionary <string, object> reportParameters = new Dictionary <string, object>();

                foreach (DataGridViewRow row in dgv_param.Rows)
                {
                    String sKey   = Utility.NullToString(row.Cells[0].Value);
                    String sType  = Utility.NullToString(row.Cells[3].Value).ToUpper();
                    Object oValue = row.Cells[1].Value;

                    reportParameters[sKey] = Program.CaseValueByDataType(oValue, sType);
                }
                xrreport.SetParameters(reportParameters);
                xrreport.TranslateLabels(Translation.Instance, Settings.Default.Language);

                xrreport.RequestParameters = false;


                if (cbx_fileformat.SelectedItem.Equals("pdf"))
                {
                    xrreport.ExportToPdf(sFilePath);
                }
                else if (cbx_fileformat.SelectedItem.Equals("xls"))
                {
                    xrreport.ExportToXls(sFilePath);
                }
                else if (cbx_fileformat.SelectedItem.Equals("xlsx"))
                {
                    xrreport.ExportToXlsx(sFilePath);
                }


                Email           emailService = Email.Instance;
                EmailServerInfo emailInfo    = new EmailServerInfo();
                emailInfo.ServerName = sEmailServer;
                emailInfo.UserID     = sEmailUser;
                emailInfo.Password   = sEmailPassword;

                List <String> attachmentList = new List <string>();
                attachmentList.Add(sFilePath);

                emailService.SendEmail(sEmail, "Reporting Mail for report " + txt_program.Text.Trim(), sEmailMsg, attachmentList, emailInfo);
                msgsend = true;
            }

            catch (System.Exception ex)
            {
                Utility.WriteLog(DateTime.Now.ToString("yyy-MM-dd HH:mm:ss") + ", ReportName: " + txt_program.Text.Trim() + ", Cannot generate Report : Failed\n Exception Message: " + ex.Message, sLogFile);
                Utility.WriteLog("\n" + ex.StackTrace, sLogFile);

                msgsend = false;
            }

            if (msgsend == true)
            {
                MessageBox.Show("Email Send Successfully ");
            }
            else
            {
                MessageBox.Show("Email Not Sent : ERROR ...Please check the Log");
            }
        }
Ejemplo n.º 9
0
        public bool TestEmailServerConnection(EmailServerInfo info, string email = null)
        {
            var provider = new EmailServerTestingProvider();

            return(provider.TestNode(info, email));
        }
Ejemplo n.º 10
0
 public void SaveEmailServerConfiguration(EmailServerInfo info)
 {
     _manager.SaveEmailServerConfiguration(info);
 }
Ejemplo n.º 11
0
        static void Main(System.String[] argss)
        {
            string[] args = { "report", "334", "PCD", "0000003,0000005,Job0000000001" };
            Dictionary <string, object> dicto = new Dictionary <string, object>();

            Utility.SetDefaultFormat(Thread.CurrentThread.CurrentCulture.Name);
            if (args.Length == 0)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new ReportingForm());
            }
            else
            {
                if (args[0].ToLower() == "report")
                {
                    //Call and execute ALL the valid report jobs
                    string sLogFile             = "";
                    InfowareDataContext context = new InfowareDataContext();

                    IQueryable <rptmallst> rptMaster = from rptmaster in context.rptmallsts
                                                       where rptmaster.rptmltenab.Equals("Y")
                                                       orderby rptmaster.rptmltseqn ascending
                                                       select rptmaster;


                    IQueryable <rptJobMst_rptDetail> progRptQuery = from rptlist in context.rptjobmsts
                                                                    from rptdetail in context.rptmaldtls
                                                                    where rptlist.rptmstbrcd == rptdetail.rptmdlbrcd &&
                                                                    rptlist.rptmstcpcd == rptdetail.rptmdlcpcd &&
                                                                    rptlist.rptmstjbcd == rptdetail.rptmdljbcd &&
                                                                    rptdetail.rptmdlenab.Equals("Y")
                                                                    select new rptJobMst_rptDetail {
                        detail = rptdetail, master = rptlist
                    };


                    Dictionary <String, EmailServerInfo> emailInfoDict = new Dictionary <string, EmailServerInfo>();

                    emailInfoDict = (from rptlist in progRptQuery
                                     join emailSer in context.emrcorcmps
                                     on rptlist.detail.rptmdlcpcd equals emailSer.emrcmpcpcd
                                     select new
                    {
                        Key = rptlist.detail.rptmdlcpcd.Trim(),
                        Value = new EmailServerInfo
                        {
                            ServerName = emailSer.emrcmpemsr == null ? "" : emailSer.emrcmpemsr.Trim(),
                            UserID = emailSer.emrcmpesur == null ? "" : emailSer.emrcmpesur.Trim(),
                            Password = emailSer.emrcmpespd == null ? "" : emailSer.emrcmpespd.Trim()
                        }
                    }).Distinct().ToDictionary(p => p.Key, p => p.Value);
                    Email           emailService = Email.Instance;
                    EmailServerInfo emailInfo    = new EmailServerInfo();
                    if (String.IsNullOrWhiteSpace(emailInfo.ServerName))
                    {
                        emailInfo.ServerName = Settings.Default.DefaultEmailServerName;
                        emailInfo.UserID     = Settings.Default.DefaultEmailServerLogin;
                        emailInfo.Password   = Settings.Default.DefaultEmailServerPasword;
                    }

                    List <rptJobMst_rptDetail> progRptList       = new List <rptJobMst_rptDetail>();
                    List <rptmallst>           progRptMasterList = new List <rptmallst>();
                    if (args.Length == 3)
                    {
                        if (!string.IsNullOrEmpty(args[1]) && !string.IsNullOrEmpty(args[2]))
                        {
                            rptMaster    = rptMaster.Where(x => x.rptmltcpcd == args[1] && x.rptmltbrcd == args[2]);
                            progRptQuery = progRptQuery.Where(x => x.detail.rptmdlcpcd == args[1] && x.detail.rptmdlbrcd == args[2]);
                        }
                    }
                    if (args.Length == 4)
                    {
                        String[]      code     = args[3].Split(',');
                        List <string> codeList = new List <string>();
                        for (int i = 0; i < code.Length; i++)
                        {
                            if (code[i].Trim() != "")
                            {
                                codeList.Add(code[i]);
                            }
                        }
                        rptMaster    = rptMaster.Where(x => x.rptmltcpcd == args[1] && x.rptmltbrcd == args[2] && codeList.Contains(x.rptmltmlcd));
                        progRptQuery = progRptQuery.Where(x => x.detail.rptmdlcpcd == args[1] && x.detail.rptmdlbrcd == args[2] && codeList.Contains(x.detail.rptmdlmlcd));
                    }
                    progRptMasterList = rptMaster.ToList();
                    foreach (var value in progRptMasterList)
                    {
                        sLogFile    = Settings.Default.DefaultLogPath + Path.DirectorySeparatorChar + value.rptmltcpcd + Path.DirectorySeparatorChar + value.rptmltbrcd + Path.DirectorySeparatorChar + value.rptmltmlcd + Path.DirectorySeparatorChar + "log_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".txt";
                        progRptList = progRptQuery.Where(x => x.detail.rptmdlmlcd == value.rptmltmlcd && x.detail.rptmdlcpcd == value.rptmltcpcd && x.detail.rptmdlbrcd == value.rptmltbrcd).ToList();
                        Dictionary <String, List <string> > attachDic = new Dictionary <string, List <string> >();
                        List <string> attachmentList = new List <string>();
                        string        result         = "";
                        foreach (var rptValue in progRptList)
                        {
                            String sCpcd = Utility.NullToString(rptValue.detail.rptmdlcpcd.TrimEnd());
                            String sBrcd = Utility.NullToString(rptValue.detail.rptmdlbrcd.TrimEnd());
                            String sJbcd = Utility.NullToString(rptValue.detail.rptmdljbcd.TrimEnd());

                            String sModuleID   = Utility.NullToString(rptValue.master.rptmstmdcd);
                            String sProgramID  = Utility.NullToString(rptValue.master.rptmstpgid);
                            String sReportDesc = Utility.NullToString(rptValue.master.rptmstdesc);
                            if (sReportDesc == "")
                            {
                                sReportDesc = sProgramID;
                            }
                            string sepMail = Utility.NullToString(value.rptmltemal.TrimEnd());
                            IQueryable <rptjobpam> paramQuery = from rptpar in context.rptjobpams
                                                                where rptpar.rptpamjbcd.Equals(sJbcd) &&
                                                                rptpar.rptpamcpcd.Equals(sCpcd) &&
                                                                rptpar.rptpambrcd.Equals(sBrcd)
                                                                orderby rptpar.rptpampram ascending
                                                                select rptpar;

                            #region reportGeneration

                            try
                            {
                                String sFileDirectory = Settings.Default.OutputFilePath + Path.DirectorySeparatorChar + sCpcd + Path.DirectorySeparatorChar + sBrcd + Path.DirectorySeparatorChar + sJbcd;
                                if (!Directory.Exists(sFileDirectory))
                                {
                                    Directory.CreateDirectory(sFileDirectory);
                                }
                                string prefix = "";
                                if (Utility.NullToString(rptValue.master.rptmstrpnm) != "")
                                {
                                    prefix = Utility.NullToString(rptValue.master.rptmstrpnm);
                                }
                                else
                                {
                                    prefix = Utility.NullToString(rptValue.master.rptmstpgid);
                                }
                                string fileNameValue = prefix + "_" + DateTime.Now.ToString("yyyyMMdd") + "_" + DateTime.Now.ToString("HHmmss");

                                String sFilePath = sFileDirectory + Path.DirectorySeparatorChar + fileNameValue + "." + rptValue.master.rptmstfmcd.TrimEnd();

                                //if program id end with data, use the new approach
                                if (sProgramID.Trim().EndsWith("Data"))
                                {
                                    Type           reportType = Type.GetType("IS21DotNet.Reports." + sModuleID + "." + sProgramID + "");
                                    BaseReportData report     = (BaseReportData)Activator.CreateInstance(reportType);
                                    Dictionary <string, object> reportParameters = new Dictionary <string, object>();
                                    foreach (var row in paramQuery)    //neeed to be ordered
                                    {
                                        String sKey   = Utility.NullToString(row.rptpampram);
                                        String sType  = Utility.NullToString(row.rptpamvtyp).ToUpper();
                                        Object oValue = Utility.NullToString(row.rptpampval);

                                        reportParameters[sKey] = CaseValueByDataType(oValue, sType);
                                    }
                                    report.createFile(report.export(reportParameters, sFilePath), sFileDirectory, fileNameValue + "." + rptValue.master.rptmstfmcd.TrimEnd());
                                    attachmentList.Add(sFilePath);
                                }
                                else if (sProgramID.Trim().EndsWith("Alert"))
                                {
                                    Dictionary <string, object> reportParameters = new Dictionary <string, object>();
                                    Dictionary <string, object> rptLocc          = new Dictionary <string, object>();
                                    foreach (var row in paramQuery)    //neeed to be ordered
                                    {
                                        String sKey   = Utility.NullToString(row.rptpampram);
                                        String sType  = Utility.NullToString(row.rptpamvtyp).ToUpper();
                                        Object oValue = Utility.NullToString(row.rptpampval);

                                        reportParameters[sKey] = CaseValueByDataType(oValue, sType);
                                    }

                                    Type          reportType = Type.GetType("IS21DotNet.Reports.Alert." + sProgramID + "");
                                    BaseAlertData report     = (BaseAlertData)Activator.CreateInstance(reportType, reportParameters);
                                    if (!report.IsAttachFile)
                                    {
                                        result += report.ExportToHTML(reportParameters) + "<br>";
                                    }
                                    else
                                    {
                                        report.createFile(report.export(reportParameters, sFilePath), sFileDirectory, fileNameValue + "." + rptValue.master.rptmstfmcd.TrimEnd());
                                        attachmentList.Add(sFilePath);
                                    }
                                }
                                else
                                {
                                    Type       reportType = Type.GetType("IS21DotNet.Reports." + sModuleID + "." + sProgramID + "Report");
                                    BaseReport xrreport   = (BaseReport)Activator.CreateInstance(reportType);
                                    Dictionary <string, object> reportParameters = new Dictionary <string, object>();

                                    foreach (var row in paramQuery)
                                    {
                                        String sKey   = Utility.NullToString(row.rptpampram);
                                        String sType  = Utility.NullToString(row.rptpamvtyp).ToUpper();
                                        Object oValue = Utility.NullToString(row.rptpampval);

                                        reportParameters[sKey] = CaseValueByDataType(oValue, sType);
                                    }

                                    xrreport.SetParameters(reportParameters);
                                    xrreport.TranslateLabels(Translation.Instance, Settings.Default.Language);
                                    xrreport.RequestParameters = false;

                                    if (rptValue.master.rptmstfmcd.TrimEnd().Equals("pdf"))
                                    {
                                        xrreport.ExportToPdf(sFilePath);
                                    }
                                    else if (rptValue.master.rptmstfmcd.TrimEnd().Equals("xls"))
                                    {
                                        xrreport.ExportToXls(sFilePath);
                                    }
                                    else if (rptValue.master.rptmstfmcd.TrimEnd().Equals("xlsx"))
                                    {
                                        xrreport.ExportToXlsx(sFilePath);
                                    }
                                    attachmentList.Add(sFilePath);
                                }
                            }
                            catch (System.Exception ex)
                            {
                                Utility.WriteLog(DateTime.Now.ToString("yyy-MM-dd HH:mm:ss") + ", ReportName: " + sReportDesc + ", Cannot generate Report : Failed\n Exception Message: " + ex.Message + ex.InnerException + "\n" + ex.StackTrace, sLogFile);
                            }

                            #endregion
                            //}
                        }
                        if (emailInfoDict.ContainsKey(value.rptmltcpcd.TrimEnd()))
                        {
                            emailInfo = emailInfoDict[value.rptmltcpcd.TrimEnd()];
                        }
                        string message = GetMessage(value.rptmltmsgh, value.rptmltmsgc, value.rptmltmsgf, "", "");
                        if (attachmentList.Count > 0 || result != "")
                        {
                            if (result != "")
                            {
                                string sCpcdName = "";
                                try
                                {
                                    sCpcdName = Utility.NullToString(context.emrcorcmps
                                                                     .Where(a => a.emrcmpcpcd == value.rptmltcpcd.TrimEnd())
                                                                     .Select(b => b.emrcmpfnmp).SingleOrDefault(), "");
                                }
                                catch
                                {
                                    sCpcdName = "";
                                }

                                message = GetMessage(value.rptmltmsgh, value.rptmltmsgc, value.rptmltmsgf, result, sCpcdName);
                            }
                            emailService.SendEmail(value.rptmltemal, value.rptmltsubj, message, attachmentList, emailInfo);
                        }
                    }
                }
            }
        }