コード例 #1
0
//		private void FormatFileWithNArranger(string file)
//		{
//			WaitForUnlock(file);
//
//			FileArranger fileArranger = new FileArranger(Path.Combine(templatesPath, "SimpleConfig.xml"),
//			                                             new NArrangeLogger(log));
//			if (!fileArranger.Arrange(file, null))
//				log.Error("Could not format file: " + file + ". The file has wrong code :(");
//		}

        private void FormatFileWithAStyle(string file)
        {
            WaitForUnlock(file);

            AStyleInterface astyle = new AStyleInterface(new AStyleLogger(log));

            var options = File.ReadAllLines(Path.Combine(templatesPath, "astylerc"));

            string result = astyle.FormatSource(File.ReadAllText(file),
                                                "mode=cs " + string.Join(" ", options));

            if (result == null)
            {
                log.Error("Could not format file: " + file + ". The file has wrong code :(");
            }
            else
            {
                result = result.Replace("\r\n", "\n").Replace('\r', '\n').Replace("\n", "\r\n");

                try
                {
                    File.WriteAllText(file, result);
                }
                catch (IOException e)
                {
                    log.Info("[AStyle] [Warn] Could not format file: " + file + ". Error writing file to disc: "
                             + e.Message);
                }
            }
        }
コード例 #2
0
ファイル: ModelProcessor.cs プロジェクト: pescuma/modelsharp
//		private void FormatFileWithNArranger(string file)
//		{
//			WaitForUnlock(file);
//
//			FileArranger fileArranger = new FileArranger(Path.Combine(templatesPath, "SimpleConfig.xml"),
//			                                             new NArrangeLogger(log));
//			if (!fileArranger.Arrange(file, null))
//				log.Error("Could not format file: " + file + ". The file has wrong code :(");
//		}

		private void FormatFileWithAStyle(string file)
		{
			WaitForUnlock(file);

			AStyleInterface astyle = new AStyleInterface(new AStyleLogger(log));

			var options = File.ReadAllLines(Path.Combine(templatesPath, "astylerc"));

			string result = astyle.FormatSource(File.ReadAllText(file),
			                                    "mode=cs " + string.Join(" ", options));

			if (result == null)
			{
				log.Error("Could not format file: " + file + ". The file has wrong code :(");
			}
			else
			{
				result = result.Replace("\r\n", "\n").Replace('\r', '\n').Replace("\n", "\r\n");

				try
				{
					File.WriteAllText(file, result);
				}
				catch (IOException e)
				{
					log.Info("[AStyle] [Warn] Could not format file: " + file + ". Error writing file to disc: "
					         + e.Message);
				}
			}
		}