コード例 #1
0
        private async Task<OpObject> Execute(Func<Task> a, IsolatedContext IsoContext)
        {
            try
            {
                /* Convert session -> guid? */
                if (IsoContext.SessionId != "0")
                {
                    using (MaintienceRepository MainRepo = new MaintienceRepository())
                    {
                        String Result = await MainRepo.IsSessionValid(IsoContext.SessionId);

                        /* Sanity */
                        if (Result == "0")
                            return new OpObject(StatusCode.InvalidSession, "SessionId was invalid");
                        else
                            IsoContext.uGuid = Result;
                    }
                }

                /* Run function */
                await a.Invoke();

                /* Done */
                return IsoContext.RetObj;
            }
            catch (DbEntityValidationException Ex)
            {
                /* Get all validation errors */
                var ErrMsgs = Ex.EntityValidationErrors
                        .SelectMany(x => x.ValidationErrors)
                        .Select(x => x.ErrorMessage);

                /* Combine them */
                String FullErrMsgs = String.Join("; ", ErrMsgs);

                /* Create a new exception message */
                String ExMsg = String.Concat(Ex.Message, " The validation errors are: ", FullErrMsgs);

                /* Return it */
                return new OpObject(StatusCode.InvalidParameters, ExMsg);
            }
            catch (OptimisticConcurrencyException Ex)
            {
                /* Return a try-again */
                return new OpObject(StatusCode.TryAgain, Ex.ToString());
            }
            catch (DbUpdateException Ex)
            {
                return new OpObject(StatusCode.TryAgain, Ex.ToString());
            }
            catch (Exception Ex)
            {
                /* Invalid Params? */
                if (Ex is NullReferenceException ||
                    Ex is ArgumentNullException ||
                    Ex is ArgumentException ||
                    Ex is ArgumentOutOfRangeException)
                {
                    /* Return a arg-exception */
                    return new OpObject(StatusCode.InvalidParameters, Ex.ToString());
                }

                /* Return fault */
                return new OpObject(StatusCode.FuckedUp, Ex.ToString());
            }
        }
コード例 #2
0
        /* Validate SessionId */
        public async Task<bool> ValidateSessionId(String SessionId)
        {
            using (MaintienceRepository MainRepo = new MaintienceRepository())
            {
                String Result = await MainRepo.IsSessionValid(SessionId);

                /* Sanity */
                return (Result == "0") ? false : true;
            }
        }