示例#1
0
        /// <summary>
        /// Is the gate applicable for the current context
        /// </summary>
        /// <param name="gate">gate to check</param>
        /// <returns>true if applicable, false otherwise</returns>
        public bool IsGateApplicable(IGate gate)
        {
            if (!Code.ValidateArgument(gate, nameof(gate), TaggingUtilities.ReserveTag(0x2382104a /* tag_967bk */)) ||
                !Code.ValidateNotNullOrWhiteSpaceArgument(gate.Name, nameof(gate.Name), TaggingUtilities.ReserveTag(0x2382104b /* tag_967bl */)))
            {
                return(false);
            }

            if (IsKnownApplicableGate(gate.Name))
            {
                return(true);
            }

            if (IsKnownBlockedGate(gate.Name))
            {
                return(false);
            }

            bool grantAccess = IsGateApplicableInternal(gate);

            if (grantAccess)
            {
                KnownApplicableGates.AddOrUpdate(gate.Name, _ => 0, (_, __) => 0);
            }
            else
            {
                KnownBlockedGates.AddOrUpdate(gate.Name, _ => 0, (_, __) => 0);
            }

            return(grantAccess);
        }
示例#2
0
        /// <summary>
        /// Executes the async call and logs errors to ULS.
        /// </summary>
        /// <param name="tagId">ULS tag. Should be auto generated by git tagger, no need to specify.</param>
        /// <param name="asyncFunc">Async delegate etc.</param>
        /// <param name="caller">Caller function name. No need to specify explicitly, will be set automatically on run time.</param>
        /// <returns>The a task of type T.</returns>
        public static async Task ExecuteAndLogAsync(
            uint tagId,
            Func <Task> asyncFunc,
            [CallerMemberName] string caller = null)
        {
            Code.ExpectsArgument(asyncFunc, nameof(asyncFunc), TaggingUtilities.ReserveTag(0x2381b1e0 /* tag_961h6 */));

            try
            {
                await asyncFunc().ConfigureAwait(false);
            }
            catch (DocumentClientException exception)
            {
                ULSLogging.ReportExceptionTag(
                    tagId, Categories.DocumentDb, exception, $"Operation: {caller} {exception.ToErrorMessage()}");

                throw;
            }
            catch (Exception exception)
            {
                ULSLogging.ReportExceptionTag(tagId, Categories.DocumentDb, exception,
                                              $"Exception detected. Caller: {caller} Error: {exception.Message}.");

                throw;
            }
        }
示例#3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="endpoint">Document db endpoint.</param>
        /// <param name="key">Document db key.</param>
        public DocumentDbSecureSettings(string endpoint, SecureString key) : base(endpoint)
        {
            Code.ExpectsArgument(key, nameof(key), TaggingUtilities.ReserveTag(0x2381b149 /* tag_961fj */));

            SecureKey = key;
            m_lazyKey = new Lazy <string>(() => SecureKey.ToPlainText(), LazyThreadSafetyMode.ExecutionAndPublication);
        }
示例#4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="file">File adaptor</param>
        /// <param name="folder">Folder</param>
        /// <param name="name">File Name including extension</param>
        public FileResource(IFile file, string folder, string name)
        {
            File   = Code.ExpectsArgument(file, nameof(file), TaggingUtilities.ReserveTag(0x238208d2 /* tag_9669s */));
            Folder = Code.ExpectsNotNullOrWhiteSpaceArgument(folder, nameof(folder), TaggingUtilities.ReserveTag(0x238208d3 /* tag_9669t */));
            Name   = Code.ExpectsNotNullOrWhiteSpaceArgument(name, nameof(name), TaggingUtilities.ReserveTag(0x238208d4 /* tag_9669u */));

            bool locationSet = false;

            try
            {
                if (!HasInvalidPathChars(Folder) && !HasInvalidPathChars(Name))
                {
                    Location    = Path.Combine(Folder, Name);
                    locationSet = true;
                }
                else
                {
                    ULSLogging.LogTraceTag(0x238208d5 /* tag_9669v */, Categories.ConfigurationDataSet, Levels.Error,
                                           "Failed to combine FileResource.Location for folder: '{0}', name: '{1}'", Folder, Name);
                }
            }
            catch (ArgumentException exception)
            {
                ULSLogging.ReportExceptionTag(0x238208d6 /* tag_9669w */, Categories.ConfigurationDataSet, exception,
                                              "Exception constructing FileResource for folder: '{0}', name: '{1}'", Folder, Name);
            }

            if (!locationSet)
            {
                Location = Name;
            }
        }
示例#5
0
        /// <summary>
        /// Add data to the current correlation
        /// </summary>
        /// <remarks>If there is no current correlation, starts a new correlation</remarks>
        /// <param name="key">key (name) of the correlation</param>
        /// <param name="value">value of the added correlation data</param>
        public void CorrelationAdd(string key, string value)
        {
            Code.ExpectsNotNullOrWhiteSpaceArgument(key, nameof(key), TaggingUtilities.ReserveTag(0x2381771e /* tag_96x24 */));
            Code.ExpectsNotNullOrWhiteSpaceArgument(value, nameof(value), TaggingUtilities.ReserveTag(0x2381771f /* tag_96x25 */));

            CorrelationData data = CurrentCorrelation;

            if (data == null)
            {
                CorrelationStart(null);
                data = CurrentCorrelation;
            }

            if (data != null)
            {
                string oldData = data.Data(key);

                CorrelationHandler.CorrelationAdd(key, value, data);

                EventHandler <CorrelationEventArgs> correlationDataAdded = CorrelationDataAdded;
                if (correlationDataAdded != null)
                {
                    correlationDataAdded(this, new CorrelationEventArgs(data, key, oldData));
                }
            }
        }
示例#6
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="scopeName">Strongy typed cope name</param>
        /// <param name="classification">Failure classification</param>
        public TimedScopeInstanceName(TimedScopeName scopeName, TimedScopeResult classification)
        {
            Code.ExpectsArgument(scopeName, nameof(scopeName), TaggingUtilities.ReserveTag(0x23817705 /* tag_96x2f */));

            CompleteScopeName = scopeName;
            Classification    = classification;
        }
示例#7
0
        /// <summary>
        /// Converts document to specified type.
        /// </summary>
        /// <param name="document">Document db document.</param>
        /// <param name="jsonSerializerSettings">Json serialization settings.</param>
        /// <returns>Deserialized object of specified type T</returns>
        public static T ConvertTo <T>(
            this Document document, JsonSerializerSettings jsonSerializerSettings = null)
        {
            Code.ExpectsArgument(document, nameof(document), TaggingUtilities.ReserveTag(0x2381b144 /* tag_961fe */));

            return(JsonConvert.DeserializeObject <T>(document.ToString(), jsonSerializerSettings));
        }
示例#8
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="cache">The cache object.</param>
        /// <param name="resourceMonitor">Resource Watcher instance</param>
        /// <param name="dataSetOverride">The data set override.</param>
        protected ConfigurationDataSetLoader(ICache cache, IResourceMonitor resourceMonitor, T dataSetOverride = null)
        {
            Cache             = Code.ExpectsArgument(cache, nameof(cache), TaggingUtilities.ReserveTag(0x238208d9 /* tag_9669z */));
            m_resourceMonitor = Code.ExpectsArgument(resourceMonitor, nameof(resourceMonitor), TaggingUtilities.ReserveTag(0x23821000 /* tag_967aa */));

            DataSetOverride = dataSetOverride;
        }
示例#9
0
        /// <summary>
        /// Start monitoring the resources.
        /// </summary>
        /// <param name="resourcesToMonitor">The resources to be monitored.</param>
        /// <param name="callbackAction">Handler to call when any of the resources is uptdated</param>
        /// <returns><c>true</c> if the operation succeeded; <c>false</c> otherwise.</returns>
        public bool TryStartMonitoring(IEnumerable <IResource> resourcesToMonitor, ResourceUpdatedHandler callbackAction)
        {
            if (!Code.ValidateArgument(resourcesToMonitor, nameof(resourcesToMonitor), TaggingUtilities.ReserveTag(0x238208c9 /* tag_9669j */)) ||
                !Code.ValidateArgument(callbackAction, nameof(callbackAction), TaggingUtilities.ReserveTag(0x238208ca /* tag_9669k */)))
            {
                return(false);
            }

            IList <IResource>      resources      = resourcesToMonitor.ToList();
            ResourceMonitoringData monitoringData = new ResourceMonitoringData(callbackAction, resources);

            if (!TryPerformInitialLoad(resources, monitoringData))
            {
                return(false);
            }

            if (!m_resourceMonitoringData.TryAdd(callbackAction, monitoringData))
            {
                return(false);
            }

            foreach (IResource resource in resources)
            {
                if (!resource.IsStatic)
                {
                    m_monitoredResources.TryAdd(resource, true);
                }
            }

            StartExclusiveAction();

            return(true);
        }
示例#10
0
        /// <summary>
        /// Retrieves all groups for the currently logged-in user.
        /// </summary>
        /// <param name="identity">The identity of the logged in user. This value cannot be null.</param>
        /// <returns>The list of user groups.</returns>
        public IEnumerable <string> GetUserGroups(IUserIdentity identity)
        {
            if (!Code.ValidateArgument(identity, nameof(identity), TaggingUtilities.ReserveTag(0x2382109d /* tag_967c3 */)))
            {
                return(Enumerable.Empty <string>());
            }

            ITestGroupsDataSet testGroupsDataSet = GetTestGroupsDataSet();

            if (testGroupsDataSet == null)
            {
                return(Enumerable.Empty <string>());
            }

            if (!identity.IsAuthenticated)
            {
                return(testGroupsDataSet.DefaultGroups);
            }

            IEnumerable <string> result = new List <string>();

            if (!string.IsNullOrWhiteSpace(identity.EmailAddressSignIn))
            {
                result = result.Union(GetUserGroups(identity.EmailAddressSignIn), StringComparer.OrdinalIgnoreCase);
            }

            if (!string.IsNullOrWhiteSpace(identity.EmailAddressPreferred))
            {
                result = result.Union(GetUserGroups(identity.EmailAddressPreferred), StringComparer.OrdinalIgnoreCase);
            }

            return(result);
        }
示例#11
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="item">Item stored in the stack</param>
        /// <param name="parent">Parent of this stack</param>
        private TimedScopeStack(TimedScope item, TimedScopeStack parent)
        {
            Code.ExpectsArgument(parent, nameof(parent), TaggingUtilities.ReserveTag(0x23817061 /* tag_96xb7 */));

            Item   = item;
            Parent = parent;
        }
示例#12
0
        /// <summary>
        /// Document db settings class.
        /// </summary>
        protected DocumentDbSettings(string endpoint, DocumentDbSettingsConfig config = null)
        {
            Code.ExpectsNotNullOrWhiteSpaceArgument(endpoint, nameof(endpoint), TaggingUtilities.ReserveTag(0x2381b146 /* tag_961fg */));

            Endpoint = new Uri(endpoint);
            Config   = config;
        }
示例#13
0
        /// <summary>
        /// A constructor
        /// </summary>
        /// <param name="handler">A handler to be called when resources are updated</param>
        /// <param name="resources">A set of resources to be monitored</param>
        public ResourceMonitoringData(ResourceUpdatedHandler handler, IList <IResource> resources)
        {
            OnSomeOfTrackedResourcesUpdated = Code.ExpectsArgument(handler, nameof(handler), TaggingUtilities.ReserveTag(0x238208c4 /* tag_9669e */));
            m_trackedResources = Code.ExpectsArgument(resources, nameof(resources), TaggingUtilities.ReserveTag(0x238208c5 /* tag_9669f */));

            m_wasCalledAtLeastOnce = false;
        }
示例#14
0
        /// <summary>
        /// Queries all documents in current continuation and returns continuation token for paged requests.
        /// </summary>
        /// <param name="dbId">Database id.</param>
        /// <param name="collectionId">Collection id.</param>
        /// <param name="continuationToken">Continuation token that can be used  to request next page.
        ///  Should be passed as null in the first call.</param>
        /// <param name="feedOptions">Feed options.</param>
        /// <returns>List of objects of specified type returned from specified database and collection.</returns>
        public async Task <Tuple <string, IEnumerable <T> > > GetAllDocumentsWithPagingAsync <T>(
            string dbId,
            string collectionId,
            string continuationToken,
            FeedOptions feedOptions = null)
        {
            Code.ExpectsNotNullOrWhiteSpaceArgument(dbId, nameof(dbId), TaggingUtilities.ReserveTag(0x2381b192 /* tag_961gs */));
            Code.ExpectsNotNullOrWhiteSpaceArgument(collectionId, nameof(collectionId), TaggingUtilities.ReserveTag(0x2381b193 /* tag_961gt */));

            Uri colUri = UriFactory.CreateDocumentCollectionUri(dbId, collectionId);

            feedOptions = feedOptions ?? new FeedOptions();
            feedOptions.RequestContinuation = continuationToken;

            IDocumentClient client = await GetDocumentClientAsync().ConfigureAwait(false);

            try
            {
                using (IDocumentQuery <T> query =
                           client.CreateDocumentQuery <T>(colUri, feedOptions).AsDocumentQuery())
                {
                    FeedResponse <T> page = await DocumentDbAdapter.ExecuteAndLogAsync(
                        0, () => query.ExecuteNextAsync <T>()).ConfigureAwait(false);

                    return(new Tuple <string, IEnumerable <T> >(page.ResponseContinuation, page));
                }
            }
            catch (DocumentClientException e) when(e.StatusCode == HttpStatusCode.NotFound)
            {
                return(new Tuple <string, IEnumerable <T> >(continuationToken, Enumerable.Empty <T>()));
            }
        }
示例#15
0
        /// <summary>
        /// Creates a document and its parent containers (database, collection) if they do not exist.
        /// </summary>
        /// <param name="dbId">Database id.</param>
        /// <param name="collectionId">Collection id.</param>
        /// <param name="document">Object to create.</param>
        /// <param name="partitionKeyField">Request options</param>
        /// <param name="requestOptions">Request options</param>
        /// <param name="disableIdGeneration">Disables automatic id generation</param>
        /// <returns>Created document</returns>
        public async Task <ResourceResponse <Document> > CreateDocumentAndContainersAsync(
            string dbId,
            string collectionId,
            object document,
            string partitionKeyField,
            RequestOptions requestOptions = null,
            bool disableIdGeneration      = false)
        {
            Code.ExpectsNotNullOrWhiteSpaceArgument(dbId, nameof(dbId), TaggingUtilities.ReserveTag(0x2381b161 /* tag_961f7 */));
            Code.ExpectsNotNullOrWhiteSpaceArgument(collectionId, nameof(collectionId), 0);
            Code.ExpectsArgument(document, nameof(document), TaggingUtilities.ReserveTag(0x2381b162 /* tag_961f8 */));

            Uri collectionUri = UriFactory.CreateDocumentCollectionUri(dbId, collectionId);

            IDocumentClient client = await GetDocumentClientAsync().ConfigureAwait(false);

            return(await DocumentDbAdapter.ExecuteAndLogAsync(TaggingUtilities.ReserveTag(0x2381b163 /* tag_961f9 */),
                                                              async() =>
            {
                try
                {
                    return await client.CreateDocumentAsync(collectionUri, document, requestOptions, disableIdGeneration).ConfigureAwait(false);
                }
                catch (DocumentClientException e) when(e.StatusCode == HttpStatusCode.NotFound)
                {
                    // We get NotFound exception either when db and/or collection is not yet created. We create the missing component before retrying to create the document.
                    await GetOrCreateDbAndCollectionAsync(dbId, collectionId, partitionKeyField).ConfigureAwait(false);

                    return await client.CreateDocumentAsync(collectionUri, document, requestOptions, disableIdGeneration).ConfigureAwait(false);
                }
            }).ConfigureAwait(false));
        }
示例#16
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="assembly">assembly containing embedded resource</param>
        /// <param name="resourceName">resource name in assembly</param>
        public EmbeddedResource(Assembly assembly, string resourceName)
        {
            Assembly = Code.ExpectsArgument(assembly, nameof(assembly), TaggingUtilities.ReserveTag(0x238208c0 /* tag_9669a */));
            Name     = Code.ExpectsNotNullOrWhiteSpaceArgument(resourceName, nameof(resourceName), TaggingUtilities.ReserveTag(0x238208c1 /* tag_9669b */));

            ResourceContent = new Lazy <Tuple <ResourceReadStatus, byte[]> >(() =>
            {
                ResourceReadStatus status = ResourceReadStatus.NotFound;
                byte[] content            = null;
                try
                {
                    string resourceContent = Assembly.LoadEmbeddedResourceAsString(Name);
                    if (resourceContent != null)
                    {
                        content = Encoding.UTF8.GetBytes(resourceContent);
                        status  = ResourceReadStatus.Success;
                    }
                }
                catch (Exception ex)
                {
                    ULSLogging.ReportExceptionTag(0x238208c2 /* tag_9669c */, Categories.ConfigurationDataSet, ex,
                                                  "Unable to read resource {resourceName}", resourceName);
                    status = ResourceReadStatus.ReadFailed;
                }

                return(Tuple.Create(status, content));
            }, LazyThreadSafetyMode.PublicationOnly);
        }
示例#17
0
        /// <summary>
        /// Checks if the logged-in user with the specified identity is in one or more of the
        /// specified groups.
        /// </summary>
        /// <param name="identity">The identity of the logged in user. This value cannot be null.</param>
        /// <param name="groupNames">A semicolon-delimited list of group names. This value cannot be null.</param>
        /// <returns>True if the user belongs to one or more of the groups, false otherwise.</returns>
        public bool IsUserInGroups(IUserIdentity identity, string groupNames)
        {
            if (!Code.ValidateNotNullOrWhiteSpaceArgument(groupNames, nameof(groupNames), TaggingUtilities.ReserveTag(0x238210a0 /* tag_967c6 */)) ||
                !Code.ValidateArgument(identity, nameof(identity), TaggingUtilities.ReserveTag(0x238210a1 /* tag_967c7 */)))
            {
                return(false);
            }

            if (!identity.IsAuthenticated)
            {
                return(IsDefault(groupNames));
            }

            if (!string.IsNullOrWhiteSpace(identity.EmailAddressSignIn) && IsUserInGroups(identity.EmailAddressSignIn, groupNames))
            {
                return(true);
            }

            if (!string.IsNullOrWhiteSpace(identity.EmailAddressPreferred) && IsUserInGroups(identity.EmailAddressPreferred, groupNames))
            {
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Logs the scope end
        /// </summary>
        /// <param name="scope">Scope to log</param>
        /// <param name="data">Correlation data</param>
        public void LogScopeEnd(TimedScope scope, CorrelationData data)
        {
            if (!Code.ValidateArgument(scope, nameof(scope), TaggingUtilities.ReserveTag(0x2375d3d8 /* tag_933py */)) ||
                !Code.ValidateArgument(data, nameof(data), TaggingUtilities.ReserveTag(0x2375d3d9 /* tag_933pz */)))
            {
                return;
            }

            if (scope.IsTransaction)
            {
                m_eventSource.LogEvent(Categories.TimingGeneral,
                                       name: scope.Name,
                                       subtype: scope.SubType ?? NullPlaceholder,
                                       metadata: scope.MetaData ?? NullPlaceholder,
                                       serviceName: ServiceName ?? NullPlaceholder,
                                       result: scope.Result,
                                       correlationId: data.VisibleId.ToString("D", CultureInfo.InvariantCulture),
                                       durationMs: scope.DurationInMilliseconds);
            }
            else
            {
                m_eventSource.LogEvent(Categories.TimingGeneral,
                                       name: scope.Name,
                                       subtype: scope.SubType ?? NullPlaceholder,
                                       metadata: scope.MetaData ?? NullPlaceholder,
                                       serviceName: ServiceName ?? NullPlaceholder,
                                       userHash: data.Data(TimedScopeDataKeys.InternalOnly.UserHash) ?? data.UserHash ?? NullPlaceholder,
                                       result: scope.Result,
                                       correlationId: data.VisibleId.ToString("D", CultureInfo.InvariantCulture),
                                       durationMs: scope.DurationInMilliseconds);
            }
        }
示例#19
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="callContextManager">Call context manager</param>
        /// <param name="machineInformation">Machine information</param>
        public TimedScopeStackManager(ICallContextManager callContextManager, IMachineInformation machineInformation)
        {
            Code.ExpectsArgument(callContextManager, nameof(callContextManager), TaggingUtilities.ReserveTag(0x2381705f /* tag_96xb5 */));
            Code.ExpectsArgument(machineInformation, nameof(machineInformation), TaggingUtilities.ReserveTag(0x23817060 /* tag_96xb6 */));

            CallContextManager = callContextManager;
            MachineInformation = machineInformation;
        }
示例#20
0
        /// <summary>
        /// Constructor that copies all fields (except the classification) from a TimedScopeInstanceName.
        /// </summary>
        /// <param name="copyFrom">Object to copy values from</param>
        public TimedScopeName(TimedScopeInstanceName copyFrom)
        {
            Code.ExpectsArgument(copyFrom, nameof(copyFrom), TaggingUtilities.ReserveTag(0x23817703 /* tag_96x2d */));

            Scope    = copyFrom.Scope;
            SubType  = copyFrom.SubType;
            MetaData = copyFrom.MetaData;
        }
示例#21
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="scope">Scope name</param>
        /// <param name="subType">SubType</param>
        /// <param name="metaData">MetaData</param>
        public TimedScopeName(string scope, string subType = null, string metaData = null)
        {
            Code.ExpectsNotNullOrWhiteSpaceArgument(scope, nameof(scope), TaggingUtilities.ReserveTag(0x23817702 /* tag_96x2c */));

            Scope    = scope;
            SubType  = subType;
            MetaData = metaData;
        }
示例#22
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="disabledTimedScopes">Disabled timed scopes</param>
        /// <param name="correlation">Correlation</param>
        public ReplayEventConfigurator(IReplayEventDisabledTimedScopes disabledTimedScopes, Correlation correlation)
        {
            Code.ExpectsArgument(disabledTimedScopes, nameof(disabledTimedScopes), TaggingUtilities.ReserveTag(0x23817714 /* tag_96x2u */));
            Code.ExpectsArgument(correlation, nameof(correlation), TaggingUtilities.ReserveTag(0x23817715 /* tag_96x2v */));

            DisabledTimedScopes = disabledTimedScopes;
            Correlation         = correlation;
        }
示例#23
0
        /// <summary>
        /// Overloaded Constructor that uses the specified document db client instead of creating one.
        /// </summary>
        /// <param name="documentClient">Document db client.</param>
        public DocumentDbAdapter(IDocumentClient documentClient)
        {
            Code.ExpectsArgument(documentClient, nameof(documentClient), TaggingUtilities.ReserveTag(0x2381b1dd /* tag_961h3 */));

            m_DocumentClient = new Lazy <Task <IDocumentClient> >(
                () => Task.FromResult(documentClient),
                LazyThreadSafetyMode.ExecutionAndPublication);
        }
示例#24
0
        /// <summary>
        /// Populates a SerializationInfo with the data needed to serialize the target object.
        /// </summary>
        /// <param name="info">Serialization info</param>
        /// <param name="context">Serialization context - unused</param>
        public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            Code.ExpectsArgument(info, nameof(info), TaggingUtilities.ReserveTag(0x23817741 /* tag_96x3b */));

            info.AddValue(SerializedFieldName, m_store.ToArray(), typeof(KeyValuePair <TKey, TValue>[]));
            info.AddValue(KeyComparerFieldName, m_store.KeyComparer, typeof(IEqualityComparer <TKey>));
            info.AddValue(ValueComparerFieldName, m_store.ValueComparer, typeof(IEqualityComparer <TValue>));
        }
示例#25
0
        /// <summary>
        /// Get a Database by id, or create a new one if one with the id provided doesn't exist.
        /// </summary>
        /// <param name="dbId">The id of the Database to search for, or create.</param>
        /// <param name="requestOptions">Request Options</param>
        /// <returns>The matched, or created, Database object</returns>
        public Task <ResourceResponse <Database> > GetOrCreateDatabaseAsync(
            string dbId, RequestOptions requestOptions = null)
        {
            Code.ExpectsNotNullOrWhiteSpaceArgument(dbId, nameof(dbId), TaggingUtilities.ReserveTag(0x2381b1c7 /* tag_961hh */));

            return(GetOrCreateDatabaseAsync(new Database {
                Id = dbId
            }, requestOptions));
        }
示例#26
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="endpoint">Document db endpoint.</param>
        /// <param name="key">Document db key.</param>
        /// <param name="config">Document db settings config.</param>
        public DocumentDbSettings(string endpoint, string key, DocumentDbSettingsConfig config = null)
        {
            Code.ExpectsNotNullOrWhiteSpaceArgument(endpoint, nameof(endpoint), TaggingUtilities.ReserveTag(0x2381b147 /* tag_961fh */));
            Code.ExpectsNotNullOrWhiteSpaceArgument(key, nameof(key), TaggingUtilities.ReserveTag(0x2381b148 /* tag_961fi */));

            Endpoint = new Uri(endpoint);
            Key      = key;
            Config   = config;
        }
        /// <summary>
        /// Extracts error information from document client exception.
        /// </summary>
        /// <param name="exception">Document client exception.</param>
        /// <returns>Converted error string from document client exception information.</returns>
        public static string ToErrorMessage(this DocumentClientException exception)
        {
            Code.ExpectsArgument(exception, nameof(exception), TaggingUtilities.ReserveTag(0x2381b145 /* tag_961ff */));

            return($"Cost: {exception.RequestCharge}" +
                   $" ContentLocation: {exception.ResponseHeaders["Content-Location"]}" +
                   $"StatusCode: {(int)exception.StatusCode.GetValueOrDefault()} ActivityId: {exception.ActivityId}" +
                   $" Error: {exception.Message}");
        }
示例#28
0
        /// <summary>
        /// Loads the list of experiments
        /// </summary>
        public void Load(IDictionary <string, IExperiment> experiments)
        {
            if (!Code.ValidateArgument(experiments, nameof(experiments), TaggingUtilities.ReserveTag(0x23821082 /* tag_967cc */)))
            {
                return;
            }

            ExperimentsDictionary = experiments;
        }
示例#29
0
        /// <summary>
        /// Converts byte array to string.
        /// </summary>
        /// <param name="input">The input byte array.</param>
        /// <param name="convertToHexString">Indicator to convert the hash to hex string if true, Base64 otherwise.</param>
        /// <returns>Converted string.</returns>
        private static string ConvertToString(byte[] input, bool convertToHexString = false)
        {
            if (!Code.ValidateArgument(input, nameof(input), TaggingUtilities.ReserveTag(0x23820894 /* tag_9668u */)))
            {
                return(null);
            }

            return(convertToHexString ? ConvertToHexString(input) : Convert.ToBase64String(input));
        }
示例#30
0
        /// <summary>
        /// Add version range to range set
        /// </summary>
        public bool AddVersionRange(ProductVersionRange range)
        {
            if (!Code.ValidateArgument(range, nameof(range), TaggingUtilities.ReserveTag(0x23821042 /* tag_967bc */)))
            {
                return(false);
            }

            return(Range.Add(range));
        }