Exemple #1
0
        static int Main(string[] args)
        {
            var options = new Options();
            var parser  = new CommandLine.Parser(with => with.HelpWriter = Console.Error);

            if (parser.ParseArgumentsStrict(args, options, () => Environment.Exit(-2)))
            {
                if (string.IsNullOrEmpty(options.PathToRockWeb))
                {
                    string removeString     = "Dev Tools\\Applications";
                    string currentDirectory = System.Reflection.Assembly.GetExecutingAssembly().Location;
                    int    index            = currentDirectory.IndexOf(removeString);
                    string rockDirectory    = (index < 0)
                        ? currentDirectory
                        : currentDirectory.Substring(0, index);

                    options.PathToRockWeb = Path.Combine(rockDirectory, "RockWeb");
                }

                if (!Directory.Exists(options.PathToRockWeb))
                {
                    Console.WriteLine("Error: unable to find directory: " + options.PathToRockWeb);
                    return(-1);
                }

                Run(options);
            }

            return(0);
        }
Exemple #2
0
        static int Main( string[] args )
        {
            var options = new Options();
            var parser = new CommandLine.Parser( with => with.HelpWriter = Console.Error );

            if ( parser.ParseArgumentsStrict( args, options, () => Environment.Exit( -2 ) ) )
            {
                if ( string.IsNullOrEmpty( options.PathToRockWeb ) )
                {
                    string removeString = "Dev Tools\\Applications";
                    string currentDirectory = System.Reflection.Assembly.GetExecutingAssembly().Location;
                    int index = currentDirectory.IndexOf( removeString );
                    string rockDirectory = ( index < 0 )
                        ? currentDirectory
                        : currentDirectory.Substring( 0, index );

                    options.PathToRockWeb = Path.Combine( rockDirectory, "RockWeb" );

                }

                if ( !Directory.Exists( options.PathToRockWeb ) )
                {
                    Console.WriteLine( "Error: unable to find directory: " + options.PathToRockWeb );
                    return -1;
                }

                Run( options );
            }

            return 0;
        }
Exemple #3
0
        static int Main(string[] args)
        {
#if !DEBUG
            try
#endif
            {
                var options = new Options();
                var parser  = new CommandLine.Parser(
                    s =>
                {
                    s.IgnoreUnknownArguments = false;
                    s.MutuallyExclusive      = true;
                    s.CaseSensitive          = true;
                    s.HelpWriter             = Console.Error;
                }
                    );
                var isValid = parser.ParseArgumentsStrict(args, options);
                if (!isValid)
                {
                    return(1);
                }

                if (options.Version)
                {
                    PrintVersion();
                    return(0);
                }

                if (options.DeploymentFilePaths == null || options.DeploymentFilePaths.Count == 0)
                {
                    Console.WriteLine(options.GetUsage());
                }

                Utils.Quiet = options.Quiet || options.GetBinPath;
                var deployer = new Deployer(options.DeploymentFilePaths, options.BinPath, options.InstallPath, options.OutputProcessJson);
                if (options.GetBinPath)
                {
                    Console.WriteLine(deployer.Deployment.BinPath);
                    return(0);
                }

                if (!options.DryRun)
                {
                    deployer.Run(options.Clean, options.Toolset);
                }

                return(0);
            }
#if !DEBUG
            catch (Exception e)
            {
                Console.WriteLine("Fatal error -> " + e.Message);
                return(-1);
            }
#endif
        }
        public static Arguments Parse(string[] args)
        {
            var parameters = new Arguments();

            var parser = new Parser(with => with.HelpWriter = Console.Error);

            parser.ParseArgumentsStrict(args, parameters, () => { throw new ArgumentOutOfRangeException("args", args, "Command line arguments are invalid."); });

            return parameters;
        }
Exemple #5
0
        /// <summary>
        /// CommandLine Main
        /// </summary>
        /// <param name="args">Input parameters</param>
        static void Main(string[] args)
        {
            var options = new Options();
            var parser  = new CommandLine.Parser(with => with.HelpWriter = Console.Error);

            if (parser.ParseArgumentsStrict(args, options, () => Environment.Exit(-2)))
            {
                Run(options);
            }
        }
        /// <summary>
        /// CommandLine Main
        /// </summary>
        /// <param name="args">Input parameters</param>
        static void Main(string[] args)
        {
            var options = new Options();
            var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Error);

            if (parser.ParseArgumentsStrict(args, options, () => Environment.Exit(-2)))
            {
                Run(options);
            }
        }
Exemple #7
0
        public static void Main(string[] args)
        {
            Parser            parser     = new CommandLine.Parser();
            bladeDirectorArgs parsedArgs = new bladeDirectorArgs();

            if (parser.ParseArgumentsStrict(args, parsedArgs, () => { Console.Write(HelpText.AutoBuild(parsedArgs).ToString()); }))
            {
                _Main(parsedArgs);
            }
        }
Exemple #8
0
 private static void InitializeOptions(string[] args)
 {
     s_options = new Options();
       var parser = new Parser(
       x =>
       {
     x.MutuallyExclusive = true;
     x.HelpWriter = System.Console.Error;
       });
       parser.ParseArgumentsStrict(args, s_options);
 }
Exemple #9
0
        /// <summary>
        /// Application's Entry Point.
        /// </summary>
        /// <param name="args">Command line arguments splitted by the system.</param>
        private static void Main(string[] args)
        {
#if EXEC_TESTS
            RunATestForDebugging();
#endif
            var options = new Options();
            var parser  = new CommandLine.Parser(with => with.HelpWriter = Console.Error);

            if (parser.ParseArgumentsStrict(args, options, () => Environment.Exit(-2)))
            {
                Run(options);
            }
        }
Exemple #10
0
        /// <summary>
        /// Application's Entry Point.
        /// </summary>
        /// <param name="args">Command line arguments splitted by the system.</param>
        private static void Main(string[] args)
        {
#if EXEC_TESTS
            RunATestForDebugging();
#endif
            var options = new Options();
            var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Error);

            if (parser.ParseArgumentsStrict(args, options, () => Environment.Exit(-2)))
            {
                Run(options);
            }
        }
Exemple #11
0
        public static int Main(string[] args)
        {
            int retval = -1;
            var options = new Options();
            var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Error);

            if (parser.ParseArgumentsStrict(args, options, () => Environment.Exit(-2)))
            {
                log.InfoFormat("Started:\t{0}", !String.IsNullOrEmpty(options.Job) ?  options.Job : options.InputFile);

                Bits.Wcf.BitsWcfServiceClient cl = new Bits.Wcf.BitsWcfServiceClient();

                switch(options.Mode)
                {
                    case TriggerMode.FolderWatcher:

                        retval = cl.RunJobFromClient(options.Job, options.InputFile);
                        break;

                    case TriggerMode.Timer:

                        //see if there is a [full] set of geneva parms
                        if (options.PS != null || options.PE != null || options.K != null || options.PK != null)
                        {
                            if (options.PS == null || options.PE == null || options.K == null || options.PK == null)
                            {
                                log.Warn("If providing Geneva parameters, all parameters must be provided (PS, PE, K, PK)");
                                return 0;
                            }
                            else
                            {
                                log.InfoFormat("Geneva Dates:\tps{0} pe{1} k{2} ps{3} ", options.PS, options.PE, options.K, options.PK);
                                retval = cl.RunJobFromClient(options.Job, String.Empty);
                            }
                        }
                        else
                            retval = cl.RunJobFromClient(options.Job, String.Empty);
                        break;

                }
            }
            log.InfoFormat("Completed:\t{0}", options.Job);
            log.InfoFormat("Return Value:\t{0}", retval);

            return retval;
        }
Exemple #12
0
        static void Main(string[] args)
        {
            Parser      parser     = new CommandLine.Parser();
            hyptoolargs parsedArgs = new hyptoolargs();

            if (parser.ParseArgumentsStrict(args, parsedArgs, () => { Console.Write(HelpText.AutoBuild(parsedArgs).ToString()); }))
            {
                _Main(parsedArgs);
            }
            else
            {
                Console.WriteLine("Valid action values:");
                foreach (string actionName in Enum.GetNames(typeof(hypervisorAction)))
                {
                    Console.WriteLine(" * '" + actionName + "'");
                }
            }
        }
Exemple #13
0
        private static void Main(string[] args)
        {
            var options = new Options();
            var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Error);

            // ReadKey() is there for debugging.
            if (parser.ParseArgumentsStrict(args, options, () => { Console.ReadKey();  Environment.Exit(-2); }))
            {
                Console.WriteLine("inject: {0}", options.InputFile);
                Console.WriteLine("function: {0}", options.FuncName);
                Console.WriteLine("args: {0}", options.FuncArgs);
                Console.WriteLine("pid: {0}", options.ProcID);
                Console.WriteLine("name: {0}", options.ProcName);
                Console.WriteLine("launch: {0}", options.ProcLaunch);

                InjectorLib injector = new InjectorLib();
                bool injected = false;
                UInt32 retCode = 0;
                if( !string.IsNullOrWhiteSpace(options.ProcName) )
                {
                    Process[] procs = Process.GetProcessesByName(options.ProcName);
                    foreach (Process proc in procs)
                    {
                        Console.WriteLine("Injecting '{0}' into process {1}", options.InputFile, proc.Id);
                        injected = injector.InjectAndRun((UInt32)proc.Id, options.InputFile, options.FuncName, options.FuncArgs, ref retCode);
                    }
                }
                else if( options.ProcID != 0 )
                {
                    Console.WriteLine("Injecting '{0}' into process {1}", options.InputFile, options.ProcID);
                    injected = injector.InjectAndRun(options.ProcID, options.InputFile, options.FuncName, options.FuncArgs, ref retCode);
                }
                else if( !string.IsNullOrWhiteSpace(options.ProcLaunch) )
                {
                    Console.WriteLine("Launching '{0}' and injecting '{1}'", options.ProcLaunch, options.InputFile);
                    injected = injector.LaunchAndInject(options.ProcLaunch, options.InputFile, options.FuncName, options.FuncArgs, ref retCode);
                }
                Environment.Exit(injected ? 0 : -1);
            }
        }
Exemple #14
0
        public static Options ParseCommandLine(string[] args, TextWriter helpWriter)
        {
            var options = new Options();
            var parser = new Parser(settings =>
            {
                settings.HelpWriter = helpWriter;
                settings.IgnoreUnknownArguments = false;
            });

            Action onFail = () =>
            {
                HelpText.AutoBuild(options);
                options.Exit = true;
            };

            if (parser.ParseArgumentsStrict(args, options, onFail))
            {
                return options;
            }

            return options;
        }
        public async Task ExecuteArguments(string[] args, List<string> programHeader = null)
        {
            //Show header
            if (programHeader != null)
            {
                foreach (var row in programHeader)
                {
                    Console.WriteLine(row);
                }
            }

            if (args == null) throw new ArgumentNullException(nameof(args));
            if (args.Length == 0)
            {
                ShowFunctionList();
                return;
            }

            //Grab function
            var functionName = args[0];
            var function = _functions.FirstOrDefault(x => x.Name == functionName);

            //Parse then execute function
            if (function != null)
            {
                //Short args length to remove function name
                var parseArgs = new string[] { };
                if (args.Length > 1)
                {
                    parseArgs = new string[args.Length - 1];
                    for (var i = 0; i < parseArgs.Length; i++)
                    {
                        parseArgs[i] = args[i + 1];
                    }
                }

                //Parse
                var parser = new Parser();
                var result = parser.ParseArgumentsStrict(parseArgs, function, () =>
                {
                    Console.Write(function.GetUsage());
                });

                //Execute
                if (result)
                {
                    await function.Execute();
                    function.Dispose();
                }                
            }
            else if (_functions.Count > 0)
            {
                if (functionName != "help")
                {
                    Console.WriteLine("Invalid function name");
                }

                ShowFunctionList();
            }
            else
            {
                ShowFunctionList();
            }
        }
        static void Main(string [] args)
        {
            AttachConsole(ATTACH_PARENT_PROCESS);
            Debug.WriteLine(" ");
            Console.WriteLine(" ");

            var options = new Options();

            options.szFormat = "{0}";
            var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Error);

            if (!parser.ParseArgumentsStrict(args, options, () => Environment.Exit(-2)))
            {
                return;
            }

            if (options.iTunes)
            {
                iTunes_Start(options);
                return;
            }

            MMDeviceEnumerator deviceEnum    = new MMDeviceEnumerator();
            MMDevice           defaultDevice = deviceEnum.GetDefaultAudioEndpoint(EDataFlow.eRender, options.deviceRole);

            if (options.bSwitch)
            {
                iTunes_Mute(options);
                bool     b      = defaultDevice.ID.Contains(options.cyrilleDevices [0]);
                MMDevice device = deviceEnum.GetDevice("{0.0.0.00000000}." + options.cyrilleDevices [Convert.ToInt16(b)]);
                SetDefaultEndpoint(options, device);
                return;
            }

            if (options.defaultDevice)
            {
                printDevice(options, defaultDevice);
                FreeConsole();
                return;
            }
            else if (options.allDevices && options.Items.Count == 0)
            {
                options.deviceState = EDeviceState.DEVICE_STATEMASK_ALL;
            }
            if (options.comm)
            {
                options.deviceRole = ERole.eCommunications;
            }

            if (options.Items.Count == 1)
            {
                MMDevice device = deviceEnum.GetDevice("{0.0.0.00000000}." + options.Items [0]);
                SetDefaultEndpoint(options, device);
            }
            else
            {
                MMDeviceCollection audioEndPointsEnum = deviceEnum.EnumerateAudioEndPoints(EDataFlow.eRender, options.deviceState);
                int count = audioEndPointsEnum.Count;
                for (int i = 0; i < count; i++)
                {
                    MMDevice device = audioEndPointsEnum [i];
                    printDevice(options, device);
                    if (options.verbose)
                    {
                        device.DebugProperties();
                    }
                }
            }
            if (options.iTunesMute)
            {
                iTunes_Mute(options);
            }

            FreeConsole();
        }
 private static Options GetOptions(string[] args)
 {
     var options = new Options();
     var parser = new Parser(configuration =>
                                 {
                                     configuration.IgnoreUnknownArguments = false;
                                     configuration.HelpWriter = Console.Error;
                                 });
     parser.ParseArgumentsStrict(args, options);
     if (options.PageSize > MaxListPageSize || options.PageSize < 1)
     {
         options.PageSize = MaxListPageSize;
     }
     return options;
 }
Exemple #18
0
        static void ParseSysCmd(string cmd)
        {
            string[] cmdArray = cmd.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (cmdArray.Length < 2)
            {
                Console.WriteLine("Bad Command");
                return;
            }
            switch (cmdArray[0])
            {
            case "wsd":
                switch (cmdArray[1])
                {
                case "powup":
                    if (busStarted)
                    {
                        if (wsd.OP_MODE != ControlOpMode.NoInit)
                        {
                            Console.WriteLine("WSD is already started,please stop first");
                        }
                        else
                        {
                            try
                            {
                                wsd.PowerUp();
                                Console.WriteLine("WSD is started successfully");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("WSD could not start");
                                Console.WriteLine("WSD ERROR: " + ex.Message);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Need to start bus before start WSD");
                    }
                    break;

                case "powoff":
                    if (wsd.OP_MODE != ControlOpMode.NoInit)
                    {
                        try
                        {
                            wsd.PowerOff();
                            Console.WriteLine("WSD is stopped successfully");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("WSD could not stop");
                            Console.WriteLine("WSD ERROR: " + ex.Message);
                        }
                    }
                    else
                    {
                        Console.WriteLine("WSD is already stopped,please start firstly");
                    }
                    break;

                case "autocenter":
                    wsd.keypad.AUTO_CENTER_SW = true;
                    Thread.Sleep(500);
                    Console.Write("Moving.");
                    while ((wsd.OP_MODE != ControlOpMode.Idle) || (otcxyz.OP_MODE != ControlOpMode.Idle) || (tbl.OP_MODE != ControlOpMode.Idle) || (otcxyz.AB_OPMODE != ControlOpMode.Idle))
                    {
                        Console.Write(" .");
                        Thread.Sleep(500);
                        Console.Write(" .");
                        Thread.Sleep(500);
                        Console.Write(" .");
                    }
                    Console.WriteLine("");
                    Console.WriteLine("Auto Center Finished");
                    wsd.keypad.AUTO_CENTER_SW = false;
                    break;

                case "autopos":
                    wsd.keypad.AUTO_POS_SW = true;
                    Thread.Sleep(500);
                    Console.Write("Moving.");
                    while ((wsd.OP_MODE != ControlOpMode.Idle) || (otcxyz.OP_MODE != ControlOpMode.Idle) || (tbl.OP_MODE != ControlOpMode.Idle) || (otcxyz.AB_OPMODE != ControlOpMode.Idle))
                    {
                        Console.Write(" .");
                        Thread.Sleep(500);
                        Console.Write(" .");
                        Thread.Sleep(500);
                        Console.Write(" .");
                    }
                    Console.WriteLine("");
                    Console.WriteLine("Auto Position Finished");
                    wsd.keypad.AUTO_POS_SW = false;
                    break;

                case "getstat":
                    Console.WriteLine("WSD Status: " + wsd.OP_MODE.ToString());
                    break;

                case "getpos":
                    Console.WriteLine("WSD Position: " + "X-" + wsd.X_POS.ToString() + " Y-" + wsd.Y_POS.ToString() + " Z-" + wsd.Z_POS.ToString() + " Tilt-" + wsd.TILT_POS.ToString() + " Ang-" + wsd.ANG_POS.ToString());
                    break;

                case "move":
                    if (cmdArray.Length < 3)
                    {
                        Console.WriteLine("The command wsd move will move WSD to designated position");
                        Console.WriteLine("wsd move [-x xpos] [-y ypos] [-z zpos] [-t tiltpos] [-a angpos]");
                        break;
                    }
                    var options = new WSDOption();
                    var parser  = new CommandLine.Parser(with => with.HelpWriter = Console.Out);

                    if (parser.ParseArgumentsStrict(SplitArray(cmdArray, 2, cmdArray.Length - 1), options, () => Console.WriteLine()))
                    {
                        try
                        {
                            if (options.Xpos != -8192.00)
                            {
                                wsd.XRelBtnPress();
                                wsd.X_POS = options.Xpos;
                                wsd.XRelBtnRelease();
                            }
                            if (options.ZPos != -8192.00)
                            {
                                wsd.ZRelBtnPress();
                                wsd.Z_POS = options.ZPos;
                                wsd.ZRelBtnRelease();
                            }
                            Thread.Sleep(500);
                            Console.WriteLine("WSD Move Finished!");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("WSD Move Error: " + ex.Message);
                        }
                    }
                    break;

                default:
                    Console.WriteLine("unknown WSD command,please make sure the command format is correct!");
                    break;
                }
                break;

            case "otc":
                switch (cmdArray[1])
                {
                case "powup":
                    if (busStarted)
                    {
                        if ((otcxyz.OP_MODE != ControlOpMode.NoInit) || (otcxyz.AB_OPMODE != ControlOpMode.NoInit))
                        {
                            Console.WriteLine("OTC is already started,please stop first");
                        }
                        else
                        {
                            try
                            {
                                otcxyz.PowerUp();
                                Console.WriteLine("OTC is started successfully");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("OTC could not start");
                                Console.WriteLine("OTC ERROR: " + ex.Message);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Need to start bus before start OTC");
                    }
                    break;

                case "powoff":
                    if (otcxyz.OP_MODE != ControlOpMode.NoInit)
                    {
                        try
                        {
                            otcxyz.PowerOff();
                            Console.WriteLine("OTC is stopped successfully");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("OTC could not stop");
                            Console.WriteLine("OTC ERROR: " + ex.Message);
                        }
                    }
                    else
                    {
                        Console.WriteLine("OTC is already stopped,please start firstly");
                    }
                    break;

                case "getstat":
                    Console.WriteLine("OTC XYZ Status: " + otcxyz.OP_MODE.ToString());
                    Console.WriteLine("OTC AB  Status: " + otcxyz.AB_OPMODE.ToString());
                    break;

                case "getpos":
                    Console.WriteLine("OTC Position: " + "X-" + otcxyz.X_POS.ToString() + " Y-" + otcxyz.Y_POS.ToString() + " Z-" + otcxyz.Z_POS.ToString() + " A-" + otcxyz.A_POS.ToString() + " B" + otcxyz.B_POS.ToString());
                    break;

                case "xyzmove":
                {
                    if (cmdArray.Length < 3)
                    {
                        Console.WriteLine("The command otc xyzmove will move otc xyz to designated position");
                        Console.WriteLine("otc xyzmove [-x xpos] [-y ypos] [-z zpos]");
                        break;
                    }
                    var options = new OTCOption();
                    var parser  = new CommandLine.Parser(with => with.HelpWriter = Console.Out);
                    if (parser.ParseArgumentsStrict(SplitArray(cmdArray, 2, cmdArray.Length - 1), options, () => Console.WriteLine()))
                    {
                        try
                        {
                            otcxyz.XYZRelBtnPress();
                            if (options.Xpos != -8192.00)
                            {
                                otcxyz.X_POS = options.Xpos;
                            }
                            if (options.Ypos != -8192.00)
                            {
                                otcxyz.Y_POS = options.Ypos;
                            }
                            if (options.ZPos != -8192.00)
                            {
                                otcxyz.Z_POS = options.ZPos;
                            }
                            otcxyz.XYZRelBtnRelease();
                            Thread.Sleep(500);
                            Console.WriteLine("OTC xyzmove Finished!");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("OTC xyzmove Error: " + ex.Message);
                        }
                    }
                }
                break;

                case "abmove":
                {
                    if (cmdArray.Length < 3)
                    {
                        Console.WriteLine("The command otc  abmove will move otc ab to designated position");
                        Console.WriteLine("otc abmove [-a apos] [-b bpos]");
                        break;
                    }
                    var options = new OTCOption();
                    var parser  = new CommandLine.Parser(with => with.HelpWriter = Console.Out);
                    if (parser.ParseArgumentsStrict(SplitArray(cmdArray, 2, cmdArray.Length - 1), options, () => Console.WriteLine()))
                    {
                        try
                        {
                            if (options.APos != -3276.0)
                            {
                                otcxyz.ARelBtnPress();
                                otcxyz.A_POS = options.APos;
                                otcxyz.ARelBtnRelease();
                            }

                            if (options.BPos != -3276.0)
                            {
                                otcxyz.BRelBtnPress();
                                otcxyz.B_POS = options.BPos;
                                otcxyz.BRelBtnRelease();
                            }
                            Thread.Sleep(500);
                            Console.WriteLine("OTC AB Move Finished!");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("OTC AB Move Error: " + ex.Message);
                        }
                    }
                }
                break;

                default:
                    Console.WriteLine("unknown OTC command,please make sure the command format is correct!");
                    break;
                }
                break;

            case "tbl":
                switch (cmdArray[1])
                {
                case "powup":
                    if (busStarted)
                    {
                        if (tbl.OP_MODE != ControlOpMode.NoInit)
                        {
                            Console.WriteLine("TBL is already started,please stop first");
                        }
                        else
                        {
                            try
                            {
                                tbl.PowerUp();
                                Console.WriteLine("TBL is started successfully");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("TBL could not start");
                                Console.WriteLine("TBL ERROR: " + ex.Message);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("Need to start bus before start TBL");
                    }
                    break;

                case "powoff":
                    if (tbl.OP_MODE != ControlOpMode.NoInit)
                    {
                        try
                        {
                            tbl.PowerOff();
                            Console.WriteLine("TBL is stopped successfully");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("TBL could not stop");
                            Console.WriteLine("TBL ERROR: " + ex.Message);
                        }
                    }
                    else
                    {
                        Console.WriteLine("TBL is already stopped,please start firstly");
                    }
                    break;

                case "autocenter":
                    tbl.AUTOCENTER_SW = true;
                    Thread.Sleep(500);
                    Console.Write("Moving.");
                    while ((wsd.OP_MODE != ControlOpMode.Idle) || (otcxyz.OP_MODE != ControlOpMode.Idle) || (tbl.OP_MODE != ControlOpMode.Idle) || (otcxyz.AB_OPMODE != ControlOpMode.Idle))
                    {
                        Console.Write(" .");
                        Thread.Sleep(500);
                        Console.Write(" .");
                        Thread.Sleep(500);
                        Console.Write(" .");
                    }
                    Console.WriteLine("");
                    Console.WriteLine("Auto Center Finished");
                    tbl.AUTOCENTER_SW = false;
                    break;

                case "getstat":
                    Console.WriteLine("TBL Status: " + tbl.OP_MODE.ToString());
                    break;

                case "getpos":
                    Console.WriteLine("TBL Position: " + "X-" + tbl.X_POS.ToString() + " Y-" + tbl.Y_POS.ToString() + " Z-" + tbl.Z_POS.ToString());
                    break;

                case "move":
                    if (cmdArray.Length < 3)
                    {
                        Console.WriteLine("The command tbl move will move table to designated position");
                        Console.WriteLine("tbl move [-x xpos] [-y ypos] [-z zpos]");
                        break;
                    }
                    var options = new TBLOption();
                    var parser  = new CommandLine.Parser(with => with.HelpWriter = Console.Out);
                    if (parser.ParseArgumentsStrict(SplitArray(cmdArray, 2, cmdArray.Length - 1), options, () => Console.WriteLine()))
                    {
                        try
                        {
                            tbl.FloatBtnDown();
                            if (options.Xpos != -8192.00)
                            {
                                tbl.X_POS = options.Xpos;
                            }
                            if (options.Ypos != -8192.00)
                            {
                                tbl.Y_POS = options.Ypos;
                            }
                            tbl.FloatBtnUp();
                            if (options.ZPos != -8192.00)
                            {
                                if (tbl.Z_POS < options.ZPos)
                                {
                                    tbl.ZUpBtnDown();
                                    tbl.Z_POS = options.ZPos;
                                    tbl.ZUpBtnUp();
                                }
                                else
                                {
                                    tbl.ZDownBtnDown();
                                    tbl.Z_POS = options.ZPos;
                                    tbl.ZDownBtnUp();
                                }
                            }
                            Thread.Sleep(500);
                            Console.WriteLine("TBL Move Finished!");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("TBL Move Error: " + ex.Message);
                        }
                    }
                    break;

                default:
                    Console.WriteLine("unknown TBL command,please make sure the command format is correct!");
                    break;
                }
                break;

            case "wsdbk":
                switch (cmdArray[1])
                {
                case "eject":
                    try
                    {
                        wsd.EjectDetector();
                        Console.WriteLine("Detector ejected");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Eject Error: " + ex.Message);
                    }
                    Thread.Sleep(1000);
                    break;

                case "insert":
                    try
                    {
                        wsd.InsertDetector(Byte.Parse(cmdArray[2]));
                        Console.WriteLine("Detector " + wsd.DET_ID.ToString() + " is inserted in Wall Bucky successfully");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("detector inserting failed");
                        Console.WriteLine("Error: " + ex.Message);
                    }
                    break;

                case "check":
                    Console.WriteLine("WSD Detector: " + wsd.DET_ID.ToString());
                    break;

                default:
                    Console.WriteLine("unknown WSD bucky command,please make sure the command format is correct!");
                    break;
                }
                break;

            case "tblbk":
                switch (cmdArray[1])
                {
                case "eject":
                    try
                    {
                        tbl.EjectDetector();
                        Console.WriteLine("Detector ejected");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Eject Error: " + ex.Message);
                    }
                    Thread.Sleep(1000);
                    break;

                case "insert":
                    try
                    {
                        tbl.InsertDetector(Byte.Parse(cmdArray[2]));
                        Console.WriteLine("Detector " + tbl.DET_ID.ToString() + " is inserted in Table Bucky successfully");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("detector inserting failed");
                        Console.WriteLine("Error: " + ex.Message);
                    }
                    break;

                case "check":
                    Console.WriteLine("TBL Detector: " + wsd.DET_ID.ToString());
                    break;

                default:
                    Console.WriteLine("unknown TBL bucky command,please make sure the command format is correct!");
                    break;
                }
                break;

                #region System CMD
            case "system":
                switch (cmdArray[1])
                {
                case "up":
                    if (!busStarted)
                    {
                        try
                        {
                            bus.StartBus();
                            busStarted = true;
                            Console.WriteLine("Can bus started successfully!");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Can bus could not start!");
                            Console.WriteLine("Error: " + ex.Message);
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Can bus is already running,please run system power up when state is poweroff");
                    }
                    if (otcxyz.OP_MODE == ControlOpMode.NoInit)
                    {
                        try
                        {
                            otcxyz.PowerUp();
                            Console.WriteLine("OTC started successfully!");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("OTC could not start!");
                            Console.WriteLine("Error: " + ex.Message);
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("OTC is already running");
                    }
                    if (wsd.OP_MODE == ControlOpMode.NoInit)
                    {
                        try
                        {
                            wsd.PowerUp();
                            Console.WriteLine("WSD started successfully!");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("WSD could not start!");
                            Console.WriteLine("Error: " + ex.Message);
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("WSD is already running");
                    }
                    if (tbl.OP_MODE == ControlOpMode.NoInit)
                    {
                        try
                        {
                            tbl.PowerUp();
                            Console.WriteLine("TBL started successfully!");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("TBL could not start!");
                            Console.WriteLine("Error: " + ex.Message);
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("TBL is already running");
                    }
                    if (!col.POW_ON)
                    {
                        try
                        {
                            col.PowerUp();
                            Console.WriteLine("Collimator started successfully!");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Collimator could not start!");
                            Console.WriteLine("Error: " + ex.Message);
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Collimator is already running");
                    }

                    if (busStarted && col.POW_ON && (otcxyz.OP_MODE == ControlOpMode.NoInit) && (wsd.OP_MODE == ControlOpMode.NoInit) && (otcxyz.AB_OPMODE == ControlOpMode.NoInit) && (tbl.OP_MODE == ControlOpMode.NoInit))
                    {
                        Console.WriteLine("Virtual Lab System Started Successfully!");
                    }
                    break;

                case "off":
                    if (otcxyz.OP_MODE != ControlOpMode.NoInit)
                    {
                        try
                        {
                            otcxyz.PowerOff();
                            Console.WriteLine("OTC stopped successfully!");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("OTC could not stop!");
                            Console.WriteLine("Error: " + ex.Message);
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("OTC is already stopped");
                    }
                    if (wsd.OP_MODE != ControlOpMode.NoInit)
                    {
                        try
                        {
                            wsd.PowerOff();
                            Console.WriteLine("WSD stopped successfully!");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("WSD could not stop!");
                            Console.WriteLine("Error: " + ex.Message);
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("WSD is already stopped");
                    }
                    if (tbl.OP_MODE != ControlOpMode.NoInit)
                    {
                        try
                        {
                            tbl.PowerOff();
                            Console.WriteLine("TBL stopped successfully!");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("TBL could not stop!");
                            Console.WriteLine("Error: " + ex.Message);
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("TBL is already stopped");
                    }
                    if (col.POW_ON)
                    {
                        try
                        {
                            col.PowerOff();
                            Console.WriteLine("Collimator stopped successfully!");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Collimator could not stop!");
                            Console.WriteLine("Error: " + ex.Message);
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Collimator is already stopped");
                    }
                    if (busStarted)
                    {
                        try
                        {
                            bus.StopBus();
                            busStarted = false;
                            Console.WriteLine("Can bus stopped successfully!");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Can bus could not stop!");
                            Console.WriteLine("Error: " + ex.Message);
                            break;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Can bus is already stopped,please run system power off when system is running");
                    }
                    break;

                case "getstat":
                    Console.WriteLine("Can Bus: " + busStarted.ToString());
                    Console.WriteLine("OTC XYZ: " + otcxyz.OP_MODE.ToString());
                    Console.WriteLine("OTC AB: " + otcxyz.AB_OPMODE.ToString());
                    Console.WriteLine("WSD: " + wsd.OP_MODE.ToString());
                    Console.WriteLine("TBL: " + tbl.OP_MODE.ToString());
                    Console.WriteLine("COLLIMATOR:" + col.POW_ON.ToString());
                    break;

                default:
                    Console.WriteLine("unknown SYS command,please make sure the command format is correct!");
                    break;
                }
                break;

                #endregion



            default:
                Console.WriteLine("unknown SYS command,please make sure the command format is correct!");
                break;
            }
        }
        static void Main(string[] args)
        {
            //-- 分析命令行参数
            var options = new Options();
            var parser  = new CommandLine.Parser(with => with.HelpWriter = Console.Error);

            if (!parser.ParseArgumentsStrict(args, options, () => Environment.Exit(-1)))
            {
                //-- 执行导出操作
                return;
            }


            string outputcsfile = options.OutPutCSFile;            //@"../../../../HotFixProto/proto.cs";

            string outputswcfile = options.OutPutCSWC;             //@"../../../../AS3ProtoBuf_Unity/Assets/StreamingAssets/proto.cswc";

            ASTool.Grammar grammar = ASCompiler.Grammar.getGrammar();

            string teststring = "package{}";

            Dictionary <string, string> srcFiles = new Dictionary <string, string>();

            string[] protofiles = null;


            {
                string path = options.ProtoAS3;

                if (path.EndsWith(".as"))
                {
                    path = System.IO.Path.GetDirectoryName(path);
                }

                if (string.IsNullOrEmpty(path))
                {
                    path = ".\\";
                }

                string[] ps = path.Split(System.IO.Path.DirectorySeparatorChar);
                if (ps.Length == 2 && string.IsNullOrEmpty(ps[1]) && ps[0].IndexOf(System.IO.Path.VolumeSeparatorChar) > 0)
                {
                    Console.WriteLine("无法在根目录下搜索.请将as源代码放到一个文件夹内");
                    return;
                }
                else if (System.IO.Directory.Exists(path))
                {
                    //Console.WriteLine(path);
                    //teststring = System.IO.File.ReadAllText(args[0]);
                    //files = System.IO.Directory.GetFiles(path, "*.as", System.IO.SearchOption.AllDirectories);

                    AddSrcFiles(path, srcFiles);
                    protofiles = new string[srcFiles.Count];
                    srcFiles.Keys.CopyTo(protofiles, 0);                     //(string[])files.Clone();
                }
            }


            if (srcFiles.Count == 0)
            {
                Console.Write("输入as文件所在路径");
                return;
            }

            //*********加入ProtoBuf API*****
            //string apidir = @"../../../../as3protobuflib";
            //if (System.IO.Directory.Exists(apidir))
            //{
            //	AddSrcFiles(apidir, srcFiles);
            //}
            //*********************

            var proj   = new ASTool.AS3.AS3Proj();
            var srcout = new ASTool.ConSrcOut();

            foreach (var src in srcFiles)
            {
                grammar.hasError = false;
                teststring       = System.IO.File.ReadAllText(src.Key);
                if (string.IsNullOrEmpty(teststring))
                {
                    continue;
                }

                teststring = teststring.Replace("override com.netease.protobuf.used_by_generated_code final function", "override protected final function");

                var tree = grammar.ParseTree(teststring, ASTool.AS3LexKeywords.LEXKEYWORDS,
                                             ASTool.AS3LexKeywords.LEXSKIPBLANKWORDS, src.Value);

                if (grammar.hasError)
                {
                    Console.WriteLine(src.Key);
                    Console.WriteLine("解析语法树失败!");
                    Console.ReadLine();
                    return;
                }



                var analyser = new ASTool.AS3FileGrammarAnalyser(proj, src.Value);
                if (!analyser.Analyse(tree))                 //生成项目的语法树
                {
                    Console.WriteLine(analyser.err.ToString());
                    Console.WriteLine("语义分析失败!");
                    Console.ReadLine();
                    return;
                }
#if DEBUG
                //Console.Clear();
#endif
            }

#if DEBUG
            Console.WriteLine();
            Console.WriteLine("====语法树翻译====");

            //runtimeCompiler rtLoader = new runtimeCompiler();
            foreach (var p in proj.SrcFiles)
            {
                p.Write(0, srcout);
            }
#endif
            //Console.Read();
            //return;
            ASCompiler.compiler.Builder builder = new ASCompiler.compiler.Builder();
            builder.LoadLibrary(System.IO.File.ReadAllBytes("as3protobuf.swc"));
            //builder.LoadLibrary( System.IO.File.ReadAllBytes("astoolglobal.swc"));

            builder.Build(proj, null);


            if (builder.buildErrors.Count == 0)
            {
                ASBinCode.CSWC swc = builder.getBuildOutSWC();
                //System.IO.File.WriteAllBytes("astoolglobal.swc", swc.toBytes());
                //System.IO.File.WriteAllBytes("as3protobuf.swc", swc.toBytes());
                System.IO.File.WriteAllBytes(outputswcfile, swc.toBytes());

                if (swc != null)
                {
                    ASRuntime.Player player = new ASRuntime.Player();
                    player.loadCode(swc);

                    StringBuilder stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine("using System;");

                    foreach (var cls in swc.classes)
                    {
                        if (cls.staticClass != null)
                        {
                            //判断是否在编译路径中
                            string fullname = cls.package + (string.IsNullOrEmpty(cls.package)?"":  ".") + cls.name + ".as";
                            foreach (var f in protofiles)
                            {
                                string ff = f.Replace("\\", ".").Replace("/", ".");
                                if (ff.EndsWith(fullname))
                                {
                                    CodeGen codeGen = new CodeGen(cls, swc, player);

                                    string cs = codeGen.GetCode();

                                    Console.Write(cs);
                                    stringBuilder.AppendLine(cs);

                                    break;
                                }
                            }
                        }
                    }

                    System.IO.File.WriteAllText(outputcsfile, stringBuilder.ToString());
                }
            }
        }
Exemple #20
0
        static void Main(string[] args)
        {
            if (args != null && args.Length > 0)
            {
                IVLVariables.isCommandLineArgsPresent = true;

                var options = new Options();
                var parser  = new CommandLine.Parser(with => with.HelpWriter = Console.Error);
                if (parser.ParseArgumentsStrict(args, options, () => Environment.Exit(-2)))
                {
                    string path = string.Empty;
                    Common.Validators.FileNameFolderPathValidator f = Common.Validators.FileNameFolderPathValidator.GetInstance();

                    switch (f.CheckFolderPath(options.ImageSavePath, ref path))
                    {
                    case Common.Validators.FolderPathErrorCode.Success:
                    {
                        Directory.SetCurrentDirectory(new FileInfo(Application.ExecutablePath).Directory.FullName);

                        IVLVariables.isCommandLineAppLaunch = true;
                        IVLVariables.CmdImageSavePath       = path;
                        break;
                    }

                    case Common.Validators.FolderPathErrorCode.FolderPath_Empty:
                    {
                        Directory.SetCurrentDirectory(new FileInfo(Application.ExecutablePath).Directory.FullName);

                        IVLVariables.isCommandLineAppLaunch = true;

                        break;
                    }

                    case Common.Validators.FolderPathErrorCode.InvalidDirectory:
                    {
                        MessageBox.Show("Please enter a valid path for the application to run");
                        return;
                    }

                    case Common.Validators.FolderPathErrorCode.DirectoryDoesnotExist:
                    {
                        if (!Directory.Exists(options.ImageSavePath))
                        {
                            Directory.CreateDirectory(options.ImageSavePath);
                            IVLVariables.isCommandLineAppLaunch = true;
                            Directory.SetCurrentDirectory(new FileInfo(Application.ExecutablePath).Directory.FullName);

                            IVLVariables.CmdImageSavePath = options.ImageSavePath;
                        }
                        break;
                    }
                    }

                    if (options.ReportBatchFilePath == null && options.ImageSavePath == null)//this has been added to run the old batchfile and to get the batchfile path.
                    {
                        options.ReportBatchFilePath = options.DefinitionFiles[0];
                    }
                    if (!string.IsNullOrEmpty(options.ReportBatchFilePath))
                    {
                        IVLVariables.isCommandLineAppLaunch = false;

                        IVLVariables.batchFilePath = options.ReportBatchFilePath;
                    }
                }
            }
            if (registryKey != null)
            {
                IVLVariables.appDirPathName = (string)registryKey.GetValue("AppDataPath");
            }
            bool createdNew = false;

            using (Mutex mutex = new Mutex(true, "IntuSoft", out createdNew))
            {
                if (createdNew)
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    try
                    {
                        if (string.IsNullOrEmpty(IVLVariables.appDirPathName))
                        {
                            IVLVariables.appDirPathName = new FileInfo(Application.ExecutablePath).Directory.FullName + Path.DirectorySeparatorChar;
                        }
                        else if (Directory.Exists(IVLVariables.appDirPathName))
                        {
                            IVLVariables.appDirPathName = IVLVariables.appDirPathName + Path.DirectorySeparatorChar;    // new FileInfo(Application.ExecutablePath).Directory.FullName + Path.DirectorySeparatorChar;
                        }
                        else
                        {
                            IVLVariables.appDirPathName = new FileInfo(Application.ExecutablePath).Directory.FullName + Path.DirectorySeparatorChar;
                        }


                        LogManager.Configuration.Variables["dir"]  = IVLVariables.appDirPathName;
                        LogManager.Configuration.Variables["dir2"] = DateTime.Now.ToString("yyyy-MM-dd");
                        #region Previous Log Codes Commented
                        //string filePath = new FileInfo(Application.ExecutablePath).Directory.FullName + Path.DirectorySeparatorChar
                        //                                 + "Logs" + Path.DirectorySeparatorChar + DateTime.Now.ToString("dd-MM-yyyy") + Path.DirectorySeparatorChar; //log file path
                        //if (!Directory.Exists(filePath))
                        //    Directory.CreateDirectory(filePath);

                        //log4net.GlobalContext.Properties["LogFileName"] = filePath + "Camera";
                        //log4net.Config.XmlConfigurator.Configure();

                        //log4net.GlobalContext.Properties["UIFileName"] = filePath + "UI";
                        //log4net.Config.XmlConfigurator.Configure();

                        //log4net.GlobalContext.Properties["FrameEventFileName"] = filePath + "Frames";
                        //log4net.Config.XmlConfigurator.Configure();
                        //// Configure log file for capture sequence//
                        //log4net.GlobalContext.Properties["CaptureFileName"] = filePath + "CaptureLog";
                        //log4net.Config.XmlConfigurator.Configure();

                        //log4net.GlobalContext.Properties["CaptureSettingsFileName"] = filePath + "CaptureSettingsLog";
                        //log4net.Config.XmlConfigurator.Configure();
                        #endregion
                        _currentInstance = new IvlMainWindow();
                        // code to create logs folder during start of the application
                        Application.Run(_currentInstance);
                    }
                    catch (Exception ex)
                    {
                        Common.ExceptionLogWriter.WriteLog(ex, exceptionLog);
//                            exceptionLog.Info(ex.StackTrace);
                    }
                }
                else
                {
                    //STRING_Program_062
                    //Common.CustomMessageBox.Show(Resources.Program_01 ,Resources.Software_Name, Common.Common.CustomMessageBoxButtons.OK, Common.CustomMessageBoxIcon.Information);
                    try
                    {
                        #region Region of Commented Code
                        //string filePath = new FileInfo(Application.ExecutablePath).Directory.FullName + Path.DirectorySeparatorChar
                        //                                 + "Logs" + Path.DirectorySeparatorChar + DateTime.Now.ToString("dd-MM-yyyy") + Path.DirectorySeparatorChar; //log file path
                        //if (!Directory.Exists(filePath))
                        //    Directory.CreateDirectory(filePath);

                        //log4net.GlobalContext.Properties["LogFileName"] = filePath + "Camera";
                        //log4net.Config.XmlConfigurator.Configure();

                        //log4net.GlobalContext.Properties["UIFileName"] = filePath + "UI";
                        //log4net.Config.XmlConfigurator.Configure();

                        //log4net.GlobalContext.Properties["FrameEventFileName"] = filePath + "Frames";
                        //log4net.Config.XmlConfigurator.Configure();
                        //// Configure log file for capture sequence//
                        //log4net.GlobalContext.Properties["CaptureFileName"] = filePath + "CaptureLog";
                        //log4net.Config.XmlConfigurator.Configure();
                        #endregion
                        if (IVLVariables.LangResourceManager == null)
                        {
                            IVLVariables.LangResourceManager = new ResourceManager("INTUSOFT.Desktop.LanguageResources.Res", typeof(IvlMainWindow).Assembly);
                        }
                        System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName(IVLVariables.LangResourceManager.GetString("Software_Name", IVLVariables.LangResourceCultureInfo));
                        foreach (System.Diagnostics.Process item in processes)
                        {
                            ShowWindow(item.MainWindowHandle, SW_RESTORE);
                            ShowWindow(item.MainWindowHandle, SW_SHOWMAXIMIZED);
                            SetForegroundWindow(item.MainWindowHandle);
                        }
                    }
                    catch (Exception ex)
                    {
                        Common.ExceptionLogWriter.WriteLog(ex, exceptionLog);
                    }
                }
            }
        }
Exemple #21
0
        static void ParseSysCmd(string cmd)
        {
            string[] cmdArray = cmd.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);
            if (cmdArray.Length < 2)
            {
                Console.WriteLine("Bad Command");
                return;
            }
            switch (cmdArray[0])
            {
                case "wsd":
                    switch (cmdArray[1])
                    {
                        case "powup":
                            if (busStarted)
                            {
                                if (wsd.OP_MODE != ControlOpMode.NoInit)
                                {
                                    Console.WriteLine("WSD is already started,please stop first");
                                }
                                else
                                {
                                    try
                                    {
                                        wsd.PowerUp();
                                        Console.WriteLine("WSD is started successfully");
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine("WSD could not start");
                                        Console.WriteLine("WSD ERROR: " + ex.Message);
                                    }
                                }
                            }
                            else
                            {
                                Console.WriteLine("Need to start bus before start WSD");
                            }
                            break;
                        case "powoff":
                            if (wsd.OP_MODE != ControlOpMode.NoInit)
                            {
                                try
                                {
                                    wsd.PowerOff();
                                    Console.WriteLine("WSD is stopped successfully");
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("WSD could not stop");
                                    Console.WriteLine("WSD ERROR: " + ex.Message);
                                }
                            }
                            else
                            {
                                Console.WriteLine("WSD is already stopped,please start firstly");
                            }
                            break;
                        case "autocenter":
                            wsd.keypad.AUTO_CENTER_SW = true;
                            Thread.Sleep(500);
                            Console.Write("Moving.");
                            while ((wsd.OP_MODE != ControlOpMode.Idle) || (otcxyz.OP_MODE != ControlOpMode.Idle) || (tbl.OP_MODE != ControlOpMode.Idle) || (otcxyz.AB_OPMODE != ControlOpMode.Idle))
                            {
                                Console.Write(" .");
                                Thread.Sleep(500);
                                Console.Write(" .");
                                Thread.Sleep(500);
                                Console.Write(" .");
                            }
                            Console.WriteLine("");
                            Console.WriteLine("Auto Center Finished");
                            wsd.keypad.AUTO_CENTER_SW = false;
                            break;
                        case "autopos":
                            wsd.keypad.AUTO_POS_SW = true;
                            Thread.Sleep(500);
                            Console.Write("Moving.");
                            while ((wsd.OP_MODE != ControlOpMode.Idle) || (otcxyz.OP_MODE != ControlOpMode.Idle) || (tbl.OP_MODE != ControlOpMode.Idle) || (otcxyz.AB_OPMODE != ControlOpMode.Idle))
                            {
                                Console.Write(" .");
                                Thread.Sleep(500);
                                Console.Write(" .");
                                Thread.Sleep(500);
                                Console.Write(" .");
                            }
                            Console.WriteLine("");
                            Console.WriteLine("Auto Position Finished");
                            wsd.keypad.AUTO_POS_SW = false;
                            break;

                        case "getstat":
                            Console.WriteLine("WSD Status: " + wsd.OP_MODE.ToString());
                            break;
                        case "getpos":
                            Console.WriteLine("WSD Position: " + "X-" + wsd.X_POS.ToString() + " Y-" + wsd.Y_POS.ToString() + " Z-" + wsd.Z_POS.ToString() + " Tilt-" + wsd.TILT_POS.ToString() + " Ang-" + wsd.ANG_POS.ToString());
                            break;
                        case "move":
                            if (cmdArray.Length < 3)
                            {
                                Console.WriteLine("The command wsd move will move WSD to designated position");
                                Console.WriteLine("wsd move [-x xpos] [-y ypos] [-z zpos] [-t tiltpos] [-a angpos]");
                                break;
                            }
                            var options = new WSDOption();
                            var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Out);

                             if (parser.ParseArgumentsStrict(SplitArray(cmdArray,2,cmdArray.Length-1), options, () => Console.WriteLine()))
                              {
                                  try
                                  {
                                      if (options.Xpos != -8192.00)
                                      {
                                          wsd.XRelBtnPress();
                                          wsd.X_POS = options.Xpos;
                                          wsd.XRelBtnRelease();
                                      }
                                      if (options.ZPos != -8192.00)
                                      {
                                          wsd.ZRelBtnPress();
                                          wsd.Z_POS = options.ZPos;
                                          wsd.ZRelBtnRelease();
                                      }
                                      Thread.Sleep(500);
                                      Console.WriteLine("WSD Move Finished!");
                                  }
                                  catch (Exception ex)
                                  {
                                      Console.WriteLine("WSD Move Error: " + ex.Message);
                                  }
                              }
                            break;
                        default:
                            Console.WriteLine("unknown WSD command,please make sure the command format is correct!");
                            break;
                    }
                    break;
                case "otc":
                    switch (cmdArray[1])
                    {
                        case "powup":
                            if (busStarted)
                            {
                                if ((otcxyz.OP_MODE != ControlOpMode.NoInit) || (otcxyz.AB_OPMODE != ControlOpMode.NoInit))
                                {
                                    Console.WriteLine("OTC is already started,please stop first");
                                }
                                else
                                {
                                    try
                                    {
                                        otcxyz.PowerUp();
                                        Console.WriteLine("OTC is started successfully");
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine("OTC could not start");
                                        Console.WriteLine("OTC ERROR: " + ex.Message);
                                    }
                                }
                            }
                            else
                            {
                                Console.WriteLine("Need to start bus before start OTC");
                            }
                            break;
                        case "powoff":
                            if (otcxyz.OP_MODE != ControlOpMode.NoInit)
                            {
                                try
                                {
                                    otcxyz.PowerOff();
                                    Console.WriteLine("OTC is stopped successfully");
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("OTC could not stop");
                                    Console.WriteLine("OTC ERROR: " + ex.Message);
                                }
                            }
                            else
                            {
                                Console.WriteLine("OTC is already stopped,please start firstly");
                            }
                            break;
                        case "getstat":
                            Console.WriteLine("OTC XYZ Status: " + otcxyz.OP_MODE.ToString());
                            Console.WriteLine("OTC AB  Status: " + otcxyz.AB_OPMODE.ToString());
                            break;
                        case "getpos":
                            Console.WriteLine("OTC Position: " + "X-" + otcxyz.X_POS.ToString() + " Y-" + otcxyz.Y_POS.ToString() + " Z-" + otcxyz.Z_POS.ToString() + " A-" + otcxyz.A_POS.ToString() + " B" + otcxyz.B_POS.ToString());
                            break;
                        case "xyzmove":
                            {
                                if (cmdArray.Length < 3)
                                {
                                    Console.WriteLine("The command otc xyzmove will move otc xyz to designated position");
                                    Console.WriteLine("otc xyzmove [-x xpos] [-y ypos] [-z zpos]");
                                    break;
                                }
                                var options = new OTCOption();
                                var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Out);
                                if (parser.ParseArgumentsStrict(SplitArray(cmdArray, 2, cmdArray.Length - 1), options, () => Console.WriteLine()))
                                {
                                    try
                                    {
                                        otcxyz.XYZRelBtnPress();
                                        if (options.Xpos != -8192.00)
                                        {
                                            otcxyz.X_POS = options.Xpos;
                                        }
                                        if (options.Ypos != -8192.00)
                                        {
                                            otcxyz.Y_POS = options.Ypos;
                                        }
                                        if (options.ZPos != -8192.00)
                                        {
                                            otcxyz.Z_POS = options.ZPos;
                                        }
                                        otcxyz.XYZRelBtnRelease();
                                        Thread.Sleep(500);
                                        Console.WriteLine("OTC xyzmove Finished!");
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine("OTC xyzmove Error: " + ex.Message);
                                    }
                                }
                            }
                            break;
                        case "abmove":
                            {
                                if (cmdArray.Length < 3)
                                {
                                    Console.WriteLine("The command otc  abmove will move otc ab to designated position");
                                    Console.WriteLine("otc abmove [-a apos] [-b bpos]");
                                    break;
                                }
                                var options = new OTCOption();
                                var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Out);
                                if (parser.ParseArgumentsStrict(SplitArray(cmdArray, 2, cmdArray.Length - 1), options, () => Console.WriteLine()))
                                {
                                    try
                                    {

                                        if (options.APos != -3276.0)
                                        {
                                            otcxyz.ARelBtnPress();
                                            otcxyz.A_POS = options.APos;
                                            otcxyz.ARelBtnRelease();
                                        }

                                        if (options.BPos != -3276.0)
                                        {
                                            otcxyz.BRelBtnPress();
                                            otcxyz.B_POS = options.BPos;
                                            otcxyz.BRelBtnRelease();
                                        }
                                        Thread.Sleep(500);
                                        Console.WriteLine("OTC AB Move Finished!");
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine("OTC AB Move Error: " + ex.Message);
                                    }
                                }
                            }
                            break;
                        default:
                            Console.WriteLine("unknown OTC command,please make sure the command format is correct!");
                            break;
                    }
                    break;
                case "tbl":
                    switch (cmdArray[1])
                    {
                        case "powup":
                            if (busStarted)
                            {
                                if (tbl.OP_MODE != ControlOpMode.NoInit)
                                {
                                    Console.WriteLine("TBL is already started,please stop first");
                                }
                                else
                                {
                                    try
                                    {
                                        tbl.PowerUp();
                                        Console.WriteLine("TBL is started successfully");
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine("TBL could not start");
                                        Console.WriteLine("TBL ERROR: " + ex.Message);
                                    }
                                }
                            }
                            else
                            {
                                Console.WriteLine("Need to start bus before start TBL");
                            }
                            break;
                        case "powoff":
                            if (tbl.OP_MODE != ControlOpMode.NoInit)
                            {
                                try
                                {
                                    tbl.PowerOff();
                                    Console.WriteLine("TBL is stopped successfully");
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("TBL could not stop");
                                    Console.WriteLine("TBL ERROR: " + ex.Message);
                                }
                            }
                            else
                            {
                                Console.WriteLine("TBL is already stopped,please start firstly");
                            }
                            break;
                        case "autocenter":
                            tbl.AUTOCENTER_SW = true;
                            Thread.Sleep(500);
                            Console.Write("Moving.");
                            while ((wsd.OP_MODE != ControlOpMode.Idle) || (otcxyz.OP_MODE != ControlOpMode.Idle) || (tbl.OP_MODE != ControlOpMode.Idle) || (otcxyz.AB_OPMODE != ControlOpMode.Idle))
                            {
                                Console.Write(" .");
                                Thread.Sleep(500);
                                Console.Write(" .");
                                Thread.Sleep(500);
                                Console.Write(" .");
                            }
                            Console.WriteLine("");
                            Console.WriteLine("Auto Center Finished");
                            tbl.AUTOCENTER_SW = false;
                            break;
                        case "getstat":
                            Console.WriteLine("TBL Status: " + tbl.OP_MODE.ToString());
                            break;
                        case "getpos":
                            Console.WriteLine("TBL Position: " + "X-" + tbl.X_POS.ToString() + " Y-" + tbl.Y_POS.ToString() + " Z-" + tbl.Z_POS.ToString());
                            break;
                        case "move":
                            if (cmdArray.Length < 3)
                            {
                                Console.WriteLine("The command tbl move will move table to designated position");
                                Console.WriteLine("tbl move [-x xpos] [-y ypos] [-z zpos]");
                                break;
                            }
                             var options = new TBLOption();
                            var parser = new CommandLine.Parser(with => with.HelpWriter = Console.Out);
                             if (parser.ParseArgumentsStrict(SplitArray(cmdArray,2,cmdArray.Length-1), options, () => Console.WriteLine()))
                              {
                                  try
                                  {
                                      tbl.FloatBtnDown();
                                      if (options.Xpos != -8192.00)
                                      {
                                          tbl.X_POS = options.Xpos;
                                      }
                                      if (options.Ypos != -8192.00)
                                      {
                                          tbl.Y_POS = options.Ypos;
                                      }
                                      tbl.FloatBtnUp();
                                      if (options.ZPos != -8192.00)
                                      {
                                          if (tbl.Z_POS < options.ZPos)
                                          {
                                              tbl.ZUpBtnDown();
                                              tbl.Z_POS = options.ZPos;
                                              tbl.ZUpBtnUp();
                                          }
                                          else
                                          {
                                              tbl.ZDownBtnDown();
                                              tbl.Z_POS = options.ZPos;
                                              tbl.ZDownBtnUp();
                                          }
                                      }
                                      Thread.Sleep(500);
                                      Console.WriteLine("TBL Move Finished!");
                                  }
                                  catch (Exception ex)
                                  {
                                      Console.WriteLine("TBL Move Error: " + ex.Message);
                                  }
                              }
                            break;
                        default:
                            Console.WriteLine("unknown TBL command,please make sure the command format is correct!");
                            break;
                    }
                    break;
                case "wsdbk":
                    switch (cmdArray[1])
                    {
                        case "eject":
                            try
                            {
                                wsd.EjectDetector();
                                Console.WriteLine("Detector ejected");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Eject Error: " + ex.Message);
                            }
                            Thread.Sleep(1000);
                            break;
                        case "insert":
                            try
                            {
                                wsd.InsertDetector(Byte.Parse(cmdArray[2]));
                                Console.WriteLine("Detector " + wsd.DET_ID.ToString() + " is inserted in Wall Bucky successfully");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("detector inserting failed");
                                Console.WriteLine("Error: " + ex.Message);
                            }
                            break;
                        case "check":
                            Console.WriteLine("WSD Detector: " + wsd.DET_ID.ToString());
                            break;
                        default:
                            Console.WriteLine("unknown WSD bucky command,please make sure the command format is correct!");
                            break;
                    }
                    break;
                case "tblbk":
                    switch (cmdArray[1])
                    {
                        case "eject":
                            try
                            {
                                tbl.EjectDetector();
                                Console.WriteLine("Detector ejected");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Eject Error: " + ex.Message);
                            }
                            Thread.Sleep(1000);
                            break;
                        case "insert":
                            try
                            {
                                tbl.InsertDetector(Byte.Parse(cmdArray[2]));
                                Console.WriteLine("Detector " + tbl.DET_ID.ToString() + " is inserted in Table Bucky successfully");
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("detector inserting failed");
                                Console.WriteLine("Error: " + ex.Message);
                            }
                            break;
                        case "check":
                            Console.WriteLine("TBL Detector: " + wsd.DET_ID.ToString());
                            break;
                        default:
                            Console.WriteLine("unknown TBL bucky command,please make sure the command format is correct!");
                            break;
                    }
                    break;

                #region System CMD
                case "system":
                    switch (cmdArray[1])
                    {
                        case "up":
                            if (!busStarted)
                            {
                                try
                                {
                                    bus.StartBus();
                                    busStarted = true;
                                    Console.WriteLine("Can bus started successfully!");
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("Can bus could not start!");
                                    Console.WriteLine("Error: " + ex.Message);
                                    break;
                                }
                            }
                            else
                            {
                                Console.WriteLine("Can bus is already running,please run system power up when state is poweroff");
                            }
                            if (otcxyz.OP_MODE == ControlOpMode.NoInit)
                            {
                                try
                                {
                                    otcxyz.PowerUp();
                                    Console.WriteLine("OTC started successfully!");
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("OTC could not start!");
                                    Console.WriteLine("Error: " + ex.Message);
                                    break;
                                }

                            }
                            else
                            {
                                Console.WriteLine("OTC is already running");
                            }
                            if (wsd.OP_MODE == ControlOpMode.NoInit)
                            {
                                try
                                {
                                    wsd.PowerUp();
                                    Console.WriteLine("WSD started successfully!");
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("WSD could not start!");
                                    Console.WriteLine("Error: " + ex.Message);
                                    break;
                                }

                            }
                            else
                            {
                                Console.WriteLine("WSD is already running");
                            }
                            if (tbl.OP_MODE == ControlOpMode.NoInit)
                            {
                                try
                                {
                                    tbl.PowerUp();
                                    Console.WriteLine("TBL started successfully!");
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("TBL could not start!");
                                    Console.WriteLine("Error: " + ex.Message);
                                    break;
                                }

                            }
                            else
                            {
                                Console.WriteLine("TBL is already running");
                            }
                            if (!col.POW_ON)
                            {
                                try
                                {
                                    col.PowerUp();
                                    Console.WriteLine("Collimator started successfully!");
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("Collimator could not start!");
                                    Console.WriteLine("Error: " + ex.Message);
                                    break;
                                }
                            }
                            else
                            {
                                Console.WriteLine("Collimator is already running");
                            }

                            if (busStarted && col.POW_ON && (otcxyz.OP_MODE == ControlOpMode.NoInit) && (wsd.OP_MODE == ControlOpMode.NoInit) && (otcxyz.AB_OPMODE == ControlOpMode.NoInit) && (tbl.OP_MODE == ControlOpMode.NoInit))
                            {
                                Console.WriteLine("Virtual Lab System Started Successfully!");
                            }
                            break;

                        case "off":
                            if (otcxyz.OP_MODE != ControlOpMode.NoInit)
                            {
                                try
                                {
                                    otcxyz.PowerOff();
                                    Console.WriteLine("OTC stopped successfully!");
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("OTC could not stop!");
                                    Console.WriteLine("Error: " + ex.Message);
                                    break;
                                }

                            }
                            else
                            {
                                Console.WriteLine("OTC is already stopped");
                            }
                            if (wsd.OP_MODE != ControlOpMode.NoInit)
                            {
                                try
                                {
                                    wsd.PowerOff();
                                    Console.WriteLine("WSD stopped successfully!");
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("WSD could not stop!");
                                    Console.WriteLine("Error: " + ex.Message);
                                    break;
                                }

                            }
                            else
                            {
                                Console.WriteLine("WSD is already stopped");
                            }
                            if (tbl.OP_MODE != ControlOpMode.NoInit)
                            {
                                try
                                {
                                    tbl.PowerOff();
                                    Console.WriteLine("TBL stopped successfully!");
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("TBL could not stop!");
                                    Console.WriteLine("Error: " + ex.Message);
                                    break;
                                }

                            }
                            else
                            {
                                Console.WriteLine("TBL is already stopped");
                            }
                            if (col.POW_ON)
                            {
                                try
                                {
                                    col.PowerOff();
                                    Console.WriteLine("Collimator stopped successfully!");
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("Collimator could not stop!");
                                    Console.WriteLine("Error: " + ex.Message);
                                    break;
                                }
                            }
                            else
                            {
                                Console.WriteLine("Collimator is already stopped");
                            }
                            if (busStarted)
                            {
                                try
                                {
                                    bus.StopBus();
                                    busStarted = false;
                                    Console.WriteLine("Can bus stopped successfully!");
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine("Can bus could not stop!");
                                    Console.WriteLine("Error: " + ex.Message);
                                    break;
                                }
                            }
                            else
                            {
                                Console.WriteLine("Can bus is already stopped,please run system power off when system is running");
                            }
                            break;
                        case "getstat":
                            Console.WriteLine("Can Bus: " + busStarted.ToString());
                            Console.WriteLine("OTC XYZ: " + otcxyz.OP_MODE.ToString());
                            Console.WriteLine("OTC AB: " + otcxyz.AB_OPMODE.ToString());
                            Console.WriteLine("WSD: " + wsd.OP_MODE.ToString());
                            Console.WriteLine("TBL: " + tbl.OP_MODE.ToString());
                            Console.WriteLine("COLLIMATOR:" + col.POW_ON.ToString());
                            break;
                        default:
                            Console.WriteLine("unknown SYS command,please make sure the command format is correct!");
                            break;
                    }
                    break;

                #endregion

                default:
                    Console.WriteLine("unknown SYS command,please make sure the command format is correct!");
                    break;
            }
        }
Exemple #22
0
        static void Main(string[] args)
        {
            try
            {
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                System.Console.WriteLine("HyperVBackup 2.0");
                System.Console.WriteLine("Copyright (C) 2012 Cloudbase Solutions Srl");
                System.Console.WriteLine("Copyright (C) 2015 Coliseo Software Srl");

                var parser = new Parser(ConfigureSettings);
                var options = new Options();
                if (parser.ParseArgumentsStrict(args, options, () => Environment.Exit(1)))
                {
                    GetConsoleWidth();

                    var vmNames = GetVMNames(options);

                    System.Console.WriteLine();
                    if (vmNames == null)
                        System.Console.WriteLine("Backing up all VMs on this server");

                    if (!Directory.Exists(options.Output))
                        throw new Exception(string.Format("The folder \"{0}\" is not valid", options.Output));

                    VMNameType nameType = options.Name ? VMNameType.ElementName : VMNameType.SystemName;

                    BackupManager mgr = new BackupManager();
                    mgr.BackupProgress += MgrBackupProgress;

                    System.Console.CancelKeyPress += Console_CancelKeyPress;

                    var backupOptions = new HyperVBackUp.Engine.Options
                    {
                        CompressionLevel = options.CompressionLevel,
                        Output = options.Output,
                        OutputFormat = options.OutputFormat,
                        SingleSnapshot = options.SingleSnapshot,
                        VhdInclude = options.VhdInclude,
                        VhdIgnore = options.VhdIgnore,
                        Password = options.Password
                    };

                    var vmNamesMap = mgr.VSSBackup(vmNames, nameType, backupOptions);

                    CheckRequiredVMs(vmNames, nameType, vmNamesMap);

                    ShowElapsedTime(stopwatch);
                }
            }
            catch (BackupCancelledException ex)
            {
                System.Console.Error.WriteLine(string.Format(ex.Message));
                Environment.Exit(3);
            }
            catch (Exception ex)
            {
                System.Console.Error.WriteLine(string.Format("Error: {0}", ex.Message));
                System.Console.Error.WriteLine(ex.StackTrace);
                Environment.Exit(2);
            }

            Environment.Exit(cancel ? 3 : 0);
        }
Exemple #23
0
        public BitSharpNode(string[] args, bool strictArgs)
        {
            // parse command line options
            var options = new NodeOptions();

            var parser = new Parser(settings =>
            {
                settings.HelpWriter = Parser.Default.Settings.HelpWriter;
                settings.MutuallyExclusive = true;
            });

            if (strictArgs)
            {
                parser.ParseArgumentsStrict(args, options);
            }
            else
            {
                if (!parser.ParseArguments(args, options))
                    throw new InvalidOperationException($"Invalid command line:\n {options.GetUsage()}");
            }

            options.DataFolder = Environment.ExpandEnvironmentVariables(options.DataFolder);

            // clean data folder, depending on options
            if (Directory.Exists(options.DataFolder))
            {
                if (options.Clean || options.CleanAll)
                {
                    var dataPath = Path.Combine(options.DataFolder, "Data");
                    var peerPath = Path.Combine(options.DataFolder, "Peer");

                    if (Directory.Exists(dataPath))
                        Directory.Delete(dataPath, recursive: true);
                    if (Directory.Exists(peerPath))
                        Directory.Delete(peerPath, recursive: true);
                }

                if (options.CleanAll)
                {
                    var iniPath = Path.Combine(options.DataFolder, "BitSharp.ini");
                    var logPath = Path.Combine(options.DataFolder, "BitSharp.log");

                    if (File.Exists(iniPath))
                        File.Delete(iniPath);
                    if (File.Exists(logPath))
                        File.Delete(logPath);
                }
            }

            // create data folder
            Directory.CreateDirectory(options.DataFolder);

            // initialize kernel
            Kernel = new StandardKernel();
            try
            {
                // add logging module
                Kernel.Load(new LoggingModule(options.DataFolder, LogLevel.Info));

                // log startup
                logger = LogManager.GetCurrentClassLogger();
                logger.Info($"Starting up: {DateTime.Now}");
                logger.Info($"Using data folder: {options.DataFolder}");

                // write default ini file, if it doesn't exist
                var iniFile = Path.Combine(options.DataFolder, "BitSharp.ini");
                if (!File.Exists(iniFile))
                {
                    var assembly = Assembly.GetAssembly(GetType());
                    using (var defaultIniStream = assembly.GetManifestResourceStream("BitSharp.Node.BitSharp.ini"))
                    using (var outputStream = File.Create(iniFile))
                    {
                        defaultIniStream.CopyTo(outputStream);
                    }
                }

                logger.Info($"Loading configuration: {iniFile}");

                // parse ini
                var iniConfig = Configuration.LoadFromFile(iniFile);

                // parse node config
                if (!iniConfig.Contains("Node"))
                    throw new ApplicationException("INI is missing [Node] section");

                nodeConfig = iniConfig["Node"].CreateObject<NodeConfig>();

                // parse dev config
                if (iniConfig.Contains("Dev"))
                {
                    var devConfig = iniConfig["Dev"].CreateObject<DevConfig>();

                    if (devConfig.SecondaryBlockFolder != null)
                    {
                        BlockRequestWorker.SecondaryBlockFolder =
                            Environment.ExpandEnvironmentVariables(devConfig.SecondaryBlockFolder);
                    }
                }

                // add storage module
                switch (nodeConfig.StorageType)
                {
                    case StorageType.Esent:
                        if (!iniConfig.Contains("Esent"))
                            throw new ApplicationException("INI is missing [Esent] section");

                        var esentConfig = iniConfig["Esent"].CreateObject<EsentConfig>();

                        var cacheSizeMaxBytes = esentConfig.CacheSizeMaxMebiBytes != null
                            ? esentConfig.CacheSizeMaxMebiBytes * 1.MEBIBYTE() : null;

                        Kernel.Load(new EsentStorageModule(options.DataFolder, nodeConfig.ChainType, cacheSizeMaxBytes));
                        break;

                    case StorageType.LevelDb:
                        Kernel.Load(new LevelDbStorageModule(options.DataFolder, nodeConfig.ChainType));
                        break;

                    case StorageType.Memory:
                        Kernel.Load(new MemoryStorageModule());
                        Kernel.Load(new NetworkMemoryStorageModule());
                        break;

                    default:
                        throw new ApplicationException($"INI has unrecognized storage type: {nodeConfig.StorageType}");
                }

                // add rules module
                Kernel.Load(new RulesModule(nodeConfig.ChainType));

                // initialize rules
                var rules = Kernel.Get<ICoreRules>();
                rules.IgnoreScripts = !nodeConfig.ExecuteScripts;

                // initialize the blockchain daemon
                CoreDaemon = Kernel.Get<CoreDaemon>();
                CoreDaemon.PruningMode = nodeConfig.PruningMode;
                Kernel.Bind<CoreDaemon>().ToConstant(CoreDaemon).InTransientScope();

                // initialize p2p client
                LocalClient = Kernel.Get<LocalClient>();
                Kernel.Bind<LocalClient>().ToConstant(LocalClient).InTransientScope();
            }
            catch (Exception)
            {
                Kernel.Dispose();
                throw;
            }
        }