Ejemplo n.º 1
0
 public void Load(ArgInfo argInfo)
 {
     _argInfo = argInfo;
     _origArg = new ArgInfo {
         upLimit = argInfo.upLimit, downLimit = argInfo.downLimit, argDataSql = argInfo.argDataSql, argName = argInfo.argName, argNo = argInfo.argNo
     };
     argPanel.DataContext = _argInfo;
     BindData();
 }
Ejemplo n.º 2
0
 public SettingArgBuilder(StandardConsoleCommandBase command, string argName, string description)
 {
     Contract.Requires(command != null);
     Contract.Requires(argName != null);
     this.command       = command;
     argInfo            = new ArgInfo(argName, description);
     argInfo.IsSetting  = true;
     argInfo.IsRequired = true;
     command.settingsArgs.Add(argInfo.ArgName.ToLowerInvariant(), argInfo);
 }
Ejemplo n.º 3
0
        void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var listBox = sender as ListBox;

            if (listBox == null)
            {
                return;
            }
            _selectedArgInfo = listBox.SelectedItem as ArgInfo;
        }
Ejemplo n.º 4
0
            public static ArgInfo Parse(string file)
            {
                var factory = StartHelper.CreateImportExportFactory();

                var ret = new ArgInfo();

                ret.Importer   = factory.Create(file);
                ret.Extension  = factory.Extension;
                ret.ModuleName = factory.ModuleName;
                return(ret);
            }
Ejemplo n.º 5
0
 public static dynamic GetValue(this Parameter parameter, object value, ArgInfo argInfo)
 {
     if (argInfo != null && argInfo.IsValueEncrypted && value != null)
     {
         return(Convert.ChangeType(Convert.ToString(value).Decrypt(), Type.GetType(parameter.DataType)));
     }
     else if (value != null)
     {
         return(Convert.ChangeType(value, Type.GetType(parameter.DataType)));
     }
     return(null);
 }
Ejemplo n.º 6
0
        public BindSignature(HostTarget target, string name, Type[] typeArgs, object[] args)
        {
            targetInfo    = new TargetInfo(target);
            this.typeArgs = typeArgs;
            this.name     = name;

            argData = new ArgInfo[args.Length];
            for (var index = 0; index < args.Length; index++)
            {
                argData[index] = new ArgInfo(args[index]);
            }
        }
Ejemplo n.º 7
0
 public SwitchArgBuilder(
     StandardConsoleCommandBase command, string argName, string description, Action <bool, CommandLineParsingContext> valueAction)
 {
     Contract.Requires(command != null);
     Contract.Requires(argName != null);
     Contract.Requires(valueAction != null);
     this.command            = command;
     argInfo                 = new ArgInfo(argName, description);
     argInfo.IsSetting       = true;
     argInfo.IsRequired      = true;
     argInfo.ArgType         = typeof(bool);
     argInfo.BoolValueAction = valueAction;
     command.settingsArgs.Add(argInfo.ArgName.ToLowerInvariant(), argInfo);
 }
Ejemplo n.º 8
0
        public BindSignature(Type context, BindingFlags flags, HostTarget target, string name, Type[] typeArgs, object[] args)
        {
            this.context  = context;
            this.flags    = flags;
            targetInfo    = new TargetInfo(target);
            this.name     = name;
            this.typeArgs = typeArgs;

            argData = new ArgInfo[args.Length];
            for (var index = 0; index < args.Length; index++)
            {
                argData[index] = new ArgInfo(args[index]);
            }
        }
Ejemplo n.º 9
0
        public static string UpdateArgConfig(ArgInfo argInfo)
        {
            var origArgInfoList =
                WindowsTools.XmlDeseerializer(typeof(List <ArgInfo>), ArgConfigPath, out _tmpResult) as List <ArgInfo>;

            if (origArgInfoList == null || _tmpResult != "")
            {
                return(_tmpResult);
            }
            origArgInfoList.Remove(origArgInfoList.Single(p => p.argID == argInfo.argID));
            origArgInfoList.Add(argInfo);
            origArgInfoList =
                origArgInfoList.OrderBy(p => p.templateID).ThenBy(p => p.argType).OrderBy(p => p.argName).ToList();
            WindowsTools.XmlSerialize(origArgInfoList, ArgConfigPath, out _tmpResult);
            return(_tmpResult);
        }
        private ArgInfo[] ParaInfos(string s)
        {
            var info = new ArgInfo[s.Length];

            for (var i = 0; i < s.Length; ++i)
            {
                info[i] = new ArgInfo
                {
                    ParaName   = ParameterNames[i],
                    Type       = s[i] == '0' ? ParameterTypes[i] : ParameterTypes[i].BaseType,
                    Scalar     = s[i] != '0',
                    ParaInvoke = s[i] == '0' ? "{0}.{1}" : "{0}"
                };
            }
            return(info);
        }
Ejemplo n.º 11
0
        protected override void SynchronizeItem(object o, XmlElement e)
        {
            ArgInfo ai = (ArgInfo)o;

            AssertDocsElement(e);

            XmlElement type = AssertChildElement(e, "type");

            type.InnerText = ai.type.ToString();

            if (ai.default_to != null)
            {
                XmlElement dflt = AssertChildElement(e, "default_to");
                dflt.InnerText = ai.default_to;
            }

            string flags = "";

            if ((ai.flags & ArgFlags.Optional) != 0)
            {
                flags += "optional ";
            }
            if ((ai.flags & ArgFlags.Multi) != 0)
            {
                flags += "multi ";
            }
            if ((ai.flags & ArgFlags.Default) != 0)
            {
                flags += "default ";
            }
            if ((ai.flags & ArgFlags.Ordered) != 0)
            {
                flags += "ordered ";
            }
            if ((ai.flags & ArgFlags.DefaultOrdered) != 0)
            {
                flags += "default_ordered ";
            }

            XmlElement f = AssertChildElement(e, "flags");

            f.InnerText = flags;
        }
Ejemplo n.º 12
0
 public static dynamic GetValue(this ArgInfo argInfo, object[] value)
 {
     if (value == null || value.Count() < 1)
     {
         return(null);
     }
     if (value[argInfo.Index] == null)
     {
         return(null);
     }
     else if (argInfo.IsValueEncrypted)
     {
         return(Convert.ChangeType(Convert.ToString(value[argInfo.Index]).Decrypt(), Type.GetType(argInfo.DataType)));
     }
     else
     {
         return(Convert.ChangeType(value[argInfo.Index], Type.GetType(argInfo.DataType)));
     }
 }
Ejemplo n.º 13
0
        protected override void Run()
        {
            FileSysEmulator fs = new FileSysEmulator();

            foreach (String drv in ConfigurationManager.AppSettings["drives"].Split(','))
            {
                fs.AddDrive(drv.Trim());
            }

            ArgInfo ai = new ArgInfo(ConfigurationManager.AppSettings["current-drive"] + ":\\");

            ai.Resolve(fs);
            fs.CurrentDrive = (FileSysEmulator.FsDrive)fs.SearchResolvedPath(ai);


            Int32 lineNumber = 1;

            using (FileStream stm = new FileStream(_inputBatchFileName, FileMode.Open, FileAccess.Read))
                using (StreamReader rd = new StreamReader(stm))
                    while (!rd.EndOfStream)
                    {
                        String cmdText = rd.ReadLine();
                        if (cmdText.Trim().Length > 0)
                        {
                            try
                            {
                                FileSysEmulator.CommandBase cmd = FileSysEmulator.CommandBase.Create(cmdText);
                                fs.ExecuteCommandAgainstFileSystem(cmd);
                            }
                            catch (Exception e)
                            {
                                throw new ApplicationException(String.Format("Command '{0}' at line '{1:d}' is failed.", cmdText, lineNumber), e);
                            }
                        }
                        ++lineNumber;
                    }

            XmlDocument doc = fs.GetFileSystemContent();

            fs.PrintTo(Console.Out);
        }
Ejemplo n.º 14
0
        public virtual int?ParseArgs(IConsoleEnvironment consoleEnvironment, IList <string> args)
        {
            int positionalArgsCovered = 0;

            foreach (string arg in args)
            {
                int?exitCode;
                if (arg.StartsWith("-", StringComparison.OrdinalIgnoreCase))
                {
                    exitCode = ParseNonPositionalArg(consoleEnvironment, arg);
                    if (exitCode.HasValue)
                    {
                        return(exitCode);
                    }
                }
                else
                {
                    exitCode = ParsePositionalArg(consoleEnvironment, positionalArgsCovered, arg);
                    if (exitCode.HasValue)
                    {
                        return(exitCode);
                    }
                    positionalArgsCovered++;
                }
            }

            for (int i = positionalArgsCovered; i < positionalArgs.Count; i++)
            {
                ArgInfo arg = positionalArgs[i];
                if (arg.IsRequired)
                {
                    consoleEnvironment.ErrWriter.WriteLine("Required argument {0} is missing", arg.ArgName);
                    return(2);
                }
            }

            return(null);
        }
Ejemplo n.º 15
0
        static AppArgs()
        {
            switch1Help[help]         =
                switch1Help[question] = new ArgInfo("-help|-? [command]",
                                                    "Displays either generic or command specific help info.");
            switch1Help[e] = new ArgInfo("-e",
                                         "Compiles script into console application executable.");
            switch1Help[ew] = new ArgInfo("-ew",
                                          "Compiles script into Windows application executable.");
            switch1Help[c] = new ArgInfo("-c[:<0|1>]",
                                         "Uses compiled file (cache file .compiled) if found (to improve performance).",
                                         "   -c:1|-c  enable caching\n" +
                                         "   -c:0     disable caching (which might be enabled globally);");
            switch1Help[ca] = new ArgInfo("-ca",
                                          "Compiles script file into assembly (cache file .compiled) without execution.");
            switch1Help[cd] = new ArgInfo("-cd",
                                          "Compiles script file into assembly (.dll) without execution.");
            switch1Help[check] = new ArgInfo("-check",
                                             "Checks script for errors without execution.");
            switch1Help[proj] = new ArgInfo("-proj",
                                            "Shows script 'project info' - script and all its dependencies.");

            switch1Help[cache] = new ArgInfo("-cache[:<ls|trim|clear>]",
                                             "Performs script cache operations.",
                                             " ls    - lists all cache items.\n" +
                                             " trim  - removes all abandoned cache items.\n" +
                                             " clear - removes all cache items.");
            switch1Help[co] = new ArgInfo("-co:<options>",
                                          "Passes compiler options directly to the language compiler.",
                                          "(e.g.  -co:/d:TRACE pass /d:TRACE option to C# compiler\n" +
                                          "or  -co:/platform:x86 to produce Win32 executable)");
            switch1Help[s] = new ArgInfo("-s",
                                         "Prints content of sample script file",
                                         "(e.g. " + AppInfo.appName + " /s > sample.cs).");
            switch1Help[ac]            =
                switch1Help[autoclass] = new ArgInfo("-wait[:prompt]",
                                                     "Waits for user input after the execution before exiting.",
                                                     "If specified the execution will proceed with exit only after any STD input is received.\n" +
                                                     "Applicable for console mode only.\n" +
                                                     "prompt - if none specified 'Press any key to continue...' will be used\n");

            switch1Help[wait] = new ArgInfo("-ac|-autoclass",
                                            "Automatically generates 'entry point' class if the script doesn't define any.",
                                            "\n" +
                                            "    using System;\n" +
                                            "                 \n" +
                                            "    void Main()\n" +
                                            "    {\n" +
                                            "        Console.WriteLine(\"Hello World!\";\n" +
                                            "    }");
            switch2Help[nl] = new ArgInfo("-nl",
                                          "No logo mode: No banner will be shown/printed at execution time.",
                                          "Applicable for console mode only.");
            switch2Help[d]       =
                switch2Help[dbg] = new ArgInfo("-dbg|-d",
                                               "Forces compiler to include debug information.");
            switch2Help[l] = new ArgInfo("-l",
                                         "'local' (makes the script directory a 'current directory').");
            switch2Help[ver]   =
                switch2Help[v] = new ArgInfo("-v",
                                             "Prints CS-Script version information.");
            switch2Help[inmem] = new ArgInfo("-inmem[:<0|1>]",
                                             "Loads compiled script in memory before execution.",
                                             "This mode allows preventing locking the compiled script file. \n" +
                                             "Can be beneficial for fine concurrency control as it allows changing \n" +
                                             "and executing the scripts that are already loaded (being executed). This mode is incompatible \n" +
                                             "with the scripting scenarios that require scriptassembly to be file based (e.g. advanced Reflection).\n" +
                                             "    -inmem:1   enable caching (which might be disabled globally;\n" +
                                             "    -inmem:0   disable caching (which might be enabled globally;");
            switch2Help[verbose] = new ArgInfo("-verbose",
                                               "Prints runtime information during the script execution.",
                                               "(applicable for console clients only)");
            switch2Help[noconfig] = new ArgInfo("-noconfig[:<file>]",
                                                "Do not use default CS-Script config file or use alternative one.",
                                                "Value \"out\" of the <file> is reserved for creating the config file (css_config.xml) with the default settings.\n" +
                                                "(e.g. " + AppInfo.appName + " -noconfig sample.cs\n" +
                                                AppInfo.appName + " -noconfig:c:\\cs-script\\css_VB.dat sample.vb)");
            switch2Help[@out] = new ArgInfo("-out[:<file>]",
                                            "Forces the script to be compiled into a specific location.",
                                            "Used only for very fine hosting tuning.\n" +
                                            "(e.g. " + AppInfo.appName + " -out:%temp%\\%pid%\\sample.dll sample.cs");
            switch2Help[sconfig] = new ArgInfo("-sconfig[:file]",
                                               "Uses script config file or custom config file as a .NET app.config.",
                                               "This option might be useful for running scripts, which usually cannot be executed without configuration \n" +
                                               "file (e.g. WCF, Remoting).\n\n" +
                                               "(e.g. if -sconfig is used the expected config file name is <script_name>.cs.config or <script_name>.exe.config\n" +
                                               "if -sconfig:myApp.config is used the expected config file name is myApp.config)");
            switch2Help[r] = new ArgInfo("-r:<assembly 1>:<assembly N>",
                                         "Uses explicitly referenced assembly.", "It is required only for " +
                                         "rare cases when namespace cannot be resolved into assembly.\n" +
                                         "(e.g. " + AppInfo.appName + " /r:myLib.dll myScript.cs).");
            switch2Help[dir] = new ArgInfo("-dir:<directory 1>,<directory N>",
                                           "Adds path(s) to the assembly probing directory list.",
                                           "You can use a reserved word 'show' as a directory name to print the configured probing directories.\n" +
                                           "(e.g. " + AppInfo.appName + " -dir:C:\\MyLibraries myScript.cs\n" +
                                           " " + AppInfo.appName + " -dir:-show).");
            switch2Help[pc] =
                switch2Help[precompiler] = new ArgInfo("-precompiler[:<file 1>,<file N>]",
                                                       "Specifies custom precompiler. This can be either script or assembly file.",
                                                       "Alias - pc[:<file 1>,<file N>]\n" +
                                                       "If no file(s) specified prints the code template for the custom precompiler.\n" +
                                                       "There is a special reserved word '" + CSSUtils.noDefaultPrecompilerSwitch + "' to be used as a file name.\n" +
                                                       "It instructs script engine to prevent loading any built-in precompilers \n" +
                                                       "like the one for removing shebang before the execution.\n" +
                                                       "(see Precompilers chapter in the documentation)");
            switch2Help[provider] = new ArgInfo("-provider:<file>",
                                                "Location of alternative code provider assembly.",
                                                "If set it forces script engine to use an alternative code compiler.\n" +
                                                "(see \"Alternative compilers\" chapter in the documentation)");
            switch2Help[syntax] = new ArgInfo("-syntax",
                                              "Prints documentation for CS-Script specific C# syntax.");
            switch2Help[commands] =
                switch2Help[cmd]  = new ArgInfo("-commands|-cmd",
                                                "Prints list of supporeted commands (arguments).");

            miscHelp["file"] = new ArgInfo("file",
                                           "Specifies name of a script file to be run.");
            miscHelp["params"] = new ArgInfo("params",
                                             "Specifies optional parameters for a script file to be run.");
            miscHelp["//x"] = new ArgInfo("//x",
                                          "Launch debugger just before starting the script.");


            #region SyntaxHelp

            syntaxHelp = "**************************************\n" +
                         "Script specific syntax\n" +
                         "**************************************\n" +
                         "\n" +
                         "Engine directives:\n" +
                         "------------------------------------\n" +
                         "//css_include <file>;\n" +
                         "\n" +
                         "Alias - //css_inc\n" +
                         "\n" +
                         "file - name of a script file to be included at compile-time.\n" +
                         "\n" +
                         "This directive is used to include one script into another one.It is a logical equivalent of '#include' in C++.\n" +
                         "This directive is a simplified version of //css_import.\n" +
                         "If a relative file path is specified with single-dot preficx it will be automatically converted onto the absolute path \n" +
                         "with respect to the location of the file containing the directive being resolved.\n" +
                         "Note if you use wildcard in the imported script name (e.g. *_build.cs) the directive will only import from the first\n" +
                         "probing directory where the matching file(s) is found. Be careful with the wide wildcard as '*.cs' as they may lead to \n" +
                         "unpredictable behaviour. For example they may match everything from the very first probing directory, which is typically a current \n" +
                         "directory. Using more specific wildcards is arguably more practical (e.g. 'utils/*.cs', '*Helper.cs', './*.cs')\n" +
                         "------------------------------------\n" +
                         "//css_import <file>[, preserve_main][, rename_namespace(<oldName>, <newName>)];\n" +
                         "\n" +
                         "Alias - //css_imp\n" +
                         "There are also another two aliases //css_include and //css_inc. They are equivalents of //css_import <file>, preserve_main\n" +
                         "If $this (or $this.name) is specified as part of <file> it will be replaced at execution time with the main script full name (or file name only).\n" +
                         "\n" +
                         "file            - name of a script file to be imported at compile-time.\n" +
                         "<preserve_main> - do not rename 'static Main'\n" +
                         "oldName         - name of a namespace to be renamed during importing\n" +
                         "newName         - new name of a namespace to be renamed during importing\n" +
                         "\n" +
                         "This directive is used to inject one script into another at compile time. Thus code from one script can be exercised in another one.\n" +
                         "'Rename' clause can appear in the directive multiple times.\n" +
                         "====================================\n" +
                         "\n" +
                         "//css_nuget [-noref] [-force[:delay]] [-ver:<version>] [-ng:<nuget arguments>] package0[,package1]..[,packageN];\n" +
                         "\n" +
                         "Downloads/Installs the NuGet package. It also automatically references the downloaded package assemblies.\n" +
                         "Note:\n" +
                         "  The directive switches need to be in the order as above.\n" +
                         "  By default the package is not downloaded again if it was already downloaded.\n" +
                         "  If no version is specified then the highest downloaded version (if any) will be used.\n" +
                         "  Referencing the downloaded packages can only handle simple dependency scenarios when all downloaded assemblies are to be referenced.\n" +
                         "  You should use '-noref' switch and reference assemblies manually for all other cases. For example multiple assemblies with the same file name that \n" +
                         "  target different CLRs (e.g. v3.5 vs v4.0) in the same package.\n" +
                         "Switches:\n" +
                         " -noref - switch for individual packages if automatic referencing isn't desired. You can use 'css_nuget' environment variable for\n" +
                         "          further referencing package content (e.g. //css_dir %css_nuget%\\WixSharp\\**)\n" +
                         " -force[:delay] - switch to force individual packages downloading even when they were already downloaded.\n" +
                         "                  You can optionally specify delay for the next forced downloading by number of seconds since last download.\n" +
                         "                  '-force:3600' will delay it for one hour. This option is useful for preventing frequent download interruptions\n" +
                         "                  during active script development.\n" +
                         " -ver: - switch to download/reference a specific package version.\n" +
                         " -ng: - switch to pass NuGet arguments for every individual package.\n" +
                         "Example: //css_nuget cs-script;\n" +
                         "         //css_nuget -ver:4.1.2 NLog\n" +
                         "         //css_nuget -ver:\"4.1.1-rc1\" -ng:\"-Pre -NoCache\" NLog\n" +
                         "This directive will install CS-Script NuGet package.\n" +
                         "------------------------------------\n" +
                         "//css_args arg0[,arg1]..[,argN];\n" +
                         "\n" +
                         "Embedded script arguments. The both script and engine arguments are allowed except \"/noconfig\" engine command switch.\n" +
                         " Example: //css_args -dbg, -inmem;\n This directive will always force script engine to execute the script in debug mode.\n" +
                         "------------------------------------\n" +
                         "//css_reference <file>;\n" +
                         "\n" +
                         "Alias - //css_ref\n" +
                         "\n" +
                         "file - name of the assembly file to be loaded at run-time.\n" +
                         "\n" +
                         "This directive is used to reference assemblies required at run time.\n" +
                         "The assembly must be in GAC, the same folder with the script file or in the 'Script Library' folders (see 'CS-Script settings').\n" +
                         "------------------------------------\n" +
                         "//css_precompiler <file 1>,<file 2>;\n" +
                         "\n" +
                         "Alias - //css_pc\n" +
                         "\n" +
                         "file - name of the script or assembly file implementing precompiler.\n" +
                         "\n" +
                         "This directive is used to specify the CS-Script precompilers to be loaded and exercised against script at run time.\n" +
                         "------------------------------------\n" +
                         "//css_searchdir <directory>;\n" +
                         "\n" +
                         "Alias - //css_dir\n" +
                         "\n" +
                         "directory - name of the directory to be used for script and assembly probing at run-time.\n" +
                         "\n" +
                         "This directive is used to extend set of search directories (script and assembly probing).\n" +
#if !net1
                         "The directory name can be a wildcard based expression.In such a case all directories matching the pattern will be this \n" +
                         "case all directories will be probed.\n" +
                         "The special case when the path ends with '**' is reserved to indicate 'sub directories' case. Examples:\n" +
                         "    //css_dir packages\\ServiceStack*.1.0.21\\lib\\net40\n" +
                         "    //css_dir packages\\**\n" +
#endif
                         "------------------------------------\n" +
                         "//css_resource <file>;\n" +
                         "\n" +
                         "Alias - //css_res\n" +
                         "\n" +
                         "file - name of the resource file (.resources) to be used with the script.\n" +
                         "\n" +
                         "This directive is used to reference resource file for script.\n" +
                         " Example: //css_res Scripting.Form1.resources;\n" +
                         "------------------------------------\n" +
                         "//css_co <options>;\n" +
                         "\n" +
                         "options - options string.\n" +
                         "\n" +
                         "This directive is used to pass compiler options string directly to the language specific CLR compiler.\n" +
                         " Example: //css_co /d:TRACE pass /d:TRACE option to C# compiler\n" +
                         "          //css_co /platform:x86 to produce Win32 executable\n\n" +
                         "------------------------------------\n" +
                         "//css_ignore_namespace <namespace>;\n" +
                         "\n" +
                         "Alias - //css_ignore_ns\n" +
                         "\n" +
                         "namespace - name of the namespace. Use '*' to completely disable namespace resolution\n" +
                         "\n" +
                         "This directive is used to prevent CS-Script from resolving the referenced namespace into assembly.\n" +
                         "------------------------------------\n" +
                         "//css_prescript file([arg0][,arg1]..[,argN])[ignore];\n" +
                         "//css_postscript file([arg0][,arg1]..[,argN])[ignore];\n" +
                         "\n" +
                         "Aliases - //css_pre and //css_post\n" +
                         "\n" +
                         "file    - script file (extension is optional)\n" +
                         "arg0..N - script string arguments\n" +
                         "ignore  - continue execution of the main script in case of error\n" +
                         "\n" +
                         "These directives are used to execute secondary pre- and post-action scripts.\n" +
                         "If $this (or $this.name) is specified as arg0..N it will be replaced at execution time with the main script full name (or file name only).\n" +
                         "------------------------------------\n" +
                         "//css_host [/version:<CLR_Version>] [/platform:<CPU>]\n" +
                         "\n" +
                         "CLR_Version - version of CLR the script should be execute on (e.g. //css_host /version:v3.5)\n" +
                         "CPU - indicates which platforms the script should be run on: x86, Itanium, x64, or anycpu.\n" +
                         "Sample: //css_host /version:v2.0 /platform:x86;" +
                         "\n" +
                         "These directive is used to execute script from a surrogate host process. The script engine application (cscs.exe or csws.exe) launches the script\n" +
                         "execution as a separate process of the specified CLR version and CPU architecture.\n" +
                         "------------------------------------\n" +
                         "Note the script engine always sets the following environment variables:\n" +
                         " 'pid' - host processId (e.g. Environment.GetEnvironmentVariable(\"pid\")\n" +
                         " 'CSScriptRuntime' - script engine version\n" +
                         " 'CSScriptRuntimeLocation' - script engine location\n" +
                         " 'css_nuget' - location of the NuGet packages scripts can load/reference\n" +
                         " 'EntryScript' - location of the entry script\n" +
                         " 'EntryScriptAssembly' - location of the compiled script assembly\n" +
                         " 'location:<assm_hash>' - location of the compiled script assembly.\n" +
                         "                          This variable is particularly useful as it allows finding the compiled assembly file from the inside of the script code.\n" +
                         "                          Even when the script loaded in-memory (InMemoryAssembly setting) but not from the original file.\n" +
                         "                          (e.g. var location = Environment.GetEnvironmentVariable(\"location:\" + Assembly.GetExecutingAssembly().GetHashCode());\n" +
                         "------------------------------------\n" +
                         "\n" +
                         "Any directive has to be written as a single line in order to have no impact on compiling by CLI compliant compiler.\n" +
                         "It also must be placed before any namespace or class declaration.\n" +
                         "\n" +
                         "------------------------------------\n" +
                         "Example:\n" +
                         "\n" +
                         " using System;\n" +
                         " //css_prescript com(WScript.Shell, swshell.dll;\n" +
                         " //css_import tick, rename_namespace(CSScript, TickScript;\n" +
                         " //css_reference teechart.lite.dll;\n" +
                         " \n" +
                         " namespace CSScript\n" +
                         " {\n" +
                         "   class TickImporter\n" +
                         "   {\n" +
                         "      static public void Main(string[] args)\n" +
                         "      {\n" +
                         "         TickScript.Ticker.i_Main(args;\n" +
                         "      }\n" +
                         "   }\n" +
                         " }\n" +
                         "\n";;
            #endregion
        }
Ejemplo n.º 16
0
        void ParseArgs(string[] args)
        {
            Info = new ArgInfo();

            Info.Stages = new List<StageItem>();
            Info.Namespace = "Shaders";
            Info.ShaderName = "__Shader" + args.GetHashCode();
            Info.ContextVersion = new Version(3, 0);

            foreach (string arg in args)
            {
                try
                {
                    if (arg.StartsWith("-") || arg.StartsWith("/"))
                    {
                        string option = arg.Substring(1);

                        if (option == "r")
                        {
                            Info.RecompileFromFile = true;
                        }
                        else if (option == "s")
                        {
                            Info.RecompileFromFile = false;
                        }
                        else if (option.StartsWith("out="))
                        {
                            Info.OutputFile = option.Substring(4).TrimMatchingQuotes();
                        }
                        else if (option.StartsWith("name="))
                        {
                            Info.ShaderName = option.Substring(5).TrimMatchingQuotes();
                        }
                        else if (option.StartsWith("vert="))
                        {
                            Info.Stages.Add(new StageItem(option.Substring(5).TrimMatchingQuotes(), ShaderStage.Vertex, File.ReadAllText(option.Substring(5))));
                        }
                        else if (option.StartsWith("frag="))
                        {
                            Info.Stages.Add(new StageItem(option.Substring(5).TrimMatchingQuotes(), ShaderStage.Fragment, File.ReadAllText(option.Substring(5))));
                        }
                        else if (option.StartsWith("geom="))
                        {
                            Info.Stages.Add(new StageItem(option.Substring(5).TrimMatchingQuotes(), ShaderStage.Geometry, File.ReadAllText(option.Substring(5))));
                        }
                        else if (option.StartsWith("tessEval="))
                        {
                            Info.Stages.Add(new StageItem(option.Substring(9).TrimMatchingQuotes(), ShaderStage.TessEval, File.ReadAllText(option.Substring(9))));
                        }
                        else if (option.StartsWith("tessControl="))
                        {
                            Info.Stages.Add(new StageItem(option.Substring(12).TrimMatchingQuotes(), ShaderStage.TessControl, File.ReadAllText(option.Substring(12))));
                        }
                        else if (option.StartsWith("compute="))
                        {
                            Info.Stages.Add(new StageItem(option.Substring(8).TrimMatchingQuotes(), ShaderStage.Compute, File.ReadAllText(option.Substring(8))));
                        }
                        else if (option.StartsWith("namespace="))
                        {
                            Info.Namespace = option.Substring("namespace=".Length).TrimMatchingQuotes();
                        }
                        else if (option.StartsWith("contextVersion="))
                        {
                            Info.ContextVersion = new Version(option.Substring("contextVersion=".Length).TrimMatchingQuotes());
                        }
                        else
                        {
                            Console.WriteLine("Unknown argument: '" + arg + "'");
                        }
                    }
                    else
                    {
                        if (arg.EndsWith(".vert", true, null))
                        {
                            Info.Stages.Add(new StageItem(arg, ShaderStage.Vertex, File.ReadAllText(arg)));
                        }
                        else if (arg.EndsWith(".frag", true, null))
                        {
                            Info.Stages.Add(new StageItem(arg, ShaderStage.Fragment, File.ReadAllText(arg)));
                        }
                        else if (arg.EndsWith(".geom", true, null))
                        {
                            Info.Stages.Add(new StageItem(arg, ShaderStage.Geometry, File.ReadAllText(arg)));
                        }
                        else if (arg.EndsWith(".tessEval", true, null))
                        {
                            Info.Stages.Add(new StageItem(arg, ShaderStage.TessEval, File.ReadAllText(arg)));
                        }
                        else if (arg.EndsWith(".tessControl", true, null))
                        {
                            Info.Stages.Add(new StageItem(arg, ShaderStage.TessControl, File.ReadAllText(arg)));
                        }
                        else if (arg.EndsWith(".compute", true, null))
                        {
                            Info.Stages.Add(new StageItem(arg, ShaderStage.Compute, File.ReadAllText(arg)));
                        }
                        else if (arg.EndsWith(".vs", true, null))
                        {
                            Info.Stages.Add(new StageItem(arg, ShaderStage.Vertex, File.ReadAllText(arg)));
                        }
                        else if (arg.EndsWith(".fs", true, null))
                        {
                            Info.Stages.Add(new StageItem(arg, ShaderStage.Fragment, File.ReadAllText(arg)));
                        }
                        else if (arg.EndsWith(".gs", true, null))
                        {
                            Info.Stages.Add(new StageItem(arg, ShaderStage.Geometry, File.ReadAllText(arg)));
                        }
                        else
                        {
                            Console.WriteLine("Unable to determine stage of file: '" + arg + "' argument will be ignored.");
                        }
                    }
                }
                catch (FormatException)
                {
                    Console.WriteLine("Invalid argument.");
                }
                catch (OverflowException)
                {
                    Console.WriteLine("Invalid argument.");
                }
                catch(ArgumentOutOfRangeException)
                {
                    Console.WriteLine("Invalid argument.");
                }
                catch (FileNotFoundException exec)
                {
                    Console.WriteLine("Error: File \"" + exec.FileName + "\" was not found.");
                }
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Creates an instance of GetArgs
        /// </summary>
        protected GetArgs()
        {
            const BindingFlags flags = BindingFlags.DeclaredOnly |
                                       BindingFlags.Public | BindingFlags.Instance;

            Type argclass = GetType();

            if (re == null)
            {
                ArgOptionsAttribute aoa = argclass.GetCustomAttributes(typeof(ArgOptionsAttribute), true)[0]
                                          as ArgOptionsAttribute;

                casesensitive = aoa.CaseSensitive;
                allowshortcut = aoa.AllowShortcut;
                seperator     = aoa.Seperator;
                prefix        = aoa.Prefix;
                msgbox        = aoa.MessageBox;
                shortlen      = aoa.ShortcutLength;
                pauserr       = aoa.PauseOnError;
                ignoreunknown = aoa.IgnoreUnknownArguments;

                re = new Regex(string.Format(@"
(({0}																# switch
(?<name>[_A-Za-z][_\w]*)						# name (any legal C# name)
({1}																# sep + optional space
(((""(?<value>((\\"")|[^""])*)"")|	# match a double quoted value (escape "" with \)
('(?<value>((\\')|[^'])*)'))|				# match a single quoted value (escape ' with \)
(\{{(?<arrayval>[^\}}]*)\}})|				# list value (escaped for string.Format)
(?<value>\S+))											# any single value
)?)|																# sep option + list
(((""(?<value>((\\"")|[^""])*)"")|	# match a double quoted value (escape "" with \)
('(?<value>((\\')|[^'])*)'))|				# match a single quoted value (escape ' with \)
(\{{(?<arrayval>[^\}}]*)\}})|				# list value (escaped for string.Format)
(?<value>\S+)))*										# any single value"                                        ,
                                             Regex.Escape(prefix),
                                             seperator.Trim() == string.Empty ? @"\s+" : @"\s*" + Regex.Escape(seperator) + @"\s*"
                                             ),
                               RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnorePatternWhitespace);

                arrre = new Regex(@"\s*(?<value>((\\,)|[^,])+)(\s*,\s*(?<value>((\\,)|[^,])+))*\s*",                 // escape , with \
                                  RegexOptions.Compiled | RegexOptions.ExplicitCapture);
            }

            Dictionary <string, ArgInfo> argz = new Dictionary <string, ArgInfo>();

            string allargs = Environment.CommandLine;

            allargs = allargs.Replace(string.Format(@"""{0}""", Application.ExecutablePath), "").Trim();

            if (prefix == string.Empty)
            {
                throw new ArgumentException("prefix cannot be empty string");
            }

            if (defvals == null)
            {
                defvals = this;

                string schemafilename = Assembly.GetEntryAssembly().Location + ".args.xsd";
                string deffilename    = Assembly.GetEntryAssembly().Location + ".args";

                if (!File.Exists(schemafilename))
                {
                    using (TextWriter w = File.CreateText(schemafilename))
                    {
                        GetSchema(w);
                    }
                }

                if (File.Exists(deffilename))
                {
                    using (TextReader deffile = File.OpenText(deffilename))
                    {
                        defvals = new XmlSerializer(GetType()).Deserialize(deffile) as GetArgs;
                    }
                }
                else
                {
                    using (TextWriter w = File.CreateText(deffilename))
                    {
                        StringWriter sw = new StringWriter();
                        new XmlSerializer(GetType()).Serialize(sw, this);
                        string all = sw.ToString().Replace(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"",
                                                           string.Empty).Replace(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"",
                                                                                 string.Empty);
                        w.WriteLine(all);
                    }
                }
            }
            else
            {
                return; //this
            }

            foreach (FieldInfo fi in argclass.GetFields(flags))
            {
                object defval = fi.GetValue(defvals);
                string n      = fi.Name;
                if (!casesensitive)
                {
                    n = n.ToLower();
                }

                fi.SetValue(this, defval);
                ArgInfo ai = new ArgInfo(fi, this, defval);


                if (ai.Options is DefaultArgAttribute)
                {
                    argz.Add(MAGIC, ai);
                }

                //be very careful with the next line!
                if (!(ai.Options is DefaultArgAttribute) || ((DefaultArgAttribute)ai.Options).AllowName)
                {
                    argz.Add(n, ai);
                    if (allowshortcut)
                    {
                        string sn = ai.Options.Shortname;
                        if (sn == null)
                        {
                            int nlen = n.Length - 1;
                            if (nlen > 0 && shortlen < n.Length)
                            {
                                sn = n.Substring(0, nlen < shortlen ? nlen : shortlen);
                                if (!argz.ContainsKey(sn))
                                {
                                    argz.Add(sn, ai);
                                    ai.Options.Shortname = sn;
                                }
                            }
                        }
                        else
                        {
                            if (!argz.ContainsKey(sn))
                            {
                                argz.Add(sn, ai);
                            }
                        }
                    }
                }
            }

            defvals = null;

            if (allargs.StartsWith(prefix + "?") || allargs.StartsWith(prefix + "help"))
            {
                PrintHelp(argz);
                Environment.Exit(0);
            }

            Group g        = null;
            bool  haserror = false;

            foreach (Match m in re.Matches(allargs))
            {
                string argname = null;
                try
                {
                    if (m.Value == string.Empty)
                    {
                        continue;
                    }
                    object val = null;
                    if ((g = m.Groups["name"]).Success)
                    {
                        argname = g.Value;
                        if (!casesensitive)
                        {
                            argname = argname.ToLower();
                        }
                    }
                    else
                    {
                        argname = MAGIC;
                    }

                    ArgInfo arginfo = argz[argname];

                    if (arginfo == null)
                    {
                        if (ignoreunknown)
                        {
                            Console.Error.WriteLine("Warning: Ignoring argument unknown '{0}'", argname);
                        }
                        else
                        {
                            Console.Error.WriteLine("Error: Argument '{0}' not known", argname);
                            haserror = true;
                        }
                        continue;
                    }

                    Type t = arginfo.Type;
                    if (t == null)
                    {
                        continue;
                    }

                    if (t.IsArray && argname != MAGIC)
                    {
                        if ((g = m.Groups["arrayval"]).Success)
                        {
                            Type          elet = t.GetElementType();
                            TypeConverter tc   = TypeDescriptor.GetConverter(elet);

                            Match arrm = arrre.Match(g.Value);

                            if (arrm.Success)
                            {
                                Group gg = arrm.Groups["value"];

                                Array arr = Array.CreateInstance(elet, gg.Captures.Count);

                                for (int i = 0; i < arr.Length; i++)
                                {
                                    arr.SetValue(tc.ConvertFromString(gg.Captures[i].Value.Trim()), i);
                                }
                                val = arr;
                            }
                        }
                    }
                    else
                    {
                        if ((g = m.Groups["value"]).Success)
                        {
                            string v = g.Value;
                            if (t == typeof(bool) && (v == "on" || v == "off"))
                            {
                                val = v == "on";
                            }
                            else
                            {
                                if (t.IsArray)
                                {
                                    ArrayList vals = new ArrayList();
                                    if (arginfo.Value != null)
                                    {
                                        vals.AddRange(arginfo.Value as ICollection);
                                    }
                                    TypeConverter tc = TypeDescriptor.GetConverter(t.GetElementType());
                                    vals.Add(tc.ConvertFromString(v));

                                    val = vals.ToArray(typeof(string)) as string[];
                                }
                                else
                                {
                                    TypeConverter tc = TypeDescriptor.GetConverter(t);
                                    val = tc.ConvertFromString(v);
                                }
                            }
                        }
                        else
                        {
                            val = t == typeof(bool);
                        }
                    }

                    arginfo.Value = val;
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("Error: Argument '{0}' could not be read ({1})",
                                            argname, ex.Message, ex.GetBaseException().GetType().Name);
                    haserror = true;
                }
            }
            if (haserror)
            {
                PrintHelp(argz);
                if (pauserr && !msgbox)
                {
                    Console.WriteLine("Press any key to exit");
                    Console.Read();
                }
                Environment.Exit(1);
            }
        }
Ejemplo n.º 18
0
        void PrintHelp(Dictionary <string, ArgInfo> map)
        {
            TextWriter writer = null;

            if (msgbox)
            {
                writer = new StringWriter();
            }
            else
            {
                writer = Console.Out;
            }

            Assembly     ass     = Assembly.GetEntryAssembly();
            AssemblyName assname = ass.GetName();

            AssemblyCopyrightAttribute acopy = null;

            object[] atts = ass.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
            if (atts.Length > 0)
            {
                acopy = atts[0] as AssemblyCopyrightAttribute;
            }

            string progname = string.Format("{0} {1}.{2} {3}", assname.Name, assname.Version.Major, assname.Version.Minor,
                                            acopy == null ? string.Empty : acopy.Copyright);

            if (!msgbox)
            {
                writer.WriteLine(progname);
            }
            writer.WriteLine("Usage: {0}", assname.Name);
            writer.WriteLine("{0}? or {0}help       prints usage", prefix);

            List <string> keys           = new List <string>(map.Keys);
            bool          acceptsdefault = false;

            foreach (KeyValuePair <string, ArgInfo> de in map)
            {
                ArgInfo arginfo   = de.Value;
                string  name      = de.Key;
                string  shortname = arginfo.Options.Shortname;

                if (shortname == name)
                {
                    continue;
                }

                if (name == MAGIC)
                {
                    acceptsdefault = true;
                    continue;
                }

                writer.WriteLine();

                Type t = arginfo.Type;

                if (t.IsArray)
                {
                    writer.WriteLine("{2}{0,-15}{3} {{ <{1}> , ... }}",
                                     MakeArg(name, shortname),
                                     GetShortTypeName(t.GetElementType()),
                                     prefix, seperator);
                }
                else
                {
                    if (t == typeof(bool))
                    {
                        writer.WriteLine("{2}{0,-15}  {3,-20} default: {1}",
                                         MakeArg(name, shortname),
                                         (bool)arginfo.defaultvalue ? "on" : "off", prefix, "(toggles)");
                    }
                    else
                    {
                        writer.WriteLine("{3}{0,-15}{4} {1,-20} {2}",
                                         MakeArg(name, shortname),
                                         "<" + GetShortTypeName(t) + ">",
                                         arginfo.Value != null ? "default: " + arginfo.Value : string.Empty, prefix, seperator);
                    }
                }
                if (arginfo.Options.Description != null)
                {
                    string[] lines = arginfo.Options.Description.Split('\n');
                    foreach (string line in lines)
                    {
                        writer.WriteLine("    {0}", line.TrimEnd('\r'));
                    }
                }
            }
            writer.WriteLine();
            if (acceptsdefault)
            {
                writer.WriteLine("Non-named arguments are used as input.");
            }
            writer.WriteLine("Note: Argument names are case-{0}sensitive.", casesensitive ? string.Empty : "in");
            if (msgbox)
            {
                MessageBox.Show(writer.ToString(), progname);
            }
        }
Ejemplo n.º 19
0
 public void load(ArgInfo ArgInfoA)
 {
     _ArgInfo            = ArgInfoA;
     argGrid.DataContext = _ArgInfo;
 }
Ejemplo n.º 20
0
 public void load(ArgInfo ArgInfoA)
 {
     _ArgInfo = ArgInfoA;
     argGrid.DataContext = _ArgInfo;
 }
Ejemplo n.º 21
0
        protected override string GetItemIdentifier(object o)
        {
            ArgInfo ai = (ArgInfo)o;

            return(ai.name);
        }
Ejemplo n.º 22
0
        public void DoRun(params string[] args)
        {
            ArgInfo argInfo = null;

            //MessageBox.Show("Hello!");
            if (args != null && args.Length == 1)
            {
                argInfo = ArgInfo.Parse(args[0]);
            }

            var currentPro = Process.GetCurrentProcess();

            bool created;

            using (Mutex mtx = new Mutex(true, API.mainWindowName, out created))
            {
                if (!created)
                {
                    if (argInfo != null)
                    {
                        HandlerPreviewProcessInfo(args, currentPro);
                    }
                    return;
                }

                var loginTask = Task.Create(p => ShowSplash());

                CodeTimer.Time("Start Main Form", () =>
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);

                    XmlConfigurator.Configure();
                    Log.InnerLog = new ProWrite.Core.Logger("-Sys-");

                    string moduleName  = null;
                    object[] argArrary = null;

                    mainForm = StartHelper.CreateMainForm();
                    (mainForm as IMainForm).Initialize();

                    var profile             = ServiceManager.Get <ProjectProfile>();
                    Task registerModuleTask = null;
                    registerModuleTask      = Task.Create(p =>
                    {
                        if (moduleName == null)
                        {
                            moduleName = profile.DefaultModule;
                        }

                        var moduleInfo = profile.Modules.First(m => m.ModuleName == moduleName);
                        ModuleManager.Register(moduleInfo.Module);

                        var modules = profile.Modules.Where(m => m.ModuleName != moduleName);
                        foreach (var m in modules)
                        {
                            ModuleManager.Register(m.Module);
                        }
                    });



                    var timer       = ServiceManager.Get <System.Windows.Forms.Timer>();
                    mainForm.Shown += (s, e) =>
                    {
                        ModuleManager.DisplayModule(ModuleNames.Editor);    //moduleName);
                        ModuleManager.DisplayModule(moduleName);
                        timer.Tick += delegate
                        {
                            timer.Stop();

                            if (argInfo != null)
                            {
                                moduleName = argInfo.ModuleName;
                                argArrary  = new object[] { argInfo.Importer.OnImportOpen(args[0]), true };
                                ModuleManager.DisplayModule(moduleName, argArrary);
                            }

                            if (!registerModuleTask.IsCompleted)
                            {
                                registerModuleTask.Wait();
                                registerModuleTask.Dispose();
                            }
                            if (!loginTask.IsCompleted)
                            {
                                loginTask.Wait();
                                loginTask.Dispose();
                            }

                            //TODO:
                            DirtyWordList.Load();
                        };
                        timer.Start();
                    };

                    ServiceManager.Add <bool>(false);
                    filter = new UserPreferenceChangingFilter();
                    Application.AddMessageFilter(filter);
                    Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
                    Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
                });

                while (!HasAuthenticated.HasValue)
                {
                    loginTask.Wait(50);
                }
                var ewh = ServiceManager.Get <System.Threading.EventWaitHandle>();
                ewh.Set();

                if (!HasAuthenticated.Value)
                {
                    Application.Exit();
                    return;
                }

                Application.Run(mainForm);
            }
        }
Ejemplo n.º 23
0
        /*
         * Arguments
         *	- out=[filename] : Sets the output file (The default is 'shader_file.h')
         *	- name=[string] : Sets the name of the shader (This will be the name of the output class)
         *	- [filename] : One of the files to compile as a shader stage (The stage of the shader is inferred from the extension)
         *	- vert=[filename] : Compiles the file as a vertex shader
         *	- frag=[filename] : Compiles the file as a fragment shader
         *	- geom=[filename] : Compiles the file as a geometry shader
         *	- tessEval=[filename] : Compiles the file as a tesselation evaluation shader
         *	- tessControl=[filename] : Compiles the file as a tesseleation control shader
         *	- compute=[filename] : Compiles the file as a compute shader (This option cannot be specified with any of the other file types)

         */
        static void ParseArgs(string[] args)
        {
            Info = new ArgInfo();

            Info.Stages = new List<StageItem>();
            Info.Namespace = "Shaders";
            Info.ShaderName = "__Shader" + args.GetHashCode();
            Info.OutputFile = "shader_file.h";

            foreach (string arg in args)
            {
                if (arg.StartsWith("-") || arg.StartsWith("/"))
                {
                    string option = arg.Substring(1);

                    if (option.StartsWith("out="))
                    {
                        Info.OutputFile = option.Substring(4).TrimMatchingQuotes();
                    }
                    else if (option.StartsWith("name="))
                    {
                        Info.ShaderName = option.Substring(5).TrimMatchingQuotes();
                    }
                    else if (option.StartsWith("vert="))
                    {
                        Info.Stages.Add(new StageItem(option.Substring(5).TrimMatchingQuotes(), ShaderStage.Vertex, File.ReadAllText(option.Substring(5))));
                    }
                    else if (option.StartsWith("frag="))
                    {
                        Info.Stages.Add(new StageItem(option.Substring(5).TrimMatchingQuotes(), ShaderStage.Fragment, File.ReadAllText(option.Substring(5))));
                    }
                    else if (option.StartsWith("geom="))
                    {
                        Info.Stages.Add(new StageItem(option.Substring(5).TrimMatchingQuotes(), ShaderStage.Geometry, File.ReadAllText(option.Substring(5))));
                    }
                    else if (option.StartsWith("tessEval="))
                    {
                        Info.Stages.Add(new StageItem(option.Substring(9).TrimMatchingQuotes(), ShaderStage.TessEval, File.ReadAllText(option.Substring(9))));
                    }
                    else if (option.StartsWith("tessControl="))
                    {
                        Info.Stages.Add(new StageItem(option.Substring(12).TrimMatchingQuotes(), ShaderStage.TessControl, File.ReadAllText(option.Substring(12))));
                    }
                    else if (option.StartsWith("compute="))
                    {
                        Info.Stages.Add(new StageItem(option.Substring(8).TrimMatchingQuotes(), ShaderStage.Compute, File.ReadAllText(option.Substring(8))));
                    }
                    else if (option.StartsWith("namespace="))
                    {
                        Info.Namespace = option.Substring("namespace=".Length).TrimMatchingQuotes();
                    }
                    else
                    {
                        Console.WriteLine("Unknown argument: '" + arg + "'");
                    }
                }
                else
                {
                    if (arg.EndsWith(".vert", true, null))
                    {
                        Info.Stages.Add(new StageItem(arg, ShaderStage.Vertex, File.ReadAllText(arg)));
                    }
                    else if (arg.EndsWith(".frag", true, null))
                    {
                        Info.Stages.Add(new StageItem(arg, ShaderStage.Fragment, File.ReadAllText(arg)));
                    }
                    else if (arg.EndsWith(".geom", true, null))
                    {
                        Info.Stages.Add(new StageItem(arg, ShaderStage.Geometry, File.ReadAllText(arg)));
                    }
                    else if (arg.EndsWith(".tessEval", true, null))
                    {
                        Info.Stages.Add(new StageItem(arg, ShaderStage.TessEval, File.ReadAllText(arg)));
                    }
                    else if (arg.EndsWith(".tessControl", true, null))
                    {
                        Info.Stages.Add(new StageItem(arg, ShaderStage.TessControl, File.ReadAllText(arg)));
                    }
                    else if (arg.EndsWith(".compute", true, null))
                    {
                        Info.Stages.Add(new StageItem(arg, ShaderStage.Compute, File.ReadAllText(arg)));
                    }
                    else if (arg.EndsWith(".vs", true, null))
                    {
                        Info.Stages.Add(new StageItem(arg, ShaderStage.Vertex, File.ReadAllText(arg)));
                    }
                    else if (arg.EndsWith(".fs", true, null))
                    {
                        Info.Stages.Add(new StageItem(arg, ShaderStage.Fragment, File.ReadAllText(arg)));
                    }
                    else if (arg.EndsWith(".gs", true, null))
                    {
                        Info.Stages.Add(new StageItem(arg, ShaderStage.Geometry, File.ReadAllText(arg)));
                    }
                    else
                    {
                        Console.WriteLine("Unable to determine stage of file: '" + arg + "' argument will be ignored.");
                    }
                }
            }
        }
Ejemplo n.º 24
0
        private static int?ParseSettingArg(IConsoleEnvironment consoleEnvironment, string arg, int valueIndex, ArgInfo settingArg)
        {
            Contract.Requires(consoleEnvironment != null);
            Contract.Requires(arg != null);
            Contract.Requires(settingArg != null);
            Contract.Requires(valueIndex == -1 || (valueIndex + 1) >= 0);
            Contract.Requires(valueIndex == -1 || (valueIndex + 1) <= arg.Length);

            if (valueIndex == -1)
            {
                consoleEnvironment.ErrWriter.WriteLine("Setting '{0}' is missing the value", settingArg.ArgName);
                return(2);
            }

            string settingValueStr = arg.Substring(valueIndex + 1);

            CommandLineParsingContext context = new CommandLineParsingContext(consoleEnvironment);

            context.ArgName = settingArg.ArgName;

            if (settingArg.ArgType == typeof(string))
            {
                settingArg.StringValueAction(settingValueStr, context);
            }
            else if (settingArg.ArgType == typeof(int))
            {
                int intValue;
                if (int.TryParse(settingValueStr, out intValue))
                {
                    settingArg.IntValueAction(intValue, context);
                }
                else
                {
                    consoleEnvironment.ErrWriter.WriteLine("Setting '{0}' has an invalid value ('{1}') - it should be an integer", settingArg.ArgName, settingValueStr);
                    return(2);
                }
            }
            else
            {
                throw new NotImplementedException();
            }

            return(null);
        }
Ejemplo n.º 25
0
        private static int?ParseSwitchArg(IConsoleEnvironment consoleEnvironment, string arg, int valueIndex, ArgInfo switchArg)
        {
            Contract.Requires(consoleEnvironment != null);
            Contract.Requires(arg != null);
            Contract.Requires(switchArg != null);
            Contract.Requires(valueIndex < 0 || (valueIndex + 1) <= arg.Length);

            bool switchValue;

            if (valueIndex < 0)
            {
                switchValue = true;
            }
            else
            {
                string settingValueStr = arg.Substring(valueIndex + 1);

                if (!bool.TryParse(settingValueStr, out switchValue))
                {
                    consoleEnvironment.ErrWriter.WriteLine(
                        @"Switch '{0}' has an invalid value ('{1}') - it should either be empty, 'true' or 'false'",
                        switchArg.ArgName,
                        settingValueStr);
                    return(2);
                }
            }

            CommandLineParsingContext context = new CommandLineParsingContext(consoleEnvironment);

            context.ArgName = switchArg.ArgName;
            switchArg.BoolValueAction(switchValue, context);

            return(null);
        }
Ejemplo n.º 26
0
        public static SqlParameter GetSqlParameter(this Parameter parameter, object value, ArgInfo argInfo)
        {
            var dbType = Type.GetType(parameter.DataType).ToSqlDbType();
            var param  = new SqlParameter()
            {
                ParameterName = parameter.Name,
                SqlDbType     = dbType
            };

            if (argInfo != null && argInfo.IsValueEncrypted && value != null)
            {
                param.SqlValue = Convert.ChangeType(Convert.ToString(value).Decrypt(), Type.GetType(parameter.DataType));
            }
            else if (value != null)
            {
                param.SqlValue = value;
            }
            return(param);
        }
Ejemplo n.º 27
0
        void PrintHelp(Hashtable map)
        {
            TextWriter writer = null;

            writer = Console.Out;

            writer.WriteLine("Usage: {0}", assname.Name);
            writer.WriteLine("{0}? or {0}help       prints usage", prefix);
            writer.WriteLine();
            writer.WriteLine("{0}nologo           suppresses program and copyright notice", prefix);

            ArrayList keys           = new ArrayList(map.Keys);
            bool      acceptsdefault = false;

            foreach (DictionaryEntry de in map)
            {
                ArgInfo arginfo   = de.Value as ArgInfo;
                string  name      = de.Key as string;
                string  shortname = arginfo.Options.Shortname;

                if (shortname == name)
                {
                    continue;
                }

                if (name == MAGIC)
                {
                    acceptsdefault = true;
                    continue;
                }

                writer.WriteLine();

                Type t = arginfo.Type;

                if (t.IsArray)
                {
                    writer.WriteLine("{2}{0,-15}{3} {{ <{1}> , ... }}",
                                     MakeArg(name, shortname),
                                     GetShortTypeName(t.GetElementType()),
                                     prefix, seperator);
                }
                else
                {
                    if (t == typeof(bool))
                    {
                        writer.WriteLine("{2}{0,-15}  {3,-20} default: {1}",
                                         MakeArg(name, shortname),
                                         (bool)arginfo.defaultvalue ? "on" : "off", prefix, "(toggles)");
                    }
                    else
                    {
                        writer.WriteLine("{3}{0,-15}{4} {1,-20} {2}",
                                         MakeArg(name, shortname),
                                         "<" + GetShortTypeName(t) + ">",
                                         arginfo.Value != null ? "default: " + arginfo.Value : string.Empty, prefix, seperator);
                    }
                }
                if (arginfo.Options.Description != null)
                {
                    string[] lines = arginfo.Options.Description.Split('\n');
                    foreach (string line in lines)
                    {
                        writer.WriteLine("    {0}", line.TrimEnd('\r'));
                    }
                }
            }
            writer.WriteLine();
            if (acceptsdefault)
            {
                writer.WriteLine("Non-named arguments are used as input.");
            }
            writer.WriteLine("Note: Argument names are case-{0}sensitive.", casesensitive ? string.Empty : "in");
        }