Exemplo n.º 1
0
        /// <summary>
        /// 初始化浏览器
        /// </summary>
        private void InitializeBrowser()
        {
            if (IsDesignMode())
            {
                return;
            }
            CefRuntime.Load(ConfigurationManager.AppSettings["CefLibraryPath"]);
            var mainArgs = new CefMainArgs(new string[] { });
            var cefApp   = new WebApp();
            var exitCode = CefRuntime.ExecuteProcess(mainArgs, cefApp, IntPtr.Zero);

            if (exitCode != -1)
            {
                return;
            }
            var settings = new CefSettings
            {
                SingleProcess            = false,
                MultiThreadedMessageLoop = true,
                LogSeverity = CefLogSeverity.Disable,
                Locale      = "zh-CN"
            };

            CefRuntime.Initialize(mainArgs, settings, cefApp, IntPtr.Zero);
            if (!settings.MultiThreadedMessageLoop)
            {
                Application.Idle += (sender, e) => CefRuntime.DoMessageLoopWork();
            }
        }
Exemplo n.º 2
0
        private static int Main(string[] args)
        {
            try
            {
                CefRuntime.Load();
            }
            catch (DllNotFoundException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(1);
            }
            catch (CefRuntimeException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(2);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(3);
            }

            var mainArgs = new CefMainArgs(args);
            var app      = new DemoApp();

            var exitCode = CefRuntime.ExecuteProcess(mainArgs, app);

            if (exitCode != -1)
            {
                return(exitCode);
            }

            var codeBase           = Assembly.GetExecutingAssembly().CodeBase;
            var localFolder        = Path.GetDirectoryName(new Uri(codeBase).LocalPath);
            var browserProcessPath = CombinePaths(localFolder, "..", "..", "..",
                                                  "CefGlue.Demo.WinForms", "bin", "Release", "Xilium.CefGlue.Demo.WinForms.exe");

            var settings = new CefSettings
            {
                BrowserSubprocessPath    = browserProcessPath,
                MultiThreadedMessageLoop = true,
                LogSeverity = CefLogSeverity.Disable,
                LogFile     = "CefGlue.log",
            };

            CefRuntime.Initialize(mainArgs, settings, app);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (!settings.MultiThreadedMessageLoop)
            {
                Application.Idle += (sender, e) => { CefRuntime.DoMessageLoopWork(); };
            }

            Application.Run(new MainForm());

            CefRuntime.Shutdown();
            return(0);
        }
Exemplo n.º 3
0
 private void Update()
 {
     if (_mDoUpdates)
     {
         CefRuntime.DoMessageLoopWork();
     }
 }
 private void FixedUpdate()
 {
     if (!this.shouldQuit)
     {
         CefRuntime.DoMessageLoopWork();
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// The platform run message loop.
 /// </summary>
 protected override void PlatformRunMessageLoop()
 {
     if (!MultiThreadedMessageLoop)
     {
         System.Windows.Forms.Application.Idle += (s, e) => CefRuntime.DoMessageLoopWork();
     }
     System.Windows.Forms.Application.Run();
 }
Exemplo n.º 6
0
        private static int Main(string[] args)
        {
            try
            {
                CefRuntime.Load();
            }
            catch (DllNotFoundException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(1);
            }
            catch (CefRuntimeException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(2);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(3);
            }

            var mainArgs = new CefMainArgs(args);
            var app      = new DemoApp();

            var exitCode = CefRuntime.ExecuteProcess(mainArgs, app);

            if (exitCode != -1)
            {
                return(exitCode);
            }

            var settings = new CefSettings
            {
                // BrowserSubprocessPath = @"D:\fddima\Projects\Xilium\Xilium.CefGlue\CefGlue.Demo\bin\Release\Xilium.CefGlue.Demo.exe",
                SingleProcess            = false,
                MultiThreadedMessageLoop = true,
                LogSeverity         = CefLogSeverity.Disable,
                LogFile             = "CefGlue.log",
                RemoteDebuggingPort = 7777,
            };

            CefRuntime.Initialize(mainArgs, settings, app);
            CefRuntime.RegisterSchemeHandlerFactory("http", "server", new MySchemeHandlerFactory());

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (!settings.MultiThreadedMessageLoop)
            {
                Application.Idle += (sender, e) => { CefRuntime.DoMessageLoopWork(); };
            }

            Application.Run(new MainForm());

            CefRuntime.Shutdown();
            return(0);
        }
Exemplo n.º 7
0
        static void Main()
        {
            vt1 = new VisualStudio2012DarkTheme();
            //vt2 = new Office2013DarkTheme();
            //vt3 = new VisualStudio2012LightTheme();
            //vt4 = new Windows7Theme();
            //vt5 = new Windows8Theme();

            CefRuntime.Load();
            var mainArgs = new CefMainArgs(new string[] { });
            var settings = new CefSettings();

            settings.MultiThreadedMessageLoop = CefRuntime.Platform == CefRuntimePlatform.Windows;
            settings.SingleProcess            = false;
            settings.LogSeverity         = CefLogSeverity.Verbose;
            settings.LogFile             = "cef.log";
            settings.Locale              = "zh-CN";
            settings.ResourcesDirPath    = System.IO.Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetEntryAssembly().CodeBase).LocalPath);
            settings.RemoteDebuggingPort = 20480;
            settings.NoSandbox           = true;

            //settings.CachePath = @"E:\mine\工作相关\工作代码\Spot Trade System\UseOnlineTradingSystem\UseOnlineTradingSystem\bin\Debug";

            var app      = new BsCefApp();
            var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero);

            if (exitCode != -1)
            {
                return;
            }
            CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (!settings.MultiThreadedMessageLoop)
            {
                Application.Idle += (sender, e) => { CefRuntime.DoMessageLoopWork(); };
            }

            LoginFm = new FormLogin();
            main    = new MainForm();
            //mf = new MainForm();
            //Application.Run(mf);
            // Application.Run(LoginFm);
            try
            {
                Application.Run(LoginFm);
            }
            catch (Exception err)
            {
                Logger.LogError(err.ToString());
            }
            Logger.LogInfo("退出程序!");
            USeManager.Instance.Stop();
            KillProcess();
            //CefRuntime.Shutdown();
            //Environment.Exit(0);
        }
Exemplo n.º 8
0
 IEnumerator MessagePump()
 {
     while (!mShouldQuit)
     {
         CefRuntime.DoMessageLoopWork();
         sCEFClient.UpdateTexture(BrowserTexture);
         yield return(new WaitForEndOfFrame());
     }
 }
Exemplo n.º 9
0
        public CefWebBrowser()
        {
            /* BEG: modbyme */
            if (LicenseManager.UsageMode != LicenseUsageMode.Designtime)
            {
                CefRuntime.Load();

                CefSettings settings = new CefSettings();
                settings.CachePath = @"Cache"; //Cache Folder
                settings.MultiThreadedMessageLoop = false;
                settings.NoSandbox = true;
                //settings.LogSeverity = CefLogSeverity.Error;
                //settings.LogFile = "cef.log";
                //settings.ResourcesDirPath = System.IO.Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetEntryAssembly().CodeBase).LocalPath);
                //settings.RemoteDebuggingPort = 20480;
                // // settings.SingleProcess = true;

                CefMainArgs mainArgs = new CefMainArgs(Environment.GetCommandLineArgs());
                CefWebApp app = new CefWebApp(this);

                if (CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero) != -1)
                {
                    MessageBox.Show("ExecuteProcess failed");
                }

                CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero);

                Application.Idle += (s, e) => CefRuntime.DoMessageLoopWork();
            }
            /* END: modbyme */

            SetStyle(
                ControlStyles.ContainerControl
                | ControlStyles.ResizeRedraw
                | ControlStyles.FixedWidth
                | ControlStyles.FixedHeight
                | ControlStyles.StandardClick
                | ControlStyles.UserMouse
                | ControlStyles.SupportsTransparentBackColor
                | ControlStyles.StandardDoubleClick
                | ControlStyles.OptimizedDoubleBuffer
                | ControlStyles.CacheText
                | ControlStyles.EnableNotifyMessage
                | ControlStyles.DoubleBuffer
                | ControlStyles.OptimizedDoubleBuffer
                | ControlStyles.UseTextForAccessibility
                | ControlStyles.Opaque,
                false);

            SetStyle(
                ControlStyles.UserPaint
                | ControlStyles.AllPaintingInWmPaint
                | ControlStyles.Selectable,
                true);

            StartUrl = "about:blank";
        }
Exemplo n.º 10
0
 public void Update()
 {
     if (!isMultiThreadedMessageLoop)
     {
         dispatcher.PostTask(new Action(() =>
         {
             CefRuntime.DoMessageLoopWork();
         }));
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// The run message loop.
        /// </summary>
        public static void RunMessageLoop()
        {
            while (User32Methods.GetMessage(out Message msg, IntPtr.Zero, 0, 0) != 0)
            {
                CefRuntime.DoMessageLoopWork();

                User32Methods.TranslateMessage(ref msg);
                User32Methods.DispatchMessage(ref msg);
            }
        }
Exemplo n.º 12
0
        protected void PlatformRunMessageLoop()
        {
            if (!MultiThreadedMessageLoop)
            {
                Application.Idle += (s, e) => CefRuntime.DoMessageLoopWork();
            }

            Program.frmLogin = new FrmLogin();

            Application.Run(Program.frmLogin);
        }
Exemplo n.º 13
0
 IEnumerator MessagePump()
 {
     while (!mShouldQuit)
     {
         CefRuntime.DoMessageLoopWork();
         foreach (BaseCEFClient client in registeredClients)
         {
             client.Update();
         }
         yield return(new WaitForEndOfFrame());
     }
 }
Exemplo n.º 14
0
 private IEnumerator MessagePump()
 {
     while (!this.shouldQuit)
     {
         CefRuntime.DoMessageLoopWork();
         if (!this.shouldQuit)
         {
             this.cefClient.UpdateTexture(this.BrowserTexture);
         }
         yield return(null);
     }
 }
Exemplo n.º 15
0
        public void Stop()
        {
            int maximumBrowserKillWaitTime = BrowserSettings.Instance.RuntimeSettings.MaximumBrowserKillWaitTime;

            bool isDoingMessageLoopWork = true;

            Thread shutdownThread = new Thread(new ThreadStart(() =>
            {
                while (BrowserInstanceCount > 0)
                {
                    if (!isMultiThreadedMessageLoop)
                    {
                        dispatcher.BeginInvoke(new Action(() => { if (isDoingMessageLoopWork)
                                                                  {
                                                                      CefRuntime.DoMessageLoopWork();
                                                                  }
                                                          }));
                    }

                    GC.Collect(GC.MaxGeneration);
                    GC.WaitForPendingFinalizers();
                    Thread.Sleep(100);
                }
            }));

            shutdownThread.Start();

            while (!shutdownThread.Join(maximumBrowserKillWaitTime))
            {
                MessageBoxResult result = MessageBox.Show("Would you like to continue waiting? \r\nNo will forcefully abort the clients and may result in unexpected behavior.", "Shutting down the browser instances is taking longer than usual.", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.No)
                {
                    shutdownThread.Abort();
                    API.Instance.Log("BrowserManager::Stop() Aborting shutdown thread due to timeout.");
                }
            }

            isDoingMessageLoopWork = false;

            if (BrowserInstanceCount > 0)
            {
                API.Instance.Log("BrowserManager::Stop() Unable to dispose of {0} orphaned browser objects", BrowserInstanceCount);
            }

            dispatcher.BeginInvoke(new Action(() => { CefRuntime.Shutdown(); }));
            dispatcher.BeginInvokeShutdown(DispatcherPriority.Normal);
            if (!dispatcherThread.Join(maximumBrowserKillWaitTime))
            {
                dispatcherThread.Abort();
                API.Instance.Log("BrowserManager::Stop() Unable to abort dispatcher thread, giving up");
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// The run message loop.
        /// </summary>
        public static void RunMessageLoop()
        {
            while (User32Methods.GetMessage(out Message msg, IntPtr.Zero, 0, 0) != 0)
            {
                if (ChromelyConfiguration.Instance.HostFrameless)
                {
                    CefRuntime.DoMessageLoopWork();
                }

                User32Methods.TranslateMessage(ref msg);
                User32Methods.DispatchMessage(ref msg);
            }
        }
Exemplo n.º 17
0
        private IEnumerator MessagePump()
        {
            if (messagePumpIsOff)
            {
                messagePumpIsOff = false;

                while (!UnityCefEngine.shouldQuit)
                {
#if !UNITY_EDITOR
                    CefRuntime.DoMessageLoopWork();
#endif
                    yield return(null);
                }
            }
        }
        protected override void OnScheduleMessagePumpWork(long delayMs)
        {
            lock (schedule)
            {
                _current?.Dispose();

                if (delayMs <= 0)
                {
                    delayMs = 1;
                }

                _current = Observable.Interval(TimeSpan.FromMilliseconds(delayMs)).ObserveOn(AvaloniaScheduler.Instance)
                           .Subscribe(i => { CefRuntime.DoMessageLoopWork(); });
            }
        }
Exemplo n.º 19
0
        private static void RunMessageLoopInternal()
        {
            while (GetMessage(out MSG msg, IntPtr.Zero, 0, 0) != 0)
            {
                if (msg.message == (uint)WM.CLOSE)
                {
                    DetachKeyboardHook();
                }

                if (NativeInstance._options.KioskMode && msg.message == (uint)WM.HOTKEY && msg.wParam == (IntPtr)1)
                {
                    PostMessage(NativeInstance._handle, (uint)WM.CLOSE, IntPtr.Zero, IntPtr.Zero);
                }
                if (NativeInstance._options.WindowFrameless || NativeInstance._options.KioskMode)
                {
                    CefRuntime.DoMessageLoopWork();
                }

                TranslateMessage(ref msg);
                DispatchMessage(ref msg);
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// The run message loop.
        /// </summary>
        public static void RunMessageLoop()
        {
            while (User32Methods.GetMessage(out Message msg, IntPtr.Zero, 0, 0) != 0)
            {
                if (msg.Value == (uint)WM.CLOSE)
                {
                    DetachKeyboardHook();
                }

                if (ChromelyConfiguration.Instance.HostPlacement.KioskMode && msg.Value == (uint)WM.HOTKEY && msg.WParam == (IntPtr)1)
                {
                    User32Methods.PostMessage(NativeWindow.NativeInstance.Handle, (uint)WM.CLOSE, IntPtr.Zero, IntPtr.Zero);
                }
                if (ChromelyConfiguration.Instance.HostPlacement.Frameless || ChromelyConfiguration.Instance.HostPlacement.KioskMode)
                {
                    CefRuntime.DoMessageLoopWork();
                }

                User32Methods.TranslateMessage(ref msg);
                User32Methods.DispatchMessage(ref msg);
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// The run core.
        /// </summary>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        public override int RunCore()
        {
            var quitMsg = (uint)WM.QUIT;

            bool isMultiThreadedLoopSet = this.mHostConfig.GetBooleanValue(CefSettingKeys.MultiThreadedMessageLoop, true);
            bool isExternalPumpSet      = this.mHostConfig.GetBooleanValue(CefSettingKeys.ExternalMessagePump);

            if (!isMultiThreadedLoopSet && !isExternalPumpSet)
            {
                CefRuntime.RunMessageLoop();
            }
            else
            {
                while (true)
                {
                    Message msg;
                    if (User32Helpers.PeekMessage(out msg, IntPtr.Zero, 0, 0, PeekMessageFlags.PM_REMOVE))
                    {
                        if (msg.Value == quitMsg)
                        {
                            break;
                        }

                        User32Methods.TranslateMessage(ref msg);
                        User32Methods.DispatchMessage(ref msg);
                    }

                    // Do your idle processing
                    if (isExternalPumpSet)
                    {
                        CefRuntime.DoMessageLoopWork();
                    }
                }
            }

            return(0);
        }
Exemplo n.º 22
0
        private static int Main(string[] args1)
        {
            //自定义初始化系统配置
            InitAllinOne();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            MainForm.taskRunner   = GlobalUI.taskRunner;
            GlobalVar.AccountList = HaoziHelper.importAccounts();
            //导入账号信息

            //每个账号建立一个cache
            string zfbEmail = "";

            zfbEmail = GlobalVar.AccountList.Count == 0 ? "downloadAccount" : GlobalVar.AccountList[0].zfbEmail;
            string MyCachePath = Application.StartupPath + "\\cache\\{0}\\".With(zfbEmail);

            if (!Directory.Exists(MyCachePath))
            {
                Directory.CreateDirectory(MyCachePath);
            }

            //每个账号建立一个个性化信息配置文件
            string zfbEmailConfig = MyCachePath + zfbEmail + ".txt";
            string httpHeadAgent  = FileHelper.RandomReadOneLine("Resources//httpHead.txt").ReplaceNum();

            if (!File.Exists(zfbEmailConfig))
            {
                //  File.Create(zfbEmailConfig); //Directory.CreateDirectory(MyCachePath);
                File.WriteAllText(zfbEmailConfig, httpHeadAgent);
            }
            else
            {
                httpHeadAgent = File.ReadAllLines(zfbEmailConfig)[0];
            }
            GlobalCefGlue.UserAgent = httpHeadAgent;
            LogManager.WriteLog(httpHeadAgent + " " + MyCachePath);

            //
            string[] args = { "" };
            int      main;

            if (cefruntimeLoad(out main))
            {
                return(main);
            }
            var mainArgs = new CefMainArgs(args);
            var app      = new DemoApp();

            var exitCode = CefRuntime.ExecuteProcess(mainArgs, app);

            if (exitCode != -1)
            {
                return(exitCode);
            }

            var settings = new CefSettings {
                // BrowserSubprocessPath = @"D:\fddima\Projects\Xilium\Xilium.CefGlue\CefGlue.Demo\bin\Release\Xilium.CefGlue.Demo.exe",
                SingleProcess = false,
                LogSeverity   = CefLogSeverity.Disable,
                LogFile       = "CefGlue.log",
                //设置缓存地址
                CachePath           = MyCachePath,// Application.StartupPath + "\\cache\\{0}\\".With(zfbEmail),
                RemoteDebuggingPort = 20480,
                //  UserAgent = httpHeadAgent//FileHelper.RandomReadOneLine("Resources//httpHead.txt").ReplaceNum()
            };

            if (ConfigHelper.GetBoolValue("UseUserAgent"))
            {
                settings.UserAgent = httpHeadAgent;
            }
            settings.UserAgent = httpHeadAgent;

            //   settings.MultiThreadedMessageLoop = CefRuntime.Platform == CefRuntimePlatform.Windows;
            settings.MultiThreadedMessageLoop = bool.Parse(ConfigHelper.GetValue("MultiThreadedMessageLoop"));
            ;

            CefRuntime.Initialize(mainArgs, settings, app);
            //注册  register custom scheme handler
            //
            CefRuntime.RegisterSchemeHandlerFactory("http", GlobalVar.Js2CsharpRequestDomain, new Js2CsharpSchemeHandlerFactory());
            CefRuntime.AddCrossOriginWhitelistEntry(
                "http://trade.taobao.com", "http", "https://tbapi.alipay.com", true);
            CefRuntime.AddCrossOriginWhitelistEntry(
                "http://trade.taobao.com", "https", "https://tbapi.alipay.com", true);

            if (!settings.MultiThreadedMessageLoop)
            {
                Application.Idle += (sender, e) => { CefRuntime.DoMessageLoopWork(); };
            }

            MainForm mainform;

            //通过配置觉得是否自运行
            if (GlobalVar.autoRun)
            {
                mainform = new MainForm(true);
            }
            else
            {
                mainform = new MainForm();
            }

            Application.Run(mainform);

            CefRuntime.Shutdown();


            return(0);
        }
Exemplo n.º 23
0
        private static int Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);


            try
            {
                CefRuntime.Load();
            }
            catch (DllNotFoundException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(1);
            }
            catch (CefRuntimeException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(2);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(3);
            }

            //hmm not working
            //Should maybe move to callback in render process vs can modify from browser process this way
            //Array.Resize(ref args, args.Length + 1);
            //args[args.Length - 1] = @"--log-file ""..\logs\LVCef.RenderApp.log""";
            //for (int i = 0; i < args.Length; i++)
            //    Debug.WriteLine("Render args[" + i +"]: " + args[i]);

            var mainArgs = new CefMainArgs(args);
            var exitCode = CefRuntime.ExecuteProcess(mainArgs, null, IntPtr.Zero);

            if (exitCode != -1)
            {
                return(exitCode);
            }

            var settings = new CefSettings
            {
                //Relative path from \cef, make sure to set Working Directory to \cef, see README.md
                BrowserSubprocessPath    = @"..\dotnet\LVCef.RenderApp\bin\Debug\LVCef.RenderApp.exe",
                SingleProcess            = false,
                MultiThreadedMessageLoop = true,
                LogSeverity = CefLogSeverity.Default,
                LogFile     = @"..\logs\TestControlAppSimple.log",
            };

            CefRuntime.Initialize(mainArgs, settings, null, IntPtr.Zero);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (!settings.MultiThreadedMessageLoop)
            {
                Application.Idle += (sender, e) => { CefRuntime.DoMessageLoopWork(); };
            }

            Application.Run(new TestControlAppSimpleForm());

            CefRuntime.Shutdown();
            return(0);
        }
Exemplo n.º 24
0
 public void Update()
 {
     CefRuntime.DoMessageLoopWork();
 }
Exemplo n.º 25
0
        private static int Main(string[] args)
        {
            try
            {
                try
                {
                    CefRuntime.Load();
                }
                catch (DllNotFoundException ex)
                {
                    MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(1);
                }
                catch (CefRuntimeException ex)
                {
                    MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(2);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(3);
                }

                var mainArgs = new CefMainArgs(args);
                var app      = new CefApplication();

                int exitCode = CefRuntime.ExecuteProcess(mainArgs, app);
                if (exitCode != -1)
                {
                    return(exitCode);
                }

                var settings = new CefSettings
                {
                    SingleProcess            = false,
                    MultiThreadedMessageLoop = true,
                    LogSeverity = CefLogSeverity.Disable,
                    LogFile     = "CefGlue.log",
                };

                CefRuntime.Initialize(mainArgs, settings, app);

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                if (!settings.MultiThreadedMessageLoop)
                {
                    Application.Idle += (sender, e) => { CefRuntime.DoMessageLoopWork(); };
                }
                InitDevExpress();
                UpdateHelper.ForcedUpdate();
                Application.ThreadException += Application_ThreadException;
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                BaseSystemInfo.StartupPath         = Application.StartupPath;
                BaseSystemInfo.CustomerCompanyName = "申通快递";
                BaseSystemInfo.SoftFullName        = "申通打印专家";
                BaseSystemInfo.SoftName            = BaseSystemInfo.SoftFullName;
                BaseSystemInfo.MailUserName        = "******";
                BaseSystemInfo.MailServer          = "smtp.qq.com";
                BaseSystemInfo.MailPassword        = "******";
                BaseSystemInfo.SystemCode          = "ZTOPrint";
                //  ZipFile();
                Synchronous.Synchronous.BeforeLogOn();
                // new FrmWaiting().ShowDialog();
                CheckPrinterWindowsServer();
                CheckInitData();
                var t = new Task(() => ComputerHelper.GetServerDataTime());
                t.Start();

                // Application.Run(new FrmLogOnByMobile());
                Application.Run(new FrmMain());
                return(0);
            }
            catch (Exception ex)
            {
                LogUtil.WriteException(ex);
                MessageBox.Show(ex.Message);
            }
            CefRuntime.Shutdown();
            return(0);
        }
Exemplo n.º 26
0
        public static int Init(string[] args)
        {
            ///开启多线程任务
            bool multiThreadedMessageLoop = true;

            //InitCEF.Init(args, multiThreadedMessageLoop);

            try
            {
                //加载CEF 运行时  lib cef
                CefRuntime.Load();
            }
            catch (DllNotFoundException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(1);
            }
            catch (CefRuntimeException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(2);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(3);
            }

            var mainArgs = new CefMainArgs(args);
            var app      = new SamrtWebBrowerApp();


            //执行CEF启动进程
            var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero);

            if (exitCode != -1)
            {
                return(exitCode);
            }

            // CEF的配置参数,有很多参数,我们这里挑几个解释一下:
            //SingleProcess = false:此处目的是使用多进程。
            //注意: 强烈不建议使用单进程,单进程不稳定,而且Chromium内核不支持
            //MultiThreadedMessageLoop = true:此处的目的是让浏览器的消息循环在一个单独的线程中执行
            //注意: 强烈建议设置成true,要不然你得在你的程序中自己处理消息循环;自己调用CefDoMessageLoopWork()
            //Locale = "zh-CN":webkit用到的语言资源,如果不设置,默认将为en - US
            //注意: 可执行文件所在的目录一定要有locals目录,而且这个目录下要有相应的资源文件
            //var settings = new CefSettings
            //{
            //    // BrowserSubprocessPath = @"D:\fddima\Projects\Xilium\Xilium.CefGlue\CefGlue.Demo\bin\Release\Xilium.CefGlue.Demo.exe",
            //    SingleProcess = false,
            //    MultiThreadedMessageLoop = true,
            //    Locale = "en-US"
            //    /// LogSeverity = CefLogSeverity.Disable//,
            //    // LogFile = "CefGlue.log",
            //};

            var settings = new CefSettings
            {
                // BrowserSubprocessPath = @"D:\fddima\Projects\Xilium\Xilium.CefGlue\CefGlue.Demo\bin\Release\Xilium.CefGlue.Demo.exe",
                SingleProcess              = false,//tab 页面多进程模型
                MultiThreadedMessageLoop   = multiThreadedMessageLoop,
                WindowlessRenderingEnabled = true,
                //Locale = "en-US",
                LogSeverity = CefLogSeverity.Disable,
                //LogFile = "CefGlue.log",
                NoSandbox    = true,
                UserAgent    = GlobalContext.ChromeUserAgent,
                UserDataPath = System.IO.Path.Combine(Environment.CurrentDirectory, "UserData"),
                CachePath    = System.IO.Path.Combine(Environment.CurrentDirectory, "LocalCache")
            };


            //初始化  CEF进程参数设置
            CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero);



            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (!multiThreadedMessageLoop)
            {
                Application.Idle += (sender, e) => { CefRuntime.DoMessageLoopWork(); };
            }


            //第二步 开启tcp端口---不再开启端口,采取定时向远程redis 推送cookie
            //RemoteServer.Start();

            try
            {
                Application.Run(new MainForm());
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                MessageBox.Show(ex.ToString());
            }


            //注销CEF app
            app.Dispose();

            ///终止CEF 线程
            CefRuntime.Shutdown();


            return(0);
        }
Exemplo n.º 27
0
        public void StartChromiumThread(string[] args)
        {
            Exception      ex     = null;
            AutoResetEvent ev     = new AutoResetEvent(false);
            Thread         thread = new Thread(() =>
            {
                try
                {
                    CefRuntime.Load();

                    var argv = args;
                    if (CefRuntime.Platform != CefRuntimePlatform.Windows)
                    {
                        argv = new string[args.Length + 1];
                        Array.Copy(args, 0, argv, 1, args.Length);
                        argv[0] = "-";
                    }
                    var mainArgs = new CefMainArgs(argv);

                    ChromiumApp app = new ChromiumApp();

                    var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero);
                    if (exitCode != -1)
                    {
                        return;
                    }

                    // guard if something wrong
                    foreach (var arg in args)
                    {
                        if (arg.StartsWith("--type="))
                        {
                            return;
                        }
                    }

                    DirectoryInfo baseDir = new FileInfo(Assembly.GetEntryAssembly().Location).Directory;


                    Console.WriteLine("Initializing");
                    CefRuntime.Initialize(mainArgs, new CefSettings()
                    {
                        MultiThreadedMessageLoop = CefRuntime.Platform == CefRuntimePlatform.Windows,
                        SingleProcess            = true,
                        LogSeverity         = CefLogSeverity.Error,
                        LogFile             = "cef.log",
                        ResourcesDirPath    = baseDir.FullName,
                        NoSandbox           = true,
                        RemoteDebuggingPort = 52345
                    }, app, IntPtr.Zero);

                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);

                    if (CefRuntime.Platform != CefRuntimePlatform.Windows)
                    {
                        Application.Idle += (s, e) =>
                        {
                            if (_invokeQueue.Count > 0)
                            {
                                Action eq = null;
                                if (_invokeQueue.TryDequeue(out eq))
                                {
                                    try
                                    {
                                        eq();
                                    }
                                    catch (Exception x)
                                    {
                                        Console.WriteLine("Invoke exception: " + x.Message);
                                    }
                                }
                            }
                            try
                            {
                                CefRuntime.DoMessageLoopWork();
                            }
                            catch (Exception x)
                            {
                                Console.WriteLine("Exception in MSG loop:" + x.Message);
                            }
                        }
                    }
                    ;

                    //ev.Set();

                    if (CefRuntime.Platform == CefRuntimePlatform.Windows)
                    {
                        MainForm                 = new Form();
                        MainForm.Width           = 0;
                        MainForm.Height          = 0;
                        MainForm.FormBorderStyle = FormBorderStyle.None;
                        MainForm.Opacity         = 0;
                        MainForm.Load           += (s, e) =>
                        {
                            ev.Set();
                            MainForm.Hide();
                        };
                        Application.Run(MainForm);
                    }
                    else
                    {
                        ev.Set();
                        Application.Run();
                    }
                    CefRuntime.Shutdown();
                }
                catch (Exception x)
                {
                    ex = x;
                }
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            ev.WaitOne();
            if (ex != null)
            {
                throw ex;
            }
        }
Exemplo n.º 28
0
        private static int Main(string[] args)
        {
            PublicClass.currDirectiory = Environment.CurrentDirectory.ToString(); // PublicClass.currDirectiory = System.Windows.Forms.Application.StartupPath;
            new ProcessHook().InitHook();
            try
            {
                CefRuntime.Load();
            }
            catch (DllNotFoundException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(1);
            }
            catch (CefRuntimeException ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(2);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(3);
            }

            var mainArgs = new CefMainArgs(args);
            var app      = new DemoApp();

            var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero);

            if (exitCode != -1)
            {
                return(exitCode);
            }

            var codeBase    = Assembly.GetExecutingAssembly().CodeBase;
            var localFolder = Path.GetDirectoryName(new Uri(codeBase).LocalPath);
            var settings    = new CefSettings
            {
                //BrowserSubprocessPath = browserProcessPath,
                //SingleProcess = false,
                //WindowlessRenderingEnabled = true,
                MultiThreadedMessageLoop = true,
                LogSeverity = CefLogSeverity.Disable,
                //LogFile = "CefGlue.log",
                Locale                  = "zh-CN",
                JavaScriptFlags         = "js-flags",
                CommandLineArgsDisabled = false,
                IgnoreCertificateErrors = true,
                CachePath               = GetAppDir("Cache"),
                UserAgent               = CefConstHelper.UserAgent,
                //NoSandbox = true,

                //AcceptLanguageList = "zh-CN",
                //PersistSessionCookies = true,
            };


            CefRuntime.RegisterSchemeHandlerFactory(CefConstHelper.Branding, CefConstHelper.Branding, new SchemeHandlerFactory());
            CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero);
            Application.EnableVisualStyles();
            CefRuntime.EnableHighDpiSupport();
            Application.SetCompatibleTextRenderingDefault(false);

            if (!settings.MultiThreadedMessageLoop)
            {
                Application.Idle += (sender, e) => { CefRuntime.DoMessageLoopWork(); };
            }

            if (args.Length > 0)
            {
                Application.Run(new MainForm(args[0].ToString()));

                //MessageBox.Show(PublicClass.StartUrl);
            }
            else
            {
                Application.Run(new MainForm(""));
            }


            CefRuntime.Shutdown();

            try
            {
                //if (Directory.Exists(GetAppDir("Cache")))
                //    Directory.Delete(GetAppDir("Cache"), true);
            }
            catch
            { }
            return(0);
        }