Ejemplo n.º 1
0
 private void Time_Elapsed(object sender, ElapsedEventArgs e)
 {
     try
     {
         //这里是监测操作
         new ImgsDetectionHelper().Monitor();
     }
     catch (Exception ex)
     {
         ErrorCollectHelper.ErrorLog(ex.ToString());
     }
 }
Ejemplo n.º 2
0
        public MonitoringService()
        {
            InitializeComponent();
            int timelast = 0;

            if (int.TryParse(timelagStr, out timelast))
            {
                if (timelast > 1)
                {
                    time = new Timer(timelast * 60 * 60);
                }
                else
                {
                    time = new Timer(timelag);
                    ErrorCollectHelper.ErrorLog("配置文件错误!timelag配置不符合条件,采取默认1小时内置配置");
                }
            }
            else
            {
                time = new Timer(timelag);
                ErrorCollectHelper.ErrorLog("配置文件错误!timelag配置不符合条件,采取默认1小时内置配置");
            }
        }
        /// <summary>
        /// 图片检测,大小和格式检测
        /// </summary>
        private void DecideImageNorms()
        {
            List <string>        imagesList       = addPathList;
            List <QuestionModel> notmeetImageList = new List <QuestionModel>();
            List <QuestionModel> imageContentList = new List <QuestionModel>();
            bool isAccordWithSize = true;

            if (imagesList.Count < 1)
            {
                return;
            }
            foreach (string imgFileName in imagesList)
            {
                QuestionModel QuestionPath = new QuestionModel();
                using (FileStream fs = new FileStream(imgFileName, FileMode.Open, FileAccess.Read))
                {
                    if (fs.Length < minSize || fs.Length > maxSize)
                    {
                        QuestionPath.error    = "[图片大小 不符规范]";
                        QuestionPath.path     = imgFileName;
                        QuestionPath.fileName = FieldInterception(imgFileName);
                        ErrorCollectHelper.ImgErrorLog(QuestionPath);
                        isAccordWithSize = false;
                    }
                    fs.Close();
                    fs.Dispose();
                }

                if (!isAccordWithSize)
                {
                    CopyFile(QuestionPath);
                    File.Delete(imgFileName);
                    isAccordWithSize = true;
                    continue;
                }

                string extension = Path.GetExtension(imgFileName);
                Image  img       = Image.FromFile(imgFileName);

                if (extension.ToUpper().Equals(".JPG"))
                {
                    if (img.RawFormat.Equals(ImageFormat.Jpeg))
                    {
                        firstPathList.Add(imgFileName);
                        continue;
                    }
                    else if (img.RawFormat.Equals(ImageFormat.Png))
                    {
                        QuestionPath.error = "[图片本质为PNG格式]";
                        QuestionPath.path  = imgFileName;
                    }
                    else if (img.RawFormat.Equals(ImageFormat.Bmp))
                    {
                        QuestionPath.error = "[图片本质为BMP格式]";
                        QuestionPath.path  = imgFileName;
                    }
                    else
                    {
                        QuestionPath.error = "[图片的本质格式未知]";
                        QuestionPath.path  = imgFileName;
                    }
                }
                QuestionPath.fileName = FieldInterception(imgFileName);
                img.Dispose();
                CopyFile(QuestionPath);
                File.Delete(imgFileName);
                ErrorCollectHelper.ImgErrorLog(QuestionPath);
            }
        }