Example #1
0
 public MockImageGalleryClient(Cosmos.MockCosmosState cosmosState, MockLogger logger) :
     base(null)
 {
     this.AzureStorageProvider = new AzureStorage.MockBlobContainerProvider(logger);
     this.CosmosClientProvider = new Cosmos.MockClientProvider(cosmosState, logger);
     this.Logger = logger;
 }
Example #2
0
 protected CloudConnection(
     IIdentity identity,
     Action <string, CloudConnectionStatus> connectionStatusChangedHandler,
     ITransportSettings[] transportSettings,
     IMessageConverterProvider messageConverterProvider,
     IClientProvider clientProvider,
     ICloudListener cloudListener,
     TimeSpan idleTimeout,
     bool closeOnIdleTimeout,
     TimeSpan operationTimeout,
     string productInfo,
     Option <string> modelId)
 {
     this.Identity = Preconditions.CheckNotNull(identity, nameof(identity));
     this.ConnectionStatusChangedHandler = connectionStatusChangedHandler;
     this.transportSettingsList          = Preconditions.CheckNotNull(transportSettings, nameof(transportSettings));
     this.messageConverterProvider       = Preconditions.CheckNotNull(messageConverterProvider, nameof(messageConverterProvider));
     this.clientProvider     = Preconditions.CheckNotNull(clientProvider, nameof(clientProvider));
     this.cloudListener      = Preconditions.CheckNotNull(cloudListener, nameof(cloudListener));
     this.idleTimeout        = idleTimeout;
     this.closeOnIdleTimeout = closeOnIdleTimeout;
     this.cloudProxy         = Option.None <ICloudProxy>();
     this.operationTimeout   = operationTimeout;
     this.productInfo        = productInfo;
     this.modelId            = modelId;
 }
Example #3
0
 public CloudConnectionProvider(
     IMessageConverterProvider messageConverterProvider,
     int connectionPoolSize,
     IClientProvider clientProvider,
     Option <UpstreamProtocol> upstreamProtocol,
     ITokenProvider edgeHubTokenProvider,
     IDeviceScopeIdentitiesCache deviceScopeIdentitiesCache,
     ICredentialsCache credentialsCache,
     IIdentity edgeHubIdentity,
     TimeSpan idleTimeout,
     bool closeOnIdleTimeout,
     TimeSpan operationTimeout,
     bool useServerHeartbeat,
     Option <IWebProxy> proxy,
     IMetadataStore metadataStore,
     bool nestedEdgeEnabled = false)
 {
     this.messageConverterProvider = Preconditions.CheckNotNull(messageConverterProvider, nameof(messageConverterProvider));
     this.clientProvider           = Preconditions.CheckNotNull(clientProvider, nameof(clientProvider));
     this.upstreamProtocol         = upstreamProtocol;
     this.connectionPoolSize       = Preconditions.CheckRange(connectionPoolSize, 1, nameof(connectionPoolSize));
     this.proxy                      = proxy;
     this.edgeHub                    = Option.None <IEdgeHub>();
     this.idleTimeout                = idleTimeout;
     this.closeOnIdleTimeout         = closeOnIdleTimeout;
     this.useServerHeartbeat         = useServerHeartbeat;
     this.edgeHubTokenProvider       = Preconditions.CheckNotNull(edgeHubTokenProvider, nameof(edgeHubTokenProvider));
     this.deviceScopeIdentitiesCache = Preconditions.CheckNotNull(deviceScopeIdentitiesCache, nameof(deviceScopeIdentitiesCache));
     this.credentialsCache           = Preconditions.CheckNotNull(credentialsCache, nameof(credentialsCache));
     this.edgeHubIdentity            = Preconditions.CheckNotNull(edgeHubIdentity, nameof(edgeHubIdentity));
     this.operationTimeout           = operationTimeout;
     this.metadataStore              = Preconditions.CheckNotNull(metadataStore, nameof(metadataStore));
     this.nestedEdgeEnabled          = nestedEdgeEnabled;
 }
Example #4
0
        public async Task GetCloudConnectionForIdentityWithTokenTest()
        {
            IClientProvider clientProvider           = GetMockDeviceClientProviderWithToken();
            var             transportSettings        = new ITransportSettings[] { new AmqpTransportSettings(TransportType.Amqp_Tcp_Only) };
            var             messageConverterProvider = new MessageConverterProvider(new Dictionary <Type, IMessageConverter> {
                [typeof(TwinCollection)] = Mock.Of <IMessageConverter>()
            });
            ITokenCredentials          clientCredentials1 = GetMockClientCredentialsWithToken();
            ClientTokenCloudConnection cloudConnection    = await ClientTokenCloudConnection.Create(
                clientCredentials1,
                (_, __) => { },
                transportSettings,
                messageConverterProvider,
                clientProvider,
                Mock.Of <ICloudListener>(),
                TimeSpan.FromMinutes(60),
                true,
                TimeSpan.FromSeconds(20));

            Option <ICloudProxy> cloudProxy1 = cloudConnection.CloudProxy;

            Assert.True(cloudProxy1.HasValue);
            Assert.True(cloudProxy1.OrDefault().IsActive);

            ITokenCredentials clientCredentials2 = GetMockClientCredentialsWithToken();
            ICloudProxy       cloudProxy2        = await cloudConnection.UpdateTokenAsync(clientCredentials2);

            Assert.Equal(cloudProxy2, cloudConnection.CloudProxy.OrDefault());
            Assert.True(cloudProxy2.IsActive);
            Assert.False(cloudProxy1.OrDefault().IsActive);
            Assert.NotEqual(cloudProxy1.OrDefault(), cloudProxy2);
        }
 public CloudConnectionProvider(IMessageConverterProvider messageConverterProvider, int connectionPoolSize, IClientProvider clientProvider, Option <UpstreamProtocol> upstreamProtocol)
 {
     Preconditions.CheckRange(connectionPoolSize, 1, nameof(connectionPoolSize));
     this.messageConverterProvider = Preconditions.CheckNotNull(messageConverterProvider, nameof(messageConverterProvider));
     this.clientProvider           = Preconditions.CheckNotNull(clientProvider, nameof(clientProvider));
     this.transportSettings        = GetTransportSettings(upstreamProtocol, connectionPoolSize);
 }
Example #6
0
        public static async Task <CloudConnection> Create(
            IIdentity identity,
            Action <string, CloudConnectionStatus> connectionStatusChangedHandler,
            ITransportSettings[] transportSettings,
            IMessageConverterProvider messageConverterProvider,
            IClientProvider clientProvider,
            ICloudListener cloudListener,
            ITokenProvider tokenProvider,
            TimeSpan idleTimeout,
            bool closeOnIdleTimeout,
            TimeSpan operationTimeout)
        {
            Preconditions.CheckNotNull(tokenProvider, nameof(tokenProvider));
            var cloudConnection = new CloudConnection(
                identity,
                connectionStatusChangedHandler,
                transportSettings,
                messageConverterProvider,
                clientProvider,
                cloudListener,
                idleTimeout,
                closeOnIdleTimeout,
                operationTimeout);
            ICloudProxy cloudProxy = await cloudConnection.CreateNewCloudProxyAsync(tokenProvider);

            cloudConnection.cloudProxy = Option.Some(cloudProxy);
            return(cloudConnection);
        }
 ClientTokenCloudConnection(
     IIdentity identity,
     Action <string, CloudConnectionStatus> connectionStatusChangedHandler,
     ITransportSettings[] transportSettings,
     IMessageConverterProvider messageConverterProvider,
     IClientProvider clientProvider,
     ICloudListener cloudListener,
     TimeSpan idleTimeout,
     bool closeOnIdleTimeout,
     TimeSpan operationTimeout,
     string productInfo,
     Option <string> modelId)
     : base(
         identity,
         connectionStatusChangedHandler,
         transportSettings,
         messageConverterProvider,
         clientProvider,
         cloudListener,
         idleTimeout,
         closeOnIdleTimeout,
         operationTimeout,
         productInfo,
         modelId)
 {
 }
Example #8
0
        public async Task GetCloudConnectionForIdentityWithKeyTest()
        {
            IClientProvider clientProvider           = GetMockDeviceClientProviderWithKey();
            var             tokenProvider            = Mock.Of <ITokenProvider>();
            var             identity                 = Mock.Of <IIdentity>(i => i.Id == "d1");
            var             transportSettings        = new ITransportSettings[] { new AmqpTransportSettings(TransportType.Amqp_Tcp_Only) };
            var             messageConverterProvider = new MessageConverterProvider(new Dictionary <Type, IMessageConverter> {
                [typeof(TwinCollection)] = Mock.Of <IMessageConverter>()
            });
            CloudConnection cloudConnection = await CloudConnection.Create(
                identity,
                (_, __) => { },
                transportSettings,
                messageConverterProvider,
                clientProvider,
                Mock.Of <ICloudListener>(),
                tokenProvider,
                TimeSpan.FromMinutes(60),
                true,
                TimeSpan.FromSeconds(20),
                DummyProductInfo);

            Option <ICloudProxy> cloudProxy1 = cloudConnection.CloudProxy;

            Assert.True(cloudProxy1.HasValue);
            Assert.True(cloudProxy1.OrDefault().IsActive);
        }
Example #9
0
 public MainViewModel(IClientProvider clientProvider)
 {
     _clientsProvider = clientProvider;
     DeleteCommand    = new RelayCommand(OnDeleteExecute, OnDeleteCanExecute);
     Clients          = new ObservableCollection <Client>();
     LoadData();
 }
Example #10
0
 public CloudConnectionProvider(
     IMessageConverterProvider messageConverterProvider,
     int connectionPoolSize,
     IClientProvider clientProvider,
     Option <UpstreamProtocol> upstreamProtocol,
     ITokenProvider edgeHubTokenProvider,
     IDeviceScopeIdentitiesCache deviceScopeIdentitiesCache,
     ICredentialsCache credentialsCache,
     IIdentity edgeHubIdentity,
     TimeSpan idleTimeout,
     bool closeOnIdleTimeout,
     TimeSpan operationTimeout,
     Option <IWebProxy> proxy,
     IProductInfoStore productInfoStore)
 {
     Preconditions.CheckRange(connectionPoolSize, 1, nameof(connectionPoolSize));
     this.messageConverterProvider = Preconditions.CheckNotNull(messageConverterProvider, nameof(messageConverterProvider));
     this.clientProvider           = Preconditions.CheckNotNull(clientProvider, nameof(clientProvider));
     this.transportSettings        = GetTransportSettings(upstreamProtocol, connectionPoolSize, proxy);
     this.edgeHub                    = Option.None <IEdgeHub>();
     this.idleTimeout                = idleTimeout;
     this.closeOnIdleTimeout         = closeOnIdleTimeout;
     this.edgeHubTokenProvider       = Preconditions.CheckNotNull(edgeHubTokenProvider, nameof(edgeHubTokenProvider));
     this.deviceScopeIdentitiesCache = Preconditions.CheckNotNull(deviceScopeIdentitiesCache, nameof(deviceScopeIdentitiesCache));
     this.credentialsCache           = Preconditions.CheckNotNull(credentialsCache, nameof(credentialsCache));
     this.edgeHubIdentity            = Preconditions.CheckNotNull(edgeHubIdentity, nameof(edgeHubIdentity));
     this.operationTimeout           = operationTimeout;
     this.productInfoStore           = Preconditions.CheckNotNull(productInfoStore, nameof(productInfoStore));
 }
Example #11
0
        public async Task RefreshTokenTest()
        {
            string iothubHostName = "test.azure-devices.net";
            string deviceId       = "device1";

            IClientCredentials GetClientCredentialsWithExpiringToken()
            {
                string token    = TokenHelper.CreateSasToken(iothubHostName, DateTime.UtcNow.AddSeconds(10));
                var    identity = new DeviceIdentity(iothubHostName, deviceId);

                return(new TokenCredentials(identity, token, string.Empty));
            }

            IAuthenticationMethod authenticationMethod = null;
            IClientProvider       clientProvider       = GetMockDeviceClientProviderWithToken((s, a, t) => authenticationMethod = a);

            var transportSettings = new ITransportSettings[] { new AmqpTransportSettings(TransportType.Amqp_Tcp_Only) };

            var receivedStatus = CloudConnectionStatus.ConnectionEstablished;

            void ConnectionStatusHandler(string id, CloudConnectionStatus status) => receivedStatus = status;

            var messageConverterProvider = new MessageConverterProvider(new Dictionary <Type, IMessageConverter>());

            var cloudConnection = new CloudConnection(ConnectionStatusHandler, transportSettings, messageConverterProvider, clientProvider);

            IClientCredentials clientCredentialsWithExpiringToken1 = GetClientCredentialsWithExpiringToken();
            ICloudProxy        cloudProxy1 = await cloudConnection.CreateOrUpdateAsync(clientCredentialsWithExpiringToken1);

            Assert.True(cloudProxy1.IsActive);
            Assert.Equal(cloudProxy1, cloudConnection.CloudProxy.OrDefault());

            Assert.NotNull(authenticationMethod);
            var deviceAuthenticationWithTokenRefresh = authenticationMethod as DeviceAuthenticationWithTokenRefresh;

            Assert.NotNull(deviceAuthenticationWithTokenRefresh);

            // Wait for the token to expire
            await Task.Delay(TimeSpan.FromSeconds(10));

            Task <string> getTokenTask = deviceAuthenticationWithTokenRefresh.GetTokenAsync(iothubHostName);

            Assert.False(getTokenTask.IsCompleted);

            Assert.Equal(receivedStatus, CloudConnectionStatus.TokenNearExpiry);

            IClientCredentials clientCredentialsWithExpiringToken2 = GetClientCredentialsWithExpiringToken();
            ICloudProxy        cloudProxy2 = await cloudConnection.CreateOrUpdateAsync(clientCredentialsWithExpiringToken2);

            // Wait for the task to complete
            await Task.Delay(TimeSpan.FromSeconds(10));

            Assert.Equal(cloudProxy2, cloudConnection.CloudProxy.OrDefault());
            Assert.True(cloudProxy2.IsActive);
            Assert.True(cloudProxy1.IsActive);
            Assert.Equal(cloudProxy1, cloudProxy2);
            Assert.True(getTokenTask.IsCompletedSuccessfully);
            Assert.Equal(getTokenTask.Result, (clientCredentialsWithExpiringToken2 as ITokenCredentials)?.Token);
        }
Example #12
0
 public IndexModel(tt_apps_srs_db_context db,
                   IClientProvider clientProvider,
                   IAuditor auditor)
 {
     _db             = db;
     _clientProvider = clientProvider;
     _auditor        = auditor;
 }
        public async Task Invoke(HttpContext context, IClientProvider provider)
        {
            HttpClient calendarClient = null;
            HttpClient CalcClient = null;

            try
            {

                //
                //get the respective client
                //
                calendarClient = provider.GetClientFor("calendar");
                CalcClient = provider.GetClientFor("calc");

                //
                //call the calendar api
                //
                var calendarResponse = "";
                if (context.Request.Path.Value == "/today")
                {
                    calendarResponse = await calendarClient.GetStringAsync("http://www.calendarApi.io/today");
                }
                else if (context.Request.Path.Value == "/yesterday")
                {
                    calendarResponse = await calendarClient.GetStringAsync("http://www.calendarApi.io/yesterday");
                }
                else
                {
                    context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                    //does not process further
                    return;
                }
                //
                //call another api
                //
                var calcResponse = await CalcClient.GetStringAsync("http://www.calcApi.io/count");

                //
                // write the final response
                //
                await context.Response.WriteAsync(calendarResponse + " count is " + calcResponse);

               // await next(context);
            }
            finally
            {
                if (calendarClient != null)
                {
                    calendarClient.Dispose();
                }
                if (CalcClient != null)
                {
                    CalcClient.Dispose();
                }
            }

        }
Example #14
0
        public MessageStoreContext GetContext(IClientProvider clientProvider)
        {
            // Mocking entity framework seems like a bad idea. Use the provided in memory database for tests
            var options = new DbContextOptionsBuilder <MessageStoreContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            return(new MessageStoreContext(options, clientProvider));
        }
        public void CTOR_initializesSpanCollector()
        {
            SpanCollector.spanQueue = null;

            clientProviderStub = MockRepository.GenerateStub <IClientProvider>();
            spanCollector      = new SpanCollector(clientProviderStub, 0);

            Assert.IsNotNull(SpanCollector.spanQueue);
        }
        public void CTOR_initializesSpanCollector()
        {
            SpanCollector.spanQueue = null;

            clientProviderStub = MockRepository.GenerateStub<IClientProvider>();
            spanCollector = new SpanCollector(clientProviderStub, 0);

            Assert.IsNotNull(SpanCollector.spanQueue);
        }
        private void SetupSpanCollector()
        {
            clientProviderStub = MockRepository.GenerateStub <IClientProvider>();
            spanCollector      = new SpanCollector(clientProviderStub, 0);

            SpanCollector.spanQueue     = fixture.Create <BlockingCollection <Span> >();
            spanProcessorStub           = MockRepository.GenerateStub <SpanProcessor>(SpanCollector.spanQueue, clientProviderStub, 0);
            spanCollector.spanProcessor = spanProcessorStub;
        }
        public ElasticSearcher(IClientProvider clientProvider, IElasticConnectionSettings elasticConnectionSettings)
        {
            if (clientProvider == null) throw new ArgumentNullException("clientProvider");
            if (elasticConnectionSettings == null) throw new ArgumentNullException("elasticConnectionSettings");

            _clientProvider = clientProvider;
            _elasticConnectionSettings = elasticConnectionSettings;
            _client = _clientProvider.GetClient(_elasticConnectionSettings);
        }
Example #19
0
        public ApiResult <IEnumerable <Client> > IndexList([FromServices] IClientProvider clientProvider, VSearchModel vSearchModel)
        {
            var lst = clientProvider.Search(vSearchModel.Keywords, vSearchModel.PageIndex, vSearchModel.PageSize, out int count);

            return(new ApiResult <IEnumerable <Client> >()
            {
                Data = lst
            });
        }
        /// <summary>
        ///     Runs the transmitter process
        /// </summary>
        public void Run()
        {
            IClientProvider provider = Activator.CreateInstance <T>();
            var             client   = provider.GetClient();

            _beforeRun();
            _run(client);
            _afterRun();
        }
        public void CTOR_doesntReinitializeSpanCollector()
        {
            var spanQueue = new BlockingCollection<Span>();
            SpanCollector.spanQueue = spanQueue;

            clientProviderStub = MockRepository.GenerateStub<IClientProvider>();
            spanCollector = new SpanCollector(clientProviderStub, 0);

            Assert.IsTrue(System.Object.ReferenceEquals(SpanCollector.spanQueue, spanQueue));
        }
        public MongoContext(
            IClientProvider clientProvider,
            ILoggerFactory loggerFactory)
        {
            this.clientProvider = clientProvider;
            logger = loggerFactory.CreateLogger(typeof(MongoContext).FullName);

            // every command will be stored and it'll be processed at SaveChanges
            commands = new List <Func <Task> >();
        }
Example #23
0
 public CreditBusiness(ICreditRepository creditRepository,
                       IClientProvider clientProvider,
                       IMapper mapper,
                       IConfiguration config)
 {
     _creditRepository = creditRepository;
     _clientProvider   = clientProvider;
     _mapper           = mapper;
     _config           = config;
 }
Example #24
0
 public QuotaBusiness(IQuotaRepository quotaRepository,
                      IClientProvider clientProvider,
                      IMapper mapper,
                      IConfiguration config)
 {
     _quotaRepository = quotaRepository;
     _clientProvider  = clientProvider;
     _mapper          = mapper;
     _config          = config;
 }
        public async Task Invoke(HttpContext context, IClientProvider provider)
        {
            HttpClient calendarClient = null;
            HttpClient CalcClient     = null;

            try
            {
                //
                //get the respective client
                //
                calendarClient = provider.GetClientFor("calendar");
                CalcClient     = provider.GetClientFor("calc");

                //
                //call the calendar api
                //
                var calendarResponse = "";
                if (context.Request.Path.Value == "/today")
                {
                    calendarResponse = await calendarClient.GetStringAsync("http://www.calendarApi.io/today");
                }
                else if (context.Request.Path.Value == "/yesterday")
                {
                    calendarResponse = await calendarClient.GetStringAsync("http://www.calendarApi.io/yesterday");
                }
                else
                {
                    context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                    //does not process further
                    return;
                }
                //
                //call another api
                //
                var calcResponse = await CalcClient.GetStringAsync("http://www.calcApi.io/count");

                //
                // write the final response
                //
                await context.Response.WriteAsync(calendarResponse + " count is " + calcResponse);

                // await next(context);
            }
            finally
            {
                if (calendarClient != null)
                {
                    calendarClient.Dispose();
                }
                if (CalcClient != null)
                {
                    CalcClient.Dispose();
                }
            }
        }
        public SpanCollector(IClientProvider clientProvider, int maxProcessorBatchSize)
        {
            if ( spanQueue == null)
            {
                spanQueue = new BlockingCollection<Span>(MAX_QUEUE_SIZE);
            }

            this.clientProvider = clientProvider;
            
            spanProcessor = new SpanProcessor(spanQueue, clientProvider, maxProcessorBatchSize);
        }
 public CloudConnection(Action <string, CloudConnectionStatus> connectionStatusChangedHandler,
                        ITransportSettings[] transportSettings,
                        IMessageConverterProvider messageConverterProvider,
                        IClientProvider clientProvider)
 {
     this.connectionStatusChangedHandler = connectionStatusChangedHandler;
     this.transportSettingsList          = Preconditions.CheckNotNull(transportSettings, nameof(transportSettings));
     this.messageConverterProvider       = Preconditions.CheckNotNull(messageConverterProvider, nameof(messageConverterProvider));
     this.tokenGetter    = Option.None <TaskCompletionSource <string> >();
     this.clientProvider = Preconditions.CheckNotNull(clientProvider, nameof(clientProvider));
 }
Example #28
0
        public void Init()
        {
            fixture = new Fixture();

            queue            = new BlockingCollection <Span>();
            clientProvider   = MockRepository.GenerateStub <IClientProvider>();
            testMaxBatchSize = 10;
            spanProcessor    = new SpanProcessor(queue, clientProvider, testMaxBatchSize);
            taskFactory      = MockRepository.GenerateStub <SpanProcessorTaskFactory>();
            spanProcessor.spanProcessorTaskFactory = taskFactory;
        }
        public void CTOR_doesntReinitializeSpanCollector()
        {
            var spanQueue = new BlockingCollection <Span>();

            SpanCollector.spanQueue = spanQueue;

            clientProviderStub = MockRepository.GenerateStub <IClientProvider>();
            spanCollector      = new SpanCollector(clientProviderStub, 0);

            Assert.IsTrue(System.Object.ReferenceEquals(SpanCollector.spanQueue, spanQueue));
        }
Example #30
0
        public SpanCollector(IClientProvider clientProvider, int maxProcessorBatchSize)
        {
            if (spanQueue == null)
            {
                spanQueue = new BlockingCollection <Span>(MAX_QUEUE_SIZE);
            }

            this.clientProvider = clientProvider;

            spanProcessor = new SpanProcessor(spanQueue, clientProvider, maxProcessorBatchSize);
        }
        public void Init()
        {
            fixture = new Fixture();

            queue = new BlockingCollection<Span>();
            clientProvider = MockRepository.GenerateStub<IClientProvider>();
            testMaxBatchSize = 10;
            spanProcessor = new SpanProcessor(queue, clientProvider, testMaxBatchSize);
            taskFactory = MockRepository.GenerateStub<SpanProcessorTaskFactory>();
            spanProcessor.spanProcessorTaskFactory = taskFactory;
        }
Example #32
0
        public StoresController(tt_apps_srs_db_context db,
                                IClientProvider client,
                                ElasticClient esSvcClient)
        {
            _db              = db;
            _client_id       = client.ClientId;
            _client_name     = client.Name;
            _client_url_code = client.UrlCode;
            _client          = client;

            _esStoreClient = new ESIndex_Store(esSvcClient);
        }
Example #33
0
 private void SetupClients(IClientProvider clientProvider)
 {
     runspace = new Lazy <Runspace>(() =>
     {
         var localRunspace = RunspaceFactory.CreateRunspace(this.Host);
         localRunspace.Open();
         return(localRunspace);
     });
     client        = new Lazy <ManagementClient>(clientProvider.CreateClient);
     computeClient = new Lazy <ComputeManagementClient>(clientProvider.CreateComputeClient);
     storageClient = new Lazy <StorageManagementClient>(clientProvider.CreateStorageClient);
     networkClient = new Lazy <NetworkManagementClient>(clientProvider.CreateNetworkClient);
 }
        private static IV2Facade RestClientV2Initializer(IRequestBuilderFactory requestBuilderFactory,
                                                         IClientProvider clientProvider,
                                                         IContentFormattersFactory contentFormattersFactory)
        {
            var container = new Container(requestBuilderFactory, clientProvider, contentFormattersFactory);
            var search    = new SearchV2(requestBuilderFactory, clientProvider, contentFormattersFactory);
            var user      = new UserV2(requestBuilderFactory, clientProvider);
            var document  = new DocumentV2(requestBuilderFactory, clientProvider, contentFormattersFactory);
            var command   = new Command(requestBuilderFactory, clientProvider, contentFormattersFactory);
            var cabinet   = new CabinetV2(requestBuilderFactory, clientProvider);
            var service   = new Service(requestBuilderFactory, clientProvider);

            return(new V2Facade(container, search, user, document, command, cabinet, service));
        }
        public IdentityServerConfigService(string connectionString, string schema)
        {
            var dbSchema = schema.IndexOf("[", StringComparison.InvariantCultureIgnoreCase) >= 0 ? schema : $"[{schema}]";

            this.clientProvider = new DefaultClientProvider(new DBProviderOptions()
            {
                ConnectionString = connectionString, DbSchema = dbSchema
            }, null);
            this.identityResourceProvider = new DefaultIdentityResourceProvider(new DBProviderOptions()
            {
                ConnectionString = connectionString, DbSchema = dbSchema
            }, null);
            this.apiResourceProvider = new DefaultApiResourceProvider(new DBProviderOptions()
            {
                ConnectionString = connectionString, DbSchema = dbSchema
            }, null);
        }
Example #36
0
        public string GetPage(string url)
        {
            string    data      = string.Empty;
            WebClient webClient = null;

            try
            {
                webClient = new WebClient();
                data      = webClient.DownloadString(url);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(data);
        }
        public MultivipTests()
        {
            this.networkingClientMock = new Mock<NetworkManagementClient>();
            this.computeClientMock = new Mock<ComputeManagementClient>();
            this.managementClientMock = new Mock<ManagementClient>();
            this.storageClientMock = new Mock<StorageManagementClient>();
            this.mockCommandRuntime = new MockCommandRuntime();
            testClientProvider = new TestClientProvider(this.managementClientMock.Object, this.computeClientMock.Object,
                this.storageClientMock.Object, this.networkingClientMock.Object);

            testClientProvider = new TestClientProvider(this.managementClientMock.Object,
                this.computeClientMock.Object, this.storageClientMock.Object, this.networkingClientMock.Object);

            this.computeClientMock
                .Setup(c => c.Deployments.GetBySlotAsync(ServiceName, DeploymentSlot.Production, It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new DeploymentGetResponse()
                {
                    Name = DeploymentName
                }));

            this.networkingClientMock
                .Setup(c => c.VirtualIPs.AddAsync(
                    ServiceName,
                    DeploymentName,
                    VipName,
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new OperationStatusResponse()
                {
                    Status = OperationStatus.Succeeded
                }));


            this.networkingClientMock
                .Setup(c => c.VirtualIPs.RemoveAsync(
                    ServiceName,
                    DeploymentName,
                    VipName,
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new OperationStatusResponse()
                {
                    Status = OperationStatus.Succeeded
                }));
        }
        public SpanProcessor(BlockingCollection<Span> spanQueue, IClientProvider clientProvider, int maxBatchSize)
        {
            if ( spanQueue == null) 
            {
                throw new ArgumentNullException("spanQueue is null");
            }

            if ( clientProvider == null) 
            {
                throw new ArgumentNullException("clientProvider is null");
            }

            this.spanQueue = spanQueue;
            this.clientProvider = clientProvider;
            this.maxBatchSize = maxBatchSize;
            logEntries = new List<LogEntry>();
            protocolFactory = new TBinaryProtocol.Factory();
            spanProcessorTaskFactory = new SpanProcessorTaskFactory();
        }
 internal void Log(IClientProvider client, List<LogEntry> logEntries)
 {
     try
     {
         clientProvider.Log(logEntries);
         retries = 0;
     }
     catch (TException tEx)
     {
         if ( retries < 3 )
         {
             retries++;
             Log(client, logEntries);
         }
         else
         {
             throw;
         }
     }
 }
Example #40
0
        public Importer(
            IFileSystem fileSystem, 
            ITweetDataFileParser tweetDataFileParser,
            IClientProvider clientProvider, 
            IElasticConnectionSettings elasticConnectionSettings, 
            string sourceDirectory)
        {
            if (fileSystem == null) throw new ArgumentNullException("fileSystem");
            if (tweetDataFileParser == null) throw new ArgumentNullException("tweetDataFileParser");
            if (clientProvider == null) throw new ArgumentNullException("clientProvider");
            if (elasticConnectionSettings == null) throw new ArgumentNullException("elasticConnectionSettings");

            if (!fileSystem.DirectoryExists(sourceDirectory))
                throw new DirectoryNotFoundException("Source directory does not exist");

            _fileSystem = fileSystem;
            _parser = tweetDataFileParser;
            _clientProvider = clientProvider;
            _elasticConnectionSettings = elasticConnectionSettings;
            _sourceDirectory = sourceDirectory;
        }
 public SetAzureReservedIPAssociationCmdlet(IClientProvider provider)
     : base(provider)
 {
 }
 public NewAzureReservedIPCmdlet(IClientProvider provider) : base(provider)
 {
 }
 public AddAzureVirtualIP(IClientProvider provider) : base(provider)
 {
 }
        private void SetupSpanCollector()
        {
            clientProviderStub = MockRepository.GenerateStub<IClientProvider>();
            spanCollector = new SpanCollector(clientProviderStub, 0);

            SpanCollector.spanQueue = fixture.Create<BlockingCollection<Span>>();
            spanProcessorStub = MockRepository.GenerateStub<SpanProcessor>(SpanCollector.spanQueue, clientProviderStub, 0);
            spanCollector.spanProcessor = spanProcessorStub;
        }
 public RemoveAzureVirtualIP(IClientProvider provider) : base(provider)
 {
 }
        public ReservedIPTest()
        {
            this.networkingClientMock = new Mock<NetworkManagementClient>();
            this.computeClientMock = new Mock<ComputeManagementClient>();
            this.managementClientMock = new Mock<ManagementClient>();
            this.storageClientMock = new Mock<StorageManagementClient>();
            this.mockCommandRuntime = new MockCommandRuntime();
            
            testClientProvider = new TestClientProvider(this.managementClientMock.Object,
                this.computeClientMock.Object, this.storageClientMock.Object, this.networkingClientMock.Object);

            this.computeClientMock
                .Setup(c => c.Deployments.GetBySlotAsync(ServiceName, DeploymentSlot.Production, It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new DeploymentGetResponse()
                {
                    Name = DeploymentName
                }));

            this.computeClientMock
                .Setup(
                    c =>
                        c.Deployments.GetBySlotAsync(ServiceName, DeploymentSlot.Staging,
                            It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new DeploymentGetResponse()
                {
                    Name = DeploymentName
                }));

            // Reserve IP simple
            this.networkingClientMock
                .Setup(c => c.ReservedIPs.CreateAsync(
                    It.Is<NetworkReservedIPCreateParameters>(
                        p =>
                            string.Equals(p.Name, ReservedIPName) && string.IsNullOrEmpty(p.ServiceName) &&
                            string.IsNullOrEmpty(p.VirtualIPName) && string.IsNullOrEmpty(p.DeploymentName)),
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new OperationStatusResponse()
                {
                    Status = OperationStatus.Succeeded
                }));

            // Reserve in use IP single vip
            this.networkingClientMock
                .Setup(c => c.ReservedIPs.CreateAsync(
                    It.Is<NetworkReservedIPCreateParameters>(
                        p =>
                            string.Equals(p.Name, ReservedIPName) && string.Equals(p.ServiceName, ServiceName) &&
                            string.IsNullOrEmpty(p.VirtualIPName) && string.Equals(p.DeploymentName, DeploymentName)),
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new OperationStatusResponse()
                {
                    Status = OperationStatus.Succeeded
                }));

            // Reserve in use IP named vip
            this.networkingClientMock
                .Setup(c => c.ReservedIPs.CreateAsync(
                    It.Is<NetworkReservedIPCreateParameters>(
                        p =>
                            string.Equals(p.Name, ReservedIPName) && string.Equals(p.ServiceName, ServiceName) &&
                            string.Equals(p.VirtualIPName, VipName) && string.Equals(p.DeploymentName, DeploymentName)),
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new OperationStatusResponse()
                {
                    Status = OperationStatus.Succeeded
                }));

            // Associate a reserved IP with a deployment
            this.networkingClientMock
                .Setup(c => c.ReservedIPs.AssociateAsync(
                    ReservedIPName,
                    It.Is<NetworkReservedIPMobilityParameters>(
                        p => string.Equals(p.ServiceName, ServiceName) &&
                            string.IsNullOrEmpty(p.VirtualIPName) && string.Equals(p.DeploymentName, DeploymentName)),
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new OperationStatusResponse()
                {
                    Status = OperationStatus.Succeeded
                }));


            // Associate a reserved IP with a vip
            this.networkingClientMock
                .Setup(c => c.ReservedIPs.AssociateAsync(
                    ReservedIPName,
                    It.Is<NetworkReservedIPMobilityParameters>(
                        p => string.Equals(p.ServiceName, ServiceName) &&
                            string.Equals(p.VirtualIPName, VipName) && string.Equals(p.DeploymentName, DeploymentName)),
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new OperationStatusResponse()
                {
                    Status = OperationStatus.Succeeded
                }));


            // Remove Azure Reserved IP
            this.networkingClientMock
                .Setup(c => c.ReservedIPs.DeleteAsync(
                   ReservedIPName,
                    It.IsAny<CancellationToken>()))
                .Returns(Task.Factory.StartNew(() => new OperationStatusResponse()
                {
                    Status = OperationStatus.Succeeded
                }));
        }