public AspNetRequest(HttpRequest request)
        {
            ContractUtils.RequiresNotNull(request, "request");

            // http or https
            this.scheme = request.Url.Scheme;

            // move headers to a Ruby Hash
            this.headers = new Hash(IronRubyEngine.Context);
            foreach (string key in request.Headers.AllKeys)
            {
                string value = request.Headers.Get(key);
                if (string.IsNullOrEmpty(value))
                {
                    continue;
                }
                headers.Add(key, value);
            }

            this.queryString = request.QueryString.ToString();

            this.body = new RubyIO(IronRubyEngine.Context, request.InputStream, IOMode.ReadOnly);

            // Save the origional request incase it's needed.
            OrigionalRequest = request;
        }
Esempio n. 2
0
 public static int Seek(StringIO /*!*/ self, [DefaultProtocol] int pos, [DefaultProtocol, DefaultParameterValue(RubyIO.SEEK_SET)] int seekOrigin)
 {
     self.SetPosition(RubyIO.GetSeekPosition(
                          self._content.GetByteCount(), self._position, pos, RubyIO.ToSeekOrigin(seekOrigin)
                          ));
     return(0);
 }
Esempio n. 3
0
        private static TextReader CheckYamlPort(object port)
        {
            MutableString ms = port as MutableString;

            if (ms != null)
            {
                return(new MutableStringReader(ms));
            }

            string str = port as string;

            if (str != null)
            {
                return(new StringReader(str));
            }

            RubyIO io = port as RubyIO;

            if (io != null)
            {
                RubyIOOps.Binmode(io);
                return(new RubyIOReader(io));
            }

            throw RubyExceptions.CreateTypeError("instance of IO needed");
        }
Esempio n. 4
0
 public static object Parse(RubyModule self, object io)
 {
     try {
         foreach (object obj in MakeComposer(CheckYamlPort(io)))
         {
             return(obj);
         }
         return(null);
     } finally {
         RubyIO rio = io as RubyIO;
         if (rio != null)
         {
             rio.Close();
         }
     }
 }
Esempio n. 5
0
 public static object Load(RubyScope /*!*/ scope, RubyModule /*!*/ self, object io)
 {
     try {
         foreach (object obj in MakeConstructor(scope, CheckYamlPort(io)))
         {
             return(obj);
         }
         return(null);
     } finally {
         RubyIO rio = io as RubyIO;
         if (rio != null)
         {
             rio.Close();
         }
     }
 }
Esempio n. 6
0
 public static object Load(ConversionStorage <MutableString> /*!*/ toStr, RespondToStorage /*!*/ respondTo,
                           RubyScope /*!*/ scope, RubyModule /*!*/ self, object io)
 {
     try {
         foreach (object obj in MakeConstructor(scope.GlobalScope, GetStream(toStr, respondTo, io)))
         {
             return(obj);
         }
         return(null);
     } catch (Exception e) {
         throw RubyExceptions.CreateArgumentError(e, e.Message);
     } finally {
         RubyIO rio = io as RubyIO;
         if (rio != null)
         {
             rio.Close();
         }
     }
 }
Esempio n. 7
0
 public static object Emit(YamlCallSiteStorage /*!*/ siteStorage, YamlStream /*!*/ self, [Optional] RubyIO io)
 {
     return(RubyYaml.DumpAll(siteStorage, self._documents, io));
 }
Esempio n. 8
0
 public static object Emit(RubyContext /*!*/ context, YamlStream /*!*/ self, [Optional] RubyIO io)
 {
     return(RubyYaml.DumpAll(context, self.Documents, io));
 }
Esempio n. 9
0
 public static object DumpAll(YamlCallSiteStorage /*!*/ siteStorage, RubyModule /*!*/ self, [NotNull] IList /*!*/ objs, [Optional] RubyIO io)
 {
     return(DumpAll(siteStorage, objs, io));
 }
Esempio n. 10
0
 public static object DumpAll(RubyModule /*!*/ self, [NotNull] IEnumerable objs, [Optional] RubyIO io)
 {
     return(DumpAll(self.Context, objs, io));
 }
Esempio n. 11
0
 public static object Dump(RubyModule /*!*/ self, object obj, [Optional] RubyIO io)
 {
     return(DumpAll(self, new object[] { obj }, io));
 }
Esempio n. 12
0
 public static GZipReader /*!*/ Create(RubyClass /*!*/ self, [NotNull] RubyIO /*!*/ io)
 {
     using (BinaryReader reader = io.GetBinaryReader()) {
         return(new GZipReader(reader));
     }
 }
Esempio n. 13
0
 internal RubyIOWriter(RubyIO /*!*/ io)
 {
     Assert.NotNull(io);
     _io = io;
 }
Esempio n. 14
0
        internal static object DumpAll(RubyRepresenter /*!*/ rep, IEnumerable /*!*/ objs, RubyIO io)
        {
            TextWriter writer;

            if (io != null)
            {
                writer = new RubyIOWriter(io);
            }
            else
            {
                // the output is ascii:
                writer = new MutableStringWriter(MutableString.CreateMutable(RubyEncoding.Binary));
            }

            YamlOptions cfg = YamlOptions.DefaultOptions;
            Serializer  s   = new Serializer(writer, cfg);

            foreach (object obj in objs)
            {
                s.Serialize(rep.Represent(obj));
                rep.ForgetObjects();
            }
            s.Close();

            if (io != null)
            {
                return(io);
            }
            else
            {
                return(((MutableStringWriter)writer).String);
            }
        }
Esempio n. 15
0
 internal static object DumpAll(YamlCallSiteStorage /*!*/ siteStorage, IEnumerable /*!*/ objs, RubyIO io)
 {
     return(DumpAll(new RubyRepresenter(siteStorage), objs, io));
 }
Esempio n. 16
0
        internal static object DumpAll(RubyContext /*!*/ context, [NotNull] IEnumerable objs, [Optional] RubyIO io)
        {
            TextWriter writer;

            if (io != null)
            {
                writer = new RubyIOWriter(io);
            }
            else
            {
                writer = new MutableStringWriter();
            }
            YamlOptions cfg = YamlOptions.DefaultOptions;

            using (Serializer s = new Serializer(new Emitter(writer, cfg), cfg)) {
                RubyRepresenter r = new RubyRepresenter(context, s, cfg);
                foreach (object obj in objs)
                {
                    r.Represent(obj);
                }
            }
            if (null != io)
            {
                return(io);
            }
            else
            {
                return(((MutableStringWriter)writer).String);
            }
        }
Esempio n. 17
0
 internal RubyIOReader(RubyIO io)
 {
     _io = io;
 }
Esempio n. 18
0
 public static object Dump(YamlCallSiteStorage /*!*/ siteStorage, RubyModule /*!*/ self, object obj, [Optional] RubyIO io)
 {
     return(DumpAll(siteStorage, new object[] { obj }, io));
 }