예제 #1
0
    static void Main(string[] args)
    {
      if (args.Length < 2)
      {
        Console.WriteLine("usage: urlstrong.exe <url map> <output>");
        Environment.Exit(1);
        return;
      }

      if (!File.Exists(args[0]))
      {
        Console.WriteLine("Can't find url map: " + args[0]);
        Environment.Exit(1);
        return;
      }

      var outDir = Path.GetDirectoryName(args[1]);
      if (!String.IsNullOrEmpty(outDir) && !Directory.Exists(outDir))
      {
        Console.WriteLine("Can't find output dir: " + outDir);
        Environment.Exit(1);
        return;
      }

      using(var reader = new StreamReader(args[0]))
      using(var writer = new StreamWriter(args[1]))
      {
        var doIt = new DoIt();

        doIt.Now(reader, writer);
      }
    }
예제 #2
0
 static string GenerateCodeString(string inputFileName, string inputFileContent)
 {
   try
   {
     var doIt = new DoIt();
     using (var reader = new StringReader(inputFileContent))
     using (var writer = new StringWriter())
     {
       doIt.Now(reader, writer);
       return writer.ToString();
     }
   }
   catch (Exception err)
   {
     return "/*" + err + "*/";
   }
 }
예제 #3
0
    public override bool Execute()
    {
      var outputFiles = new List<ITaskItem>();

      foreach (var item in InputFiles)
      {
        if (item.ItemSpec.Length == 0) continue;

        var input = item.ItemSpec;
        if (!File.Exists(input))
        {
          Log.LogError("Couldn't find url file: {0}", item.ItemSpec);
          return false;
        }

        string outputDir;
        if (OutputDir != null && OutputDir.ItemSpec.Length > 0)
        {
          if (!Directory.Exists(OutputDir.ItemSpec))
          {
            Log.LogError("Output directory doesn't exist: {0}", OutputDir.ItemSpec);
            return false;
          }

          outputDir = OutputDir.ItemSpec;
        }
        else
        {
          outputDir = Path.GetDirectoryName(input);
        }

        var output = Path.Combine(outputDir, Path.GetFileNameWithoutExtension(input) + ".generated.cs");

        using (var reader = new StreamReader(input))
        using (var writer = new StreamWriter(output))
        {
          var doIt = new DoIt();

          doIt.Now(reader, writer);
          outputFiles.Add(new TaskItem(output));
        }
      }
      OutputFiles = outputFiles.ToArray<ITaskItem>();
      return true;
    }