예제 #1
0
 public ServiceResponse <string> GetUserNameFromAuthToken(string auth)
 {
     return(AuthResultWrapper(auth, () =>
     {
         var TR = SecurityService.GetUserNameFromAuthToken(auth);
         if (TR == null)
         {
             ExecMsgScope.RaiseMsg(ExecMsgSeverity.Error, SysMsgCode.AuthTokenNotValid);
         }
         return TR;
     }));
 }
예제 #2
0
 public ServiceResponse <string> LoginByAuthToken(string auth, int ttlSeconds)
 {
     return(AuthResultWrapper(auth, () =>
     {
         var TR = SecurityService.LoginByAuthToken(auth, (ttlSeconds <= 0) ? TimeSpan.Zero : TimeSpan.FromSeconds(ttlSeconds));
         if (TR == null)
         {
             ExecMsgScope.RaiseMsg(ExecMsgSeverity.Error, SysMsgCode.InvalidLogin);
         }
         return TR.ToString();
     }));
 }
예제 #3
0
 public ServiceResponse <string> LoginByUsernamePassword(string username, string password, int ttlSeconds)
 {
     return(ResultWrapper(() =>
     {
         //UserBase UB = new UserBaseService().LoginByUserNamePassword(username, password);
         //if ( UB == null )
         //    ExecMsgScope.RaiseMsg(ExecMsgSeverity.Error, SysMsgCode.InvalidLogin);
         var TR = SecurityService.LoginByUserNamePassword(username, password, (ttlSeconds <= 0) ? TimeSpan.Zero : TimeSpan.FromSeconds(ttlSeconds));
         if (TR == null)
         {
             ExecMsgScope.RaiseMsg(ExecMsgSeverity.Error, SysMsgCode.InvalidLogin);
         }
         return TR.ToString();
     }));
 }
예제 #4
0
        public static void AuthWrapper(string auth, Action toExecute)
        {
            var Token = SecurityService.CheckAuthToken(auth);

            if (Token == null)
            {
                ExecMsgScope.RaiseMsg(ExecMsgSeverity.Error, SysMsgCode.AuthTokenNotValid);
            }
            // Throw this token info into the context so logging can include it if needed.
            // Using the item [] instead of Add() method will replace an existing item in the Dictionary, where
            // the Add method throws an exception if there is already an item with the same name in the Dictionary.
            EXSLogger.ExtraEnvironmentInfo["UserName"]   = Token.UserName;
            EXSLogger.ExtraEnvironmentInfo["ExpDateUTC"] = Token.ExpiresUTC;
            Token.ExecuteAsUser(toExecute);
        }
예제 #5
0
        /// <summary>
        /// This method runs a delegate, catches any ExecMsgs raised,
        /// and returns the messages.
        /// </summary>
        /// <param name="toRun">The action to run, wrapped in the exception
        /// handling pattern.</param>
        /// <param name="reThrowInternal">If true (the default), internal errors
        /// will be rethrown, causing the application to abort to the "Our
        /// Apologies" page.  If false, internal errors are not rethrown, and
        /// instead are wrapped in an ExecMsg with the unique Exception ID,
        /// to be used by a developer to track down the error.</param>
        /// <remarks>WARNING: This method RETURNS ExecMsgs.  In general, ExecMsgs should
        /// NOT be returned, but instead should be raised via ExecMsgScope.RaiseMsg,
        /// and caught or captured via ExecMsgScope.ExtractMessages.  Checking a
        /// return value for errors is far too easy for a developer to forget to do,
        /// and the RaiseMsg pattern ensures that this does not happen.  This method
        /// only exists because a standard way of catching various messages, and
        /// handling internal messages, is needed.</remarks>
        public static IEnumerable <ExecMsg> TrapMsgs(Action toRun, bool reThrowInternal = true)
        {
            HashSet <ExecMsg> Msgs = new HashSet <ExecMsg>();

            using (new ExecMsgScope())
            {
                try
                {
                    ExecMsgScope.ConvertTaggedMsgs(toRun);
                }
                catch (ExecMsgException ex)
                {
                    //ex.Log();
                    Msgs.UnionWith(ex.ExecMsgs);
                }
                catch (ThreadAbortException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    ex.Log();
                    Msgs.Add(new ExecMsg(ExecMsgSeverity.Error, SysMsgCode.InternalError, ex.Message));
                    Exception e = ex.InnerException;
                    while (e != null)
                    {
                        Msgs.Add(new ExecMsg(ExecMsgSeverity.Error, SysMsgCode.InternalError, e.Message));
                        e = e.InnerException;
                    }
                    if (reThrowInternal)
                    {
                        throw;
                    }
                }
                finally
                {
                    Msgs.UnionWith(ExecMsgScope.ExtractMessages());
                }
            }
            return(Msgs);
        }
예제 #6
0
        //public string FormatDataToXml(DataSet ds)
        //{
        //    string Xml = "";
        //    if ( ds.Tables.Count > 0 )
        //        if ( ds.Tables[0].Rows.Count > 0 )
        //            Xml = ds.GetXml();
        //    return Xml;
        //}
        #endregion

        #region RaiseEXSMessages
        /// <summary>
        /// Converts the ExecutionMessageCollection into ExecMsg objects, then uses
        /// ExecMsgScope.RaiseMsg to raise the messages.
        /// </summary>
        /// <param name="msgs">List of EXS Messages.</param>
        protected void RaiseEXSMessages(ExecutionMessageCollection msgs)
        {
            var Errors = LogEXSMessages(msgs);

            ExecMsgScope.RaiseMsg(Errors);
        }