Example #1
0
        public void Test()
        {
            var executions = 0;

            void OnSecondExecution()
            {
                executions++;
                if (executions != 2)
                {
                    throw new Exception(executions.ToString());
                }
            }

            ControlFlow.ExecuteWithRetry(OnSecondExecution);
            executions.Should().Be(2);
        }
Example #2
0
    public static void FtpUploadFileInternal(string file, string hostDestination, string prefix = null)
    {
        ControlFlow.ExecuteWithRetry(() =>
        {
            FtpMakeDirectory(GetParentPath(hostDestination));

            var request         = WebRequest.Create(hostDestination);
            request.Credentials = FtpCredentials;
            request.Method      = WebRequestMethods.Ftp.UploadFile;

            var content           = File.ReadAllBytes(file);
            request.ContentLength = content.Length;

            var requestStream = request.GetRequestStream();
            requestStream.Write(content, offset: 0, count: content.Length);
            requestStream.Close();
        });
    }
Example #3
0
        private static void FtpUploadFileInternal(string file, string hostDestination, string prefix = null)
        {
            Logger.Info($"{prefix}Uploading to '{hostDestination}'...");

            ControlFlow.ExecuteWithRetry(() =>
            {
                FtpMakeDirectory(GetParentPath(hostDestination));
                var request           = WebRequest.Create(hostDestination);
                request.Credentials   = FtpCredentials;
                request.Method        = WebRequestMethods.Ftp.UploadFile;
                var content           = File.ReadAllBytes(file);
                request.ContentLength = content.Length;
                using (var requestStream = request.GetRequestStream())
                {
                    requestStream.Write(content, offset: 0, count: content.Length);
                    requestStream.Close();
                    // TODO: check response
                    //var response = (FtpWebResponse) request.GetResponse ();
                    //response.Close ();
                }
            });
        }