Exemple #1
0
        /// <summary>
        /// 数据显示及保存
        /// </summary>
        /// <param name="operate">操作事件</param>
        /// <param name="itemId">项目id</param>
        /// <param name="oldPath">老图路径</param>
        /// <param name="newPath">新图路径</param>
        /// <param name="status">状态</param>
        /// <param name="summary">摘要</param>
        public void WriteMessage(int operate, string itemId, string oldPath, string newPath, int status, string summary)
        {
            SnowflakeIdWorker snowflakeIdWorker = new SnowflakeIdWorker(1, 1);
            Data_TempCopy     tempCopyData      = new Data_TempCopy();

            tempCopyData.Id         = snowflakeIdWorker.NextId().ToString();
            tempCopyData.OperateKey = _OperateKey;
            tempCopyData.Operate    = operate;
            tempCopyData.ItemId     = itemId;
            tempCopyData.OldPath    = oldPath;
            tempCopyData.NewPath    = newPath;
            tempCopyData.Status     = status;
            tempCopyData.Summary    = summary;
            tempCopyData.CreateDate = DateTime.Now;

            if (status == 0)
            {
                int index = this._dataGV.Rows.Add();
                this._dataGV.Rows[index].Cells[0].Value = tempCopyData.Id;
                this._dataGV.Rows[index].Cells[1].Value = tempCopyData.OperateKey;
                this._dataGV.Rows[index].Cells[2].Value = OperatebyEmun((int)tempCopyData.Operate);
                this._dataGV.Rows[index].Cells[3].Value = tempCopyData.ItemId;
                this._dataGV.Rows[index].Cells[4].Value = tempCopyData.OldPath;
                this._dataGV.Rows[index].Cells[5].Value = tempCopyData.NewPath;
                this._dataGV.Rows[index].Cells[6].Value = StatusbyEmun((int)tempCopyData.Status);
                this._dataGV.Rows[index].Cells[7].Value = tempCopyData.Summary;
                this._dataGV.Rows[index].Cells[8].Value = tempCopyData.CreateDate;
            }
            else
            {
                using (var context = new DataModelEntities())
                {
                    context.Data_TempCopy.Add(tempCopyData);

                    int index = this._dataGV.Rows.Add();
                    this._dataGV.Rows[index].Cells[0].Value = tempCopyData.Id;
                    this._dataGV.Rows[index].Cells[1].Value = tempCopyData.OperateKey;
                    this._dataGV.Rows[index].Cells[2].Value = OperatebyEmun((int)tempCopyData.Operate);
                    this._dataGV.Rows[index].Cells[3].Value = tempCopyData.ItemId;
                    this._dataGV.Rows[index].Cells[4].Value = tempCopyData.OldPath;
                    this._dataGV.Rows[index].Cells[5].Value = tempCopyData.NewPath;
                    this._dataGV.Rows[index].Cells[6].Value = StatusbyEmun((int)tempCopyData.Status);
                    this._dataGV.Rows[index].Cells[7].Value = tempCopyData.Summary;
                    this._dataGV.Rows[index].Cells[8].Value = tempCopyData.CreateDate;

                    //context.SaveChangesAsync();
                    context.SaveChanges();
                }
            }

            this._dataGV.FirstDisplayedScrollingRowIndex = this._dataGV.Rows[this._dataGV.Rows.Count - 1].Index;
        }
Exemple #2
0
        /// <summary>
        /// 当前项目
        /// </summary>
        /// <param name="itemid">项目ID</param>
        /// <param name="fileSrcStr">加密的文件路径</param>
        public void DataUpdata(string itemid, string fileSrcStr)
        {
            try
            {
                using (var context = new DataModelEntities())
                {
                    var itemData = context.Web_ItemLibrary.FirstOrDefault(o => o.ItemId.Equals(itemid));
                    if (itemData != null)
                    {
                        itemData.ItemFilePath = fileSrcStr;

                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
                MessageBox.Show(string.Format("保存数据出错!{0}", ex.Message));
            }
        }
        private void imgTextResourceObj(List <Web_UserBuildingCircle> data)
        {
            //var domainData = data.Where(o => !string.IsNullOrEmpty(o.ResourceObj) && o.FirstTitleImg.Contains(_domainOne)).ToList();

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

            foreach (var item in data)
            {
                CallbackUploadInfo callbackUploadInfo = new CallbackUploadInfo();

                string url = item.FirstTitleImg.Split('?').FirstOrDefault();

                callbackUploadInfo.smallImgUrl = url + smallImg;
                callbackUploadInfo.bigImgUrl   = url + string.Format(bigImg, 90);

                callbackUploadInfos.Add(callbackUploadInfo);

                // 保存数据
                try
                {
                    using (var context = new DataModelEntities())
                    {
                        var itemData = context.Web_UserBuildingCircle.FirstOrDefault(o => o.TalkId.Equals(item.TalkId));
                        if (itemData != null)
                        {
                            itemData.ResourceObj = callbackUploadInfos.Count == 0 ? null : callbackUploadInfos.ToJson();

                            itemData.TalkTitle = itemData.TalkTitle.Equals("NULL") ? null : itemData.TalkTitle;

                            context.SaveChanges();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Failed with error info: {0}", ex.Message);
                    MessageBox.Show(string.Format("保存数据出错!{0}", ex.Message));
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// 当前项目
        /// </summary>
        /// <param name="itemid">项目ID</param>
        /// <param name="itemContent">项目内容数据</param>
        /// <param name="callback">9宫格对象</param>
        public void DataUpdata(string itemid, string itemContent, List <CallbackUploadInfo> callback)
        {
            try
            {
                using (var context = new DataModelEntities())
                {
                    var itemData = context.Web_ItemLibrary.FirstOrDefault(o => o.ItemId.Equals(itemid));
                    if (itemData != null)
                    {
                        itemData.ItemContentBefore = itemContent;
                        itemData.ResourceObj       = callback.Count == 0 ? null : callback.ToJson();

                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
                MessageBox.Show(string.Format("保存数据出错!{0}", ex.Message));
            }
        }
        private void videoPro(List <Web_UserBuildingCircle> data)
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();

            //过来只有在服务器上的数据https://www.pic.jzbl.com
            var domainData = data.Where(o => o.FirstTitleImg.Contains(_domain)).ToList();

            string domainOSSFirstTitlet = string.Empty;

            foreach (var item in domainData)
            {
                //处理封面图片数据
                string filePath = item.FirstTitleImg.ToLower()
                                  .Replace(_domain, _D)
                                  .Replace(_itemfiles.ToLower(), ItemImages.ToLower())
                                  .Replace('/', '\\').ToLower();

                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, ref infoStatus);

                    domainOSSFirstTitlet = _domainOne + ossImgPath + firstTitletImg;
                }


                //处理 对象数据
                var obj = item.ResourceObj.ToList <CallbackUploadInfo>();


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

                if (obj != null)
                {
                    foreach (var itemRes in obj)
                    {
                        string filePathRes = itemRes.smallImgUrl
                                             .Replace(_domain, _D)
                                             .Replace(_itemfiles.ToLower(), ItemImages.ToLower())
                                             .Replace('/', '\\').ToLower();

                        if (filePathRes.Contains(_nS))
                        {
                            filePathRes = filePathRes.Replace(_nS, "\\");

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

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

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

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

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

                                this.OssUpload(ossImgPath, filePathRes, ref infoStatus);

                                CallbackUploadInfo callback = new CallbackUploadInfo();

                                string ossPro = string.Empty;
                                if (fileInfo.Length >= 500000)
                                {
                                    ossPro = string.Format(bigImg, 20);
                                }
                                else if (fileInfo.Length >= 400000)
                                {
                                    ossPro = string.Format(bigImg, 30);
                                }
                                else if (fileInfo.Length >= 300000)
                                {
                                    ossPro = string.Format(bigImg, 40);
                                }
                                else if (fileInfo.Length >= 200000)
                                {
                                    ossPro = string.Format(bigImg, 50);
                                }
                                else if (fileInfo.Length >= 100000)
                                {
                                    ossPro = string.Format(bigImg, 90);
                                }
                                else
                                {
                                    ossPro = string.Format(bigImg, 100);
                                }

                                string ossUrl = _domainOne + ossImgPath + ossPro;

                                callback.smallImgUrl = _domainOne + ossImgPath + smallImg;
                                callback.bigImgUrl   = ossUrl;
                                callback.fileName    = itemRes.fileName;

                                callbackUploadInfos.Add(callback);
                            }
                        }
                    }
                }



                // 保存数据
                try
                {
                    using (var context = new DataModelEntities())
                    {
                        var itemData = context.Web_UserBuildingCircle.FirstOrDefault(o => o.TalkId.Equals(item.TalkId));
                        if (itemData != null)
                        {
                            itemData.FirstTitleImg = domainOSSFirstTitlet;
                            itemData.ResourceObj   = callbackUploadInfos.Count == 0 ? null : callbackUploadInfos.ToJson();

                            itemData.TalkContent = string.IsNullOrEmpty(itemData.TalkContent.Trim()) ? itemData.TalkTitle : itemData.TalkContent;
                            itemData.TalkTitle   = string.IsNullOrEmpty(itemData.TalkTitle) ? null : "NULL";

                            context.SaveChanges();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Failed with error info: {0}", ex.Message);
                    MessageBox.Show(string.Format("保存数据出错!{0}", ex.Message));
                }



                if (this.InvokeRequired)
                {
                    this.Invoke(new DelegateWriteMessage(_comm.WriteMessage), new object[] { 2, item.TalkId, filePath, infoStatus.OldPath, infoStatus.iStatus, infoStatus.Summary });
                    this.Invoke(new DelegateCurrent(_comm.Current), new object[] { 1, item.TalkId });
                    this.Invoke(new DelegateTimeCost(_comm.TimeCost), new object[] { watch.Elapsed.ToString() });
                }
                else
                {
                    _comm.WriteMessage(2, item.TalkId, filePath, infoStatus.OldPath, infoStatus.iStatus, infoStatus.Summary);
                    _comm.Current(1, item.TalkId);
                    _comm.TimeCost(watch.Elapsed.ToString());
                }
            }
        }
        private void imgTextPro(List <Web_UserBuildingCircle> data)
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();

            //过来只有在服务器上的数据
            var domainData = data.Where(o => !string.IsNullOrEmpty(o.FirstTitleImg) && o.FirstTitleImg.Contains(_domain)).ToList();

            string domainOSSFirstTitlet = string.Empty;

            foreach (var item in domainData)
            {
                infoStatus.Summary = "处理再" + _domain + "域名数据";

                //处理封面图片数据
                string filePath = item.FirstTitleImg.ToLower()
                                  .Replace(_domain, _D)
                                  .Replace(_itemfiles.ToLower(), ItemImages.ToLower())
                                  .Replace('/', '\\').ToLower();

                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, ref infoStatus);

                    domainOSSFirstTitlet = _domainOne + ossImgPath + firstTitletImg;
                }


                //处理 对象数据
                var obj = item.ResourceObj.ToList <CallbackUploadInfo>();


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

                if (obj != null)
                {
                    foreach (var itemRes in obj)
                    {
                        string filePathRes = itemRes.smallImgUrl
                                             .Replace(_domain, _D)
                                             .Replace(_itemfiles.ToLower(), ItemImages.ToLower())
                                             .Replace('/', '\\').ToLower();

                        if (filePathRes.Contains(_nS))
                        {
                            filePathRes = filePathRes.Replace(_nS, "\\");

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

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

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

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

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

                                this.OssUpload(ossImgPath, filePathRes, ref infoStatus);

                                CallbackUploadInfo callback = new CallbackUploadInfo();

                                string ossPro = string.Empty;
                                if (fileInfo.Length >= 500000)
                                {
                                    ossPro = string.Format(bigImg, 20);
                                }
                                else if (fileInfo.Length >= 400000)
                                {
                                    ossPro = string.Format(bigImg, 30);
                                }
                                else if (fileInfo.Length >= 300000)
                                {
                                    ossPro = string.Format(bigImg, 40);
                                }
                                else if (fileInfo.Length >= 200000)
                                {
                                    ossPro = string.Format(bigImg, 50);
                                }
                                else if (fileInfo.Length >= 100000)
                                {
                                    ossPro = string.Format(bigImg, 90);
                                }
                                else
                                {
                                    ossPro = string.Format(bigImg, 100);
                                }

                                string ossUrl = _domainOne + ossImgPath + ossPro;

                                callback.smallImgUrl = _domainOne + ossImgPath + "?x-oss-process=image/quality,q_90/resize,w_400";
                                callback.bigImgUrl   = ossUrl;
                                callback.fileName    = itemRes.fileName;

                                callbackUploadInfos.Add(callback);
                            }
                        }
                    }
                }



                // 保存数据
                try
                {
                    using (var context = new DataModelEntities())
                    {
                        var itemData = context.Web_UserBuildingCircle.FirstOrDefault(o => o.TalkId.Equals(item.TalkId));
                        if (itemData != null)
                        {
                            itemData.FirstTitleImg = domainOSSFirstTitlet;
                            itemData.ResourceObj   = callbackUploadInfos.Count == 0 ? null : callbackUploadInfos.ToJson();

                            itemData.TalkContent = string.IsNullOrEmpty(itemData.TalkContent.Trim()) ? itemData.TalkTitle : itemData.TalkContent;
                            itemData.TalkTitle   = string.IsNullOrEmpty(itemData.TalkTitle) ? null : "NULL";

                            context.SaveChanges();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Failed with error info: {0}", ex.Message);
                    MessageBox.Show(string.Format("保存数据出错!{0}", ex.Message));
                }



                if (this.InvokeRequired)
                {
                    this.Invoke(new DelegateWriteMessage(_comm.WriteMessage), new object[] { 2, item.TalkId, filePath, infoStatus.OldPath, infoStatus.iStatus, infoStatus.Summary });
                    this.Invoke(new DelegateCurrent(_comm.Current), new object[] { 1, item.TalkId });
                    this.Invoke(new DelegateTimeCost(_comm.TimeCost), new object[] { watch.Elapsed.ToString() });
                }
                else
                {
                    _comm.WriteMessage(2, item.TalkId, filePath, infoStatus.OldPath, infoStatus.iStatus, infoStatus.Summary);
                    _comm.Current(1, item.TalkId);
                    _comm.TimeCost(watch.Elapsed.ToString());
                }
            }



            // 修改https://www.pic1.jzbl.com 的后缀
            var domainOneData = data.Where(o => !string.IsNullOrEmpty(o.FirstTitleImg) && o.FirstTitleImg.Contains(_domainOne)).ToList();

            // var domainOneData = data.Where(o =>o.TalkId.Equals("615a6f97-4fda-439a-b5c4-3b0e708bce13")).ToList();


            foreach (var itemOne in domainOneData)
            {
                infoStatus.Summary = "处理再" + _domainOne + "域名数据";

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

                //处理oss图片有后缀的,只压缩图片就行
                if (itemOne.FirstTitleImg.Split('.').LastOrDefault().ToLower().Equals("jpg"))
                {
                    domainOSSFirstTitlet = itemOne.FirstTitleImg + firstTitletImg;

                    //处理 对象数据
                    var obj = itemOne.ResourceObj.ToList <CallbackUploadInfo>();


                    if (obj != null)
                    {
                        foreach (var itemRes in obj)
                        {
                            CallbackUploadInfo callback = new CallbackUploadInfo();

                            string ossPro = string.Empty;

                            ossPro = string.Format(bigImg, 90);

                            string ossUrl = itemRes.smallImgUrl + ossPro;

                            callback.smallImgUrl = itemRes.smallImgUrl + "?x-oss-process=image/quality,q_90/resize,w_400";
                            callback.bigImgUrl   = ossUrl;
                            callback.fileName    = itemRes.fileName;

                            callbackUploadInfos.Add(callback);
                        }
                    }

                    infoStatus.Summary = "处理oss图片有后缀的,只压缩图片就行";
                }
                else
                {
                    string sourcekey = itemOne.FirstTitleImg.Replace(_domainOne, "");
                    string targetkey = sourcekey + ".jpg";


                    CopyObject(bucketName, sourcekey, bucketName, targetkey);

                    domainOSSFirstTitlet = _domainOne + targetkey;

                    //处理 对象数据
                    var obj = itemOne.ResourceObj.ToList <CallbackUploadInfo>();

                    if (obj != null)
                    {
                        foreach (var itemRes in obj)
                        {
                            CallbackUploadInfo callback = new CallbackUploadInfo();


                            string sourcekeylist = itemRes.smallImgUrl.Replace(_domainOne, "");
                            string targetkeylist = sourcekeylist + ".jpg";

                            CopyObject(bucketName, sourcekeylist, bucketName, targetkeylist);


                            string ossPro = string.Empty;

                            ossPro = string.Format(bigImg, 90);

                            string ossUrl = itemRes.smallImgUrl + ossPro;

                            callback.smallImgUrl = itemRes.smallImgUrl + "?x-oss-process=image/quality,q_90/resize,w_400";
                            callback.bigImgUrl   = ossUrl;
                            callback.fileName    = itemRes.fileName;

                            callbackUploadInfos.Add(callback);
                        }
                    }


                    infoStatus.Summary = "处理oss图片没有后缀,先拷贝,再删除原图";
                }


                // 保存数据
                try
                {
                    using (var context = new DataModelEntities())
                    {
                        var itemData = context.Web_UserBuildingCircle.FirstOrDefault(o => o.TalkId.Equals(itemOne.TalkId));
                        if (itemData != null)
                        {
                            itemData.FirstTitleImg = domainOSSFirstTitlet;
                            itemData.ResourceObj   = callbackUploadInfos.Count == 0 ? null : callbackUploadInfos.ToJson();

                            itemData.TalkContent = string.IsNullOrEmpty(itemData.TalkContent.Trim()) ? itemData.TalkTitle : itemData.TalkContent;
                            itemData.TalkTitle   = string.IsNullOrEmpty(itemData.TalkTitle) ? null : "NULL";

                            context.SaveChanges();
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Failed with error info: {0}", ex.Message);
                    MessageBox.Show(string.Format("保存数据出错!{0}", ex.Message));
                }



                if (this.InvokeRequired)
                {
                    this.Invoke(new DelegateWriteMessage(_comm.WriteMessage), new object[] { 2, itemOne.TalkId, "---------", infoStatus.OldPath, infoStatus.iStatus, infoStatus.Summary });
                    this.Invoke(new DelegateCurrent(_comm.Current), new object[] { 1, itemOne.TalkId });
                    this.Invoke(new DelegateTimeCost(_comm.TimeCost), new object[] { watch.Elapsed.ToString() });
                }
                else
                {
                    _comm.WriteMessage(2, itemOne.TalkId, "---------", infoStatus.OldPath, infoStatus.iStatus, infoStatus.Summary);
                    _comm.Current(1, itemOne.TalkId);
                    _comm.TimeCost(watch.Elapsed.ToString());
                }
            }
        }