Exemple #1
0
        public RegexConstraint(string parameterName, string pattern, RegexOptions options)
        {
            Precondition.Defined(parameterName, () => Error.ArgumentNull("parameterName"));

            _parameterName = parameterName;
            _pattern       = new Regex(NormalizePattern(pattern), options);
        }
Exemple #2
0
        public static string CheckBox(this HtmlControlHelper helper,
                                      string name, object value, bool isChecked, IDictionary <string, object> attributes)
        {
            Precondition.Defined(name, () => Error.ArgumentNull("name"));

            if (attributes == null)
            {
                attributes = new ValueDictionary();
            }

            if (helper.DataSource.Keys.Any(k => k.Equals(name,
                                                         StringComparison.OrdinalIgnoreCase)) || helper.DataSource.Keys.Any())
            {
                isChecked = helper.DataSource.GetValue <bool>(name);
            }

            if (isChecked)
            {
                attributes["checked"] = "checked";
            }
            else
            {
                attributes.Remove("checked");
            }

            return(InputBuilder(helper, "checkbox", name, value, attributes));
        }
Exemple #3
0
        public static string RadioButton(this HtmlControlHelper helper,
                                         string name, object value, bool isChecked, IDictionary <string, object> attributes)
        {
            Precondition.Defined(name, () => Error.ArgumentNull("name"));

            if (attributes == null)
            {
                attributes = new ValueDictionary();
            }

            if (helper.DataSource.Keys.Any(k => k.Equals(name, StringComparison.OrdinalIgnoreCase)))
            {
                string providedValue = Convert.ToString(value, CultureInfo.InvariantCulture);
                string actualValue   = helper.DataSource.GetValue <string>(name);

                isChecked = (!String.IsNullOrEmpty(actualValue) &&
                             String.Equals(providedValue, actualValue, StringComparison.OrdinalIgnoreCase));
            }

            if (isChecked)
            {
                attributes["checked"] = "checked";
            }
            else
            {
                attributes.Remove("checked");
            }

            return(InputBuilder(helper, "radio", name, value, attributes));
        }
        protected virtual bool IsAssemblyResource(string virtualPath, out string resourceName)
        {
            Precondition.Defined(virtualPath, () => Error.ArgumentNull("virtualPath"));
            virtualPath  = VirtualPathUtility.ToAppRelative(virtualPath);
            resourceName = null;

            if (!virtualPath.StartsWith(VirtualPath, StringComparison.InvariantCultureIgnoreCase))
            {
                return(false);
            }

            if (Assembly != null)
            {
                string[] resources = Assembly.GetManifestResourceNames();
                resourceName = ConstructAssemblyResourceName(virtualPath);

                if (resources != null && resources.Contains(resourceName,
                                                            StringComparer.InvariantCultureIgnoreCase))
                {
                    return(true);
                }
            }
            resourceName = null;
            return(false);
        }
Exemple #5
0
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="CommonDbDataProvider"/> class.
        /// </summary>
        /// <param name="connectionString">The database connection string.</param>
        protected CommonDbDataProvider(string connectionString)
        {
            Precondition.Defined(connectionString, () =>
                                 Error.ConnectionStringNotInitialized());

            _connection = CreateConnection(connectionString);
        }
        protected RouteConstraintDefinition(string parameterName)
        {
            Precondition.Defined(parameterName, () =>
                                 Error.ArgumentNull("parameterName"));

            _parameterName = parameterName;
        }
Exemple #7
0
        public virtual T Get <T>(string key, CacheItemSelector <T> selector,
                                 DateTime expiration, IEnumerable <string> tags)
        {
            Precondition.Defined(key, () => Error.ArgumentNull("key"));
            Precondition.Require(selector, () => Error.ArgumentNull("selector"));
            Precondition.Require(!_disposed, () => Error.ObjectDisposed("entries"));

            _entriesLock.EnterUpgradeableReadLock();
            try
            {
                CacheEntry entry;
                if (!TryGetEntryAndValidate(key, out entry))
                {
                    _entriesLock.EnterWriteLock();
                    try
                    {
                        if (!TryGetEntryAndValidate(key, out entry))
                        {
                            _entries[key] = entry = new CacheEntry(key, selector(),
                                                                   expiration, CreateEntryTags(tags));
                        }
                    }
                    finally
                    {
                        _entriesLock.ExitWriteLock();
                    }
                }
                return(Converter.ChangeType <T>(entry.Value));
            }
            finally
            {
                _entriesLock.ExitUpgradeableReadLock();
            }
        }
        public void Add(string name, IDbDataProviderFactory item)
        {
            Precondition.Defined(name, () => Error.ArgumentNull("name"));
            Precondition.Require(item, () => Error.ArgumentNull("item"));

            _collection[name] = item;
            _default          = null;
        }
Exemple #9
0
        /// <summary>
        /// Renders the specified view against the current context.
        /// </summary>
        /// <param name="viewName">The name of the view to render.</param>
        /// <param name="model">The model object supplied to the view.</param>
        /// <param name="viewData">The view data supplied to the view.</param>
        public void Include(string viewName, object model, ViewDataDictionary viewData)
        {
            Precondition.Defined(viewName, () => Error.ArgumentNull("viewName"));

            ComponentController component = new ComponentController();

            component.RenderView(_context, viewName, model, viewData);
        }
Exemple #10
0
        protected virtual IController CreateController(
            RequestContext context, string controllerName)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
            Precondition.Defined(controllerName, () => Error.InvalidArgument("controllerName"));

            return(GetControllerInstance(context, GetControllerType(controllerName)));
        }
Exemple #11
0
 public HtmlElementBuilder(string tagName,
                           object attributes, string content)
 {
     Precondition.Defined(tagName, () => Error.ArgumentNull("tagName"));
     _name       = tagName;
     _attributes = new HtmlAttributeDictionary(attributes);
     _content    = content;
 }
        public ApplyCultureAttribute(string parameterName)
        {
            Precondition.Defined(parameterName,
                                 () => Error.ArgumentNull("parameterName"));

            _parameterName = parameterName;
            _source        = "Header";
        }
Exemple #13
0
            public CacheTag(string value, long version)
            {
                Precondition.Defined(value, () =>
                                     Error.ArgumentNull("value"));

                _value   = value;
                _version = version;
            }
Exemple #14
0
        public void Merge(string key, object value, bool replaceExisting)
        {
            Precondition.Defined(key, () => Error.ArgumentNull("key"));

            if (!_values.ContainsKey(key) || replaceExisting)
            {
                _values[key] = value;
            }
        }
Exemple #15
0
        public DirectiveExpression(string directiveName)
            : base(TemplateExpressionType.Directive)
        {
            Precondition.Defined(directiveName,
                                 () => Error.ArgumentNull("directiveName"));

            _name       = directiveName;
            _attributes = new ParsedAttributeCollection();
        }
        public DbParameterDescriptor(string name,
                                     ParameterDirection direction, object value)
        {
            Precondition.Defined(name,
                                 () => Error.ArgumentNull("name"));

            _name      = name;
            _direction = direction;
            _value     = value;
        }
Exemple #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Radischevo.Wahha.Web.Hosting.AssemblyResourceVirtualFile" /> class.
        /// </summary>
        /// <param name="virtualPath">The virtual path to the resource represented by this instance.</param>
        /// <param name="assembly">The <see cref="System.Reflection.Assembly"/> containing
        /// the resource represented by this instance.</param>
        /// <param name="resourcePath">The path to the embedded resource in the <paramref name="assembly" />.</param>
        /// <exception cref="System.ArgumentNullException" />
        public AssemblyResourceVirtualFile(string virtualPath,
                                           Assembly assembly, string resourcePath)
            : base(virtualPath)
        {
            Precondition.Require(assembly, () => Error.ArgumentNull("assembly"));
            Precondition.Defined(resourcePath, () => Error.ArgumentNull("resourcePath"));

            _assembly     = assembly;
            _resourcePath = resourcePath;
        }
Exemple #18
0
        public WebFormRoutingHandler(string virtualPath,
                                     bool validateAccessRights, IBuildManager buildManager)
            : base()
        {
            Precondition.Defined(virtualPath, () => Error.ArgumentNull("virtualPath"));

            _virtualPath          = virtualPath;
            _validateAccessRights = validateAccessRights;
            _buildManager         = buildManager;
        }
Exemple #19
0
 public CacheEntry(string key, object value, DateTime expiration,
                   IEnumerable <CacheTag> tags)
 {
     Precondition.Defined(key, () => Error.ArgumentNull("key"));
     _key      = key;
     _hashCode = _key.GetHashCode();
     _value    = value;
     _tags     = tags ?? Enumerable.Empty <CacheTag>();
     _expires  = expiration;
 }
Exemple #20
0
        public override bool InvokeAction(ControllerContext context,
                                          string actionName, IDictionary <string, object> values)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
            Precondition.Defined(actionName, () => Error.ArgumentNull("actionName"));

            IAsyncResult result = BeginInvokeAction(context,
                                                    actionName, null, null, values);

            return(EndInvokeAction(result));
        }
Exemple #21
0
        public StringReplacementRule(StringReplacementMode mode,
                                     string pattern, string replacement)
        {
            Precondition.Defined(pattern, () => Error.ArgumentNull("pattern"));

            _mode        = mode;
            _pattern     = pattern;
            _replacement = replacement;
            _options     = RegexOptions.IgnoreCase | RegexOptions.Multiline |
                           RegexOptions.Singleline;
        }
Exemple #22
0
        public static string TextArea(this HtmlControlHelper helper,
                                      string name, string value, int rows, int columns, IDictionary <string, object> attributes)
        {
            Precondition.Defined(name, () => Error.ArgumentNull("name"));
            if (helper.DataSource.Keys.Any(k => k.Equals(name, StringComparison.OrdinalIgnoreCase)))
            {
                value = helper.DataSource.GetValue <string>(name);
            }

            return(TextAreaBuilder(helper, name, value, rows, columns, attributes));
        }
Exemple #23
0
        public ParsedTemplate ParseFile(string fileName)
        {
            Precondition.Defined(fileName,
                                 () => Error.ArgumentNull("fileName"));

            using (StreamReader reader = new StreamReader(
                       ConstructPhysicalPath(fileName, out _virtualPath)))
            {
                return(Parse(reader));
            }
        }
        protected BuildManagerCompiledView(string viewPath,
                                           IBuildManager buildManager, IViewActivator activator)
        {
            Precondition.Defined(viewPath, () => Error.ArgumentNull("viewPath"));
            Precondition.Require(buildManager, () => Error.ArgumentNull("buildManager"));
            Precondition.Require(activator, () => Error.ArgumentNull("activator"));

            _viewPath     = viewPath;
            _buildManager = buildManager;
            _activator    = activator;
        }
        public RouteDefinition(string name, Route route)
        {
            Precondition.Defined(name, () => Error.ArgumentNull("name"));
            Precondition.Require(route, () => Error.ArgumentNull("route"));

            _name  = name;
            _route = route;
            _url   = route.Url;

            _defaults    = CreateDefaults(route.Defaults);
            _constraints = new List <RouteConstraintDefinition>();
        }
Exemple #26
0
        public static string TextBox(this HtmlControlHelper helper,
                                     string name, object value, IDictionary <string, object> attributes)
        {
            Precondition.Defined(name, () => Error.ArgumentNull("name"));
            if (helper.DataSource.Keys.Any(c => String.Equals(c, name,
                                                              StringComparison.InvariantCultureIgnoreCase)))
            {
                value = helper.DataSource.GetValue <object>(name);
            }

            return(InputBuilder(helper, "text", name, value, attributes));
        }
Exemple #27
0
        public static string Hidden(this HtmlControlHelper helper,
                                    string name, object value, IDictionary <string, object> attributes)
        {
            Precondition.Defined(name, () => Error.ArgumentNull("name"));

            if (helper.DataSource.Keys.Any(k => k.Equals(name, StringComparison.OrdinalIgnoreCase)))
            {
                value = helper.DataSource.GetValue <object>(name);
            }

            return(InputBuilder(helper, "hidden", name, value, attributes));
        }
        public virtual bool InvokeAction(ControllerContext context, string actionName,
                                         IDictionary <string, object> values)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
            Precondition.Defined(actionName, () => Error.ArgumentNull("actionName"));

            ControllerDescriptor controller    = GetControllerDescriptor(context);
            ActionDescriptor     currentAction = FindAction(context, controller, actionName);

            if (currentAction == null)
            {
                return(false);
            }

            ActionFilterInfo filters = GetFilters(context, currentAction);

            try
            {
                context.Parameters.Merge(values);
                context.Parameters.Merge(GetParameterValues(context, currentAction));

                AuthorizationContext authContext = InvokeAuthorizationFilters(
                    context, currentAction, filters.AuthorizationFilters);

                if (authContext.Cancel)
                {
                    InvokeActionResult(context, authContext.Result ?? EmptyResult.Instance);
                }
                else
                {
                    if (context.Controller.ValidateRequest)
                    {
                        ValidateRequest(context.Context.Request);
                    }

                    ActionExecutedContext resultContext = InvokeActionFilters(
                        context, currentAction, filters.ActionFilters);

                    InvokeActionResultFilters(context, filters.ResultFilters, resultContext.Result);
                }
            }
            catch (Exception ex)
            {
                ExceptionContext exceptionContext = InvokeExceptionFilters(context, ex, filters.ExceptionFilters);
                if (!exceptionContext.Handled)
                {
                    throw;
                }

                InvokeActionResult(context, exceptionContext.Result);
            }
            return(true);
        }
        public HtmlElementRule(HtmlElementRule parent,
                               string name, HtmlElementOptions flags)
        {
            Precondition.Defined(name,
                                 () => Error.ArgumentNull("name"));

            _name       = name;
            _options    = flags;
            _children   = new HtmlElementRuleCollection();
            _attributes = new HtmlAttributeRuleCollection();
            _parent     = parent;
        }
Exemple #30
0
        public StaticFileResult(string path,
                                string fileName, string contentType,
                                Encoding contentEncoding)
            : base()
        {
            Precondition.Defined(path, () => Error.ArgumentNull("path"));

            _path            = path;
            _contentEncoding = contentEncoding;

            base.ContentType = contentType;
            base.FileName    = fileName;
        }