コード例 #1
0
        void AnalysisFile(string file, CancellationToken ct, ManualResetEvent pauseEvent, IProgress <ScanProgress> progress, int num, int tcount, bool onlyImage)
        {
            log.Info("Scan: " + file);
            Exception classifyException;

            PornDatabase.PornItemType itype = PornDatabase.PornItemType.Undefined;
            if (onlyImage || ActiveFileMonitor.IsFileExtWith(file, ActiveFileMonitor.ImageExts))
            {
                if (PornClassifier.Instance.Classify(file, out classifyException) == PornClassifier.ImageType.P**n)
                {
                    itype = PornDatabase.PornItemType.LocalImage;
                }
            }
            else if (ActiveFileMonitor.IsFileExtWith(file, ActiveFileMonitor.VideoExts))
            {
                if (PornClassifier.Instance.ClassifyVideoFile(file, out classifyException))
                {
                    itype = PornDatabase.PornItemType.LocalVideo;
                }
            }
            if (progress != null)
            {
                ScanProgress npro = new ScanProgress();
                npro.Percentage     = PercentageOffset + PercentageRatio * num / tcount;
                npro.TargetFilePath = file;
                npro.Description    = "正在扫描:" + npro.TargetFilePath;
                npro.ItemType       = itype;
                progress.Report(npro);
            }
            pauseEvent.WaitOne();
            if (ct.IsCancellationRequested)
            {
                ct.ThrowIfCancellationRequested();
            }
        }
コード例 #2
0
 void TargetProcessedProgressOnProgressChanged(object sender, PornDatabase.PornItemType e)
 {
     TargetProcessedNum++;
     analysisItemsNumLabel.Text = TargetProcessedNum.ToString();
     if (e != PornDatabase.PornItemType.Undefined)
     {
         log.Info("Show analysisview button!");
         PornDetectedNum++;
         string cont = "新检测到{0}个不良项目!";
         analysisResultDescLabel.Text    = string.Format(cont, PornDetectedNum);
         analysisResultDescLabel.Visible = true;
         analysisResultViewBtn.Visible   = true;
     }
     log.Info("Target Processed Progress, Item Type: " + e.ToString() + " Total Num: " + TargetProcessedNum + " P**n Num: " + PornDetectedNum);
 }
コード例 #3
0
        public void AddRow(string info, PornDatabase.PornItemType itype, PornDatabase.PornItemStatus status)
        {
            DataRow dr = _pornItemDataTable.NewRow();

            if (!_viewProtectionLogs)
            {
                dr.SetField <bool>("checked", _ifCheckAll);
            }
            dr.SetField <string>("info", info);
            //dr.SetField<string>("desc", "12");
            dr.SetField <PornDatabase.PornItemStatus>("status", status);
            dr.SetField <PornDatabase.PornItemType>("item_type", itype);
            dr.SetField <DateTime>("created_at", DateTime.Now);
            _pornItemDataTable.Rows.Add(dr);
            if (_showLastestItem)
            {
                try { _dataGridView.CurrentCell = _dataGridView.Rows[0].Cells["info"]; }
                catch (Exception exp) { log.Error(exp.ToString()); }
            }
        }
コード例 #4
0
        void PornDataGridViewOnCellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.RowIndex < 0 || e.ColumnIndex < 0)
            {
                return;
            }
            DataGridView dgView = (DataGridView)(sender);

            // no need to add TaskTime...
            if (e.ColumnIndex == dgView.Columns["created_at"].Index)
            {
                try
                {
                    DateTime dsutc = (DateTime)e.Value;
                    e.Value = TimeZoneInfo.ConvertTimeFromUtc(dsutc, TimeZoneInfo.Local);
                }
                catch (Exception ex)
                {
                    log.Equals(ex.ToString());
                }
            }
            else if (e.ColumnIndex == dgView.Columns["item_type"].Index)
            {
                PornDatabase.PornItemType type = (PornDatabase.PornItemType)(Int64) e.Value;
                if (type == PornDatabase.PornItemType.Undefined)
                {
                    e.Value = "未知";
                }
                else if (type == PornDatabase.PornItemType.PornDomain)
                {
                    e.Value = "不良网站";
                }
                else if (type == PornDatabase.PornItemType.NetworkImage)
                {
                    e.Value = "网络图片";
                }
                else if (type == PornDatabase.PornItemType.NetworkVideo)
                {
                    e.Value = "网络视频";
                }
                else if (type == PornDatabase.PornItemType.LocalImage)
                {
                    e.Value = "本地图片";
                }
                else if (type == PornDatabase.PornItemType.LocalVideo)
                {
                    e.Value = "本地视频";
                }
            }
            else if (e.ColumnIndex == dgView.Columns["status"].Index)
            {
                PornDatabase.PornItemStatus status = (PornDatabase.PornItemStatus)(Int64) e.Value;
                if (status == PornDatabase.PornItemStatus.Undefined)
                {
                    e.Value = "未知";
                }
                else if (status == PornDatabase.PornItemStatus.Normal)
                {
                    e.Value = "已屏蔽";
                }
                else if (status == PornDatabase.PornItemStatus.Trusted)
                {
                    e.Value = "已信任";
                }
            }
        }
コード例 #5
0
        void _dataGridViewOnSelectionChanged(object sender, EventArgs e)
        {
            //log.Info(sender.ToString());
            DataRowView currentRow = (DataRowView)_pornItemBindingSource.Current;

            if (currentRow != null)
            {
                PornDatabase.PornItemType type = (PornDatabase.PornItemType)currentRow.Row.Field <Int64>("item_type");
                string info = currentRow.Row.Field <string>("info");
                string fname;
                if (type == PornDatabase.PornItemType.LocalImage)
                //|| type == PornDatabase.PornItemType.LocalVideo)
                {
                    //_previewPictureBox.ImageLocation = info;
                    fname = info;
                }
                else if (type == PornDatabase.PornItemType.NetworkImage)
                {
                    string filename = Program.AppLocalDir + Properties.Settings.Default.imagesDir + "\\" + HttpUtility.UrlEncode(info);
                    //_previewPictureBox.ImageLocation = filename;
                    fname = filename;
                }
                else
                {
                    //_previewPictureBox.ImageLocation = null;
                    fname = null;
                }
                log.Info("PornPreview image location: " + fname);
                //_previewPictureBox.ImageLocation = fname;
                //这里没有直接设置ImageLocation,因为发现如果文件名为httpurl编码形式,在文件拷贝以后无法显示
                try
                {
                    DisposeCurrentImage();
                    if (fname != null)
                    {
                        using (Image x = Image.FromFile(fname))
                        {
                            //通过拷贝构造函数生成新的bitmap,可以解除对文件的锁定
                            //这样正在打开的文件也可以被删除了
                            _previewPictureBox.Image = new Bitmap(x);
                            x.Dispose();
                        }
                    }
                    else
                    {
                        _previewPictureBox.Image = null;
                    }
                }
                catch (Exception ex)
                {
                    log.Info(ex.ToString());
                    _previewPictureBox.Image = null;
                }
            }
            //如果为空,要将picturebox置空
            else
            {
                _previewPictureBox.ImageLocation = null;
                _previewPictureBox.Image         = null;
            }
            //if (data_grid_view_porn_pics.SelectedRows.Count > 0)
            //{
            //    string value2 = data_grid_view_porn_pics.SelectedRows[0].Cells["url"].Value.ToString();
            //    string filename = Properties.Settings.Default.imagesDir + "\\" + HttpUtility.UrlEncode(value2);
            //    picture_box.ImageLocation = filename;
            //    picture_box.SizeMode = PictureBoxSizeMode.Zoom;
            //}
        }
コード例 #6
0
        void BackgroundWorker(CancellationToken ct, IProgress <PornActiveFile> progress)
        {
            Dictionary <string, PornDatabase.PornItemType> md5Set = new Dictionary <string, PornDatabase.PornItemType>();
            //Dictionary<byte[], int> md5Set = new Dictionary<byte[], int>();
            Dictionary <string, int> fileSet = new Dictionary <string, int>();

            while (true)
            {
                ct.ThrowIfCancellationRequested();
                if (_taskQueue.IsEmpty)
                {
                    _newFileEvent.WaitOne(1000);
                }
                string nfile;
                while (_taskQueue.TryDequeue(out nfile))
                {
                    fileSet[nfile] = 0;
                }
                List <string> tobeDeleted = new List <string>();
                foreach (string key in fileSet.Keys.ToList())
                {
                    try
                    {
                        log.Info("Process: " + key);
                        FileAttributes attr = File.GetAttributes(key);
                        if (!attr.HasFlag(FileAttributes.Directory))
                        {
                            FileInfo finfo = new FileInfo(key);
                            if (!_fileProcessed.ContainsKey(key) || _fileProcessed[key] != finfo.Length)
                            {
                                //string shash = GetMd5Hash(_md5hash, File.ReadAllBytes(key));
                                //log.Info("\tHash: " + shash + " Time: " + fileSet[key]);
                                //PornClassifier.ImageType itype;
                                PornDatabase.PornItemType itype = PornDatabase.PornItemType.Undefined;
                                //if (md5Set.ContainsKey(shash))
                                //{
                                //    itype = md5Set[shash];
                                //}
                                //else
                                {
                                    Exception classifyException;
                                    if (IsFileExtWith(key, ImageExts))
                                    {
                                        var t = PornClassifier.Instance.Classify(key, out classifyException);
                                        if (classifyException != null)
                                        {
                                            throw classifyException;
                                        }
                                        else if (t == PornClassifier.ImageType.P**n)
                                        {
                                            itype = PornDatabase.PornItemType.LocalImage;
                                            //md5Set[shash] = PornDatabase.PornItemType.LocalImage;
                                        }
                                    }
                                    else if (IsFileExtWith(key, VideoExts))
                                    {
                                        var t = PornClassifier.Instance.ClassifyVideoFile(key, out classifyException);
                                        if (classifyException != null)
                                        {
                                            throw classifyException;
                                        }
                                        else if (t)
                                        {
                                            itype = PornDatabase.PornItemType.LocalVideo;
                                            //md5Set[shash] = PornDatabase.PornItemType.LocalVideo;
                                        }
                                    }
                                }
                                IProgress <PornDatabase.PornItemType> ip = MainForm.Instance.TargetProcessedProgress as IProgress <PornDatabase.PornItemType>;
                                if (itype != PornDatabase.PornItemType.Undefined)
                                {
                                    log.Info("Detect Active File: " + key);
                                    PornDatabase pdb = new PornDatabase();
                                    pdb.InsertPornFile(key, itype);
                                    ip.Report(itype);
                                }
                                else
                                {
                                    ip.Report(PornDatabase.PornItemType.Undefined);
                                }

                                _fileProcessed[key] = (int)finfo.Length;
                            }
                            else
                            {
                                log.Info("\tIgnore same file: " + key);
                            }
                        }
                        tobeDeleted.Add(key);
                    }
                    //catch (System.IO.IOException ioex)
                    catch (Exception ex)
                    {
                        int value = fileSet[key];
                        if (value + 1 > 10)
                        {
                            tobeDeleted.Add(key);
                            log.Info("Delete: " + key);
                        }
                        else
                        {
                            fileSet[key] = value + 1;
                        }
                        log.Info(ex.ToString());
                    }
                    //{
                    //    log.Error(ex.ToString());
                    //}
                }
                foreach (string del in tobeDeleted)
                {
                    fileSet.Remove(del);
                }
            }
        }