Example #1
0
        /// <summary>
        /// 判断特殊文件夹中是否包含了需要更改的文件夹或者文件
        /// </summary>
        /// <param name="dirInfo"></param>
        /// <param name="parentId"></param>
        /// <param name="userName"></param>
        /// <param name="projectId"></param>
        /// <returns></returns>
        private bool CheckSpecialForderUpload(DirectoryInfo dirInfo, int parentId, string userName, int projectId)
        {
            // 构建对象数据上传到数据库
            ForderDalEx forderDal = new ForderDalEx("FM_");
            // 上传之前判断是否已经存在
            int curForderId = forderDal.GetForderId(this.connection, parentId, dirInfo.Name, userName, projectId);

            if (curForderId <= 0)
            {
                return(true);
            }

            var suvDirs = dirInfo.GetDirectories();

            if (suvDirs != null && suvDirs.Length > 0)
            {
                foreach (var item in suvDirs)
                {
                    try
                    {
                        //递归检查文件夹
                        bool isNeedUpload = CheckSpecialForderUpload(item, curForderId, userName, projectId);;
                        if (isNeedUpload)
                        {
                            return(true);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogHelper.WriteLog("Error", ex.Message + "\r\n" + ex.StackTrace);
                    }
                }
            }

            var files = dirInfo.GetFiles();

            //文件上传
            foreach (var item in files)
            {
                if ((item.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)   //必须进行与运算,因为默认文件是“Hidden”+归档(二进制11)。而Hidden是10.因此与运算才可以判断
                {
                    continue;
                }
                bool isNeedUpload = CheckSpecialFileUploadToDb(item, curForderId, userName, projectId);
                if (isNeedUpload)
                {
                    return(true);
                }
                totalNum++;
                //this.textBox1.AppendText("\r\n文件:" + item.FullName);
                Application.DoEvents();
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// 递归检查文件夹和文件
        /// </summary>
        /// <param name="dirInfo"></param>
        /// <param name="parentId"></param>
        /// <param name="user"></param>
        private void CheckFolderUploadAllToDb(DirectoryInfo dirInfo, int parentId, string userName, int projectId)
        {
            // 构建对象数据上传到数据库
            ForderDalEx forderDal = new ForderDalEx("FM_");
            // 上传之前判断是否已经存在
            int curForderId = forderDal.GetForderId(this.connection, parentId, dirInfo.Name, userName, projectId);

            if (curForderId < 0)
            {
                //文件夹不存在,全部新增
                List <Model.FileModel> fileLists = GetAllFiles(dirInfo);
                foreach (var item in fileLists)
                {
                    AddFileToCache(item.ClientPath, item);
                    AddNeedAllUploadFilesToCache(item.ClientPath, item);
                }
                return;
            }

            var files = dirInfo.GetFiles();

            //文件上传
            foreach (var item in files)
            {
                var file = CheckFileUploadToDb(item, curForderId, userName, projectId);
                if (file != null)
                {
                    AddFileToCache(file.ClientPath, file);
                }
                totalNum++;
                this.textBox1.AppendText("\r\n文件:" + item.FullName);
                Application.DoEvents();
            }
            var suvDirs = dirInfo.GetDirectories();

            if (suvDirs != null && suvDirs.Length > 0)
            {
                foreach (var item in suvDirs)
                {
                    //递归检查文件夹
                    CheckFolderUploadAllToDb(item, curForderId, userName, projectId);
                }
            }
        }
Example #3
0
        /// <summary>
        /// 递归检查文件夹和文件
        /// </summary>
        /// <param name="dirInfo"></param>
        /// <param name="parentId"></param>
        /// <param name="user"></param>
        private void CheckFolderUploadAllToDb(DirectoryInfo dirInfo, int parentId, string userName, int projectId)
        {
            try
            {
                // 构建对象数据上传到数据库
                ForderDalEx forderDal = new ForderDalEx("FM_");
                // 上传之前判断是否已经存在
                int curForderId = forderDal.GetForderId(this.connection, parentId, dirInfo.Name, userName, projectId);
                // 20160515 添加特殊文件夹判断,如果是特殊文件夹全部上传
                SpecialForder(dirInfo, userName, parentId, projectId);

                //bool isSpecialForder = ForderSpecialControl.IsSpecialForder(dirInfo);
                //if (isSpecialForder)
                //{
                //    if (CheckSpecialForderUpload(dirInfo, parentId, userName, projectId))
                //    {
                //        // 如果特殊文件夹需要更新
                //        if (ForderSpecialControl.ZipSpecialForder(dirInfo))
                //        {
                //            string zipFile = Path.Combine(dirInfo.Parent.FullName, dirInfo.Name + ".ztlj");
                //            var file = CheckFileUploadToDb(new FileInfo(zipFile), parentId, userName, projectId);
                //            if (file != null)
                //            {
                //                AddFileToCache(file.ClientPath, file);
                //            }
                //        }
                //    }
                //}

                if (curForderId < 0)
                {
                    //文件夹不存在,全部新增
                    List <Model.FileModel> fileLists = GetAllFiles(dirInfo);
                    foreach (var item in fileLists)
                    {
                        AddFileToCache(item.ClientPath, item);
                        AddNeedAllUploadFilesToCache(item.ClientPath, item);
                    }
                    return;
                }
                else
                {
                    //Common.LogHelper.WriteLog(string.Format("已经存在文件:{0},parentId:{1},dirInfo.Name:{2},projectId:{3} \r\n",dirInfo.Name, parentId, dirInfo.Name, projectId));
                }

                try
                {
                    var files = dirInfo.GetFiles();
                    //文件上传
                    foreach (var item in files)
                    {
                        if ((item.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)   //必须进行与运算,因为默认文件是“Hidden”+归档(二进制11)。而Hidden是10.因此与运算才可以判断
                        {
                            continue;
                        }
                        var file = CheckFileUploadToDb(item, curForderId, userName, projectId);
                        if (file != null)
                        {
                            AddFileToCache(file.ClientPath, file);
                        }
                        totalNum++;
                        //this.textBox1.AppendText("\r\n文件:" + item.FullName);
                        Application.DoEvents();
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog("Error", ex.Message + "\r\n" + ex.StackTrace);
                }

                try
                {
                    var suvDirs = dirInfo.GetDirectories();
                    if (suvDirs != null && suvDirs.Length > 0)
                    {
                        foreach (var item in suvDirs)
                        {
                            if ((item.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)   //必须进行与运算,因为默认文件是“Hidden”+归档(二进制11)。而Hidden是10.因此与运算才可以判断
                            {
                                continue;
                            }
                            // Common.LogHelper.WriteLog(string.Format("文件夹:{0},parentId:{1},dirInfo.Name:{2},projectId:{3} \r\n", item.Name, curForderId, item.FullName, projectId));

                            try
                            {
                                SpecialForder(item, userName, curForderId, projectId);
                                //递归检查文件夹
                                CheckFolderUploadAllToDb(item, curForderId, userName, projectId);
                            }
                            catch (Exception ex)
                            {
                                LogHelper.WriteLog("Error", ex.Message + "\r\n" + ex.StackTrace);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog("Error", ex.Message + "\r\n" + ex.StackTrace);
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("Error", ex.Message + "\r\n" + ex.StackTrace);
            }
        }