internal static void Map(AwsInstance src, Instance dest, SaveMechanic mechanic) { var nameTag = src.Tags.FirstOrDefault(x => x.Key.Equals("name", StringComparison.InvariantCultureIgnoreCase)); string name = nameTag == null ? string.Format("Unknown-{0}", src.InstanceId) : nameTag.Value; List<IPAddress> privateIpAddresses = src.PrivateIpAddress == null ? new List<IPAddress>() : new List<IPAddress> {IPAddress.Parse(src.PrivateIpAddress)}; List<IPAddress> publicIpAddresses = src.PublicIpAddress == null ? new List<IPAddress>() : new List<IPAddress> {IPAddress.Parse(src.PublicIpAddress)}; List<string> volumeResourceIds = src.BlockDeviceMappings.Select(x => x.Ebs.VolumeId).ToList(); dest.AvailabilityZone = src.Placement.AvailabilityZone; dest.InstanceType = src.InstanceType.Value; dest.KeyName = src.KeyName; dest.LaunchTime = src.LaunchTime; dest.MonitoringState = src.Monitoring.State != MonitoringState.Disabled; dest.Name = name; dest.PrivateAddresses = privateIpAddresses.Select(x => x.ToString()).ToList(); dest.PublicAddresses = publicIpAddresses.Select(x => x.ToString()).ToList(); dest.VolumeResourceIds = volumeResourceIds; dest.ResourceId = src.InstanceId; dest.State = src.State.Name; dest.StorageType = src.RootDeviceType.Value; dest.SubnetId = src.SubnetId; dest.VirtualizationType = src.VirtualizationType.Value; dest.VpcId = src.VpcId; dest.NeedsRefreshing = false; if(mechanic == SaveMechanic.Add) { dest.Id = Guid.NewGuid(); } }
public void Execute(Guid profileId) { IAwsClient awsClient; if (!TryInitializeClient(profileId, out awsClient)) { return; } List <InstanceResource> awsInstances = awsClient.InstanceService.GetAllInstances().ToList(); Dictionary <string, List <SecurityGroupResource> > securityGroupsFor = awsClient.SecurityGroupService.GetSecurityGroupMap(awsInstances); foreach (InstanceResource awsInstance in awsInstances) { List <SecurityGroupEntity> securityGroups = securityGroupsFor[awsInstance.InstanceId] .Select(x => new SecurityGroupEntity { Name = x.GroupName, ResourceId = x.GroupId }).ToList(); string instanceId = awsInstance.InstanceId; InstanceEntity dbInstance = _instanceRepository.FindAll() .FirstOrDefault(x => StackItIdTagsMatch(x, awsInstance) || x.ResourceId == instanceId); InstanceEntity instanceToPersist = dbInstance ?? new InstanceEntity(); SaveMechanic saveMechanic = dbInstance == null ? SaveMechanic.Add : SaveMechanic.Update; UpdateInstance.Map(awsInstance, instanceToPersist, saveMechanic); instanceToPersist.OwnerProfileId = profileId; instanceToPersist.SecurityGroups = securityGroups; UpdateInstance.Persist(_instanceRepository, instanceToPersist, saveMechanic); } }
internal static void Map(AwsInstance src, Instance dest, SaveMechanic mechanic) { var nameTag = src.Tags.FirstOrDefault(x => x.Key.Equals("name", StringComparison.InvariantCultureIgnoreCase)); string name = nameTag == null?string.Format("Unknown-{0}", src.InstanceId) : nameTag.Value; List <IPAddress> privateIpAddresses = src.PrivateIpAddress == null ? new List <IPAddress>() : new List <IPAddress> { IPAddress.Parse(src.PrivateIpAddress) }; List <IPAddress> publicIpAddresses = src.PublicIpAddress == null ? new List <IPAddress>() : new List <IPAddress> { IPAddress.Parse(src.PublicIpAddress) }; List <string> volumeResourceIds = src.BlockDeviceMappings.Select(x => x.Ebs.VolumeId).ToList(); dest.AvailabilityZone = src.Placement.AvailabilityZone; dest.InstanceType = src.InstanceType.Value; dest.KeyName = src.KeyName; dest.LaunchTime = src.LaunchTime; dest.MonitoringState = src.Monitoring.State != MonitoringState.Disabled; dest.Name = name; dest.PrivateAddresses = privateIpAddresses.Select(x => x.ToString()).ToList(); dest.PublicAddresses = publicIpAddresses.Select(x => x.ToString()).ToList(); dest.VolumeResourceIds = volumeResourceIds; dest.ResourceId = src.InstanceId; dest.State = src.State.Name; dest.StorageType = src.RootDeviceType.Value; dest.SubnetId = src.SubnetId; dest.VirtualizationType = src.VirtualizationType.Value; dest.VpcId = src.VpcId; dest.NeedsRefreshing = false; if (mechanic == SaveMechanic.Add) { dest.Id = Guid.NewGuid(); } }
public void Execute(Guid profileId, string instanceId) { IAwsClient awsClient; if (!TryInitializeClient(profileId, out awsClient)) { return; } AwsInstance awsInstance = awsClient.InstanceService.GetInstance(instanceId); if (awsInstance == null) { // Don't do any work if the instance isn't even in Amazon anymore return; } IEnumerable <SecurityGroup> awsSecurityGroups = awsClient.InstanceService.GetSecurityGroups(awsInstance); List <Core.Entities.SecurityGroup> securityGroups = awsSecurityGroups.Select(x => new Core.Entities.SecurityGroup { Name = x.GroupName, ResourceId = x.GroupId }).ToList(); Instance dbInstance = _instanceRepository.FindAll().FirstOrDefault(x => x.ResourceId == instanceId); Instance instanceToPersist = dbInstance ?? new Instance(); SaveMechanic saveMechanic = dbInstance == null ? SaveMechanic.Add : SaveMechanic.Update; Map(awsInstance, instanceToPersist, saveMechanic); instanceToPersist.OwnerProfileId = profileId; instanceToPersist.SecurityGroups = securityGroups; Persist(_instanceRepository, instanceToPersist, saveMechanic); }
private void Persist(Stack stackToPersist, SaveMechanic saveMechanic) { switch (saveMechanic) { case SaveMechanic.Add: _stackRepository.Add(stackToPersist); break; case SaveMechanic.Update: _stackRepository.Update(stackToPersist); break; default: throw new InvalidOperationException("Unknown save mechanic. This should never happen."); } }
public void Execute(Guid profileId) { IAwsClient awsClient; if (!TryInitializeClient(profileId, out awsClient)) { return; } IImageService imageService = awsClient.ImageService; List <Image> images = imageService.GetImagesByTagName(Conventions.BaseImageTag); foreach (Image image in images) { var imageName = image.Tags.Single(x => x.Key == Conventions.BaseImageTag).Value; BaseImage baseImage = _imageRepository.FindAll().FirstOrDefault(x => x.Name == imageName); SaveMechanic saveMechanic = baseImage == null ? SaveMechanic.Add : SaveMechanic.Update; baseImage = baseImage ?? new BaseImage(); MapToBaseImage(image, baseImage); // TODO: Still need a way to remove stale AMI's // like when someone deletes an AMI whose id was already stored locally with a profile if (imageName.ToLower().EndsWith("-edge")) { baseImage.EdgeAmi[profileId] = image.ImageId; } else { baseImage.ProductionAmi[profileId] = image.ImageId; } if (saveMechanic == SaveMechanic.Add) { _imageRepository.Add(baseImage); } else { _imageRepository.Update(baseImage); } } }
// Start is called before the first frame update void Start() { isPaused = true; //start the level paused levelComplete = false; //false at start, because obviously the player would not be able to beat the level as soon as it loads ShowTutorial(); //show the tutorial for the level if (GameObject.Find("SaveManager") != null) { saveManagerScript = GameObject.Find("SaveManager").GetComponent <SaveMechanic>(); } else { // If there is no SaveManager object (bc the game was started from game and not menu) // Create a SaveManager object and attach the SaveMechanic script to it GameObject saveManagerObject = new GameObject("SaveManager"); saveManagerObject.AddComponent <SaveMechanic>(); saveManagerScript = saveManagerObject.GetComponent <SaveMechanic>(); } }
public void LoadStack(IAwsClient awsClient, AwsStack stack, string hostedZone, Guid profileId) { Stack dbStack = _stackRepository.FindAll().FirstOrDefault(x => x.Name == stack.StackName); IEnumerable <StackResource> stackResources = awsClient.StackService.GetResources(stack).ToList(); List <ResourceRecord> resourceRecords = GetResourceRecords(awsClient, stackResources, stack, hostedZone); List <Guid> instanceIds = GetInstanceIds(stackResources).ToList(); Stack stackToPersist = dbStack ?? new Stack(); SaveMechanic saveMechanic = dbStack == null ? SaveMechanic.Add : SaveMechanic.Update; Map(stack, stackToPersist); stackToPersist.ResourceRecords = resourceRecords; if (!stackToPersist.CreatedByApplication) { stackToPersist.InstanceIds = instanceIds; } stackToPersist.StackEvents = GetStackEvents(awsClient, stack); stackToPersist.OwnerProfileId = profileId; Persist(stackToPersist, saveMechanic); }
internal static void Persist(IRepository<Instance> instanceRepository, Instance instanceToPersist, SaveMechanic saveMechanic) { switch(saveMechanic) { case SaveMechanic.Add: instanceRepository.Add(instanceToPersist); break; case SaveMechanic.Update: instanceRepository.Update(instanceToPersist); break; default: throw new InvalidOperationException("Unknown save mechanic. This should never happen."); } }
// Start is called before the first frame update void Start() { saveManagerScript = GameObject.Find("SaveManager").GetComponent <SaveMechanic>(); }
internal static void Persist(IRepository <Instance> instanceRepository, Instance instanceToPersist, SaveMechanic saveMechanic) { switch (saveMechanic) { case SaveMechanic.Add: instanceRepository.Add(instanceToPersist); break; case SaveMechanic.Update: instanceRepository.Update(instanceToPersist); break; default: throw new InvalidOperationException("Unknown save mechanic. This should never happen."); } }