protected override Scenario Handle(Event e, ref ListenerAction result) { PlayedChessEvent pEvent = e as PlayedChessEvent; if (pEvent == null) { return(null); } if (pEvent.mOpponent == null) { return(null); } if (!pEvent.WonGame) { return(null); } Sim sim = e.Actor as Sim; if (sim == null) { return(null); } mOpponent = pEvent.mOpponent.SimDescription; return(base.Handle(e, ref result)); }
protected override Scenario Handle(Event e, ref ListenerAction result) { mRepaired = e.TargetObject as GameObject; if (mRepaired == null) { return(null); } Sim sim = e.Actor as Sim; if (sim == null) { return(null); } if (mRepaired.LotCurrent == null) { return(null); } if (mRepaired.LotCurrent.CanSimTreatAsHome(sim)) { return(null); } mHousehold = mRepaired.LotCurrent.Household; return(base.Handle(e, ref result)); }
protected override Scenario Handle(Event e, ref ListenerAction result) { if (!GetValue <ForceChangeOption, bool>()) { return(null); } return(base.Handle(e, ref result)); }
protected override Scenario Handle(Event e, ref ListenerAction result) { mEvent = e as HouseholdUpdateEvent; if (mEvent == null) return null; mOldHousehold = StoryProgression.Main.Households.ActiveHousehold; return base.Handle(e, ref result); }
protected override Scenario Handle(Event e, ref ListenerAction result) { CareerHiredBaseScenario scenario = base.Handle(e, ref result) as CareerHiredBaseScenario; if (scenario != null) { scenario.UpdateText(); } return scenario; }
protected override Scenario Handle(Event e, ref ListenerAction result) { mSim = e.TargetObject as Sim; if (mSim == null) { return(null); } return(base.Handle(e, ref result)); }
protected override Scenario Handle(Event e, ref ListenerAction result) { if (Sim != GetEventSim(e)) return null; Scenario scenario = base.Handle(e, ref result); result = ListenerAction.Remove; return scenario; }
protected override Scenario Handle(Event e, ref ListenerAction result) { CareerHiredBaseScenario scenario = base.Handle(e, ref result) as CareerHiredBaseScenario; if (scenario != null) { scenario.UpdateText(); } return(scenario); }
protected override Scenario Handle(Event e, ref ListenerAction result) { mEvent = e as HouseholdUpdateEvent; if (mEvent == null) { return(null); } mOldHousehold = StoryProgression.Main.Households.ActiveHousehold; return(base.Handle(e, ref result)); }
protected override Scenario Handle(Event paramE, ref ListenerAction result) { NPCPartyArriveScenario scenario = base.Handle(paramE, ref result) as NPCPartyArriveScenario; if (scenario == null) { return(null); } scenario.PrivateUpdate(null); return(null); }
protected override Scenario Handle(Event e, ref ListenerAction result) { Sim simA = e.Actor as Sim; Sim simB = e.TargetObject as Sim; if ((simA == null) || (simB == null)) { return(null); } return(base.Handle(e, ref result)); }
protected override Scenario Handle(Event e, ref ListenerAction result) { WentToWorkScenario scenario = base.Handle(e, ref result) as WentToWorkScenario; if (scenario != null) { // Do this now, rather than waiting the 10 sim-minute Scenario manager delay Careers.VerifyTone(scenario.Sim); } return(scenario); }
void _RemoveListener(string eventName, ListenerAction <EventPayload> action) { EventInvoker <EventPayload> invoker; if (events.TryGetValue(eventName, out invoker)) { invoker.RemoveListener(action); if (events[eventName].ListenersCount == 0) { events.Remove(eventName); } } }
protected override Scenario Handle(Event e, ref ListenerAction result) { PromotedScenario scenario = base.Handle(e, ref result) as PromotedScenario; if (scenario != null) { scenario.UpdateText(); scenario.mSuppressed.AddRange(sSuppressed); sSuppressed.Clear(); } return(scenario); }
protected override Scenario Handle(Event e, ref ListenerAction result) { mLot = e.TargetObject as Lot; if (mLot == null) { return(null); } if (mLot.Household == null) { return(null); } return(base.Handle(e, ref result)); }
protected override Scenario Handle(Event e, ref ListenerAction result) { HasGuidEvent <BuffNames> bEvent = e as HasGuidEvent <BuffNames>; if (bEvent == null) { return(null); } if (!Allow(bEvent.Guid)) { return(null); } return(base.Handle(e, ref result)); }
protected override Scenario Handle(Event e, ref ListenerAction result) { HouseholdUpdateEvent data = e as HouseholdUpdateEvent; if (data != null) { House = data.Household; } else { House = e.TargetObject as Household; } if (House == null) return null; return Clone(); }
protected override Scenario Handle(Event paramE, ref ListenerAction result) { MartialArts.SparEvent e = paramE as MartialArts.SparEvent; if (e == null) { return(null); } if (e.HasWon) { return(null); } mWinner = e.Actor as Sim; return(base.Handle(paramE, ref result)); }
public ListenerAction Listen(Event e) { ListenerAction result = ListenerAction.Keep; try { Scenario scenario = Handle(e, ref result); if (scenario != null) { Spawn(scenario); } } catch (Exception exception) { Common.Exception(e.Actor, e.TargetObject, exception); } return(result); }
protected override Scenario Handle(Event e, ref ListenerAction result) { HouseholdUpdateEvent data = e as HouseholdUpdateEvent; if (data != null) { House = data.Household; } else { House = e.TargetObject as Household; } if (House == null) { return(null); } return(Clone()); }
protected override Scenario Handle(Event e, ref ListenerAction result) { mWasSecondCycle = Main.SecondCycle; mEvent = e as TEvent; if (mEvent == null) { IncStat("Event Mismatch"); return(null); } Sim = GetEventSim(e); if (Sim == null) { IncStat("No Event Sim"); return(null); } return(Clone()); }
protected override Scenario Handle(Event e, ref ListenerAction result) { HasGuidEvent <SkillNames> skillEvent = e as HasGuidEvent <SkillNames>; if (skillEvent == null) { return(null); } if (skillEvent.Actor == null) { return(null); } if (skillEvent.Actor.SkillManager == null) { return(null); } mLevel = skillEvent.Actor.SkillManager.GetSkillLevel(skillEvent.Guid); return(base.Handle(e, ref result)); }
protected override Scenario Handle(Event e, ref ListenerAction result) { MartialArts.SparEvent sEvent = e as MartialArts.SparEvent; if (sEvent == null) { return(null); } if (!sEvent.HasWon) { return(null); } if (!sEvent.IsRanked) { return(null); } Sim opponent = sEvent.TargetObject as Sim; if (opponent == null) { return(null); } Sim sim = e.Actor as Sim; if (sim == null) { return(null); } mOpponent = opponent.SimDescription; return(base.Handle(e, ref result)); }
internal AutoScaledInstances( CdkStack stack, CfnParameter targetPlatform, Vpc vpc, bool publicAccess, SecurityGroup albSecurityGroup, SecurityGroup instanceSecurityGroup, Database database = null, Policy policy = null, ApplicationLoadBalancer restApiLoadBalancer = null) { IMachineImage selectedImage; bool targetWindows = false; if (targetWindows) { var userData = UserData.ForWindows(); userData.AddCommands( "New-Item -Path c:\\temp -ItemType Directory -Force", $"Read-S3Object -BucketName aws-codedeploy-{stack.Region}/latest -Key codedeploy-agent.msi -File c:\\temp\\codedeploy-agent.msi", "Start-Process -Wait -FilePath c:\\temp\\codedeploy-agent.msi -WindowStyle Hidden" ); selectedImage = new WindowsImage( WindowsVersion.WINDOWS_SERVER_2019_ENGLISH_CORE_BASE, new WindowsImageProps { UserData = userData } ); } else { var userData = UserData.ForLinux(new LinuxUserDataOptions { Shebang = "#!/bin/bash -xe" }); userData.AddCommands( "exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1", "yum install -y aws-cli ruby jq", "yum -y update", "cd /tmp/", $"curl -O https://aws-codedeploy-{stack.Region}.s3.amazonaws.com/latest/install", "chmod +x ./install", "if ./install auto; then", " echo \"CodeDeploy Agent installation completed successfully!\"", " exit 0", "else", " echo \"CodeDeploy Agent installation failed, please investigate.\"", " rm -f /tmp/install", " exit 1", "fi", "rm -rf /tmp/*" ); selectedImage = new AmazonLinuxImage(new AmazonLinuxImageProps { Edition = AmazonLinuxEdition.STANDARD, Virtualization = AmazonLinuxVirt.HVM, Generation = AmazonLinuxGeneration.AMAZON_LINUX_2, Storage = AmazonLinuxStorage.EBS, UserData = userData }); }; var alb = new ApplicationLoadBalancer(stack, $"ApplicationLoadBalancer-{(publicAccess ? "public" : "private")}", new ApplicationLoadBalancerProps { InternetFacing = publicAccess, Vpc = vpc, VpcSubnets = new SubnetSelection { SubnetType = publicAccess ? SubnetType.PUBLIC : SubnetType.PRIVATE }, SecurityGroup = albSecurityGroup, IpAddressType = IpAddressType.IPV4, Http2Enabled = true }); var albTargetGroup = new ApplicationTargetGroup(stack, $"ApplicationTargetGroup-{(publicAccess ? "public" : "private")}", new ApplicationTargetGroupProps { Vpc = vpc, Port = 80, Protocol = ApplicationProtocol.HTTP, TargetType = TargetType.INSTANCE, HealthCheck = new Amazon.CDK.AWS.ElasticLoadBalancingV2.HealthCheck { Timeout = Duration.Seconds(5), Interval = Duration.Seconds(10), HealthyThresholdCount = 2 } }); var albListener = new ApplicationListener(stack, $"ApplicationListener-{(publicAccess ? "public" : "private")}", new ApplicationListenerProps { Port = 80, Protocol = ApplicationProtocol.HTTP, DefaultAction = ListenerAction.Forward(new[] { albTargetGroup }), LoadBalancer = alb }); var asg = new AutoScalingGroup(stack, $"ASG-{(publicAccess ? "public" : "private")}", new AutoScalingGroupProps { Vpc = vpc, MinCapacity = 2, InstanceType = InstanceType.Of(InstanceClass.BURSTABLE3, InstanceSize.MEDIUM), MachineImage = selectedImage, BlockDevices = new[] { new Amazon.CDK.AWS.AutoScaling.BlockDevice() { DeviceName = "/dev/xvda", Volume = Amazon.CDK.AWS.AutoScaling.BlockDeviceVolume.Ebs( targetWindows ? 30: 8, new Amazon.CDK.AWS.AutoScaling.EbsDeviceOptions { VolumeType = Amazon.CDK.AWS.AutoScaling.EbsDeviceVolumeType.GP2, DeleteOnTermination = true } ) } }, AssociatePublicIpAddress = false, VpcSubnets = new SubnetSelection { SubnetType = SubnetType.PRIVATE } }); if (policy != null) { asg.Role.AttachInlinePolicy(policy); } asg.Role.AddToPrincipalPolicy( new PolicyStatement(new PolicyStatementProps { Effect = Effect.ALLOW, Actions = new[] { "ec2:DescribeTags" }, Resources = new[] { "*" } }) ); asg.Role.AddManagedPolicy(ManagedPolicy.FromAwsManagedPolicyName("AmazonSSMManagedInstanceCore")); asg.Role.AddManagedPolicy(ManagedPolicy.FromAwsManagedPolicyName("AWSXRayDaemonWriteAccess")); asg.Role.AddManagedPolicy(ManagedPolicy.FromAwsManagedPolicyName("CloudWatchAgentServerPolicy")); Tag.Add(asg, "Application", stack.StackName); if (publicAccess) { Tag.Add(asg, "ApplicationRole", "Front End"); Tag.Add(asg, "RESTAPIAddress", restApiLoadBalancer.LoadBalancerDnsName); } else { Tag.Add(asg, "ApplicationRole", "REST API"); } if (database != null) { asg.Node.AddDependency(database.DatabaseResource); Tag.Add(asg, "DBSecretArn", database.Password.SecretArn); } // Enable access from the ALB asg.AddSecurityGroup(instanceSecurityGroup); Result = new LoadBalancedInstancesResult { AutoScalingGroup = asg, TargetGroup = albTargetGroup, LoadBalancer = alb }; }
public ApplicationLoadBalancer Create(Construct construct, Amazon.CDK.AWS.EC2.Vpc vpc, Amazon.CDK.AWS.AutoScaling.AutoScalingGroup asg, SecurityGroup sg) { var lb = new ApplicationLoadBalancer(construct, _config.Alb.Name, new ApplicationLoadBalancerProps { Vpc = vpc, InternetFacing = true, LoadBalancerName = _config.Alb.Name, SecurityGroup = sg }); Amazon.CDK.Tags.Of(lb).Add("Name", $"{_config.Alb.Name}"); // add a listener var listener = AddListener(lb, 80, null); var appPort = 80; var group = listener.AddTargets($"AppFleet", new AddApplicationTargetsProps { Port = appPort, Targets = new[] { asg } }); // add specific tags Amazon.CDK.Tags.Of(listener).Add("Name", $"{_config.Alb.Name}-listner"); Amazon.CDK.Tags.Of(group).Add("Name", $"{_config.Alb.Name}-fleet"); // exmple of a fixed ok message returned by the LB listener.AddAction($"FixedOkMessage", new AddApplicationActionProps { Priority = 10, Conditions = new[] { ListenerCondition.PathPatterns(new[] { "/ok" }) }, Action = ListenerAction.FixedResponse(200, new FixedResponseOptions { ContentType = "text/html", MessageBody = "OK" }) }); // example of a fixed health status message returned by LB listener.AddAction($"LBHealthInfo", new AddApplicationActionProps { Priority = 15, Conditions = new[] { ListenerCondition.PathPatterns(new[] { "/lb-status" }) }, Action = ListenerAction.FixedResponse(200, new FixedResponseOptions { ContentType = "application/json", MessageBody = "{ \"lb\": { \"type\": \"application-load-balancer\", \"launchDateUtc\": \"{" + DateTime.UtcNow + "}\", \"status\": \"ok\" } }" }) }); //"arn:aws:acm:us-east-1:xxxxxxxxx:certificate/eb2b584c-421d-4134-b679-1746642b5e3f" if (_config.Alb.CertArn != null) { listener = AddListener(lb, 443, _config.Alb.CertArn); // forward any ssl requests to the target group listener.AddAction("SSLForward", new AddApplicationActionProps { Action = ListenerAction.Forward(new[] { group }), }); } return(lb); }
void _AddListener(string eventName, ListenerAction <EventPayload> action, object emitterToListen = null) { _AddEvent(eventName); events[eventName].AddListener(action, emitterToListen); }
static public void RemoveListener(string eventName, ListenerAction <EventPayload> action) { Instance._RemoveListener(eventName, action); }
protected override Scenario Handle(Event e, ref ListenerAction result) { PregnancyEvent pe = e as PregnancyEvent; if (pe == null) { return(null); } if ((pe.Babies == null) || (pe.Babies.Count == 0)) { return(null); } Sim mom = pe.Actor as Sim; if (mom == null) { return(null); } if (mom.SimDescription == null) { return(null); } List <SimDescription> parents = Relationships.GetParents(pe.Babies[0].SimDescription); if (parents.Count == 0) { return(null); } SimDescription actualMom = null; foreach (SimDescription parent in parents) { if (parent.Pregnancy == pe.Pregnancy) { actualMom = parent; break; } } if (actualMom == null) { actualMom = parents[0]; } // Stops the second PregnancyEvent fired for the father from being picked up if (actualMom != mom.SimDescription) { return(null); } mBabies = new List <SimDescription>(); foreach (Sim baby in pe.Babies) { mBabies.Add(baby.SimDescription); } Scenario scenario = base.Handle(e, ref result); if (scenario == null) { return(null); } return(scenario); }
internal InfraStack(Construct scope, string id, CustomStackProps props = null) : base(scope, id, props) { var vpc = props.Vpc; var cluster = new Cluster(this, "Cluster", new ClusterProps { Vpc = vpc, ClusterName = Globals.GetDeployEnvironment(this).PutEnvNamePrefixWithDash("Cluster") }); var albSecurityGroup = new SecurityGroup(this, "AlbSecurityGroup", new SecurityGroupProps { Vpc = vpc, AllowAllOutbound = true }); albSecurityGroup.AddIngressRule(Peer.AnyIpv4(), Port.Tcp(80)); var alb = new ApplicationLoadBalancer(this, "ALB", new ApplicationLoadBalancerProps { Vpc = vpc, InternetFacing = true, Http2Enabled = true, IdleTimeout = Duration.Seconds(60), IpAddressType = IpAddressType.IPV4, SecurityGroup = albSecurityGroup }); var webApiServiceSecurityGroup = new SecurityGroup(this, "WebApiServiceSecurityGroup", new SecurityGroupProps { Vpc = vpc, AllowAllOutbound = true }); webApiServiceSecurityGroup.AddIngressRule(albSecurityGroup, Port.Tcp(80)); var appListener = alb.AddListener("AppListener", new BaseApplicationListenerProps { Port = 80, Protocol = ApplicationProtocol.HTTP, DefaultAction = ListenerAction.FixedResponse(404, new FixedResponseOptions { ContentType = "text/plain", MessageBody = "This is not here..." }) }); new CfnOutput(this, "ClusterName", new CfnOutputProps { ExportName = Globals.GetDeployEnvironment(this).PutEnvNamePrefixWithDash("ClusterName"), Value = cluster.ClusterName }); new CfnOutput(this, "WebApiServiceSecurityGroupId", new CfnOutputProps { ExportName = Globals.GetDeployEnvironment(this).PutEnvNamePrefixWithDash("WebApiServiceSecurityGroupId"), Value = albSecurityGroup.SecurityGroupId }); new CfnOutput(this, "AppListenerArn", new CfnOutputProps { ExportName = Globals.GetDeployEnvironment(this).PutEnvNamePrefixWithDash("AppListenerArn"), Value = appListener.ListenerArn }); }
public void AddListener(ListenerAction <T> listenerAction, object emitterToListen = null) { _AddListener(ref listenersWithData, listenerAction, emitterToListen); }
public void RemoveListener(ListenerAction listenerAction) { _RemoveListener(ref listenersWithoutData, listenerAction); }
static public void AddListener(string eventName, ListenerAction <EventPayload> action, object listenTo = null) { Instance._AddListener(eventName, action, listenTo); }
public void RemoveListener(ListenerAction <T> listenerAction) { _RemoveListener(ref listenersWithData, listenerAction); }