예제 #1
0
        public override DataTable GetFilmInfoDatabaseTransferData()
        {
            String     cmdText = String.Format("select * from {0} where disk_desc!=@disk_desc order by id;", "film_info");
            DataTable  dt = CommonDataTable.GetFilmInfoDataTable();
            List <int> continuedMinList = new List <int>();
            List <int> continuedMaxList = new List <int>();
            List <int> subtractList = new List <int>();
            int        continuedMin = -1, continuedMax = -1, subtract = -1, id = -1, preID = -1;

            using (SQLiteConnection sqlCon = new SQLiteConnection(SQLOpenCmdText))
            {
                sqlCon.Open();
                using (SQLiteCommand sqlCmd = new SQLiteCommand(cmdText, sqlCon))
                {
                    sqlCmd.Parameters.AddWithValue("@disk_desc", CommonString.RealOrFake4KDiskName);
                    using (SQLiteDataReader sqlDataReader = sqlCmd.ExecuteReader())
                    {
                        while (sqlDataReader.Read())
                        {
                            DataRow dr = dt.NewRow();
                            for (int i = 0; i < dt.Columns.Count; i++)
                            {
                                dr[i] = sqlDataReader[i];
                            }
                            dt.Rows.Add(dr);

                            preID = id;
                            id    = Convert.ToInt32(dr["id"]);
                            if (continuedMin == -1)
                            {
                                continuedMin = preID;
                            }

                            if (preID != -1 && id - preID > 1)
                            {
                                continuedMax = preID;
                                if (continuedMinList.Count == 0)
                                {
                                    subtract = continuedMin - 1;
                                }
                                else
                                {
                                    subtract = subtractList[subtractList.Count - 1] +
                                               continuedMin - continuedMaxList[continuedMaxList.Count - 1] - 1;
                                }
                                continuedMinList.Add(continuedMin);
                                continuedMaxList.Add(continuedMax);
                                subtractList.Add(subtract);

                                continuedMin = -1;
                            }
                        }

                        continuedMax = id;
                        if (continuedMinList.Count == 0)
                        {
                            subtract = continuedMin - 1;
                        }
                        else
                        {
                            subtract = subtractList[subtractList.Count - 1] +
                                       continuedMin - continuedMaxList[continuedMaxList.Count - 1] - 1;
                        }
                        continuedMinList.Add(continuedMin);
                        continuedMaxList.Add(continuedMax);
                        subtractList.Add(subtract);
                    }
                }
                sqlCon.Close();
            }

            int[] cols = new int[3] {
                0, 14, 15
            };
            int startIndex = 0;

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                id = Convert.ToInt32(dt.Rows[i][0]);
                for (int j = startIndex; j < continuedMaxList.Count; j++)
                {
                    if (id <= continuedMaxList[j])
                    {
                        startIndex = j;
                        break;
                    }
                }
                foreach (int col in cols)
                {
                    int num = Convert.ToInt32(dt.Rows[i][col]);
                    if (num != -1)
                    {
                        dt.Rows[i][col] = num - subtractList[startIndex];
                    }
                }
            }

            return(dt);
        }
예제 #2
0
        public void ScanDisk()
        {
            progressSetView?.Invoke(0, diskPath);

            diskScanNum = CountDisk();

            actualMaxScanLayer = 0;
            bCompleteScan      = true;

            int maxId   = sqlData.GetMaxIdOfFilmInfo();
            int startId = maxId + 1;

            startIdGlobal = startId;
            diskScanIndex = 1;

            DriveInfo driveInfo = new DriveInfo(diskPath);
            DataTable dt        = CommonDataTable.GetFilmInfoDataTable();
            DataRow   dr        = dt.NewRow();

            dr["id"]           = startIdGlobal++;
            dr["name"]         = driveInfo.RootDirectory.Name;
            dr["path"]         = driveInfo.RootDirectory.FullName;
            dr["size"]         = -1;
            dr["create_t"]     = driveInfo.RootDirectory.CreationTime;
            dr["modify_t"]     = driveInfo.RootDirectory.LastWriteTime;
            dr["is_folder"]    = true;
            dr["to_watch"]     = false;
            dr["to_watch_ex"]  = false;
            dr["s_w_t"]        = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
            dr["to_delete"]    = false;
            dr["to_delete_ex"] = false;
            dr["s_d_t"]        = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
            dr["content"]      = String.Empty;
            dr["pid"]          = -1;
            dr["disk_desc"]    = diskDescribe;
            dt.Rows.Add(dr);

            Dictionary <String, int> maxCidDic = new Dictionary <String, int>();

            maxCidDic.Add(driveInfo.RootDirectory.FullName, startIdGlobal - 1);

            ScanAllInFolder(driveInfo.RootDirectory,
                            startIdGlobal - 1, setMaxScanLayer, ref dt, ref maxCidDic);

            progressSetView?.Invoke(96, "写入数据库");

            Dictionary <int, long> sizeDic = new Dictionary <int, long>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (Convert.ToBoolean(dt.Rows[i]["is_folder"]))
                {
                    int maxCid = maxCidDic[dt.Rows[i]["path"].ToString()];
                    dt.Rows[i]["max_cid"] = maxCid;

                    if (bCompleteScan)
                    {
                        sizeDic.Add(i, 0);
                        for (int j = i + 1; j + startId <= maxCid; j++)
                        {
                            if (!Convert.ToBoolean(dt.Rows[j]["is_folder"]))
                            {
                                sizeDic[i] += Helper.CalcSpace(Convert.ToInt64(dt.Rows[j]["size"]));
                            }
                        }
                    }
                }
                else
                {
                    dt.Rows[i]["max_cid"] = dt.Rows[i]["id"];
                }
            }

            // 简略扫描不计算文件夹大小
            if (bCompleteScan)
            {
                foreach (KeyValuePair <int, long> kv in sizeDic)
                {
                    dt.Rows[kv.Key]["size"] = kv.Value;
                }
            }

            sqlData.InsertDataToFilmInfo(dt);

            // 更新磁盘信息
            sqlData.InsertOrUpdateDataToDiskInfo(
                diskDescribe, driveInfo.TotalFreeSpace, driveInfo.TotalSize,
                bCompleteScan, bCompleteScan ? actualMaxScanLayer : setMaxScanLayer);

            progressSetView?.Invoke(100, "完成");
            threadCallback?.Invoke(bCompleteScan);
            progressFinish?.Invoke();
        }
예제 #3
0
        /// <summary>
        /// -1 从网页抓取数据失败,0 从网页抓取数据条数和数据库相同只更新时间
        /// 返回抓取数据条数
        /// </summary>
        /// <param name="strMsg">输出信息,用于显示</param>
        /// <param name="crawlTime">抓取时间</param>
        /// <returns></returns>
        public void Update4KInfo()
        {
            RealOrFake4KWebDataCaptureResult rst = new RealOrFake4KWebDataCaptureResult();

            rst.crawlTime = DateTime.Now;

            string    errMsg  = "";
            DataTable crawlDt = CrawlData(ref errMsg, this.crawlURL);

            if (crawlDt == null || crawlDt.Rows.Count == 0)
            {
                rst.strMsg = string.Format("从网页\n{0}\n抓取数据失败\n{1}",
                                           this.crawlURL, errMsg);
                rst.code = -1;
                this.threadWebDataCaptureCallback?.Invoke(rst);
                this.threadWebDataCaptureFinish?.Invoke();
                return;
            }

            int diskCount = sqlData.CountRowsOfDiskFromFilmInfo(
                CommonString.RealOrFake4KDiskName);

            if ((diskCount - 1) >= crawlDt.Rows.Count)
            {
                // 更新时间
                int affectedCount =
                    sqlData.UpdateDiskRealOrFake4KInModifyTimeFromDiskInfo(
                        rst.crawlTime);
                Debug.Assert(diskCount == affectedCount);

                rst.strMsg = string.Format(
                    "从网页\n{0}\n抓取数据条数 {1} 小于或等于数据库已存在条数 {2}\n不更新数据库信息",
                    this.crawlURL, crawlDt.Rows.Count, diskCount - 1);
                rst.code = 0;
                this.threadWebDataCaptureCallback?.Invoke(rst);
                this.threadWebDataCaptureFinish?.Invoke();
                return;
            }

            sqlData.DeleteByDiskDescribeFromFilmInfo(CommonString.RealOrFake4KDiskName);

            int maxId   = sqlData.GetMaxIdOfFilmInfo();
            int startId = maxId + 1;
            int diskId  = startId;

            DataTable dt = CommonDataTable.GetFilmInfoDataTable();

            DataRow drDisk = dt.NewRow();

            drDisk["id"]           = startId++;
            drDisk["name"]         = CommonString.RealOrFake4KDiskName;
            drDisk["path"]         = "------";
            drDisk["size"]         = -1;
            drDisk["create_t"]     = rst.crawlTime;
            drDisk["modify_t"]     = rst.crawlTime;
            drDisk["is_folder"]    = true;
            drDisk["to_watch"]     = false;
            drDisk["to_watch_ex"]  = false;
            drDisk["s_w_t"]        = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
            drDisk["to_delete"]    = false;
            drDisk["to_delete_ex"] = false;
            drDisk["s_d_t"]        = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
            drDisk["content"]      = String.Empty;
            drDisk["pid"]          = -1;
            drDisk["max_cid"]      = startId - 1 + crawlDt.Rows.Count;
            drDisk["disk_desc"]    = CommonString.RealOrFake4KDiskName;
            dt.Rows.Add(drDisk);

            foreach (DataRow crawlDr in crawlDt.Rows)
            {
                DataRow dr = dt.NewRow();
                dr["id"]   = startId++;
                dr["name"] = string.Join(" | ", crawlDr.ItemArray.Cast <string>().
                                         Where(x => !string.IsNullOrWhiteSpace(x)));
                dr["path"]         = "------";
                dr["size"]         = -1;
                dr["create_t"]     = rst.crawlTime;
                dr["modify_t"]     = rst.crawlTime;
                dr["is_folder"]    = false;
                dr["to_watch"]     = false;
                dr["to_watch_ex"]  = false;
                dr["s_w_t"]        = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
                dr["to_delete"]    = false;
                dr["to_delete_ex"] = false;
                dr["s_d_t"]        = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
                dr["content"]      = String.Empty;
                dr["pid"]          = diskId;
                dr["max_cid"]      = startId - 1;
                dr["disk_desc"]    = CommonString.RealOrFake4KDiskName;
                dt.Rows.Add(dr);
            }

            sqlData.InsertDataToFilmInfo(dt);

            rst.strMsg = string.Format("从网页\n{0}\n抓取数据 {1} 条,已写入数据库",
                                       this.crawlURL, crawlDt.Rows.Count);
            rst.code = crawlDt.Rows.Count;
            this.threadWebDataCaptureCallback?.Invoke(rst);
            this.threadWebDataCaptureFinish?.Invoke();
        }