public ActionExecutor(ControllerContext context)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
            Precondition.Require(context.Controller, () => Error.ArgumentNull("controller"));

            _context = context;
        }
        /// <summary>
        /// Searches the registered view engines and returns the 
        /// <see cref="T:Radischevo.Wahha.Web.Mvc.ViewEngineResult"/> 
        /// used to render the view.
        /// </summary>
        /// <param name="context"></param>
        protected override ViewEngineResult FindView(ControllerContext context)
        {
            ViewEngineResult result = base.ViewEngines.FindView(context, base.ViewName);
            Precondition.Require(result, () => Error.ViewNotFound(base.ViewName));

            return result;
        }
		public object Create(ControllerContext context, Type type)
		{
			Precondition.Require(context, () => Error.ArgumentNull("context"));
			Precondition.Require(type, () => Error.ArgumentNull("type"));

			return ServiceLocator.Instance.GetService(type);
		}
 public ExceptionContext(ControllerContext context, Exception exception)
     : base(context)
 {
     Precondition.Require(exception, () => Error.ArgumentNull("exception"));
     _exception = exception;
     _result = EmptyResult.Instance;
 }
        public override void Execute(ControllerContext context)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
			if (context.IsChild)
				throw Error.CannotRedirectFromChildAction();

            context.Context.Response.Redirect(_url);
        }
        protected ResultContext(ControllerContext context, ActionResult result)
        {
			Precondition.Require(context, () => Error.ArgumentNull("context"));
            Precondition.Require(result, () => Error.ArgumentNull("error"));

			_context = context;
            _result = result;
        }
 public ViewContext(ControllerContext context, IView view,
     ViewDataDictionary viewData, TempDataDictionary tempData)
     : this(ViewContext.GetControllerContext(context).Context, 
     GetControllerContext(context).RouteData, 
     GetControllerContext(context).Controller, view, 
     viewData, tempData)
 {
 }
		public ChildContextOperator(ControllerContext context)
		{
			Precondition.Require(context, () => 
				Error.ArgumentNull("context"));

			_context = context;
			Init();
		}
		public IEnumerable<Filter> GetFilters(ControllerContext context, ActionDescriptor action)
		{
			Precondition.Require(context, () => Error.ArgumentNull("context"));
			Precondition.Require(action, () => Error.ArgumentNull("action"));

			if (context.Controller != null)
				yield return new Filter(context.Controller, FilterScope.First, Int32.MinValue);
		}
        public override void Execute(ControllerContext context)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
            if (_command == null)
                return;

            _command(context);
        }
        protected ActionContext(ControllerContext context, ActionDescriptor action)
        {
			Precondition.Require(context, () => Error.ArgumentNull("context"));
            Precondition.Require(action, () => Error.ArgumentNull("action"));

            _action = action;
			_context = context;
        }
		protected override IValueSet GetDataSource(ControllerContext context)
		{
			HttpSessionStateBase sessionState = context.Context.Session;

			if (sessionState == null)
				return new ValueDictionary();

			return sessionState.AsValueSet();
		}
		private string GetResourceString(ControllerContext context, string resourceName)
		{
			if (!String.IsNullOrEmpty(ResourceClassKey) &&
				context != null && context.Context != null)
				return context.Context.GetGlobalResourceObject(ResourceClassKey,
					resourceName, CultureInfo.CurrentUICulture) as string;

			return null;
		}
        public override void Execute(ControllerContext context)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
			if (context.IsChild)
				throw Error.CannotRedirectFromChildAction();

            context.Context.Response.StatusCode = (int)HttpStatusCode.MovedPermanently;
            context.Context.Response.StatusDescription = "Moved Permanently";
            context.Context.Response.RedirectLocation = Url;
        }
		protected HttpValueProvider(ControllerContext context, CultureInfo culture)
			: base(culture)
		{
			Precondition.Require(context, () => Error.ArgumentNull("context"));

			_prefixes = new HashSet<string>(
				StringComparer.OrdinalIgnoreCase);
			_values = EnsureValues(GetDataSource(context));

			Initialize();
		}
		public IValueProvider Create (ControllerContext context)
		{
			if (ValidateRequest (context.Context.Request))
			{
				Stream input = context.Context.Request.InputStream;
				Encoding encoding = context.Context.Request.ContentEncoding;
				IValueSet data = CreateBindingStore (input, encoding) ?? new ValueDictionary ();
				
				return new DictionaryValueProvider (data);
			}
			return null;
		}
        public virtual IDictionary<string, object> Load(ControllerContext context)
        {
            HttpSessionStateBase session = context.Context.Session;

			if (session != null)
			{
				Dictionary<string, object> data = (session[SessionStateKey] as Dictionary<string, object>);
				if (data != null)
					session.Remove(SessionStateKey);
			}
            return new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
        }
        public BindingContext(ControllerContext context, Type modelType, 
            string modelName, IValueProvider valueProvider, 
			ModelStateCollection modelState) 
            : base(context)
        {
            Precondition.Require(modelType, () => Error.ArgumentNull("modelType"));
			Precondition.Require(valueProvider, () => Error.ArgumentNull("valueProvider"));

            _modelType = modelType;
            _modelName = modelName;
			_valueProvider = valueProvider;
            _modelState = modelState;
        }
        public override void Execute(ControllerContext context)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
            HttpResponseBase response = context.Context.Response;

            if (!String.IsNullOrEmpty(_contentType))
                response.ContentType = _contentType;
            
            if (_contentEncoding != null)
                response.ContentEncoding = _contentEncoding;
            
            if (!String.IsNullOrEmpty(_content))
                response.Write(_content);
        }
        public override void Execute(ControllerContext context)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
			if (context.IsChild)
				throw Error.CannotExecuteResultInChildAction();

            HttpResponseBase response = context.Context.Response;
            response.ContentType = "application/x-javascript";
            
            if (_contentEncoding != null)
                response.ContentEncoding = _contentEncoding;
            
            if (!String.IsNullOrEmpty(_script))
                response.Write(_script);
        }
		public virtual IEnumerable<Filter> GetFilters(ControllerContext context, ActionDescriptor action)
		{
			Precondition.Require(context, () => Error.ArgumentNull("context"));
			Precondition.Require(action, () => Error.ArgumentNull("action"));

			ControllerBase controller = context.Controller;
			if (controller == null)
				return Enumerable.Empty<Filter>();

			return GetControllerAttributes(context, action)
				.Select(attr => new Filter(attr, FilterScope.Controller, null))
				.Concat(GetActionAttributes(context, action)
				.Select(attr => new Filter(attr, FilterScope.Action, null)))
				.ToList();
		}
        public virtual MethodInfo GetActionMethod(ControllerContext context, string actionName)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
            Precondition.Defined(actionName, () => Error.ArgumentNull("actionName"));

            List<ActionMethodCacheEntry> matchingMethods = _methods[actionName].Where(m => m.IsValidFor(context)).ToList();
            switch (matchingMethods.Count)
            {
                case 0:
                    return null;
                case 1: 
                    return matchingMethods[0].Method;
            }
            throw Error.AmbiguousActionName(context.Controller.GetType(), actionName);
        }
        public virtual void Save(ControllerContext context, IDictionary<string, object> values)
        {
            HttpSessionStateBase session = context.Context.Session;
			bool isDirty = (values != null && values.Count > 0);

			if (session == null)
			{
				if (isDirty)
					throw Error.SessionStateDisabled();
			}
			else
			{
				if (isDirty)
					session[SessionStateKey] = values;
				else
				{
					if (session[SessionStateKey] != null)
						session.Remove(SessionStateKey);
				}
			}
        }
		protected virtual IEnumerable<FilterAttribute> GetControllerAttributes(
			ControllerContext context, ActionDescriptor action)
		{
			return action.Controller.GetFilters(_useCache);
		}
Example #25
0
        public override void Execute(ControllerContext context)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
			if (context.IsChild)
				throw Error.CannotExecuteResultInChildAction();

            HttpResponseBase response = context.Context.Response;
            response.ContentType = (String.IsNullOrEmpty(_contentType)) 
				? _defaultContentType : _contentType;

            if (_contentEncoding != null)
                response.ContentEncoding = _contentEncoding;

            if (_data != null)
            {
                using (MemoryStream ms = new MemoryStream(500))
                {
                    using (XmlWriter writer = XmlTextWriter.Create(ms,
                        new XmlWriterSettings() {
                            OmitXmlDeclaration = true, Indent = true,
                            Encoding = response.ContentEncoding }))
                    {
                        XmlSerializer xs = new XmlSerializer(_data.GetType(), _includedTypes);
                        xs.Serialize(writer, _data);
                    }
                    ms.WriteTo(response.OutputStream);
                }
            }
        }
 public ActionExecutionContext(ControllerContext context, ActionDescriptor action)
     : base(context, action)
 {
 }
 public override void Execute(ControllerContext context)
 {
     Precondition.Require(context, () => Error.ArgumentNull("context"));
     foreach (ActionResult result in _results)
         result.Execute(context);
 }
		public IValueProvider Create(ControllerContext context)
		{
			return new FormValueProvider(context, CultureInfo.CurrentCulture);
		}
		protected override IValueSet GetDataSource(ControllerContext context)
		{
			return context.Context.Request.Parameters.Form;
		}
		public FormValueProvider(ControllerContext context, CultureInfo culture)
			: base(context, culture)
		{
		}