Exemple #1
0
        private static void run(string[] args)
        {
            var config = new CommandArgsConfiguration(args);


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

            if (config.Root["?", "h", "help"].Exists)
            {
                ConsoleUtils.WriteMarkupContent(typeof(ProgramBody).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();
        }
Exemple #2
0
        static int Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            App.Current.OnExecute(async() =>
                                  await Watch(CommandArgsConfiguration.Parse(App.Current, args))
                                  );

            return(App.Current.Execute(args));
        }
Exemple #3
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();
        }
Exemple #4
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();
     }
 }
Exemple #5
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);
            }
        }
Exemple #6
0
        private static void run(string[] args)
        {
            var config = new CommandArgsConfiguration(args);


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

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


            var asmFileName = config.Root.AttrByIndex(0).Value;
            var path        = config.Root.AttrByIndex(1).Value;

            if (asmFileName.IsNullOrWhiteSpace())
            {
                throw new Exception("Assembly missing");
            }
            if (path.IsNullOrWhiteSpace())
            {
                throw new Exception("Output path is missing");
            }

            if (!File.Exists(asmFileName))
            {
                throw new Exception("Assembly file does not exist");
            }
            if (!Directory.Exists(path))
            {
                throw new Exception("Output path does not exist");
            }

            var assembly = Assembly.LoadFrom(asmFileName);

            using (var generator = new CodeGenerator())
            {
                generator.RootPath        = path;
                generator.CodeSegregation = config.Root["c", "code"].ValueAsEnum(CodeGenerator.GeneratedCodeSegregation.FilePerNamespace);
                generator.Generate(assembly);
            }
        }
Exemple #7
0
        //perform the core construction of app instance,
        //this is a method because of C# inability to control ctor chaining sequence
        //this is framework internal code, developers do not call
        protected void Constructor(bool allowNesting,
                                   string[] cmdLineArgs,
                                   ConfigSectionNode rootConfig,
                                   IApplicationDependencyInjectorImplementation defaultDI = null)
        {
            m_AllowNesting = allowNesting;

            if (cmdLineArgs != null && cmdLineArgs.Length > 0)
            {
                var acfg = new CommandArgsConfiguration(cmdLineArgs)
                {
                    Application = this
                };
                m_CommandArgs = acfg.Root;
            }
            else
            {
                var acfg = new MemoryConfiguration {
                    Application = this
                };
                m_CommandArgs = acfg.Root;
            }

            m_ConfigRoot = rootConfig ?? GetConfiguration().Root;
            m_Singletons = new ApplicationSingletonManager();
            m_NOPApplicationSingletonManager = new NOPApplicationSingletonManager();
            m_DefaultDependencyInjector      = defaultDI ?? new ApplicationDependencyInjector(this);
            m_Realm = new ApplicationRealmBase(this);

            m_NOPLog             = new NOPLog(this);
            m_NOPModule          = new NOPModule(this);
            m_NOPInstrumentation = new NOPInstrumentation(this);
            m_NOPDataStore       = new NOPDataStore(this);
            m_NOPObjectStore     = new NOPObjectStore(this);
            m_NOPGlue            = new NOPGlue(this);
            m_NOPSecurityManager = new NOPSecurityManager(this);
            m_DefaultTimeSource  = new DefaultTimeSource(this);
            m_NOPEventTimer      = new NOPEventTimer(this);
        }
        /// <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 ServiceBaseApplication(string[] args, ConfigSectionNode rootConfig)
        {
            lock (typeof(ServiceBaseApplication))
            {
                if (s_Instance != null)
                {
                    throw new NFXException(StringConsts.SVCAPP_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;
                }
            }
        }
Exemple #9
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());
            }



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

            var result = new XMLConfiguration();

            result.Create("inventory");
            manager.Run(result.Root);
            Console.WriteLine(result.SaveToString());
        }
Exemple #10
0
        private static void run(string[] args)
        {
            var config = new CommandArgsConfiguration(args);


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

            if (config.Root["?", "h", "help"].Exists)
            {
                ConsoleUtils.WriteMarkupContent(typeof(ProgramBody).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(MsSqlCompiler);
            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));
            if (compiler is RDBMSCompiler)
            {
                Console.WriteLine("   DomainsSearchPath={0}".Args(((RDBMSCompiler)compiler).DomainSearchPaths));
            }
            Console.WriteLine("   OutPath={0}".Args(compiler.OutputPath));
            Console.WriteLine("   OutPrefix={0}".Args(compiler.OutputPrefix));
            Console.WriteLine("   CaseSensitivity={0}".Args(compiler.NameCaseSensitivity));

            compiler.Compile();



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


            if (compiler.CompileException != null)
            {
                ConsoleUtils.Warning("Compile exception thrown");
                throw compiler.CompileException;
            }
        }
Exemple #11
0
        private static void run(string[] args)
        {
            var config = new CommandArgsConfiguration(args);


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

            if (config.Root["?"].Exists ||
                config.Root["h"].Exists ||
                config.Root["help"].Exists)
            {
                ConsoleUtils.WriteMarkupContent(typeof(ProgramBody).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(Azos.Templatization.TextCSTemplateCompiler) : Type.GetType(ctypename);

            if (ctype == null)
            {
                throw new AzosException("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);
            }
        }
Exemple #12
0
        private static void run(string[] args)
        {
            var config = new CommandArgsConfiguration(args);


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

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


            var asmFileName = config.Root.AttrByIndex(0).Value;
            var path        = config.Root.AttrByIndex(1).Value;

            if (asmFileName.IsNullOrWhiteSpace())
            {
                throw new Exception("Assembly missing");
            }
            if (path.IsNullOrWhiteSpace())
            {
                throw new Exception("Output path is missing");
            }

            if (!File.Exists(asmFileName))
            {
                throw new Exception("Assembly file does not exist");
            }
            if (!Directory.Exists(path))
            {
                throw new Exception("Output path does not exist");
            }

            //20191106 DKh
            //var assembly = Assembly.LoadFrom(asmFileName);
            Assembly assembly;

            try
            {
                assembly = Assembly.LoadFrom(asmFileName);

                var allTypes = CodeGenerator.DefaultScanForAllRowTypes(assembly);

                //this throws on invalid loader exception as
                var schemas = allTypes.Select(t => Schema.GetForTypedDoc(t)).ToArray();//it touches all type/schemas because of .ToArray()
                ConsoleUtils.Info("Assembly contains {0} data document schemas".Args(schemas.Length));
            }
            catch (Exception asmerror)
            {
                ConsoleUtils.Error("Could not load assembly: `{0}`".Args(asmFileName));
                ConsoleUtils.Warning("Exception: ");
                ConsoleUtils.Warning(asmerror.ToMessageWithType());
                Console.WriteLine();
                ConsoleUtils.Warning(new WrappedExceptionData(asmerror).ToJson(JsonWritingOptions.PrettyPrintASCII));
                throw;
            }

            using (var generator = new CodeGenerator())
            {
                generator.RootPath          = path;
                generator.CodeSegregation   = config.Root["c", "code"].AttrByIndex(0).ValueAsEnum(CodeGenerator.GeneratedCodeSegregation.FilePerNamespace);
                generator.HeaderDetailLevel = config.Root["hdr", "header", "hl"].AttrByIndex(0).ValueAsInt(255);
                generator.Generate(assembly);
            }
        }