private ICapabilityStatementBuilder SyncProfile(string resourceType, bool disableCacheRefresh) { EnsureArg.IsNotNullOrEmpty(resourceType, nameof(resourceType)); EnsureArg.IsTrue(_modelInfoProvider.IsKnownResource(resourceType), nameof(resourceType), x => GenerateTypeErrorMessage(x, resourceType)); ApplyToResource(resourceType, resourceComponent => { var supportedProfiles = _supportedProfiles.GetSupportedProfiles(resourceType, disableCacheRefresh); if (supportedProfiles != null) { if (!_modelInfoProvider.Version.Equals(FhirSpecification.Stu3)) { resourceComponent.SupportedProfile.Clear(); foreach (var profile in supportedProfiles) { resourceComponent.SupportedProfile.Add(profile); } } else { foreach (var profile in supportedProfiles) { _statement.Profile.Add(new ReferenceComponent { Reference = profile, }); } } } }); return(this); }
public ICapabilityStatementBuilder ApplyToResource(string resourceType, Action <ListedResourceComponent> action) { EnsureArg.IsNotNullOrEmpty(resourceType, nameof(resourceType)); EnsureArg.IsNotNull(action, nameof(action)); EnsureArg.IsTrue(_modelInfoProvider.IsKnownResource(resourceType), nameof(resourceType), x => GenerateTypeErrorMessage(x, resourceType)); ListedRestComponent listedRestComponent = _statement.Rest.Server(); ListedResourceComponent resourceComponent = listedRestComponent.Resource.SingleOrDefault(x => string.Equals(x.Type, resourceType, StringComparison.OrdinalIgnoreCase)); if (resourceComponent == null) { resourceComponent = new ListedResourceComponent { Type = resourceType, Profile = new ReferenceComponent { Reference = $"http://hl7.org/fhir/StructureDefinition/{resourceType}", }, }; listedRestComponent.Resource.Add(resourceComponent); } action(resourceComponent); return(this); }
public string GetETag(ResourceType resourceType, IEnumerable <VersionedInstanceIdentifier> retrieveInstances) { EnsureArg.IsTrue( resourceType == ResourceType.Study || resourceType == ResourceType.Series || resourceType == ResourceType.Instance, nameof(resourceType)); EnsureArg.IsNotNull(retrieveInstances); EnsureArg.IsTrue(retrieveInstances.Any()); string eTag = string.Empty; long maxWatermark = retrieveInstances.Max(ri => ri.Version); switch (resourceType) { case ResourceType.Study: case ResourceType.Series: int countInstances = retrieveInstances.Count(); eTag = $"{maxWatermark}-{countInstances}"; break; case ResourceType.Instance: eTag = maxWatermark.ToString(); break; default: break; } return(eTag); }
public Product(string name, decimal price) { EnsureArg.IsNotNullOrWhiteSpace(name, "", options => options.WithMessage("The product must have a name.")); EnsureArg.IsTrue(price > 0.0m, "", options => options.WithMessage("The item must have a price greater then 0.")); Name = name; Price = price; }
private static string CamelCase(string str) { EnsureArg.IsNotEmpty(str, nameof(str)); EnsureArg.IsTrue(str.Length > 1, nameof(str)); return(string.Concat(char.ToLowerInvariant(str[0]), str.Substring(1))); }
public bool IsDue(DateTime fromUtc, DateTime toUtc) { EnsureArg.IsTrue(fromUtc.Kind == DateTimeKind.Utc); EnsureArg.IsTrue(toUtc.Kind == DateTimeKind.Utc); EnsureArg.IsTrue(fromUtc < toUtc); return(this.cronExpression.GetOccurrences(fromUtc, toUtc, true)?.Any() == true); }
/// <summary> /// Initializes a new instance of the <see cref="CompartmentSearchExpression"/> class. /// </summary> /// <param name="compartmentType">The compartment type.</param> /// <param name="compartmentId">The compartment id.</param> public CompartmentSearchExpression(string compartmentType, string compartmentId) { EnsureArg.IsTrue(ModelInfoProvider.IsKnownCompartmentType(compartmentType), nameof(compartmentType)); EnsureArg.IsNotNullOrWhiteSpace(compartmentId, nameof(compartmentId)); CompartmentType = compartmentType; CompartmentId = compartmentId; }
/// <summary> /// Initializes a new instance of the <see cref="CompartmentSearchExpression"/> class. /// </summary> /// <param name="compartmentType">The compartment type.</param> /// <param name="compartmentId">The compartment id.</param> public CompartmentSearchExpression(CompartmentType compartmentType, string compartmentId) { EnsureArg.IsTrue(Enum.IsDefined(typeof(CompartmentType), compartmentType), nameof(compartmentType)); EnsureArg.IsNotNullOrWhiteSpace(compartmentId, nameof(compartmentId)); CompartmentType = compartmentType; CompartmentId = compartmentId; }
/// <summary> /// Initializes a new instance of the <see cref="StreamOriginatedDicomInstanceEntry"/> class. /// </summary> /// <param name="seekableStream">The stream.</param> /// <remarks>The <paramref name="seekableStream"/> must be seekable.</remarks> internal StreamOriginatedDicomInstanceEntry(Stream seekableStream) { // The stream must be seekable. EnsureArg.IsNotNull(seekableStream, nameof(seekableStream)); EnsureArg.IsTrue(seekableStream.CanSeek, nameof(seekableStream)); _stream = seekableStream; }
/// <summary> /// Initializes a new instance of the <see cref="MultiaryExpression"/> class. /// </summary> /// <param name="multiaryOperation">The multiary operator type.</param> /// <param name="expressions">The expressions.</param> public MultiaryExpression(MultiaryOperator multiaryOperation, IReadOnlyList <Expression> expressions) { EnsureArg.IsNotNull(expressions, nameof(expressions)); EnsureArg.IsTrue(expressions.Any(), nameof(expressions)); EnsureArg.IsTrue(expressions.All(o => o != null), nameof(expressions)); MultiaryOperation = multiaryOperation; Expressions = expressions; }
/// <summary> /// Initializes a new instance of the <see cref="CompartmentSearchExpression"/> class. /// </summary> /// <param name="compartmentType">The compartment type.</param> /// <param name="compartmentId">The compartment id.</param> /// <param name="filteredResourceTypes">Resource types to filter</param> public CompartmentSearchExpression(string compartmentType, string compartmentId, params string[] filteredResourceTypes) { EnsureArg.IsTrue(ModelInfoProvider.IsKnownCompartmentType(compartmentType), nameof(compartmentType)); EnsureArg.IsNotNullOrWhiteSpace(compartmentId, nameof(compartmentId)); CompartmentType = compartmentType; CompartmentId = compartmentId; FilteredResourceTypes = filteredResourceTypes ?? Array.Empty <string>(); }
/// <summary> /// Initializes a new instance of the <see cref="StreamOriginatedDicomInstanceEntry"/> class. /// </summary> /// <param name="seekableStream">The stream.</param> /// <remarks>The <paramref name="seekableStream"/> must be seekable.</remarks> internal StreamOriginatedDicomInstanceEntry(Stream seekableStream) { // The stream must be seekable. EnsureArg.IsNotNull(seekableStream, nameof(seekableStream)); EnsureArg.IsTrue(seekableStream.CanSeek, nameof(seekableStream)); _stream = seekableStream; _dicomFileCache = new AsyncCache <DicomFile>(_ => DicomFile.OpenAsync(_stream, FileReadOption.SkipLargeTags)); }
public static int GetPartitionKey(this IDicomRequestContext dicomRequestContext) { EnsureArg.IsNotNull(dicomRequestContext, nameof(dicomRequestContext)); var partitionKey = dicomRequestContext.DataPartitionEntry?.PartitionKey; EnsureArg.IsTrue(partitionKey.HasValue, nameof(partitionKey)); return(partitionKey.Value); }
public EditPerson(PersonDTO person) { EnsureArg.IsNotNull(person); EnsureArg.IsTrue(person.PersonId > 0); EnsureArg.IsNotNullOrEmpty(person.FirstName); EnsureArg.IsNotNullOrEmpty(person.SurName); EnsureArg.IsNotNullOrEmpty(person.PhoneNumber); EnsureArg.IsDateTime(person.DateOfBirth); PersonDTO = person; }
internal static Task SetSecurityHeaders(object context) { EnsureArg.IsNotNull(context, nameof(context)); EnsureArg.IsTrue(context is HttpContext, nameof(context)); var httpContext = (HttpContext)context; httpContext.Response.Headers.TryAdd(XContentTypeOptions, XContentTypeOptionsValue); return(Task.CompletedTask); }
public void IsTrue_WhenTrueExpression_ShouldNotThrow() { var returnedValue = Ensure.That(true, ParamName).IsTrue(); AssertReturnedAsExpected(returnedValue, true); Action a = () => EnsureArg.IsTrue(true, ParamName); a.ShouldNotThrow(); }
public ResourceKey(string resourceType, string id, string versionId = null) { EnsureArg.IsNotNullOrEmpty(resourceType, nameof(resourceType)); EnsureArg.IsNotNullOrEmpty(id, nameof(id)); EnsureArg.IsTrue(ModelInfo.IsKnownResource(resourceType), nameof(resourceType)); Id = id; VersionId = versionId; ResourceType = resourceType; }
public void IsTrue_WhenFalseExpression_ThrowsArgumentException() { var ex = Assert.Throws <ArgumentException>(() => Ensure.That(false, ParamName).IsTrue()); AssertThrowedAsExpected(ex, ExceptionMessages.Booleans_IsTrueFailed); var ex2 = Assert.Throws <ArgumentException>(() => EnsureArg.IsTrue(false, ParamName)); AssertThrowedAsExpected(ex2, ExceptionMessages.Booleans_IsTrueFailed); }
public static AdAccount For(string value) { EnsureArg.IsNotNullOrEmpty(value, nameof(value)); EnsureArg.IsTrue(value.Contains("\\"), nameof(value)); return(new AdAccount { Domain = value.SubstringTill("\\"), Name = value.SubstringFrom("\\") }); }
protected Entity(TKey id, DateTime creationDate) { EnsureArg.IsNotDefault(id, nameof(id), o => o.WithException(new RequiredArgumentException(nameof(id)))); Id = id; EnsureArg.IsTrue(creationDate.Kind == DateTimeKind.Utc, nameof(creationDate), o => o.WithException(new ArgumentException(nameof(creationDate), "Date must be of type UTC"))); EnsureArg.IsLte(creationDate, DateTime.UtcNow, nameof(creationDate), o => o.WithException(new ArgumentException(nameof(creationDate), "Date must not be in the future"))); CreationDate = creationDate; }
/// <summary> /// Initializes a new instance of the <see cref="TokenSearchValue"/> class. /// </summary> /// <param name="system">The token system value.</param> /// <param name="code">The token code value.</param> /// <param name="text">The display text.</param> public TokenSearchValue(string system, string code, string text) { // Either system or code has to exist. EnsureArg.IsTrue( !string.IsNullOrWhiteSpace(system) || !string.IsNullOrWhiteSpace(code) || !string.IsNullOrWhiteSpace(text)); System = system; Code = code; Text = text; }
public FileSystemVirtualFiles(DirectoryInfo rootDirectoryInfo) { EnsureArg.IsNotNull(rootDirectoryInfo, nameof(rootDirectoryInfo)); EnsureArg.IsTrue( rootDirectoryInfo.Exists, optsFn: options => options.WithMessage( $"Root directory '{rootDirectoryInfo.FullName}' for virtual path does not exist." ) ); RootDirectory = new FileSystemVirtualDirectory(this, NullVirtualDirectory.Instance, rootDirectoryInfo); }
/// <summary> /// Decompress the file (Gzip). /// </summary> /// <param name="sourcePath">Path to the file to decompress.</param> public static void Decompress(string sourcePath, Stream output) { EnsureArg.IsNotNullOrEmpty(sourcePath, nameof(sourcePath)); EnsureArg.IsTrue(File.Exists(sourcePath), nameof(sourcePath)); // source file does not exist using (var source = File.OpenRead(sourcePath)) { if (output != null) { source.Decompress(output); output.Position = 0; } } }
public bool IsDue(DateTime fromUtc, TimeSpan?span = null) { EnsureArg.IsTrue(fromUtc.Kind == DateTimeKind.Utc); span = span ?? TimeSpan.FromMinutes(1); var occurrence = this.cronExpression.GetNextOccurrence(fromUtc, true); if (!occurrence.HasValue) { return(false); } return(occurrence.Value - fromUtc < span); }
/// <summary> /// Encode the given number into a <see cref="Base36"/>string. /// </summary> /// <param name="input">The number to encode.</param> /// <returns>Encoded <paramref name="input"/> as string.</returns> public static string Encode(long input) { EnsureArg.IsTrue(input >= 0, nameof(input)); var arr = Base36Characters.ToCharArray(); var result = new Stack <char>(); while (input != 0) { result.Push(arr[input % 36]); input /= 36; } return(new string(result.ToArray())); }
public IEnumerable <ISearchValue> ConvertTo(object value) { if (value == null) { yield break; } Type type = value.GetType(); EnsureArg.IsTrue(type.IsGenericType && type.GetGenericTypeDefinition() == FhirElementType, nameof(value)); ISystemAndCode systemAndCode = (ISystemAndCode)value; yield return(new TokenSearchValue(systemAndCode.System, systemAndCode.Code, null)); }
public async Task RunAsync(DateTime moment) // TODO: a different token per job is better to cancel individual jobs (+ timeout) { EnsureArg.IsTrue(moment.Kind == DateTimeKind.Utc); if (!this.Options.Enabled) { //this.logger.LogDebug($"job scheduler run not started (enabled={this.Settings.Enabled})"); return; } Interlocked.Increment(ref this.activeCount); await this.ExecuteJobsAsync(moment).AnyContext(); Interlocked.Decrement(ref this.activeCount); }
/// <summary> /// Decompress the file (Gzip) /// </summary> /// <param name="sourcePath">Path to the file to decompress</param> /// <param name="destinationPath">Path to the decompressed file</param> public static void Decompress(string sourcePath, string destinationPath = null) { EnsureArg.IsNotNullOrEmpty(sourcePath, nameof(sourcePath)); EnsureArg.IsTrue(File.Exists(sourcePath), nameof(sourcePath)); // source file does not exist destinationPath ??= sourcePath.SubstringTill("."); using (var source = File.OpenRead(sourcePath)) { using (var destination = File.Create(destinationPath)) { source.Decompress(destination); } } }
private void ValidateSmpConfiguration(SmpConfigurationDetail smpConfiguration) { EnsureArg.IsTrue(smpConfiguration.EncryptAlgorithmKeySize >= 0, nameof(smpConfiguration.EncryptAlgorithmKeySize)); EnsureArg.IsNotNullOrWhiteSpace(smpConfiguration.PartyRole, nameof(smpConfiguration.PartyRole)); EnsureArg.IsNotNullOrWhiteSpace(smpConfiguration.PartyType, nameof(smpConfiguration.PartyType)); EnsureArg.IsNotNullOrWhiteSpace(smpConfiguration.ToPartyId, nameof(smpConfiguration.ToPartyId)); EnsureArg.IsNotNullOrWhiteSpace(smpConfiguration.Url, nameof(smpConfiguration.Url)); if (!String.IsNullOrEmpty(smpConfiguration.EncryptPublicKeyCertificate) && String.IsNullOrEmpty(smpConfiguration.EncryptPublicKeyCertificateName)) { throw new BusinessException( "EncryptPublicKeyCertificateName needs to be provided when EncryptPublicKeyCertificate is not empty!"); } }
public ICapabilityStatementBuilder AddRestInteraction(string resourceType, string interaction) { EnsureArg.IsNotNullOrEmpty(resourceType, nameof(resourceType)); EnsureArg.IsNotNullOrEmpty(interaction, nameof(interaction)); EnsureArg.IsTrue(_modelInfoProvider.IsKnownResource(resourceType), nameof(resourceType), x => GenerateTypeErrorMessage(x, resourceType)); UpdateRestResourceComponent(resourceType, c => { c.Interaction.Add(new ResourceInteractionComponent { Code = interaction, }); }); return(this); }