private void AddServiceInstanceModel2Map(ServiceInstanceModel model) { if (!_serviceInstanceMap.ContainsKey(model.InstanceID)) { _serviceInstanceMap.Add(model.InstanceID, model); } else { Debug.WriteLine("Service instance {0} already exists and cannot be added", model.InstanceID); } }
private void UpdateServiceList(List <ServiceInstance> updatedList) { try { // first of all update the flat Map with the new instances foreach (var instance in updatedList) { if (_serviceInstanceMap.ContainsKey(instance.InstanceID.ToString())) { // if service instance already exists, replace it's scheduling info and notify about the change _serviceInstanceMap[instance.InstanceID.ToString()].Instance.SchedulingInfo = instance.SchedulingInfo; _serviceInstanceMap[instance.InstanceID.ToString()].NotifyAllPropertyChanged(); } else { // insert into the flat Map var instanceModel = new ServiceInstanceModel { Instance = instance }; _serviceInstanceMap.Add(instanceModel.InstanceID, instanceModel); instance.Connect(); instance.StateChanged += ServiceInstance_StateChanged; } } // update the hierarchy foreach (var instance in updatedList) { var instanceModel = _serviceInstanceMap[instance.InstanceID.ToString()]; if (instance.ParentInstance == null) { if (!_serviceInstanceList.Contains(instanceModel)) { _serviceInstanceList.Add(instanceModel); } } else { var parentInstance = _serviceInstanceMap[instance.ParentInstance.InstanceID.ToString()]; if (parentInstance != null) { if (!parentInstance.ChildsSteps.Contains(instanceModel)) { parentInstance.ChildsSteps.Add(instanceModel); } } } } } catch (Exception ex) { Log.Write(ToString(), String.Format("Failed to update service instances, ex: {0}", ex.Message), LogMessageType.Error); } }
private void RemoveServiceRecursively(ServiceInstanceModel service) { // clean all service childs recursively if (service.ChildsSteps != null) { foreach (var child in service.ChildsSteps) { RemoveServiceRecursively(child); } service.ChildsSteps.Clear(); } _serviceInstanceMap.Remove(service.InstanceID); }
private void GenerateSampleData() { for (var i = 0; i < 10; i++) { var instanceModel = new ServiceInstanceModel { Instance = CreateServiceInstance(String.Format("service{0}", i)) }; for (var j = 0; j < i; j++) { var instanseChild = new ServiceInstanceModel { Instance = CreateServiceInstance(String.Format("service{0} child{1}", i, j)) }; // add to childs and to map instanceModel.ChildsSteps.Add(instanseChild); AddServiceInstanceModel2Map(instanseChild); } // add to list and to map _serviceInstanceList.Add(instanceModel); AddServiceInstanceModel2Map(instanceModel); } }