Пример #1
0
 public void TestToString()
 {
     CheckResult result1 = new CheckResult() { Index = 0, Success = true };
     Assert.AreEqual("Success = True, Index = 0", result1.ToString(), "The wrong string representation was returned."); // implicit conversion
     CheckResult result2 = new CheckResult() { Index = 1, Success = false };
     Assert.AreEqual("Success = False, Index = 1", result2.ToString(), "The wrong string representation was returned."); // implicit conversion
 }
Пример #2
0
        /// <summary>
        /// 反馈消息至PLC
        /// </summary>
        /// <param name="_session"></param>
        /// <param name="_transData"></param>
        /// <param name="checkR"></param>
        public static void SendMsg(MesSession _session, TransData _transData, CheckResult checkR)
        {
            _transData.Status = checkR.ToString();
            string msg = GlobalData.ToTranString(_transData);

            _session.Send(msg);
            LogInfo log = new SocketService.LogInfo(_session, LogLevel.Info, GlobalData.Pre_Send + msg);
        }
        /// <summary>
        /// Check if a permission is granted and request a permission if it's not granted
        /// </summary>
        /// <param name="privilege">privilege name</param>
        /// <returns>bool</returns>
        public async Task <bool> CheckAndRequestPermission(string privilege)
        {
            try
            {
                // Gets the status of a privacy privilege permission.
                CheckResult result = PrivacyPrivilegeManager.CheckPermission(privilege);
                Log.Debug(Utility.LOG_TAG, "State: " + result.ToString());
                switch (result)
                {
                case CheckResult.Allow:
                    // Permission has already been granted
                    // Privilege can be used
                    return(true);

                case CheckResult.Deny:
                    // Privilege can't be used
                    Log.Debug(Utility.LOG_TAG, "In this case, " + privilege + " privilege is not available until the user changes the permission state from the Settings application.");
                    return(false);

                case CheckResult.Ask:
                    // Permission is not granted so we need to request the permission
                    PrivacyPrivilegeManager.ResponseContext context;
                    PrivacyPrivilegeManager.GetResponseContext(privilege).TryGetTarget(out context);
                    if (context == null)
                    {
                        return(false);
                    }

                    tcs = new TaskCompletionSource <bool>();
                    context.ResponseFetched += PPMResponseHandler;
                    // Request a permission
                    // Calling it brings up a system dialog that an app user can decide to approve or deny it.
                    PrivacyPrivilegeManager.RequestPermission(privilege);
                    return(await tcs.Task);

                default:
                    return(false);
                }
            }
            catch (Exception e)
            {
                // Handle exception
                Log.Error(Utility.LOG_TAG, "An error occurred. : " + e.Message);
                return(false);
            }
        }
Пример #4
0
        public async Task <bool> CheckAndRequestPermission(string privilege)
        {
            try
            {
                CheckResult result = PrivacyPrivilegeManager.CheckPermission(privilege);
                Log.Debug(Utility.LOG_TAG, "State: " + result.ToString());
                switch (result)
                {
                case CheckResult.Allow:
                    return(true);

                case CheckResult.Deny:
                    Log.Debug(Utility.LOG_TAG, "In this case, health data is not available until the user changes the permission state from the Settings application.");
                    return(false);

                case CheckResult.Ask:
                    // Request permission to User
                    PrivacyPrivilegeManager.ResponseContext context;
                    PrivacyPrivilegeManager.GetResponseContext(privilege).TryGetTarget(out context);
                    if (context == null)
                    {
                        return(false);
                    }
                    tcs = new TaskCompletionSource <bool>();
                    context.ResponseFetched += PPMResponseHandler;
                    PrivacyPrivilegeManager.RequestPermission(privilege);
                    return(await tcs.Task);

                default:
                    return(false);
                }
            }
            catch (Exception e)
            {
                // Handle exception
                Log.Error(Utility.LOG_TAG, "An error occurred. : " + e.Message);
                return(false);
            }
        }
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            bool ignoreValidate = (actionContext.ActionDescriptor.GetCustomAttributes <IgnoreValidateAttribute>().Count > 0);

            HttpRequest request = HttpContext.Current.Request;

            SpecialLog(request);
            ApiLogModel log = BuildApiLog(request);

            log.Controller = actionContext.ControllerContext.ControllerDescriptor.ControllerName;
            log.Action     = actionContext.ActionDescriptor.ActionName;
            CheckResult result = ignoreValidate ? CheckResult.FROM_ZJB : Check(request);

            log.ValidationResult = result.ToString();
            if (result == CheckResult.INVALID_HASH || result == CheckResult.INVALID_USERAGENT)
            {
                apiBll.AddApiLog(log);
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Forbidden,
                                                                              new ApiResponse(Metas.INVALID_PERMISSION, null));
                return;
            }
            apiBll.AddApiLog(log);
        }
Пример #6
0
 /// <summary>
 /// Changes the reporting level of the given error to <paramref name="value"/> instead of it's <see cref="ErrorCode.DefaultTreatment"/>
 /// </summary>
 /// <param name="errorCode"></param>
 /// <param name="value"></param>
 public static void SetErrorReportingLevelFor(ErrorCode errorCode, CheckResult value)
 {
     AppSettings.AddOrUpdateValue("EC_" + errorCode.Code, value.ToString());
 }
Пример #7
0
 private void RenderCheckResult(StringBuilder sb)
 {
     AppendField(sb, "Check results", CheckResult?.ToString());
 }