Example #1
0
        public static void Main(string[] startup_args)
        {
            //添加程序集解析事件
            AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
            {
                String resourceName = "CMWTAT_DIGITAL.Res." +

                                      new AssemblyName(args.Name).Name + ".dll";

                using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
                {
                    Byte[] assemblyData = new Byte[stream.Length];

                    stream.Read(assemblyData, 0, assemblyData.Length);

                    return(Assembly.Load(assemblyData));
                }
            };

            //if (startup_args.Length == 0)
            //{
            //    //MessageBox.Show("ARGS NULL");
            //    //Console.WriteLine("CMWTAT Digital Edition V2");
            //    //Console.WriteLine("This application can use console args.");
            //}
            foreach (string arg in startup_args)
            {
                Console.WriteLine("arg: " + arg);
                if (arg == "-a" || arg == "--auto")
                {
                    Console.WriteLine("AUTO: True");
                    autoact = true;
                }
                if (arg == "-h" || arg == "--hide")
                {
                    Console.WriteLine("HIDE: True");
                    hiderun = true;
                }
                if (arg == "-e" || arg == "--expact")
                {
                    Console.WriteLine("EXPACT: True");
                    expact = true;
                }
                if (arg == "-?" || arg == "--help")
                {
                    Console.WriteLine("EXPACT: True");
                    showhelp = true;
                }
            }

            CMWTAT_DIGITAL.App app = new CMWTAT_DIGITAL.App();//WPF项目的Application实例,用来启动WPF项目的
            app.InitializeComponent();
            app.Run();
        }
Example #2
0
        public static void Main(string[] startup_args)
        {
            //添加程序集解析事件
            //AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
            //{
            //    String resourceName = "CMWTAT_DIGITAL.Res." +

            //    new AssemblyName(args.Name).Name + ".dll";

            //    Console.WriteLine("Load Assembly: " + resourceName);

            //    using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
            //    {
            //        if (stream == null)
            //            return null;

            //        Byte[] assemblyData = new Byte[stream.Length];

            //        stream.Read(assemblyData, 0, assemblyData.Length);

            //        return Assembly.Load(assemblyData);
            //    }
            //};
            var loadedAssemblies = new Dictionary <string, Assembly>();

            AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
            {
                String resourceName = "CMWTAT_DIGITAL.Res." +
                                      new AssemblyName(args.Name).Name + ".dll";

                //Must return the EXACT same assembly, do not reload from a new stream
                if (loadedAssemblies.TryGetValue(resourceName, out Assembly loadedAssembly))
                {
                    return(loadedAssembly);
                }

                using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
                {
                    if (stream == null)
                    {
                        return(null);
                    }
                    Byte[] assemblyData = new Byte[stream.Length];

                    stream.Read(assemblyData, 0, assemblyData.Length);

                    var assembly = Assembly.Load(assemblyData);
                    loadedAssemblies[resourceName] = assembly;
                    return(assembly);
                }
            };

            foreach (string arg in startup_args)
            {
                Console.WriteLine("arg: " + arg);
                if (arg == "-a" || arg == "--auto")
                {
                    Console.WriteLine("AUTO: True");
                    autoact = true;
                }
                if (arg == "-h" || arg == "--hide")
                {
                    Console.WriteLine("HIDE: True");
                    hiderun = true;
                }
                if (arg == "-e" || arg == "--expact")
                {
                    Console.WriteLine("EXPACT: True");
                    expact = true;
                }
                if (arg == "-l" || arg == "--log")
                {
                    Console.WriteLine("LOG: True");
                    log2file = true;
                }
                if (arg == "-?" || arg == "--help")
                {
                    Console.WriteLine("SHOWHELP: True");
                    showhelp = true;
                }
            }

            CMWTAT_DIGITAL.App app = new CMWTAT_DIGITAL.App();//WPF项目的Application实例,用来启动WPF项目的
            app.InitializeComponent();
            app.Run();
        }