Exemplo n.º 1
0
        public void Dispose()
        {
            if (config != null)
            {
                config.Dispose();
                config = null;
            }

            if (inputData != null)
            {
                inputData.Dispose();
                inputData = null;
            }

            if (sqlContext != null)
            {
                sqlContext.Dispose();
            }

            if (logWriter != null)
            {
                logWriter.Dispose();
                logWriter = null;
            }

            if (outputTextWriter != null)
            {
                outputTextWriter.Dispose();
                outputTextWriter = null;
            }
        }
        public void GetSetEncoding()
        {
            TextFileWriter writer = new TextFileWriter(path);
            writer.Encoding = Encoding.ASCII;

            Assert.AreEqual(Encoding.ASCII, writer.Encoding);
        }
Exemplo n.º 3
0
 public IGrammar TheRecordedMessagesAre()
 {
     return
         (VerifyStringList(() => TextFileWriter.Read())
          .Titled("The recorded message log from the service should be")
          .Grammar());
 }
Exemplo n.º 4
0
 private static void WriteRecords(TextFileWriter fileWriter, string[] records)
 {
     for (var i = 0; i < records.Length; i++)
     {
         fileWriter.WriteRecord(records[i]);
     }
 }
Exemplo n.º 5
0
        public void SplitBills_ShouldReturnListOfTripsThatContainsExpensesOwnedPerPerson()
        {
            string filePath = Path.GetFullPath("Resources/testfile.txt");

            decimal[] expected = new decimal[] { -1.99m, -8.01m, 10.01m, 0.98m, -0.98m };

            IFileReader         fileReader = new TextFileReader();
            IFileWriter         fileWriter = new TextFileWriter();
            IExpensesCalculator calculator = new ExpensesCalculator();

            SplitBillsService service = new SplitBillsService(fileReader, fileWriter, calculator);
            bool isSuccess            = service.SplitBills(filePath);

            Assert.True(isSuccess);

            int i = 0;

            foreach (var trip in service.Trips)
            {
                foreach (var participant in trip.Participants)
                {
                    Assert.Equal(expected[i++], participant.ExpensesShouldBePaid);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Writes a file containing the sha1 hash code of the file given. The file is named <paramref name="filePath"/>.sha1
        /// </summary>
        /// <param name="filePath">The file path.</param>
        public void WriteSha1HashFile(string filePath)
        {
            ITextReader reader = new TextFileReader(filePath);
            ITextWriter writer = new TextFileWriter(GetSha1FilePath(filePath));

            this.hashService.WriteHash(reader, writer);
        }
Exemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>

        public void Open()
        {
            string path = Path.Combine(root, name + extension);

            writer = new TextFileWriter(path);

            WriteHeader();
        }
Exemplo n.º 8
0
        public void GetSetEncoding()
        {
            TextFileWriter writer = new TextFileWriter(path);

            writer.Encoding = Encoding.ASCII;

            Assert.AreEqual(Encoding.ASCII, writer.Encoding);
        }
Exemplo n.º 9
0
        public DebugTextLogger()
        {
            Disposed = false;
            Boolean append   = ReflectInsightConfig.Settings.GetDebugWriterAttribute("append", "true").ToLower() == "true";
            String  filePath = ReflectInsightConfig.Settings.GetDebugWriterAttribute("path", String.Format(@"{0}RIDebugLog.txt", AppDomain.CurrentDomain.BaseDirectory));

            FTextWriter = new TextFileWriter(filePath, append, true);
        }
        public void WriteReadFile()
        {
            TextFileWriter writer = new TextFileWriter(path);
            writer.Write(content);

            TextFileReader reader = new TextFileReader(path);
            
            Assert.AreEqual(content, reader.GetString());
        }
Exemplo n.º 11
0
        public void WriteReadFile()
        {
            TextFileWriter writer = new TextFileWriter(path);

            writer.Write(content);

            TextFileReader reader = new TextFileReader(path);

            Assert.AreEqual(content, reader.GetString());
        }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            IFileReader         fileReader = new TextFileReader();
            IFileWriter         fileWriter = new TextFileWriter();
            IExpensesCalculator calculator = new ExpensesCalculator();

            IService service = new SplitBillsService(fileReader, fileWriter, calculator);

            service.Serve();
        }
Exemplo n.º 13
0
        public void WriteHashFile()
        {
            new TextFileWriter(this.path).Write(Text);

            TextFileReader reader = new TextFileReader(this.path);
            TextFileWriter writer = new TextFileWriter(this.md5Path);

            this.testee.WriteHash(reader, writer);

            Assert.AreEqual(new MD5Algorithm().ComputeHash(Text), new TextFileReader(this.md5Path).GetString());
        }
Exemplo n.º 14
0
        public void TextFileWriter_WritesFileToDisk()
        {
            var path = "file.txt";
            var encryptionService = new AesEncryptionService();
            var textFileWriter    = new TextFileWriter(path, true, encryptionService, Encoding.Unicode);

            textFileWriter.Write("Hello world!");
            var fileExists = File.Exists(path);

            Assert.True(fileExists);
        }
Exemplo n.º 15
0
        /// <summary>
        ///
        /// </summary>

        public void Close()
        {
            try
            {
                WriteFooter();
            }
            finally
            {
                writer.Dispose();
                writer = null;
            }
        }
Exemplo n.º 16
0
 /// <summary>
 /// 
 /// </summary>
 public void Close()
 {
     try
     {
         WriteFooter();
     }
     finally
     {
         writer.Dispose();
         writer = null;
     }
 }
Exemplo n.º 17
0
        /// <summary>
        /// 
        /// </summary>
        public void Dispose()
        {
            if (!isDisposed)
            {
                if (writer != null)
                {
                    writer.Dispose();
                    writer = null;
                }

                isDisposed = true;
            }
        }
Exemplo n.º 18
0
        private void Game_DataRead(object sender, DataReadEventArgs e)
        {
            if (!Config.Enabled)
            {
                return;
            }

            var fileWriter = new TextFileWriter();
            var statWriter = new CharacterStatFileWriter(fileWriter, Config.FileFolder);
            var stats      = new CharacterStats(e.Character);

            statWriter.WriteFiles(stats);
        }
Exemplo n.º 19
0
        protected override void beforeEach(IContainer scope)
        {
            Retry.Twice(() => TextFileWriter.Clear());

            Runtime.Get <MessageRecorder>().Messages.Clear();

            var browser = scope.GetInstance <IBrowserLifecycle>();

            if (browser.HasBeenStarted())
            {
                scope.GetInstance <NavigationDriver>().NavigateTo <LogoutRequest>();
            }
        }
Exemplo n.º 20
0
        public void SplitBills_ShouldNotSplitBillsWhenGivenIncorrectDataFile()
        {
            string filePath = Path.GetFullPath("Resources/IncorrectDatatestFile.txt");

            IFileReader         fileReader = new TextFileReader();
            IFileWriter         fileWriter = new TextFileWriter();
            IExpensesCalculator calculator = new ExpensesCalculator();

            SplitBillsService service = new SplitBillsService(fileReader, fileWriter, calculator);
            bool isSuccess            = service.SplitBills(filePath);

            Assert.False(isSuccess);
        }
Exemplo n.º 21
0
        public void CanSplitFileWithTemplatedName()
        {
            var writer = new TextFileWriter
            {
                FileName     = Path.Combine(Tmpdir, "${date}-${host}-${level}.log"),
                CustomFormat = "${Time} : ${Message}",
                Level        = LogLevel.All
            };

            var message1 = new LogMessage
            {
                Time = new DateTime(2010, 5, 2), HostObject = "host1", Level = LogLevel.Warn, Message = "message1"
            };

            writer.Write(message1);

            message1 = new LogMessage
            {
                Time = new DateTime(2010, 5, 2), HostObject = "host1", Level = LogLevel.Warn, Message = "message1_2"
            };
            writer.Write(message1);
            var message2 = new LogMessage
            {
                Time = new DateTime(2010, 5, 3), HostObject = "host2", Level = LogLevel.Error, Message = "message2"
            };

            writer.Write(message2);
            message2 = new LogMessage
            {
                Time = new DateTime(2010, 5, 3), HostObject = "host2", Level = LogLevel.Error, Message = "message2_1"
            };
            writer.Write(message2);



            Assert.True(File.Exists(Path.Combine(Tmpdir, "2010-05-02-host1-Warn.log")));
            Assert.True(File.Exists(Path.Combine(Tmpdir, "2010-05-03-host2-Error.log")));

            var fstlog = File.ReadAllText(Path.Combine(Tmpdir, "2010-05-02-host1-Warn.log"));
            var seclog = File.ReadAllText(Path.Combine(Tmpdir, "2010-05-03-host2-Error.log"));

            Console.WriteLine(fstlog);
            Console.WriteLine(seclog);

            Assert.AreEqual(@"2010-05-02 00:00:00 : message1
2010-05-02 00:00:00 : message1_2".LfOnly(), fstlog.Trim().LfOnly());
            Assert.AreEqual(@"2010-05-03 00:00:00 : message2
2010-05-03 00:00:00 : message2_1".LfOnly(), seclog.Trim().LfOnly());
        }
Exemplo n.º 22
0
        public static async Task WriteFacts()
        {
            AnimalFacts    facts  = new AnimalFacts(HttpClient);
            TextFileWriter writer = new TextFileWriter(WRITEFILE);

            while (true)
            {
                var fact = await facts.GetFact(new AnimalFactQuery(FactSubject.Cat));

                bool successfullyWritten = await writer.CreateOrAppend(fact.ToString());

                Console.WriteLine($"Fact {fact.Id} written to file. Successful: {successfullyWritten}");
                await Task.Delay(TimeSpan.FromSeconds(10));
            }
        }
        void GameServiceOnDataRead(object sender, DataReadEventArgs e)
        {
            var settings = settingsService.CurrentSettings;

            if (!settings.CreateFiles)
            {
                return;
            }

            var fileWriter = new TextFileWriter();
            var statWriter = new CharacterStatFileWriter(fileWriter, settings.FileFolder);
            var stats      = new CharacterStats(e.Character);

            statWriter.WriteFiles(stats);
        }
        public void ShouldBeConstructedWithAGivenDelimiterAndTextFileWriterAtGivenPath(char delimiter, char expected)
        {
            var file     = System.IO.File.Create("testFile.txt");
            var filePath = "";

            using (file)
                filePath = file.Name;

            var sut = new TextFileWriter(filePath, delimiter);

            Assert.That(sut.Delimiter, Is.EqualTo(expected));
            Assert.That(sut.FilePath, Is.EqualTo(filePath));

            sut.Dispose();
            System.IO.File.Delete(filePath);
        }
Exemplo n.º 25
0
        public void WriteExchangeRateToFile(ICollection <T> collection, FileType fileType, string filePath)
        {
            switch (fileType)
            {
            case FileType.Csv:
            case FileType.Text:
                IWriter <T> textFileWriter = new TextFileWriter <T>();
                textFileWriter.WriteToFile(collection, filePath);
                break;

            case FileType.Xml:
                IWriter <T> xmlWriter = new XmlWriter <T>();
                xmlWriter.WriteToFile(collection, filePath);
                break;
            }
        }
Exemplo n.º 26
0
        public void Dispose()
        {
            lock (this)
            {
                if (!Disposed)
                {
                    Disposed = true;
                    GC.SuppressFinalize(this);

                    if (FTextWriter != null)
                    {
                        FTextWriter.Dispose();
                        FTextWriter = null;
                    }
                }
            }
        }
Exemplo n.º 27
0
        public void WriteRecord_MultipleRecords_RecordsAreWritten()
        {
            var records = new string[]
            {
                "Line 1",
                "Line 2",
                "Line 3"
            };

            using (var fileWriter = new TextFileWriter(this.FilePath))
            {
                fileWriter.Open();

                TextFileWriterTests.WriteRecords(fileWriter, records);
            }

            TextFileWriterTests.AssertFileMatches(this.FilePath, records);
        }
Exemplo n.º 28
0
        public void Evaluate(out OutAttrubute outputAttribute)
        {
            outputAttribute = new OutAttrubute();
            try
            {
                outputAttribute.add("log", logFileName);
                sqlContext = new SQLContext(logWriter.Write);

                config = new ConfigHelper(inputParameter.ConfigExcelFilePath, logWriter.Write);

                config.Initilize();

                inputData = new InputDataHelper(inputParameter.InputExcelFilePath, logWriter.Write);

                Dictionary <string, DataTable> baseData = inputData.GetBaseData(config.GetBaseDataObjectNames());

                config.SetBaseDataObjectContext(baseData);

                config.ValidateBaseDataObjects();

                //insert data in sql
                config.EvaluateComputedDataObjects(sqlContext);

                //validate computed data types
                config.ValidateComputedDataObjects();

                var outputfile = Path.Combine(inputParameter.LogFolder, prefix + inputParameter.OutputFileName);

                outputAttribute.add("csv", outputfile);

                outputTextWriter = new TextFileWriter(outputfile);

                logWriter.Write(outputfile);

                outputTextWriter.Write(OutputMeasure.CsvHeader);


                config.WriteMeasureOutput(outputTextWriter);
            }
            catch (Exception ex)
            {
                logWriter.Write(ex.Message);
            }
        }
Exemplo n.º 29
0
        public void CanGenerateAdditionalFilesOnSizeChange()
        {
            var writer = new TextFileWriter
            {
                FileName     = Path.Combine(Tmpdir, "my.log"),
                CustomFormat = "${Time} : ${Message}",
                Level        = LogLevel.All,
                MaxSize      = 0.5m,                    //500 байт
            };

            var message1 = new LogMessage
            {
                Time = new DateTime(2010, 5, 2), HostObject = "host1", Level = LogLevel.Warn, Message = "this is a message"
            };

            for (var i = 0; i <= 10; i++)
            {
                writer.Write(message1);
            }
            message1.Message = "another message";
            for (var i = 0; i <= 10; i++)
            {
                writer.Write(message1);
            }

            Assert.True(File.Exists(Path.Combine(Tmpdir, "0001.my.log")));
            Assert.True(File.Exists(Path.Combine(Tmpdir, "0002.my.log")));

            var fstlog = File.ReadAllText(Path.Combine(Tmpdir, "0001.my.log"));
            var seclog = File.ReadAllText(Path.Combine(Tmpdir, "0002.my.log"));

            var size1 = new FileInfo(Path.Combine(Tmpdir, "0001.my.log")).Length;
            var size2 = new FileInfo(Path.Combine(Tmpdir, "0002.my.log")).Length;

            Console.WriteLine(fstlog);
            Console.WriteLine(seclog);

            Console.WriteLine(size1);
            Console.WriteLine(size2);
            Assert.LessOrEqual(519, size1);
            Assert.LessOrEqual(345, size2);
        }
Exemplo n.º 30
0
        public void Test_Writer_Can_Write_Addresses()
        {
            var stream = CreateMockStream();

            var rdr = new CSVReader(stream);

            var result = rdr.ReadCSVFile();

            var prog = new CSVReaderProgram(rdr, null);

            var addresses = prog.GetAddressesSorted(result);

            var mockWriter = new Mock <IWriter>();

            mockWriter.Setup(r => r.Write(It.IsAny <List <string> >(), It.IsAny <string>()));

            var  writer  = new TextFileWriter(mockWriter.Object);
            bool success = writer.WriteAddressesToFile(addresses, "UniqueNames.txt");

            Assert.IsTrue(success);
        }
Exemplo n.º 31
0
		public void CanSplitFileWithTemplatedName() {
			var writer = new TextFileWriter
				{
					FileName = Path.Combine(Tmpdir, "${date}-${host}-${level}.log"),
					CustomFormat = "${Time} : ${Message}",
					Level = LogLevel.All
				};

			var message1 = new LogMessage
				{Time = new DateTime(2010, 5, 2), HostObject = "host1", Level = LogLevel.Warn, Message = "message1"};
			writer.Write(message1);

			message1 = new LogMessage
				{Time = new DateTime(2010, 5, 2), HostObject = "host1", Level = LogLevel.Warn, Message = "message1_2"};
			writer.Write(message1);
			var message2 = new LogMessage
				{Time = new DateTime(2010, 5, 3), HostObject = "host2", Level = LogLevel.Error, Message = "message2"};
			writer.Write(message2);
			message2 = new LogMessage
				{Time = new DateTime(2010, 5, 3), HostObject = "host2", Level = LogLevel.Error, Message = "message2_1"};
			writer.Write(message2);
           
            

			Assert.True(File.Exists(Path.Combine(Tmpdir, "2010-05-02-host1-Warn.log")));
			Assert.True(File.Exists(Path.Combine(Tmpdir, "2010-05-03-host2-Error.log")));

			var fstlog = File.ReadAllText(Path.Combine(Tmpdir, "2010-05-02-host1-Warn.log"));
			var seclog = File.ReadAllText(Path.Combine(Tmpdir, "2010-05-03-host2-Error.log"));

			Console.WriteLine(fstlog);
			Console.WriteLine(seclog);

			Assert.AreEqual(@"2010-05-02 00:00:00 : message1
2010-05-02 00:00:00 : message1_2".LfOnly(), fstlog.Trim().LfOnly());
			Assert.AreEqual(@"2010-05-03 00:00:00 : message2
2010-05-03 00:00:00 : message2_1".LfOnly(), seclog.Trim().LfOnly());
		}
Exemplo n.º 32
0
		public void CanGenerateAdditionalFilesOnSizeChange() {
			var writer = new TextFileWriter
				{
					FileName = Path.Combine(Tmpdir, "my.log"),
					CustomFormat = "${Time} : ${Message}",
					Level = LogLevel.All,
					MaxSize = 0.5m, //500 байт
				};

			var message1 = new LogMessage
				{Time = new DateTime(2010, 5, 2), HostObject = "host1", Level = LogLevel.Warn, Message = "this is a message"};
			for (var i = 0; i <= 10; i++) {
				writer.Write(message1);
			}
			message1.Message = "another message";
			for (var i = 0; i <= 10; i++) {
				writer.Write(message1);
			}

			Assert.True(File.Exists(Path.Combine(Tmpdir, "0001.my.log")));
			Assert.True(File.Exists(Path.Combine(Tmpdir, "0002.my.log")));

			var fstlog = File.ReadAllText(Path.Combine(Tmpdir, "0001.my.log"));
			var seclog = File.ReadAllText(Path.Combine(Tmpdir, "0002.my.log"));

			var size1 = new FileInfo(Path.Combine(Tmpdir, "0001.my.log")).Length;
			var size2 = new FileInfo(Path.Combine(Tmpdir, "0002.my.log")).Length;

			Console.WriteLine(fstlog);
			Console.WriteLine(seclog);

			Console.WriteLine(size1);
			Console.WriteLine(size2);
			Assert.LessOrEqual(519, size1);
			Assert.LessOrEqual(345, size2);
		}
Exemplo n.º 33
0
 private static void WriteText( TextFileWriter stream, string content, Encoding encoding, bool flush )
 {
     stream.WriteText( content, AutoFlush || flush );
 }
Exemplo n.º 34
0
        public TextFileWriterTests()
        {
            textFileWriter = new TextFileWriter();

            Directory.CreateDirectory(dirPath);
        }
Exemplo n.º 35
0
		public void CanWriteSomeLogWithLevelChecking() {
			var man = new DefaultLogManager();
			var file = Path.GetTempFileName();
			var file2 = Path.GetTempFileName();
			var file3 = Path.GetTempFileName();
			var writer = new TextFileWriter {FileName = file, CustomFormat = "${Name}:${Level}", Level = LogLevel.Error};
			var writer2 = new TextFileWriter {FileName = file2, CustomFormat = "${Name}:${Level}", Level = LogLevel.Warn};
			var writer3 = new TextFileWriter {FileName = file3, CustomFormat = "${Name}:${Level}", Level = LogLevel.Trace};
			var logger = new BaseLogger
				{
					Writers = new[] {writer, writer2, writer3},
					Level = LogLevel.Info
					,
					Mask = "ZZZ"
				};
			var logger2 = new BaseLogger
				{
					Writers = new[] {writer, writer2, writer3},
					Level = LogLevel.Trace
					,
					Mask = "ZZZ2"
				};
			man.ErrorBehavior = InternalLoggerErrorBehavior.Throw;

			man.Loggers.Add(logger);
			man.Loggers.Add(logger2);

			var l1 = man.GetLog("ZZZ1", this);
			var l2 = man.GetLog("ZZZ2", this);
			var l3 = man.GetLog("XXX", this); //stub

			l1.Debug("");
			l2.Debug("");
			l3.Debug("");

			l1.Trace("");
			l2.Trace("");
			l3.Trace("");
			Thread.Sleep(10);
			l1.Info("");
			l2.Info("");
			l3.Info("");


			l1.Warn("");
			l2.Warn("");
			l3.Warn("");

			l1.Error("");
			l2.Error("");
			l3.Error("");

			man.Join(); //for direct file access

			var f1 = File.ReadAllText(file);
			var f2 = File.ReadAllText(file2);
			var f3 = File.ReadAllText(file3);
			Console.WriteLine(f1);
			Console.WriteLine(f2);
			Console.WriteLine(f3);
			File.Delete(file);
			File.Delete(file2);
			File.Delete(file3);
			Assert.AreEqual(@"ZZZ1:Error
ZZZ2:Error
ZZZ2:Error
".Trim().LfOnly(), f1.Trim().LfOnly());
			Assert.AreEqual(@"ZZZ1:Warning
ZZZ2:Warning
ZZZ2:Warning
ZZZ1:Error
ZZZ2:Error
ZZZ2:Error".Trim().LfOnly(), f2.Trim().LfOnly());
			Assert.AreEqual(@"ZZZ2:Trace
ZZZ1:Info
ZZZ2:Info
ZZZ2:Info
ZZZ1:Warning
ZZZ2:Warning
ZZZ2:Warning
ZZZ1:Error
ZZZ2:Error
ZZZ2:Error".Trim().LfOnly(), f3.Trim().LfOnly());
		}
 public void TextFileWriterWithNullStream()
 {
     TextFileWriter writer = new TextFileWriter(path);
     writer.Write(null, 2);
 }
 public void TextFileWriterWithNullBuffersize()
 {
     TextFileWriter writer = new TextFileWriter(path);
     writer.Write( new MemoryStream( Encoding.Default.GetBytes("text") ) , 0 );
 }
Exemplo n.º 38
0
 /// <summary>
 /// Writes a file containing the sha1 hash code of the file given. The file is named <paramref name="filePath"/>.sha1
 /// </summary>
 /// <param name="filePath">The file path.</param>
 public void WriteSha1HashFile(string filePath)
 {
     ITextReader reader = new TextFileReader(filePath);
     ITextWriter writer = new TextFileWriter(GetSha1FilePath(filePath));
     this.hashService.WriteHash(reader, writer);
 }
Exemplo n.º 39
0
        public void CanWriteSomeLogWithLevelChecking()
        {
            var man    = new DefaultLogManager();
            var file   = Path.GetTempFileName();
            var file2  = Path.GetTempFileName();
            var file3  = Path.GetTempFileName();
            var writer = new TextFileWriter {
                FileName = file, CustomFormat = "${Name}:${Level}", Level = LogLevel.Error
            };
            var writer2 = new TextFileWriter {
                FileName = file2, CustomFormat = "${Name}:${Level}", Level = LogLevel.Warn
            };
            var writer3 = new TextFileWriter {
                FileName = file3, CustomFormat = "${Name}:${Level}", Level = LogLevel.Trace
            };
            var logger = new BaseLogger
            {
                Writers = new[] { writer, writer2, writer3 },
                Level   = LogLevel.Info
                ,
                Mask = "ZZZ"
            };
            var logger2 = new BaseLogger
            {
                Writers = new[] { writer, writer2, writer3 },
                Level   = LogLevel.Trace
                ,
                Mask = "ZZZ2"
            };

            man.ErrorBehavior = InternalLoggerErrorBehavior.Throw;

            man.Loggers.Add(logger);
            man.Loggers.Add(logger2);

            var l1 = man.GetLog("ZZZ1", this);
            var l2 = man.GetLog("ZZZ2", this);
            var l3 = man.GetLog("XXX", this);             //stub

            l1.Debug("");
            l2.Debug("");
            l3.Debug("");

            l1.Trace("");
            l2.Trace("");
            l3.Trace("");
            Thread.Sleep(10);
            l1.Info("");
            l2.Info("");
            l3.Info("");


            l1.Warn("");
            l2.Warn("");
            l3.Warn("");

            l1.Error("");
            l2.Error("");
            l3.Error("");

            man.Join();             //for direct file access

            var f1 = File.ReadAllText(file);
            var f2 = File.ReadAllText(file2);
            var f3 = File.ReadAllText(file3);

            Console.WriteLine(f1);
            Console.WriteLine(f2);
            Console.WriteLine(f3);
            File.Delete(file);
            File.Delete(file2);
            File.Delete(file3);
            Assert.AreEqual(@"ZZZ1:Error
ZZZ2:Error
ZZZ2:Error
".Trim().LfOnly(), f1.Trim().LfOnly());
            Assert.AreEqual(@"ZZZ1:Warning
ZZZ2:Warning
ZZZ2:Warning
ZZZ1:Error
ZZZ2:Error
ZZZ2:Error".Trim().LfOnly(), f2.Trim().LfOnly());
            Assert.AreEqual(@"ZZZ2:Trace
ZZZ1:Info
ZZZ2:Info
ZZZ2:Info
ZZZ1:Warning
ZZZ2:Warning
ZZZ2:Warning
ZZZ1:Error
ZZZ2:Error
ZZZ2:Error".Trim().LfOnly(), f3.Trim().LfOnly());
        }
Exemplo n.º 40
0
 public TextFile(string name, string contents)
 {
     Name     = name;
     Contents = contents;
     Writer   = new TextFileWriter();
 }
Exemplo n.º 41
0
        /// <summary>
        /// 
        /// </summary>
        public void Open()
        {
            string path = Path.Combine(root, name + extension);
            writer = new TextFileWriter(path);

            WriteHeader();
        }
Exemplo n.º 42
0
        private void done_Click(object sender, EventArgs e)
        {
            //查错
            if (titleValue.Text.Equals(""))
            {
                MessageBox.Show("请填写软件名!", "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (dirValue.Text.Equals(""))
            {
                MessageBox.Show("请填写待打包文件夹!", "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (!Directory.Exists(dirValue.Text))
            {
                MessageBox.Show("打包文件夹不存在!", "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (generateShortcut.Checked && shortcutList.Items.Count == 0)
            {
                MessageBox.Show("请指定要创建快捷方式的文件或者取消勾选创建快捷方式!", "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (installPathValue.Text.Equals(""))
            {
                MessageBox.Show("请填写默认安装路径!", "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (publisherValue.Text.Equals(""))
            {
                MessageBox.Show("请填写发布者!", "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (versionValue1.Text.Equals("") || versionValue2.Text.Equals("") || versionValue3.Text.Equals("") || versionValue4.Text.Equals(""))
            {
                MessageBox.Show("请填写版本号并填写完整!", "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (versionValue1.Text.Contains(".") || versionValue2.Text.Contains(".") || versionValue3.Text.Contains(".") || versionValue4.Text.Contains("."))
            {
                MessageBox.Show("每个版本号字段中不能包含点(.)!", "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //写入配置文件
            Configure cfg = new Configure();

            cfg.Title            = titleValue.Text;
            cfg.PackedDir        = dirValue.Text;
            cfg.MainEXE          = mainExeValue.Text;
            cfg.GenerateShortcut = generateShortcut.Checked;
            List <string> shortcuts = new List <string>();

            foreach (string item in shortcutList.Items)
            {
                shortcuts.Add(item);
            }
            cfg.ShortcutList       = shortcuts;
            cfg.InstallPath        = installPathValue.Text;
            cfg.AddBootOption      = addBootOption.Checked;
            cfg.RunAfterSetup      = runafterValue.Text;
            cfg.RunBeforeUnSetup   = runBeforeUnValue.Text;
            cfg.OpenAfterSetup     = openAfterSetup.Checked;
            cfg.GenerateUninstall  = genUnsetup.Checked;
            cfg.ShowInstallProcess = showInstallWindow.Checked;
            cfg.Publisher          = publisherValue.Text;
            cfg.Version            = versionValue1.Text + "." + versionValue2.Text + "." + versionValue3.Text + "." + versionValue4.Text;
            string currentDir = AppDomain.CurrentDomain.BaseDirectory;

            if (!Directory.Exists(currentDir + "Resources"))
            {
                Directory.CreateDirectory(currentDir + "Resources");
            }
            string cfgJson = JsonConvert.SerializeObject(cfg);

            File.WriteAllText(currentDir + @"Resources\cfg.ezcfg", cfgJson);
            //写入安装包文件程序集信息
            string assemblyInfoFile = currentDir + "AssemblyInfo.cs";

            if (File.Exists(assemblyInfoFile))
            {
                TextFileWriter.ClearAll(assemblyInfoFile);
            }
            else
            {
                File.Create(assemblyInfoFile).Close();
            }
            List <string> csContent = new List <string>();

            csContent.Add("using System.Reflection;");
            csContent.Add("using System.Runtime.InteropServices;");
            csContent.Add("[assembly: AssemblyTitle(\"" + cfg.Title + "\")]");
            csContent.Add("[assembly: AssemblyProduct(\"" + cfg.Title + " 安装向导" + "\")]");
            csContent.Add("[assembly: AssemblyDescription(\"" + cfg.Title + "的安装程序。" + "\")]");
            csContent.Add("[assembly: AssemblyCompany(\"" + cfg.Publisher + "\")]");
            csContent.Add("[assembly: AssemblyCopyright(\"Copyright ©  " + DateTime.Now.ToString("yyyy") + "\")]");
            csContent.Add("[assembly: AssemblyVersion(\"" + cfg.Version + "\")]");
            csContent.Add("[assembly: AssemblyFileVersion(\"" + cfg.Version + "\")]");
            foreach (string info in csContent)
            {
                TextFileWriter.AppendText(assemblyInfoFile, info, Encoding.UTF8);
            }
            string uninstallCode;

            if (cfg.GenerateUninstall)
            {
                uninstallCode = "1";
            }
            else
            {
                uninstallCode = "0";
            }
            Program.code = cfg.PackedDir + "|" + uninstallCode;
            Close();
        }