public void ShouldWriteToInnerTextWriters()
        {
            const string expected = "0E62D3EF-75A5-4EB2-9915-F8C169AF77B2\r\n";

            using (var writer1 = new StringWriter())
            using (var writer2 = new StringWriter())
            {
                var sut = new TextWriterProxy(writer1, writer2);

                sut.Write(expected);

                var actual1 = writer1.ToString();
                var actual2 = writer2.ToString();
                Assert.That(actual1, Is.EqualTo(actual2), "#1");
                Assert.That(actual1, Is.EqualTo(expected), "#2");
            }
        }
Esempio n. 2
0
        private bool UploadFile(HttpFile httpFile, TextWriter responseWriter)
        {
            var unpackPath = UnpackDestination;
            if (!Directory.Exists(unpackPath))
                Directory.CreateDirectory(unpackPath);

            var packageName = Path.GetFileNameWithoutExtension(httpFile.Name);
            if (packageName == null)
            {
                responseWriter.WriteLine("Cannot get filename without extension from uploaded file: " + httpFile.Name);
                return false;
            }

            var logFile = Path.Combine(unpackPath, packageName + ".log");
            var unpackDestination = Path.Combine(unpackPath, packageName);

            using (var fileStream = File.OpenWrite(logFile))
            using (var fileWriter = new StreamWriter(fileStream))
            using (var logWriter = new TextWriterProxy(responseWriter, fileWriter))
            {
                try
                {
                    DeleteOldArtifacts(logWriter);
                    var command = new DeployZipFileCommand(logWriter, unpackDestination);
                    command.Execute(httpFile.Value);
                    return true;
                }
                catch (Exception error)
                {
                    logWriter.WriteLine(error);
                    return false;
                }
            }
        }