Ejemplo n.º 1
0
        /// <summary>
        /// 上传到OSS
        /// </summary>
        /// <param name="ossFilePath">Oss上的图片地址: TempTest/1.jpg</param>
        /// <param name="filePath">D:\test\1.jpg</param>
        /// <param name="itemId">项目ID</param>
        private void OssUpload(string ossFilePath, string filePath, string itemId, ref InfoStatus infoStatus)
        {
            //上传到OSS
            try
            {
                client.PutObject(bucketName, ossFilePath, filePath);
                Console.WriteLine("Put object:{0} succeeded", ossFilePath);
                infoStatus.Summary = "上传成功";
                //修改数据文件
                string imgsrc = _domainOne + ossFilePath
                                .Replace(ItemImages, _itemfiles);
                //文件路径进行加密


                this.DataUpdata(itemId, imgsrc);
                infoStatus.Summary = infoStatus.Summary + ",数据修改成功";
                infoStatus.iStatus = (int)EnumStatus.Ok;
            }
            catch (OssException ex)
            {
                Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
                                  ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);

                MessageBox.Show(string.Format("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
                MessageBox.Show(string.Format("Failed with error info:{0}", ex.Message));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 上传到OSS
        /// </summary>
        /// <param name="ossFilePath">Oss上的图片地址: TempTest/1.jpg</param>
        /// <param name="filePath">D:\test\1.jpg</param>
        /// <param name="itemId">项目ID</param>
        private void OssUpload(string ossFilePath, string filePath, string itemId, ref InfoStatus infoStatus)
        {
            //上传到OSS
            try
            {
                client.PutObject(bucketName, ossFilePath, filePath);
                Console.WriteLine("Put object:{0} succeeded", ossFilePath);
                infoStatus.Summary = "上传成功";
            }
            catch (OssException ex)
            {
                Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
                                  ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);

                MessageBox.Show(string.Format("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
                MessageBox.Show(string.Format("Failed with error info:{0}", ex.Message));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="data"></param>
        /// <param name="stopwatch"></param>
        private void ContentImgUploadToOSS(List <Web_ItemLibrary> data, Stopwatch stopwatch)
        {
            InfoStatus infoStatus = new InfoStatus();

            int i = 0;


            string[] xtAdmin = { "系统用户01", "系统用户02", "系统用户03", "系统用户04", "系统用户05", "系统用户06", "管理员" };

            string filePath = string.Empty;

            foreach (var item in data)
            {
                if (!string.IsNullOrEmpty(item.ItemContentBefore))
                {
                    string[] imgDatas = ContentHelper.GetImgsByContentBefore(item.ItemContentBefore);

                    string proContent = item.ItemContentBefore.ToLower();

                    if (imgDatas.Length > 0 && imgDatas != null)
                    {
                        yxxm++;
                        this.tsslgyxm.Text = $"共计项目:{gjxm},有效项目{yxxm}";

                        this.tsslgj.Text = (int.Parse(this.tsslgj.Text) + imgDatas.Length).ToString();

                        string userName = "******" + (xtAdmin.Contains(item.CreateUserName) ? "部落建筑" : item.CreateUserName);

                        var bytes = Encoding.UTF8.GetBytes(userName);

                        char[] padding           = { '=' };
                        string userNameURLBase64 = Convert.ToBase64String(bytes, Base64FormattingOptions.None).TrimEnd(padding).Replace('+', '-').Replace('/', '_');


                        List <CallbackUploadInfo> callbacks = new List <CallbackUploadInfo>();

                        for (int j = 0; j < imgDatas.Length; j++)
                        {
                            filePath = imgDatas[j].ToLower()
                                       .Replace(_domain, _D)
                                       .Replace(_itemfiles.ToLower(), ItemImages.ToLower())
                                       .Replace('/', '\\').ToLower();

                            //处理文件(将原图上传到oss)

                            if (filePath.Contains(_samll))
                            {
                                filePath = filePath.Replace(_samll, "");
                            }
                            else if (filePath.Contains(_nS))
                            {
                                filePath = filePath.Replace(_nS, "\\");

                                //判断/s/里面的图片是否带 Ori_
                                string tempFilePath = filePath.Replace(filePath.Split('\\').LastOrDefault(), "Ori_" + filePath.Split('\\').LastOrDefault());

                                if (File.Exists(tempFilePath))
                                {
                                    filePath = tempFilePath;
                                }
                            }


                            //判断文件是否存在
                            if (File.Exists(filePath))
                            {
                                var fileInfo = new System.IO.FileInfo(filePath);
                                if (fileInfo.Length >= ImgLeng)
                                {
                                    CompressImg.PicCompress(filePath);
                                }

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

                                //处理带Ori的数据
                                if (ossImgPath.Contains("Ori_".ToLower()))
                                {
                                    ossImgPath = ossImgPath.Replace("Ori_".ToLower(), "");
                                }

                                //暂时注释
                                this.OssUpload(ossImgPath, filePath, item.ItemId, ref infoStatus);

                                //内容数据修改
                                //https://www.pic1.jzbl.com/itemfiles/0d54bf62-e42b-460b-aab4-7e6bd1990221/001cc6d4-bd91-4d22-8ad8-e6fa5be7f294/6367192853011954234817412.jpg?x-oss-process=image/quality,q_90/watermark,image_V2F0ZXJtYXJrL3dhdGVybWFyay5wbmc=,size_30,type_d3F5LXplbmhlaQ,text_QOS4iua1t-azm-WiqOaVsOeggeenkeaKgOaciemZkOWFrOWPuA,color_E94743,shadow_50,order_0,align_2,interval_10,t_90,g_sw,x_20,y_20

                                CallbackUploadInfo callback = new CallbackUploadInfo();

                                string ossPro = string.Empty;
                                if (fileInfo.Length >= 500000)
                                {
                                    ossPro = string.Format(ossProcess, 20, userNameURLBase64);
                                }
                                else if (fileInfo.Length >= 400000)
                                {
                                    ossPro = string.Format(ossProcess, 30, userNameURLBase64);
                                }
                                else if (fileInfo.Length >= 300000)
                                {
                                    ossPro = string.Format(ossProcess, 40, userNameURLBase64);
                                }
                                else if (fileInfo.Length >= 200000)
                                {
                                    ossPro = string.Format(ossProcess, 50, userNameURLBase64);
                                }
                                else if (fileInfo.Length >= 100000)
                                {
                                    ossPro = string.Format(ossProcess, 90, userNameURLBase64);
                                }
                                else
                                {
                                    ossPro = string.Format(ossProcess, 100, userNameURLBase64);
                                }
                                string ossUrl = _domainOne + ossImgPath + ossPro;
                                proContent = proContent.Replace(imgDatas[j].ToLower(), ossUrl);

                                callback.smallImgUrl = _domainOne + ossImgPath + "?x-oss-process=image/quality,q_90/resize,w_400";
                                callback.bigImgUrl   = ossUrl;
                                callbacks.Add(callback);
                            }
                            else
                            {
                                infoStatus.iStatus = (int)EnumStatus.OldFileUnExists;
                                infoStatus.Summary = "本地文件不存在";
                            }
                        }

                        // 修改数据
                        this.DataUpdata(item.ItemId, proContent, callbacks);
                        infoStatus.Summary = infoStatus.Summary + ",【" + imgDatas.Length + "】数据修改成功";
                        infoStatus.iStatus = (int)EnumStatus.Ok;
                    }
                }
                else
                {
                    infoStatus.iStatus = (int)EnumStatus.Unknown;
                    infoStatus.Summary = "项目内容不存在";
                }



                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[] { stopwatch.Elapsed.ToString() });
                }
                else
                {
                    _comm.WriteMessage(2, item.ItemId, filePath, infoStatus.OldPath, infoStatus.iStatus, infoStatus.Summary);
                    _comm.Current(i, item.ItemId);
                    _comm.TimeCost(stopwatch.Elapsed.ToString());
                }
            }
        }
Ejemplo n.º 4
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);
                }
            }
        }
        //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());
                    }
                }
            }
        }