private Guid Create(string currentUser, UserTypeEnum userType, ErrorCodeEnum exitedUser, ErrorCodeEnum exitedEmail, EnumIDGenerate genCode, dynamic dataObject) { if (!(dataObject is ManagerInput || dataObject is StaffInput || dataObject is EmployeeInput)) { throw new BadData(); } if (ExistedUser(dataObject.Username)) { Log.Information("Username {Username} existed!", (string)dataObject.Username); throw new DefinedException(exitedUser); } else { if (CheckAuthority(currentUser, userType)) { Log.Information("Account {Username} not authorized!", currentUser); throw new DefinedException(ErrorCodeEnum.NotAuthorized); } if (ExisedEmail((string)dataObject.Email)) { Log.Information("Email {Email} existed!", (string)dataObject.Email); throw new DefinedException(exitedEmail); } if (((string)dataObject.Username).HasSpecial()) { Log.Information("User {Username} wrong format!", (string)dataObject.Username); throw new DefinedException(ErrorCodeEnum.ExitedSpecialInUsername); } if (!((string)dataObject.Password).CheckPassFormat()) { Log.Information("Password {Password} wrong format!", (string)dataObject.Password); throw new DefinedException(ErrorCodeEnum.PasswordWrongFormat); } string codeLate = _userRepository.GetAll().OrderBy(x => x.CreatedDate).Last().Code.Base64ToString(); var Code = genCode.GenerateCode(Convert.ToInt32(codeLate) + 1); User user = new User { Id = Guid.NewGuid(), Code = Code, CountryId = (string)dataObject.CountryId, Username = (string)dataObject.Username, FullName = (string)dataObject.FullName, Users = dataObject is EmployeeInput ? null : GenerateUsers(userType, (string)dataObject.CountryId, (string)dataObject.Groups), Groups = dataObject is ManagerInput ? (string)dataObject.Groups : (string)dataObject.Group, Address = (string)dataObject.Address, Email = (string)dataObject.Email, Phone = (string)dataObject.PhoneNo, UserType = userType, Status = dataObject is EmployeeInput ? StatusEnum.Available : StatusEnum.Active, StartDate = (DateTime?)dataObject.StartDate, ExpiredDate = (DateTime?)dataObject.ExpiredDate, Password = string.IsNullOrEmpty(dataObject.Password) ? GeneratePassword() : dataObject.Password, CreatedBy = currentUser, }; user = _userRepository.Insert(user); //_emailService.SendNewPassword(user.Email, EncryptService.Decrypt(user.Password), user.FullName, null); Log.Information("Create " + user.UserTypeStr + ": {Username} Successfully", user.Username); return(user.Id); } }
public GenericSocialChannelException(string channel, ErrorCodeEnum errorCode, string errorMessage) : base( channel, errorCode, errorMessage) { }
/// <summary> /// Creates an exception instance based on a supplied inner exception and a /// message describing the situation. Should only be used for unexpected errors. /// </summary> /// <param name="message"></param> /// <param name="innerException"></param> public PandoraException(string message, Exception innerException, string xmlStr) : base(message, innerException) { _message = message; _errorCode = ErrorCodeEnum.APPLICATION_ERROR; _xmlString = xmlStr; }
////////////////////////////////游戏事件响应//////////////////////////////////// //登录失败 void LoginFail(ErrorCodeEnum errorCode) { mPlayAnimate.enabled = true; mPlaySubmitBtn.gameObject.SetActive(true); GameObject.DestroyImmediate(mPlayEffect.gameObject); }
private void Update(UpdateInput requestDto, ErrorCodeEnum exitedEmail) { dynamic dataInput = requestDto.DataUpdate; if (!(dataInput is ManagerUpdateInput || dataInput is StaffUpdateInput || dataInput is EmployeeUpdateInput)) { throw new BadData(); } User user = _userRepository.GetById((Guid)dataInput.Id); if (user != null) { if (ExisedEmail(email: (string)dataInput.AddressInfo.Email, idUpdate: (Guid)dataInput.Id)) { Log.Information("Email {Email} existed!", (string)dataInput.AddressInfo.Email); throw new DefinedException(exitedEmail); } #region handle variable bool dataStatus = (user.ExpiredDate.Value - DateTime.Now).TotalDays < 0 ? false : (bool)dataInput.Status; StatusEnum valueType = dataStatus ? dataInput is EmployeeUpdateInput ? StatusEnum.Available : StatusEnum.Active : dataInput is EmployeeUpdateInput ? StatusEnum.Unavailable : StatusEnum.Inactive; if (!AllowUnselectGroups((string)dataInput.CountryId, dataInput is ManagerUpdateInput ? (string)dataInput.Groups : (string)dataInput.Group, (string)dataInput.Users, user)) { Log.Information("Cannot unselect the group from the list!", ErrorCodeEnum.CannotUnSelectGroup); throw new DefinedException(ErrorCodeEnum.CannotUnSelectGroup); } #endregion #region update user user.Status = valueType; user.CountryId = (string)dataInput.CountryId; user.FullName = (string)dataInput.FullName; user.Groups = dataInput is ManagerUpdateInput ? (string)dataInput.Groups : (string)dataInput.Group; user.Users = dataInput is EmployeeUpdateInput ? null : user.CountryId.Equals((string)dataInput.CountryId) ? (string)dataInput.Users : string.Empty; user.Address = (string)dataInput.AddressInfo.Address; user.Phone = (string)dataInput.AddressInfo.PhoneNo; user.Email = (string)dataInput.AddressInfo.Email; user.ExpiredDate = (DateTime?)dataInput.ExpiredDate; user.LastUpdatedBy = requestDto.CurrentUser; user.LastUpdateDate = DateTime.Now; #endregion try { _unitOfWork.Update(user); _unitOfWork.Commit(); } catch { Log.Information("Cannot Update " + user.UserTypeStr + ": {Username}.", user.Username); throw new DefinedException(ErrorCodeEnum.CannotUpdateUsers); } } else { Log.Information("Not Found User: {Username}.", (string)dataInput.Username); throw new DefinedException(ErrorCodeEnum.UserNotFound); } }
public GdErrorException(string msg, LogObject logData, ErrorCodeEnum errorCode, string errorName, Exception ex) : base(msg, ex) { LogData = logData; ErrorCode = errorCode; ErrorName = errorName; }
public static ErrorCode Create(ErrorCodeEnum v) { return(new ErrorCode { InnerValue = v }); }
/// <summary> /// Instantiate. /// </summary> /// <param name="code">Error code.</param> /// <param name="msg">Message.</param> /// <param name="detail">Detail.</param> /// <param name="e">Exception.</param> public ErrorResponse(ErrorCodeEnum code, string msg, string detail, Exception e = null) { Success = false; Code = code; Message = msg; Detail = detail; Exception = e; }
public void SetFail(Exception ex, ErrorCodeEnum code = ErrorCodeEnum.NoErrorCode) { Status = false; ErrorCode = code; string message = $"Message: {ex.Message}, StackTrace: {ex.StackTrace}"; Messages.Add(message); }
public void SetFail(ErrorCodeEnum code) { Status = false; ErrorCode = code; string message = code.GetDisplayName(); Messages.Add(message); }
protected BaseException(string title, string details, ErrorCodeEnum errorCode, ProblemDetails problemDetails) : base(details) { StatusCode = (HttpStatusCode)problemDetails.Status; Title = $"{title} - [Inner problem : {problemDetails?.Status?.ToString()} {problemDetails?.Title}]"; ExposedDetails = $"{details} - [Inner errorCode: {problemDetails?.Type} - details : {problemDetails?.Detail} - Instance: {problemDetails?.Instance}]"; ErrorCode = errorCode; }
/// <summary> /// Marca el resultado como fallido /// </summary> /// <param name="message">Mensaje de error a ingresar a la lista</param> /// <param name="errorCode">Código de error</param> public void MarkAsFailed(string message = "Ha ocurrido un error y el proceso no ha podido continuar", ErrorCodeEnum errorCode = ErrorCodeEnum.LOGIC_ERROR) { Result = ResultTypeEnum.Error; Info.Add(new OperationMessage(message, MessageTypeEnum.Error)); log.Error(message); ErrorCode = errorCode; }
protected BaseException(HttpStatusCode statusCode, string title, string details, ErrorCodeEnum errorCode, Exception inner) : base(details, inner) { StatusCode = statusCode; Title = title; ExposedDetails = details; ErrorCode = errorCode; }
public void SetFail(IEnumerable <string> messages, ErrorCodeEnum code = ErrorCodeEnum.NoErrorCode) { Status = false; ErrorCode = code; foreach (var message in messages) { Messages.Add(message); } }
void RegisterResult(ErrorCodeEnum m_n32ErrorId) { if (m_n32ErrorId == ErrorCodeEnum.NULLNickName) { ShowTip(nullName); } MsgInfoManager.Instance.ShowMsg((int)m_n32ErrorId); noPass.gameObject.SetActive(true); pass.gameObject.SetActive(false); }
/// <summary> /// Create an exception from an error code and message provided by the Pandora servers. /// If the error code is recognized, the ErrorCode field will be populated. /// </summary> /// <param name="errorCodeStr"></param> /// <param name="message"></param> public PandoraException(int errorCode, string message) { try { _message = message; _errorCode = (ErrorCodeEnum)errorCode; } catch (Exception) { _errorCode = ErrorCodeEnum.UNKNOWN; _message = message; } }
private Exception AssignDefaultErrorCode(Exception ex, ErrorCodeEnum errorCode) { var gdEx = ex as GdErrorException; if (gdEx?.ErrorCode == ErrorCodeEnum.None) { gdEx.ErrorCode = errorCode; return(gdEx); } return(ex); }
/// <summary> /// Builds a Bad Request (400) result with a default error message indicating the request is invalid. /// </summary> /// <returns></returns> protected new BadRequestObjectResult BadRequest() { ErrorCodeEnum errorCode = ErrorCodeEnum.RequestIsNull; var response = new OperationResponse { Success = false }; response.AddError((int)errorCode, ErrorCodeMessage.GetMessage(errorCode)); return(base.BadRequest(response)); }
public static Result <T> CreateFailure <T>(ErrorCodeEnum errorCode, Exception exception = null) { return(new Result <T>(new List <ErrorCodeEnum>() { errorCode }) { Status = ResultStatusEnum.Failure, Exception = exception }); }
/// <summary> /// 返回错误提示 /// </summary> /// <typeparam name="T">默认返回值类型</typeparam> /// <param name="errorCode">错误代码</param> /// <param name="errorMsg">错误信息</param> /// <returns></returns> protected new AjaxResult <T> Response <T>(ErrorCodeEnum errorCode, string errorMsg) { if (IsValidOperation()) { return(new AjaxResult <T>(errorCode, errorMsg)); } var errMsg = _notifications.GetNotifications().Select(n => n.Value).ToList(); errMsg.Add(errorMsg); return(new AjaxResult <T>(errorCode, errMsg.Join("", "|"))); }
/// <summary> /// Builds a Not Found (404) result with a message indicating the key not found. /// </summary> /// <param name="resource"></param> /// <param name="key"></param> /// <returns></returns> protected NotFoundObjectResult NotFound(string resource, object key) { ErrorCodeEnum errorCode = ErrorCodeEnum.ResourceNotFound; var response = new OperationResponse { Success = false }; // TODO: Validate if modify the property name of "Key" to "Identifier". response.AddError((int)errorCode, ErrorCodeMessage.GetMessage(errorCode, resource, key), "Key"); return(base.NotFound(response)); }
/// <summary> /// Marca el resultado como fallido /// </summary> /// <param name="ex">Excepción que genera el error. Toma en cuenta el error interno si es que este existe</param> /// <param name="errorCode">Código de error</param> public void MarkAsFailed(Exception ex, ErrorCodeEnum errorCode = ErrorCodeEnum.LOGIC_ERROR) { Result = ResultTypeEnum.Error; Info.Add(new OperationMessage("Ha ocurrido una excepción no controlada, ha quedado registrada en el log de la plataforma.", MessageTypeEnum.Error)); log.Error(ex); ErrorCode = errorCode; if (ex.InnerException != null) { log.Error(ex.InnerException, "Inner Exception"); } }
/// <summary> /// 根据错误枚举获取错误提示 /// </summary> /// <param name="e">错误枚举值</param> /// <param name="para">替换参数</param> /// <returns></returns> public static string GetErrorMsgByEnum(ErrorCodeEnum e, params string[] para) { switch (e) { case ErrorCodeEnum.NotHasLoginInfo: return(ConstNotHasLoginInfo); case ErrorCodeEnum.NoAuthorize: return(ConstNoAuthorize); case ErrorCodeEnum.ProcExecError: return(string.Format(ConstProcExecError, para)); default: return("未知错误"); } }
public SocialChannelExceptionBase( string channel, ErrorCodeEnum errorCode, string errorMessage) : base( $"SocialLogin channel exception\r\n" + $" Channel = {channel}\r\n" + $" ErrorCode = {errorCode.ToString()}\r\n" + $" ErrorMessage = {errorMessage}") { this.Channel = channel; this.ErrorCode = errorCode; this.ErrorMessage = errorMessage; }
/// <summary> /// 返回失败结果 /// </summary> /// <param name="errorCode"></param> /// <returns></returns> protected ResponseModel Fail(ErrorCodeEnum errorCode) { //获得枚举值对应错误信息 var errorDescription = ((int)errorCode).ToEnumDescriptionString(typeof(ErrorCodeEnum)); if (string.IsNullOrEmpty(errorDescription)) { errorDescription = "未知错误"; } return(new ResponseModel { Code = (int)errorCode, Message = errorDescription }); }
protected virtual ErrorModel CreateLogError(string methodName, ErrorCodeEnum errorCodeEnum, string errorMessage, ILogger log) { var error = new ErrorModel() { ErrorId = Guid.NewGuid(), Method = methodName, ErrorCode = errorCodeEnum, ErrorMessage = errorMessage, ErrorTime = DateTime.UtcNow }; log.LogError(JsonSerializer.Serialize(error)); return(error); }
/// <summary> /// Converts a ErrorCodeEnum value to a corresponding string value /// </summary> /// <param name="enumValue">The ErrorCodeEnum value to convert</param> /// <returns>The representative string value</returns> public static string ToValue(ErrorCodeEnum enumValue) { switch (enumValue) { //only valid enum elements can be used //this is necessary to avoid errors case ErrorCodeEnum.SUCCESS: case ErrorCodeEnum.PROCESSING: case ErrorCodeEnum.FAILURE: case ErrorCodeEnum.UNSUPPORTED: return(stringValues[(int)enumValue]); //an invalid enum value was requested default: return(null); } }
/// <summary> /// Marca el resultado como fallido /// </summary> /// <param name="messages">Lista de mensajes a ingresar</param> /// <param name="errorCode">Código de error</param> public void MarkAsFailed(IEnumerable <string> messages, ErrorCodeEnum errorCode = ErrorCodeEnum.LOGIC_ERROR) { if (messages == null) { messages = new string[] { "Se recomienda hacer una verificación mas profunda, la lista de errores llego nula" } } ; Result = ResultTypeEnum.Error; Info.AddRange(messages.Select(x => new OperationMessage(x, MessageTypeEnum.Error))); ErrorCode = errorCode; foreach (var item in messages) { log.Error(item); } }
/// <summary> /// Creates an exception from the given server response object. /// </summary> /// <param name="response"></param> internal PandoraException(PandoraResponse response) { try { if (response == null) { throw new PandoraException("Attempted to parse null response."); } if (response.Success) { throw new PandoraException("Attempted to parse error from successful response."); } _message = response.ErrorMessage; _errorCode = (ErrorCodeEnum)response.ErrorCode; } catch (Exception e) { throw new PandoraException("Failed parsing error response.", e); } }
private Task sendUnsuccessfullResponse(string connectionId, ErrorCodeEnum errorCode) { switch (errorCode) { case ErrorCodeEnum.ERROR100: return(Clients.Client(connectionId).SendAsync("HasAnErrorOccurred", "ERROR100")); case ErrorCodeEnum.ERROR101: return(Clients.Client(connectionId).SendAsync("HasAnErrorOccurred", "ERROR101")); case ErrorCodeEnum.ERROR102: return(Clients.Client(connectionId).SendAsync("HasAnErrorOccurred", "ERROR102")); case ErrorCodeEnum.ERROR103: return(Clients.Client(connectionId).SendAsync("HasAnErrorOccurred", "ERROR103")); default: return(Clients.Client(connectionId).SendAsync("HasAnErrorOccurred", "UNKNOWN")); } }
/// <summary> /// Creates an exception from the given server response object. /// </summary> /// <param name="response"></param> internal PandoraException(PandoraResponse response) { try { if (response == null) throw new PandoraException("Attempted to parse null response."); if (response.Success) throw new PandoraException("Attempted to parse error from successful response."); _message = response.ErrorMessage; _errorCode = (ErrorCodeEnum)response.ErrorCode; } catch (Exception e) { throw new PandoraException("Failed parsing error response.", e); } }
/// <summary> /// Sets the error code to a known valie /// </summary> /// <param name="errorCode"></param> public void SetKnownErrorCode(ErrorCodeEnum errorCode) { _errorCode = (int)errorCode; }
/// <summary> /// Creates an exception instance with the given message describing the situation. /// Should only be used for unexpected errors. /// </summary> /// <param name="message"></param> public PandoraException(string message) : base(message) { _message = message; _errorCode = ErrorCodeEnum.APPLICATION_ERROR; }
/// <summary> /// Initializes a new instance of <see cref="ReportingDateException"/> /// </summary> public ReportingDateException(ErrorCodeEnum errorCode) { ErrorCode = errorCode; }
public static ErrorCode Create(ErrorCodeEnum v) { return new ErrorCode { InnerValue = v }; }
/// <summary> /// Used when handle faulty rps request for example when there is no handler/script to handle it but we want to response or log it anyway as there is a waiting client. /// </summary> /// <param name="op"></param> /// <param name="req"></param> /// <param name="error"></param> /// <param name="message"></param> /// <returns></returns> public static RequestData Create( string op, RequestData req, ErrorCodeEnum error, string message) { RequestData newReq = new RequestData ( req.CommunicationObject ) { Op = op }; newReq.InnerRequestData = req; newReq.ErrorCode = error; newReq.ErrorMessage = message; //we need these fields to do rpc response newReq.CorrelationId = req.CorrelationId; newReq.DestAddress = req.DestAddress; newReq.DeliveryTag = req.DeliveryTag; return newReq; }
/// <summary> /// Initializes a new instance of the <see cref="ReportingParameterValueException"/> class with a specified error message. /// </summary> public ReportingParameterValueException(ErrorCodeEnum errorCode, string parameterPrompt) { ErrorCode = errorCode; ParameterPrompt = parameterPrompt; }
// This function updates the WARNING box. public void UpdateWarningDisplay(string Warning, ErrorCodeEnum ErrorCode) { if (abort_oven_program) { StopThreads_AndCloseOvenProgram(); return; } try { WarningTextBox.Text = Warning; switch (ErrorCode) { case ErrorCodeEnum.NoError: ReadTC_Button.BackColor = Color.GreenYellow; StopTC_Button.BackColor = default(Color); for (int i = 0; i < MAX_CHANCOUNT; i++) { if (this.Controls["Channel" + i.ToString("#0") + "TextBox"].ForeColor == Color.Gray) { this.Controls["Channel" + i.ToString("#0") + "TextBox"].ForeColor = Color.LawnGreen; } } break; case ErrorCodeEnum.Error: ReadTC_Button.BackColor = default(Color); StopTC_Button.BackColor = Color.Red; for (int i = 0; i < MAX_CHANCOUNT; i++) { this.Controls["Channel" + i.ToString("#0") + "TextBox"].ForeColor = Color.Gray; } break; default: break; } return; } catch { MessageBox.Show( "Update Error Warning Display has encountered an unexpected error!", " ERROR!"); return; } }