Example #1
0
        /// <summary>
        /// 对比本地backs文件下xml报文和省前置机上RepMsg文件夹下的报文如果有不存在的就移动出来
        /// </summary>
        public List <string> fileFilter(string ip, string port, string username, string password, FileInfo[] fileInfos, string filepath)
        {
            //连接SFTP
            SFTPHandler sftp = new SFTPHandler(ip, port, username, password);

            if (!sftp.Connected)
            {
                sftp.Connect();
            }
            //获取SFTP当天的报文
            ArrayList     fileList     = sftp.GetFileListByCreateTime(filepath, ".xml");
            List <string> sftpfileList = new List <string>();

            foreach (var file in fileList)
            {
                sftpfileList.Add(stringEx(file.ToString()));
            }
            //把本地读取的报文文件放入ArryList集合中
            List <string> localFileList = new List <string>();

            foreach (var file in fileInfos)
            {
                localFileList.Add(stringEx(file.ToString()));
            }

            if (sftpfileList.Count() > 0)
            {
                //取本地当日文件集合和SFTP上面当日文件集合的差集

                localFileList = localFileList.Except(sftpfileList).ToList();
            }

            sftp.Disconnect();
            return(localFileList);
        }
Example #2
0
        private int vMax = 100;                                         //用于实例化进度条,可以根据自己的需要,自己改变

        private void ThreadFun()
        {
            //获取本地当日报文的数量
            FileInfo[] fileInfos = new DirectoryInfo(fileBacksPath).GetFiles("*.xml");

            FileInfo[] localTodayFileInfos = getLocalTodatyFile(fileInfos);

            localtodayfilenum = localTodayFileInfos == null?0: localTodayFileInfos.Count();
            //如果是周末或0:00分,就设为初始值
            if (localtodayfilenum == 0)
            {
                localtodayfilenum = 1;
            }

            // 获取sftp当日报文的数量  localTodayFileInfos, provinceBackFilePath
            //连接SFTP
            SFTPHandler sftp = new SFTPHandler(provinceIP, provincePort, username, password);

            if (!sftp.Connected)
            {
                sftp.Connect();
            }
            //获取SFTP当天的报文
            ArrayList fileList = sftp.GetFileListByCreateTime(provinceBackFilePath, ".xml");

            sftptodayfilenum = fileList.Count;
            //如果是周末或0:00分,就设为初始值
            if (sftptodayfilenum == 0)
            {
                sftptodayfilenum = 2;
            }
            sftp.Disconnect();

            vMax = (localtodayfilenum - sftptodayfilenum) <= 0?1: (localtodayfilenum - sftptodayfilenum); //如果vMax为0就设置为1,不然进度条会卡死

            initShowPie();

            removeUnUploadFile(fileBacksPath, fileUpPath);


            MethodInvoker mi = new MethodInvoker(ShowProcessBar);

            this.BeginInvoke(mi);
            Thread.Sleep(100);
            object objReturn = null;

            for (int i = 0; i < vMax; i++)
            {
                objReturn = this.Invoke(this.myIncrease, new object[] { 1, i.ToString() + "\r\n" });
                Thread.Sleep(1000);
            }
        }