private string ResolvePrimaryServiceRoot(string RequestUri, FhirUri fhirUri) { string RequestRelativePath; if (RequestUri.StripHttp().ToLower().StartsWith(fhirUri.PrimaryServiceRootServers !.OriginalString.StripHttp().ToLower())) { //If the request URL starts with our known servers root then cut it off and return relative part , job done. fhirUri.IsRelativeToServer = true; RequestUri = RequestUri.StripHttp(); string PrimaryServiceRootServers = fhirUri.PrimaryServiceRootServers !.OriginalString.StripHttp(); RequestRelativePath = RequestUri.Substring(PrimaryServiceRootServers.Count(), RequestUri.Count() - PrimaryServiceRootServers.Count()); if (RequestRelativePath.StartsWith("/")) { RequestRelativePath = RequestRelativePath.TrimStart('/'); } return(RequestRelativePath); }
private string ResolvePrimaryServiceRoot(string RequestUri) { string RequestRelativePath; if (RequestUri.StripHttp().ToLower().StartsWith(this.PrimaryServiceRootServers.OriginalString.StripHttp())) //if (RequestUri.ToLower().StartsWith(this.PrimaryServiceRootServers.OriginalString)) { //If the request URL starts with our known servers root then cut it off and return relative part , job done. this.IsRelativeToServer = true; RequestUri = RequestUri.StripHttp(); string PrimaryServiceRootServers = this.PrimaryServiceRootServers.OriginalString.StripHttp(); RequestRelativePath = RequestUri.Substring(PrimaryServiceRootServers.Count(), RequestUri.Count() - PrimaryServiceRootServers.Count()); if (RequestRelativePath.StartsWith("/")) { RequestRelativePath = RequestRelativePath.TrimStart('/'); } return(RequestRelativePath); } else if (RequestUri.ToLower().StartsWith(_HttpName) || RequestUri.ToLower().StartsWith(_HttpsName)) { //If not and the URL starts with 'http' or 'https' then loop through each segment of the URL looking for //a segment that matches to the FHIR Resource name. Once found we can determine the remote root and return the // relative part. this.IsRelativeToServer = false; //string FhirResourceRegexPattern = string.Empty; //string RegexResourceDilimeter = "|"; //FhirResourceRegexPattern += String.Join(RegexResourceDilimeter, ModelInfo.SupportedResources); string RemotePrimaryServiceRoot = string.Empty; var PathSplit = RequestUri.Split('#')[0].Split('/'); foreach (string Segment in PathSplit) { if (IsResourceTypeString(Segment)) { //Resource segment found break; } else if (Segment.StartsWith("$")) { //Operation segment found break; } else if (Segment.ToLower() == _MetadataName) { //metadate segment found break; } RemotePrimaryServiceRoot = String.Join("/", RemotePrimaryServiceRoot, Segment); } RemotePrimaryServiceRoot = RemotePrimaryServiceRoot.TrimStart('/'); //strip off and set the primary root this.PrimaryServiceRootRemote = new Uri(RemotePrimaryServiceRoot); RequestRelativePath = RequestUri.Substring(RemotePrimaryServiceRoot.Count(), RequestUri.Count() - RemotePrimaryServiceRoot.Count()); if (RequestRelativePath.StartsWith("/")) { RequestRelativePath = RequestRelativePath.TrimStart('/'); } return(RequestRelativePath); } else if (RequestUri.ToLower().StartsWith($"{_UrnName}:{_uuidName}:") || RequestUri.ToLower().StartsWith($"{_UrnName}:{_OidName}:")) { this.IsRelativeToServer = false; this.IsUrn = true; if (RequestUri.ToLower().StartsWith($"{_UrnName}:{_uuidName}:")) { this.UrnType = UriSupport.UrnType.uuid; this.Urn = RequestUri; if (!Uuid.IsValidValue(this.Urn)) { ParseErrorMessage = $"The {_UrnName}:{_uuidName} value given is not valid: {this.Urn}"; ErrorInParseing = true; return(string.Empty); } } if (RequestUri.ToLower().StartsWith($"{_UrnName}:{_OidName}:")) { this.UrnType = UriSupport.UrnType.oid; this.Urn = RequestUri; if (!Oid.IsValidValue(this.Urn)) { ParseErrorMessage = $"The {_UrnName}:{_OidName} value given is not valid: {this.Urn}"; ErrorInParseing = true; return(string.Empty); } } RequestRelativePath = RequestUri.Substring(this.Urn.Count(), RequestUri.Count() - this.Urn.Count()); return(RequestRelativePath); } else { //The path has not Primary root and is a relative URI this.IsRelativeToServer = true; RequestRelativePath = RequestUri; return(RequestRelativePath); } }