Exemplo n.º 1
0
        private void CheckSerialization(Envelope expected)
        {
            var xml    = ObjectToXml.Serialize(expected);
            var actual = XmlToObject.Deserialize <Envelope>(xml);

            EnvelopeAssert.AreEqual(expected, actual);
        }
Exemplo n.º 2
0
        private void TruyenData()
        {
            IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616");
            IConnection        con     = factory.CreateConnection("admin", "admin");

            con.Start();
            ISession         session     = con.CreateSession(AcknowledgementMode.AutoAcknowledge);
            ActiveMQTopic    destination = new ActiveMQTopic("PhongKhamNhaKhoa");
            IMessageProducer producer    = session.CreateProducer(destination);

            ePhieuKham p = new ePhieuKham();

            p.idPhieuKham = idPhieuKham;
            p.idNV        = 1;
            p.ngayDKKham  = DateTime.Today;
            p.tinhTrang   = 1;
            p.moTa        = txtmota.Text.Trim();
            p.idKH        = Convert.ToInt32(idKhachHang);

            string   xml = new ObjectToXml <ePhieuKham>().object2XML(p);
            IMessage msg = new ActiveMQTextMessage(xml);

            producer.Send(msg);
            session.Close();
            con.Close();
        }
Exemplo n.º 3
0
        private void loadConnectionsToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            var openFileDialog = new OpenFileDialog
            {
                RestoreDirectory = true,
                Filter           = "All Connection Xml files (*.PXML)|*.PXML"
            };

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                var fileName = openFileDialog.FileName;

                if (File.Exists(fileName) == true)
                {
                    Connections connections = ObjectToXml <Connections> .Load(fileName);

                    if (connections == null)
                    {
                        MessageBox.Show("Unable to load customer object from file '" + fileName + "'!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        this.LoadConnections(connections);
                        MessageBox.Show("Customer loaded from file '" + fileName + "'!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("File does not exist. Please try again.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Exemplo n.º 4
0
        private void CheckEncryption(Envelope envelope, Attachment attachment)
        {
            var xml         = ObjectToXml.Serialize(envelope);
            var certificate = Certificates.CreateSelfSigned();

            var expected = Copy(attachment.Stream);

            var encrypter = new EbmsEncrypter
            {
                Xml                   = xml,
                Attachments           = new [] { attachment },
                PublicKeyInAsn1Format = certificate.GetPublicKey()
            };

            encrypter.Encrypt();

            var decrypter = new EbmsDecrypter
            {
                Xml         = xml,
                Attachments = new [] { attachment },
                Certificate = certificate
            };

            decrypter.Decrypt();

            var actual = Copy(attachment.Stream);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
Exemplo n.º 5
0
        private void saveConnectionsToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            if (this.ConnectionsIsValid())
            {
                var connections = new Connections {
                    ConnectionList = CreateConnections()
                };

                try
                {
                    var openFileDialog = new SaveFileDialog
                    {
                        RestoreDirectory = true,
                        Filter           = "All Connection Xml files (*.PXML)|*.PXML"
                    };

                    if (openFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        var fileName = openFileDialog.FileName;

                        ObjectToXml <Connections> .Save(connections, fileName);

                        MessageBox.Show("Customer saved to XML file '" + fileName + "'!", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("File can not be saved. Please try again.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to save connection object!" + Environment.NewLine + Environment.NewLine + ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 6
0
        public void Sign()
        {
            var qualifyingProperties    = GetQualifyingProperties(Certificate);
            var qualifyingPropertiesXml = ObjectToXml.Serialize(qualifyingProperties);

            var signedXml = new ExtendedSignedXml(Xml);

            signedXml.Signature.Id = qualifyingProperties.Target;
            signedXml.SigningKey   = Certificate.GetRSAPrivateKey();
            signedXml.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NTransformUrl;
            signedXml.SignedInfo.SignatureMethod        = SignedXml.XmlDsigRSASHA256Url;

            var documentReference = new Reference
            {
                Id   = qualifyingProperties.SignedProperties.SignedDataObjectProperties.DataObjectFormat.ObjectReference,
                Type = null,
                Uri  = ""
            };

            documentReference.AddTransform(new XmlDsigEnvelopedSignatureTransform());
            documentReference.DigestMethod = SignedXml.XmlDsigSHA256Url;
            signedXml.AddReference(documentReference);

            var signedProperties = new Reference
            {
                Type = Namespaces.SignedProperties,
                Uri  = "#" + qualifyingProperties.SignedProperties.Id
            };

            signedProperties.AddTransform(new XmlDsigExcC14NTransform());
            signedProperties.DigestMethod = SignedXml.XmlDsigSHA256Url;
            signedXml.AddReference(signedProperties);

            var dataObject = new DataObject
            {
                Data = qualifyingPropertiesXml.ChildNodes
            };

            signedXml.AddObject(dataObject);

            var certificateKeyInfo = new KeyInfo();

            certificateKeyInfo.AddClause(new KeyInfoX509Data(Certificate));
            signedXml.KeyInfo = certificateKeyInfo;

            signedXml.ComputeSignature();

            var signature = signedXml.GetXml();

            Insert(signature, Xml.DocumentElement);
        }
Exemplo n.º 7
0
        private void CheckSigning(Envelope envelope, params Attachment[] attachments)
        {
            var xml = ObjectToXml.Serialize(envelope);

            var ebmsSigner = new EbmsSigner
            {
                Xml         = xml,
                Certificate = Certificates.CreateSelfSigned(),
                Uris        = new [] { envelope.Header.Messaging.Id, envelope.Body.Id },
                Attachments = attachments
            };

            ebmsSigner.Sign();

            var ebmsVerifier = new EbmsVerifier
            {
                Xml         = xml,
                Attachments = attachments
            };

            ebmsVerifier.Verify();
        }
Exemplo n.º 8
0
        private void TruyenData()
        {
            IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616");
            IConnection        con     = factory.CreateConnection("admin", "admin");

            con.Start();
            ISession         session     = con.CreateSession(AcknowledgementMode.AutoAcknowledge);
            ActiveMQQueue    destination = new ActiveMQQueue("donThuoc");
            IMessageProducer producer    = session.CreateProducer(destination);
            eDonThuoc        dt          = new eDonThuoc();

            dt.idNhaSi     = idNV;;
            dt.ngayLap     = DateTime.Today;
            dt.idPhieuKham = str;
            dt.idDonThuoc  = donThuocWCFClient.getIdLast();
            dt.tinhTrang   = false;
            string   xml = new ObjectToXml <eDonThuoc>().object2XML(dt);
            IMessage msg = new ActiveMQTextMessage(xml);

            producer.Send(msg);
            session.Close();
            con.Close();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Update the XML and string values from the object value. The caller needs to pass in a delegate to
        /// a method that can perform the conversion to XML.
        /// </summary>
        public void UpdateFromObject(ObjectToXml objectToXml)
        {
            if ((AvailableFormats & WrappedValueFormats.Object) != WrappedValueFormats.Object)
            {
                throw new InvalidOperationException("Unable to update the GenericWrapper XML and string values,"
                                                    + " because it does not have the actual object value.");
            }

            // Clear existing XML and string values.

            m_xml     = null;
            m_string  = null;
            m_formats = WrappedValueFormats.Object;

            // Try to read them from the object.

            if (objectToXml != null)
            {
                try
                {
                    m_xml      = objectToXml(m_wrapped);
                    m_formats |= WrappedValueFormats.Xml;
                }
                catch (System.Exception)
                {
                }
            }

            try
            {
                m_string   = m_wrapped.ToString();
                m_formats |= WrappedValueFormats.String;
            }
            catch (System.Exception)
            {
            }
        }
Exemplo n.º 10
0
 public void Set(Envelope envelope)
 {
     SoapEnvelope = ObjectToXml.Serialize(envelope);
 }
Exemplo n.º 11
0
        public void Sign()
        {
            var security = new AS4.Security.Security
            {
                BinarySecurityToken = new BinarySecurityToken
                {
                    Id           = Guid.NewGuid().ToString(),
                    EncodingType = Soap.Namespaces.Base64Binary,
                    ValueType    = Soap.Namespaces.X509TokenProfile,
                    Value        = Certificate.GetRawCertData()
                }
            };

            var securityXml = ObjectToXml.Serialize(security);

            var signedXml = new ExtendedSignedXml(Xml)
            {
                SigningKey = Certificate.GetRSAPrivateKey()
            };

            foreach (var uri in Uris)
            {
                var reference = new Reference
                {
                    Uri          = "#" + uri,
                    DigestMethod = SignedXml.XmlDsigSHA256Url
                };
                reference.AddTransform(new XmlDsigExcC14NTransform());
                signedXml.AddReference(reference);
            }

            foreach (var attachment in Attachments)
            {
                var reference = new Reference(new NonCloseableStream(attachment.Stream))
                {
                    Uri          = "cid:" + attachment.ContentId,
                    DigestMethod = SignedXml.XmlDsigSHA256Url
                };
                reference.AddTransform(new AttachmentContentSignatureTransform());
                signedXml.AddExternalReference(reference);
            }

            var keyInfo = new KeyInfo();

            keyInfo.AddClause(new SecurityTokenReference(security.BinarySecurityToken.Id));

            signedXml.KeyInfo = keyInfo;

            signedXml.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigExcC14NTransformUrl;
            signedXml.SignedInfo.SignatureMethod        = SignedXml.XmlDsigRSASHA256Url;

            signedXml.ComputeSignature();

            var signature = signedXml.GetXml();

            Insert(signature, securityXml.DocumentElement);

            var namespaces = new XmlNamespaceManager(Xml.NameTable);

            namespaces.AddNamespace("s", Soap.Namespaces.SoapEnvelope);
            var header = Xml.SelectSingleNode("/s:Envelope/s:Header", namespaces);

            Insert(securityXml, header);
        }