/// <summary>
        /// Validate the Content for this Requested Service
        /// </summary>
        /// <param name="path">The path to this object as a string</param>
        /// <param name="messages">the validation messages, these may be added to within this method</param>
        public void Validate(string path, List <ValidationMessage> messages)
        {
            var vb = new ValidationBuilder(path, messages);

            if (vb.ArgumentRequiredCheck("RequestedServiceDescription", RequestedServiceDescription))
            {
                RequestedServiceDescription.Validate(vb.Path + "RequestedServiceDescription", vb.Messages);
            }

            vb.ArgumentRequiredCheck("ServiceBookingStatus", ServiceBookingStatus);

            if (vb.ArgumentRequiredCheck("ServiceRequester", ServiceRequester))
            {
                ServiceRequester.Validate(vb.Path + "ServiceRequester", vb.Messages);
            }

            vb.ArgumentRequiredCheck("RequestedServiceDateTime", RequestedServiceDateTime);

            if (vb.ArgumentRequiredCheck("RequestIdentifier", RequestIdentifier))
            {
                RequestIdentifier.Validate(vb.Path + "RequestIdentifier", vb.Messages);
            }

            if (vb.ArgumentRequiredCheck("RequestedServiceInstanceIdentifier", RequestedServiceInstanceIdentifier))
            {
                RequestedServiceInstanceIdentifier.Validate(vb.Path + "RequestedServiceInstanceIdentifier", vb.Messages);
            }

            if (vb.ArgumentRequiredCheck("DetailedClinicalModelIdentifier", DetailedClinicalModelIdentifier))
            {
                DetailedClinicalModelIdentifier.Validate(vb.Path + "DetailedClinicalModelIdentifier", vb.Messages);
            }
        }
Пример #2
0
        public object GetInstance(InstanceContext instanceContext, Message message)
        {
            Identifier = new RequestIdentifier();
            var instance = Activator.CreateInstance(_instanceType, new object[] { Identifier });

            return(instance);
        }
Пример #3
0
        private static Tuple <RequestIdentifier, string> GetSeperatedIdsAndVal(string argmentName, string argumentValue)
        {
            // check if \n or space comes first and seperates url from script part
            int indexOfSpace   = argumentValue.IndexOf(' ');
            int indexOfNewLine = argumentValue.IndexOf('\n');

            if (indexOfSpace <= 0 && indexOfNewLine <= 0)
            {
                Tools.Logger.Log("Identifier and script are not correctly seperated by either a space or new line (values ignored), name of the parameter was: " + argmentName, Tools.Logger.LogLevel.error);
                return(null);
            }

            string[] addressAndValue = null;

            if (argumentValue.TrimStart().StartsWith("\""))
            {
                if (argumentValue.Count((c) => c == '"') < 2)
                {
                    Tools.Logger.Log("Identifier starts with \" but misses a second \" to delimit the identifier: " + argmentName, Tools.Logger.LogLevel.error);
                    return(null);
                }

                int idEndIndex = argumentValue.IndexOf('"', 1) - 1;

                string id  = argumentValue.Substring(1, idEndIndex);
                string val = argumentValue.Substring(idEndIndex + 2).TrimStart();

                addressAndValue = new string[] { id, val };
            }
            else
            {
                string splittingChar = "\n";
                if (indexOfSpace <= 0)
                {
                    splittingChar = "\n";
                }
                else if (indexOfNewLine > indexOfSpace)
                {
                    splittingChar = " ";
                }
                addressAndValue = argumentValue.Split(splittingChar.ToCharArray(), 2);
                if (addressAndValue.Length < 2)
                {
                    Tools.Logger.Log("Identifier and script are not correctly seperated by either a space or new line (values ignored), name of the parameter was: " + argmentName, Tools.Logger.LogLevel.error);
                    return(null);
                }
            }

            var ri = new RequestIdentifier(addressAndValue[0]);

            string value = addressAndValue[1];

            return(new Tuple <RequestIdentifier, string>(
                       ri,
                       value
                       ));
        }
Пример #4
0
        public ActionResult SendPDF(string formXml, string xsnName, string viewName, string toEmail, string emailBody)
        {
            var spContext = SharePointContextProvider.Current.GetSharePointContext(System.Web.HttpContext.Current);

            using (var clientContext = spContext.CreateUserClientContextForSPHost())
            {
                SP.User spUser = GetSharePointUser(clientContext);

                string internalUserID = null;

                // Store data for processing
                string            tenantID = TokenHelper.GetRealmFromTargetUrl(new Uri(clientContext.Url));
                RequestIdentifier rid      = RequestUtil.AddRequestEntity(PdfRequestType.SendPDF, PdfRequestStatus.InProgress, tenantID, internalUserID);

                PDFRequest response = new PDFRequest();
                response.RequestID   = rid.ID;
                response.RequestType = PdfRequestType.SendPDF;
                response.Status      = PdfRequestStatus.InProgress;
                response.Message     = "";

                BlobUtil bu = null;
                try
                {
                    bu = new BlobUtil();

                    ParameterCollection plist = new ParameterCollection();
                    plist.Add(Parameters.Api, "SendPDF");
                    plist.Add(Parameters.ViewName, viewName ?? "");
                    plist.Add(Parameters.UserID, internalUserID);
                    plist.Add(Parameters.XsnName, xsnName ?? "");
                    plist.Add(Parameters.FromEmail, spUser.Email ?? "");
                    plist.Add(Parameters.ToEmail, toEmail ?? "");
                    plist.Add(Parameters.EmailBody, emailBody ?? "");

                    BlobCollection bc = new BlobCollection();
                    bc.Add("xml", formXml);
                    bc.Add("parameters", plist);
                    bu.StoreRequestArguments(rid.ID, bc);

                    // post to queue
                    PdfServiceQueues.XmlToHtmlClient.AddMessage(rid.ID, internalUserID);
                }
                catch (Exception ex)
                {
                    // Update request status
                    response.Status  = PdfRequestStatus.Error;
                    response.Message = ex.Message;
                    RequestUtil.UpdateRequestStatus(rid.ID, PdfRequestStatus.Error, ex.Message);
                    //PdfServiceQueues.EmailSendClient.AddErrorMessage(requestID, internalUserID.Value, ex.Message);
                }
                finally
                {
                }
                return(new ObjectResult <PDFRequest>(response));
            }
        }
Пример #5
0
        public object BeforeCall(string operationName, object[] inputs)
        {
            Watch         = Stopwatch.StartNew();
            this.inputs   = inputs;
            OperationName = operationName;
            var serviceInstance = OperationContext.Current.InstanceContext.GetServiceInstance();

            Identifier = (serviceInstance as BaseService).Identifier;
            return(null);
        }
Пример #6
0
        public async Task Invoke(HttpContext context)
        {
            #region 取得 Request
            using (RequestIdentifier.Ensure(context)) {
                context.Items[SettingHelper.Re_quest_Id] = context.Features.Get <IHttpRequestIdentifierFeature>().TraceIdentifier;
                var requestBodyStream   = new MemoryStream();
                var originalRequestBody = context.Request.Body;
                await context.Request.Body.CopyToAsync(requestBodyStream);

                requestBodyStream.Seek(0, SeekOrigin.Begin);
                var requestBodyText = new StreamReader(requestBodyStream).ReadToEnd();
                context.Items[SettingHelper.Re_quest] = requestBodyText;
                requestBodyStream.Seek(0, SeekOrigin.Begin);
                context.Request.Body = requestBodyStream;
                await next(context).ConfigureAwait(false);

                context.Request.Body = originalRequestBody;
            }
            #endregion 取得 Request
        }
        public bool RemoveRessourceRequestHandler(RequestIdentifier ri)
        {
            lock (_locker) {
                int indexToRemove = -1;

                for (int i = 0; i < _ressourceRequestHandlers.Count; i++)
                {
                    var rrh = _ressourceRequestHandlers[i];
                    if (rrh.Equals(ri))
                    {
                        indexToRemove = i;
                        break;
                    }
                }

                if (indexToRemove >= 0)
                {
                    _ressourceRequestHandlers.RemoveAt(indexToRemove);
                    return(true);
                }

                return(false);
            }
        }
Пример #8
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="identifier">The network request identifier.</param>
 public NetworkRequestAttribute( RequestIdentifier identifier )
 {
     this.Identifier = identifier;
 }
Пример #9
0
 public bool Matches(RequestIdentifier identifier)
 {
     Console.WriteLine(identifier.GetMethod() + " " + Method + " " + identifier.GetUrl() + " " + SubURL);
     return(HasRequestMethod(identifier.GetMethod()) && HasSubUrl(identifier.GetUrl()));
 }
        public override IDeepCopyable CopyTo(IDeepCopyable other)
        {
            var dest = other as GuidanceResponse;

            if (dest == null)
            {
                throw new ArgumentException("Can only copy to an object of the same type", "other");
            }

            base.CopyTo(dest);
            if (RequestIdentifier != null)
            {
                dest.RequestIdentifier = (Hl7.Fhir.Model.Identifier)RequestIdentifier.DeepCopy();
            }
            if (Identifier != null)
            {
                dest.Identifier = new List <Hl7.Fhir.Model.Identifier>(Identifier.DeepCopy());
            }
            if (Module != null)
            {
                dest.Module = (Hl7.Fhir.Model.DataType)Module.DeepCopy();
            }
            if (StatusElement != null)
            {
                dest.StatusElement = (Code <Hl7.Fhir.Model.GuidanceResponse.GuidanceResponseStatus>)StatusElement.DeepCopy();
            }
            if (Subject != null)
            {
                dest.Subject = (Hl7.Fhir.Model.ResourceReference)Subject.DeepCopy();
            }
            if (Encounter != null)
            {
                dest.Encounter = (Hl7.Fhir.Model.ResourceReference)Encounter.DeepCopy();
            }
            if (OccurrenceDateTimeElement != null)
            {
                dest.OccurrenceDateTimeElement = (Hl7.Fhir.Model.FhirDateTime)OccurrenceDateTimeElement.DeepCopy();
            }
            if (Performer != null)
            {
                dest.Performer = (Hl7.Fhir.Model.ResourceReference)Performer.DeepCopy();
            }
            if (ReasonCode != null)
            {
                dest.ReasonCode = new List <Hl7.Fhir.Model.CodeableConcept>(ReasonCode.DeepCopy());
            }
            if (ReasonReference != null)
            {
                dest.ReasonReference = new List <Hl7.Fhir.Model.ResourceReference>(ReasonReference.DeepCopy());
            }
            if (Note != null)
            {
                dest.Note = new List <Hl7.Fhir.Model.Annotation>(Note.DeepCopy());
            }
            if (EvaluationMessage != null)
            {
                dest.EvaluationMessage = new List <Hl7.Fhir.Model.ResourceReference>(EvaluationMessage.DeepCopy());
            }
            if (OutputParameters != null)
            {
                dest.OutputParameters = (Hl7.Fhir.Model.ResourceReference)OutputParameters.DeepCopy();
            }
            if (Result != null)
            {
                dest.Result = (Hl7.Fhir.Model.ResourceReference)Result.DeepCopy();
            }
            if (DataRequirement != null)
            {
                dest.DataRequirement = new List <Hl7.Fhir.Model.DataRequirement>(DataRequirement.DeepCopy());
            }
            return(dest);
        }
Пример #11
0
        /// <summary>
        /// Serialize to a JSON object
        /// </summary>
        public new void SerializeJson(Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }

            if (!string.IsNullOrEmpty(ResourceType))
            {
                writer.WriteString("resourceType", (string)ResourceType !);
            }


            ((Fhir.R4.Models.DomainResource) this).SerializeJson(writer, options, false);

            if (RequestIdentifier != null)
            {
                writer.WritePropertyName("requestIdentifier");
                RequestIdentifier.SerializeJson(writer, options);
            }

            if ((Identifier != null) && (Identifier.Count != 0))
            {
                writer.WritePropertyName("identifier");
                writer.WriteStartArray();

                foreach (Identifier valIdentifier in Identifier)
                {
                    valIdentifier.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (!string.IsNullOrEmpty(ModuleUri))
            {
                writer.WriteString("moduleUri", (string)ModuleUri !);
            }

            if (_ModuleUri != null)
            {
                writer.WritePropertyName("_moduleUri");
                _ModuleUri.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(ModuleCanonical))
            {
                writer.WriteString("moduleCanonical", (string)ModuleCanonical !);
            }

            if (_ModuleCanonical != null)
            {
                writer.WritePropertyName("_moduleCanonical");
                _ModuleCanonical.SerializeJson(writer, options);
            }

            if (ModuleCodeableConcept != null)
            {
                writer.WritePropertyName("moduleCodeableConcept");
                ModuleCodeableConcept.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(Status))
            {
                writer.WriteString("status", (string)Status !);
            }

            if (_Status != null)
            {
                writer.WritePropertyName("_status");
                _Status.SerializeJson(writer, options);
            }

            if (Subject != null)
            {
                writer.WritePropertyName("subject");
                Subject.SerializeJson(writer, options);
            }

            if (Encounter != null)
            {
                writer.WritePropertyName("encounter");
                Encounter.SerializeJson(writer, options);
            }

            if (!string.IsNullOrEmpty(OccurrenceDateTime))
            {
                writer.WriteString("occurrenceDateTime", (string)OccurrenceDateTime !);
            }

            if (_OccurrenceDateTime != null)
            {
                writer.WritePropertyName("_occurrenceDateTime");
                _OccurrenceDateTime.SerializeJson(writer, options);
            }

            if (Performer != null)
            {
                writer.WritePropertyName("performer");
                Performer.SerializeJson(writer, options);
            }

            if ((ReasonCode != null) && (ReasonCode.Count != 0))
            {
                writer.WritePropertyName("reasonCode");
                writer.WriteStartArray();

                foreach (CodeableConcept valReasonCode in ReasonCode)
                {
                    valReasonCode.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((ReasonReference != null) && (ReasonReference.Count != 0))
            {
                writer.WritePropertyName("reasonReference");
                writer.WriteStartArray();

                foreach (Reference valReasonReference in ReasonReference)
                {
                    valReasonReference.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((Note != null) && (Note.Count != 0))
            {
                writer.WritePropertyName("note");
                writer.WriteStartArray();

                foreach (Annotation valNote in Note)
                {
                    valNote.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if ((EvaluationMessage != null) && (EvaluationMessage.Count != 0))
            {
                writer.WritePropertyName("evaluationMessage");
                writer.WriteStartArray();

                foreach (Reference valEvaluationMessage in EvaluationMessage)
                {
                    valEvaluationMessage.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (OutputParameters != null)
            {
                writer.WritePropertyName("outputParameters");
                OutputParameters.SerializeJson(writer, options);
            }

            if (Result != null)
            {
                writer.WritePropertyName("result");
                Result.SerializeJson(writer, options);
            }

            if ((DataRequirement != null) && (DataRequirement.Count != 0))
            {
                writer.WritePropertyName("dataRequirement");
                writer.WriteStartArray();

                foreach (DataRequirement valDataRequirement in DataRequirement)
                {
                    valDataRequirement.SerializeJson(writer, options, true);
                }

                writer.WriteEndArray();
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
Пример #12
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="identifier">The network request identifier.</param>
 public NetworkRequestAttribute(RequestIdentifier identifier)
 {
     this.Identifier = identifier;
 }
Пример #13
0
 public TestService(RequestIdentifier requestIdentifier) : base(requestIdentifier)
 {
 }
Пример #14
0
 public BaseService(RequestIdentifier requestIdentifier)
 {
     _requestIdentifier = requestIdentifier;
 }
Пример #15
0
        private void OnUdpReceive(IAsyncResult ar)
        {
            if (!running)
            {
                return;
            }
            var endPoint = new IPEndPoint(IPAddress.Any, 0);
            var data = udp.EndReceive(ar, ref endPoint);
            UdpListen();

            var ms = new MemoryStream(data);
            var protocolVersion = ms.ReadByte();
            if (protocolVersion != ProtocolVersion)
            {
                this.Warn("Ignoring message from {0} with unknown protocol version {1}", endPoint, protocolVersion);
                return;
            }

            var incomingMessage = Serializer.Deserialize<UdpMessage>(ms);

            if (!incomingMessage.Validate(endPoint))
                return;

            var ni = new NodeInformation(endPoint, incomingMessage.SenderNodeId);

            if (incomingMessage.ResponseId != 0)
            {
                var identifier = new RequestIdentifier {EndPoint = ni.EndPoint, RequestId = incomingMessage.ResponseId};

                lock (outstandingRequests)
                {
                    if (!outstandingRequests.ContainsKey(identifier))
                    {
                        this.Warn("{2} from {0} has unknown response ID {1:X16}", endPoint, incomingMessage.ResponseId, incomingMessage.Inspect());
                    }
                    else
                    {
                        var request = outstandingRequests[identifier];

                        if (request.NodeId != null && request.NodeId != incomingMessage.SenderNodeId)
                        {
                            this.Warn("In {0}, node ID from {1} does not match (expected {2}, received {3})", incomingMessage.Inspect(), endPoint, request.NodeId, (KademliaId) incomingMessage.SenderNodeId);
                        }
                        else
                        {
                            outstandingRequests.Remove(identifier);

                            // the callback will deal with handling the actual response
                            request.OutgoingMessage.ResponseCallback(incomingMessage);
                        }
                    }
                }
            }

            if (incomingMessage.PingRequest != null)
            {
                IncomingPing(ni, incomingMessage);
            }
            else if (incomingMessage.FindNodeRequest != null)
            {
                IncomingFindNode(ni, incomingMessage);
            }
            else if (incomingMessage.FindValueRequest != null)
            {
                IncomingFindValue(ni, incomingMessage);
            }
            else if (incomingMessage.StoreRequest != null)
            {
                IncomingStore(ni, incomingMessage);
            }
            else if (incomingMessage.KeepObjectRequest != null)
            {
                IncomingKeepObject(ni, incomingMessage);
            }
        }
Пример #16
0
        /// <summary>Sends an UDP message to a given node.</summary>
        /// <param name="message">The message to be sent.</param>
        /// <param name="target">The address of the target node.</param>
        /// <param name="targetNodeId">The target node ID.</param>
        internal void SendUdpMessage(UdpMessage message, IPEndPoint target, KademliaId targetNodeId)
        {
            message.RequestId = Random.UInt64();
            message.SenderNodeId = Id;

            var requestIdentifier = new RequestIdentifier {EndPoint = target, RequestId = message.RequestId};
            var requestInformation = new RequestInformation {OutgoingMessage = message, SecondAttempt = false, NodeId = targetNodeId};

            if (message.IsRequest)
            {
                lock (outstandingRequests)
                {
                    outstandingRequests.Add(requestIdentifier, requestInformation);
                }
            }

            SendUdp(message, target);
        }