Exemplo n.º 1
0
        private async void FtpDataStreamingHandler(StreamedFileDataRequest request)
        {
            try
            {
                using 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())
                {
                    request.FailAndClose(StreamedFileFailureMode.CurrentlyUnavailable);
                    return;
                }

                using (var outStream = request.AsStreamForWrite())
                {
                    await ftpClient.DownloadAsync(outStream, FtpPath);

                    await outStream.FlushAsync();
                }
                request.Dispose();
            }
            catch
            {
                request.FailAndClose(StreamedFileFailureMode.Incomplete);
            }
        }
Exemplo n.º 2
0
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        private async void StreamedFileWriter(StreamedFileDataRequest request)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            try {
                using (var outStream = request.AsStreamForWrite( )) {
                    var res = Properties.Resources.ResourceManager.GetObject(_sound.Id);
                    if (res is byte[])
                    {
                        using (var streamWriter = new BinaryWriter(outStream)) {
                            streamWriter.Write((byte[])Properties.Resources.ResourceManager.GetObject(_sound.Id));
                        }
                    }
                    else
                    {
                        using (var inStream = Properties.Resources.ResourceManager.GetStream(_sound.Id)) {
                            await inStream.CopyToAsync(outStream);
                        }
                    }
                }
                request.Dispose( );
            }
            catch {
                request.FailAndClose(StreamedFileFailureMode.Incomplete);
            }
        }
Exemplo n.º 3
0
        private async void FtpDataStreamingHandler(StreamedFileDataRequest request)
        {
            try
            {
                using var ftpClient = GetFtpClient();
                if (!await ftpClient.EnsureConnectedAsync())
                {
                    request.FailAndClose(StreamedFileFailureMode.CurrentlyUnavailable);
                    return;
                }

                using (var outStream = request.AsStreamForWrite())
                {
                    await ftpClient.DownloadAsync(outStream, FtpPath);

                    await outStream.FlushAsync();
                }
                request.Dispose();
            }
            catch
            {
                request.FailAndClose(StreamedFileFailureMode.Incomplete);
            }
        }