예제 #1
0
        /// <summary>
        /// 记错误日志或异常日志
        /// </summary>
        /// <param name="moduleID">模块编号</param>
        /// <param name="funcCode">权限代码</param>
        /// <param name="level">日志级别,3级(WARN,EROR,FATL)<</param>
        /// <param name="errCode">错误码,对于没有明确错误码的场合需要给一个系统级的通用错误码</param>
        /// <param name="ex">发生的异常</param>
        /// <param name="msg">错误信息</param>
        /// <param name="contextInfo">错误上下文</param>
        public void LogError(string moduleID, string funcCode, AppError level, string errCode, string ex, string msg, string contextInfo)
        {
            StringBuilder logMessage = new StringBuilder();

            logMessage.AppendFormat("Time={0}; LogLevel={1}; ModuleID={2}; FuncCode={3}; ErrorCode={4}; ", DateTime.Now, level, moduleID, funcCode, errCode);

            if (!string.IsNullOrEmpty(contextInfo))
            {
                logMessage.AppendLine();
                logMessage.AppendFormat("[ContextInfo]={0}", contextInfo);
            }

            if (!string.IsNullOrEmpty(msg))
            {
                logMessage.AppendLine();
                logMessage.AppendFormat("[Custom Message]={0}", msg);
            }

            if (ex != null)
            {
                logMessage.AppendLine();
                logMessage.AppendLine(ex);
                //logMessage.AppendLine(string.Format("Exception={0}", ex));
            }

            if (logerror.IsErrorEnabled)
            {
                logerror.Error(logMessage.ToString());
            }
        }
예제 #2
0
        public bool UpdateUser(AppUser user)
        {
            using (SqlConnection con = new SqlConnection(DbHelper.ConnectionString))
            {
                SqlCommand com = new SqlCommand("Administration.usp_AppUser_Update", con);
                com.CommandType = CommandType.StoredProcedure;
                com.Parameters.AddWithValue("@userId", user.Id);
                com.Parameters.AddWithValue("@firstName", user.FirstName);
                com.Parameters.AddWithValue("@lastName", user.LastName);
                com.Parameters.AddWithValue("@email", user.Email);
                com.Parameters.AddWithValue("@bio", user.Bio);

                try
                {
                    con.Open();
                    com.ExecuteNonQuery();

                    return(true);
                }
                catch (Exception e)
                {
                    AppError er = new AppError()
                    {
                        UserId           = user.Id,
                        ExceptionMessage = e.Message
                    };
                    Error.AppErrorRepo.InsertError(er);
                    return(false);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// ErrorTypes:
        /// </summary>
        /// <remarks>
        /// <para>msg:  Error message</para>
        /// <para>ErrorType: 1- Exception : Exception in Code, 2- third Party,
        /// ErrorType: 2- Server : Server Error,
        /// ErrorType: 3- ThirdParty : Third Party like Email Sender API,
        /// ErrorType: 4- Other : Other Errors </para>
        /// <para>line: Error Line</para>
        /// </remarks>
        public async Task ErrorRegister(string msg, int statusCode = 0, string details = null, int errorTypeId = 4, string filePath = null, int errorLine = 0)
        {
            var fileP = "";

            if (!string.IsNullOrEmpty(filePath))
            {
                fileP = $"File Path:{filePath}\n";
            }

            if (errorLine != 0)
            {
                fileP = $"{fileP}in line: {errorLine}\n";
            }

            var appError = new AppError
            {
                Message     = msg,
                StatusCode  = statusCode,
                ErrorTypeId = errorTypeId,
                Details     = fileP + details,
                ErrorDate   = DateTime.Now
            };
            await _context.AppError.AddAsync(appError);

            await _context.SaveChangesAsync();

            // add this code where errors need to register
            /************************* ADD Error In AppError Table ****************************/
            //await _globalFunc.ErrorRegister(msg: "Some text to descript the error",
            //    statusCode: 0,
            //    errorTypeId: 2, /* the error type: 1: Exception, 2:Server, 3: third party, 4: Other */
            //    filePath: new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName(),/* Get File Name */
            //    errorLine: (new System.Diagnostics.StackFrame(0, true)).GetFileLineNumber()); /* Get Error Line */
            /************************* END ADD Error In AppError Table ************************/
        }
예제 #4
0
        public string UpdatePassword(AppUser user, string newPassword)
        {
            using (SqlConnection con = new SqlConnection(DbHelper.ConnectionString))
            {
                SqlCommand com = new SqlCommand("Administration.usp_AppUser_UpdatePassword", con);
                com.CommandType = CommandType.StoredProcedure;
                com.Parameters.AddWithValue("@userId", user.Id);
                com.Parameters.AddWithValue("@oldPassword", user.Password);
                com.Parameters.AddWithValue("@newPassword", newPassword);

                try
                {
                    con.Open();
                    var r = com.ExecuteReader();
                    if (r.Read())
                    {
                        return(r["Message"].ToString());
                    }
                }
                catch (Exception e)
                {
                    AppError er = new AppError()
                    {
                        UserId           = user.Id,
                        ExceptionMessage = e.Message
                    };
                    Error.AppErrorRepo.InsertError(er);
                }
            }
            return("Error while changing password!");
        }
예제 #5
0
        private void FillResultsGrid()
        {
            const string METHOD_NAME = "FillResultsGrid";

            try {
                txtEditAction.Text    = "";
                txtEditClient.Text    = "";
                txtEditErrorCode.Text = "";
                txtEditServer.Text    = "";
                txtEditUser.Text      = "";
                txtErrorText.Text     = "";

                string fromDate = txtFromDate.Text;
                string toDate   = txtToDate.Text;
                string status   = Common.UILib.GetDropDownText(ddlStatus);

                List <ListAppErrorItem> errorFiles = AppError.AppErrorFileGet(status, Convert.ToDateTime(fromDate), Convert.ToDateTime(toDate));

                grdResult.SelectedIndex = -1;
                if (errorFiles.Count > 0)
                {
                    grdResult.DataSource = errorFiles;
                }
                else
                {
                    grdResult.DataSource = null;
                }
                grdResult.DataBind();
            }
            catch (Exception ex) {
                Common.CException wex = new Common.CException(MOD_NAME + METHOD_NAME, ex);
                throw (wex);
            }
        }
예제 #6
0
        protected void btnDeleteErrorFile_Click(object sender, EventArgs e)
        {
            const string METHOD_NAME = "btnDeleteErrorFile_Click";

            try {
                GridViewRow row  = grdResult.SelectedRow;
                string      path = row.Cells[Convert.ToInt32(ErrorResultColumn.errColPath)].Text;

                if (Common.CodeLib.IsNumeric(path))
                {
                    AppError.AppErrorFileDelete(Convert.ToInt32(path));
                }
                else
                {
                    File.Delete(path);
                }

                ClearEditValues();
                FillResultsGrid();
            }
            catch (System.Exception ex) {
                Common.CException wex = new Common.CException(MOD_NAME + METHOD_NAME, ex);
                ((PrimaryTemplate)Page.Master).ShowWarning(ex);
            }
        }
예제 #7
0
        /// <summary>
        /// 取得用户所有电站跨小时的功率图表
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="startYYYYMMDDHH"></param>
        /// <param name="endYYYYMMDDHH"></param>
        /// <param name="chartType"></param>
        /// <returns></returns>
        public ActionResult AllPlantDayChart(int userId, string startYYYYMMDDHH, string endYYYYMMDDHH, string chartType, string lan)
        {
            setlan(lan);

            if (string.IsNullOrEmpty(chartType))
            {
                chartType = ChartType.column;
            }
            User user = UserService.GetInstance().Get(userId);

            //获得报表业务逻辑类
            PlantChartService reportService = PlantChartService.GetInstance();
            //获得报表js代码
            int         monitorCode = MonitorType.PLANT_MONITORITEM_POWER_CODE;//发电量测点
            MonitorType Mt          = MonitorType.getMonitorTypeByCode(monitorCode);
            string      unit        = Mt.unit;
            string      chartName   = LanguageUtil.getDesc("CHART_DAY_POWER_CHART");
            string      reportData  = string.Empty;

            if (user != null && user.plants != null)
            {
                Cn.Loosoft.Zhisou.SunPower.Common.ChartData chartData = reportService.PlantDayChart(user.plants, chartName, startYYYYMMDDHH, endYYYYMMDDHH, chartType, unit, monitorCode, intervalTime);
                reportData = JsonUtil.convertToJson(chartData, typeof(Cn.Loosoft.Zhisou.SunPower.Common.ChartData));
            }
            else
            {
                AppError appError = new AppError(AppError.useridnoexist, Resources.SunResource.CHART_USER_DONT_EXISTED);
                reportData = JsonUtil.convertToJson(appError, typeof(AppError));
            }
            return(Content(reportData));
        }
예제 #8
0
        static void Main(string[] args)
        {
            ICourseDataAccess da       = new CourseRepository();
            IAppError         apperror = new AppError();

            ICourseService serv = new CourseService(apperror, da);
            Course         c    = new Course();

            c.CourseName = "";
            serv.AddNewCourse(c);

            if (apperror.IsValid)
            {
                Console.WriteLine("Course Added");
            }
            else
            {
                foreach (Error e in apperror.GetErrors())
                {
                    Console.WriteLine(e.ErrorDescription);
                }
            }

            Console.ReadLine();
        }
예제 #9
0
        /// <summary>
        /// 用户所有电站的年度发电量图表数据
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="chartType"></param>
        /// <returns></returns>
        public ActionResult AllPlantYearChart(int userId, string chartType, string lan)
        {
            setlan(lan);

            string reportData = string.Empty;

            if (string.IsNullOrEmpty(chartType))
            {
                chartType = ChartType.column;
            }
            User user = UserService.GetInstance().Get(userId);

            if (user != null && user.plants != null)
            {
                MonitorType energyMt = MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_ENERGY_CODE);
                string      unit     = energyMt.unit;
                Cn.Loosoft.Zhisou.SunPower.Common.ChartData chartData = PlantChartService.GetInstance().YearChartBypList(user.plants, chartType, unit);
                reportData = JsonUtil.convertToJson(chartData, typeof(Cn.Loosoft.Zhisou.SunPower.Common.ChartData));
            }
            else
            {
                AppError appError = new AppError(AppError.useridnoexist, Resources.SunResource.CHART_USER_DONT_EXISTED);
                reportData = JsonUtil.convertToJson(appError, typeof(AppError));
            }
            return(Content(reportData));
        }
예제 #10
0
        /// <summary>
        /// 电站的月天数据
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="startYYYYMMDD"></param>
        /// <param name="endYYYYMMDD"></param>
        /// <param name="chartType"></param>
        /// <returns></returns>
        public ActionResult PlantMonthDayChart(int pid, string startYYYYMMDD, string endYYYYMMDD, string chartType, string lan)
        {
            setlan(lan);

            if (string.IsNullOrEmpty(chartType))
            {
                chartType = ChartType.column;
            }
            Plant  plant      = PlantService.GetInstance().GetPlantInfoById(pid);
            string reportData = string.Empty;

            if (plant != null)
            {
                MonitorType energyMt = MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_ENERGY_CODE);
                string      unit     = energyMt.unit;
                Cn.Loosoft.Zhisou.SunPower.Common.ChartData chartData = PlantChartService.GetInstance().MMDDChartBypList(new List <Plant> {
                    plant
                }, startYYYYMMDD, endYYYYMMDD, chartType, unit);
                reportData = JsonUtil.convertToJson(chartData, typeof(Cn.Loosoft.Zhisou.SunPower.Common.ChartData));
            }
            else
            {
                AppError appError = new AppError(AppError.plantnoexist, Resources.SunResource.CHART_PLANT_DONT_EXISTED);
                reportData = JsonUtil.convertToJson(appError, typeof(AppError));
            }
            return(Content(reportData));
        }
예제 #11
0
        /// <summary>
        /// 逆变器设备的月天数据
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="startYYYYMMDD"></param>
        /// <param name="endYYYYMMDD"></param>
        /// <param name="chartType"></param>
        /// <returns></returns>
        public ActionResult DeviceMonthDayChart(int dId, string startYYYYMMDD, string endYYYYMMDD, string chartType, string lan)
        {
            setlan(lan);

            if (string.IsNullOrEmpty(chartType))
            {
                chartType = ChartType.column;
            }
            Device device     = DeviceService.GetInstance().get(dId);
            string reportData = string.Empty;

            if (device != null)
            {
                MonitorType energyMt = MonitorType.getMonitorTypeByCode(MonitorType.MIC_INVERTER_TODAYENERGY);
                string      unit     = energyMt.unit;
                Cn.Loosoft.Zhisou.SunPower.Common.ChartData chartData = DeviceChartService.GetInstance().MonthDDChartByDevice(device, 1.0F, string.Format(LanguageUtil.getDesc("DEVICEMONTHCHART_NAME"), device.fullName), startYYYYMMDD, endYYYYMMDD, chartType, unit);
                reportData = JsonUtil.convertToJson(chartData, typeof(Cn.Loosoft.Zhisou.SunPower.Common.ChartData));
            }
            else
            {
                AppError appError = new AppError(AppError.devicenoexist, Resources.SunResource.CHART_DEVICE_DONT_EXISTED);
                reportData = JsonUtil.convertToJson(appError, typeof(AppError));
            }
            return(Content(reportData));
        }
예제 #12
0
        /// <summary>
        /// 取得某个设备跨小时的某测点图表
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="startYYYYMMDD"></param>
        /// <param name="endYYYYMMDD"></param>
        /// <returns></returns>
        public ActionResult MonitorDayChart(int dId, string startYYYYMMDDHH, string endYYYYMMDDHH, string chartType, int monitorCode, string lan)
        {
            setlan(lan);

            if (string.IsNullOrEmpty(chartType))
            {
                chartType = ChartType.column;
            }
            Device device = DeviceService.GetInstance().get(dId);
            //获得报表js代码
            MonitorType energyMt   = MonitorType.getMonitorTypeByCode(monitorCode);
            string      unit       = energyMt.unit;
            string      chartName  = device.fullName + " " + LanguageUtil.getDesc("CHART_DAY_CHART");
            string      reportData = string.Empty;

            if (device != null)
            {
                Cn.Loosoft.Zhisou.SunPower.Common.ChartData chartData = DeviceChartService.GetInstance().DayChart(device, chartName, startYYYYMMDDHH, endYYYYMMDDHH, chartType, unit, monitorCode, intervalTime);
                reportData = JsonUtil.convertToJson(chartData, typeof(Cn.Loosoft.Zhisou.SunPower.Common.ChartData));
            }
            else
            {
                AppError appError = new AppError(AppError.devicenoexist, Resources.SunResource.CHART_DEVICE_DONT_EXISTED);
                reportData = JsonUtil.convertToJson(appError, typeof(AppError));
            }
            return(Content(reportData));
        }
예제 #13
0
        /// <summary>
        /// 单个设备的年月发电量图表数据
        /// </summary>
        /// <param name="userId">用户id</param>
        /// <param name="startYM">开始年月</param>
        /// <param name="endYM">截止年月</param>
        /// <param name="chartType">图表类型</param>
        /// <returns></returns>
        public ActionResult DeviceYearMMChart(int dId, string startYM, string endYM, string chartType, string lan)
        {
            setlan(lan);

            string reportData = string.Empty;

            if (string.IsNullOrEmpty(chartType))
            {
                chartType = ChartType.column;
            }
            Device device = DeviceService.GetInstance().get(dId);

            if (device != null)
            {
                MonitorType energyMt = MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_ENERGY_CODE);
                string      unit     = energyMt.unit;
                //取得用户年度发电量图表数据
                Cn.Loosoft.Zhisou.SunPower.Common.ChartData chartData = DeviceChartService.GetInstance().YearMMChartByDevice(device, 1.0F, string.Format(LanguageUtil.getDesc("DEVICEYEAR_CHART_NAME"), device.fullName), startYM, endYM, chartType, unit);
                reportData = JsonUtil.convertToJson(chartData, typeof(Cn.Loosoft.Zhisou.SunPower.Common.ChartData));
            }
            else
            {
                AppError appError = new AppError(AppError.devicenoexist, Resources.SunResource.CHART_DEVICE_DONT_EXISTED);
                reportData = JsonUtil.convertToJson(appError, typeof(AppError));
            }
            return(Content(reportData));
        }
예제 #14
0
        public async Task <BaseResponseModel> PartialEdit(int id, List <PatchModel> request)
        {
            BaseResponseModel response = new BaseResponseModel();

            AppError appError = await Load(id, response);

            if (appError != null)
            {
                foreach (var item in request)
                {
                    if (string.Compare(item.PropertyName, "solved", true) == 0)
                    {
                        appError.Solved = Convert.ToBoolean(item.Value);
                    }
                    else if (string.Compare(item.PropertyName, "deleted", true) == 0)
                    {
                        appError.Deleted = Convert.ToBoolean(item.Value);
                    }
                }

                await Database.SaveChangesAsync();

                response.Message = "App error was successfully edited!";
            }

            return(response);
        }
예제 #15
0
        private void Lv_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            var      action   = ((ListView)sender).SelectedItem;
            AppError appError = (AppError)action;

            this.Navigation.PushModalAsync(new AppErrorDetailPage(appError));
        }
예제 #16
0
        public async Task <BaseResponseModelPost> Create(AppErrorModel request)
        {
            BaseResponseModelPost response = new BaseResponseModelPost();

            AppError appError = new AppError
            {
                Deleted        = false,
                Exception      = request.Exception ?? UNKNOWN,
                Function       = request.Function ?? UNKNOWN,
                InnerException = request.InnerException ?? UNKNOWN,
                Message        = request.Message ?? UNKNOWN,
                Module         = request.Module ?? UNKNOWN,
                Solved         = false,
                Time           = request.Time ?? DateTime.Now,
                AppInfo        = request.AppInfo ?? UNKNOWN
            };

            await Database.AppError.AddAsync(appError);

            await Database.SaveChangesAsync();

            response.Id      = appError.Id;
            response.Message = "App error was successfully created!";

            return(response);
        }
예제 #17
0
    public void AddError(GameObject errorObject)
    {
        AppError appError    = null;
        AppError appNewError = GetNewAppError(errorObject);
        int      position    = FindPositionOfGameObjectError(errorObject);

        if (position == -1)
        {
            appError = appNewError;
            errors.Add(appError);
            if (errors.Count == 1)
            {
                if (OnErrorChanged != null)
                {
                    OnErrorChanged.Invoke(appError.errorName);
                }
            }
        }
        else
        {
            appError = errors[position];
            bool updated = UpdateError(appError, appNewError);
            if (updated && position == 0)
            {
                if (OnErrorChanged != null)
                {
                    OnErrorChanged.Invoke(appError.errorName);
                }
            }
        }
        Error = true;
    }
예제 #18
0
        /// <summary>
        /// 取得电站详细信息
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public ActionResult Plantinfo(int pid, string lan)
        {
            setlan(lan);

            string data;
            Plant  plant = PlantService.GetInstance().GetPlantInfoById(pid);

            if (plant == null)
            {
                AppError appError = new AppError(AppError.plantnoexist, Resources.SunResource.CHART_PLANT_DONT_EXISTED);
                data = JsonUtil.convertToJson(appError, typeof(AppError));
            }
            else
            {
                User        user     = UserService.GetInstance().Get((int)plant.userID);
                MonitorType energyMt = MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_ENERGY_CODE);
                MonitorType powerMt  = MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_POWER_CODE);
                PlantInfoVO plantvo  = new PlantInfoVO();

                plantvo.totalEnergy      = plant.upTotalEnergy;
                plantvo.todayEnergy      = plant.upTotalDayEnergy;
                plantvo.pId              = plant.id;
                plantvo.name             = plant.name;
                plantvo.co2Reduction     = plant.Reductiong;
                plantvo.revenue          = user.revenue * plantvo.totalEnergy;
                plantvo.designPower      = Math.Round(plant.design_power, 2);
                plantvo.powerUnit        = "KWp";
                plantvo.revenueUnit      = plant.currencies;
                plantvo.totalEnergyUnit  = plant.TotalEnergyUnit;
                plantvo.todayEnergyUnit  = plant.TotalDayEnergyUnit;
                plantvo.co2ReductionUnit = plant.ReductiongUnit;
                plantvo.pic              = base.getCurWebContext() + "/ufile/small/" + plant.onePic;
                plantvo.country          = plant.country;
                plantvo.city             = plant.city;
                plantvo.direction        = plant.direction;
                plantvo.installdate      = plant.installdate.ToString("yyyy-MM-dd");
                plantvo.angle            = plant.angle;
                plantvo.latitude         = plant.latitudeString;
                plantvo.location         = plant.location;
                plantvo.longitude        = plant.longitudeString;
                plantvo.street           = plant.street;
                plantvo.sunlight         = plant.Sunstrength.ToString();
                plantvo.temperature      = plant.Temperature.ToString();
                plantvo.weather          = "Sundy";
                plantvo.moduleType       = plant.module_type;
                plantvo.email            = plant.email;

                plantvo.manufacturer   = plant.manufacturer;
                plantvo.operatorPerson = plant.operater;
                plantvo.phone          = plant.phone;
                plantvo.revenueRate    = Math.Round(plant.revenueRate, 2).ToString();

                plantvo.timeZone = Cn.Loosoft.Zhisou.SunPower.Common.TimeZone.GetText(plant.timezone);
                plantvo.zipCode  = plant.postcode;

                data = JsonUtil.convertToJson(plantvo, typeof(PlantInfoVO));
            }
            return(Content(data));
        }
예제 #19
0
        public static void InsertError(Exception error, int userId = -1)
        {
            AppError e = new AppError();

            e.ExceptionMessage = error.Message;
            e.UserId           = userId;
            InsertError(e);
        }
 public string Log([FromBody] AppError Error)
 {
     // Error.User = this.GetRefUser();
     _logger.Info(Error.FormatException());
     _logger.Error(Error.FormatException());
     _logger.Warn(Error.FormatException());
     return("Logged");
 }
예제 #21
0
        private AppError SanitizarError(HttpException httpException)
        {
            AppError customError = new AppError();

            customError.Id           = Guid.NewGuid().ToString();
            customError.MessageError = httpException.Message;
            customError.Trace        = httpException.StackTrace;
            return(customError);
        }
예제 #22
0
        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            UITableViewCell cell  = tableView.DequeueReusableCell(CELL_ID);
            AppError        error = ApplicationData.Current.Errors[indexPath.Row];

            cell.TextLabel.Text       = $"{error.ClassName}.{error.Method}";
            cell.DetailTextLabel.Text = error.ErrorMessage;
            return(cell);
        }
예제 #23
0
        private async Task HandleError(HttpResponseMessage response)
        {
            var responseStr = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            AppError appError = JsonConvert.DeserializeObject <AppError>(responseStr);

            if (appError != null)
            {
                if (appError.ErrorType != null)
                {
                    var errorType    = appError.ErrorType;
                    var errorMessage = appError.ErrorMessage;

                    switch (errorType)
                    {
                    case "BAD_REQUEST":
                        throw new AndonBadRequestException(errorMessage);

                    case "INVALID_REQUEST":
                        throw new AndonInvalidRequestException(errorMessage);

                    case "RESOURCE_NOT_FOUND":
                        throw new AndonResourceNotFoundException(errorMessage);

                    case "UNAUTHORIZED_REQUEST":
                        throw new AndonUnauthorizedRequestException(errorMessage);

                    case "INTERNAL_ERROR":
                        throw new AndonInternalErrorException(errorMessage);

                    default:
                        throw new AndonAppException(errorMessage);
                    }
                }
                else if (appError.Status.HasValue)
                {
                    var status       = appError.Status;
                    var errorMessage = appError.Message;

                    if (status == 401)
                    {
                        throw new AndonUnauthorizedRequestException(errorMessage);
                    }
                    else if (status >= 400 && status < 500)
                    {
                        throw new AndonBadRequestException(errorMessage);
                    }
                    else
                    {
                        throw new AndonInternalErrorException(errorMessage);
                    }
                }
            }

            throw new AndonAppException($"Status {response.StatusCode}: {responseStr}");
        }
예제 #24
0
 private bool UpdateError(AppError appError, AppError appNewError)
 {
     if (appError.errorName != appNewError.errorName)
     {
         appError.errorName    = appNewError.errorName;
         appError.errorMessage = appNewError.errorMessage;
         return(true);
     }
     return(false);
 }
예제 #25
0
        public void SendError(string code)
        {
            AppError appError = Pool.Get <AppError>();

            appError.error = code;
            AppResponse appResponse = Pool.Get <AppResponse>();

            appResponse.error = appError;
            Send(appResponse);
        }
예제 #26
0
        public static Error Loop2dSound(int _track)
        {
            AudioSource source = null;

            if (!pool2D.TryGetValue(_track, out source))
            {
                return(AppError.NewAccessErr("2D Audio Source {0} is not exists", _track));
            }
            source.loop = true;
            return(AppError.OK);
        }
예제 #27
0
        /// <summary>
        /// Handles an exception that occurs. First, the error is recorded. Certain types, such as security exceptions and directory permission
        /// errors, are are rendered to the user with user-friendly text. For other exceptions, a generic message is displayed, unless
        /// the system is configured to show detailed error messages (showErrorDetails="true" in galleryserverpro.config), in which
        /// case full details about the exception is displayed. If the user has disabled the exception handler
        /// (enableExceptionHandler="false"), then the error is recorded but no other action is taken. This allows
        /// global error handling in web.config or global.asax to deal with it.
        /// </summary>
        /// <param name="ex">The exception.</param>
        public static void HandleGalleryException(Exception ex)
        {
            try
            {
                LogError(ex);
            }
            catch (Exception errHandlingEx)
            {
                if (!ex.Data.Contains("Error Handling Exception"))
                {
                    ex.Data.Add("Error Handling Exception", String.Format("The following error occurred while handling the exception: {0} - {1} Stack trace: {2}", errHandlingEx.GetType(), errHandlingEx.Message, errHandlingEx.StackTrace));
                }
            }

            // If the error is security related, go to a special page that offers a friendly error message.
            if (ex is ErrorHandler.CustomExceptions.GallerySecurityException)
            {
                // User is not allowed to access the requested page. Redirect to home page.
                HttpContext.Current.Server.ClearError();
                Util.Redirect(PageId.album);
            }
            else if (ex is ErrorHandler.CustomExceptions.CannotWriteToDirectoryException)
            {
                // Gallery Server cannot write to a directory. Application startup code checks for this condition,
                // so we'll get here most often when Gallery Server is first configured and the required permissions were not given.
                // Provide friendly, customized message to help the user resolve the situation.
                HttpContext.Current.Server.ClearError();
                HttpContext.Current.Items["CurrentException"] = ex;
                Util.Transfer(PageId.error_cannotwritetodirectory);
            }
            else if (ex is ErrorHandler.CustomExceptions.InvalidLicenseException)
            {
                // Gallery Server has determined the current request cannot be completed because it would violate the licensing rules.
                // Redirect to a friendly page to explain the situation.
                HttpContext.Current.Server.ClearError();
                HttpContext.Current.Items["CurrentException"] = ex;
                Util.Transfer(PageId.error_invalidlicense);
            }
            else
            {
                // An unexpected exception is happening.
                // If Gallery Server's exception handling is enabled, clear the error and display the relevant error message.
                // Otherwise, don't do anything, which lets it propogate up the stack, thus allowing for error handling code in
                // global.asax and/or web.config (e.g. <customErrors...> or some other global error handler) to handle it.
                if (ConfigManager.GetGalleryServerProConfigSection().Core.EnableExceptionHandler)
                {
                    // Redirect to generic error page.
                    HttpContext.Current.Server.ClearError();
                    HttpContext.Current.Items["CurrentAppError"] = AppError.Create(ex);
                    Util.Transfer(PageId.error_generic);
                }
            }
        }
예제 #28
0
        public async Task <AppError> Load(int id, BaseResponseModel response, bool tracking = true, bool lazy = true)
        {
            AppError appError = await Database.AppError.FirstOrDefaultAsync(a => a.Id == id);

            if (appError == null)
            {
                response.Success = false;
                response.Message = "Unknown app error!";
            }

            return(appError);
        }
예제 #29
0
        public static Error Stop2dSound(int _track)
        {
            AudioSource source = null;

            if (!pool2D.TryGetValue(_track, out source))
            {
                return(AppError.NewAccessErr("2D Audio Source {0} is not exists", _track));
            }
            source.Stop();
            source.gameObject.SetActive(false);
            return(AppError.OK);
        }
예제 #30
0
        public static Error Play2dSound(int _track, AudioClip _clip)
        {
            AudioSource source = null;

            if (!pool2D.TryGetValue(_track, out source))
            {
                return(AppError.NewAccessErr("2D Audio Source {0} is not exists", _track));
            }
            source.gameObject.SetActive(true);
            source.clip = _clip;
            source.Play();
            return(AppError.OK);
        }
예제 #31
0
 public static void LogError(string uiSite, string moduleId, string funcCode, AppError level, Exception ex)
 {
     LogError(uiSite, moduleId, funcCode, level, -1, ex, null, null);
 }
예제 #32
0
 private static void LogError(string uiSite, string moduleId, string funcCode, AppError level, int errCode, string ex, string msg, string contextInfo)
 {
     var str = string.Empty;
     var absoluteUri = string.Empty;
     if (HttpContext.Current != null)
     {
         str = HttpContext.Current.Request.Url.ToString();
         Uri urlReferrer = HttpContext.Current.Request.UrlReferrer;
         if (urlReferrer != null)
         {
             absoluteUri = urlReferrer.AbsoluteUri;
             if (!string.IsNullOrEmpty(absoluteUri))
             {
                 ex = "引用URL:" + absoluteUri + "|" + ex;
             }
         }
         ex = "访问URL:" + str + "|" + ex;
     }
     var builder = new StringBuilder();
     if (uiSite != null)
     {
         if (errCode >= 0)
         {
             builder.AppendFormat("Time={0}; LogLevel={1}; UISite={2}; ModuleID={3}; FuncCode={4}; ErrorCode={5}; ", new object[] { DateTime.Now.ToString(), level.ToString(), uiSite, moduleId, funcCode, errCode });
         }
         else
         {
             builder.AppendFormat("Time={0}; LogLevel={1}; UISite={2}; ModuleID={3}; FuncCode={4}; ", new object[] { DateTime.Now.ToString(), level.ToString(), uiSite, moduleId, funcCode });
         }
     }
     else if (errCode >= 0)
     {
         builder.AppendFormat("Time={0}; LogLevel={1}; ModuleID={2}; FuncCode={3}; ErrorCode={4}; ", new object[] { DateTime.Now.ToString(), level.ToString(), moduleId, funcCode, errCode });
     }
     else
     {
         builder.AppendFormat("Time={0}; LogLevel={1}; ModuleID={2}; FuncCode={3}; ", new object[] { DateTime.Now.ToString(), level.ToString(), moduleId, funcCode });
     }
     if (!string.IsNullOrEmpty(contextInfo))
     {
         builder.AppendLine();
         builder.Append("ContextInfo=" + contextInfo);
     }
     if (!string.IsNullOrEmpty(msg))
     {
         builder.AppendLine();
         builder.Append("Message=" + msg);
     }
     if (ex != null)
     {
         builder.AppendLine();
         builder.AppendLine("Exception=" + ex);
         builder.AppendLine(LogPosition());
     }
     if (logDataError.IsErrorEnabled)
     {
         logDataError.Error(builder.ToString());
     }
 }
예제 #33
0
 private static void LogError(string uiSite, string moduleId, string funcCode, AppError level, int errCode, Exception ex, string msg, string contextInfo)
 {
     LogError(uiSite, moduleId, funcCode, level, errCode, ex.ToString(), msg, contextInfo);
 }