Exemplo n.º 1
0
 public Fragment(string content, Position start, Position end, Uri.Locator resource)
 {
     this.Content  = content;
     this.Start    = start;
     this.End      = end;
     this.Resource = resource;
 }
Exemplo n.º 2
0
 internal ByteDevice(System.IO.Stream backend, Uri.Locator resource, bool dontClose = false) :
     base(backend, resource, dontClose)
 {
     this.peeked = new PeekBuffer(async() =>
     {
         var buffer = new byte[64 * 1024];
         return(await this.backend.ReadAsync(buffer, 0, 1) == 1 ? new Collection.Queue <byte>(buffer) : null);
     });
 }
Exemplo n.º 3
0
 internal BlockDevice(System.IO.Stream backend, Uri.Locator resource, bool dontClose = false) :
     base(backend, resource, dontClose)
 {
     this.peeked = new PeekBuffer(async() =>
     {
         var buffer = new byte[64 * 1024];
         int count  = await this.backend.ReadAsync(buffer, 0, buffer.Length);
         return(count > 0 ? buffer.Slice(0, count) : null);
     });
 }
Exemplo n.º 4
0
        public static IBlockDevice Create(Uri.Locator resource)
        {
            IBlockDevice result = BlockDevice.Open(resource, System.IO.FileMode.Create);

            if (result.IsNull() && resource.NotNull())
            {
                System.IO.Directory.CreateDirectory(resource.Path.FolderPath.PlatformPath);
                result = BlockDevice.Open(resource, System.IO.FileMode.Create);
            }
            return(result);
        }
Exemplo n.º 5
0
        static IBlockDevice Open(Uri.Locator resource, System.IO.FileMode mode)
        {
            IBlockDevice result = null;

            if (resource.NotNull())
            {
                switch (resource.Scheme)
                {
                case "assembly":
                    result = resource.Authority == "" ? BlockDevice.Open(System.Reflection.Assembly.GetEntryAssembly(), resource.Path) : BlockDevice.Open(System.Reflection.Assembly.Load(new System.Reflection.AssemblyName(resource.Authority)), resource.Path);
                    break;

                case "file":
                    try
                    {
                        System.IO.FileStream stream = System.IO.File.Open(System.IO.Path.GetFullPath(resource.PlatformPath), mode, System.IO.FileAccess.ReadWrite, System.IO.FileShare.ReadWrite);
                        if (stream.NotNull())
                        {
                            result = new BlockDevice(stream, resource);
                        }
                    }
                    catch (System.IO.DirectoryNotFoundException)
                    {
                        result = null;
                    }
                    catch (System.IO.FileNotFoundException)
                    {
                        result = null;
                    }
                    break;

                case "http":
                case "https":
                    if (mode == System.IO.FileMode.Open)
                    {
                        // TODO: support http and https.
                    }
                    break;
                }
            }
            return(result);
        }
Exemplo n.º 6
0
 public static IBlockDevice Open(Uri.Locator resource)
 {
     return(BlockDevice.Open(resource, System.IO.FileMode.Open));
 }
Exemplo n.º 7
0
 public static IBlockDevice Open(System.IO.Stream stream, Uri.Locator resource = null)
 {
     return(stream.NotNull() ? new BlockDevice(stream, resource) : null);
 }
Exemplo n.º 8
0
 public static ITextIndenter Create(Uri.Locator resource)
 {
     return(TextIndenter.Open(TextWriter.Create(resource)));
 }
Exemplo n.º 9
0
 public SeekableDevice(System.IO.Stream backend, Uri.Locator resource, bool dontClose = false)
 {
     this.backend   = backend;
     this.Resource  = resource;
     this.dontClose = dontClose;
 }
Exemplo n.º 10
0
 public static IByteDevice Wrap(System.IO.Stream stream, Uri.Locator resource = null)
 {
     return(stream.NotNull() ? new ByteDevice(stream, resource, true) : null);
 }
Exemplo n.º 11
0
 public static IByteDevice Open(Uri.Locator input, Uri.Locator output)
 {
     return(ByteDeviceCombiner.Open(ByteDevice.Open(input), ByteDevice.Create(output)));
 }
Exemplo n.º 12
0
 public static ITextWriter Create(Uri.Locator resource)
 {
     return(TextWriter.Open(CharacterDevice.Create(resource)));
 }
Exemplo n.º 13
0
 protected Device(System.IO.Stream stream, Uri.Locator resource)
 {
     this.stream   = stream;
     this.Resource = resource;
     this.Encoding = Text.Encoding.Utf8;
 }
Exemplo n.º 14
0
 public static ITextReader Open(Uri.Locator resource)
 {
     return(TextReader.Open(CharacterDevice.Open(resource)));
 }
Exemplo n.º 15
0
 public static ICharacterDevice Create(Uri.Locator resource)
 {
     return(CharacterDevice.Open(ByteDevice.Create(resource)));
 }