コード例 #1
0
 private static void ProcessAppsSate(AppsHash appsState, ServiceItem service)
 {
     foreach (KeyValuePair <string, AppInfoEx> entry in appsState)
     {
         entry.Value.Weight = (entry.Value.ServiceName == _serviceConfig.GetServiceName()) ? 0 : _servicesCollector.GetServiceWeight(entry.Value.ServiceName);
         AppInfoStorageController.CheckAndSetAppInfo(entry.Value, _serviceConfig.GetServiceAddress(), service.Url);
     }
 }
コード例 #2
0
 public static void CheckAndSetAppInfo(AppInfoEx appInfo, string currentServiceName, string serviceName)
 {
     lock (_lock)
     {
         if (NeedUpdate(appInfo.Hash, appInfo.Time, currentServiceName, serviceName))
         {
             AppInfoStorageController.SetAppInfo(appInfo);
         }
     }
 }
コード例 #3
0
        public void Post(Contracts.StateChangedEvent stateEvent)
        {
            Console.WriteLine("Receive info app from " + stateEvent.ServiceName);
            ResetService(stateEvent.ServiceName);
            var serviceName = _serviceConfig.GetServiceAddress();

            if (AppInfoStorageController.NeedUpdate(stateEvent.AppState.Hash, stateEvent.AppState.Time, serviceName, stateEvent.ServiceName))
            {
                SendGetAppInfoRequest(stateEvent);
            }
        }
コード例 #4
0
 public static void StepForwardAndSetAppInfo(AppInfoEx appInfo)
 {
     lock (_lock)
     {
         var stotingInfo = AppInfoStorageController.GetAppInfo(appInfo.Hash);
         if (stotingInfo != null)
         {
             appInfo.Time = stotingInfo.Time + 1;
         }
         AppInfoStorageController.SetAppInfo(appInfo);
     }
 }
コード例 #5
0
        public void Post(Contracts.AppInfo appInfo)
        {
            var appInfoEx = new AppInfoEx()
            {
                Name        = appInfo.Name,
                Url         = appInfo.Url,
                Weight      = 0,
                Status      = appInfo.Status,
                Time        = 1,
                Hash        = AppInfoStorageController.GenerateHash(appInfo.Url),
                ServiceName = _serviceConfig.GetServiceName(),
            };

            AppInfoStorageController.StepForwardAndSetAppInfo(appInfoEx);
            Console.WriteLine("Application with name: " + appInfo.Name + " and status: " + appInfo.Status + " and url: " + appInfo.Url + " and weight: 0 ");

            Task.WaitAll(SendStateChangedEvent(appInfoEx));
        }
コード例 #6
0
        private async void SendGetAppInfoRequest(Contracts.StateChangedEvent stateEvent)
        {
            var serviceUrl = _servicesCollector.GetServiceUrl(stateEvent.ServiceName);

            if (serviceUrl != null)
            {
                var query = HttpUtility.ParseQueryString(string.Empty);
                query["serviceName"] = _serviceConfig.GetServiceName();
                query["hash"]        = Uri.EscapeDataString(stateEvent.AppState.Hash);

                var response = await _httpClient.GetAsync(serviceUrl + "?" + query.ToString());

                var formattedResponse = await response.Content.ReadAsStringAsync();

                var serviceName = _serviceConfig.GetServiceAddress();
                var appInfo     = JsonConvert.DeserializeObject <AppInfoEx>(formattedResponse);
                appInfo.Weight = _servicesCollector.GetServiceWeight(appInfo.ServiceName);

                AppInfoStorageController.CheckAndSetAppInfo(appInfo, serviceName, stateEvent.ServiceName);
            }
        }
コード例 #7
0
 public string Get(string appName)
 {
     return(AppInfoStorageController.GetOptimalUrl(appName));
 }
コード例 #8
0
 public AppInfoEx Get(string serviceName, string hash)
 {
     Console.WriteLine("Get app state request from " + serviceName);
     ResetService(serviceName);
     return(AppInfoStorageController.GetAppInfo(Uri.UnescapeDataString(hash)));
 }
コード例 #9
0
 public AppsHash Get(string serviceName)
 {
     Console.WriteLine("Get all state request from " + serviceName);
     ResetService(serviceName);
     return(AppInfoStorageController.GetState());
 }