public static void ImportN360() { PCMSDBContext db = new PCMSDBContext(); //using (ImpersonateUser u = new ImpersonateUser()) { try { string n360importpath = HttpContext.Current.Server.MapPath("~/Content/xfer/xfer.exe"); string xferargs = @"-z https://secure-transfer.cegedim.com -user:okc_pfizer_kr -password:4azr39 -s:" + HttpContext.Current.Server.MapPath("~/Content/xfer/xfer_n360_import.txt"); var processInfo = new ProcessStartInfo(n360importpath, xferargs); processInfo.CreateNoWindow = true; processInfo.UseShellExecute = true; processInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/Content/xfer/"); var process = Process.Start(processInfo); process.WaitForExit(); process.Close(); // System.Diagnostics.Process.Start(n360importpath, xferargs); } catch (Exception e) { Batch batch = new Batch { name = @"XferHelper.ImportN360", message = e.Message, status = BatchStatus.Error }; db.Batchs.Add(batch); db.SaveChanges(); } } }
public static void SendAlertPfizerLink() { PCMSDBContext db = new PCMSDBContext(); SmtpClient client = initClient(); MailMessage message = initMail(Status.SettingType.PfizerLinkAlert); message.Subject = "[PCMS] 화이자링크 신청이 등록되었습니다."; string template = File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath("~/Template/PfizerLinkEmail.html")); IEnumerable <Privacy> pLinks = db.Privacies.Where(p => !string.IsNullOrEmpty(p.LINK_RESERVATION) && !p.LINK_ALERTED); foreach (Privacy p in pLinks) { try { message.Body = Engine.Razor.RunCompile(template, Guid.NewGuid().ToString(), typeof(Privacy), p); db.Userlogs.Add(new Userlog { useremail = message.To.ToString(), reqtype = @"Email", url = message.Subject, parameters = message.Body }); client.Send(message); p.LINK_ALERTED = true; db.Entry(p).State = System.Data.Entity.EntityState.Modified; } catch (Exception e) { log.Error(e); } } message.Dispose(); db.SaveChanges(); }
public static string Generater() { PCMSDBContext dbContext = new PCMSDBContext(); PcmsId id = new PcmsId(); using (System.Data.Entity.DbContextTransaction dbTran = dbContext.Database.BeginTransaction()) { try { dbContext.PcmsIds.Add(id); dbContext.SaveChanges(); id.KEY = String.Format("P{0:D6}", id.ID); dbContext.SaveChanges(); dbTran.Commit(); } catch (Exception e) { log.Error(e); dbTran.Rollback(); } dbTran.Dispose(); } return(id.KEY); }
public static void SendAlertInterface(string inf) { PCMSDBContext db = new PCMSDBContext(); SmtpClient client = initClient(); MailMessage message = initMail(inf); message.Subject = "[PCMS] 인터페이스 오류 알림"; string template = File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath("~/Template/InterfaceAlert.html")); try { message.Body = Engine.Razor.RunCompile(template, Guid.NewGuid().ToString(), typeof(string), inf); db.Userlogs.Add(new Userlog { useremail = message.To.ToString(), reqtype = @"Email", url = message.Subject, parameters = message.Body }); client.Send(message); } catch (Exception e) { log.Error(e); } message.Dispose(); db.SaveChanges(); }
//public static bool canAccessPage(string path) //{ // PCMSDBContext db = new PCMSDBContext(); // string username = getCurrentName(); // if (accessablePath.Contains(path)) return true; // UserRole roles = db.UserRoles.Where(r => r.username == username).FirstOrDefault(); // if (roles == null) return false; // bool ret = db.AccessAuthorities.Where(p => p.AccessPaths.path.Equals(path) && p.roleID == (int)roles.roletype).Count() > 0; // if (ret) accessablePath.Add(path); // return ret; //} public static bool canAccessPage(string path) { PCMSDBContext pcmsdbContext = new PCMSDBContext(); string username = MyRoleManager.getCurrentName(); UserRole roles = ((IQueryable <UserRole>)pcmsdbContext.UserRoles).Where <UserRole>((Expression <Func <UserRole, bool> >)(r => r.username == username)).FirstOrDefault <UserRole>(); if (roles == null) { return(false); } if (MyRoleManager.accessablePath.Contains(path) && roles.roletype != (MyRoleManager.RoleType)MyRoleManager.roleId) { MyRoleManager.accessablePath.Clear(); } else if (MyRoleManager.accessablePath.Contains(path)) { return(true); } bool flag = ((IQueryable <AccessAuthorities>)pcmsdbContext.AccessAuthorities).Where <AccessAuthorities>((Expression <Func <AccessAuthorities, bool> >)(p => p.AccessPaths.path.Equals(path) && p.roleID == (int)roles.roletype)).Count <AccessAuthorities>() > 0; if (flag) { MyRoleManager.accessablePath.Add(path); MyRoleManager.roleId = (int)roles.roletype; } return(flag); }
public static void SendApprovalRequest() { PCMSDBContext db = new PCMSDBContext(); SmtpClient client = initClient(); MailMessage message = initMail(Status.SettingType.NotificationEmail); message.Subject = "[PCMS:알림] 승인요청이 등록되었습니다."; string template = File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath("~/Template/AprovalRequestEmail.html")); try { message.Body = Engine.Razor.RunCompile(template, Guid.NewGuid().ToString()); db.Userlogs.Add(new Userlog { useremail = message.To.ToString(), reqtype = @"Email", url = message.Subject, parameters = message.Body }); client.Send(message); } catch (Exception e) { log.Error(e); } message.Dispose(); db.SaveChanges(); }
public static bool hasRole(RoleType roletype) { PCMSDBContext db = new PCMSDBContext(); string username = getCurrentName(); IEnumerable <UserRole> roles = db.UserRoles.Where(r => r.username == username && r.roletype == roletype).ToList(); return(roles.Count() > 0); }
public static void Call(XferActionEnum action, string scriptfile) { StringBuilder sb = new StringBuilder(); PCMSDBContext db = new PCMSDBContext(); string basefolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"xfer\"); string exepath = basefolder + @"xfer.exe"; try { string id = ConfigurationManager.AppSettings["user"]; string pwd = ConfigurationManager.AppSettings["password"]; //string xferargs = @" -z https://secure-transfer.cegedim.com -user:"******" -password:"******" -s:" + scriptfile; string xferargs = @" -z https://SECURE-TRANSFER.SOLUTIONS.IQVIA.COM -user:"******" -password:"******" -s:" + scriptfile; Process p = new Process(); var processInfo = p.StartInfo; p.StartInfo.RedirectStandardError = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = false; p.StartInfo.WorkingDirectory = basefolder; p.StartInfo.FileName = exepath; p.StartInfo.Arguments = xferargs; p.OutputDataReceived += new DataReceivedEventHandler((s, e) => { sb.Append(e.Data); sb.Append("\r\n"); }); p.ErrorDataReceived += new DataReceivedEventHandler((s, e) => { sb.Append(e.Data); sb.Append("\r\n"); }); p.Start(); p.BeginOutputReadLine(); p.WaitForExit(); p.Close(); Batch batch = new Batch { name = @"XPER_" + action.ToString(), message = sb.ToString(), status = BatchStatus.Running }; db.Batches.Add(batch); db.SaveChanges(); } catch (Exception e) { sb.Append(e.Message); Batch batch = new Batch { name = @"XPER_" + action.ToString(), message = sb.ToString(), status = BatchStatus.Error }; db.Batches.Add(batch); db.SaveChanges(); } }
public static string getRoleName() { PCMSDBContext db = new PCMSDBContext(); string username = getCurrentName(); string rolename = ""; IEnumerable <UserRole> roles = db.UserRoles.Where(r => r.username == username).OrderByDescending(r => r.roletype).ToList(); if (roles.Count() > 0) { UserRole ur = roles.First(); rolename = EnumHelper <RoleType> .GetDisplayValue(ur.roletype); } return(username + " [" + rolename + "]"); }
public static void Connect() { Disconnect(); PCMSDBContext db = new PCMSDBContext(); // 네트워크 드라이브 연결 AppSettingsReader appSettingsReader = new AppSettingsReader(); string userName = (string)appSettingsReader.GetValue("ImpersonateUser", typeof(string)); string password = (string)appSettingsReader.GetValue("ImpersonatePassword", typeof(string)); try { IWshRuntimeLibrary.IWshNetwork_Class network = new IWshRuntimeLibrary.IWshNetwork_Class(); network.MapNetworkDrive("i:", @"\\SDCUNS600VFS02\kr_pcms", Type.Missing, userName, password); } catch (Exception e) { CommonUtil.LogWrite(e.Message); } }
private static MailMessage initMail(string receiver) // receiver = NTID { PCMSDBContext db = new PCMSDBContext(); AppSettingsReader appSettingsReader = new AppSettingsReader(); string smtpAccount = "*****@*****.**"; string remail = string.Empty; // remail = receiver; MailMessage message = new MailMessage(); message.From = new MailAddress(smtpAccount); message.To.Add(remail); message.BodyEncoding = System.Text.Encoding.UTF8; message.SubjectEncoding = System.Text.Encoding.UTF8; message.IsBodyHtml = true; return(message); }
public static void Connect() { Disconnect(); PCMSDBContext db = new PCMSDBContext(); // 네트워크 드라이브 연결 AppSettingsReader appSettingsReader = new AppSettingsReader(); string userName = @"SRVASP-PCMSMGT"; string password = @"Pfe51627"; try { IWshRuntimeLibrary.IWshNetwork_Class network = new IWshRuntimeLibrary.IWshNetwork_Class(); network.MapNetworkDrive("i:", @"\\SDCUNS600VFS02\kr_pcms", Type.Missing, userName, password); } #pragma warning disable CS0168 // The variable 'e' is declared but never used catch (Exception e) #pragma warning restore CS0168 // The variable 'e' is declared but never used { } }
private static MailMessage initMail(string receiver) // receiver = NTID { PCMSDBContext db = new PCMSDBContext(); AppSettingsReader appSettingsReader = new AppSettingsReader(); string smtpAccount = (string)appSettingsReader.GetValue("SMTPAccount", typeof(string)); string remail = string.Empty; // MembershipUser member = Membership.GetUser(receiver); remail = member.Email; MailMessage message = new MailMessage(); message.From = new MailAddress(smtpAccount); message.To.Add(remail); message.BodyEncoding = System.Text.Encoding.UTF8; message.SubjectEncoding = System.Text.Encoding.UTF8; message.IsBodyHtml = true; return(message); }
private static MailMessage initMail(Status.SettingType stype) { PCMSDBContext db = new PCMSDBContext(); AppSettingsReader appSettingsReader = new AppSettingsReader(); string smtpAccount = (string)appSettingsReader.GetValue("SMTPAccount", typeof(string)); // 승인 발생시 승인요청 알림. Setting conf = db.Settings.Where(s => s.type == stype).First(); String[] toaddr = conf.value.Split(';'); MailMessage message = new MailMessage(); message.From = new MailAddress(smtpAccount); try { foreach (var a in toaddr) { if (!string.IsNullOrEmpty(a)) { MembershipUser member = Membership.GetUser(a); string remail = member.Email; if (!string.IsNullOrEmpty(remail)) { message.To.Add(remail); } } } } catch (Exception e) { Console.WriteLine(e.Message); } message.BodyEncoding = System.Text.Encoding.UTF8; message.SubjectEncoding = System.Text.Encoding.UTF8; message.IsBodyHtml = true; return(message); }
public static void SendAlertInterface(string inf, string msg = null) { PCMSDBContext db = new PCMSDBContext(); SmtpClient client = initClient(); MailMessage message = initMail(Status.SettingType.InterfaceAlertMail); message.Subject = "[PCMS] 인터페이스 오류 알림"; try { message.Body = "Interface error occured from " + inf + "\n" + msg; db.Userlogs.Add(new Userlog { useremail = message.To.ToString(), reqtype = @"Email", url = message.Subject, parameters = message.Body }); client.Send(message); } catch (Exception e) { log.Error(e); } message.Dispose(); db.SaveChanges(); }
public static void Call(XferActionEnum action, string localpath, string remotepath) { StringBuilder sb = new StringBuilder(); PCMSDBContext db = new PCMSDBContext(); string basefolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"xfer\"); string exepath = basefolder + @"xfer.exe"; string scriptfile = basefolder + @"xfer_n360_" + action.ToString() + "_" + DateTime.UtcNow.ToString("yyyyMMddTHHmmss") + @".txt"; try { StreamWriter fileStream = new StreamWriter(scriptfile); fileStream.WriteLine(@"lcd " + localpath); fileStream.WriteLine(@"cd " + remotepath); if (action == XferActionEnum.Import) { fileStream.WriteLine(@"mget *.txt"); } else if (action == XferActionEnum.Export) { fileStream.WriteLine(@"mput *.txt"); } fileStream.WriteLine(@"quit"); fileStream.Close(); fileStream.Dispose(); string id = ConfigurationManager.AppSettings["user"]; string pwd = ConfigurationManager.AppSettings["password"]; //string xferargs = @" -z https://secure-transfer.cegedim.com -user:"******" -password:"******" -s:" + scriptfile; string xferargs = @" -z https://SECURE-TRANSFER.SOLUTIONS.IQVIA.COM -user:"******" -password:"******" -s:" + scriptfile; Process p = new Process(); var processInfo = p.StartInfo; p.StartInfo.RedirectStandardError = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = false; p.StartInfo.WorkingDirectory = basefolder; p.StartInfo.FileName = exepath; p.StartInfo.Arguments = xferargs; p.OutputDataReceived += new DataReceivedEventHandler((s, e) => { sb.Append(e.Data); sb.Append("\r\n"); }); p.ErrorDataReceived += new DataReceivedEventHandler((s, e) => { sb.Append(e.Data); sb.Append("\r\n"); }); p.Start(); p.BeginOutputReadLine(); p.WaitForExit(); p.Close(); Batch batch = new Batch { name = @"XPER_" + action.ToString(), message = sb.ToString(), status = BatchStatus.Running }; db.Batches.Add(batch); db.SaveChanges(); File.Delete(scriptfile); } catch (Exception e) { sb.Append(e.Message); Batch batch = new Batch { name = @"XPER_" + action.ToString(), message = sb.ToString(), status = BatchStatus.Error }; db.Batches.Add(batch); db.SaveChanges(); } }
public void TaskApi() { // 네트워크드라이브 연결 NetworkDriveHelper.Connect(); //CommonUtil.LogWrite("Start PcmsTask"); //CommonUtil.LogWrite("connection string" + System.Configuration.ConfigurationManager.ConnectionStrings["PUBLISH"].ConnectionString); // 디비 연결 PCMSDBContext db = new PCMSDBContext(); string curHour = DateTime.UtcNow.ToString("HH"); //CommonUtil.LogWrite("현재시간:" + curHour); List <Channel> channels = new List <Channel>(); try { channels = db.Channels.ToList(); } #pragma warning disable CS0168 // The variable 'e' is declared but never used catch (Exception e) { #pragma warning restore CS0168 // The variable 'e' is declared but never used //CommonUtil.LogWrite(e.Message); } //CommonUtil.LogWrite("Channel Count:" + channels.Count()); foreach (Channel c in channels) { //CommonUtil.LogWrite("Channel:"+c.name + "=" + c.type); // 사용여부 if (c.usage == false && !c.Instantrun) { continue; } // 입력 시간 -> UTC 화 int athour = c.athour - 9 < 0 ? c.athour - 9 + 24: c.athour - 9; if (string.Format("{0:D2}", athour) != curHour && !c.Instantrun) { continue; } if (!c.Instantrun) { //CommonUtil.LogWrite("Time Trigger"); // 최근실행 내역 비교 var bs = db.Batches.Where(b => b.name == c.name && b.bound == c.bound); if (bs.Count() > 0) { Batch lastrun = bs.OrderByDescending(b => b.ID).First(); string cur = DateTime.UtcNow.ToString("yyyyMMddHH"); string old = lastrun.createdate.ToString("yyyyMMddHH"); if (cur == old) { continue; } } } else { //CommonUtil.LogWrite("Instant Run"); c.Instantrun = false; db.Entry(c).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } // 실행 if (c.name == @"ODSM" && c.bound == BoundType.Inbound) { ODSMInbound bound = new ODSMInbound(c); bound.Execute(); } else if (c.name == @"N360" && c.bound == BoundType.Outbound) { N360Outbound bound = new N360Outbound(c); bound.Execute(); } else if (c.name == @"PforceRX" && c.bound == BoundType.Inbound) { PforceRXInbound bound = new PforceRXInbound(c); bound.Execute(); } else if (c.name == @"PforceRX" && c.bound == BoundType.Outbound) { PforceRXOutbound bound = new PforceRXOutbound(c); bound.Execute(); } else if (c.name == @"MMS" && c.bound == BoundType.Inbound) { MMSInbound bound = new MMSInbound(c); bound.Execute(); } } // for channel // 삭제/만료 설정 추가 try { if (db.Settings.Where(s => s.type == SettingType.ExpiredBatch).Count() < 1) { Setting s = new Setting(); s.name = @"만료배치"; s.type = SettingType.ExpiredBatch; s.value = @"N"; db.Settings.Add(s); db.SaveChanges(); } if (db.Settings.Where(s => s.type == SettingType.RemoveBatch).Count() < 1) { Setting s = new Setting(); s.name = @"삭제배치"; s.type = SettingType.RemoveBatch; s.value = @"N"; db.Settings.Add(s); db.SaveChanges(); } #pragma warning disable CS0168 // The variable 'e' is declared but never used } catch (Exception e) { #pragma warning restore CS0168 // The variable 'e' is declared but never used } // 삭제처리 if (curHour == "00") { Setting ss = db.Settings.Where(s => s.type == SettingType.RemoveBatch).First(); if (ss.value != @"N") { DeleteTask dt = new DeleteTask(); dt.Execute(); } } // 기간 만료 하기 if (curHour == "00") { Setting ss = db.Settings.Where(s => s.type == SettingType.ExpiredBatch).First(); if (ss.value != @"N") { ExpirationTask et = new ExpirationTask(); et.Execute(); } } NetworkDriveHelper.Disconnect(); //CommonUtil.LogWrite("PcmsTask End."); }