Пример #1
0
        /// <summary>
        /// Creates a negative acknowledgement message.
        /// </summary>
        /// <param name="request">The request message to use to create the response message.</param>
        /// <param name="responseCode">The response code of the message.</param>
        /// <param name="errCode">The error code of the message.</param>
        /// <param name="errDescription">The error description of the message.</param>
        /// <returns>Returns the created negative acknowledgement message instance.</returns>
        public static IMessage CreateNack(IMessage request, string responseCode, string errCode, string errDescription)
        {
            MessageUtil.tracer.TraceEvent(TraceEventType.Warning, 0, $"NACK Condition : {errDescription}");

            if (request.Version == "2.3.1")
            {
                var ack = new ACK();

                var terser = new Terser(ack);

                terser.Set("/MSA-1", responseCode);
                terser.Set("/MSA-3", "Error occurred");
                terser.Set("/MSA-6-1", errCode);
                terser.Set("/MSA-6-2", errDescription);

                UpdateMSH(terser, request);

                return(ack);
            }
            else
            {
                var ack = new NHapi.Model.V25.Message.ACK();

                var terser = new Terser(ack);

                terser.Set("/MSA-1", responseCode);

                UpdateMSH(terser, request);

                terser.Set("/ERR-3-1", errCode);
                terser.Set("/ERR-3-2", errDescription);

                return(ack);
            }
        }
Пример #2
0
        public void testMSH()
        {
            var __msh = new MSH(@"MSH |^ ~\&| ADT1 | MCM | LABADT | MCM | 198808181126 | SECURITY | ADT ^ A01 | MSG00001 | P | 2.4");
            var __ack = new ACK(__msh);

            Console.WriteLine("ACK: {0}", __ack.__ack_string);

            var __nak = new NAK(__msh, "AF");

            Console.WriteLine("NAK: {0}", __nak.__nak_string);

            __msh = new MSH(@"MSH|^~\&|FrameworkLTC|DELPHI|100|MAYQ|20110802115657||RDE^O11^RDE_O11|36652|P|2.5||||||ASCII|||");
            __ack = new ACK(__msh);
            Console.WriteLine("ACK: {0}", __ack.__ack_string);

            __nak = new NAK(__msh, "AF");
            Console.WriteLine("NAK: {0}", __nak.__nak_string);

            __msh = new MSH(@"MSH|^~\&|FrameworkLTC|DELPHI|100|MAYQ|20110802115657||RDE ^O11^ RDE_O11|36652|P|2.5||||||ASCII|||");
            __ack = new ACK(__msh);
            Console.WriteLine("ACK: {0}", __ack.__ack_string);

            __nak = new NAK(__msh, "AF");
            Console.WriteLine("NAK: {0}", __nak.__nak_string);
        }
Пример #3
0
        private ACK InitAcknowledgment(HL7Header hl7Header)
        {
            ACK reply = new ACK();

            Identifier serverApplication = hl7Header.ReceivingApplication;
            Identifier serverFacility    = hl7Header.ReceivingFacility;
            //Identifier sendingApplication = PixRegistryConfigration.ReceivingApplication;
            //Identifier sendingFacility = PixRegistryConfigration.ReceivingFacility;
            Identifier sendingApplication = hl7Header.SendingApplicaiton;
            Identifier sendingFacility    = hl7Header.SendingFacility;

            string @event = hl7Header.TriggerEvent;

            PopulateMSH(
                reply.MSH,
                "ACK",
                @event,
                hl7Header.MessageControlId,
                serverApplication,
                serverFacility,
                sendingApplication,
                sendingFacility);

            return(reply);
        }
Пример #4
0
            /// <summary>
            /// Try to send the message
            /// </summary>
            /// <returns></returns>
            public bool TrySend()
            {
                try
                {
                    // Now send
                    MllpMessageSender sender = new MllpMessageSender(new Uri(this.Target.ConnectionString), this.Target.LlpClientCertificate, this.Target.TrustedIssuerCertificate);
                    ACK response             = sender.SendAndReceive(this.Message) as ACK;
                    // See if the ACK is good
                    if (response == null)
                    {
                        this.FailCount += 1;
                        return(false);
                    }

                    if (response.MSA.AcknowledgementCode.Value != "AA" &&
                        response.MSA.AcknowledgementCode.Value != "CA")
                    {
                        this.FailCount += 1;
                        return(false);
                    }
                    return(true);
                }
                catch (Exception e)
                {
                    this.FailCount += 1;
                    Trace.TraceError(e.ToString());
                    return(false);
                }
            }
Пример #5
0
        public Task <string> Handle(Hl7Message message)
        {
            var ack = new ACK();
            var hl7 = _parser.Encode(ack);

            return(Task.FromResult(hl7));
        }
Пример #6
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            if (String.Compare(txtCase.Text, "") == 0)
            {
                MessageBox.Show("Enter Case Name");
                return;
            }
            Case c = new Case(txtCase.Text);

            c.Type = (int)PacketType.Case;
            Packet.Serialize(c).CopyTo(this.sendBuf, 0);
            this.Send();

            Recv();
            ACK ack = (ACK)Packet.Deserialize(this.recvBuf);

            if (ack.isOK)
            {   // Success
                listCase.Items.Add(txtCase.Text);
            }
            else
            {
                MessageBox.Show("The case already exists.");
            }
            txtCase.Clear();
        }
Пример #7
0
        private string CreatACKQ03(string device)
        {
            PipeParser Parser = new PipeParser();
            ACK        ack    = new ACK();

            ack.MSH.FieldSeparator.Value                 = "|";
            ack.MSH.EncodingCharacters.Value             = @"^~\&";
            ack.MSH.SendingApplication.NamespaceID.Value = GlobalVariable.Manufacturer; //仪器供应商
            ack.MSH.SendingFacility.NamespaceID.Value    = device;
            ack.MSH.DateTimeOfMessage.TimeOfAnEvent.SetLongDate(DateTime.Now);          //当前时间
            ack.MSH.MessageType.MessageType.Value   = "ACK";
            ack.MSH.MessageType.TriggerEvent.Value  = "Q03";
            ack.MSH.MessageControlID.Value          = "1";
            ack.MSH.ProcessingID.ProcessingID.Value = "P";
            ack.MSH.VersionID.VersionID.Value       = "2.3.1";
            ack.MSH.GetCharacterSet(0).Value        = GlobalVariable.SocketCode ? "ASCII" : "UTF8";

            ack.MSA.AcknowledgementCode.Value       = "AA";
            ack.MSA.MessageControlID.Value          = "1";
            ack.MSA.TextMessage.Value               = "Message accepted";
            ack.MSA.ErrorCondition.Identifier.Value = "0";

            ack.ERR.GetErrorCodeAndLocation(0).SegmentID.Value = "0";

            return(Parser.Encode(ack));
        }
//测试实例
        private void btnSample_Click(object sender, EventArgs e)
        {
            messageFactory factory = new messageFactory();
            ACK            msg     = factory.Create(null, enumMessage.ACK, "ACK") as ACK;

            msg.msh.FieldSeparator.Value               = "|";
            msg.msh.EncodingCharacters.Value           = "^~\\&";
            msg.msh.DateOrTimeOfMessage.Value          = DateTime.Now.ToString("yyyyMMddhhmmss.fff");
            msg.msh.MessageType.messagecode.Value      = "ACK";
            msg.msh.MessageType.triggerevent.Value     = "A01";
            msg.msh.MessageType.messagestructure.Value = "ACK_A01";
            //msg.msh.MessageType.Value = "ACK^A01^ACK_A01";
            msg.msh.MessageControlID.Value          = "A00002";
            msg.msh.ProcessingID.processingID.Value = "P";
            msg.msh.VersionID.versionID.Value       = "2.4";
            msg.msa.AcknowledgmentCode.Value        = "AA";
            msg.msa.MessageControlID.Value          = "MSG00001";
            msg.msa.TextMessage.Value = "Success";

            txMessage.Text = msg.ToString() + "\n";
            ORM orm = factory.Create(null, enumMessage.ORM, "ORM") as ORM;

            orm.msh.FieldSeparator.Value               = "|";
            orm.msh.EncodingCharacters.Value           = "^~\\&";
            orm.msh.DateOrTimeOfMessage.Value          = DateTime.Now.ToString("yyyyMMddhhmmss.fff");
            orm.msh.MessageType.messagecode.Value      = "ORM";
            orm.msh.MessageType.triggerevent.Value     = "001";
            orm.msh.MessageType.messagestructure.Value = "ORM_001";
            orm.pid.PatientName.Value = "Wangzifu";
            txMessage.Text           += orm.ToString();
        }
Пример #9
0
        public Task <IMessage> Handle(
            Hl7Message message,
            CancellationToken cancellation = default)
        {
            var ack = new ACK();

            return(Task.FromResult <IMessage>(ack));
        }
Пример #10
0
        public void ConvertToLongDate()
        {
            var checkDate = DateTime.Now;
            var ack       = new ACK();

            ack.MSH.DateTimeOfMessage.TimeOfAnEvent.SetLongDate(checkDate);
            Assert.AreEqual(ack.MSH.DateTimeOfMessage.TimeOfAnEvent.Value, checkDate.ToString("yyyyMMddHHmm"));
        }
Пример #11
0
        public void ConvertToLongDateWithFractionOfSecond()
        {
            DateTime checkDate = DateTime.Now;
            ACK      ack       = new ACK();

            ack.MSH.DateTimeOfMessage.TimeOfAnEvent.SetLongDateWithFractionOfSecond(checkDate);
            Assert.AreEqual(ack.MSH.DateTimeOfMessage.TimeOfAnEvent.Value, checkDate.ToString("yyyyMMddHHmmss.FFFF"));
        }
Пример #12
0
        public void ConvertToShortDate()
        {
            DateTime checkDate = DateTime.Now;
            ACK      ack       = new ACK();

            ack.MSH.DateTimeOfMessage.TimeOfAnEvent.SetShortDate(checkDate);
            Assert.AreEqual(ack.MSH.DateTimeOfMessage.TimeOfAnEvent.Value, checkDate.ToString("yyyyMMdd"));
        }
Пример #13
0
        private void FormApplication_Load(object sender, EventArgs e)
        {
            messageFactory factory = new messageFactory();
            ACK            msg     = factory.Create(null, enumMessage.ACK, "ACK") as ACK;

            msg.Parse("MSH|^~\\&|HIS|00001|LIS|1234|2004112754000||ACK^A01^ACK_A01|0200002|P|2.4\rMSA|AE|0200001|type error|||102\r");
            txMessage.Text = msg.ToString();
        }
Пример #14
0
        public void SetError(IMessage msg)
        {
            message = (ACK)HL7MessageHelper.MakeACK(msg, "AE", "Error");

            // Add an ERR segment
            NHapi.Model.V24.Datatype.ELD eld = message.ERR.GetErrorCodeAndLocation(0);
            eld.CodeIdentifyingError.AlternateIdentifier.Value = "1";
            eld.CodeIdentifyingError.AlternateText.Value       = "Something went wrong.";
        }
Пример #15
0
        public void ACKTest()
        {
            ACK    ack = new ACK(null, "ACK01");
            String str = @"MSH|^~\&|RIS||HIS||200405201205||ACK|RIS0001|P|2.4" + "\r" + "MSA|AE|MSG0001|type error|||102" + "\r";

            //str += "\x0d\x1c";
            ack.Value = str;
            Assert.AreEqual(str, ack.Value);
        }
Пример #16
0
        public static ACK ProduceACK(string messageControlId)
        {
            ACK ack = new ACK();

            ProduceMSH(ack.MSH, "ACK", "", "0001");
            ack.MSA.AcknowledgementCode.Value = "AA";
            ack.MSA.MessageControlID.Value    = messageControlId;
            return(ack);
        }
Пример #17
0
        public Task <IMessage> Handle(
            Hl7Message message,
            CancellationToken cancellation = default)
        {
            var controlId = message.Message.GetMessageControlId();
            var ack       = new ACK();

            ack.MSH.MessageControlID.Value = controlId;
            return(Task.FromResult <IMessage>(ack));
        }
Пример #18
0
        private void button2_Click(object sender, EventArgs e)
        {
            messageFactory factory = new messageFactory();
            ACK            msg     = factory.Create(null, enumMessage.ACK, "ACK") as ACK;

            msg.Parse("MSH|^~\\&|HIS|00001|LIS|1234|2004112754000||ACK^A01^ACK_A01|0200002|P|2.4\rMSA|AE|0200001|type   error|||102\r");
            richTextBox1.Text = msg.ToString();                 //txtMessage
            richTextBox2.Text = msg.msa.MessageControlID.Value; //txtMsgControllID
            richTextBox1.Text = msg.msa.TextMessage.Value;
        }
Пример #19
0
        public void ConvertBackToLongDate()
        {
            DateTime checkDate = DateTime.Now;
            ACK      ack       = new ACK();

            ack.MSH.DateTimeOfMessage.TimeOfAnEvent.SetLongDate(checkDate);

            DateTime checkDate2 = ack.MSH.DateTimeOfMessage.TimeOfAnEvent.GetAsDate();

            Assert.AreEqual(checkDate.ToLongDateString(), checkDate2.ToLongDateString());
        }
Пример #20
0
        public void ConvertBackToShortDate()
        {
            var checkDate = DateTime.Now;
            var ack       = new ACK();

            ack.MSH.DateTimeOfMessage.TimeOfAnEvent.SetShortDate(checkDate);

            var checkDate2 = ack.MSH.DateTimeOfMessage.TimeOfAnEvent.GetAsDate();

            Assert.AreEqual(checkDate.ToShortDateString(), checkDate2.ToShortDateString());
        }
Пример #21
0
        /// <summary>
        ///设置一般回复(ACK)
        /// </summary>
        /// <param name="oEntity">原消息体</param>
        /// <param name="messageType">消息类型</param>
        /// <param name="trriggerEvent">触发事件</param>
        /// <param name="messageStruct">消息结构</param>
        /// <param name="ErrMSG">错误信息</param>
        /// <returns>ACK字符</returns>
        public string SetACK(dynamic oEntity, string messageType, string trriggerEvent, string messageStruct = "", string errMSG = "", dynamic ack = null)
        {
            //ACK ack = new ACK();
            if (ack == null)
            {
                ack = new ACK();
            }

            return(MediII.Common.MessageHelper.SetACK(messageType, trriggerEvent, messageStruct, SEDING_APPLICATION, SEDING_APPLICATION,
                                                      oEntity.MSH.SendingApplication.NamespaceID.Value, oEntity.MSH.SendingFacility.NamespaceID.Value, oEntity.MSH.MessageControlID.Value,
                                                      errMSG, ack));
        }
        internal void Update()
        {
            if (this.timedOut <= 0)
            {
                this.Close("disconnect.timeout");
            }
            this.timedOut--;

            if (this.ackQueue.Count > 0)
            {
                ACK ack = new ACK();
                ack.packets = this.ackQueue.Values.ToArray();
                this.server.SendPacket(ack, this.point.Address, this.point.Port);
                this.ackQueue.Clear();
            }

            if (this.nackQueue.Count > 0)
            {
                NACK nack = new NACK();
                nack.packets = this.nackQueue.Values.ToArray();
                this.server.SendPacket(nack, this.point.Address, this.point.Port);
                this.nackQueue.Clear();
            }

            int[] a = this.receivedWindow.Values.ToArray();
            for (int i = 0; i < this.receivedWindow.Values.Count; ++i)
            {
                int seq = a[i];
                if (seq < this.startSeq)
                {
                    if (this.receivedWindow.ContainsKey(seq))
                    {
                        this.receivedWindow.Remove(seq);
                    }
                }
                else
                {
                    break;
                }
            }

            if (packetToSend.Count > 0)
            {
                foreach (DataPacket pk in packetToSend.Values)
                {
                    this.server.SendPacket(pk, point.Address, point.Port);
                }
                packetToSend.Clear();
            }

            SendQueuePackets();
        }
Пример #23
0
        public static string GetACKMessage(string message)
        {
            ACK ack = MessageFactory.parser.parse(message, "2.3.1") as ACK;

            if (ack == null)
            {
                return(string.Empty);
            }
            else
            {
                return(ack.MSA.AcknowledgementCode.Value);
            }
        }
Пример #24
0
        private void CreateNewCase()
        {
            Case c   = (Case)Packet.Deserialize(this.recvBuf);
            ACK  ack = new ACK(false);

            ack.Type = (int)PacketType.ACK;
            if (!Directory.Exists(c.caseName))
            {
                ack.isOK = true;
                Directory.CreateDirectory(c.caseName);
            }
            Packet.Serialize(ack).CopyTo(this.sendBuf, 0);
            this.Send();
        }
Пример #25
0
        public static IMessage MakeACK(ISegment inboundHeader, string ackCode)
        {
            if (!inboundHeader.GetStructureName().Equals("MSH"))
            {
                throw new NHapi.Base.HL7Exception(
                          "Need an MSH segment to create a response ACK (got " + inboundHeader.GetStructureName() + ")");
            }

            // Find the HL7 version of the inbound message:
            //
            string version = null;

            try
            {
                version = Terser.Get(inboundHeader, 12, 0, 1, 1);
            }
            catch (NHapi.Base.HL7Exception)
            {
                // I'm not happy to proceed if we can't identify the inbound
                // message version.
                throw new NHapi.Base.HL7Exception("Failed to get valid HL7 version from inbound MSH-12-1");
            }

            IMessage ackMessage = new ACK();
            // Create a Terser instance for the outbound message (the ACK).
            Terser terser = new Terser(ackMessage);

            // Populate outbound MSH fields using data from inbound message
            ISegment outHeader = (ISegment)terser.getSegment("MSH");

            DeepCopy.copy(inboundHeader, outHeader);

            // Now set the message type, HL7 version number, acknowledgement code
            // and message control ID fields:
            string sendingApp = terser.Get("/MSH-3");
            string sendingEnv = terser.Get("/MSH-4");

            terser.Set("/MSH-3", CommunicationName);
            terser.Set("/MSH-4", EnvironmentIdentifier);
            terser.Set("/MSH-5", sendingApp);
            terser.Set("/MSH-6", sendingEnv);
            terser.Set("/MSH-7", DateTime.Now.ToString("yyyyMMddmmhh"));
            terser.Set("/MSH-9", "ACK");
            terser.Set("/MSH-12", version);
            terser.Set("/MSA-1", ackCode == null ? "AA" : ackCode);
            terser.Set("/MSA-2", Terser.Get(inboundHeader, 10, 0, 1, 1));

            return(ackMessage);
        }
Пример #26
0
        public void ACKTest()
        {
            ACK ack = new ACK();

            ack.Value = "第一层消息容器ACK类";
            Assert.AreEqual(ack.msh.Name, "MSH");


            DateTime dt = DateTime.Now;

            ack.msh.FieldSeparator.Parse(dt.ToString("yyyy年MM月dd日hh时mm分"));
            Assert.AreEqual(dt.ToString("yyyyMMddhhmm"), ack.msh.FieldSeparator.Value);
            //FieldSeparator是ST类型,实现和第一次测试的一样
            //成功了说明容器构件、类关联没问题,只是叶子节点类的方法都是一样的,没有各自实现
        }
Пример #27
0
        private void SendFile(string fileName)
        {
            FileInfo f        = new FileInfo(fileName);
            string   md5      = PUtility.CalculateMD5(fileName);
            FileMeta fileMeta = new FileMeta(
                f.Length,
                fileName,
                md5);

            fileMeta.Type = (int)PacketType.FileMeta;
            Packet.Serialize(fileMeta).CopyTo(this.sendBuf, 0);
            this.Send();

            Recv();
            ACK ack = (ACK)Packet.Deserialize(this.recvBuf);

            if (ack.isOK == false)
            {   // same name file
                ack = new ACK(false);
                if (MessageBox.Show("A same name already exists.\r\n\r\n" +
                                    "Do you want version control?", "FM", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    ack.isOK = true;
                }
                Packet.Serialize(ack).CopyTo(this.sendBuf, 0);
                this.Send();
            }

            if (f.Length != 0)
            {
                byte[] file = File.ReadAllBytes(fileName);

                this.stream.Write(file, 0, file.Length);
                this.stream.Flush();
            }

            Recv();

            ack = (ACK)Packet.Deserialize(this.recvBuf);
            if (ack.isOK)
            {
                //MessageBox.Show("성공적으로 업로드하였습니다!");
            }
            else
            {
                MessageBox.Show("파일 업로드 실패");
            }
        }
Пример #28
0
        public string PostHL7(JObject jsonFile)
        {
            //string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            try
            {
                string hl7msg = jsonFile["hl7Message"].ToString();

                //string jsonContent = jsonFile.ToString();
                //string hl7msg = "MSH|^~\\&|WellSky|44935|IntelliH|IntelliH-FACILITY|202104271600-0500||ADT^A01|2|P|2.4|\rEVN|A01|201908191159-0500\rPID|1||0000-000-002||Test^Patient^P||19640101|M|||123 Some Street^^Some City^TX^12345^^^^||1234567890||||||0001|||||||||||N\rPV1|1|U|^^^^^1||||0000000006^Another Test^Physician^|0000000004^Test^Physician^||||||||||||||||||||||||||||||||||Team E||201908190000-0500|\rPV2|||||||||||||||||||||||Some Hospice, LLC\rDG1|1|I10|Z51.1^Encounter for palliative care^I10|Encounter for palliative care||A|||||||||1\rDG1|2|I10|D63^Anemia in other chronic diseases classified elsewhere^I10|Anemia in other chronic diseases classified elsewhere||A|||||||||2\rDG1|3|I10|C25^Malignant neoplasm of head of pancreas^I10|Malignant neoplasm of head of pancreas||A|||||||||3\r";

                //File.WriteAllText(Path.Combine(path.Replace("file:\\", string.Empty), "WellSky", "WellSky_HL7Endpoint_Files_Called_" + DateTime.Now.Date.ToShortDateString().Replace('/', '_') + "_" + DateTime.Now.Hour + "_" + DateTime.Now.Minute + "_" + DateTime.Now.Second + "_" + DateTime.Now.Millisecond + ".txt"), jsonContent);

                //string responseMessage = "MSH|^~\\&|IntelliH|IntelliH-FACILITY|WELLSKY|12345|20180821084905||ACK^A01|0228506632277834|P|2.4" + Environment.NewLine + "MSA|AA|633|Application Accept ADT message successfully received and queued for processing.";

                ACK           objACK          = new ACK();
                MSH           oMSH            = objACK.fetchMSHComponents(hl7msg);
                StringBuilder responseMessage = new StringBuilder();
                responseMessage.Append("MSH|");
                responseMessage.Append(string.Concat(oMSH.encodingcharactors, oMSH.fieldseparator));
                responseMessage.Append(string.Concat(oMSH.sendingapplication, oMSH.fieldseparator));
                responseMessage.Append(string.Concat(oMSH.sendingfacility, oMSH.fieldseparator));
                responseMessage.Append(string.Concat(oMSH.receivingapplication, oMSH.fieldseparator));
                responseMessage.Append(string.Concat(oMSH.receivingfacility, oMSH.fieldseparator));
                responseMessage.Append(string.Concat(oMSH.creationdatetime, oMSH.fieldseparator));
                responseMessage.Append(string.Concat(oMSH.security, oMSH.fieldseparator));
                responseMessage.Append(string.Concat(oMSH.messagetype, "^", oMSH.triggerevent, oMSH.fieldseparator));
                responseMessage.Append(string.Concat(oMSH.messagecontrolid, oMSH.fieldseparator));
                responseMessage.Append(string.Concat(oMSH.processingid, oMSH.fieldseparator));
                responseMessage.Append(oMSH.versionid);
                responseMessage.Append(Environment.NewLine);
                responseMessage.Append(string.Concat("MSA|AA|", oMSH.messagecontrolid, "|Application Accept ADT message successfully received and queued for processing."));

                saveHL7(oMSH.messagecontrolid, hl7msg);

                return(responseMessage.ToString());

                //return data;
            }
            catch (Exception ex)
            {
                //File.WriteAllText(Path.Combine(path.Replace("file:\\", string.Empty), "WellSky", "WellSky_HL7Endpoint_Files_Error_" + DateTime.Now.Date.ToShortDateString().Replace('/', '_') + "_" + DateTime.Now.Hour + "_" + DateTime.Now.Minute + "_" + DateTime.Now.Second + "_" + DateTime.Now.Millisecond + ".txt"), ex.Message + Environment.NewLine + ex.StackTrace);
                return(ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
Пример #29
0
        private void HandleReqFile()
        {
            FileMeta reqFile = (FileMeta)Packet.Deserialize(this.recvBuf);

            this.Invoke((MethodInvoker)(() => {
                txtLog.AppendText(pathCur + reqFile.fileName + " start\r\n");
            }));

            FileInfo f = new FileInfo(pathCur + reqFile.fileName);

            FileMeta fileMeta = new FileMeta(
                f.Length,
                reqFile.fileName,
                "");

            fileMeta.Type = (int)PacketType.FileMeta;
            Packet.Serialize(fileMeta).CopyTo(this.sendBuf, 0);
            this.Send();

            if (f.Length != 0)
            {
                byte[] file = File.ReadAllBytes(pathCur + reqFile.fileName);

                this.stream.Write(file, 0, file.Length);
                this.stream.Flush();
            }

            Recv();

            ACK ack = (ACK)Packet.Deserialize(this.recvBuf);

            if (ack.isOK)
            {
                this.Invoke((MethodInvoker)(() => {
                    txtLog.AppendText("download " + reqFile.fileName + " success\r\n");
                }));
            }
            else
            {
                this.Invoke((MethodInvoker)(() => {
                    txtLog.AppendText("download " + reqFile.fileName + " failure\r\n");
                }));
            }
        }
Пример #30
0
    {/// <summary>
     /// 消息工厂创建messageType,生成ADT,ACK等消息
     /// </summary>
     /// <param name="parent"></param>
     /// <param name="product"></param>
     /// <param name="name"></param>
     /// <returns></returns>
        public override abstractType Create(compositeType parent, Enum product, string name)
        {
            abstractType tmp = null;

            switch (product)
            {
            case enumMessage.ACK:
                tmp = new ACK(parent, name);
                break;

            case enumMessage.ORM:
                tmp = new ORM(parent, name);
                break;

            default:
                throw new NotSupportedException();
            }
            return(tmp);
        }