Ejemplo n.º 1
0
        public override bool PrePushToRabbitMq(out string fileSavePath, out string errorMsg)
        {
            fileSavePath = string.Empty;
            errorMsg     = string.Empty;

            try
            {
                if (string.IsNullOrWhiteSpace(customId))
                {
                    errorMsg = "wordreport缺少customID";
                    return(false);
                }

                string sysPrimaryKey = string.Empty;
                if (!dicData.TryGetValue("SYSPRIMARYKEY", out sysPrimaryKey))
                {
                    errorMsg = "wordreport缺少SYSPRIMARYKEY";
                    return(false);
                }

                string suffix = "doc";
                if (!dicData.TryGetValue("REPORTTYPES", out suffix))
                {
                    suffix = "doc";
                }

                if (string.IsNullOrWhiteSpace(suffix))
                {
                    suffix = "doc";
                }

                //附件___blob___

                //bool hasData = false;

                if (cmdAttach != null)
                {
                    #region 附件处理

                    string relativePath = string.Format("{0}\\{1}\\{2}\\{3}.{4}",
                                                        FSSelector.GetSafeFilename(customId),
                                                        DateTime.Now.ToString("yyyy-MM"),
                                                        FSSelector.GetSafeFilename(sysPrimaryKey),
                                                        FSSelector.GetSafeFilename(pk), suffix);

                    string baseFileDir = FSSelector.GetFSWordUrl(customId);
                    string filePath    = Path.Combine(baseFileDir, relativePath);

                    string fileFolder = Path.GetDirectoryName(filePath);
                    if (!Directory.Exists(fileFolder))
                    {
                        Directory.CreateDirectory(fileFolder);
                    }

                    try
                    {
                        File.WriteAllBytes(filePath, cmdAttach);
                        fileSavePath = filePath;

                        //hasData = true;
                        //dicData["WORDREPORTPATH"] = filePath;
                        //dicData["ISLOCALSTORE"] = "0";
                        //if (cmdAttach.Length >= limitedSized * 1024 * 1024)
                        //{
                        //    //标识为大型文件,通过wcf的stream模式传输
                        //    dicData["ISLOCALSTORE"] = "1";
                        //}
                    }
                    catch (Exception ex)
                    {
                        LoggerHelper.WriteErrorLog(logger, ex);
                        errorMsg = string.Format("[ErrorMsg:{0}]-[StackTrace:{1}]-[Source:{2}]",
                                                 ex.Message,
                                                 ex.StackTrace,
                                                 ex.Source);
                        return(false);
                    }

                    #endregion
                }

                #region old code

                //if (dicData.ContainsKey("IMAGE") && cmdAttach != null)
                //{
                //    var binaryIndexs = dicData["IMAGE"];
                //    if (binaryIndexs.Contains("___blob___"))
                //    {
                //        var bData = GetBinaryByIndexs(binaryIndexs);
                //        if (bData != null)
                //        {
                //            //
                //            #region 附件处理

                //            string relativePath = string.Format("{0}\\{1}\\{2}\\{3}.{4}",
                //                FSSelector.GetSafeFilename(customId),
                //                DateTime.Now.ToString("yyyy-MM"),
                //                FSSelector.GetSafeFilename(sysPrimaryKey),
                //                FSSelector.GetSafeFilename(pk),
                //                suffix);
                //            string baseFileDir = FSSelector.GetFSWordUrl(customId);
                //            string filePath = Path.Combine(baseFileDir, relativePath);

                //            string fileFolder = Path.GetDirectoryName(filePath);
                //            if (!Directory.Exists(fileFolder))
                //            {
                //                Directory.CreateDirectory(fileFolder);
                //            }

                //            try
                //            {
                //                File.WriteAllBytes(filePath, bData);
                //                hasData = true;
                //                dicData["WORDREPORTPATH"] = filePath;
                //                dicData["ISLOCALSTORE"] = "0";
                //                if (bData.Length >= limitedSized * 1024 * 1024)
                //                {
                //                    //标识为大型文件,通过wcf的stream模式传输
                //                    dicData["ISLOCALSTORE"] = "1";
                //                }
                //            }
                //            catch (Exception ex)
                //            {
                //                LoggerHelper.WriteErrorLog(logger, ex);
                //                errorMsg = string.Format("[ErrorMsg:{0}]-[StackTrace:{1}]-[Source:{2}]",
                //                    ex.Message,
                //                    ex.StackTrace,
                //                    ex.Source);
                //                return false;
                //            }


                //            #endregion

                //            //Task.Factory.StartNew(() => SaveToRavenDB(filePath, ms));
                //        }

                //    }
                //}

                #endregion

                //if (!hasData)
                //{
                //    dicData["NODATA"] = "1";
                //    LoggerHelper.WriteCustomLog(logger, "无附件 " + cmdData, "CWorkNoReport", false);
                //}

                return(true);
            }
            catch (Exception ex)
            {
                LoggerHelper.WriteErrorLog(logger, ex);
                errorMsg = ex.Message;
                return(false);
            }
        }
Ejemplo n.º 2
0
        public override bool PrePushToRabbitMq(out string fileSavePath, out string errorMsg)
        {
            fileSavePath = string.Empty;
            errorMsg     = string.Empty;
            try
            {
                if (string.IsNullOrWhiteSpace(customId))
                {
                    errorMsg = "wordreport缺少customID";
                    return(false);
                }

                string sysPrimaryKey = string.Empty;
                if (!dicData.TryGetValue("SYSPRIMARYKEY", out sysPrimaryKey))
                {
                    errorMsg = "wordreport缺少SYSPRIMARYKEY";
                    return(false);
                }

                string suffix = "doc";
                if (!dicData.TryGetValue("FILETYPE", out suffix))
                {
                    suffix = "doc";
                }

                if (string.IsNullOrWhiteSpace(suffix))
                {
                    suffix = "doc";
                }



                if (cmdAttach != null)
                {
                    #region 附件处理

                    string relativePath = string.Format("{0}\\{1}\\{2}\\{3}.{4}",
                                                        FSSelector.GetSafeFilename(customId),
                                                        DateTime.Now.ToString("yyyy-MM-dd"),
                                                        FSSelector.GetSafeFilename(sysPrimaryKey),
                                                        FSSelector.GetSafeFilename(pk),
                                                        suffix);
                    string baseFileDir = FSSelector.GetFSWordUrl(customId);
                    string filePath    = Path.Combine(baseFileDir, relativePath);

                    string fileFolder = Path.GetDirectoryName(filePath);
                    if (!Directory.Exists(fileFolder))
                    {
                        Directory.CreateDirectory(fileFolder);
                    }

                    try
                    {
                        File.WriteAllBytes(filePath, cmdAttach);
                        fileSavePath = filePath;
                    }
                    catch (Exception ex)
                    {
                        LoggerHelper.WriteErrorLog(logger, ex);
                        errorMsg = string.Format("[ErrorMsg:{0}]-[StackTrace:{1}]-[Source:{2}]",
                                                 ex.Message,
                                                 ex.StackTrace,
                                                 ex.Source);
                        return(false);
                    }

                    #endregion
                }


                return(true);
            }
            catch (Exception ex)
            {
                LoggerHelper.WriteErrorLog(logger, ex);
                errorMsg = ex.Message;
                return(false);
            }
        }