コード例 #1
0
 public FieldMapParameterBehavior(string key, int argIndex, Encoding encoding, Formatters.IFormatter formatter)
 {
     this.Key       = key;
     this.ArgIndex  = argIndex;
     this.Encoding  = encoding;
     this.Formatter = formatter;
 }
コード例 #2
0
 public Config(IConfig config)
 {
     Encoding         = config.Encoding;
     ResponseEncoding = config.ResponseEncoding;
     Host             = config.Host;
     FiexdHeaders     = new Dictionary <string, string>(config.FiexdHeaders);
     Formatter        = config.Formatter;
 }
コード例 #3
0
 private bool ParameterBehavior(IHttpBehavior behavior, string paramName, PartAttribute attr, EnctypeAttribute enctype, int argIndex, Encoding encoding, Formatters.IFormatter formatter)
 {
     if (attr == null)
     {
         return(false);
     }
     if (!attr.IsFile)
     {
         var pb = new HttpParameterBehavior(paramName, argIndex, encoding, formatter)
         {
             IsEncodeKey   = enctype.DefaultEncodeKey,
             IsEncodeValue = enctype.DefaultEncodeValue
         };
         behavior.PartKeys.Add(new HttpStringParameterStreamWrapperBehavior(pb));
     }
     else
     {
         behavior.PartKeys.Add(new HttpFileParameterBehavior(paramName, argIndex, encoding));
     }
     return(true);
 }
コード例 #4
0
 private bool ParameterBehavior(IHttpBehavior behavior, string paramName, FieldMapAttribute attr, EnctypeAttribute enctype, int argIndex, Encoding encoding, Formatters.IFormatter formatter)
 {
     if (attr == null)
     {
         return(false);
     }
     behavior.FieldKeys.Add(new FieldMapParameterBehavior(paramName, argIndex, encoding, formatter)
     {
         IsEncodeKey   = attr.IsEncodeKey ?? enctype.DefaultEncodeKey,
         IsEncodeValue = attr.IsEncodeValue ?? enctype.DefaultEncodeValue
     });
     return(true);
 }
コード例 #5
0
        private bool ParameterBehavior(IHttpBehavior behavior, string paramName, FieldAttribute attr, EnctypeAttribute enctype, int argIndex, Encoding encoding, Formatters.IFormatter formatter)
        {
            if (attr == null)
            {
                return(false);
            }
            var pb = new HttpParameterBehavior(paramName, argIndex, encoding, formatter)
            {
                IsEncodeKey   = attr.IsEncodeKey ?? enctype.DefaultEncodeKey,
                IsEncodeValue = attr.IsEncodeValue ?? enctype.DefaultEncodeValue
            };

            if (enctype is MultipartAttribute)
            {
                behavior.PartKeys.Add(new HttpStringParameterStreamWrapperBehavior(pb));
            }
            else
            {
                behavior.FieldKeys.Add(pb);
            }
            return(true);
        }
コード例 #6
0
 private bool ParameterBehavior(IHttpBehavior behavior, string paramName, HeaderAttribute attr, int argIndex, Encoding encoding, Formatters.IFormatter formatter)
 {
     if (attr == null)
     {
         return(false);
     }
     behavior.HeaderKeys.Add(new HttpParameterBehavior(paramName, argIndex, encoding, formatter));
     return(true);
 }
コード例 #7
0
            public ExtensionInitializer(Assembly schemaAssembly, ValidationAttribute validation)
            {
                this.SchemaAssembly = schemaAssembly;
                this.Validation     = validation;

                // Use temporary validator to load schemas and validate them at the same time.
                Validator val = new Validator(OutputFormatting.Log);

                // Cache all schemas.
                foreach (string schema in validation.Schemas)
                {
                    // First try full resource name.
                    Stream memstream = schemaAssembly.GetManifestResourceStream(schema);
                    if (memstream == null)
                    {
                        // Retry appending assembly name.
                        string resourcebase = schemaAssembly.FullName.Substring(
                            0, schemaAssembly.FullName.IndexOf(','));
                        memstream = schemaAssembly.GetManifestResourceStream(
                            resourcebase + "." + schema);
                    }

                    if (memstream == null)
                    {
                        throw new FileNotFoundException("Schema not found.", schema);
                    }

                    XmlTextReader reader = new XmlTextReader(memstream);
                    val.AddSchema(reader);
                }

                // Pull schemas out so that validator can be GC-collected;
                XmlSchema[] xsds = new XmlSchema[val.XmlSchemas.Count];
                val.XmlSchemas.CopyTo(xsds, 0);
                Schema[] schs = new Schema[val.Schemas.Count];
                val.Schemas.CopyTo(schs, 0);

                SchematronSchemas.AddRange(schs);
                foreach (XmlSchema xsd in xsds)
                {
                    XmlSchemas.Add(xsd);
                }

                // Detemine custom formatter.
                if (validation.FormattingType != null)
                {
                    if (!typeof(Formatters.IFormatter).IsAssignableFrom(validation.FormattingType))
                    {
                        throw new ArgumentException("Assigned formatter type " + validation.FormattingType.FullName +
                                                    " does not implement the required " + typeof(Formatters.IFormatter).FullName + " interface.");
                    }
                    // Try to retrieve empty constructor
                    ConstructorInfo ctor = validation.FormattingType.GetConstructor(Type.EmptyTypes);
                    if (ctor == null)
                    {
                        throw new ArgumentException("Assigned formatter type " + validation.FormattingType.FullName +
                                                    " doesn't have a parameterless constructor");
                    }

                    Formatter = (Formatters.IFormatter)Activator.CreateInstance(validation.FormattingType);
                }
            }