private static Operation ValidateProto(Operation operation) { GaxPreconditions.CheckNotNull(operation, nameof(operation)); GaxPreconditions.CheckArgument(operation.Error != null, nameof(operation), "Operation must contain an error"); return(operation); }
/// <summary> /// Constructs a new instance of the <see cref="ProjectName"/> resource name class /// from its component parts. /// </summary> /// <param name="projectId">The project ID. Must not be <c>null</c>.</param> public ProjectName(string projectId) { ProjectId = GaxPreconditions.CheckNotNull(projectId, nameof(projectId)); }
/// <summary> /// Detects the language of the specified text synchronously. /// </summary> /// <remarks>This implementation simply delegates to <see cref="DetectLanguages(IEnumerable{string})"/>.</remarks> /// <param name="text">The text to detect the language of. Must not be null.</param> /// <returns>The most likely detected language.</returns> public virtual Detection DetectLanguage(string text) => DetectLanguages(new[] { GaxPreconditions.CheckNotNull(text, nameof(text)) })[0];
/// <summary> /// Creates a <see cref="SessionPoolManager"/> with the specified SpannerSettings and options. /// </summary> /// <param name="options">The options to use. Must not be null.</param> /// <param name="spannerSettings">The SpannerSettings to use. Must not be null.</param> /// <returns>A <see cref="SessionPoolManager"/> with the given options.</returns> public static SessionPoolManager CreateWithSettings(SessionPoolOptions options, SpannerSettings spannerSettings) => new SessionPoolManager(options, GaxPreconditions.CheckNotNull(spannerSettings, nameof(spannerSettings)).Clone(), spannerSettings.Logger ?? Logger.DefaultLogger, CreateClientAsync);
/// <summary> /// Constructs a new instance of the <see cref="SubscriptionName"/> resource name class /// from its component parts. /// </summary> /// <param name="projectId">The project ID. Must not be <c>null</c>.</param> /// <param name="subscriptionId">The subscription ID. Must not be <c>null</c>.</param> public SubscriptionName(string projectId, string subscriptionId) { ProjectId = GaxPreconditions.CheckNotNull(projectId, nameof(projectId)); SubscriptionId = GaxPreconditions.CheckNotNull(subscriptionId, nameof(subscriptionId)); }
/// <summary> /// Constructs a <see cref="KindExpression"/> directly from the name of the kind. /// </summary> /// <param name="name">The name of the kind. Must not be null.</param> public KindExpression(string name) : this() { Name = GaxPreconditions.CheckNotNull(name, nameof(name)); }
internal HttpContextWrapper(HttpContext context) { _context = GaxPreconditions.CheckNotNull(context, nameof(context)); }
/// <inheritdoc /> public override PagedEnumerable <Buckets, Bucket> ListBuckets(string projectId, ListBucketsOptions options = null) { GaxPreconditions.CheckNotNull(projectId, nameof(projectId)); return(new RestPagedEnumerable <BucketsResource.ListRequest, Buckets, Bucket>( () => CreateListBucketsRequest(projectId, options), BucketPageManager.Instance)); }
/// <summary> /// Creates a nested field with the specified schema, and adds it to the schema being built. /// This method simply delegates to <see cref="Add(string, TableSchema, FieldMode, string)"/> after calling <see cref="Build"/> /// on <paramref name="nestedSchema"/>. /// </summary> /// <param name="name">The name of the field. Must be a valid field name.</param> /// <param name="nestedSchema">The schema for the nested field, in the form of a <see cref="TableSchemaBuilder"/>. Must not be null.</param> /// <param name="mode">The mode of the field. Must be a defined member within <see cref="FieldMode"/>.</param> /// <param name="description">The description of the field. May be null.</param> public void Add(string name, TableSchemaBuilder nestedSchema, FieldMode mode = FieldMode.Nullable, string description = null) { var builtSchema = GaxPreconditions.CheckNotNull(nestedSchema, nameof(nestedSchema)).Build(); Add(name, builtSchema, mode, description); }
/// <summary> /// Creates a <see cref="BigtableClient"/> which uses the specified channel for remote operations. /// </summary> /// <param name="channel">The <see cref="Channel"/> for remote operations. Must not be null.</param> /// <param name="settings">Optional <see cref="BigtableSettings"/>.</param> /// <returns>The created <see cref="BigtableClient"/>.</returns> public static BigtableClient Create(Channel channel, BigtableSettings settings = null) { GaxPreconditions.CheckNotNull(channel, nameof(channel)); Bigtable.BigtableClient grpcClient = new Bigtable.BigtableClient(channel); return(new BigtableClientImpl(grpcClient, settings)); }
/// <param name="client">The trace client that will push traces to the Stackdriver Trace API.</param> internal GrpcTraceConsumer(Task <TraceServiceClient> client) { _clientTask = GaxPreconditions.CheckNotNull(client, nameof(client)); }
/// <summary> /// Creates a <see cref="ErrorStatsServiceClient"/> which uses the specified channel for remote operations. /// </summary> /// <param name="channel">The <see cref="Channel"/> for remote operations. Must not be null.</param> /// <param name="settings">Optional <see cref="ErrorStatsServiceSettings"/>.</param> /// <returns>The created <see cref="ErrorStatsServiceClient"/>.</returns> public static ErrorStatsServiceClient Create(Channel channel, ErrorStatsServiceSettings settings = null) { GaxPreconditions.CheckNotNull(channel, nameof(channel)); ErrorStatsService.ErrorStatsServiceClient grpcClient = new ErrorStatsService.ErrorStatsServiceClient(channel); return(new ErrorStatsServiceClientImpl(grpcClient, settings)); }
internal SpannerBatchCommand(SpannerTransaction transaction) { Transaction = GaxPreconditions.CheckNotNull(transaction, nameof(transaction)); Connection = transaction.SpannerConnection; // Never null }
internal SpannerBatchCommand(SpannerConnection connection) { Connection = GaxPreconditions.CheckNotNull(connection, nameof(connection)); }
internal GoogleExceptionLogger(IContextExceptionLogger logger) { _logger = GaxPreconditions.CheckNotNull(logger, nameof(logger)); }
/// <summary> /// Adds the given field to the schema being built. /// </summary> /// <param name="field">The field to add. Must not be null.</param> public void Add(TableFieldSchema field) { GaxPreconditions.CheckNotNull(field, nameof(field)); _fields.Add(field); }
/// <summary> /// Constructs the media URL of an object from its bucket and name. This does not include the generation /// or any GaxPreconditions. The returned string will always have a query parameter, so later query parameters /// can unconditionally be appended with an "&" prefix. /// </summary> private static string GetBaseUri(string bucket, string objectName) { ValidateBucketName(bucket); GaxPreconditions.CheckNotNull(objectName, nameof(objectName)); return($"https://www.googleapis.com/download/storage/v1/b/{bucket}/o/{Uri.EscapeDataString(objectName)}?alt=media"); }
internal static void ValidateFieldName(string name, string paramName) { GaxPreconditions.CheckNotNull(name, paramName); GaxPreconditions.CheckArgument(s_fieldNamePattern.IsMatch(name), paramName, "Invalid field name '{0}'", name); }
/// <inheritdoc /> public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { GaxPreconditions.CheckNotNull(formatter, nameof(formatter)); if (!IsEnabled(logLevel)) { return; } string message = formatter(state, exception); if (string.IsNullOrEmpty(message)) { return; } var jsonStruct = new Struct(); jsonStruct.Fields.Add("message", Value.ForString(message)); jsonStruct.Fields.Add("log_name", Value.ForString(_logName)); if (eventId.Id != 0 || eventId.Name != null) { var eventStruct = new Struct(); if (eventId.Id != 0) { eventStruct.Fields.Add("id", Value.ForNumber(eventId.Id)); } if (!string.IsNullOrWhiteSpace(eventId.Name)) { eventStruct.Fields.Add("name", Value.ForString(eventId.Name)); } jsonStruct.Fields.Add("event_id", Value.ForStruct(eventStruct)); } // If we have format params and its more than just the original message add them. if (state is IEnumerable <KeyValuePair <string, object> > formatParams && !(formatParams.Count() == 1 && formatParams.Single().Key.Equals("{OriginalFormat}"))) { var paramStruct = new Struct(); foreach (var pair in formatParams) { // Consider adding formatting support for values that are IFormattable. paramStruct.Fields[pair.Key] = Value.ForString(pair.Value?.ToString() ?? ""); } if (paramStruct.Fields.Count > 0) { jsonStruct.Fields.Add("format_parameters", Value.ForStruct(paramStruct)); } } var currentLogScope = GoogleLoggerScope.Current; if (currentLogScope != null) { jsonStruct.Fields.Add("scope", Value.ForString(currentLogScope.ToString())); } // Create a map of format parameters of all the parent scopes, // starting from the most inner scope to the top-level scope. var scopeParamsList = new List <Value>(); while (currentLogScope != null) { // Determine if the state of the scope are format params if (currentLogScope.State is FormattedLogValues scopeFormatParams) { var scopeParams = new Struct(); foreach (var pair in scopeFormatParams) { scopeParams.Fields[pair.Key] = Value.ForString(pair.Value?.ToString() ?? ""); } scopeParamsList.Add(Value.ForStruct(scopeParams)); } currentLogScope = currentLogScope.Parent; } if (scopeParamsList.Count > 0) { jsonStruct.Fields.Add("parent_scopes", Value.ForList(scopeParamsList.ToArray())); } Dictionary <string, string> labels; var labelProviders = GetLabelProviders()?.ToArray(); if (labelProviders?.Length > 0) { // Create a copy of the labels from the options and invoke each provider labels = _loggerOptions.Labels.ToDictionary(kvp => kvp.Key, kvp => kvp.Value); foreach (var provider in labelProviders) { provider.Invoke(labels); } } else { labels = _loggerOptions.Labels; } LogEntry entry = new LogEntry { Resource = _loggerOptions.MonitoredResource, LogName = _fullLogName, Severity = logLevel.ToLogSeverity(), Timestamp = Timestamp.FromDateTime(_clock.GetCurrentDateTimeUtc()), JsonPayload = jsonStruct, Labels = { labels }, Trace = GetTraceName() ?? "", }; _consumer.Receive(new[] { entry }); }
/// <summary> /// Creates an instance from a Protobuf <see cref="wkt::Timestamp"/> representation. /// Later modifications to the Protobuf representation will not affect the returned oject. /// </summary> /// <param name="proto">A Protobuf timestamp representation. Must not be null.</param> /// <returns>An immutable timestamp.</returns> public static Timestamp FromProto(wkt::Timestamp proto) { GaxPreconditions.CheckNotNull(proto, nameof(proto)); return(new Timestamp(proto.Seconds, proto.Nanos)); }
/// <summary> /// Constructs a new instance of the <see cref="InstanceName"/> resource name class /// from its component parts. /// </summary> /// <param name="projectId">The project ID. Must not be <c>null</c>.</param> /// <param name="instanceId">The instance ID. Must not be <c>null</c>.</param> public InstanceName(string projectId, string instanceId) { ProjectId = GaxPreconditions.CheckNotNull(projectId, nameof(projectId)); InstanceId = GaxPreconditions.CheckNotNull(instanceId, nameof(instanceId)); }
/// <inheritdoc /> protected override void ReceiveWithSemaphoreHeld(IEnumerable <T> items) { GaxPreconditions.CheckNotNull(items, nameof(items)); _items.AddRange(items); }
/// <summary> /// Constructs a new instance of the <see cref="SnapshotName"/> resource name class /// from its component parts. /// </summary> /// <param name="projectId">The project ID. Must not be <c>null</c>.</param> /// <param name="snapshotId">The snapshot ID. Must not be <c>null</c>.</param> public SnapshotName(string projectId, string snapshotId) { ProjectId = GaxPreconditions.CheckNotNull(projectId, nameof(projectId)); SnapshotId = GaxPreconditions.CheckNotNull(snapshotId, nameof(snapshotId)); }
/// <summary> /// Returns an instance that merges the given fields. /// </summary> /// <param name="fieldMask">The fields to merge. An empty array is equivalent to using <see cref="MergeAll"/>. /// Must not be null or contain any empty or null elements. Each field is treated as a dot-separated list of segments. /// </param> /// <returns>An instance that merges the given fields.</returns> public static SetOptions MergeFields(params string[] fieldMask) { GaxPreconditions.CheckNotNull(fieldMask, nameof(fieldMask)); GaxPreconditions.CheckArgument(fieldMask.All(x => !string.IsNullOrEmpty(x)), nameof(fieldMask), "Field mask must not contain any null or empty elements"); return(new SetOptions(true, fieldMask.Select(field => FieldPath.FromDotSeparatedString(field)).ToArray())); }
/// <summary> /// Constructs a new instance of the <see cref="TopicName"/> resource name class /// from its component parts. /// </summary> /// <param name="projectId">The project ID. Must not be <c>null</c>.</param> /// <param name="topicId">The topic ID. Must not be <c>null</c>.</param> public TopicName(string projectId, string topicId) { ProjectId = GaxPreconditions.CheckNotNull(projectId, nameof(projectId)); TopicId = GaxPreconditions.CheckNotNull(topicId, nameof(topicId)); }
/// <summary> /// Create a new instance of <see cref="ErrorReportingExceptionLoggerMiddleware"/>. /// </summary> /// <param name="next">The next request delegate. Cannot be null.</param> /// <param name="logger">A logger that will report exceptions. Cannot be null.</param> public ErrorReportingExceptionLoggerMiddleware(RequestDelegate next, IExceptionLogger logger) { _next = GaxPreconditions.CheckNotNull(next, nameof(next)); _logger = GaxPreconditions.CheckNotNull(logger, nameof(logger)); }
public EphemeralTransaction(SpannerConnection connection, Logger logger) { GaxPreconditions.CheckNotNull(connection, nameof(connection)); _connection = connection; Logger = logger ?? Logger.DefaultLogger; }
/// <summary> /// Constructs a new instance from the given sequence of responses. This constructor /// is only present to facilitate testing; application code will normally obtain instances /// of this class by calling <see cref="DatastoreDb.RunQuery"/>. /// </summary> /// <remarks> /// The sequence of responses will be returned directly from <see cref="AsResponses"/>, and /// used to lazily construct the other sequences returned by this class. It should not /// contain any null references. /// </remarks> /// <param name="responses">The responses to return.</param> public DatastoreAsyncQueryResults(IAsyncEnumerable <RunQueryResponse> responses) { _responses = GaxPreconditions.CheckNotNull(responses, nameof(responses)); }
/// <summary> /// Detects the language of the specified text asynchronously. /// </summary> /// <remarks>This implementation simply delegates to <see cref="DetectLanguagesAsync(IEnumerable{string}, CancellationToken)"/>.</remarks> /// <param name="text">The text to detect the language of. Must not be null.</param> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <returns>The most likely detected language.</returns> public virtual async Task <Detection> DetectLanguageAsync(string text, CancellationToken cancellationToken = default) => (await DetectLanguagesAsync(new[] { GaxPreconditions.CheckNotNull(text, nameof(text)) }, cancellationToken) .ConfigureAwait(false))[0];
/// <summary> /// Configures the data protection system to protect keys with specified key in Google Cloud KMS. /// </summary> /// <param name="builder">The data protection builder to configure. Must not be null.</param> /// <param name="keyName">The name of the KMS key to use. Must not be null.</param> /// <returns>The same builder, for chaining purposes.</returns> public static IDataProtectionBuilder ProtectKeysWithGoogleKms( this IDataProtectionBuilder builder, string keyName) => ProtectKeysWithGoogleKms(builder, CryptoKeyName.Parse(GaxPreconditions.CheckNotNull(keyName, nameof(keyName))), null);