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)); }
private static async Task <string[]> InitStartupState() { var tasks = new List <Task <string> >(); var services = _servicesCollector.GetServices(); for (var i = 0; i < services.Count; ++i) { if ((services[i].Name.IndexOf(_serviceConfig.GetServiceName()) == -1) && services[i].Active) { var initServiceStateTask = GetInitServiceState(services[i]); tasks.Add(initServiceStateTask); var serviceState = await initServiceStateTask; if (serviceState != null) { var appsState = JsonConvert.DeserializeObject <AppsHash>(serviceState); ProcessAppsSate(appsState, services[i]); } } } return(await Task.WhenAll(tasks.ToArray())); }
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); } }