コード例 #1
0
        //public LogReporter logrpt = null;

        public void Convert(string strSrcDir, string strDstDir, DateTime startTime = default(DateTime))
        {
            // 创建目录
            if (!Directory.Exists(strDstDir))
            {
                Directory.CreateDirectory(strDstDir);
            }

            string progName = strDstDir + "\\prog.mq";

            if (!File.Exists(progName))
            {
                _logger.Error(progName + "文件不存在");
            }

            // 读取目录下已经存在的数据
            _prgMq = new ProgMqFile(progName, startTime);

            string[]      tmpdirlist = Directory.GetDirectories(strSrcDir);
            List <string> dirlist    = new List <string>(tmpdirlist);

            dirlist.Sort();
            dirlist.Reverse();

            int      month   = 0;
            DateTime lastDay = default(DateTime);

            foreach (string strDir in dirlist)
            {
                DateTime day;
                string   strshort = strDir.Substring(strDir.Length - 8);
                if (!DateTime.TryParseExact(strshort, "yyyyMMdd", null, System.Globalization.DateTimeStyles.None, out day))
                {
                    continue;
                }

                if (month != day.Month)
                {
                    SaveFuture(strDstDir, lastDay);
                    month = day.Month;
                    _logger.Info("进度: " + day.ToString("yyyy-MM-dd"));
                    //if (logrpt != null)
                    //    logrpt.Print("进度: " + day.ToString("yyyy-MM-dd"));
                }

                lastDay = day;

                if (ConvertDay(strDir, day))
                {
                    break;
                }
            }

            Save(strDstDir);
            SaveFuture(strDstDir, lastDay);

            foreach (string futureid in _beginlist.Keys)
            {
                DateTime begintime = _prgMq.BeginTime(futureid);

                DateTime endtime = _prgMq.EndTime(futureid);

                if (begintime == default(DateTime))
                {
                    begintime = _beginlist[futureid];
                }
                else if (begintime > _beginlist[futureid])
                {
                    begintime = _beginlist[futureid];
                }

                if (endtime == default(DateTime))
                {
                    endtime = _endlist[futureid];
                }
                else if (endtime < _endlist[futureid])
                {
                    endtime = _endlist[futureid];
                }

                _prgMq.Add(futureid, begintime, endtime);
            }

            _prgMq.Save(strDstDir + "\\prog.mq");

            _logger.Info("完成T2D");
            //if (logrpt != null)
            //    logrpt.Print("完成T2D");
        }