public void ExecuteDiscovery(ScomDiscoveryType direction, IEnumerable <T> objects) { var discoveryDataIncremental = PrepareScomDiscoveryData(direction, objects); switch (direction) { case ScomDiscoveryType.Insert: discoveryDataIncremental.Commit(_managementGroup); break; case ScomDiscoveryType.Update: discoveryDataIncremental.Overwrite(_managementGroup); break; case ScomDiscoveryType.Delete: discoveryDataIncremental.Commit(_managementGroup); break; } }
protected virtual IncrementalDiscoveryData PrepareScomDiscoveryData(ScomDiscoveryType direction, IEnumerable <T> objects) { // create object for both incremental and full discovery var result = new IncrementalDiscoveryData(); foreach (var @object in objects) { if ([email protected](_seedClass, _actionPointClass).IsValid) { throw new Exception($"Instance has invalid properties or missing required properties"); } var newSeedInstance = new CreatableEnterpriseManagementObject(_managementGroup, _seedClass); CreatableEnterpriseManagementRelationshipObject newSomethingShouldManageInstance = null; foreach (var classProperty in _seedClass.PropertyCollection) { try { newSeedInstance[classProperty].Value = @object[classProperty.Id]; } catch (KeyNotFoundException) // ignore situations, when non-key or non-required fields are not available { if (classProperty.Required || classProperty.Key) { throw; } } } // Set displayname try { newSeedInstance[_displayNamePropertyId].Value = @object[_displayNamePropertyId]; } catch (Exception ex) { } //Unhosted, with specific action point if (!_seedClass.Hosted && _actionPointClass != null && @object.ActionPoint != null) { if (_relMapShouldManageEntity != null) { newSomethingShouldManageInstance = new CreatableEnterpriseManagementRelationshipObject(_managementGroup, _relMapShouldManageEntity); newSomethingShouldManageInstance.SetTarget(newSeedInstance); newSomethingShouldManageInstance.SetSource(@object.ActionPoint); } // sometimes when specific Health Service is deleted, relationship may revert to All Management Server Pool if (_relHsShouldManageEntity != null && [email protected](_managementGroup.EntityTypes.GetClass(_managementServicePoolClassId))) { newSomethingShouldManageInstance = new CreatableEnterpriseManagementRelationshipObject(_managementGroup, _relHsShouldManageEntity); newSomethingShouldManageInstance.SetTarget(newSeedInstance); newSomethingShouldManageInstance.SetSource(@object.ActionPoint); } if (_relMapShouldManageEntity == null && _relHsShouldManageEntity == null) { throw new NotSupportedException("Scenario not supported."); } } // Hosted, in this case myActionPointClass is the hosing class if (_seedClass.Hosted && _actionPointClass != null && @object.ActionPoint != null) { //Doesn't break reference most likely, needs to be tested var hostClass = _actionPointClass; while (hostClass != null) { foreach (var hostProperty in hostClass.PropertyCollection) { if (hostProperty.Key) { newSeedInstance[hostProperty].Value = @object.ActionPoint[hostProperty].Value; } } hostClass = hostClass.FindHostClass(); } } switch (direction) { case ScomDiscoveryType.Insert: case ScomDiscoveryType.Update: result.Add(newSeedInstance); if (newSomethingShouldManageInstance != null) { result.Add(newSomethingShouldManageInstance); } // don't need Hosted==True check, newSomethingShouldManageInstance will be null for hosted classes if (newSomethingShouldManageInstance != null && direction == ScomDiscoveryType.Update) { PerformRelationshipCleanup(_seedClass, newSeedInstance, @object.ActionPoint); } //if (mySeedClass.Hosted) { } break; case ScomDiscoveryType.Delete: result.Remove(newSeedInstance); if (newSomethingShouldManageInstance != null) { result.Remove(newSomethingShouldManageInstance); } break; default: throw new Exception("Unknown direction, unable to prepare discovery"); } } return(result); }