Esempio n. 1
0
        /// <summary>
        /// 返回“失败”的消息包
        /// </summary>
        /// <param name="ex">异常信息</param>
        /// <returns></returns>
        public string ReturnFailure(Exception ex)
        {
            // 复制当前的消息对象
            string Error = string.Empty;

            if (ex.InnerException != null && ex.InnerException.Message != null)
            {
                Error = ex.InnerException.Message;
            }
            else if (ex.Message != null)
            {
                Error = ex.Message;
            }
            else
            {
                Error = ex.ToString();
            }
            MessageSerialXml returnResutlXml = MessageSerialXml.DeSerialClassFromXML(MessageSerialXml.SerialClassToXML(serialXmlObject));

            returnResutlXml.Head.Date            = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            returnResutlXml.Head.MsgID           = serialXmlObject.Head.MsgID + "+RET";
            returnResutlXml.Head.StateCode       = "999";
            returnResutlXml.Head.StateDesription = Error;
            returnResutlXml.Head.DataDefine      = new _DataDefine();
            returnResutlXml.Data = new _Data();
            return(MessageSerialXml.SerialClassToXML(returnResutlXml));
        }
Esempio n. 2
0
        /// <summary>
        /// 产生数据
        /// </summary>
        /// <param name="dataSet">数据集</param>
        /// <param name="serialXmlObject">xml序列化对象</param>
        /// <returns></returns>
        private _Data GenerateXmlData(DataSet dataSet, MessageSerialXml serialXmlObject)
        {
            _Data xmlData = new _Data();

            _Table[] xmlTableStructSet = serialXmlObject.Head.DataDefine.TableSet;
            xmlData.DataTableSet = new _DataTable[serialXmlObject.Head.DataDefine.TableSet.Length];
            for (int i = 0; i < xmlTableStructSet.Length; i++)
            {
                _Table     xmlTableStruct = xmlTableStructSet[i];
                _DataTable xmlDataTable   = new _DataTable();
                DataTable  dt             = null;
                if (xmlTableStructSet.Length <= 1)
                {
                    dt           = dataSet.Tables[0];
                    dt.TableName = xmlTableStruct.TableName;
                }
                else
                {
                    dt = dataSet.Tables[xmlTableStruct.TableName];
                }

                if (dt.Rows.Count <= 0)
                {
                    continue;
                }

                xmlData.DataTableSet[i] = GenerateXmlDataTable(dt, xmlTableStruct, xmlDataTable);
            }

            return(xmlData);
        }
Esempio n. 3
0
        public MessagePackage(string interfaceCode, string desc)
        {
            string      xmlPath = @"Configs\TaskConfig.xml";
            XmlDocument xmlDoc  = new XmlDocument();

            xmlDoc.Load(xmlPath);
            string taskConfigXml = xmlDoc.OuterXml;

            // 读取与当前任务相关的配置
            xmlDoc.LoadXml(taskConfigXml);
            string  xpath    = "/Configuration/TaskList/Task[@No = '" + interfaceCode + "']";
            XmlNode taskNode = xmlDoc.SelectSingleNode(xpath);

            if (taskNode == null)
            {
                throw new Exception("找不到接口代码为:" + interfaceCode + "的配置.");
            }
            string Description = taskNode.Attributes["Description"].Value;
            string XmlPath     = @"Configs\Xml\" + taskNode.Attributes["xmlFile"].Value;

            xmlDoc.Load(XmlPath);
            string xml = xmlDoc.OuterXml;

            this.serialXmlObject = MessageSerialXml.DeSerialClassFromXML(xmlDoc.OuterXml);
        }
Esempio n. 4
0
        public static string SerialClassToXML(MessageSerialXml SourceObj)
        {
            XmlSerializer ser = new XmlSerializer(typeof(MessageSerialXml));

            System.IO.StringWriter writer = new System.IO.StringWriter();
            ser.Serialize(writer, SourceObj);
            writer.GetStringBuilder().Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            writer.GetStringBuilder().Replace(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"", "");
            writer.GetStringBuilder().Replace(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", "");
            return(writer.GetStringBuilder().ToString());
        }
Esempio n. 5
0
        /// <summary>
        /// 返回“成功”的消息包
        /// </summary>
        /// <returns></returns>
        public string ReturnSuccess()
        {
            // 复制当前的消息对象
            MessageSerialXml returnResutlXml = MessageSerialXml.DeSerialClassFromXML(MessageSerialXml.SerialClassToXML(serialXmlObject));

            returnResutlXml.Head.Date            = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            returnResutlXml.Head.MsgID           = serialXmlObject.Head.MsgID + "+RET";
            returnResutlXml.Head.StateCode       = "000";
            returnResutlXml.Head.StateDesription = "成功";
            returnResutlXml.Head.DataDefine      = new _DataDefine();
            returnResutlXml.Data = new _Data();
            return(MessageSerialXml.SerialClassToXML(returnResutlXml));
        }
Esempio n. 6
0
        public static void SerialClass(MessageSerialXml SourceObj, string FileName)
        {
            XmlSerializer ser = new XmlSerializer(typeof(MessageSerialXml));

            System.IO.StringWriter writer = new System.IO.StringWriter();
            ser.Serialize(writer, SourceObj);
            writer.GetStringBuilder().Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", "<?xml version=\"1.0\" encoding=\"GB2312\"?>");
            writer.GetStringBuilder().Replace(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"", "");
            writer.GetStringBuilder().Replace(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", "");
            System.IO.File.SetAttributes(FileName, System.IO.FileAttributes.Normal);//去除只读属性
            System.IO.FileStream   fs = new System.IO.FileStream(FileName, System.IO.FileMode.Create);
            System.IO.StreamWriter sw = new System.IO.StreamWriter(fs);
            sw.Write(writer.GetStringBuilder().ToString());
            sw.Close();
            writer.Close();
            fs.Close();
        }
Esempio n. 7
0
        /// <summary>
        /// 数据打包
        /// </summary>
        /// <param name="messageDataSet">消息数据</param>
        /// <returns></returns>
        public string Pack(DataSet messageDataSet)
        {
            if (messageDataSet == null)
            {
                throw new Exception("数据集为空!");
            }
            // 当没有记录状态的时候,增加默认的记录状态:Unchange
            AddDefaultAction(messageDataSet);
            serialXmlObject.Head.MsgID = Guid.NewGuid().ToString().Replace("-", "");
            serialXmlObject.Head.Date  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            serialXmlObject.Head.User  = "******";
            serialXmlObject.Data       = GenerateXmlData(messageDataSet, serialXmlObject);
            string strXml = MessageSerialXml.SerialClassToXML(serialXmlObject);

            //调用ESB并返回执行结果
            return("");
            //EsbService.ESBServiceClient client = new EsbService.ESBServiceClient();
            //return client.tranESBService(strXml);
        }
Esempio n. 8
0
 public MessagePackage(string xml)
 {
     // 加载接口对应的消息包结构
     this.serialXmlObject = MessageSerialXml.DeSerialClassFromXML(xml);
 }
Esempio n. 9
0
        /// <summary>
        /// 获取反馈内容的消息头信息
        /// </summary>
        /// <param name="xml">反馈的XML</param>
        /// <returns></returns>
        public _Head ResultXml(string xml)
        {
            MessageSerialXml messageSerXml = MessageSerialXml.DeSerialClassFromXML(xml);

            return(messageSerXml.Head);
        }