public static ActionResponseViewModel AsActionResponseViewModel(this Exception ex) { var viewModel = new ActionResponseViewModel { ResponseType = ActionResponseViewModel.Error, Message = ex.Message }; return(viewModel); }
String BuildProcessArgs(String command, IEnumerable <CommandLineArgument> args) { String cmdAppCommand = command.Trim(); if (!String.IsNullOrEmpty(cmdAppCommand)) { ActionResponseViewModel response = ValidateCommand(cmdAppCommand); if (response.ResponseType == ActionResponseViewModel.Error) { throw new InvalidOperationException(response.Message); } return(cmdAppCommand + " " + BuildCmdAppCommandArgs(args).Trim()); } return(BuildCmdAppCommandArgs(args).Trim()); }
public static ActionResponseViewModel AsActionResponseViewModel(this String resultString, Boolean alwaysReturn = false) { String[] splittedResult = new[] { resultString.Substring(0, 1), resultString.Substring(2, resultString.Length - 2) }; String[] responseTypeList = new[] { ActionResponseViewModel.Info, ActionResponseViewModel.Warning, ActionResponseViewModel.Error, ActionResponseViewModel.Success }; if (!responseTypeList.Contains(splittedResult[0])) { throw new ArgumentException("resultString is bad formatted."); } var viewModel = new ActionResponseViewModel { ResponseType = splittedResult[0], Message = splittedResult[1] .Replace(ActionResponseViewModel.Tab, "\t") .Replace(ActionResponseViewModel.NewLine, Environment.NewLine) }; if (!alwaysReturn && viewModel.ResponseType == ActionResponseViewModel.Error) { throw new InvalidOperationException(viewModel.Message); } return(viewModel); }
public void Run() { Console.WriteLine("Start."); Dbg( Rule.Create() .DispatchWith(new Disp()) .ThenWith(new NullDisp()) .ExpressWith(new Expr()) .OrWith(new Expr()) .OrWith(new Expr()) .AndWith(new Expr()) .Evaluate(new List <BaseType>()) ); Console.WriteLine("Done."); Console.WriteLine("Start."); #region : Current State : // Correct use IWfEngine wfe = new WfEngine(); ActionResponseViewModel result1 = wfe .WithAuditTrailUsername("Username") .WithApp("App") .WithDocNo("DocNo") .WithExecutor(new ApprovalUser()) .UseSuperiorsConfigurator((wfm, pic) => new List <ApprovalUser>()) .WithSegmentPersonInCharges(new List <ApprovalUser>()) .WithSegmentActuals(new List <SegmentConditionActuals>()) .WithApprovalLevelActuals(new List <ApprovalLevelConditionActuals>()) .Start(); ActionResponseViewModel result2 = wfe .WithAuditTrailUsername("Username") .WithApp("App") .WithDocNo("DocNo") .WithExecutor(new ApprovalUser()) .WithPowerOfAttorneys(new List <PowerOfAttorney>()) .Reject(); // Abused ActionResponseViewModel result3 = wfe .WithAuditTrailUsername("Username") .WithApp("App") .WithDocNo("DocNo") .WithExecutor(new ApprovalUser()) .UseSuperiorsConfigurator((wfman, pic) => new List <ApprovalUser>()) .WithSegmentPersonInCharges(new List <ApprovalUser>()) .WithSegmentActuals(new List <SegmentConditionActuals>()) .WithApprovalLevelActuals(new List <ApprovalLevelConditionActuals>()) .UsePowerOfAttorneyConfigurator(wfm => new List <PowerOfAttorney>()) .Start(); ActionResponseViewModel result4 = wfe .WithAuditTrailUsername("Username") .WithApp("App") .WithDocNo("DocNo") .WithExecutor(new ApprovalUser()) .UseSuperiorsConfigurator((wfman, pic) => new List <ApprovalUser>()) .WithSegmentPersonInCharges(new List <ApprovalUser>()) .WithSegmentActuals(new List <SegmentConditionActuals>()) .WithApprovalLevelActuals(new List <ApprovalLevelConditionActuals>()) .UsePowerOfAttorneyConfigurator(wfm => new List <PowerOfAttorney>()) .WithAdditionalApprovalLevelConditions(new List <WfApprovalLevelConditionViewModel>()) .WithAdditionalSegmentConditions(new List <WfSegmentConditionViewModel>()) .Approve(); #endregion #region : New API : // Can't be abused IApprovalDocument ad = new ApprovalDocument(); ActionResponseViewModel result21 = ad .WithAuditTrailUsername("Username") .WithApp("App") .WithDocNo("DocNo") .WithExecutor(new ApprovalUser()) .UseSuperiorsConfigurator((wfm, pic) => new List <ApprovalUser>()) .WithSegmentPersonInCharges(new List <ApprovalUser>()) .WithSegmentActuals(new List <SegmentConditionActuals>()) .WithApprovalLevelActuals(new List <ApprovalLevelConditionActuals>()) .Create(); IApprovalEngine er = new ApprovalEngine(); ActionResponseViewModel result22 = er .Document() .WithAuditTrailUsername("Username") .WithApp("App") .WithDocNo("DocNo") .WithExecutor(new ApprovalUser()) .UseSuperiorsConfigurator((wfm, pic) => new List <ApprovalUser>()) .WithSegmentPersonInCharges(new List <ApprovalUser>()) .WithSegmentActuals(new List <SegmentConditionActuals>()) .WithApprovalLevelActuals(new List <ApprovalLevelConditionActuals>()) .Create(); ActionResponseViewModel result23 = er .Approval() .WithAuditTrailUsername("Username") .WithApp("App") .WithDocNo("DocNo") .WithExecutor(new ApprovalUser()) .UseSuperiorsConfigurator((wfman, pic) => new List <ApprovalUser>()) .WithSegmentPersonInCharges(new List <ApprovalUser>()) .WithSegmentActuals(new List <SegmentConditionActuals>()) .WithApprovalLevelActuals(new List <ApprovalLevelConditionActuals>()) .UsePowerOfAttorneyConfigurator(wfm => new List <PowerOfAttorney>()) .Approve(); #endregion Console.WriteLine("Done."); Console.WriteLine(String.Empty); Dbg("Base Type", new { BaseType1 = BaseTypeImpl.Get("hello"), BaseType2 = BaseTypeImpl.Get("87246877"), BaseType3 = BaseTypeImpl.Get("hello9834789"), BaseType4 = BaseTypeImpl.Get("98ir739"), BaseType5 = BaseTypeImpl.Get("97983347.9479"), BaseType6 = BaseTypeImpl.Get("hello9873498.0934987"), AppvRule1 = new ApproverRule { Id = "15", RegistrationNo = "08362549" }.AsRuleData(), AppvRule2 = new ApproverRule { Id = "16", RegistrationNo = "07463528" }.AsRuleData(), AppvRule3 = new ApproverRule { Id = "25", RegistrationNo = "06492649" }.AsRuleData() } ); }