Exemplo n.º 1
0
        public static void 查看气象台163pop3()
        {
            var util = new XmlConfig(Environment.CurrentDirectory + @"\config\智能网格设置.xml");
            // Connect and log in to POP3
            const string host     = "pop.163.com";
            const int    port     = 995;
            var          username = util.Read("emailConfig", "emailFrom", "address");
            var          password = util.Read("emailConfig", "emailFrom", "password");
            var          yjjl     = util.Read("emailConfig", "空气邮件查收记录");
            var          client   = new Pop3Client(host, port, username, password);

            try
            {
                var jlLists   = new List <string>();
                var dateLists = new List <DateTime>();
                var szls      = yjjl.Split(',');
                if (szls.Length > 0)
                {
                    foreach (var item in szls)
                    {
                        if (item.Trim() != "")
                        {
                            try
                            {
                                var strDate = item.Trim();
                                jlLists.Add(strDate);
                                dateLists.Add(Convert.ToDateTime(strDate.Substring(0, 4) + "-" +
                                                                 strDate.Substring(4, 2) + "-" +
                                                                 strDate.Substring(6, 2)));
                            }
                            catch
                            {
                            }
                        }
                    }
                }

                var builder1 = new MailQueryBuilder();
                builder1.From.Contains("yewu_zzy", true);
                builder1.InternalDate.Before(DateTime.Now.AddDays(1));
                builder1.InternalDate.Since(DateTime.Now.AddDays(-7));
                var query1          = builder1.GetQuery();
                var messageInfoCol1 = client.ListMessages(query1);
                var changeBS        = false;
                for (var i = 0; i < messageInfoCol1.Count; i++)
                {
                    if (!jlLists.Exists(y => messageInfoCol1[i].Subject.Contains(y)))
                    {
                        changeBS = true;
                        var msg = client.FetchMessage(messageInfoCol1[i].UniqueId);
                        try
                        {
                            var regex = new Regex("\\d{10}");
                            var m     = regex.Match(messageInfoCol1[i].Subject);
                            if (m.Success)
                            {
                                var strDate    = m.Groups[0].Value;
                                var dateTimels = Convert.ToDateTime(strDate.Substring(0, 4) + "-" +
                                                                    strDate.Substring(4, 2) + "-" +
                                                                    strDate.Substring(6, 2));
                                var dataDir = util.Read("路径", "Path空气质量中长期预报") +
                                              $@"{dateTimels:yyyy}\{dateTimels:MM}\{dateTimels:dd}\\";
                                if (!File.Exists(dataDir))
                                {
                                    Directory.CreateDirectory(dataDir);
                                }

                                foreach (var item in msg.Attachments)
                                {
                                    item.Save(dataDir + item.Name);
                                }
                                dateLists.Add(dateTimels);
                            }
                        }
                        catch
                        {
                        }
                    }
                }

                try
                {
                    if (changeBS)
                    {
                        if (dateLists.Count > 0)
                        {
                            var saveDate = new List <DateTime>();
                            foreach (var item in dateLists)
                            {
                                if (item.CompareTo(DateTime.Now.Date.AddDays(-8)) >= 0)
                                {
                                    saveDate.Add(item);
                                }
                            }

                            var saveStr = "";
                            foreach (var item in saveDate)
                            {
                                saveStr += $"{item:yyyyMMdd},";
                            }
                            if (saveStr.Length > 0)
                            {
                                saveStr = saveStr.Substring(0, saveStr.Length - 1);
                            }
                            util.Write(saveStr, "emailConfig", "空气邮件查收记录");
                        }
                    }
                }
                catch
                {
                }

                client.Dispose();
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 2
0
        public void CSH()
        {
            XmlConfig util = new XmlConfig(Environment.CurrentDirectory + @"\config\智能网格设置.xml");

            con = util.Read("OtherConfig", "DB");
        }
        public string CIMISS6H(DateTime dateTime)
        {
            /* 1. 定义client对象 */
            DataQueryClient client = new DataQueryClient();

            /* 2.   调用方法的参数定义,并赋值 */
            /*   2.1 用户名&密码 */
            string userId = "BEHT_BFHT_2131"; //
            string pwd    = "YZHHGDJM";       //
            /*   2.2 接口ID */
            string interfaceId1 = "getSevpFileByTime";
            /*   2.3 接口参数,多个参数间无顺序 */
            Dictionary <string, string> paramsqx = new Dictionary <string, string>();

            // 必选参数
            paramsqx.Add("dataCode", "SEVP_WEFC_6H"); // 资料代码
            //检索时间段
            paramsqx.Add("times", dateTime.ToUniversalTime().ToString("yyyyMMddHHmmss"));
            paramsqx.Add("elements", "File_URL,FILE_NAME_ORIG");

            // 可选参数
            //paramsqx.Add("orderby", "Station_ID_C:ASC"); // 排序:按照站号从小到大
            /*   2.4 返回文件的格式 */
            string        dataFormat = "tabText";
            StringBuilder QXSK       = new StringBuilder(); //返回字符串

            // 初始化接口服务连接资源
            client.initResources();
            // 调用接口
            int rst = client.callAPI_to_serializedStr(userId, pwd, interfaceId1, paramsqx, dataFormat, QXSK);

            // 释放接口服务连接资源
            client.destroyResources();
            string strData = Convert.ToString(QXSK);

            try
            {
                string strLS = strData.Split('\n')[0].Split()[0].Split('=')[1];
                rst = Convert.ToInt32(Regex.Replace(strLS, "\"", ""));
                if (rst == 0)
                {
                    XmlConfig util   = new XmlConfig(Environment.CurrentDirectory + @"\config\智能网格设置.xml");
                    string    myPath = util.Read("Path6Hour");

                    string[] dataSz = strData.Split('\n')[2].Split();
                    myPath += dataSz[dataSz.Length - 1];
                    bool fhbs = 保存网址文件(dataSz[3], myPath);
                    if (fhbs)
                    {
                        return("");
                    }
                    return($"{dateTime.ToString("yyyy年MM月dd日HH时")}6小时指导预保存失败\r\n");
                }

                return($"{dateTime.ToString("yyyy年MM月dd日HH时")}6小时指导预报获取失败\r\n");
            }
            catch
            {
                return($"{dateTime.ToString("yyyy年MM月dd日HH时")}6小时指导预保存失败\r\n");
            }
        }