예제 #1
0
        public override IAsyncOperation <IRandomAccessStreamWithContentType> OpenReadAsync()
        {
            return(AsyncInfo.Run <IRandomAccessStreamWithContentType>(async(cancellationToken) =>
            {
                var ftpClient = GetFtpClient();
                if (!await ftpClient.EnsureConnectedAsync())
                {
                    return null;
                }

                var inStream = await ftpClient.OpenReadAsync(FtpPath, cancellationToken);
                var nsStream = new NonSeekableRandomAccessStreamForRead(inStream, (ulong)inStream.Length)
                {
                    DisposeCallback = ftpClient.Dispose
                };
                return new StreamWithContentType(nsStream);
            }));
        }
예제 #2
0
        public override IAsyncOperation <IRandomAccessStreamWithContentType> OpenReadAsync()
        {
            return(AsyncInfo.Run <IRandomAccessStreamWithContentType>(async(cancellationToken) =>
            {
                if (Path == ContainerPath)
                {
                    if (BackingFile != null)
                    {
                        return await BackingFile.OpenReadAsync();
                    }
                    else
                    {
                        var hFile = NativeFileOperationsHelper.OpenFileForRead(ContainerPath);
                        if (hFile.IsInvalid)
                        {
                            return null;
                        }
                        return new StreamWithContentType(new FileStream(hFile, FileAccess.Read).AsRandomAccessStream());
                    }
                }

                ZipFile zipFile = await OpenZipFileAsync(FileAccessMode.Read);
                if (zipFile == null)
                {
                    return null;
                }
                zipFile.IsStreamOwner = true;
                var znt = new ZipNameTransform(ContainerPath);
                var entry = zipFile.GetEntry(znt.TransformFile(Path));
                if (entry != null)
                {
                    var nsStream = new NonSeekableRandomAccessStreamForRead(zipFile.GetInputStream(entry), (ulong)entry.Size)
                    {
                        DisposeCallback = () => zipFile.Close()
                    };
                    return new StreamWithContentType(nsStream);
                }
                return null;
            }));
        }
예제 #3
0
        public override IAsyncOperation <IRandomAccessStreamWithContentType> OpenReadAsync()
        {
            return(AsyncInfo.Run <IRandomAccessStreamWithContentType>(async(cancellationToken) =>
            {
                var ftpClient = new FtpClient();
                ftpClient.Host = FtpHelpers.GetFtpHost(Path);
                ftpClient.Port = FtpHelpers.GetFtpPort(Path);
                ftpClient.Credentials = FtpManager.Credentials.Get(ftpClient.Host, FtpManager.Anonymous);

                if (!await ftpClient.EnsureConnectedAsync())
                {
                    return null;
                }

                var inStream = await ftpClient.OpenReadAsync(FtpPath, cancellationToken);
                var nsStream = new NonSeekableRandomAccessStreamForRead(inStream, (ulong)inStream.Length)
                {
                    DisposeCallback = () => ftpClient.Dispose()
                };
                return new StreamWithContentType(nsStream);
            }));
        }