Exemplo n.º 1
0
        public void Send(PNGXPayload payload, string fileName, PublishCompleteHandler complete)
        {
            try
            {
                var rawPayload = payload.Serialize();

                using (var client = this.clientFactory.Create())
                    using (var stream = new MemoryStream(rawPayload))
                    {
                        client.Connect();

                        this.EnsureFreeSpace(client);

                        client.UploadFile(
                            stream,
                            Path.Combine(this.config.SFTPPublishPath, fileName),
                            length =>
                        {
                            if (length == (ulong)rawPayload.Length)
                            {
                                complete(PublishCompletionStatus.Success, $"Successfully uploaded {fileName}");
                            }
                        });
                    }
            }
            catch (Exception ex)
            {
                complete(PublishCompletionStatus.Failure, $"Failed to upload file: {fileName}, got error: {ex.ToString()}");
            }
        }
Exemplo n.º 2
0
        public void Send(PNGXPayload payload, string fileName, PublishCompleteHandler complete)
        {
            if (complete == null)
            {
                throw new ArgumentNullException(nameof(complete));
            }

            var fullPath = Path.Combine(this.config.DiskPath, fileName);

            try
            {
                File.WriteAllBytes(fullPath, payload.Serialize());
                complete(PublishCompletionStatus.Success, $"Completed writing file {fileName} with success");
            }
            catch (System.IO.IOException ex)
            {
                complete(PublishCompletionStatus.Failure, $"failed writing file {fileName} got error {ex.ToString()}");
            }
        }