Exemplo n.º 1
0
 static StatefulBackEndService()
 {
     serviceUri   = new Uri("fabric:/SFInsideOutPerfCompare/BackEnd.Core.Stateful");
     fabricClient = new FabricClient();
     communicationClientFactory =
         new HttpCommunicationClientFactory(new ServicePartitionResolver(() => fabricClient));
 }
        static FabricHttpClient()
        {
            addresses    = new ConcurrentDictionary <Uri, bool?>();
            fabricClient = new FabricClient();
            HttpClientHandler handler = new HttpClientHandler();

            if (handler.SupportsAutomaticDecompression)
            {
                handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            }

            httpClient = new HttpClient(handler);

            //https://stackoverflow.com/questions/7372585/protobuf-net-exception-timeout-while-inspecting-metadata
            //https://stackoverflow.com/questions/17096359/is-protobuf-net-thread-safe
            //RuntimeTypeModel.Default.MetadataTimeoutMilliseconds = 300000;

            clientFactory = new HttpCommunicationClientFactory(
                ServicePartitionResolver.GetDefault(),
                "endpointName",
                TimeSpan.FromSeconds(10),
                TimeSpan.FromSeconds(5));

            jSerializer = new JsonSerializer();  //todo - see if creating this on the fly is better or not
        }
Exemplo n.º 3
0
        public CatalogProductAPIClient(FabricClient fabricClient)
        {
            this.fabricClient = fabricClient;
            backoffQueryDelay = TimeSpan.FromSeconds(3);

            this.serviceUri      = new Uri("fabric:/MicroWishConsumerApplication/MicroWish.ConsumerAPI");
            communicationFactory = new HttpCommunicationClientFactory(new ServicePartitionResolver(() => fabricClient));
        }
        public HttpGatewayMiddleware(RequestDelegate next, HttpCommunicationClientFactory httpClientFactory)
        {
            if (httpClientFactory == null)
            {
                throw new ArgumentNullException(nameof(httpClientFactory));
            }

            _httpClientFactory = httpClientFactory;
        }
        static DefaultController()
        {
            _serviceUri = new Uri(FabricRuntime.GetActivationContext().ApplicationName + "/WordCountService");

            _backoffQueryDelay = TimeSpan.FromSeconds(3);

            _fabricClient = new FabricClient();

            _communicationFactory = new HttpCommunicationClientFactory(new ServicePartitionResolver(() => _fabricClient));
        }
        public static void RegisterComponents(HttpConfiguration config)
        {
            UnityContainer container = new UnityContainer();

            HttpCommunicationClientFactory clientFactory = new HttpCommunicationClientFactory();

            container.RegisterType<DefaultController>(new InjectionConstructor(clientFactory));

            config.DependencyResolver = new UnityDependencyResolver(container);
        }
        public static void RegisterComponents(HttpConfiguration config)
        {
            UnityContainer container = new UnityContainer();

            HttpCommunicationClientFactory clientFactory = new HttpCommunicationClientFactory();

            container.RegisterType <DefaultController>(new InjectionConstructor(clientFactory));

            config.DependencyResolver = new UnityDependencyResolver(container);
        }
        static DefaultController()
        {
            serviceUri = new Uri(FabricRuntime.GetActivationContext().ApplicationName + "/WordCountService");

            backoffQueryDelay = TimeSpan.FromSeconds(3);

            fabricClient = new FabricClient();

            communicationFactory = new HttpCommunicationClientFactory(new ServicePartitionResolver(() => fabricClient));
        }
        public CartController(UserManager <ApplicationUser> userManager)
        {
            cartServiceUri = new Uri(FabricRuntime.GetActivationContext()
                                     .ApplicationName + "/StatefulCart");
            purchaseServiceApiUri = new Uri(FabricRuntime.GetActivationContext()
                                            .ApplicationName + "/TestWebApi");

            _db          = new VideoStoreContext();
            _userManager = userManager;

            fabricClient = new FabricClient();
            commFactory  = new HttpCommunicationClientFactory(
                new ServicePartitionResolver(() => fabricClient));
        }
        private async Task AskForApproval(string employeeName, DateTime startDate, int length)
        {
            Data.RequestDate = startDate;
            Data.Length      = length;
            var isLeaveApproved      = false;
            var fabricClient         = new FabricClient();
            var communicationFactory =
                new HttpCommunicationClientFactory(new ServicePartitionResolver(() => fabricClient));
            var lineManagerServiceUri = new Uri(
                FabricRuntime.GetActivationContext().ApplicationName + "/LineManagerLeaveApprovalService");
            var lineManagerClient = new ServicePartitionClient <HttpCommunicationClient>(
                communicationFactory,
                lineManagerServiceUri,
                new ServicePartitionKey());

            var hrManagerServiceUri = new Uri(
                FabricRuntime.GetActivationContext().ApplicationName + "/HRLeaveApprovalService");
            var hrClient = new ServicePartitionClient <HttpCommunicationClient>(
                communicationFactory,
                hrManagerServiceUri,
                new ServicePartitionKey());

            await lineManagerClient.InvokeWithRetryAsync(
                async client1 =>
            {
                var lineManagerResponse =
                    await client1.HttpClient.GetStringAsync(
                        new Uri(client1.Url, $"Employee?name={employeeName}&startDate={startDate}&length={length}"));
                if (lineManagerResponse == "true")
                {
                    ServiceEventSource.Current.Message($"Line manager approval received for employee: {employeeName}");
                    await hrClient.InvokeWithRetryAsync(
                        async client2 =>
                    {
                        var hrLeaveApprovalResponse = await client2.HttpClient.GetStringAsync(
                            new Uri(client2.Url, $"Employee?name={employeeName}&startDate={startDate}&length={length}"));
                        if (hrLeaveApprovalResponse == "true")
                        {
                            ServiceEventSource.Current.Message($"HR approval received for employee: {employeeName}");
                            isLeaveApproved = true;
                        }
                    });
                }
            });

            Data.Approved = isLeaveApproved;
            // Send notification to employee here and finally mark the saga as complete.
            ServiceEventSource.Current.Message($"Leave approval process completed for employee: {employeeName}");
            this.MarkAsComplete();
        }
        /// <summary>
        /// Sends a POST request as an asynchronous operation to the specified Uri with the
        /// given value serialized as JSON.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="communicationClientFactory">THe communication client factory</param>
        /// <param name="serviceUri">The service Uri the request is sent to</param>
        /// <param name="url">The Url the request is sent to</param>
        /// <param name="value">The value to be sent in the request</param>
        /// <param name="authorization">Authentication header</param>
        /// <returns>
        /// Returns <see cref="Task{TResult}"/>. The task object representing the asynchronous
        /// operation.
        /// </returns>
        public static async Task <HttpResponseMessage> ServicePostAsync <T>(this HttpCommunicationClientFactory communicationClientFactory, Uri serviceUri, string url, T value, AuthenticationHeaderValue authorization = null)
        {
            var partitionClient = new ServicePartitionClient <HttpCommunicationClient>(
                communicationClientFactory,
                serviceUri,
                ServicePartitionKey.Singleton);

            return(await partitionClient.InvokeWithRetryAsync(
                       async client =>
            {
                if (null != authorization)
                {
                    client.HttpClient.DefaultRequestHeaders.Authorization = authorization;
                }

                return await client.HttpClient.PostAsJsonAsync(new Uri(client.Url, url), value);
            }));
        }
        private async void AskForApproval(string employeeName)
        {
            var fabricClient         = new FabricClient();
            var communicationFactory = new HttpCommunicationClientFactory(new ServicePartitionResolver(() => fabricClient));
            var serviceUri           = new Uri(FabricRuntime.GetActivationContext().ApplicationName + "/LineManagerLeaveApprovalService");

            ServicePartitionClient <HttpCommunicationClient> partitionClient =
                new ServicePartitionClient <HttpCommunicationClient>(
                    communicationFactory,
                    serviceUri,
                    new ServicePartitionKey());

            await
            partitionClient.InvokeWithRetryAsync(
                async (client) =>
            {
                await client.HttpClient.PutAsync(
                    new Uri(client.Url, "Employee/" + employeeName),
                    new StringContent(String.Empty));
            });
        }
Exemplo n.º 13
0
        public SimulationSchedulerController(IHistoryRepository historyRepository)
        {
            this.HistoryRepository = historyRepository;

            _CommunicationFactory = new HttpCommunicationClientFactory(ServicePartitionResolver.GetDefault());
        }
Exemplo n.º 14
0
        public static IServiceCollection AddHttpRequestDispatcherProvider(this IServiceCollection services, HttpCommunicationClientFactory provider)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            services.AddSingleton(provider);

            return(services);
        }
Exemplo n.º 15
0
 static CustomerController()
 {
     serviceUri           = new Uri(FabricRuntime.GetActivationContext().ApplicationName + "/ECTSService");
     fabricClient         = new FabricClient();
     communicationFactory = new HttpCommunicationClientFactory(new ServicePartitionResolver(() => fabricClient));
 }
 static StatelessBackEndService()
 {
     serviceUri = new Uri("fabric:/SFInsideOutPerfCompare/BackEnd.Core.Stateless");
     communicationClientFactory = new HttpCommunicationClientFactory();
 }