Exemplo n.º 1
0
 public void configure(int controllerID, ControllerBase controller, ModelBase model, ViewBase view)
 {
     addControllerRoute(new RouteBase(controllerID, controller));
     controller.configure(view, model);
     model.configure();
     view.configure(model);
 }
Exemplo n.º 2
0
 public PageView(string viewName, ControllerBase controller, ControllerInfo controllerInfo)
 {
     this.Context = HttpContext.Current;
     this.ViewName = viewName;
     this.Controller = controller;
     this.ControllerInfo = controllerInfo;
 }
Exemplo n.º 3
0
 public void RegisterController(OperationCode opCode,ControllerBase controll)
 {
     if (!controllers.ContainsKey((byte)opCode))
     {
         controllers.Add((byte)opCode, controll);
     }
 }
Exemplo n.º 4
0
        protected override void Initialize(ControllerBase controller)
        {
            _controller = controller as TargetedController<Family>;

            if (_controller == null)
                throw new ArgumentException("Controller was not a TargetedController<Family>");
        }
Exemplo n.º 5
0
        public void Invoke(ControllerBase controller)
        {
            if (_needAuthentication && !controller.IsAuthenticated)
                throw new WebSocketRequestException("Please authenticate to invoke this action");

            _invokeAction(controller);
        }
 public static IEnumerable<EduProgramProfileInfo> WithEduProgramProfileForms (
     this IEnumerable<EduProgramProfileInfo> eduProgramProfiles, ControllerBase controller)
 {
     foreach (var eduProgramProfile in eduProgramProfiles) {
         yield return eduProgramProfile.WithEduProgramProfileForms (controller);
     }
 }
        public static EduProgramProfileFormInfo WithEduForm (
            this EduProgramProfileFormInfo eduProgramProfileForm, ControllerBase controller)
        {
            eduProgramProfileForm.EduForm = controller.Get<EduFormInfo> (eduProgramProfileForm.EduFormID);

            return eduProgramProfileForm;
        }
        public static EduProgramProfileInfo WithEduProgram (
            this EduProgramProfileInfo eduProfile, ControllerBase controller)
        {
            eduProfile.EduProgram = controller.Get<EduProgramInfo> (eduProfile.EduProgramID);

            return eduProfile;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Standard test init actions
        /// </summary>
        protected void TestInitialize(ControllerBase controller, BuildMockRouteFunc routeFunc)
        {
            // mock the UrlHelper
            var urlMock = this.MockUrlHelper(controller.GetType(), routeFunc);
            controller.Url = urlMock.Object;

            AssertRand.AssertionCounter = 0;
        }
 public static IEnumerable<EduProgramProfileInfo> WithEduLevel (
     this IEnumerable<EduProgramProfileInfo> eduProgramProfiles, ControllerBase controller)
 {
     foreach (var eduProgramProfile in eduProgramProfiles) {
         eduProgramProfile.EduProgram.WithEduLevel (controller);
         yield return eduProgramProfile;
     }
 }
Exemplo n.º 11
0
 //用于注册Controller的方法
 public void RegisterController(OperationCode opCode, ControllerBase controller)
 {
     controllers.Add((byte) opCode, controller);
     //if (!controllers.ContainsKey((byte) opCode))
     //{
     //    controllers.Add((byte) opCode, controller);
     //}
 }
Exemplo n.º 12
0
        internal static AsyncManager GetAsyncManager(ControllerBase controller) {
            IAsyncManagerContainer helperContainer = controller as IAsyncManagerContainer;
            if (helperContainer == null) {
                throw Error.AsyncCommon_ControllerMustImplementIAsyncManagerContainer(controller.GetType());
            }

            return helperContainer.AsyncManager;
        }
Exemplo n.º 13
0
        // HelperSetup
        public static void HelperSetup( ControllerBase target )
        {
            myTarget = target;

            receiverEnable = Resources.LoadAssetAtPath<Texture>( "Assets/TouchControlsKit/Base/Resources/icons/receiverEnable.png" );
            receiverDisable = Resources.LoadAssetAtPath<Texture>( "Assets/TouchControlsKit/Base/Resources/icons/receiverDisable.png" );
            receiverRemove = Resources.LoadAssetAtPath<Texture>( "Assets/TouchControlsKit/Base/Resources/icons/receiverRemove.png" );
        }
		internal static AsyncManager GetAsyncManager(ControllerBase controller)
		{
			IAsyncManagerContainer container = (controller as IAsyncManagerContainer);
			Precondition.Require(container, () => Error
				.ControllerMustImplementAsyncManagerContainer(controller.GetType()));

			return container.AsyncManager;
		}
        public static IEnumerable<IDocument> WithDocumentType (this IEnumerable<IDocument> documents, ControllerBase controller)
        {
            foreach (var document in documents)
            {
                document.WithDocumentType (controller);
            }

            return documents;
        }
        public static IDocument WithDocumentType (this IDocument document, ControllerBase controller)
        {
            if (document.DocumentTypeID != null)
            {
                document.DocumentType = controller.Get<DocumentTypeInfo> (document.DocumentTypeID.Value);
            }

            return document;
        }
        public static IEnumerable<EduProgramInfo> WithDocuments (this IEnumerable<EduProgramInfo> eduPrograms, ControllerBase controller)
        {
            foreach (var eduProgram in eduPrograms)
            {
                eduProgram.WithDocuments (controller);
            }

            return eduPrograms;
        }
        public static EduProgramInfo WithDocuments (this EduProgramInfo eduProgram, ControllerBase controller)
        {
            eduProgram.Documents = controller.GetObjects<DocumentInfo> (
                "WHERE [ItemID] = @0", "EduProgramID=" + eduProgram.EduProgramID).ToList ();

            eduProgram.Documents.WithDocumentType (controller);

            return eduProgram;
        }
Exemplo n.º 19
0
        // HelperSetup
        public static void HelperSetup( ControllerBase target, SerializedObject serObject )
        {
            myTarget = target;
            serializedObject = serObject;

            downEventProp = serializedObject.FindProperty( "downEvent" );
            pressEventProp = serializedObject.FindProperty( "pressEvent" );
            upEventProp = serializedObject.FindProperty( "upEvent" );
            clickEventProp = serializedObject.FindProperty( "clickEvent" );
        }
        public static IEnumerable<EduProgramProfileFormInfo> WithEduForms (
            this IEnumerable<EduProgramProfileFormInfo> eduProgramProfileForms, ControllerBase controller)
        {
            foreach (var eduProgramProfileForm in eduProgramProfileForms)
            {
                eduProgramProfileForm.WithEduForm (controller);
            }

            return eduProgramProfileForms;
        }
        public static EduProgramProfileInfo WithEduProgramProfileForms (
            this EduProgramProfileInfo eduProfile, ControllerBase controller)
        {
            eduProfile.EduProgramProfileForms = controller.GetObjects<EduProgramProfileFormInfo> (
                "WHERE [EduProgramProfileID] = @0", eduProfile.EduProgramProfileID)
                .WithEduForms (controller)
                .Cast<IEduProgramProfileForm> ()
                .ToList ();

            return eduProfile;
        }
        public static IEnumerable<EduProgramProfileInfo> WithEduPrograms (
            this IEnumerable<EduProgramProfileInfo> eduProgramProfiles, ControllerBase controller)
        {
            var eduPrograms = controller.GetObjects<EduProgramInfo> ();

            return eduProgramProfiles.Join (eduPrograms, epp => epp.EduProgramID, ep => ep.EduProgramID, 
                delegate (EduProgramProfileInfo epp, EduProgramInfo ep) {
                    epp.EduProgram = ep;
                    return epp;
                }
            );
        }
Exemplo n.º 23
0
        public void BeforeAction( ControllerBase controller )
        {
            MvcContext ctx = controller.ctx;

            IEntity obj = ndb.findById( _dataType, ctx.route.id );
            if (obj == null) {
                ctx.utils.endMsg( lang.get( "exDataNotFound" ), HttpStatus.NotFound_404 );
                return;
            }

            ctx.SetItem( "__currentRouteIdData", obj );
        }
Exemplo n.º 24
0
 /// <summary>
 /// 判断用户是否有权限
 /// </summary>
 public static bool HasRights(ControllerBase controller, string action)
 {
     if (!IsLogin) return false;
     if (LoginUser.UserName == "admin") return true;
     UserDal userDal = new UserDal();
     List<FunctionModel> functionList = userDal.GetFunctionListByUserName(LoginUser.UserName);
     if (functionList.Exists(item => item.Controller == controller.GetType().FullName && item.Action == action))
     {
         return true;
     }
     return false;
 }
Exemplo n.º 25
0
        public void InvokeAction(ControllerBase controller, string actionName)
        {
            var actionCollection = _controllerCollection.GetActionCollection(controller.GetType());
            var action = actionCollection.GetAction(actionName);

            if (action == null)
            {
                throw new WebSocketRequestException(string.Format(
                    "Can't find action {0} in controller {1}",
                    actionName, controller.GetType().FullName));
            }

            action.Invoke(controller);
        }
Exemplo n.º 26
0
        public static void runAction( MvcContext ctx, ControllerBase controller, MethodInfo actionMethod, aAction run, Boolean isLayout )
        {
            if (isLayout) {
                run();
                return;
            }

            List<IActionFilter> filters = controller.utils.getActionFilters( actionMethod );
            //filters.Insert( 0, new CacheUrlAttribute() ); // Ĭ��������ַ������ͨ���޸����ý��л���

            if (filters.Count == 0) {
                run();
                return;
            }

            for (int i = 0; i < filters.Count; i++) {

                filters[i].BeforeAction( controller );

                if (ctx.utils.isEnd()) {
                    return;
                }

            }

            try {
                if (controller.utils.IsRunAction()) {
                    run();
                }
            }
            catch (Exception ex) {
                ctx.utils.setException( ex );
            }
            finally {

                for (int i = filters.Count - 1; i >= 0; i--) {

                    filters[i].AfterAction( controller );

                    if (ctx.utils.isEnd()) {
                        break;
                    }

                }

                Exception ex = ctx.utils.getException();
                if (ex != null) throw ctx.utils.getException();
            }
        }
 public void AfterAction( ControllerBase controller )
 {
     if (controller.ctx.utils.getException() == null) {
         DbContext.commitAll();
     }
     else {
         try {
             DbContext.rollbackAll();
         }
         catch (Exception ex) {
             logger.Error( "data operation ( rollbackAll ):" + ex.StackTrace );
             throw ex;
         }
         finally {
             logger.Info( "DbTransaction : rollbackAll" );
             DbContext.closeConnectionAll();
         }
     }
 }
Exemplo n.º 28
0
        /// <summary>
        /// 运行某 action
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static String Run( ControllerBase thisController, aAction action )
        {
            ControllerBase targetController = action.Target as ControllerBase;

            // 如果是当前controller,则直接调用;因为必须允许内部成员变量共享
            if (Object.ReferenceEquals( thisController, targetController )) {
                Template originalView = thisController.utils.getCurrentView();
                thisController.view( action.Method.Name );
                action();
                String result = thisController.utils.getActionResult();
                thisController.utils.setCurrentView( originalView );

                return result;
            }
            else {
                ControllerFactory.InjectController( targetController, thisController.ctx );
                targetController.view( action.Method.Name );
                action();
                return targetController.utils.getActionResult();
            }
        }
Exemplo n.º 29
0
 public static bool HasClaim(this ControllerBase controller, string type, string value)
 {
     return(controller.HasClaim(new Claim(type, value)));
 }
Exemplo n.º 30
0
        public static bool HasClaim(this ControllerBase controller, Claim claim)
        {
            var claims = controller.HttpContext.User.Claims;

            return(claims.Any(c => c.Type == claim.Type && c.Value == claim.Value));
        }
Exemplo n.º 31
0
 /// <summary>
 /// Render view to string
 /// </summary>
 /// <param name="controller"></param>
 /// <param name="viewName">View name</param>
 /// <param name="model">Model</param>
 /// <returns>Result</returns>
 public static string RenderViewToString(this ControllerBase controller, string viewName, string masterName)
 {
     return(RenderViewToString(controller, viewName, masterName, null));
 }
Exemplo n.º 32
0
 /// <summary>
 /// Render partial view to string
 /// </summary>
 /// <param name="controller"></param>
 /// <returns>Result</returns>
 public static string RenderPartialViewToString(this ControllerBase controller)
 {
     return(RenderPartialViewToString(controller, null, null));
 }
Exemplo n.º 33
0
 /// <summary>
 /// Render partial view to string
 /// </summary>
 /// <param name="controller"></param>
 /// <param name="viewName">View name</param>
 /// <returns>Result</returns>
 public static string RenderPartialViewToString(this ControllerBase controller, string viewName)
 {
     return(RenderPartialViewToString(controller, viewName, null));
 }
Exemplo n.º 34
0
 /// <summary>
 /// Render view to string
 /// </summary>
 /// <param name="model">Model</param>
 /// <returns>Result</returns>
 public static string RenderViewToString(this ControllerBase controller, object model)
 {
     return(RenderViewToString(controller, null, null, model));
 }
 public void BeforeAction( ControllerBase controller )
 {
     DbContext.beginAndMarkTransactionAll();
 }
Exemplo n.º 36
0
    public static RBACStatus Login(this ControllerBase controller, LoginViewModel model, ApplicationUserManager userMngr, ApplicationSignInManager signInMngr, out List <string> _errors)
    {
        RBACStatus _retVal = RBACStatus.Failure;

        _errors = new List <string>();
        try
        {
            var user = userMngr.FindByName(model.UserName);
            if (user != null)
            {
                var validCredentials = userMngr.Find(model.UserName, model.Password);
                if (userMngr.IsLockedOut(user.Id))
                {
                    _errors.Add(string.Format(c_AccountLockout, GetConfigSettingAsDouble(cKey_AccountLockoutTimeSpan)));
                    return(RBACStatus.LockedOut);
                }
                else if (userMngr.GetLockoutEnabled(user.Id) && validCredentials == null)
                {
                    userMngr.AccessFailed(user.Id);
                    if (userMngr.IsLockedOut(user.Id))
                    {
                        _errors.Add(string.Format(c_AccountLockout, GetConfigSettingAsDouble(cKey_AccountLockoutTimeSpan)));
                        return(RBACStatus.LockedOut);
                    }
                    else
                    {
                        int _attemptsLeftB4Lockout = (GetConfigSettingAsInt(cKey_MaxFailedAccessAttemptsBeforeLockout) - userMngr.GetAccessFailedCount(user.Id));
                        _errors.Add(string.Format(c_InvalidCredentials, _attemptsLeftB4Lockout));
                        return(_retVal);
                    }
                }
                else if (validCredentials == null)
                {
                    _errors.Add(c_InvalidLogin);
                    return(_retVal);
                }
                else
                {
                    //Valid credentials entered, we need to check whether email verification is required...
                    bool   IsAccountVerificationRequired = GetConfigSettingAsBool(cKey_AccountVerificationRequired);
                    bool   Is2FAEnabled = GetConfigSettingAsBool(cKey_2FAEnabled);
                    string DeviceType   = GetConfigSetting(cKey_2FADeviceType);

                    if ((IsAccountVerificationRequired && DeviceType == c_EmailCode) || (Is2FAEnabled && DeviceType == c_EmailCode))
                    {
                        //Check if email verification has been confirmed!
                        if (!userMngr.IsEmailConfirmed(user.Id))
                        {
                            //Display error message on login page, take no further action...
                            _errors.Add(c_AccountEmailUnconfirmed);
                            return(RBACStatus.EmailUnconfirmed);
                        }
                    }
                    //else if (Is2FAEnabled && DeviceType == c_PhoneCode)
                    else if ((IsAccountVerificationRequired && DeviceType == c_PhoneCode) || (Is2FAEnabled && DeviceType == c_PhoneCode))
                    {
                        if (!userMngr.IsPhoneNumberConfirmed(user.Id))
                        {
                            _errors.Add(c_AccountPhoneNumberUnconfirmed);
                            return(RBACStatus.PhoneNumberUnconfirmed);
                        }
                    }

                    bool _userLockoutEnabled = GetConfigSettingAsBool(cKey_UserLockoutEnabled);

                    //Before we signin, check that our 2FAEnabled config setting agrees with the database setting for this user...
                    if (Is2FAEnabled != userMngr.GetTwoFactorEnabled(user.Id))
                    {
                        userMngr.SetTwoFactorEnabled(user.Id, Is2FAEnabled);
                    }

                    _retVal = (RBACStatus)signInMngr.PasswordSignIn(model.UserName, model.Password, model.RememberMe, shouldLockout: _userLockoutEnabled);
                    switch (_retVal)
                    {
                    case RBACStatus.Success:
                    {
                        userMngr.ResetAccessFailedCount(user.Id);
                        break;
                    }

                    default:
                    {
                        _errors.Add(c_InvalidLogin);
                        break;
                    }
                    }
                }
            }
            else
            {
                _errors.Add(c_InvalidUser);
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return(_retVal);
    }
        private static ExceptionContext GetExceptionContext(HttpContextBase httpContext, ControllerBase controller, Exception exception) {
            RouteData rd = new RouteData();
            rd.Values["controller"] = "SomeController";
            rd.Values["action"] = "SomeAction";

            Mock<ExceptionContext> mockExceptionContext = new Mock<ExceptionContext>();
            mockExceptionContext.Setup(c => c.Controller).Returns(controller);
            mockExceptionContext.Setup(c => c.Exception).Returns(exception);
            mockExceptionContext.Setup(c => c.RouteData).Returns(rd);
            mockExceptionContext.Setup(c => c.HttpContext).Returns(httpContext);
            return mockExceptionContext.Object;
        }
Exemplo n.º 38
0
        public override void Process(ProcessContext context)
        {
            MvcEventPublisher.Instance.BeginProcessAction(context.ctx);
            if (context.ctx.utils.isSkipCurrentProcessor())
            {
                return;
            }

            MvcContext ctx = context.ctx;

            ControllerBase controller = context.getController();


            // 检查缓存
            String cacheKey = null;

            if (MvcConfig.Instance.IsActionCache)
            {
                IActionCache actionCache = ControllerMeta.GetActionCache(controller.GetType(), ctx.route.action);

                cacheKey = getCacheKey(actionCache, ctx);
                if (strUtil.HasText(cacheKey))
                {
                    Object cacheContent = checkCache(cacheKey);
                    if (cacheContent != null)
                    {
                        logger.Info("load from actionCache=" + cacheKey);
                        context.setContent(cacheContent.ToString());
                        getPageMetaFromCache(ctx, cacheKey);
                        return;
                    }
                }
            }

            MethodInfo actionMethod = ctx.ActionMethodInfo; // context.getActionMethod();

            // 设值模板并载入全局变量
            setControllerView(controller, actionMethod);

            // 运行并处理post值
            ActionRunner.runAction(ctx, controller, actionMethod, controller.utils.runAction);
            String actionContent = controller.utils.getActionResult();

            // 加入缓存
            if (MvcConfig.Instance.IsActionCache)
            {
                if (strUtil.HasText(cacheKey))
                {
                    addContentToCache(cacheKey, actionContent);
                    // 加入PageMeta
                    addPageMetaToCache(ctx, cacheKey);
                }
            }

            actionContent = PostValueProcessor.ProcessPostValue(actionContent, ctx);

            if (ctx.utils.isAjax)
            {
                context.showEnd(actionContent);
            }
            else if (ctx.utils.isFrame())
            {
                int intNoLayout = ctx.utils.getNoLayout();

                if (intNoLayout == 0)
                {
                    String content = MvcUtil.getFrameContent(actionContent);
                    context.showEnd(content);
                }
                else
                {
                    context.setContent(actionContent);
                }
            }
            else if (ctx.utils.isEnd())
            {
                context.showEnd(actionContent);
            }
            else
            {
                context.setContent(actionContent);
            }

            updateActionCache(ctx);

            MvcEventPublisher.Instance.EndProcessAction(context.ctx);
        }