public void Execute(NotificationSchedulerVO vo) { try { if (ShipConfirmEmailUS == "Y") { sdUS = new SAPDAO("US"); var shipmentInfoList_US = sdUS.GetShipmentInfoData(); shipmentInfoList_US.ForEach(x => { MailHelper.SendShipEmailToCustomer(x); sdUS.UpdateIsShipped(x.DocEntry); }); } if (ShipConfirmEmailCA == "Y") { sdCA = new SAPDAO("CA"); var shipmentInfoList_CA = sdCA.GetShipmentInfoData(); shipmentInfoList_CA.ForEach(x => { MailHelper.SendShipEmailToCustomer(x); sdCA.UpdateIsShipped(x.DocEntry); }); } } catch (Exception e) { log.Error(e); MailHelper.AddSystemIssueString(GetType().Name, e.ToString()); } finally { sdUS.closeConnection(); sdCA.closeConnection(); }; }
public void Execute(NotificationSchedulerVO vo) { sd = new SAPDAO("US"); try { var currentList = sd.GetAccountForRenewalData(MonthPeroid.CURRENT_MONTH); var currentFileHelper = new FileHelper <AccountForRenewalVO>(); var currentStageFileInfo = currentFileHelper.CreateCvsFileAtStage(currentList, FILE_SHOT_NAME_CURRENT_MONTH); var lastList = sd.GetAccountForRenewalData(MonthPeroid.LAST_MONTH); var lastFileHelper = new FileHelper <AccountForRenewalVO>(); var lastStageFileInfo = currentFileHelper.CreateCvsFileAtStage(lastList, FILE_SHOT_NAME_LAST_MONTH); var nextList = sd.GetAccountForRenewalData(MonthPeroid.NEXT_MONTH); var nextFileHelper = new FileHelper <AccountForRenewalVO>(); var nextStageFileInfo = currentFileHelper.CreateCvsFileAtStage(nextList, FILE_SHOT_NAME_NEXT_MONTH); var fileList = new List <CreatedFileInfoVO> { currentStageFileInfo, lastStageFileInfo, nextStageFileInfo }; MailHelper.Sendmail(vo, fileList); currentFileHelper.moveCompleteDirectory(currentStageFileInfo); currentFileHelper.moveCompleteDirectory(lastStageFileInfo); currentFileHelper.moveCompleteDirectory(nextStageFileInfo); } catch (Exception e) { log.Error(e); MailHelper.AddSystemIssueString(GetType().Name, e.ToString()); } finally { sd.closeConnection(); }; }
protected string getStringData(String sqlQuery, SqlParameter[] opArr) { SqlDataReader rdr = null; string result = null; try { rdr = getRecordSet(sqlQuery, opArr); if (rdr.HasRows) { while (rdr.Read()) { result = rdr.GetString(0); } } } catch (SqlException ex) { MailHelper.AddSystemIssueString(GetType().Name, ex.ToString()); throw ex; } finally { if (rdr.IsClosed == false) { rdr.Close(); } } return(result); }
protected Int32 getIntDataBySP(String sqlQuery, SqlParameter[] opArr) { SqlDataReader rdr = null; Int32 result = 0; try { rdr = getRecordSetBySP(sqlQuery, opArr); if (rdr.HasRows) { while (rdr.Read()) { result = Convert.ToInt32(rdr.GetValue(0)); } } } catch (SqlException ex) { MailHelper.AddSystemIssueString(GetType().Name, ex.ToString()); throw ex; } finally { if (rdr.IsClosed == false) { rdr.Close(); } } return(result); }
private HttpWebRequest GenerateRequest(string relativeUrl) { try { HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create(relativeUrl); webreq.Credentials = new NetworkCredential(SAP_USER, SAP_PASSWORD); return(webreq); } catch (Exception ex) { log.Error("Exception caught when Generating request [" + relativeUrl + "] : {0}", ex); MailHelper.AddSystemIssueString(GetType().Name, ex.ToString()); throw ex; } }
private bool makeDirectory(string path, string directoryName) { try { string newPath = Path.Combine(path, directoryName); DirectoryInfo di = new DirectoryInfo(newPath); if (di.Exists == false) { di.Create(); } return(true); } catch (Exception e) { MailHelper.AddSystemIssueString(GetType().Name, "Creat directory error", e.ToString()); return(false); } }
public void Execute(NotificationSchedulerVO vo) { sd = new SAPDAO("CA"); try { var list = sd.GetValidToShipData(); var fileHelper = new FileHelper <ValidToShipVO>(); var stageFileInfo = fileHelper.CreateCvsFileAtStage(list, FILE_SHOT_NAME); MailHelper.Sendmail(vo, stageFileInfo); fileHelper.moveCompleteDirectory(stageFileInfo); } catch (Exception e) { log.Error(e); MailHelper.AddSystemIssueString(GetType().Name, e.ToString()); } finally { sd.closeConnection(); }; }
public void Execute(NotificationSchedulerVO vo) { sd = new SAPDAO("CA"); try { var list = sd.getTestNoti(); var fileHelper = new FileHelper <TestNotiVO>(); var stageFileInfo = fileHelper.CreateCvsFileAtStage(list, FILE_SHOT_NAME); MailHelper.Sendmail(vo, stageFileInfo); //MailHelper.SendmailAdmin("test", "test", MailHelper.SERVERTYPE_INTERNAL, Path.Combine(stageFileInfo.path, stageFileInfo.fileName)); fileHelper.moveCompleteDirectory(stageFileInfo); } catch (Exception e) { log.Error(e); MailHelper.AddSystemIssueString(GetType().Name, e.ToString()); } finally { sd.closeConnection(); }; }
public void ExecuteTaskQueue(List <NotificationSchedulerVO> resultQueue) { resultQueue.ForEach(x => { try { Type type = Type.GetType(TASK_NAMESPACE + x.ProgramClass); if (type == null) { // class 명 찾지못한경우 이메일 큐에 삽입 MailHelper.AddSystemIssueString(GetType().Name, "Class not found", "Cannot found class " + x.ProgramClass + " please check database"); } else // class 리플렉션으로 인스턴스 생성 { var constructor = type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(k => k.GetParameters().Length == 0).First(); dynamic node = constructor.Invoke(null); node.Execute(x); } } catch (Exception e) { MailHelper.AddSystemIssueString(GetType().Name, "Class Ececute Error", e.ToString()); } }); }
private XmlDocument GetXML(string url) { try { HttpWebRequest request = GenerateRequest(url); request.Method = WebRequestMethods.Http.Get; //request.Timeout = HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream receiveStream = response.GetResponseStream(); Encoding encode = Encoding.GetEncoding("utf-8"); StreamReader readStream = new StreamReader(receiveStream, encode); XmlDocument doc = new XmlDocument(); doc.Load(readStream); return(doc); } catch (Exception ex) { log.Error("Exception caught when Generating request", ex); MailHelper.AddSystemIssueString(GetType().Name, ex.ToString()); throw ex; } }
public void moveCompleteDirectory(CreatedFileInfoVO fileInfoVO) { if (fileInfoVO.filePath == CreatedFileInfoVO.nil) { return; } if (makeDirectory(COMPLETE_ROOT_PATH, currentShotDate)) { GC.Collect(); // OS can access file FileInfo destFile = new FileInfo(Path.Combine(STAGE_ROOT_PATH, currentShotDate, fileInfoVO.fileName)); if (destFile.Exists) { var fileInfo = new FileInfo(Path.Combine(COMPLETE_ROOT_PATH, currentShotDate, fileInfoVO.fileName)); if (fileInfo.Exists) { var random = new Random(); int extendName = random.Next(0000, 9999); fileInfoVO.fileName = fileInfoVO.fileName.Replace(".csv", "") + "_" + extendName + ".csv"; } try { destFile.MoveTo(Path.Combine(COMPLETE_ROOT_PATH, currentShotDate, fileInfoVO.fileName)); } catch (Exception e) { MailHelper.AddSystemIssueString(GetType().Name, "File Move error", e.ToString()); } } } else { MailHelper.AddSystemIssueString(GetType().Name, MailString.FILE_CREATE_ERROR_SUBJECT, MailString.FILE_CREATE_ERROR_BODY + COMPLETE_ROOT_PATH + currentShotDate); } }
public void Execute(NotificationSchedulerVO vo) { try { var splitServerName = SERVER_NAME.Split(','); log.Info("============== Api state check =============="); foreach (var serverName in splitServerName) { var urlUS = new UrlHelper().Scheme(SCHEMA) .Host(serverName) .Port(API_PORT) .Path(SAP_US).Path(ITEMPRICE).Path(ACCOUNT_NO).Path(ITEM_CODE) .Extension(EXTENSION) .Build(); var urlCA = new UrlHelper() .Scheme(SCHEMA) .Host(serverName) .Port(API_PORT) .Path(SAP_CA).Path(ITEMPRICE).Path(ACCOUNT_NO).Path(ITEM_CODE) .Extension(EXTENSION) .Build(); Console.WriteLine("======="); Console.WriteLine(urlUS); Console.WriteLine(urlCA); ApiServerStateCheck(serverName, SAP_US, urlUS); ApiServerStateCheck(serverName, SAP_CA, urlCA); } log.Info("============================================="); } catch (Exception e) { log.Error(e); MailHelper.AddSystemIssueString(GetType().Name, e.ToString()); } }
public List <NotificationSchedulerVO> GetValidTaskQueue() { sdUP = new SAPDAO("UP"); var resultQueue = new List <NotificationSchedulerVO>(); try { var list = sdUP.getScheduler(); list.ForEach(x => { Console.WriteLine("=========="); Console.WriteLine("Id ->" + x.Id + " "); Console.WriteLine("Department ->" + x.Department + " "); Console.WriteLine("Cycle ->" + x.Cycle + " "); Console.WriteLine("CycleDate ->" + x.CycleDate + " "); Console.WriteLine("CycleDay ->" + x.CycleDay + " "); Console.WriteLine("CycleTime ->" + x.CycleTime + " "); Console.WriteLine("EmailServer ->" + x.EmailServer + " "); Console.WriteLine("EmailTitle ->" + x.EmailTitle + " "); Console.WriteLine("EmailContent ->" + x.EmailContent + " "); Console.WriteLine("ReceiverEmail ->" + x.ReceiverEmail + " "); Console.WriteLine("SenderName ->" + x.SenderName + " "); Console.WriteLine("SenderEmail ->" + x.SenderEmail + " "); Console.WriteLine("CcEmail ->" + x.CcEmail + " "); Console.WriteLine("BccEmail ->" + x.BccEmail + " "); Console.WriteLine("ProgramClass ->" + x.ProgramClass + " "); Console.WriteLine("FisrtRunDate ->" + x.FirstRunDate + " "); Console.WriteLine("LastRunDate ->" + x.LastRunDate + " "); Console.WriteLine("CreateDate ->" + x.CreateDate + " "); Console.WriteLine("ModifiedDate ->" + x.ModifiedDate + " "); Console.WriteLine("=========="); if (x.Active == 1) { try { switch (x.Cycle) { case CYCLE.ANY: { Console.WriteLine("INSERT QUEUE ============"); resultQueue.Add(x); if (x.LastRunDate == new DateTime(1900, 01, 01)) // if first run { sdUP.UpdateFirstRunDate(x.Id, DateTime.Now); sdUP.UpdateLastRunDate(x.Id, DateTime.Now); } else { sdUP.UpdateLastRunDate(x.Id, DateTime.Now); } break; } case CYCLE.HOURLY: { Console.WriteLine("HOURLY ============"); if (TimeValidationAndInsert(x, CYCLE.HOURLY)) { resultQueue.Add(x); } break; } case CYCLE.DAILY: { Console.WriteLine("DAILY ============"); if (TimeValidationAndInsert(x, CYCLE.DAILY)) { resultQueue.Add(x); } break; } case CYCLE.WEEKLY: { if (x.CycleDay == TODAY.DAYOFWEEK) { Console.WriteLine("WEEKLY PASS ============"); if (TimeValidationAndInsert(x, CYCLE.WEEKLY)) { resultQueue.Add(x); } } else { Console.WriteLine("WEEKLY NOT PASS ============"); } break; } case CYCLE.MONTHLY: { if (TODAY.DATE == x.CycleDate) { Console.WriteLine("MONTHLY PASS ============"); if (TimeValidationAndInsert(x, CYCLE.MONTHLY)) { resultQueue.Add(x); } } else { Console.WriteLine("MONTHLY NOT PASS ============"); } break; } } } catch (Exception e) { MailHelper.AddSystemIssueString(GetType().Name, e.ToString()); } } else { Console.WriteLine("NOT ACTIVE ============"); } }); } catch (Exception e) { log.Error(e); MailHelper.AddSystemIssueString(GetType().Name, e.ToString()); } finally { sdUP.closeConnection(); }; return(resultQueue); }
public CreatedFileInfoVO CreateCvsFileAtStage(List <T> itemList, string fileName) { var fileInfoVO = new CreatedFileInfoVO(); fileInfoVO.dataCount = itemList.Count; if (itemList.Count == 0) { fileInfoVO.filePath = CreatedFileInfoVO.nil; fileInfoVO.fileName = fileName; return(fileInfoVO); } var pullPath = ""; var realFileName = ""; if (makeDirectory(STAGE_ROOT_PATH, currentShotDate)) { pullPath = Path.Combine(STAGE_ROOT_PATH, currentShotDate); fileName = fileName + "_" + TODAY.DETETIME; realFileName = fileName + ".csv"; var fileInfo = new FileInfo(Path.Combine(pullPath, realFileName)); if (fileInfo.Exists) { var random = new Random(); int extendName = random.Next(0000, 9999); realFileName = fileName + "_" + extendName + ".csv"; } using (FileStream fs = new FileStream(Path.Combine(pullPath, realFileName), FileMode.OpenOrCreate, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fs)) { sw.NewLine = CARRIAGE_RETURN; try { if (itemList.Count > 0) { FieldInfo[] fields = itemList[0].GetType().GetFields(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < fields.Length; i++) { sb.Append(fields[i].Name); if (i == fields.Length - 1) { sb.Append(CARRIAGE_RETURN); } else { sb.Append(","); } } for (int i = 0; i < itemList.Count; i++) { for (int j = 0; j < fields.Length; j++) { FieldInfo info = itemList[i].GetType().GetField(fields[j].Name); string temp = info.GetValue(itemList[i]).ToString().Replace(CARRIAGE_RETURN, ""); if (temp.Contains(",")) { temp = temp.Insert(temp.Length, "\u0022"); temp = temp.Insert(0, "\u0022"); } sb.Append(temp); //sb.Append(info.GetValue(itemList[i]).ToString().Replace(CARRIAGE_RETURN, "")); if (j == fields.Length - 1) { sb.Append(CARRIAGE_RETURN); } else { sb.Append(","); } } } sw.WriteLine(sb.ToString()); } } catch (System.IO.IOException e) { fileName = ""; MailHelper.AddSystemIssueString(GetType().Name, "File Create error", e.ToString()); } } } } else { MailHelper.AddSystemIssueString(GetType().Name, MailString.FILE_CREATE_ERROR_SUBJECT, MailString.FILE_CREATE_ERROR_BODY + STAGE_ROOT_PATH + currentShotDate); } fileInfoVO.filePath = pullPath; fileInfoVO.fileName = realFileName; return(fileInfoVO); }
private bool ApiServerStateCheck(string serverName, string contryType, String apiUrl) { bool result = false; string xmlResult = ""; try { Console.Write($"{serverName} {contryType} -->"); XmlDocument resultXml = GetXML(apiUrl); XmlNodeList vStatusList = resultXml.GetElementsByTagName("b1Reply:status"); if (vStatusList.Count > 0) { xmlResult = vStatusList[0].InnerXml; //if (serverName == "prdsapapi-02") throw new Exception(serverName + contryType); if (xmlResult == "ERROR") { XmlNodeList iErrorList = resultXml.GetElementsByTagName("b1Reply:error"); if (iErrorList.Count > 0) { MailHelper.AddSystemIssueString(GetType().Name, "API server check", $"{serverName} {contryType} status error check this server"); log.Error($"{serverName} {contryType} status error check this server"); } else { MailHelper.AddSystemIssueString(GetType().Name, "API server check", $"{serverName} {contryType} status error check this server"); log.Error($"{serverName} {contryType} status error check this server"); } } else { Console.Write($" Status : {xmlResult} , "); var resultItemCode = resultXml.GetElementsByTagName("ItemCode"); var resultItemCodeString = resultItemCode[0].InnerXml; if (resultItemCodeString == ITEM_CODE) { Console.WriteLine(" Item code : Match"); result = true; } else { MailHelper.AddSystemIssueString(GetType().Name, $"API server check", $"{serverName} {contryType} Item Mathch fail"); log.Error($"{serverName} {contryType} Item Mathch fail"); } } } else { MailHelper.AddSystemIssueString(GetType().Name, "API server check", $"{serverName} {contryType} status not exist"); log.Error($"{serverName} {contryType} status not exist"); } } catch (Exception e) { MailHelper.AddSystemIssueString(GetType().Name, $"{serverName} error", e.ToString()); log.Error($"{serverName} error {e.ToString()}"); } return(result); }