Пример #1
0
 /// <summary>Creates a clone of this proxy, with a new identity and optionally other options. The clone
 /// is identical to this proxy except for its identity and other options set through parameters.</summary>
 /// <param name="prx">The source proxy.</param>
 /// <param name="identity">The identity of the clone.</param>
 /// <param name="factory">The proxy factory used to manufacture the clone.</param>
 /// <param name="adapterId">The adapter ID of the clone (optional).</param>
 /// <param name="cacheConnection">Determines whether or not the clone caches its connection (optional).</param>
 /// <param name="clearLocator">When set to true, the clone does not have an associated locator proxy (optional).
 /// </param>
 /// <param name="clearRouter">When set to true, the clone does not have an associated router proxy (optional).
 /// </param>
 /// <param name="collocationOptimized">Determines whether or not the clone can use collocation optimization
 /// (optional).</param>
 /// <param name="compress">Determines whether or not the clone compresses requests (optional).</param>
 /// <param name="connectionId">The connection ID of the clone (optional).</param>
 /// <param name="connectionTimeout">The connection timeout of the clone (optional).</param>
 /// <param name="context">The context of the clone (optional).</param>
 /// <param name="encoding">The encoding of the clone (optional).</param>
 /// <param name="endpointSelection">The encoding selection policy of the clone (optional).</param>
 /// <param name="endpoints">The endpoints of the clone (optional).</param>
 /// <param name="facet">The facet of the clone (optional).</param>
 /// <param name="fixedConnection">The connection of the clone (optional). When specified, the clone is a fixed
 /// proxy. You can clone a non-fixed proxy into a fixed proxy but not vice-versa.</param>
 /// <param name="invocationMode">The invocation mode of the clone (optional).</param>
 /// <param name="invocationTimeout">The invocation timeout of the clone (optional).</param>
 /// <param name="locator">The locator proxy of the clone (optional).</param>
 /// <param name="locatorCacheTimeout">The locator cache timeout of the clone (optional).</param>
 /// <param name="oneway">Determines whether the clone is oneway or twoway (optional). This is a simplified
 /// version of the invocationMode parameter.</param>
 /// <param name="preferNonSecure">Determines whether the clone prefers non-secure connections over secure
 /// connections (optional).</param>
 /// <param name="protocol">The Ice protocol of the clone (optional).</param>
 /// <param name="router">The router proxy of the clone (optional).</param>
 /// <returns>A new proxy manufactured by the proxy factory (see factory parameter).</returns>
 public static T Clone <T>(this IObjectPrx prx,
                           Identity identity,
                           ProxyFactory <T> factory,
                           string?adapterId          = null,
                           bool?cacheConnection      = null,
                           bool clearLocator         = false,
                           bool clearRouter          = false,
                           bool?collocationOptimized = null,
                           bool?compress             = null,
                           string?connectionId       = null,
                           int?connectionTimeout     = null,
                           IReadOnlyDictionary <string, string>?context = null,
                           Encoding?encoding = null,
                           EndpointSelectionType?endpointSelection = null,
                           IEnumerable <Endpoint>?endpoints        = null,
                           string?facet = null,
                           Connection?fixedConnection    = null,
                           InvocationMode?invocationMode = null,
                           int?invocationTimeout         = null,
                           ILocatorPrx?locator           = null,
                           int?locatorCacheTimeout       = null,
                           bool?oneway          = null,
                           bool?preferNonSecure = null,
                           Protocol?protocol    = null,
                           IRouterPrx?router    = null) where T : class, IObjectPrx
 {
     return(factory(prx.IceReference.Clone(adapterId,
                                           cacheConnection,
                                           clearLocator,
                                           clearRouter,
                                           collocationOptimized,
                                           compress,
                                           connectionId,
                                           connectionTimeout,
                                           context,
                                           encoding,
                                           endpointSelection,
                                           endpoints,
                                           facet,
                                           fixedConnection,
                                           identity,
                                           invocationMode,
                                           invocationTimeout,
                                           locator,
                                           locatorCacheTimeout,
                                           oneway,
                                           preferNonSecure,
                                           protocol,
                                           router)));
 }
Пример #2
0
        /// <summary>Creates a clone of this proxy. The clone is identical to this proxy except for options set
        /// through parameters. This method returns this proxy instead of a new proxy in the event none of the options
        /// specified through the parameters change this proxy's options.</summary>
        /// <param name="prx">The source proxy.</param>
        /// <param name="adapterId">The adapter ID of the clone (optional).</param>
        /// <param name="cacheConnection">Determines whether or not the clone caches its connection (optional).</param>
        /// <param name="clearLocator">When set to true, the clone does not have an associated locator proxy (optional).
        /// </param>
        /// <param name="clearRouter">When set to true, the clone does not have an associated router proxy (optional).
        /// </param>
        /// <param name="collocationOptimized">Determines whether or not the clone can use collocation optimization
        /// (optional).</param>
        /// <param name="compress">Determines whether or not the clone compresses requests (optional).</param>
        /// <param name="connectionId">The connection ID of the clone (optional).</param>
        /// <param name="connectionTimeout">The connection timeout of the clone (optional).</param>
        /// <param name="context">The context of the clone (optional).</param>
        /// <param name="encoding">The encoding of the clone (optional).</param>
        /// <param name="endpointSelection">The encoding selection policy of the clone (optional).</param>
        /// <param name="endpoints">The endpoints of the clone (optional).</param>
        /// <param name="fixedConnection">The connection of the clone (optional). When specified, the clone is a fixed
        /// proxy. You can clone a non-fixed proxy into a fixed proxy but not vice-versa.</param>
        /// <param name="invocationMode">The invocation mode of the clone (optional).</param>
        /// <param name="invocationTimeout">The invocation timeout of the clone (optional).</param>
        /// <param name="locator">The locator proxy of the clone (optional).</param>
        /// <param name="locatorCacheTimeout">The locator cache timeout of the clone (optional).</param>
        /// <param name="oneway">Determines whether the clone is oneway or twoway (optional). This is a simplified
        /// version of the invocationMode parameter.</param>
        /// <param name="preferNonSecure">Determines whether the clone prefers non-secure connections over secure
        /// connections (optional).</param>
        /// <param name="protocol">The Ice protocol of the clone (optional).</param>
        /// <param name="router">The router proxy of the clone (optional).</param>
        /// <returns>A new proxy with the same type as this proxy.</returns>
        public static T Clone <T>(this T prx,
                                  string?adapterId          = null,
                                  bool?cacheConnection      = null,
                                  bool clearLocator         = false,
                                  bool clearRouter          = false,
                                  bool?collocationOptimized = null,
                                  bool?compress             = null,
                                  string?connectionId       = null,
                                  int?connectionTimeout     = null,
                                  IReadOnlyDictionary <string, string>?context = null,
                                  Encoding?encoding = null,
                                  EndpointSelectionType?endpointSelection = null,
                                  IEnumerable <Endpoint>?endpoints        = null,
                                  Connection?fixedConnection    = null,
                                  InvocationMode?invocationMode = null,
                                  int?invocationTimeout         = null,
                                  ILocatorPrx?locator           = null,
                                  int?locatorCacheTimeout       = null,
                                  bool?oneway          = null,
                                  bool?preferNonSecure = null,
                                  Protocol?protocol    = null,
                                  IRouterPrx?router    = null) where T : IObjectPrx
        {
            Reference clone = prx.IceReference.Clone(adapterId,
                                                     cacheConnection,
                                                     clearLocator,
                                                     clearRouter,
                                                     collocationOptimized,
                                                     compress,
                                                     connectionId,
                                                     connectionTimeout,
                                                     context,
                                                     encoding,
                                                     endpointSelection,
                                                     endpoints,
                                                     facet: null,
                                                     fixedConnection,
                                                     identity: null,
                                                     invocationMode,
                                                     invocationTimeout,
                                                     locator,
                                                     locatorCacheTimeout,
                                                     oneway,
                                                     preferNonSecure,
                                                     protocol,
                                                     router);

            // Reference.Clone never returns a new reference == to itself.
            return(ReferenceEquals(clone, prx.IceReference) ? prx : (T)prx.Clone(clone));
        }
Пример #3
0
 public ICosmosDBService CreateService(string connectionString, ConnectionMode?connectionMode, Protocol?protocol)
 {
     return(new CosmosDBService(connectionString, connectionMode, protocol));
 }
Пример #4
0
        public async Task <ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
        {
            // Tries to parse the context parameters and see if it belongs to this [CosmosDBTrigger] binder
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            ParameterInfo            parameter = context.Parameter;
            CosmosDBTriggerAttribute attribute = parameter.GetCustomAttribute <CosmosDBTriggerAttribute>(inherit: false);

            if (attribute == null)
            {
                return(null);
            }

            ConnectionMode?desiredConnectionMode     = _options.ConnectionMode;
            Protocol?      desiredConnectionProtocol = _options.Protocol;

            DocumentCollectionInfo     documentCollectionLocation;
            DocumentCollectionInfo     leaseCollectionLocation;
            ChangeFeedProcessorOptions processorOptions = BuildProcessorOptions(attribute);

            processorOptions.StartFromBeginning = attribute.StartFromBeginning;
            if (attribute.MaxItemsPerInvocation > 0)
            {
                processorOptions.MaxItemCount = attribute.MaxItemsPerInvocation;
            }

            ICosmosDBService monitoredCosmosDBService;
            ICosmosDBService leaseCosmosDBService;

            try
            {
                string triggerConnectionString             = ResolveAttributeConnectionString(attribute);
                CosmosDBConnectionString triggerConnection = new CosmosDBConnectionString(triggerConnectionString);
                if (triggerConnection.ServiceEndpoint == null)
                {
                    throw new InvalidOperationException("The connection string for the monitored collection is in an invalid format, please use AccountEndpoint=XXXXXX;AccountKey=XXXXXX;.");
                }

                string leasesConnectionString             = ResolveAttributeLeasesConnectionString(attribute);
                CosmosDBConnectionString leasesConnection = new CosmosDBConnectionString(leasesConnectionString);
                if (leasesConnection.ServiceEndpoint == null)
                {
                    throw new InvalidOperationException("The connection string for the leases collection is in an invalid format, please use AccountEndpoint=XXXXXX;AccountKey=XXXXXX;.");
                }

                documentCollectionLocation = new DocumentCollectionInfo
                {
                    Uri            = triggerConnection.ServiceEndpoint,
                    MasterKey      = triggerConnection.AuthKey,
                    DatabaseName   = ResolveAttributeValue(attribute.DatabaseName),
                    CollectionName = ResolveAttributeValue(attribute.CollectionName)
                };

                documentCollectionLocation.ConnectionPolicy.UserAgentSuffix = CosmosDBTriggerUserAgentSuffix;

                if (desiredConnectionMode.HasValue)
                {
                    documentCollectionLocation.ConnectionPolicy.ConnectionMode = desiredConnectionMode.Value;
                }

                if (desiredConnectionProtocol.HasValue)
                {
                    documentCollectionLocation.ConnectionPolicy.ConnectionProtocol = desiredConnectionProtocol.Value;
                }

                leaseCollectionLocation = new DocumentCollectionInfo
                {
                    Uri            = leasesConnection.ServiceEndpoint,
                    MasterKey      = leasesConnection.AuthKey,
                    DatabaseName   = ResolveAttributeValue(attribute.LeaseDatabaseName),
                    CollectionName = ResolveAttributeValue(attribute.LeaseCollectionName)
                };

                leaseCollectionLocation.ConnectionPolicy.UserAgentSuffix = CosmosDBTriggerUserAgentSuffix;

                if (desiredConnectionMode.HasValue)
                {
                    leaseCollectionLocation.ConnectionPolicy.ConnectionMode = desiredConnectionMode.Value;
                }

                if (desiredConnectionProtocol.HasValue)
                {
                    leaseCollectionLocation.ConnectionPolicy.ConnectionProtocol = desiredConnectionProtocol.Value;
                }

                string resolvedPreferredLocations = ResolveAttributeValue(attribute.PreferredLocations);
                foreach (var location in CosmosDBUtility.ParsePreferredLocations(resolvedPreferredLocations))
                {
                    documentCollectionLocation.ConnectionPolicy.PreferredLocations.Add(location);
                    leaseCollectionLocation.ConnectionPolicy.PreferredLocations.Add(location);
                }

                if (string.IsNullOrEmpty(documentCollectionLocation.DatabaseName) ||
                    string.IsNullOrEmpty(documentCollectionLocation.CollectionName) ||
                    string.IsNullOrEmpty(leaseCollectionLocation.DatabaseName) ||
                    string.IsNullOrEmpty(leaseCollectionLocation.CollectionName))
                {
                    throw new InvalidOperationException("Cannot establish database and collection values. If you are using environment and configuration values, please ensure these are correctly set.");
                }

                if (documentCollectionLocation.Uri.Equals(leaseCollectionLocation.Uri) &&
                    documentCollectionLocation.DatabaseName.Equals(leaseCollectionLocation.DatabaseName) &&
                    documentCollectionLocation.CollectionName.Equals(leaseCollectionLocation.CollectionName))
                {
                    throw new InvalidOperationException("The monitored collection cannot be the same as the collection storing the leases.");
                }

                monitoredCosmosDBService = _configProvider.GetService(triggerConnectionString, resolvedPreferredLocations);
                leaseCosmosDBService     = _configProvider.GetService(leasesConnectionString, resolvedPreferredLocations);

                if (attribute.CreateLeaseCollectionIfNotExists)
                {
                    await CreateLeaseCollectionIfNotExistsAsync(leaseCosmosDBService, leaseCollectionLocation.DatabaseName, leaseCollectionLocation.CollectionName, attribute.LeasesCollectionThroughput);
                }
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format("Cannot create Collection Information for {0} in database {1} with lease {2} in database {3} : {4}", attribute.CollectionName, attribute.DatabaseName, attribute.LeaseCollectionName, attribute.LeaseDatabaseName, ex.Message), ex);
            }

            return(new CosmosDBTriggerBinding(
                       parameter,
                       documentCollectionLocation,
                       leaseCollectionLocation,
                       processorOptions,
                       monitoredCosmosDBService,
                       leaseCosmosDBService,
                       _logger));
        }
        internal static ConnectionPolicy BuildConnectionPolicy(ConnectionMode?connectionMode, Protocol?protocol, string preferredLocations, bool useMultipleWriteLocations, string userAgent)
        {
            ConnectionPolicy connectionPolicy = new ConnectionPolicy();

            if (connectionMode.HasValue)
            {
                // Default is Gateway
                // Source: https://docs.microsoft.com/dotnet/api/microsoft.azure.documents.client.connectionpolicy.connectionmode
                connectionPolicy.ConnectionMode = connectionMode.Value;
            }

            if (protocol.HasValue)
            {
                connectionPolicy.ConnectionProtocol = protocol.Value;
            }

            if (useMultipleWriteLocations)
            {
                connectionPolicy.UseMultipleWriteLocations = useMultipleWriteLocations;
            }

            foreach (var location in ParsePreferredLocations(preferredLocations))
            {
                connectionPolicy.PreferredLocations.Add(location);
            }

            connectionPolicy.UserAgentSuffix = userAgent;

            return(connectionPolicy);
        }
Пример #6
0
 internal static string ToSerializedValue(this Protocol?value)
 {
     return(value == null ? null : ((Protocol)value).ToSerializedValue());
 }
Пример #7
0
 public Settings Protocol(Protocol protocol)
 {
     this.protocol = protocol;
     return(this);
 }
Пример #8
0
        private async Task ExecuteConnectToProfileAsync(Profile profile, Protocol?protocol = null)
        {
            VpnManagerProfileCandidates profileCandidates = GetProfileCandidates(profile);

            await ConnectToProfileCandidatesAsync(profileCandidates, protocol);
        }
Пример #9
0
 public async Task ConnectToProfileAsync(Profile profile, Protocol?protocol = null)
 {
     await ValidateConnectionAsync(() => ExecuteConnectToProfileAsync(profile, protocol));
 }
Пример #10
0
        private async Task ConnectAsync(Profile profile, ServerCandidates candidates, Protocol?protocol = null, int?maxServers = null)
        {
            if (profile.IsPredefined || profile.IsTemporary)
            {
                profile.Protocol = _appSettings.GetProtocol();
            }

            LastProfile          = profile;
            LastServerCandidates = candidates;
            await _profileConnector.Connect(candidates, profile, protocol, maxServers);
        }
Пример #11
0
 private async Task ConnectToProfileCandidatesAsync(VpnManagerProfileCandidates profileCandidates, Protocol?protocol = null, int?maxServers = null)
 {
     if (profileCandidates.CanConnect)
     {
         await ConnectAsync(profileCandidates.Profile, profileCandidates.Candidates, protocol, maxServers);
     }
     else
     {
         _profileConnector.HandleNoServersAvailable(profileCandidates.Candidates.Items, profileCandidates.Profile);
     }
 }
        internal static ConnectionPolicy BuildConnectionPolicy(ConnectionMode?connectionMode, Protocol?protocol, string preferredLocations, bool useMultipleWriteLocations)
        {
            var connectionPolicy = new ConnectionPolicy();

            if (connectionMode.HasValue)
            {
                connectionPolicy.ConnectionMode = connectionMode.Value;
            }

            if (protocol.HasValue)
            {
                connectionPolicy.ConnectionProtocol = protocol.Value;
            }

            if (useMultipleWriteLocations)
            {
                connectionPolicy.UseMultipleWriteLocations = useMultipleWriteLocations;
            }

            foreach (var location in ParsePreferredLocations(preferredLocations))
            {
                connectionPolicy.PreferredLocations.Add(location);
            }

            return(connectionPolicy);
        }
Пример #13
0
 internal ConnectivityParameters(ConnectivitySource source, ConnectivityDestination destination, Protocol?protocol, ProtocolConfiguration protocolConfiguration, IPVersion?preferredIPVersion)
 {
     Source                = source;
     Destination           = destination;
     Protocol              = protocol;
     ProtocolConfiguration = protocolConfiguration;
     PreferredIPVersion    = preferredIPVersion;
 }
        public CosmosDBService(string connectionString, ConnectionMode?connectionMode, Protocol?protocol)
        {
            CosmosDBConnectionString connection = new CosmosDBConnectionString(connectionString);

            _client = new DocumentClient(connection.ServiceEndpoint, connection.AuthKey);
            if (connectionMode.HasValue)
            {
                // Default is Gateway
                // Source: https://docs.microsoft.com/dotnet/api/microsoft.azure.documents.client.connectionpolicy.connectionmode
                _client.ConnectionPolicy.ConnectionMode = connectionMode.Value;
            }

            if (protocol.HasValue)
            {
                _client.ConnectionPolicy.ConnectionProtocol = protocol.Value;
            }
        }