public ActionException(IActionData turnEvent, string message, params object[] eventData) : base(message) { Event = turnEvent; EventData = eventData; }
public override void Execute(IActionData actionData = null) { var actionTime = Delay; var data = actionData as ActionKeyboardData; if (data != null) { var action = data.ParentAction as ActionLoop; if (action == null) return; if (Delay > action.Time) actionTime = (int)action.Time; } for (var i = 0; i < Amount; i++) { SendKeys.SendWait(Key); //Console.WriteLine("Keyboard: " + Key); Thread.Sleep(actionTime); if (State != ActionState.Running) break; } }
public override void Execute(IActionData actionData = null) { var data = actionData as ActionMouseCircleData; if (data == null) return; var time = Time; var watch = new Stopwatch(); while (data.ParentAction.State == ActionState.Running && time > 0) { const double min = -Math.PI; const double max = +Math.PI; var amount = time / (double)Time; var angle = min + (max - min) * amount; var x = X + Math.Cos(angle) * Radius; var y = Y + Math.Sin(angle) * Radius; Mouse.Click((int)x, (int)y); //Mouse.SetPosition((int)x, (int)y); //Console.WriteLine("Click: {0} {1}", X, Y); time -= watch.ElapsedMilliseconds; watch.Restart(); Thread.Sleep(1); } }
public override void Execute(IActionData actionData = null) { var watch = new Stopwatch(); var currentAction = 0; var time = Time; var data = new ActionKeyboardData() { ParentAction = this }; if (AsyncActions.Count > 0) { thread = new Thread(ExecuteAsyncActions); thread.Start(); } while (time > 0 && State == ActionState.Running) { if (Actions.Count > 0) { var action = Actions[currentAction]; action.Execute(data); currentAction++; if (currentAction >= Actions.Count) currentAction = 0; } time -= watch.ElapsedMilliseconds; watch.Restart(); } }
public void BeforeEach() { _data = Substitute.For <IActionData>(); _data.OnUpdate().Returns(ActionStatus.Continue); _dialogue = Substitute.For <IDialogueController>(); _action = new ActionRuntime(_dialogue, null, _data); }
public override void Execute(IActionData data = null) { var sc = new Screen(); var img = sc.CaptureScreen(); var handler = new ConfigHandler("Data/cf.dat"); var imageName = DateTime.Now.ToString("yyyy.MM.dd-H.mm.ss"); img.Save("Data\\Images\\Image_" + imageName + "_TimeLine-" + handler.TotalTimeLines + ".png", ImageFormat.Png); }
public override ActionExecutionInformation CanPerformEvent(Company company, IActionData eventData, IHub services) { var companyService = services.Resolve<ICompanyService>(); if (!companyService.CanPerformAction(company, Type)) { return new ActionExecutionInformation(false, $"Company {company.Id} cannot perform turn action {Type}.", company); } return new ActionExecutionInformation(true); }
public IStateAction <TState> GetStateActionForData(IActionData data) { var dataType = data.GetType(); if (!_actions.ContainsKey(dataType)) { Debug.LogError($"There's no registered action for data of type {dataType}"); return(null); } return(_actions[dataType]); }
public IAction CreateActionInstance(string actionName, IActionData actionNode, bool overwrite) { IAction returnAction = null; if (true == m_RegisterActionFactory.ContainsKey(actionName)) { Type actionType = m_RegisterActionFactory[actionName]; IAction typeOfAction = (IAction)Activator.CreateInstance(actionType, actionNode, overwrite); returnAction = typeOfAction; } return returnAction; }
public override void Execute(IActionData data = null) { for (var i = 0; i < Amount; i++) { Mouse.Click(X, Y); //Mouse.SetPosition(X, Y); //Console.WriteLine("Click {0}: {1} {2}", i + 1, X, Y); Thread.Sleep(Delay); if (State != ActionState.Running) break; } }
public static void Apply(this IActionData data, ISystemWindow window, ref Rectangle region) { var type = data.GetType(); if (_methods.TryGetValue(type, out var method)) { var parameters = new object[] { data, window, region }; method.Invoke(null, parameters); region = (Rectangle)parameters[2]; } else { throw new ArgumentException($"Not found suitable method for '{type}' type"); } }
private static IList<Order> GetOrders(IActionData x, Ticket ticket) { IList<Order> orders = new List<Order>(); var selectedOrder = x.GetDataValue<Order>("Order"); if (selectedOrder == null) { if (ticket != null) { orders = ticket.Orders.Any(y => y.IsSelected) ? ticket.ExtractSelectedOrders().ToList() : ticket.Orders; } } else orders.Add(selectedOrder); return orders; }
public override CompanyMessage ProcessEvent(Company company, IActionData eventData, IHub services) { var data = eventData as MakeOfferActionData; var personService = services.Resolve<IPersonService>(); var companyService = services.Resolve<ICompanyService>(); var person = personService.GetPerson(data.PersonId); var gameClockService = services.Resolve<IGameClockService>(); var message = new CompanyMessage { Id = Utilities.InvalidId, DateCreated = gameClockService.CurrentDate, Status = CompanyMessageStatus.UnRead, Source = "Human Resources" }; if (personService.IsUnemployed(person)) { var response = companyService.MakeOffer(company, person, data.OfferValue); if (response.DidAccept) { message.Subject = "Offer Accepted"; message.Message = $"{person.FirstName} {person.LastName} accepted an offer of {data.OfferValue:C}."; } else { message.Subject = "Offer Declined"; message.Message = $"{person.FirstName} {person.LastName} declined an offer of {data.OfferValue:C}."; } } else { message.Subject = "Offer Too Late"; message.Message = $"{person.FirstName} {person.LastName} recently accepted an offer elsewhere."; } return message; }
public override CompanyMessage ProcessEvent(Company company, IActionData eventData, IHub services) { var data = eventData as AcceptProjectActionData; var projectService = services.Resolve<IProjectService>(); var project = projectService.GetProject(data.ProjectId); var gameClockService = services.Resolve<IGameClockService>(); var message = new CompanyMessage { Id = Utilities.InvalidId, DateCreated = gameClockService.CurrentDate, Source = "Project Management", Status = CompanyMessageStatus.UnRead }; if (project != null) { if (projectService.CanAcceptProject(project, company.Reputation)) { var companyService = services.Resolve<ICompanyService>(); companyService.AcceptProject(company, project); message.Subject = "We got the project!"; message.Message = $"We have been granted the {project.Definition.Name} project."; } else { message.Subject = "We did not get the project..."; message.Message = $"We were deemed not reputable enough to be granted the {project.Definition.Name} project."; } } else { message.Subject = "We missed out on the project."; message.Message = $"A project we were seeking has been given to another company."; } return message; }
public override ActionExecutionInformation CanPerformEvent(Company company, IActionData eventData, IHub services) { var companyService = services.Resolve<ICompanyService>(); if (!companyService.CanPerformAction(company, Type)) { return new ActionExecutionInformation(false, $"Company {company.Id} cannot perform turn action {Type}.", company); } var data = eventData as AdjustSalaryActionData; if (data.Salary < 0) { return new ActionExecutionInformation(false, $"Cannot have a negative employee value.", company, data.Salary); } return new ActionExecutionInformation(true); }
public override ActionExecutionInformation CanPerformEvent(Company company, IActionData eventData, IHub services) { var companyService = services.Resolve<ICompanyService>(); if (!companyService.CanPerformAction(company, Type)) { return new ActionExecutionInformation(false, $"Company {company.Id} cannot perform turn action {Type}.", company); } var data = eventData as PurchasePerkActionData; var perkService = services.Resolve<IPerkService>(); var perk = perkService.GetPerk(data.PerkId); if(!perkService.CanPurchasePerk(company, perk, data.Count)) { return new ActionExecutionInformation(false, $"Company {company.Id} cannot purchase {data.Count} of perk {perk.Id}.", company, data); } return new ActionExecutionInformation(true); }
public override ActionExecutionInformation CanPerformEvent(Company company, IActionData eventData, IHub services) { var companyService = services.Resolve<ICompanyService>(); if (!companyService.CanPerformAction(company, Type)) { return new ActionExecutionInformation(false, $"Company {company.Id} cannot perform turn action {Type}.", company); } var data = eventData as MakeOfferActionData; if(company.Money < data.OfferValue) { return new ActionExecutionInformation(false, $"Company {company.Id} does not have {data.OfferValue:C} for this offer.", company, data); } if (data.OfferValue < 0) { return new ActionExecutionInformation(false, $"Cannot offer negative amounts of money.", company, data); } return new ActionExecutionInformation(true); }
public override CompanyMessage ProcessEvent(Company company, IActionData eventData, IHub services) { var data = eventData as RecruitPersonActionData; var personService = services.Resolve<IPersonService>(); var companyService = services.Resolve<ICompanyService>(); var person = personService.GetPerson(data.PersonId); var gameClockService = services.Resolve<IGameClockService>(); var message = new CompanyMessage { Id = Utilities.InvalidId, DateCreated = gameClockService.CurrentDate, Status = CompanyMessageStatus.UnRead, Source = "Human Resources" }; if(personService.IsUnemployed(person)) { companyService.RecruitPerson(company, person); message.Subject = "Recruited Candidate"; message.Message = $"We have successfully recruited {person.FirstName} {person.LastName}."; } else { message.Subject = "Missed a Potential Recruit"; message.Message = $"{person.FirstName} {person.LastName} has been recently employed and cannot be recruited at this time."; } return message; }
public override CompanyMessage ProcessEvent(Company company, IActionData eventData, IHub services) { var data = eventData as InterviewProspectActionData; var companyService = services.Resolve<ICompanyService>(); var prospect = company.GetProspect(data.PersonId); var personService = services.Resolve<IPersonService>(); var gameClockServices = services.Resolve<IGameClockService>(); var message = new CompanyMessage { Id = Utilities.InvalidId, DateCreated = gameClockServices.CurrentDate, Status = CompanyMessageStatus.UnRead, Source = "Human Resources" }; if(personService.IsUnemployed(prospect.Person)) { companyService.InterviewProspect(company, prospect); message.Subject = "Interview Complete"; message.Message = $"{prospect.Person.FirstName} {prospect.Person.LastName} has completed a round of interviews."; } else { message.Subject = "Prospect Off the Market"; message.Message = $"{prospect.Person.FirstName} {prospect.Person.LastName} has recently accepted an offer elsewhere."; } return message; }
public override CompanyMessage ProcessEvent(Company company, IActionData eventData, IHub services) { var data = eventData as AdjustAllocationActionData; var employee = company.GetEmployee(data.PersonId); var project = company.GetProject(data.ProjectId); var companyService = services.Resolve<ICompanyService>(); companyService.AdjustAllocation(company, employee, project, data.Percentage, data.Role); var gameClockService = services.Resolve<IGameClockService>(); return new CompanyMessage { Id = Utilities.InvalidId, DateCreated = gameClockService.CurrentDate, Status = CompanyMessageStatus.UnRead, Source = "Project Management", Subject = "Employee has been reallocated.", Message = $"{employee.Person.FirstName} {employee.Person.LastName} has been directed to work on {project.Definition.Name} {data.Percentage:P} in a {data.Role} role." }; }
public override ActionExecutionInformation CanPerformEvent(Company company, IActionData eventData, IHub services) { var companyService = services.Resolve<ICompanyService>(); if(!companyService.CanPerformAction(company, Type)) { return new ActionExecutionInformation(false, $"Company {company.Id} cannot perform turn action {Type}.", company); } var data = eventData as SellPerkActionData; var perkService = services.Resolve<IPerkService>(); var perk = perkService.GetPerk(data.PerkId); var companyPerk = company.GetPerk(perk); if(companyPerk.Count < data.Count) { return new ActionExecutionInformation(false, $"Company {company.Id} cannot sell {data.Count} perks (ID: {perk.Id}).", perk, company); } return new ActionExecutionInformation(true); }
public override CompanyMessage ProcessEvent(Company company, IActionData eventData, IHub services) { var data = eventData as AdjustSalaryActionData; var companyService = services.Resolve<ICompanyService>(); var employee = company.GetEmployee(data.PersonId); var previousSalary = employee.Salary; companyService.AdjustSalary(company, employee, data.Salary); var gameClockService = services.Resolve<IGameClockService>(); return new CompanyMessage { Id = Utilities.InvalidId, DateCreated = gameClockService.CurrentDate, Status = CompanyMessageStatus.UnRead, Source = "Human Resources", Subject = "Employee Salary Adjustment", Message = $"{employee.Person.FirstName} {employee.Person.LastName}'s salary has been adjust from {previousSalary:C} to {employee.Salary:C}." }; }
public async void ExecuteActionWithData(IActionData data) { if (_busy) { _actionsData.Enqueue(data); return; } _busy = true; _actionsData.Enqueue(data); while (_actionsData.Count > 0) { var currentActionData = _actionsData.Dequeue(); var action = _actionsRegistry.GetViewActionForData(currentActionData); if (action == null) { continue; } await action.Execute(currentActionData); } _busy = false; }
public override CompanyMessage ProcessEvent(Company company, IActionData eventData, IHub services) { var data = eventData as PurchasePerkActionData; var perkService = services.Resolve<IPerkService>(); var perk = perkService.GetPerk(data.PerkId); var companyService = services.Resolve<ICompanyService>(); companyService.PurchasePerk(company, perk, data.Count); var gameClockService = services.Resolve<IGameClockService>(); return new CompanyMessage { Id = Utilities.InvalidId, DateCreated = gameClockService.CurrentDate, Status = CompanyMessageStatus.UnRead, Source = "Finance", Subject = "Purchase Made", Message = $"Purchased {data.Count} {perk.Name} perks." }; }
/// <summary> /// Add rule action to the properties list /// </summary> /// <param name="list">The properties list for a rule action</param> /// <param name="actionType">The action Type</param> /// <param name="actionData">The actionData</param> /// <param name="actionFlavor">The actionFlavor of the action</param> /// <param name="actionFlag">The action flag value.</param> private static void AddRuleAction(IList <TaggedPropertyValue> list, ActionTypes actionType, IActionData actionData, uint actionFlavor, uint actionFlag) { TaggedPropertyValue pidTagRuleActions = new TaggedPropertyValue(); PropertyTag pidTagRuleActionsPropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleActions, PropertyType = (ushort)PropertyTypeName.PtypRuleAction }; pidTagRuleActions.PropertyTag = pidTagRuleActionsPropertyTag; switch (actionType) { case ActionTypes.OP_MARK_AS_READ: case ActionTypes.OP_DELETE: pidTagRuleActions.Value = GenerateRuleAction(actionType, Count.TwoBytesCount, new DeleteMarkReadActionData(), actionFlavor, actionFlag).Serialize(); break; case ActionTypes.OP_MOVE: case ActionTypes.OP_COPY: case ActionTypes.OP_FORWARD: case ActionTypes.OP_DEFER_ACTION: case ActionTypes.OP_TAG: case ActionTypes.OP_DELEGATE: case ActionTypes.OP_BOUNCE: case ActionTypes.OP_OOF_REPLY: case ActionTypes.OP_REPLY: pidTagRuleActions.Value = GenerateRuleAction(actionType, Count.TwoBytesCount, actionData, actionFlavor, actionFlag).Serialize(); break; default: Site.Assert.Fail("The actionType is {0}, this is not a valid action type", actionType); break; } list.Add(pidTagRuleActions); }
public ActionRuntime(IDialogueController dialogue, string uniqueId, IActionData data) { _data = data; _dialogueController = dialogue; UniqueId = uniqueId; }
public void RequestActionWithData(IActionData data) { _stateActionExecutor.ExecuteActionWithData(data, _state); _state.actionsData.Add(data); }
public void ExecuteActionWithData(IActionData data, TState state) { var action = _registry.GetStateActionForData(data); action?.Execute(state, data); }
public abstract ActionExecutionInformation CanPerformEvent(Company company, IActionData eventData, IHub services);
public abstract void Execute(IActionData data = null);
/// <summary> /// Generate RuleData from ptf config base on different action Type. /// </summary> /// <param name="actionType">ActionType of each blocks, the sequence must be the same as the actionData array.</param> /// <param name="ruleSequence">Rule sequence in PidTagRuleSequence of the RuleData.</param> /// <param name="ruleState">Specifies value of PidTagRuleState of the RuleData.</param> /// <param name="actionData">The actionData array needed to construct the ActionBlock in RuleActions.</param> /// <param name="actionFlavor">The actionFlavor array of the rule ActionBlocks.</param> /// <param name="otherInfo"> /// An array of Other needed information of Actions. /// Index may be from 0-4 /// 0. Rule name /// 1. Rule provider /// 2. Rule user Flags /// 3. Rule provider data /// 4. Subject name of content restriction /// </param> /// <returns>A valid RuleData structure.</returns> public static RuleData GenerateValidRuleDataWithFlavor(ActionType[] actionType, int ruleSequence, RuleState ruleState, IActionData[] actionData, uint[] actionFlavor, RuleProperties otherInfo) { RuleData ruleData = new RuleData { RuleDataFlags = (byte)TestRuleDataType.ForAdd }; List<TaggedPropertyValue> propertyList = new List<TaggedPropertyValue>(); TaggedPropertyValue pidTagRuleSequence = new TaggedPropertyValue(); PropertyTag pidTagRuleSequencePropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleSequence, PropertyType = (ushort)PropertyType.PtypInteger32 }; pidTagRuleSequence.PropertyTag = pidTagRuleSequencePropertyTag; pidTagRuleSequence.Value = BitConverter.GetBytes(ruleSequence); propertyList.Add(pidTagRuleSequence); TaggedPropertyValue pidTagRuleLevel = new TaggedPropertyValue(); PropertyTag pidTagRuleLevelPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleLevel, PropertyType = (ushort)PropertyType.PtypInteger32 }; pidTagRuleLevel.PropertyTag = pidTagRuleLevelPropertyTag; pidTagRuleLevel.Value = BitConverter.GetBytes(Constants.RuleLevel); propertyList.Add(pidTagRuleLevel); TaggedPropertyValue pidTagRuleState = new TaggedPropertyValue(); PropertyTag pidTagRuleStatePropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleState, PropertyType = (ushort)PropertyType.PtypInteger32 }; pidTagRuleState.PropertyTag = pidTagRuleStatePropertyTag; pidTagRuleState.Value = BitConverter.GetBytes((uint)ruleState); propertyList.Add(pidTagRuleState); if (otherInfo.Name.Length > 0) { TaggedPropertyValue pidTagRuleName = new TaggedPropertyValue(); PropertyTag pidTagRuleNamePropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleName, PropertyType = (ushort)PropertyType.PtypString }; pidTagRuleName.PropertyTag = pidTagRuleNamePropertyTag; pidTagRuleName.Value = Encoding.Unicode.GetBytes((string)otherInfo.Name + "\0"); propertyList.Add(pidTagRuleName); } if (otherInfo.Provider.Length > 0) { TaggedPropertyValue pidTagRuleProvider = new TaggedPropertyValue(); PropertyTag pidTagRuleProviderPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleProvider, PropertyType = (ushort)PropertyType.PtypString }; pidTagRuleProvider.PropertyTag = pidTagRuleProviderPropertyTag; pidTagRuleProvider.Value = Encoding.Unicode.GetBytes((string)otherInfo.Provider + "\0"); propertyList.Add(pidTagRuleProvider); } if (otherInfo.UserFlag.Length > 0) { TaggedPropertyValue pidTagRuleUserFlags = new TaggedPropertyValue(); PropertyTag pidTagRuleUserFlagsPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleUserFlags, PropertyType = (ushort)PropertyType.PtypInteger32 }; pidTagRuleUserFlags.PropertyTag = pidTagRuleUserFlagsPropertyTag; pidTagRuleUserFlags.Value = BitConverter.GetBytes(int.Parse(otherInfo.UserFlag)); propertyList.Add(pidTagRuleUserFlags); } if (otherInfo.ProviderData.Length > 0) { TaggedPropertyValue pidTagRuleProviderData = new TaggedPropertyValue(); PropertyTag pidTagRuleProviderDataPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleProviderData, PropertyType = (ushort)PropertyType.PtypBinary }; pidTagRuleProviderData.PropertyTag = pidTagRuleProviderDataPropertyTag; pidTagRuleProviderData.Value = Common.GetBytesFromBinaryHexString(otherInfo.ProviderData); pidTagRuleProviderData.Value = Common.AddInt16LengthBeforeBinaryArray(pidTagRuleProviderData.Value); propertyList.Add(pidTagRuleProviderData); } if (otherInfo.ConditionSubjectName.Length > 0) { AddRuleCondition(propertyList, otherInfo.ConditionSubjectName); uint[] defaultActionFlags = new uint[actionData.Length]; for (int i = 0; i < actionData.Length; i++) { defaultActionFlags[i] = Constants.RuleActionFlags; } AddRuleAction(propertyList, actionType, actionData, actionFlavor, defaultActionFlags); } ruleData.PropertyValues = propertyList.ToArray(); ruleData.PropertyValueCount = (ushort)propertyList.Count; return ruleData; }
/// <summary> /// Generate RuleData from ptf config base on different action Type. /// </summary> /// <param name="actionType">ActionType in a rule.</param> /// <param name="ruleDataType">The type of the rule data.</param> /// <param name="ruleSequence">Rule sequence in PidTagRuleSequence of the RuleData.</param> /// <param name="ruleState">Specifies value of PidTagRuleState of the RuleData.</param> /// <param name="actionData">The actionData needed to construct the RuleData.</param> /// <param name="otherInfo"> /// An array of Other needed information of Actions. /// Index may be from 0-4 /// 0. Rule name /// 1. Rule provider /// 2. Rule user Flags /// 3. Rule provider data /// 4. Subject name of content restriction /// </param> /// <param name="ruleId">A 64-bit unsigned integer represents the rule.</param> /// <returns>A valid RuleData structure.</returns> public static RuleData GenerateValidRuleData(ActionType actionType, TestRuleDataType ruleDataType, int ruleSequence, RuleState ruleState, IActionData actionData, RuleProperties otherInfo, ulong? ruleId) { RuleData ruleData = new RuleData { RuleDataFlags = (byte)ruleDataType }; List<TaggedPropertyValue> propertyList = new List<TaggedPropertyValue>(); if (ruleDataType == TestRuleDataType.ForModify || ruleDataType == TestRuleDataType.ForRemove) { TaggedPropertyValue pidTagRuleId = new TaggedPropertyValue(); PropertyTag pidTagRuleIdPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleId, PropertyType = (ushort)PropertyType.PtypInteger64 }; pidTagRuleId.PropertyTag = pidTagRuleIdPropertyTag; pidTagRuleId.Value = BitConverter.GetBytes((ulong)ruleId); propertyList.Add(pidTagRuleId); } if (ruleDataType != TestRuleDataType.ForRemove) { TaggedPropertyValue pidTagRuleSequence = new TaggedPropertyValue(); PropertyTag pidTagRuleSequencePropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleSequence, PropertyType = (ushort)PropertyType.PtypInteger32 }; pidTagRuleSequence.PropertyTag = pidTagRuleSequencePropertyTag; pidTagRuleSequence.Value = BitConverter.GetBytes(ruleSequence); propertyList.Add(pidTagRuleSequence); TaggedPropertyValue pidTagRuleLevel = new TaggedPropertyValue(); PropertyTag pidTagRuleLevelPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleLevel, PropertyType = (ushort)PropertyType.PtypInteger32 }; pidTagRuleLevel.PropertyTag = pidTagRuleLevelPropertyTag; pidTagRuleLevel.Value = BitConverter.GetBytes(0); propertyList.Add(pidTagRuleLevel); TaggedPropertyValue pidTagRuleState = new TaggedPropertyValue(); PropertyTag pidTagRuleStatePropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleState, PropertyType = (ushort)PropertyType.PtypInteger32 }; pidTagRuleState.PropertyTag = pidTagRuleStatePropertyTag; pidTagRuleState.Value = BitConverter.GetBytes((uint)ruleState); propertyList.Add(pidTagRuleState); if (otherInfo.Name.Length > 0) { TaggedPropertyValue pidTagRuleName = new TaggedPropertyValue(); PropertyTag pidTagRuleNamePropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleName, PropertyType = (ushort)PropertyType.PtypString }; pidTagRuleName.PropertyTag = pidTagRuleNamePropertyTag; pidTagRuleName.Value = Encoding.Unicode.GetBytes((string)otherInfo.Name + "\0"); propertyList.Add(pidTagRuleName); } if (otherInfo.Provider.Length > 0) { TaggedPropertyValue pidTagRuleProvider = new TaggedPropertyValue(); PropertyTag pidTagRuleProviderPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleProvider, PropertyType = (ushort)PropertyType.PtypString }; pidTagRuleProvider.PropertyTag = pidTagRuleProviderPropertyTag; pidTagRuleProvider.Value = Encoding.Unicode.GetBytes((string)otherInfo.Provider + "\0"); propertyList.Add(pidTagRuleProvider); } if (otherInfo.UserFlag.Length > 0) { TaggedPropertyValue pidTagRuleUserFlags = new TaggedPropertyValue(); PropertyTag pidTagRuleUserFlagsPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleUserFlags, PropertyType = (ushort)PropertyType.PtypInteger32 }; pidTagRuleUserFlags.PropertyTag = pidTagRuleUserFlagsPropertyTag; pidTagRuleUserFlags.Value = BitConverter.GetBytes(int.Parse(otherInfo.UserFlag)); propertyList.Add(pidTagRuleUserFlags); } if (otherInfo.ProviderData.Length > 0) { TaggedPropertyValue pidTagRuleProviderData = new TaggedPropertyValue(); PropertyTag pidTagRuleProviderDataPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleProviderData, PropertyType = (ushort)PropertyType.PtypBinary }; pidTagRuleProviderData.PropertyTag = pidTagRuleProviderDataPropertyTag; pidTagRuleProviderData.Value = Common.GetBytesFromBinaryHexString(otherInfo.ProviderData); pidTagRuleProviderData.Value = Common.AddInt16LengthBeforeBinaryArray(pidTagRuleProviderData.Value); propertyList.Add(pidTagRuleProviderData); } if (otherInfo.ConditionSubjectName.Length > 0) { AddRuleCondition(propertyList, otherInfo.ConditionSubjectName); AddRuleAction(propertyList, actionType, actionData, Constants.CommonActionFlavor, Constants.RuleActionFlags); } } ruleData.PropertyValues = propertyList.ToArray(); ruleData.PropertyValueCount = (ushort)propertyList.Count; return ruleData; }
/// <summary> /// Generate test data for creating extended rule. /// </summary> /// <param name="rulename">The rule name.</param> /// <param name="ruleSequence">The rule sequence.</param> /// <param name="ruleState">The rule state.</param> /// <param name="provider">The rule provider.</param> /// <param name="actionType">The rule action Type.</param> /// <param name="actionData">The rule action data.</param> /// <param name="contentRestrictSubjectName">The subject name of the rule content restriction.</param> /// <param name="namedPropertyInfo">The namedPropertyInfo that needed for construct the rule data.</param> /// <returns>An array of TaggedPropertyValue of an extended rule.</returns> public static TaggedPropertyValue[] GenerateExtendedRuleTestData(string rulename, int ruleSequence, uint ruleState, string provider, ActionType actionType, IActionData actionData, string contentRestrictSubjectName, NamedPropertyInfo namedPropertyInfo) { List<TaggedPropertyValue> propList = new List<TaggedPropertyValue>(); TaggedPropertyValue pidTagRuleMessageName = new TaggedPropertyValue(); PropertyTag pidTagRuleMessageNameTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleMessageName, PropertyType = (ushort)PropertyType.PtypString }; pidTagRuleMessageName.PropertyTag = pidTagRuleMessageNameTag; pidTagRuleMessageName.Value = Encoding.Unicode.GetBytes(rulename + "\0"); propList.Add(pidTagRuleMessageName); TaggedPropertyValue pidTagMessageClass = new TaggedPropertyValue(); PropertyTag pidTagMessageClassTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagMessageClass, PropertyType = (ushort)PropertyType.PtypString }; pidTagMessageClass.PropertyTag = pidTagMessageClassTag; pidTagMessageClass.Value = Encoding.Unicode.GetBytes(Constants.ExtendedRuleMessageClass + "\0"); propList.Add(pidTagMessageClass); TaggedPropertyValue pidTagRuleMessageSequence = new TaggedPropertyValue(); PropertyTag pidTagRuleMessageSequencePropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleMessageSequence, PropertyType = (ushort)PropertyType.PtypInteger32 }; pidTagRuleMessageSequence.PropertyTag = pidTagRuleMessageSequencePropertyTag; pidTagRuleMessageSequence.Value = BitConverter.GetBytes(ruleSequence); propList.Add(pidTagRuleMessageSequence); TaggedPropertyValue pidTagRuleMessageState = new TaggedPropertyValue(); PropertyTag pidTagRuleMessageStatePropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleMessageState, PropertyType = (ushort)PropertyType.PtypInteger32 }; pidTagRuleMessageState.PropertyTag = pidTagRuleMessageStatePropertyTag; pidTagRuleMessageState.Value = BitConverter.GetBytes(ruleState); propList.Add(pidTagRuleMessageState); TaggedPropertyValue pidTagRuleMessageLevel = new TaggedPropertyValue(); PropertyTag pidTagRuleMessageLevelPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleMessageLevel, PropertyType = (ushort)PropertyType.PtypInteger32 }; pidTagRuleMessageLevel.PropertyTag = pidTagRuleMessageLevelPropertyTag; pidTagRuleMessageLevel.Value = BitConverter.GetBytes(Constants.ExtendedRuleMessageLevel); propList.Add(pidTagRuleMessageLevel); TaggedPropertyValue pidTagRuleMessageProvider = new TaggedPropertyValue(); PropertyTag pidTagRuleMessageProviderPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleMessageProvider, PropertyType = (ushort)PropertyType.PtypString }; pidTagRuleMessageProvider.PropertyTag = pidTagRuleMessageProviderPropertyTag; pidTagRuleMessageProvider.Value = Encoding.Unicode.GetBytes(provider + "\0"); propList.Add(pidTagRuleMessageProvider); ExtendedRuleActions extendedRuleActions = new ExtendedRuleActions { NamedPropertyInformation = namedPropertyInfo }; extendedRuleActions.RuleVersion = Constants.ExtendedRuleVersion; extendedRuleActions.RuleActionBuffer = GetRuleAction(actionType, CountByte.FourBytesCount, actionData, Constants.CommonActionFlavor, Constants.RuleActionFlags); TaggedPropertyValue pidTagExtendedRuleMessageActions = new TaggedPropertyValue(); PropertyTag pidTagExtendedRuleMessageActionsPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagExtendedRuleMessageActions, PropertyType = (ushort)PropertyType.PtypBinary }; pidTagExtendedRuleMessageActions.PropertyTag = pidTagExtendedRuleMessageActionsPropertyTag; pidTagExtendedRuleMessageActions.Value = Common.AddInt16LengthBeforeBinaryArray(extendedRuleActions.Serialize()); propList.Add(pidTagExtendedRuleMessageActions); TaggedPropertyValue pidTagExtendedRuleMessageCondition = new TaggedPropertyValue(); PropertyTag pidTagExtendedRuleMessageConditionPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagExtendedRuleMessageCondition, PropertyType = (ushort)PropertyType.PtypBinary }; pidTagExtendedRuleMessageCondition.PropertyTag = pidTagExtendedRuleMessageConditionPropertyTag; TaggedPropertyValue taggedProperty = new TaggedPropertyValue(); PropertyTag taggedPropertyPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagSubject, PropertyType = (ushort)PropertyType.PtypString }; taggedProperty.PropertyTag = taggedPropertyPropertyTag; taggedProperty.Value = Encoding.Unicode.GetBytes(contentRestrictSubjectName + "\0"); ContentRestriction contentRestriction = new ContentRestriction { FuzzyLevelLow = ContentRestriction.FuzzyLevelLowValue.FL_SUBSTRING, FuzzyLevelHigh = ContentRestriction.FuzzyLevelHighValue.FL_IGNORECASE, PropertyTag = taggedProperty.PropertyTag, TaggedValue = taggedProperty }; ExtendedRuleCondition extendedRuleCondition = new ExtendedRuleCondition { NamedPropertyInformation = namedPropertyInfo, RuleRestriction = contentRestriction }; pidTagExtendedRuleMessageCondition.Value = Common.AddInt16LengthBeforeBinaryArray(extendedRuleCondition.Serialize()); propList.Add(pidTagExtendedRuleMessageCondition); return propList.ToArray(); }
/// <summary> /// Add rule action to the properties list. /// </summary> /// <param name="list">The properties list for a rule action.</param> /// <param name="actionTypes">The action Type.</param> /// <param name="actionData">The actionData.</param> /// <param name="actionFlavor">The actionFlavor of the action.</param> /// <param name="actionFlags">The action flag value.</param> private static void AddRuleAction(IList<TaggedPropertyValue> list, ActionType[] actionTypes, IActionData[] actionData, uint[] actionFlavor, uint[] actionFlags) { TaggedPropertyValue pidTagRuleActions = new TaggedPropertyValue(); PropertyTag pidTagRuleActionsPropertyTag = new PropertyTag { PropertyId = (ushort)PropertyId.PidTagRuleActions, PropertyType = (ushort)PropertyType.PtypRuleAction }; pidTagRuleActions.PropertyTag = pidTagRuleActionsPropertyTag; pidTagRuleActions.Value = GetRuleAction(actionTypes, CountByte.TwoBytesCount, actionData, actionFlavor, actionFlags).Serialize(); list.Add(pidTagRuleActions); }
public abstract CompanyMessage ProcessEvent(Company company, IActionData eventData, IHub services);
/// <summary> /// Generate a sample valid RuleData structure. /// </summary> /// <param name="actionType">ActionType in a rule</param> /// <param name="ruleDataType">Rule data value.</param> /// <param name="ruleSequence">Rule sequence in PidTagRuleSequence of the RuleData</param> /// <param name="ruleState">Specifies value of PidTagRuleState of the RuleData</param> /// <param name="actionData">The actionData needed to construct the RuleData</param> /// <param name="ruleProperties">Rule properties structure.</param> /// <returns>A valid RuleData structure</returns> public static RuleData GenerateValidRuleData(ActionTypes actionType, TestRuleDataType ruleDataType, int ruleSequence, RuleState ruleState, IActionData actionData, RuleProperties ruleProperties) { RuleData ruleData = new RuleData { RuleDataFlags = (byte)ruleDataType }; List <TaggedPropertyValue> propertyList = new List <TaggedPropertyValue>(); TaggedPropertyValue pidTagRuleSequence = new TaggedPropertyValue(); PropertyTag pidTagRuleSequencePropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleSequence, PropertyType = (ushort)PropertyTypeName.PtypInteger32 }; pidTagRuleSequence.PropertyTag = pidTagRuleSequencePropertyTag; pidTagRuleSequence.Value = BitConverter.GetBytes(ruleSequence); propertyList.Add(pidTagRuleSequence); TaggedPropertyValue pidTagRuleLevel = new TaggedPropertyValue(); PropertyTag pidTagRuleLevelPropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleLevel, PropertyType = (ushort)PropertyTypeName.PtypInteger32 }; pidTagRuleLevel.PropertyTag = pidTagRuleLevelPropertyTag; pidTagRuleLevel.Value = BitConverter.GetBytes(0); propertyList.Add(pidTagRuleLevel); TaggedPropertyValue pidTagRuleState = new TaggedPropertyValue(); PropertyTag pidTagRuleStatePropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleState, PropertyType = (ushort)PropertyTypeName.PtypInteger32 }; pidTagRuleState.PropertyTag = pidTagRuleStatePropertyTag; pidTagRuleState.Value = BitConverter.GetBytes((uint)ruleState); propertyList.Add(pidTagRuleState); if (ruleProperties.Name.Length > 0) { TaggedPropertyValue pidTagRuleName = new TaggedPropertyValue(); PropertyTag pidTagRuleNamePropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleName, PropertyType = (ushort)PropertyTypeName.PtypString }; pidTagRuleName.PropertyTag = pidTagRuleNamePropertyTag; pidTagRuleName.Value = Encoding.Unicode.GetBytes((string)ruleProperties.Name + "\0"); propertyList.Add(pidTagRuleName); } if (ruleProperties.Provider.Length > 0) { TaggedPropertyValue pidTagRuleProvider = new TaggedPropertyValue(); PropertyTag pidTagRuleProviderPropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleProvider, PropertyType = (ushort)PropertyTypeName.PtypString }; pidTagRuleProvider.PropertyTag = pidTagRuleProviderPropertyTag; pidTagRuleProvider.Value = Encoding.Unicode.GetBytes((string)ruleProperties.Provider + "\0"); propertyList.Add(pidTagRuleProvider); } if (ruleProperties.UserFlag.Length > 0) { TaggedPropertyValue pidTagRuleUserFlags = new TaggedPropertyValue(); PropertyTag pidTagRuleUserFlagsPropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleUserFlags, PropertyType = (ushort)PropertyTypeName.PtypInteger32 }; pidTagRuleUserFlags.PropertyTag = pidTagRuleUserFlagsPropertyTag; pidTagRuleUserFlags.Value = BitConverter.GetBytes(int.Parse(ruleProperties.UserFlag)); propertyList.Add(pidTagRuleUserFlags); } if (ruleProperties.ProviderData.Length > 0) { TaggedPropertyValue pidTagRuleProviderData = new TaggedPropertyValue(); PropertyTag pidTagRuleProviderDataPropertyTag = new PropertyTag { PropertyId = (ushort)TestPropertyName.PidTagRuleProviderData, PropertyType = (ushort)PropertyTypeName.PtypBinary }; pidTagRuleProviderData.PropertyTag = pidTagRuleProviderDataPropertyTag; pidTagRuleProviderData.Value = Common.GetBytesFromBinaryHexString(ruleProperties.ProviderData); pidTagRuleProviderData.Value = Common.AddInt16LengthBeforeBinaryArray(pidTagRuleProviderData.Value); propertyList.Add(pidTagRuleProviderData); } if (ruleProperties.ConditionSubjectName.Length > 0) { AddRuleCondition(propertyList, ruleProperties.ConditionSubjectName); AddRuleAction(propertyList, actionType, actionData, Constants.CommonActionFlavor, Constants.RuleActionFlags); } ruleData.PropertyValues = propertyList.ToArray(); ruleData.PropertyValueCount = (ushort)propertyList.Count; return(ruleData); }
public ActionController(IActionData action) { _action = action; }
/// <summary> /// Generate a sample rule action. /// </summary> /// <param name="actionType">The action Type</param> /// <param name="bytesCount">The length of the bytes count</param> /// <param name="actionDataBufferValue">The actionData buffer</param> /// <param name="actionFlavor">Action flavor value.</param> /// <param name="actionFlag">Action flag value.</param> /// <returns>An instance of the RuleAction</returns> private static RuleAction GenerateRuleAction(ActionTypes actionType, Count bytesCount, IActionData actionDataBufferValue, uint actionFlavor, uint actionFlag) { ActionBlock actionBlock = new ActionBlock(bytesCount) { ActionType = actionType, ActionFlags = actionFlag, ActionDataValue = actionDataBufferValue, ActionFlavor = actionFlavor }; actionBlock.ActionLength = (bytesCount == Count.TwoBytesCount) ? (actionBlock.Size() - 2) : (actionBlock.Size() - 4); RuleAction ruleAction = new RuleAction(bytesCount) { NoOfActions = 0x01, Actions = new ActionBlock[1] { actionBlock } }; // Only one rule action is generated. return ruleAction; }
public void Execute(TState state, IActionData data) { Execute(state, (T)data); }
/// <summary> /// Generate a rule action. /// </summary> /// <param name="actionType">The action Type.</param> /// <param name="countBytes">The length of the bytes count.</param> /// <param name="actionDataBufferValue">The actionData buffer.</param> /// <param name="actionFlavor">Action flavor value.</param> /// <param name="actionFlags">Action flag value.</param> /// <returns>An instance of the RuleAction.</returns> private static RuleAction GetRuleAction(ActionType actionType, CountByte countBytes, IActionData actionDataBufferValue, uint actionFlavor, uint actionFlags) { ActionBlock actionBlock = new ActionBlock(countBytes) { ActionType = actionType, ActionFlags = actionFlags, ActionDataValue = actionDataBufferValue, ActionFlavor = actionFlavor }; // Get actionBlock size int lengthOfActionLength = 0; if (actionBlock.CountType == CountByte.TwoBytesCount) { lengthOfActionLength += 2; } else if (actionBlock.CountType == CountByte.FourBytesCount) { lengthOfActionLength += 4; } // Length of ActionType is 1 // Length of ActionFlavor is 4 // Length of ActionFlags is 4 int size = lengthOfActionLength + 1 + 4 + 4 + actionBlock.ActionDataValue.Size(); actionBlock.ActionLength = (countBytes == CountByte.TwoBytesCount) ? (size - 2) : (size - 4); RuleAction ruleAction = new RuleAction(countBytes) { NoOfActions = 0x01, Actions = new ActionBlock[1] { actionBlock } }; // Only one rule action is generated. return ruleAction; }
/// <summary> /// Generate a sample rule action. /// </summary> /// <param name="actionType">The action Type</param> /// <param name="bytesCount">The length of the bytes count</param> /// <param name="actionDataBufferValue">The actionData buffer</param> /// <param name="actionFlavor">Action flavor value.</param> /// <param name="actionFlag">Action flag value.</param> /// <returns>An instance of the RuleAction</returns> private static RuleAction GenerateRuleAction(ActionTypes actionType, Count bytesCount, IActionData actionDataBufferValue, uint actionFlavor, uint actionFlag) { ActionBlock actionBlock = new ActionBlock(bytesCount) { ActionType = actionType, ActionFlags = actionFlag, ActionDataValue = actionDataBufferValue, ActionFlavor = actionFlavor }; actionBlock.ActionLength = (bytesCount == Count.TwoBytesCount) ? (actionBlock.Size() - 2) : (actionBlock.Size() - 4); RuleAction ruleAction = new RuleAction(bytesCount) { NoOfActions = 0x01, Actions = new ActionBlock[1] { actionBlock } }; // Only one rule action is generated. return(ruleAction); }
/// <summary> /// Generate a rule action. /// </summary> /// <param name="actionTypes">The action Type.</param> /// <param name="countBytes">The length of the bytes count.</param> /// <param name="actionDataBufferValue">The actionData buffer.</param> /// <param name="actionFlavor">Action flavor value.</param> /// <param name="actionFlags">Action flag value.</param> /// <returns>An instance of the RuleAction.</returns> private static RuleAction GetRuleAction(ActionType[] actionTypes, CountByte countBytes, IActionData[] actionDataBufferValue, uint[] actionFlavor, uint[] actionFlags) { ActionBlock[] actionBlocks = new ActionBlock[actionTypes.Length]; for (int i = 0; i < actionDataBufferValue.Length; i++) { ActionBlock actionBlock = new ActionBlock(countBytes) { ActionType = actionTypes[i], ActionFlags = actionFlags[i], ActionDataValue = actionDataBufferValue[i], ActionFlavor = actionFlavor[i] }; // Get actionBlock size int lengthOfActionLength = 0; if (actionBlock.CountType == CountByte.TwoBytesCount) { lengthOfActionLength += 2; } else if (actionBlock.CountType == CountByte.FourBytesCount) { lengthOfActionLength += 4; } // Length of ActionType is 1 // Length of ActionFlavor is 4 // Length of ActionFlags is 4 int size = lengthOfActionLength + 1 + 4 + 4 + actionBlock.ActionDataValue.Size(); actionBlock.ActionLength = (countBytes == CountByte.TwoBytesCount) ? (size - 2) : (size - 4); actionBlocks[i] = actionBlock; } RuleAction ruleAction = new RuleAction(countBytes) { NoOfActions = actionBlocks.Length, Actions = actionBlocks }; return ruleAction; }
public Task Execute(IActionData data) { return(Execute((T)data)); }