コード例 #1
0
        public static void Run([TimerTrigger("0 30 23 * * *")] TimerInfo myTimer, TraceWriter log)
        {
            _log      = log;
            _shipList = new List <ShipItem>();
            _mailBody = new StringBuilder();
            var lab021Model = new LAB021_MODEL();

            lab021Model.SaveChanges();
            shipListInit();

            if (_functionIsRunningOrNot == true)
            {
                _log.Info($"Other Instance is Running at: {DateTime.Now}");
                return;
            }
            _functionIsRunningOrNot = true;
            try
            {
                SendMail();
            }
            catch (Exception e)
            {
                _log.Info($"Error!! : {e.ToString()}");
                _functionIsRunningOrNot = false;
            }
            finally
            {
                _functionIsRunningOrNot = false;
            }
        }
コード例 #2
0
        public static StringBuilder MakeEmailBody()
        {
            var mailBody = new StringBuilder();

            _etaReport = new List <ETA_REPORT>();

            foreach (var item in _shipList)
            {
                var endDt   = DateTime.UtcNow.AddDays(3).ToString("yyyyMMdd");
                var startDt = DateTime.UtcNow.AddDays(-5).ToString("yyyyMMdd");
                var apiUrl  = "http://poserp.possm.com/comm/restful/getPositionRpt.ex?vslCd=" + item.shipCode + "&fromDt=" + startDt + "&toDt=" + endDt;

                WebClient webClient    = new WebClient();
                Stream    stream       = webClient.OpenRead(apiUrl);
                string    responseJSON = new StreamReader(stream).ReadToEnd();

                var rootResult = JsonConvert.DeserializeObject <dynamic>(responseJSON);
                foreach (var item2 in rootResult)
                {
                    foreach (var item3 in item2)
                    {
                        Dictionary <string, string> temp = new Dictionary <string, string>();

                        foreach (var item4 in item3)
                        {
                            temp.Add(Convert.ToString(item4.Name), Convert.ToString(item4.Value));
                        }
                        try
                        {
                            var koreacheck = ParseToString(temp["ETA PORT"]).ToLower().Contains("korea");
                            var chniacheck = ParseToString(temp["ETA PORT"]).ToLower().Contains("china");

                            if (koreacheck)
                            {
                                _etaReport.Add(new ETA_REPORT
                                {
                                    SHIP_NAME   = ParseToString(temp["VESSEL NAME"]),
                                    REPORT_TIME = ParseToDate(temp["REPORT TIME"]),
                                    ETA_PORT    = ParseToString(temp["ETA PORT"]),
                                    ETA_TIME    = ParseToDate(temp["ETA TIME"]),
                                    NATION      = ParseToString("KOREA")
                                });
                            }
                            else if (chniacheck)
                            {
                                _etaReport.Add(new ETA_REPORT
                                {
                                    SHIP_NAME   = ParseToString(temp["VESSEL NAME"]),
                                    REPORT_TIME = ParseToDate(temp["REPORT TIME"]),
                                    ETA_PORT    = ParseToString(temp["ETA PORT"]),
                                    ETA_TIME    = ParseToDate(temp["ETA TIME"]),
                                    NATION      = ParseToString("CHINA")
                                });
                            }
                        }
                        catch { }
                    }
                }
            }

            using (var lab021Model = new LAB021_MODEL())
            {
                var resulttemp = _etaReport.OrderByDescending(d => d.REPORT_TIME).ToList();

                var resulttemp2 = new List <ETA_REPORT>();
                foreach (var item in resulttemp)
                {
                    if (resulttemp2.Where(d => d.SHIP_NAME == item.SHIP_NAME).Count() == 0)
                    {
                        resulttemp2.Add(item);
                    }
                }

                var resulttemp3 = resulttemp2.OrderByDescending(d => d.NATION).ThenBy(d => d.ETA_TIME).ToList();
                lab021Model.Database.ExecuteSqlCommand("TRUNCATE TABLE [" + "ETA_REPORT" + "]");
                mailBody.AppendFormat("ETA 알리미");
                mailBody.AppendFormat("<br>");
                mailBody.AppendFormat("===============================================");
                mailBody.AppendFormat("<br>");
                foreach (var item in resulttemp3)
                {
                    mailBody.AppendFormat("선 박 이 름  : " + item.SHIP_NAME);
                    mailBody.AppendFormat("<br>");
                    mailBody.AppendFormat("보 고 시 각  : " + item.REPORT_TIME.ToString());
                    mailBody.AppendFormat("<br>");
                    mailBody.AppendFormat("도착예정장소 : " + item.ETA_PORT);
                    mailBody.AppendFormat("<br>");
                    mailBody.AppendFormat("도착예정시각 : " + item.ETA_TIME.ToString());
                    mailBody.AppendFormat("<br>");
                    mailBody.AppendFormat("국        가 : " + item.NATION);
                    mailBody.AppendFormat("<br>");
                    mailBody.AppendFormat("===============================================");
                    mailBody.AppendFormat("<br>");
                    lab021Model.ETA_REPORT.Add(item);
                    lab021Model.SaveChanges();
                }
            }
            return(mailBody);
        }