Beispiel #1
0
      /// <summary>
      /// Takes optional args[] and root configuration. If configuration is null then
      ///  application is configured from a file co-located with entry-point assembly and
      ///   called the same name as assembly with '.config' extension, unless args are specified and "/config file"
      ///   switch is used in which case 'file' has to be locatable and readable.
      /// </summary>
      public BaseApplication(string[] args, ConfigSectionNode rootConfig)
      {
        lock(typeof(BaseApplication))
        {
          if (s_Instance != null) throw new WFormsException(StringConsts.APP_INSTANCE_ALREADY_CREATED_ERROR);

          try
          {  
            Configuration argsConfig;
            if (args != null)
              argsConfig = new CommandArgsConfiguration(args);
            else
              argsConfig = new MemoryConfiguration();

            m_CommandArgs = argsConfig.Root;

            m_ConfigRoot = rootConfig ?? GetConfiguration().Root;

            InitApplication();
        
            s_Instance = this;

          }
          catch
          {
              Destructor();
              throw;
          }

        }
      }
Beispiel #2
0
        private static void run(string[] args)
        {
            var config = new CommandArgsConfiguration(args);

              ConsoleUtils.WriteMarkupContent( typeof(Program).GetText("Welcome.txt") );

              if (config.Root["?"].Exists ||
              config.Root["h"].Exists ||
              config.Root["help"].Exists)
              {
             ConsoleUtils.WriteMarkupContent( typeof(Program).GetText("Help.txt") );
             return;
              }

              if (!config.Root.AttrByIndex(0).Exists)
              {
            ConsoleUtils.Error("Template source path is missing");
            return;
              }

              var files =  getFiles(config.Root);

              var ctypename = config.Root["c"].AttrByIndex(0).Value ?? config.Root["compiler"].AttrByIndex(0).Value;

              var ctype = string.IsNullOrWhiteSpace(ctypename)? typeof(NFX.Templatization.TextCSTemplateCompiler) : Type.GetType(ctypename);
              if (ctype == null)
               throw new NFXException("Can not create compiler type: " + (ctypename??"<none>"));

              var compiler = Activator.CreateInstance(ctype) as TemplateCompiler;

              var onode = config.Root["options"];
              if (!onode.Exists) onode = config.Root["o"];
              if (onode.Exists)
              {
            ConfigAttribute.Apply(compiler, onode);
            var asms = onode.AttrByName("ref").ValueAsString(string.Empty).Split(new char[] {';'}, StringSplitOptions.RemoveEmptyEntries);
            foreach(var asm in asms)
             compiler.ReferenceAssembly(asm);
              }

              showOptions(compiler);

              foreach(var f in files)
              {
             var src = new FileTemplateStringContentSource(f);
             ConsoleUtils.Info("Included: " + src.GetName(50));
             compiler.IncludeTemplateSource(src);
              }

              compiler.Compile();

              if (compiler.HasErrors)
              {
            showErrors(compiler, config.Root);
            return;
              }

              if (config.Root["src"].Exists)
            writeToDiskCompiledSourceFiles(compiler, config.Root);
        }
Beispiel #3
0
        private static void run(string[] args)
        {
            var config = new CommandArgsConfiguration(args);

              ConsoleUtils.WriteMarkupContent( typeof(Program).GetText("Welcome.txt") );

              if (config.Root["?", "h", "help"].Exists)
              {
             ConsoleUtils.WriteMarkupContent( typeof(Program).GetText("Help.txt") );
             return;
              }

              if (!config.Root.AttrByIndex(0).Exists)
            throw new Exception("Schema file missing");

              var schemaFileName = config.Root.AttrByIndex(0).Value;
              if (string.IsNullOrWhiteSpace(schemaFileName))
            throw new Exception("Schema empty path");

              schemaFileName = Path.GetFullPath(schemaFileName);

              ConsoleUtils.Info("Trying to load schema: " + schemaFileName);

              var schema = new Schema(schemaFileName, new string[] { Path.GetDirectoryName(schemaFileName) });

              ConsoleUtils.Info("Schema file loaded OK");

              var tcompiler = typeof(MySQLCompiler);
              var tcname = config.Root["c", "compiler"].AttrByIndex(0).Value;

              if (!string.IsNullOrWhiteSpace(tcname))
            tcompiler = Type.GetType(tcname, true);

              var compiler = Activator.CreateInstance(tcompiler, new object[] { schema }) as Compiler;

              if (compiler==null) throw new Exception("Could not create compiler type");

              compiler.OutputPath = Path.GetDirectoryName(schemaFileName);

              var options = config.Root["o","opt","options"];
              if (options.Exists)
            compiler.Configure(options);

              ConsoleUtils.Info("Compiler information:");
              Console.WriteLine("   Type={0}\n   Name={1}\n   Target={2}".Args(compiler.GetType().FullName, compiler.Name, compiler.Target) );
              Console.WriteLine("   OutPath={0}".Args(compiler.OutputPath) );
              Console.WriteLine("   OutPrefix={0}".Args(compiler.OutputPrefix) );
              Console.WriteLine("   CaseSensitive={0}".Args(compiler.CaseSensitiveNames) );

              compiler.Compile();

              foreach(var error in compiler.CompileErrors)
            ConsoleUtils.Error(error.ToMessageWithType());

              if (compiler.CompileException!=null)
              {
            ConsoleUtils.Warning("Compile exception thrown");
            throw compiler.CompileException;
              }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Configuration argsConfig = new CommandArgsConfiguration(args);

            if (argsConfig.Root[CommonApplicationLogic.CONFIG_SWITCH].Exists)
                using(new ServiceBaseApplication(args, null))
                    run(App.ConfigRoot, true);
            else
                run(argsConfig.Root, false);
        }
Beispiel #5
0
        private static void run(string[] args)
        {
            var config = new CommandArgsConfiguration(args);

              if (config.Root["?"].Exists ||
              config.Root["h"].Exists ||
              config.Root["help"].Exists)
              {
             ConsoleUtils.WriteMarkupContent( typeof(Program).GetText("Help.txt") );
             return;
              }

              if (!config.Root.AttrByIndex(0).Exists)
              {
            Console.WriteLine("Specify ';'-delimited assembly list");
            return;
              }

              var manager = new InventorizationManager(config.Root.AttrByIndex(0).Value);

              var fnode = config.Root["f"];
              if (!fnode.Exists) fnode = config.Root["filter"];
              if (fnode.Exists)
               ConfigAttribute.Apply(manager, fnode);

              foreach(var n in config.Root.Children.Where(chi=>chi.IsSameName("s") || chi.IsSameName("strat") || chi.IsSameName("strategy")))
              {
            var tname = n.AttrByIndex(0).Value ?? "<unspecified>";
            Type t = Type.GetType(tname);
            if (t == null)
               throw new NFXException("Can not create strategy type: " + tname);

            var strategy = Activator.CreateInstance(t) as IInventorization;

            if (strategy == null)
               throw new NFXException("The supplied type is not strategy: " + tname);

            manager.Strategies.Add(strategy);
              }

              if (manager.Strategies.Count==0)
              {
            manager.Strategies.Add( new BasicInventorization());
            manager.Strategies.Add( new RecordModelInventorization());
              }

               // if (config.Root["any"].Exists)
               //  manager.OnlyAttributed = false;

            var result = new XMLConfiguration();
            result.Create("inventory");
            manager.Run(result.Root);
            Console.WriteLine(result.SaveToString());
        }
Beispiel #6
0
        static void Main(string[] str_args)
        {
            Console.WriteLine("NFX License Block Updater");
              Console.WriteLine(" Usage:");
              Console.WriteLine("   licupd  path lfile [-pat pattern] [-insert]");
              Console.WriteLine("    path - path to code base");
              Console.WriteLine("    lfile - path to license file");
              Console.WriteLine("    [-pat pattern] - optional pattern search such as '-pat *.txt'. Assumes '*.cs' if omitted");
              Console.WriteLine("    [-insert] - optional switch that causes license block insertion when missing");

              var args = new CommandArgsConfiguration(str_args);

              var path =  args.Root.AttrByIndex(0).ValueAsString(string.Empty);

              var license = File.ReadAllText(args.Root.AttrByIndex(1).ValueAsString(string.Empty));

              var fpat = args.Root["pat"].AttrByIndex(0).ValueAsString("*.cs");

              var insert = args.Root["insert"].Exists;

              var regexp = new Regex(
              @"/\*<FILE_LICENSE>[\s*|\S*]{0,}</FILE_LICENSE>\*/"

              );

              var replaced = 0;
              var inserted = 0;

              foreach(var fn in path.AllFileNamesThatMatch(fpat, true))
              {
               var content = File.ReadAllText(fn);

               if (regexp.Match(content).Success)
               {
              Console.Write("Matched:  " + fn);
              File.WriteAllText(fn, regexp.Replace(content, license));
              Console.WriteLine("   Replaced.");
              replaced++;
               }
               else
            if (insert)
            {
              content = license + Environment.NewLine + content;
              File.WriteAllText(fn, content);
              Console.WriteLine("Inserted:  " + fn);
              inserted++;
            }
              }//freach file

             Console.WriteLine(string.Format("Total Replaced: {0}  Inserted: {1}", replaced, inserted));
             Console.WriteLine("Strike <enter>");
             Console.ReadLine();
        }
Beispiel #7
0
 private void btnCommandArgs_Click(object sender, EventArgs e)
 {
     try
     {
         var args = this.txtCommandArgs.Text.Split(new char[] {' '} ,StringSplitOptions.RemoveEmptyEntries);
         var conf = new CommandArgsConfiguration(args);
         this.resultCommandArgs.Text = conf.ToLaconicString();
     }
     catch (Exception ex)
     {
         this.resultCommandArgs.Text = ex.ToMessageWithType();
     }
 }
Beispiel #8
0
        private static void run(string[] args)
        {
            var config = new CommandArgsConfiguration(args);

              ConsoleUtils.WriteMarkupContent( typeof(Program).GetText("Welcome.txt") );

              if (config.Root["?", "h", "help"].Exists)
              {
             ConsoleUtils.WriteMarkupContent( typeof(Program).GetText("Help.txt") );
             return;
              }

              if (!config.Root.AttrByIndex(0).Exists)
            throw new Exception("Assembly is missing");

              var afn = config.Root.AttrByIndex(0).Value;
              if (string.IsNullOrWhiteSpace(afn))
            throw new Exception("Assembly empty path");

              afn = Path.GetFullPath(afn);

              ConsoleUtils.Info("Trying to load assembly: " + afn);

              var asm = Assembly.LoadFile(afn);

              ConsoleUtils.Info("Assembly file loaded OK");

              var tcompiler = typeof(CSharpGluecCompiler);
              var tcname = config.Root["c", "compiler"].AttrByIndex(0).Value;

              if (!string.IsNullOrWhiteSpace(tcname))
            tcompiler = Type.GetType(tcname, true);

              var compiler = Activator.CreateInstance(tcompiler, new object[] { asm }) as GluecCompiler;

              if (compiler==null) throw new Exception("Could not create compiler type");

              compiler.OutPath = Path.GetDirectoryName(afn);
              compiler.FilePerContract = true;
              compiler.NamespaceFilter = config.Root["f", "flt", "filter"].AttrByIndex(0).Value;

              ConfigAttribute.Apply(compiler, config.Root["o", "opt", "options"]);

              ConsoleUtils.Info("Namespace filter: " + compiler.NamespaceFilter);
              compiler.Compile();
        }
Beispiel #9
0
        public void GeneralCmdArgs()
        {
            var conf = new CAC(args);

            Assert.AreEqual(@"tool.exe", conf.Root.AttrByIndex(0).ValueAsString());
            Assert.AreEqual(@"c:\input.file", conf.Root.AttrByIndex(1).ValueAsString());
            Assert.AreEqual(@"d:\output.file", conf.Root.AttrByIndex(2).ValueAsString());

            Assert.AreEqual(true, conf.Root["compress"].Exists);
            Assert.AreEqual(100, conf.Root["compress"].AttrByName("level").ValueAsInt());
            Assert.AreEqual("zip", conf.Root["compress"].AttrByName("method").ValueAsString());

            Assert.AreEqual(true, conf.Root["shadow"].Exists);
            Assert.AreEqual("fast", conf.Root["shadow"].AttrByIndex(0).Value);
            Assert.AreEqual(1024, conf.Root["shadow"].AttrByName("swap").ValueAsInt());

            Assert.AreEqual(true, conf.Root["large"].Exists);
        }
        public void GeneralCmdArgs()
        {
            var conf = new CAC(args);

              Assert.AreEqual(@"tool.exe", conf.Root.AttrByIndex(0).ValueAsString());
              Assert.AreEqual(@"c:\input.file", conf.Root.AttrByIndex(1).ValueAsString());
              Assert.AreEqual(@"d:\output.file", conf.Root.AttrByIndex(2).ValueAsString());

              Assert.AreEqual(true, conf.Root["compress"].Exists);
              Assert.AreEqual(100, conf.Root["compress"].AttrByName("level").ValueAsInt());
              Assert.AreEqual("zip", conf.Root["compress"].AttrByName("method").ValueAsString());

              Assert.AreEqual(true, conf.Root["shadow"].Exists);
              Assert.AreEqual("fast", conf.Root["shadow"].AttrByIndex(0).Value);
              Assert.AreEqual(1024, conf.Root["shadow"].AttrByName("swap").ValueAsInt());

              Assert.AreEqual(true, conf.Root["large"].Exists);
        }