public static void SetAppInfo(AppInfoEx appInfo) { var storingInfo = GetAppInfo(appInfo.Hash); if (storingInfo != null) { storingInfo.Status = appInfo.Status; storingInfo.Time = appInfo.Time; } else { AppInfoArray appInfoArray = null; if (_appInfo.TryGetValue(appInfo.Name, out appInfoArray)) { appInfoArray.Add(appInfo); } else { appInfoArray = new AppInfoArray(); appInfoArray.Add(appInfo); _appInfo.Add(appInfo.Name, appInfoArray); } _appHash.Add(appInfo.Hash, appInfo); } }
private Task <HttpResponseMessage>[] SendStateChangedEvent(AppInfoEx appInfo) { var tasks = new List <Task <HttpResponseMessage> >(); var appsState = new Contracts.AppStateInfo() { Hash = appInfo.Hash, Time = appInfo.Time }; var stateEvent = new Contracts.StateChangedEvent(); stateEvent.ServiceName = _serviceConfig.GetServiceName(); stateEvent.AppState = appsState; var services = _servicesCollector.GetServices(); for (var i = 0; i < services.Count; ++i) { if ((services[i].Name.IndexOf(_serviceConfig.GetServiceName()) == -1) && services[i].Active) { string jsonString = JsonConvert.SerializeObject(stateEvent); HttpContent content = new StringContent(jsonString); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); try { tasks.Add(_httpClient.PostAsync(services[i].Url, content)); } catch (Exception) { services[i].Active = false; } } } return(tasks.ToArray()); }
public static AppInfoEx GetAppInfo(string hash) { AppInfoEx appInfo = null; _appHash.TryGetValue(hash, out appInfo); return(appInfo); }
public static void CheckAndSetAppInfo(AppInfoEx appInfo, string currentServiceName, string serviceName) { lock (_lock) { if (NeedUpdate(appInfo.Hash, appInfo.Time, currentServiceName, serviceName)) { AppInfoStorageController.SetAppInfo(appInfo); } } }
public static AppInfoEx GetAppInfo(string appName, string url) { AppInfoEx appInfo = null; AppInfoArray appInfoArray = null; if (_appInfo.TryGetValue(appName, out appInfoArray)) { appInfo = appInfoArray.Find(x => x.Url == url); } return(appInfo); }
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); } }
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)); }