public IEntityActionViewModel CreateEntityActionViewModel(IEntityAction entityAction) { switch (entityAction.EntityID) { case 1: switch (entityAction.ActionID) { case 1: return new PatientAdd(); case 2: return new PatientRemove(); default: return null; } case 2: switch (entityAction.ActionID) { case 1: return new ContactAdd(); case 2: return new ContactRemove(); default: return null; } default: return null; } }
public IEntityActionViewModel CreateEntityActionViewModel(IEntityAction entityAction) { switch (entityAction.EntityID) { case 1: switch (entityAction.ActionID) { case 1: return(new PatientAdd()); case 2: return(new PatientRemove()); default: return(null); } case 2: switch (entityAction.ActionID) { case 1: return(new ContactAdd()); case 2: return(new ContactRemove()); default: return(null); } default: return(null); } }
public IEntityActionViewModel CreateEntityActionViewModel(IEntityAction entityAction) { return((IEntityActionViewModel)Activator.CreateInstance( Type.GetType( String.Format("{0}.{1}", this.GetType().Namespace, entityAction.EntityName + entityAction.ActionName)))); }
public IEntityActionViewModel CreateEntityActionViewModel(IEntityAction entityAction) { return (IEntityActionViewModel)Activator.CreateInstance( Type.GetType( String.Format("{0}.{1}", this.GetType().Namespace, entityAction.EntityName + entityAction.ActionName))); }
public static void FormatExtensionNotImplementedException (IEntityAction entityAction) { if (entityAction.NotNull ()) { string msg = $"[component: {entityAction.Operation.CategoryType.Category} - operation: {entityAction.Operation.Operation}] - extension: {entityAction.Operation.Extension.ToString ()} Extension NOT implemented!"; entityAction.Result.CopyFrom (new TValidationResult (msg)); } }
public static void FormatExtensionMustExistException (IEntityAction entityAction) { if (entityAction.NotNull ()) { string msg = $"[component: {entityAction.Operation.CategoryType.Category} - operation: {entityAction.Operation.Operation}] - extension: Extension MUST Exist!"; entityAction.Result.CopyFrom (new TValidationResult (msg)); } }
public static TEntityAction Request (IEntityAction action, string databaseConnectionString) { if (action is TEntityAction entityAction) { entityAction.SelectConnection (databaseConnectionString); return (entityAction); } return (null); }
protected bool Invoke (IModelContext context, IEntityAction entityAction) { bool res = false; if (ContainsOperation (entityAction)) { Operations [entityAction.Operation.Operation].Invoke (context, entityAction, entityAction.Operation.Extension); res = true; } return (res); }
public IEntityAction <IRequisition>[] AuthorizedActions(string userId) { var actions = new IEntityAction <IRequisition>[] { new DraftAction(), new CreateAction() }; var authorized = actions.Where(e => e.IsAuthorized(this, userId).IsAuthorized).ToArray(); return(authorized); }
public static void FormatException (string tag, Exception exception, IEntityAction entityAction) { if (entityAction.NotNull ()) { if (exception.NotNull ()) { string msg = $"[{entityAction.Operation.CategoryType.Category} {tag} - {entityAction.Operation.Operation}] {exception.Message}"; if (exception.InnerException.NotNull ()) { msg = $"[component: {entityAction.Operation.CategoryType} {tag} - operation: {entityAction.Operation.Operation}] {exception.Message}{Environment.NewLine}{exception.InnerException.Message}"; } entityAction.Result.CopyFrom (new TValidationResult (msg)); } } }
public void Invoke (IModelContext modelContext, IEntityAction entityAction, TExtension extension) { if (modelContext.NotNull ()) { var context = TModelContext.CastTo (modelContext); var relationList = context.CategoryRelation .ToList () ; if (entityAction.NotNull ()) { var action = TEntityAction.Request (entityAction); action.CollectionAction.SetCollection (relationList); if (action.Operation.HasExtension) { switch (extension) { case TExtension.Full: { CollectionFull (context, action); } break; case TExtension.Minimum: { CollectionMinimum (context, action); } break; case TExtension.ById: case TExtension.Idle: case TExtension.Many: case TExtension.Zap: { Models.Infrastructure.THelper.FormatExtensionNotImplementedException (action); } break; } } else { Models.Infrastructure.THelper.FormatExtensionMustExistException (action); } } } }
public void Invoke (IModelContext modelContext, IEntityAction entityAction, Server.Models.Infrastructure.TExtension extension) { if (modelContext.NotNull ()) { var context = TModelContext.CastTo (modelContext); var relationList = context.CategoryRelation .ToList () ; if (entityAction.NotNull ()) { var action = TEntityAction.Request (entityAction); action.CollectionAction.SetCollection (relationList); if (action.Operation.HasExtension) { Server.Models.Infrastructure.THelper.FormatExtensionNotImplementedException (action); } else { Insert (context, action); } } } }
public Task<IEntityAction> OperationAsync (IEntityAction entityAction) { var task = Task.Factory.StartNew (() => { if (entityAction.NotNull ()) { IModelContext context = Request (entityAction.ConnectionString); if (context.NotNull ()) { try { if (ContainsOperation (entityAction)) { Invoke (context, entityAction); } else { // operation not found! string msg = $"context: {entityAction.Operation.CategoryType.Category} - operation: {entityAction.Operation.Operation} - NOT FOUND!"; entityAction.Result.CopyFrom (new rr.Library.Helper.TValidationResult (msg)); } } catch (Exception exception) { THelper.FormatException ("Operation", exception, entityAction); } } context.DisposeNow (); } return (entityAction); }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default ); return (task); }
public static TEntityAction Request (IEntityAction action) { return (action as TEntityAction); }
internal void RegisterAction(IEntityAction action) { _actionsQueue.Enqueue(action); }
protected bool ContainsOperation (IEntityAction entityAction) { return (entityAction.NotNull () ? Operations.ContainsKey (entityAction.Operation.Operation) : false); }
public override void TakeTurn(Combat combat) { var actionsRemaining = new List <string>() { "major", "minor", "move" }; _movementRemaining = MovementSpeedFeet; bool turnOver = false; while (!turnOver) { MaintainStatusEffects(); TakingTurn = true; // Check if turn is over: if (_movementRemaining <= 0) { actionsRemaining.Remove("move"); } if (actionsRemaining.Count == 0) { Console.WriteLine($"{Name}'s turn is over because {Pronouns[0].ToLower()} has no actions left."); PressAnyKeyToContinue(); turnOver = true; } Location.Map.PrintMap(); // Prompt player: string formattedMovement = _movementRemaining != 0 ? $"({_movementRemaining} ft) " : ""; Console.WriteLine($"\nEnter an action or type 'pass' to pass your turn. {Name} has a {actionsRemaining.FormatToString("and")} action {formattedMovement}remaining.\n"); // List IEntityActions: foreach (var action in Actions) { if (actionsRemaining.Contains(action.Type)) { Console.WriteLine($"- {action.Command} {action.Description} ({action.Type})"); } } Console.WriteLine($"\nTry 'help' for a list of other commands.\n"); string input = Console.ReadLine().ToLower(); // If IEntityAction command, parse input: if (Actions.Any(a => a.Command == input.Split(' ')[0])) { string inputCommand = input.Split(' ')[0]; IEntityAction inputAction = Actions.FirstOrDefault(a => a.Command == inputCommand); if (actionsRemaining.Contains(inputAction.Type)) { bool actionExecuted = false; if (inputAction is TargetedAction) { var inputTargetedAction = (TargetedAction)inputAction; string inputTarget = string.Join(' ', input.Split(' ').Skip(1)); actionExecuted = inputTargetedAction.Execute(inputTarget); } else if (inputAction is NonTargetedAction) { var inputNonTargetedAction = (NonTargetedAction)inputAction; actionExecuted = inputNonTargetedAction.Execute(); } PressAnyKeyToContinue(); if (actionExecuted) { actionsRemaining.Remove(inputAction.Type); } } else { Console.WriteLine($"{Name} does not have a {inputAction.Type} action remaining."); PressAnyKeyToContinue(); } } // Check for other commands: else if (input == "stats") { Console.WriteLine(GetAllStats()); PressAnyKeyToContinue(); } else if (input == "order") { Console.WriteLine(combat.GetInitiativeOrder()); PressAnyKeyToContinue(); } else if (input == "help") { Console.WriteLine($"- stats - List {Name}'s stats."); Console.WriteLine($"- order - Show current initiative order."); PressAnyKeyToContinue(); } else if (input == "pass") { Console.WriteLine($"{Name} is passing {Pronouns[2].ToLower()} turn."); PressAnyKeyToContinue(); turnOver = true; } else { Console.WriteLine($"'{input}' could not be recognized. Please enter a valid command."); PressAnyKeyToContinue(); } Console.Clear(); } Console.Clear(); TakingTurn = false; }
public IEntityActionViewModel CreateEntityActionViewModel(IEntityAction entityAction) { return Program.Container.Resolve<IEntityActionViewModel>( entityAction.EntityName + entityAction.ActionName); }
static void Main(string[] args) { //Domain Models IEntityAction patientAdd = new EntityAction() { EntityID = 1, EntityName = "Patient", ActionID = 1, ActionName = "Add" }; IEntityAction patientRemove = new EntityAction() { EntityID = 1, EntityName = "Patient", ActionID = 2, ActionName = "Remove" }; IEntityAction contactAdd = new EntityAction() { EntityID = 2, EntityName = "Contact", ActionID = 1, ActionName = "Add" }; IEntityAction contactRemove = new EntityAction() { EntityID = 2, EntityName = "Contact", ActionID = 2, ActionName = "Remove" }; IEntityActionViewModel entityActionViewModel; Factory = new EntityActionViewModelFactory(); Console.WriteLine("---{0}---", nameof(EntityActionViewModelFactory)); entityActionViewModel = Factory.CreateEntityActionViewModel(patientAdd); entityActionViewModel?.Operate(); entityActionViewModel = Factory.CreateEntityActionViewModel(patientRemove); entityActionViewModel?.Operate(); entityActionViewModel = Factory.CreateEntityActionViewModel(contactAdd); entityActionViewModel?.Operate(); entityActionViewModel = Factory.CreateEntityActionViewModel(contactRemove); entityActionViewModel?.Operate(); Factory = new ConcatEntityActionViewModelFactory(); Console.WriteLine("---{0}---", nameof(ConcatEntityActionViewModelFactory)); entityActionViewModel = Factory.CreateEntityActionViewModel(patientAdd); entityActionViewModel?.Operate(); entityActionViewModel = Factory.CreateEntityActionViewModel(patientRemove); entityActionViewModel?.Operate(); entityActionViewModel = Factory.CreateEntityActionViewModel(contactAdd); entityActionViewModel?.Operate(); entityActionViewModel = Factory.CreateEntityActionViewModel(contactRemove); entityActionViewModel?.Operate(); //Composition Root Container = new UnityContainer(); Container.RegisterType <IEntityActionViewModelFactory, ContainerEntityActionViewModelFactory>(); Container.RegisterType <IEntityAction, EntityAction>(); Container.RegisterType <IEntityActionViewModel, PatientAdd>(nameof(PatientAdd)); Container.RegisterType <IEntityActionViewModel, PatientRemove>(nameof(PatientRemove)); Container.RegisterType <IEntityActionViewModel, ContactAdd>(nameof(ContactAdd)); Container.RegisterType <IEntityActionViewModel, ContactRemove>(nameof(ContactRemove)); Factory = Container.Resolve <IEntityActionViewModelFactory>(); Console.WriteLine("---{0}---", nameof(ContainerEntityActionViewModelFactory)); IEntityAction resolvedPatientAdd = Container.Resolve <IEntityAction>(); resolvedPatientAdd.EntityID = 1; resolvedPatientAdd.EntityName = "Patient"; resolvedPatientAdd.ActionID = 1; resolvedPatientAdd.ActionName = "Add"; IEntityAction resolvedPatientRemove = Container.Resolve <IEntityAction>(); resolvedPatientRemove.EntityID = 1; resolvedPatientRemove.EntityName = "Patient"; resolvedPatientRemove.ActionID = 2; resolvedPatientRemove.ActionName = "Remove"; IEntityAction resolvedContactAdd = Container.Resolve <IEntityAction>(); resolvedContactAdd.EntityID = 2; resolvedContactAdd.EntityName = "Contact"; resolvedContactAdd.ActionID = 1; resolvedContactAdd.ActionName = "Add"; IEntityAction resolvedContactRemove = Container.Resolve <IEntityAction>(); resolvedContactRemove.EntityID = 2; resolvedContactRemove.EntityName = "Contact"; resolvedContactRemove.ActionID = 2; resolvedContactRemove.ActionName = "Remove"; entityActionViewModel = Factory.CreateEntityActionViewModel(resolvedPatientAdd); entityActionViewModel?.Operate(); entityActionViewModel = Factory.CreateEntityActionViewModel(resolvedPatientRemove); entityActionViewModel?.Operate(); entityActionViewModel = Factory.CreateEntityActionViewModel(resolvedContactAdd); entityActionViewModel?.Operate(); entityActionViewModel = Factory.CreateEntityActionViewModel(resolvedContactRemove); entityActionViewModel?.Operate(); Console.ReadKey(); }
public IEntityActionViewModel CreateEntityActionViewModel(IEntityAction entityAction) { return(Program.Container.Resolve <IEntityActionViewModel>( entityAction.EntityName + entityAction.ActionName)); }
public void Invoke (IModelContext modelContext, IEntityAction entityAction, TExtension extension) { if (modelContext.NotNull ()) { var context = TModelContext.CastTo (modelContext); var relationList = context.CategoryRelation .ToList () ; if (entityAction.NotNull ()) { var action = TEntityAction.Request (entityAction); action.CollectionAction.SetCollection (relationList); if (action.Operation.HasExtension) { switch (extension) { case TExtension.Settings: { SelectSettings (context, action); } break; case TExtension.ById: { SelectById (context, action); } break; case TExtension.Relation: { SelectRelation (context, action); } break; case TExtension.Many: { SelectMany (context, action); } break; case TExtension.Node: { SelectNode (context, action); } break; case TExtension.Zap: { SelectZap (context, action); } break; case TExtension.Summary: { SelectSummary (context, action); } break; case TExtension.Idle: { //SelectIdle (context, action); } break; case TExtension.Full: { Server.Models.Infrastructure.THelper.FormatExtensionNotImplementedException (action); } break; } } else { Server.Models.Infrastructure.THelper.FormatExtensionMustExistException (action); } } } }
public async Task<IEntityAction> OperationAsync (IEntityAction entityAction) { return (await DataContext.OperationAsync (entityAction).ConfigureAwait (false)); }