Ejemplo n.º 1
0
        private String SendAndCheck(String msg, ContentInfoTypeContentType msgType, params PublicationMessageTypeDestinationContext[] destinations)
        {
            PublicationMessageType publishMessage = new PublicationMessageType();

            //Unique ID to identify the request
            publishMessage.PublicationId = Guid.NewGuid().ToString("N").Substring(18, 13);

            //Indicate your box (optional)
            //publishMessage.BoxId = new BoxIdType();
            //publishMessage.BoxId.Id = "0820563481";
            //publishMessage.BoxId.Type = "CBE";
            //publishMessage.BoxId.Quality = "INSTITUTION";

            //Indicate the box of the destination
            publishMessage.DestinationContext = destinations;

            //And the message we send
            publishMessage.ContentContext = new PublicationMessageTypeContentContext();
            publishMessage.ContentContext.Content = new ContentType();
            switch (msgType)
            {
                case ContentInfoTypeContentType.NEWS:
                    NewsType news = new NewsType();
                    news.Title = "eH-I supports ehBox";
                    news.Item = Encoding.UTF8.GetBytes(msg);
                    news.ItemElementName = ItemChoiceType1.EncryptableTextContent;
                    news.MimeType = "text/plain";
                    publishMessage.ContentContext.Content.Item = news;
                    break;
                case ContentInfoTypeContentType.DOCUMENT:
                    DocumentType doc = new DocumentType();
                    doc.Title = "eH-I supports ehBox";
                    doc.Item = Encoding.UTF8.GetBytes(msg);
                    doc.ItemElementName = ItemChoiceType.EncryptableTextContent;
                    doc.MimeType = "text/plain";
                    doc.DownloadFileName = "msg.txt";
                    publishMessage.ContentContext.Content.Item = doc;
                    break;
            }
            publishMessage.ContentContext.ContentSpecification = new ContentSpecificationType();
            publishMessage.ContentContext.ContentSpecification.IsImportant = false;
            publishMessage.ContentContext.ContentSpecification.IsEncrypted = false;
            publishMessage.ContentContext.ContentSpecification.PublicationReceipt = true;
            publishMessage.ContentContext.ContentSpecification.ReceivedReceipt = true;
            publishMessage.ContentContext.ContentSpecification.ReadReceipt = true;
            publishMessage.ContentContext.ContentSpecification.ApplicationName = "eH-I";

            //Publish the news.
            SendMessageResponse publishResp = publish.sendMessage(publishMessage);

            //check the publish response
            Assert.AreEqual("100", publishResp.Status.Code);

            //Check if the message is received.
            GetMessageAcknowledgmentsStatusRequestType ackReq = new GetMessageAcknowledgmentsStatusRequestType();
            ackReq.MessageId = publishResp.Id;
            ackReq.StartIndex = 1;
            ackReq.EndIndex = 100;

            //Loop until the new is received.
            int loop = 0;
            bool arrived = false;
            while (loop < 8 && !arrived)
            {
                //Give eHealth some time (each time a little more)
                System.Threading.Thread.Sleep(new TimeSpan(0, 0, Fibonacci(loop++)));

                //Get the status
                GetMessageAcknowledgmentsStatusResponseType ackResp = consult.getMessageAcknowledgmentsStatus(ackReq);

                //check the publish response
                Assert.AreEqual("100", ackResp.Status.Code);

                arrived = true;
                //check if all recipients to see if there is one missing
                foreach (GetMessageAcknowledgmentsStatusResponseTypeRow ack in ackResp.AcknowledgmentsStatus)
                {
                    if (!ack.ReceivedSpecified) arrived = false;
                }
            }

            return publishResp.Id;
        }
Ejemplo n.º 2
0
        private String SendAndCheck(String msg, ContentInfoTypeContentType msgType, params PublicationMessageTypeDestinationContext[] destinations)
        {
            PublicationMessageType publishMessage = new PublicationMessageType();

            //Unique ID to identify the request
            publishMessage.PublicationId = Guid.NewGuid().ToString("N").Substring(18, 13);

            //Indicate your box (optional)
            //publishMessage.BoxId = new BoxIdType();
            //publishMessage.BoxId.Id = "0820563481";
            //publishMessage.BoxId.Type = "CBE";
            //publishMessage.BoxId.Quality = "INSTITUTION";

            //Indicate the box of the destination
            publishMessage.DestinationContext = destinations;

            //And the message we send
            publishMessage.ContentContext         = new PublicationMessageTypeContentContext();
            publishMessage.ContentContext.Content = new ContentType();
            switch (msgType)
            {
            case ContentInfoTypeContentType.NEWS:
                NewsType news = new NewsType();
                news.Title           = "eH-I supports ehBox";
                news.Item            = Encoding.UTF8.GetBytes(msg);
                news.ItemElementName = ItemChoiceType1.EncryptableTextContent;
                news.MimeType        = "text/plain";
                publishMessage.ContentContext.Content.Item = news;
                break;

            case ContentInfoTypeContentType.DOCUMENT:
                DocumentType doc = new DocumentType();
                doc.Title            = "eH-I supports ehBox";
                doc.Item             = Encoding.UTF8.GetBytes(msg);
                doc.ItemElementName  = ItemChoiceType.EncryptableTextContent;
                doc.MimeType         = "text/plain";
                doc.DownloadFileName = "msg.txt";
                publishMessage.ContentContext.Content.Item = doc;
                break;
            }
            publishMessage.ContentContext.ContentSpecification                    = new ContentSpecificationType();
            publishMessage.ContentContext.ContentSpecification.IsImportant        = false;
            publishMessage.ContentContext.ContentSpecification.IsEncrypted        = false;
            publishMessage.ContentContext.ContentSpecification.PublicationReceipt = true;
            publishMessage.ContentContext.ContentSpecification.ReceivedReceipt    = true;
            publishMessage.ContentContext.ContentSpecification.ReadReceipt        = true;
            publishMessage.ContentContext.ContentSpecification.ApplicationName    = "eH-I";

            //Publish the news.
            SendMessageResponse publishResp = publish.sendMessage(publishMessage);

            //check the publish response
            Assert.AreEqual("100", publishResp.Status.Code);

            //Check if the message is received.
            GetMessageAcknowledgmentsStatusRequestType ackReq = new GetMessageAcknowledgmentsStatusRequestType();

            ackReq.MessageId  = publishResp.Id;
            ackReq.StartIndex = 1;
            ackReq.EndIndex   = 100;

            //Loop until the new is received.
            int  loop    = 0;
            bool arrived = false;

            while (loop < 8 && !arrived)
            {
                //Give eHealth some time (each time a little more)
                System.Threading.Thread.Sleep(new TimeSpan(0, 0, Fibonacci(loop++)));

                //Get the status
                GetMessageAcknowledgmentsStatusResponseType ackResp = consult.getMessageAcknowledgmentsStatus(ackReq);

                //check the publish response
                Assert.AreEqual("100", ackResp.Status.Code);

                arrived = true;
                //check if all recipients to see if there is one missing
                foreach (GetMessageAcknowledgmentsStatusResponseTypeRow ack in ackResp.AcknowledgmentsStatus)
                {
                    if (!ack.ReceivedSpecified)
                    {
                        arrived = false;
                    }
                }
            }

            return(publishResp.Id);
        }