Exemple #1
0
        /// <summary>
        /// Обновить
        /// </summary>
        /// <param name="model"></param>
        public void Update(IResultModel model)
        {
            StudentResults = model.Students;

            DisposeRatingPanel();
            FillRating();
        }
        public void ProcessCommand(IResultModel resultModel, IList <string> resultModelPropsChanged)
        {
            var commandHandler = _runtime.Container.Resolve <ICommandHandler>(
                new TypedParameter(typeof(IResultModel), resultModel),
                new TypedParameter(typeof(IList <string>), resultModelPropsChanged),
                new TypedParameter(typeof(DisplayablesRepo), _displayablesRepo)
                );

            if (resultModel.GetType() == typeof(MovementResultModel))
            {
                commandHandler.SetCommand <MovementCommand>();
                var command = (MovementCommand)commandHandler.GetCommand();

                // Inject in any other dependencies specific to movement commands
                command.InjectInRoomMachine(_initializedMachines.Single(m => m.GetType() == typeof(RoomMachine)).Get());

                command.InjectInRoomStates(_roomsStates);

                command.InjectInRoomTriggers(_roomsTriggers);

                command.Execute();
            }

            else if (resultModel.GetType() == typeof(LookResultModel))
            {
                commandHandler.SetCommand <LookCommand>();
                var command = (LookCommand)commandHandler.GetCommand();

                command.InjectInRoomMachine(_initializedMachines.Single(m => m.GetType() == typeof(RoomMachine)).Get());

                command.InjectInRoomStates(_roomsStates);

                command.Execute();
            }
        }
Exemple #3
0
 public IResultModel OnError(IResultModel rm)
 {
     this.Success      = false;
     this.ErrorMessage = rm.ErrorMessage;
     this.ErrorCode    = rm.ErrorCode;
     return(this);
 }
Exemple #4
0
 public IResultServiceModel <TResult> OnError(IResultModel rm)
 {
     this.Success      = false;
     this.ErrorMessage = rm.ErrorMessage;
     this.Value        = default(TResult);
     this.ErrorCode    = rm.ErrorCode;
     return(this);
 }
Exemple #5
0
        /// <summary>
        /// 增加参数到ResultModel的格式化参数中
        /// </summary>
        protected void AddFormatParasToIResultModel(IResultModel resultModel, params object[] paras)
        {
            if (resultModel == null || paras == null || paras.Length == 0)
            {
                return;
            }

            resultModel.MsgFormatParameter.AddRange(paras);
        }
 public virtual void SuccessfulResponse(IResponse response, IResultModel resultModel, string message = null)
 {
     response.Result = new OkResult {
         Model = resultModel
     };
     if (!string.IsNullOrEmpty(message))
     {
         response.Result.Message = message;
     }
 }
Exemple #7
0
        public static async Task <IResultModel> OnSuccess(this IResultModel resultModel, Func <Task> func)
        {
            if (!resultModel.Success)
            {
                return(ResultModel.Fail(resultModel.ApiResult));
            }

            await func();

            return(ResultModel.Ok());
        }
 public IActionResult SetStatusCode(IResultModel model)
 {
     if (String.IsNullOrEmpty(model.errorMessage))
     {
         return(new OkObjectResult(model));
     }
     else
     {
         return(new BadRequestObjectResult(model));
     }
 }
Exemple #9
0
        public async Task <HttpResponseMessage> DeleteItem([FromUri] ProjectItemRequest request)
        {
            HttpResponseMessage httpResponse = null;
            string uri    = Url.Link("ProjectDeleteApi", new { id = request.id });
            string userId = request.userName;
            IResultServiceModel <ProjectItemResponse> response = new ResultServiceModel <ProjectItemResponse>();

            if (request.id <= 0)
            {
                response.OnError(ProjectResources.ErrorItemDoesNotExist_OnDelete, EnumErrorCode.ITEM_DOES_NOT_EXIST);
            }
            else
            {
                try
                {
                    var rmCred = this.ValidateUserCredentials(request.userName);
                    if (rmCred.Success)
                    {
                        IResultModel rmDelete = await this.projectService.DeleteProjectByUserAsync(request);

                        if (rmDelete.Success)
                        {
                            response.OnSuccess(new ProjectItemResponse()
                            {
                                item = new ProjectPOCO()
                                {
                                    Id = request.id
                                }
                            });
                        }
                        else
                        {
                            response.OnError(
                                ErrorResources.ModelStateErrors_Format.sf(rmDelete.ErrorMessage),
                                rmDelete.ErrorCode
                                );
                        }
                    }
                    else
                    {
                        response.OnError(rmCred.ErrorMessage, rmCred.ErrorCode);
                    }
                }
                catch (Exception ex)
                {
                    response.OnException(ex);
                }
            }

            httpResponse = Request.CreateResponse <IResultServiceModel <ProjectItemResponse> >(HttpStatusCode.Created, response);
            httpResponse.Headers.Location = new Uri(uri);

            return(httpResponse);
        }
Exemple #10
0
        public static async Task <IResultModel <T> > OnSuccess <T>(this IResultModel resultModel, Func <Task <T> > func, T defaultValue)
        {
            if (!resultModel.Success)
            {
                return(ResultModel.Failure(resultModel.ApiResult, defaultValue));
            }

            var result = await func();

            return(ResultModel.Ok(result));
        }
        public void ListenAndLearn(object sender, PropertyChangedEventArgs e, CommandResultModelHandler commandResultModelHandler)
        {
            Debug.WriteLine("A property has changed: " + e.PropertyName + " in " + commandResultModelHandler.GetPropSource());

            _propertiesBeingChanged.Add(e.PropertyName);

            if (commandResultModelHandler.isPropSourceChanged)
            {
                _propSourceBeingChanged = commandResultModelHandler.GetPropSource();
                _resultModel            = commandResultModelHandler.GetResultModel();
            }
        }
Exemple #12
0
        /// <summary>
        /// 增加参数到ResultModel的格式化参数中
        /// </summary>
        protected void AddFormatParasToIResultModel(IResultModel resultModel, ModelStateError firstModelError = null)
        {
            if (resultModel == null)
            {
                return;
            }

            var error = firstModelError == null?this.GetFirstModelError() : firstModelError;

            if (error == null || string.IsNullOrEmpty(error.key))
            {
                return;
            }

            var errorProperty = this.CurrentFormParameters.First().Value.GetType().GetProperty(error.key);

            if (errorProperty == null)
            {
                return;
            }

            var validAttrs = errorProperty.GetCustomAttributes <ValidationAttribute>();

            if (validAttrs == null)
            {
                return;
            }

            var targetValidAttr = validAttrs.Where(item => item.ErrorMessage == error.msg).FirstOrDefault();

            if (targetValidAttr != null)
            {
                if (targetValidAttr is StringLengthAttribute stringAttr)
                {
                    AddFormatParasToIResultModel(resultModel, stringAttr.MinimumLength, stringAttr.MaximumLength);
                }
                else if (targetValidAttr is YearRangeValidityAttribute yearAttr)
                {
                    AddFormatParasToIResultModel(resultModel, yearAttr.MinDate.ToCnDateString(), yearAttr.MaxDate.ToCnDateString());
                }
                else if (targetValidAttr is RangeAttribute rangeAttr)
                {
                    AddFormatParasToIResultModel(resultModel, rangeAttr.Minimum, rangeAttr.Maximum);
                }
            }

            if (resultModel.code <= 0)
            {
                resultModel.code = ConvertHelper.GetInt(error.msg);
            }
        }
Exemple #13
0
        public static ResultModel ToProtoResultModel(this IResultModel response)
        {
            var resultModel = new ResultModel
            {
                Status = response.Success ? Status.Success : Status.Failure,
                Data   = { response.ApiResult.ValidationErrors.Select(x => new Data
                    {
                        Key   = x.Field,
                        Value = x.Message
                    }) }
            };

            return(resultModel);
        }
Exemple #14
0
 private static void SetResult(string operationName, IResultModel resultModel)
 {
     Console.WriteLine("Operation : " + operationName);
     if (resultModel.IsSuccess)
     {
         Console.WriteLine("Success");
     }
     else
     {
         Console.WriteLine("Error");
         foreach (var item in resultModel.Messages)
         {
             Console.WriteLine("ErrorCode: " + item.Code + " - ErrorMessage: " + item.Message);
         }
     }
 }
 public IHttpActionResult GetErrorHttpActionResult(IResultModel result)
 {
     if (result.StatusCode == 400)
     {
         ModelState.AddModelError("model", result.Message);
         return(BadRequest(ModelState));
     }
     else if (result.StatusCode == 404)
     {
         return(NotFound());
     }
     else
     {
         return(InternalServerError(new Exception(result.Message)));
     }
 }
Exemple #16
0
        public async Task <HttpResponseMessage> Get()
        {
            HttpResponseMessage httpResponse = null;
            string       uri      = string.Empty;
            IResultModel response = await Task.FromResult(new ResultModel()
            {
                Success = true,
                Message = "This is a GET Test with no parameters."
            });

            httpResponse = Request.CreateResponse <IResultModel>(HttpStatusCode.Created, response);
            uri          = Url.Link("TestApi", new { id = 0 });

            httpResponse.Headers.Location = new Uri(uri);

            return(httpResponse);
        }
 public void SetResultModel(IResultModel resultModel)
 {
     _resultModel = resultModel;
 }
Exemple #18
0
 public SEOViewModel(IUserInputModel _userInputModels, IResultModel _resultModel)
 {
     UserInputModel = _userInputModels;
     //ResultModel = _resultModel;
 }
Exemple #19
0
 public SEOViewModel()
 {
     UserInputModel = new UserInputModel();
     ResultModel    = new ResultModel();
 }
Exemple #20
0
        public void PopulateResultModel(IResultModel resultModel)
        {
            var movementResultModel = resultModel as MovementResultModel;

            FindInAdverbLex();
            FindInMovementLex();
            FindInDirectionsLex();
            FindInLocationsLex();


            // if an adverb is found, we'll get the name of it
            if (_adverbLexAction != null)
            {
                movementResultModel.Adverb = _adverbLexAction.name;
            }


            // the base movement action verb should either appear at the beginning of the command, or immediately after an adverb, so let's check for this
            if (CheckAppearanceOfMovementVerbAtBeginning())
            {
                // if so, get the name and method of the movement verb
                movementResultModel.BaseActionVerb = _movementLexAction.name;
                movementResultModel.Method         = _movementLexAction.method;

                if (_adverbLexAction != null)
                {
                    // The speed defined by an adverb, and the speed defined by a movement verb, can "cancel each other out"

                    // E.g. the phrase "quickly crawl" defaults to a "normal" speed
                    if (_adverbLexAction.speed == "fast" && _movementLexAction.speed == "slow")
                    {
                        movementResultModel.Speed = "normal";
                    }
                    // Similarly, the phrase "slowly run" defaults to a "normal" speed
                    else if (_adverbLexAction.speed == "slow" && _movementLexAction.speed == "fast")
                    {
                        movementResultModel.Speed = "normal";
                    }
                    else
                    {
                        movementResultModel.Speed = _adverbLexAction.speed;
                    }
                }

                // if a valid movement verb was found and no adverb was found, we'll get the speed from the movement verb
                else if (_adverbLexAction == null)
                {
                    movementResultModel.Speed = _movementLexAction.speed;
                }
            }


            if (_directionsLexAction != null)
            {
                if (CheckCardinalDirectionIsNmodToMovementVerb())
                {
                    movementResultModel.CardinalDirection = _directionsLexAction.name;
                }
            }

            if (CheckIfCardinalDirectionIsOnlyWord())
            {
                movementResultModel.CardinalDirection = _directionsLexAction.name;
            }

            if (_locationsLexAction != null)
            {
                movementResultModel.LocationDirection = _locationsLexAction.name;

                if (!_locationsLexAction.gameRoomIds.IsNullOrEmpty())
                {
                    movementResultModel.LocationDirectionRoomIds = _locationsLexAction.gameRoomIds;
                }
            }

            if (GetLocationFromEntityMentions() != null)
            {
                movementResultModel.UnknownLocationDirection = GetLocationFromEntityMentions();
            }
        }
 public void InjectInResultModel(IResultModel resultModel, IList <string> resultModelPropsChanged)
 {
     _resultModel             = resultModel;
     _resultModelPropsChanged = resultModelPropsChanged;
 }
 public void InjectInResultModel(TextAdventure.Command.Determination.Result.Models.IResultModel resultModel, IList <string> resultModelPropsChanged)
 {
     _resultModel             = resultModel;
     _resultModelPropsChanged = resultModelPropsChanged;
 }
Exemple #23
0
 public CustomJsonBuilder(IResultModel resultado, ModelStateDictionary modelState)
 {
     ModelState   = modelState;
     IResultModel = resultado;
 }
 public CommandHandler(IResultModel resultModel, IList <string> resultModelPropsChanged, DisplayablesRepo displayablesRepo)
 {
     _resultModel             = resultModel;
     _resultModelPropsChanged = resultModelPropsChanged;
     _displayablesRepo        = displayablesRepo;
 }