コード例 #1
0
 public FileMoving()
 {
     InitializeComponent();
     //==
     _comm = new Comm(this.dataGV, this.tssldq, this.tsslhs);
 }
コード例 #2
0
        public ProPicUplToOSS()
        {
            InitializeComponent();

            _comm = new Comm(this.dataGV, this.tssldq, this.tsslhs);
        }
コード例 #3
0
        /// <summary>
        /// 移动图片
        /// </summary>
        private void TitleImgCopy(List <Web_ItemLibrary> data, Stopwatch watch)
        {
            Comm comm = new Comm(this.dataGV, this.tssldq, this.tsslhs);

            string summary = string.Empty;
            string oldPath = string.Empty;
            int    operate = (int)EnumOperate.TitleImg;
            string itemId  = string.Empty;
            string newPath = string.Empty;
            int    status  = 0;


            int iExists = 1, iUnExists = 1;

            for (int i = 0; i < data.Count; i++)
            {
                itemId = data[i].ItemId;

                string filePath = data[i].ItemTitleImg.Replace(_domain, _G).Replace('/', '\\').ToLower();

                if (!File.Exists(filePath))
                {
                    iUnExists++;
                    oldPath = filePath;
                    summary = $"路径:{filePath} 状态:< > 文件不存在";
                    status  = (int)EnumStatus.OldFileUnExists;
                }
                else
                {
                    iExists++;
                    // summary = $"路径:{filePath} 状态:< > 待复制";
                    //没有就创建一个基本文件夹

                    string filePathCopy = filePath.Replace(_itemfiles.ToLower(), _itemfilescopy.ToLower());
                    try
                    {
                        //没有文件夹还需要创建
                        //拷贝原始文件
                        string fileName = filePathCopy.Split('\\').LastOrDefault();
                        string basePath = filePathCopy.Replace(fileName, "");
                        if (!Directory.Exists(basePath))
                        {
                            Directory.CreateDirectory(basePath);
                        }

                        //判断文件是否存在
                        if (File.Exists(filePathCopy))
                        {
                            status  = (int)EnumStatus.NewFileExists;
                            oldPath = filePath;
                            newPath = filePathCopy;
                            summary = $"拷贝(新路径原图)文件:{filePath} 到 {filePathCopy} 状态:》文件已存在《";
                        }
                        else
                        {
                            File.Copy(filePath, filePathCopy);

                            status  = (int)EnumStatus.Ok;
                            oldPath = filePath;
                            newPath = filePathCopy;
                            summary = $"拷贝(压缩图片)文件:{filePath} 到 {filePathCopy} 状态:》成功《";
                        }

                        //判断图片是否带_samll
                        if (filePath.Contains(_samll))
                        {
                            //判断图片是否带/i/s/
                            if (filePath.Contains(_nS))
                            {
                                string nSPath     = filePath.Replace(_nS, @"\").Replace(_samll, "");
                                string nSfilePath = filePathCopy.Replace(_nS, @"\").Replace(_samll, "");

                                //判断文件是否存在
                                if (File.Exists(nSfilePath))
                                {
                                    status  = (int)EnumStatus.NewFileExists;
                                    oldPath = nSPath;
                                    newPath = nSfilePath;
                                    summary = $"拷贝(新路径原图)文件:{nSPath} 到 {nSfilePath} 状态:》文件已存在《";
                                }
                                else
                                {
                                    File.Copy(nSPath, nSfilePath);

                                    status  = (int)EnumStatus.Ok;
                                    oldPath = nSPath;
                                    newPath = nSfilePath;
                                    summary = $"拷贝(新路径原图)文件:{nSPath} 到 {nSfilePath} 状态:》成功《";
                                }
                            }
                            else
                            {
                                string nSPath     = filePath.Replace(_samll, "");
                                string nSfilePath = filePathCopy.Replace(_samll, "");
                                //判断文件是否存在
                                if (File.Exists(nSfilePath))
                                {
                                    status  = (int)EnumStatus.NewFileExists;
                                    oldPath = nSPath;
                                    newPath = nSfilePath;
                                    summary = $"拷贝(老路径原图)文件:{nSPath} 到 {nSfilePath} 状态:》文件以存在《";
                                }
                                else
                                {
                                    File.Copy(nSPath, nSfilePath);

                                    status  = (int)EnumStatus.Ok;
                                    oldPath = nSPath;
                                    newPath = nSfilePath;
                                    summary = $"拷贝(老路径原图)文件:{nSPath} 到 {nSfilePath} 状态:》成功《";
                                }
                            }
                        }
                        else
                        {
                            status  = (int)EnumStatus.Unknown;
                            summary = $"封面路径:{filePath} 不包含_small 状态:》未知《";
                        }
                    }
                    catch (Exception ex)
                    {
                        status  = (int)EnumStatus.Error;
                        summary = $"拷贝文件:{filePath} 状态:》失败{ex}";
                    }
                }

                if (this.InvokeRequired)
                {
                    this.Invoke(new DelegateWriteMessage(comm.WriteMessage), new object[] { operate, itemId, oldPath, newPath, status, summary });
                    this.Invoke(new DelegateCurrent(comm.Current), new object[] { i });
                    this.Invoke(new DelegateTimeCost(comm.TimeCost), new object[] { watch.Elapsed.ToString() });
                }
                else
                {
                    comm.WriteMessage(operate, itemId, oldPath, newPath, status, summary);
                    comm.Current(i);
                    comm.TimeCost(watch.Elapsed.ToString());
                }
            }


            summary = $"共计{data.Count}条,本地存在{iExists}条,不存在{iUnExists}条";


            if (this.InvokeRequired)
            {
                this.Invoke(new DelegateWriteMessage(comm.WriteMessage), new object[] { 0, "", "", "", 0, summary });
            }
            else
            {
                comm.WriteMessage(operate, itemId, oldPath, newPath, status, summary);
            }


            if (!watch.IsRunning)
            {
                watch.Stop();
            }
        }
コード例 #4
0
        public BuildingUplOss()
        {
            InitializeComponent();

            _comm = new Comm(this.dataGV, this.tssldq, this.tsslhs);
        }
コード例 #5
0
        /// <summary>
        /// 处理数据
        /// </summary>
        /// <param name="data">需要处理的数据</param>
        /// <param name="watch">计时器</param>
        private void DataProcess(List <Web_ItemLibrary> data, Stopwatch watch)
        {
            Comm comm = new Comm(this.dataGV, this.tssldq, this.tsslhs);

            InfoStatus infoStatus = new InfoStatus();

            int  i          = 0;
            long fileLength = 0;

            foreach (var item in data)
            {
                i++;

                string filePath = string.Empty;
                if (!item.ItemFilePath.Contains(_domainOne))
                {
                    filePath = DESEncrypt.Decrypt(item.ItemFilePath);

                    filePath = filePath.Replace(_domain, _D).Replace('/', '\\');
                    filePath = filePath.Split('&').FirstOrDefault().ToLower();

                    //D:\ItemImages\0d54bf62-e42b-460b-aab4-7e6bd1990221\76d408e5-2122-4e0f-b496-2d907186cbf7\6367830614380614892523145.rar
                    filePath = filePath.Replace(_itemfiles.ToLower(), ItemImages.ToLower());

                    if (File.Exists(filePath))
                    {
                        var fileInfo = new System.IO.FileInfo(filePath);
                        //fileLength = fileLength + fileInfo.Length;
                        fileLength += fileInfo.Length;


                        string ossImgPath = filePath
                                            .Replace(ItemImages.ToLower(), _itemfiles.ToLower())
                                            .Remove(0, 3)
                                            .Replace('\\', '/').ToLower();

                        this.OssUpload(ossImgPath, filePath, item.ItemId, ref infoStatus);
                    }
                    else
                    {
                        infoStatus.iStatus = (int)EnumStatus.OldFileUnExists;
                        infoStatus.Summary = "本地文件不存在";
                        //写入日志
                        Console.WriteLine("没有显示");
                    }
                }
                else
                {
                    infoStatus.iStatus = (int)EnumStatus.NewFileExists;
                    infoStatus.Summary = "数据已经传输出[" + item.ItemFilePath + "]";
                    //写入日志
                    Console.WriteLine("没有显示");
                }


                if (this.InvokeRequired)
                {
                    this.Invoke(new DelegateWriteMessage(comm.WriteMessage), new object[] { 2, item.ItemId, filePath, infoStatus.OldPath, infoStatus.iStatus, infoStatus.Summary });
                    this.Invoke(new DelegateCurrent(comm.Current), new object[] { i, item.ItemId });
                    this.Invoke(new DelegateTimeCost(comm.TimeCost), new object[] { watch.Elapsed.ToString() });
                    this.Invoke(new DelegateTFileSize(TFileSize), new object[] { fileLength });
                }
                else
                {
                    comm.WriteMessage(2, item.ItemId, filePath, infoStatus.OldPath, infoStatus.iStatus, infoStatus.Summary);
                    comm.Current(i, item.ItemId);
                    comm.TimeCost(watch.Elapsed.ToString());
                    this.TFileSize(fileLength);
                }
            }
        }
コード例 #6
0
        //1,将图片上传 (只上传大图【原图】)
        //  1.判断本地图片是否存在
        //  2.判断服务器文件是否存在

        /// <summary>
        /// 封面图片上传
        /// </summary>
        /// <param name="data">数据源</param>
        /// <param name="watch"></param>
        private void TitleImgUpLoad(List <Web_ItemLibrary> data, Stopwatch watch)
        {
            Comm comm = new Comm(this.dataGV, this.tssldq, this.tsslhs);

            int i = 0;

            InfoStatus infoStatus = new InfoStatus();

            foreach (var item in data)
            {
                i++;

                if (!string.IsNullOrEmpty(item.ItemTitleImg))
                {
                    //https://www.pic.jzbl.com/ItemFiles/d5b4fbaa-40a0-4145-a119-88af91c3bf8f/2019-11-28/5a4962f9-a138-4db7-b327-bd25ed7b6023/i/s/1574935666_small.jpg
                    //https://www.pic.jzbl.com/ItemFiles/8b166b7c-d1cf-47b2-806a-3a81ee78b6e3/91fbcff0-304c-4fa6-b3d7-3f6662cd609a/6368089569228158431363684_small.jpg
                    string filePath = item.ItemTitleImg.Replace(_domain, _D)
                                      .Replace(_itemfiles, ItemImages);

                    //if (!File.Exists(filePath))
                    //{
                    //    continue;
                    //}

                    string imgPath = string.Empty;
                    try
                    {
                        imgPath = filePath;

                        //判断 图片是否带/i/s/ 并且 图片是否带_samll
                        if (filePath.Contains(_nS))
                        {
                            imgPath = filePath.Replace(_nS, @"/");
                        }
                        // 否则就全是
                        imgPath = imgPath.Replace(_samll, "").Replace('/', '\\');

                        //判断文件是否存在  https://www.pic.jzbl.com/ItemFiles/8b166b7c-d1cf-47b2-806a-3a81ee78b6e3/91fbcff0-304c-4fa6-b3d7-3f6662cd609a/6368089569228158431363684_small.jpg
                        if (File.Exists(imgPath))
                        {
                            string ossImgPath = imgPath
                                                .Replace(_D, "")
                                                .Replace(ItemImages, _itemfiles).Remove(0, 1)
                                                .Replace('\\', '/').ToLower();
                            //进行上传操作
                            this.OssUpload(ossImgPath, imgPath, item.ItemId, ref infoStatus);
                        }
                        else
                        {
                            infoStatus.Summary = "本地文件不存在";
                            //写入日志
                            Console.WriteLine("没有显示");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }


                    //信息输出

                    if (this.InvokeRequired)
                    {
                        this.Invoke(new DelegateWriteMessage(comm.WriteMessage), new object[] { 1, item.ItemId, item.ItemTitleImg, imgPath, infoStatus.iStatus, infoStatus.Summary });
                        this.Invoke(new DelegateCurrent(comm.Current), new object[] { i, item.ItemId });

                        this.Invoke(new DelegateTimeCost(comm.TimeCost), new object[] { watch.Elapsed.ToString() });
                    }
                    else
                    {
                        comm.WriteMessage(1, item.ItemId, item.ItemTitleImg, imgPath, infoStatus.iStatus, infoStatus.Summary);
                        comm.Current(i, item.ItemId);
                        comm.TimeCost(watch.Elapsed.ToString());
                    }
                }
            }
        }