private JavaScriptValue SetWnBrowerTileAndSubtitle(Formium owner, JavaScriptValue[] arguments)
 {
     try
     {
         if (arguments.Length == 0)
         {
             return(JavaScriptValue.CreateString("无参数"));
         }
         if (arguments.Length > 1)
         {
             var strTitle    = arguments[0].GetString();
             var strSubtitle = arguments[1].GetString();
             if (!string.IsNullOrWhiteSpace(strTitle) && !string.IsNullOrWhiteSpace(strSubtitle))
             {
                 owner.Title    = strTitle;
                 owner.Subtitle = strSubtitle;
                 Wnconfig.SetAppsettingValue("Title", strTitle);
                 Wnconfig.SetAppsettingValue("Subtitle", strSubtitle);
             }
         }
         else
         {
             JavaScriptValue.CreateString("调用失败!SetWnBrowerTileAndSubtitle至少需要两个参数!(Title,Subtitle)");
         }
     }
     catch (Exception ex)
     {
         return(JavaScriptValue.CreateString(ex.Message));
     }
     return(JavaScriptValue.CreateString("调用SetWnBrowerTileAndSubtitle成功"));
 }
Example #2
0
        private void MainForm_DocumentTitleChanged(object sender, NetDimension.NanUI.Browser.DocumentTitleChangedEventArgs e)
        {
            try
            {
                if (Wnconfig.GetUrl().Contains(e.Title))
                {
                    return;
                }
                this.Title    = e.Title;
                this.Subtitle = "";
                Wnconfig.SetAppsettingValue("Title", this.Title);
                Wnconfig.SetAppsettingValue("Subtitle", this.Subtitle);
                if (this.Title != "社区卫生信息系统")
                {
                    ShortCutHelper.SetWinningBrowerShortcut(this.Title, Application.ExecutablePath);
                }
            }
            catch (Exception)
            {
            }



            //throw new NotImplementedException();
        }
Example #3
0
        /// <summary>
        /// 打开该程序主窗口
        /// </summary>
        public static void RaiseOtherProcess()
        {
            System.Diagnostics.Process proc = System.Diagnostics.Process.GetCurrentProcess();
            Process[] Proes = System.Diagnostics.Process.GetProcessesByName(proc.ProcessName);
            foreach (System.Diagnostics.Process otherProc in Proes)
            {
                if (proc.Id != otherProc.Id)
                {
                    IntPtr hWnd = otherProc.MainWindowHandle;
                    if (hWnd.ToInt32() == 0)
                    {
                        hWnd = WindowsApi.FindWindow(null, $"{Wnconfig.GetTitleName()}");

                        int id = -1;
                        WindowsApi.GetWindowThreadProcessId(hWnd, out id);
                        if (id == otherProc.Id)
                        {
                            break;
                        }
                    }
                    ActivateWindow(hWnd);
                    //此处获取的hWnd即为之前运行程序的主窗口句柄,再使用其他函数打开窗体
                    break;
                }
            }
        }
Example #4
0
        public static string GetShortName()
        {
            if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["AppNameURL"]))
            {
                return(GetAppSettingShortName());
            }

            MyWebClient wc = new MyWebClient();

            try
            {
                string strShortName = "";
                string url          = ConfigurationManager.AppSettings["AppNameURL"];
                strShortName = wc.DownloadString(url);
                Wnconfig.SetAppsettingValue("ShortcutNameOnDesktop", strShortName);
                return(strShortName);
            }
            catch (Exception)
            {
                return(null);
            }
            finally
            {
                wc = null;
            }
        }
Example #5
0
        private void MainForm_LoadError(object sender, NetDimension.NanUI.Browser.LoadErrorEventArgs e)
        {
            try
            {
                if (e.ErrorText == "ERR_ABORTED")
                {
                    return;
                }
                // Display a load error message.
                //var errorBody = string.Format("<html><body bgcolor=\"white\"><h2>Failed to load URL {0} with error {1} ({2}).</h2></body></html>",
                //                              e.FailedUrl, e.ErrorText, e.ErrorCode);

                //e.Frame.LoadStringForUrl(errorBody, e.FailedUrl);


                if (e.FailedUrl == Wnconfig.GetUrl())
                {
                    string strmsg = string.Format("网址{0}\n无法打开\n原因:【{1}】,是否刷新重试?", e.FailedUrl.Replace("?fromCustormBrowser=1", ""), e.ErrorText);
                    if ((MessageBox.Show(strmsg, "信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes))
                    {
                        Thread thread = new Thread(() =>
                        {
                            try
                            {
                                delRestart();
                            }
                            catch (Exception ex)
                            {
                            }
                        });
                        //thread.SetApartmentState(ApartmentState.STA);

                        thread.Start();

                        this.Close(true);
                        return;
                    }
                    else
                    {
                        this.Close(true);
                    }
                }
                else
                {
                    string strmsg = string.Format("【{0}】\n网址无法打开\n原因:【{1}】", e.FailedUrl.Replace("?fromCustormBrowser=1", ""), e.ErrorText);
                    MessageBox.Show(strmsg, e.ErrorText, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
            }
            catch (Exception)
            {
            }


            //throw new NotImplementedException();
        }
Example #6
0
 // Raise if browser is ready.
 protected override void OnReady()
 {
     BeforeClose             += MainForm_BeforeClose;
     RenderProcessTerminated += MainForm_RenderProcessTerminated;
     BeforePopup             += MainWindow_BeforePopup;
     KeyEvent              += MainForm_KeyEvent;
     LoadError             -= MainForm_LoadError;
     LoadError             += MainForm_LoadError;
     FullScreenModeChanged += MainForm_FullScreenModeChanged;
     DocumentTitleChanged  += MainForm_DocumentTitleChanged;
     Wnconfig.SetDefaultUrl();
 }
        private JavaScriptValue UpdateWnBrowerUrlIp(Formium owner, JavaScriptValue[] arguments)
        {
            if (!Wnconfig.GetGrayFlag())
            {
                return(JavaScriptValue.CreateString("启动灰度地址失败! 已经在配置文件WinningBrowserApp.config中已经禁用灰度更新"));
            }

            if (arguments.Length == 0)
            {
                return(JavaScriptValue.CreateString("启动灰度地址失败!未传Ip参数"));
            }
            if (arguments.Length > 0)
            {
                var strNewIp  = arguments[0].GetString();
                var strUserid = "无用户名";
                var strPw     = "无密码";
                if (arguments.Length > 1)
                {
                    strUserid = arguments[1].GetString();
                    strPw     = arguments[2].GetString();
                }

                if (!string.IsNullOrEmpty(strNewIp) && !Wnconfig.GetUrl().Contains(strNewIp))
                {
                    string strGrayIp = strNewIp;
                    MessageBox.Show(string.Format("启用灰度地址:{0}", strGrayIp));
                    string msgresault = Wnconfig.SetUrlIp(strGrayIp, strUserid, strPw, true);
                    if (msgresault.Contains("失败"))
                    {
                        return(JavaScriptValue.CreateString(msgresault));
                    }

                    Thread thread = new Thread(() =>
                    {
                        try
                        {
                            MainForm.delRestart();
                        }
                        catch (Exception ex)
                        {
                        }
                    });
                    //thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                    return(JavaScriptValue.CreateString("启动灰度地址成功(UpdateWnBrowerUrlIp)"));
                }
            }
            return(JavaScriptValue.CreateString("启动灰度地址失败!"));
        }
Example #8
0
        public static void SetWinningBrowerShortcut(string strShortcutName, string strExecutablePath)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(strShortcutName) || !System.IO.File.Exists(strExecutablePath))
                {
                    return;
                }
                string desktop = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory);//获取桌面文件夹路径
                //string shortcutdir=Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu),"卫宁基层卫生信息系统V5.6");//获取开始菜单文件夹路径
                string shortcutPath    = Path.Combine(desktop, string.Format("{0}.lnk", "卫宁基层卫生信息系统V5.6"));
                string newShortcutpath = Path.Combine(desktop, string.Format("{0}.lnk", strShortcutName));
                //string midShortCutpath = Path.Combine(desktop, string.Format("{0}.lnk", "社区卫生信息系统")); //社区卫生信息系统
                if (System.IO.File.Exists(shortcutPath))
                {
                    if (System.IO.File.Exists(newShortcutpath))
                    {
                        System.IO.File.Delete(shortcutPath);

                        return;
                    }
                    else
                    {
                        System.IO.File.Move(shortcutPath, newShortcutpath);
                        Wnconfig.SetAppsettingValue("ShortcutNameOnDesktop", strShortcutName);
                        return;
                    }
                }
                else if (!string.IsNullOrWhiteSpace(Wnconfig.GetAppSettingShortName()) && System.IO.File.Exists(Path.Combine(desktop, string.Format("{0}.lnk", Wnconfig.GetAppSettingShortName()))))
                {
                    // System.IO.File.Delete(Path.Combine(desktop, string.Format("{0}.lnk", Wnconfig.GetAppSettingShortName())));
                    System.IO.File.Move(Path.Combine(desktop, string.Format("{0}.lnk", Wnconfig.GetAppSettingShortName())), Path.Combine(desktop, string.Format("{0}.lnk", strShortcutName)));
                    Wnconfig.SetAppsettingValue("ShortcutNameOnDesktop", strShortcutName);
                    return;
                }
                CreateShortcutOnDesktop(strShortcutName, strExecutablePath);
                Wnconfig.SetAppsettingValue("ShortcutNameOnDesktop", strShortcutName);
            }
            catch (Exception ex)
            {
            }
        }
        private JavaScriptValue GrayEnable(Formium owner, JavaScriptValue[] arguments)
        {
            try
            {
                if (arguments.Length == 0)
                {
                    return(JavaScriptValue.CreateString("无参数"));
                }
                if (arguments.Length > 0 && !string.IsNullOrWhiteSpace(arguments[0].GetString()))
                {
                    var bGrayEnable = Convert.ToBoolean(arguments[0].GetString());

                    Wnconfig.SetAppsettingValue("GrayFlag", bGrayEnable.ToString());
                }
            }
            catch (Exception ex)
            {
                return(JavaScriptValue.CreateString(ex.Message));
            }
            return(JavaScriptValue.CreateString("调用GrayEnable成功"));
        }
Example #10
0
        static void Main(string[] args)
        {
#if NETCOREAPP3_1 || NET5_0
            Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
#endif
            //bool createNew;
            //using (System.Threading.Mutex m = new System.Threading.Mutex(true, Application.ProductName, out createNew))
            //{
            //    if (!createNew)
            //    {
            //        MessageBox.Show("只能运行一个实例!");
            //        return;
            //    }
            //}
            //MessageBox.Show("只能运行一个实例!");

            Application.ThreadException -= new ThreadExceptionEventHandler(Application_ThreadException);
            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            AppDomain.CurrentDomain.UnhandledException -= new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            //MainForm mfrm = null;
            WinFormium.CreateRuntimeBuilder(env =>
            {
                // You should do some initializing staffs of Cef Environment in this function.

                env.CustomCefCommandLineArguments(cmdLine =>
                {
                    // // Configure command line arguments of Cef here.

                    // //cmdLine.AppendSwitch("disable-gpu");
                    // //cmdLine.AppendSwitch("disable-gpu-compositing");
                    //cmdLine.AppendSwitch("disable-web-security");
                    //cmdLine.AppendSwitch("unsafely-treat-insecure-origin-as-secure", Wnconfig.GetUrl());
                    //cmdLine.AppendSwitch("enable-media-stream", "1");
                    // //cmdLine.AppendSwitch("disable-gpu-watchdog");
                    // //cmdLine.AppendSwitch("disable-gpu-shader-disk-cache");
                    // //cmdLine.AppendSwitch("no-crash-upload");
                    // //cmdLine.AppendSwitch("disable-breakpad");
                    // //--disk-cache-size=xxx
                    // //cmdLine.AppendSwitch("disk-cache-size", "1");
                    // //if (!Environment.Is64BitProcess)
                    // //{
                    // //    //MessageBox.Show("设置内存");
                    // //    cmdLine.AppendArgument("max-old-space-size=1000");
                    // // }

                    cmdLine.AppendSwitch("ignore-certificate-errors");
                    cmdLine.AppendSwitch("disable-web-security");
                    cmdLine.AppendSwitch("unsafely-treat-insecure-origin-as-secure", Wnconfig.GetUrl());
                    //args.AppendSwitch("enable-media-stream");
                    cmdLine.AppendSwitch("enable-media-stream", "1");
                    cmdLine.AppendSwitch("enable-print-preview");
                    cmdLine.AppendSwitch("autoplay-policy", "no-user-gesture-required");

                    cmdLine.AppendSwitch("--disable-web-security", "1");          //关闭同源策略,允许跨域
                    cmdLine.AppendSwitch("--disable-site-isolation-trials", "1"); //关闭站点隔离策略,允许跨域
                    cmdLine.AppendSwitch("disable-web-security", "1");            //关闭同源策略,允许跨域
                    cmdLine.AppendSwitch("disable-site-isolation-trials", "1");   //关闭站点隔离策略,允许跨域
                });

                env.CustomCefSettings(settings =>
                {
                    //MessageBox.Show(settings.CachePath);
                    // Configure default Cef settings here.
                    //settings.WindowlessRenderingEnabled = true;
                    //settings.
                    //settings.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36";
                });

                env.CustomDefaultBrowserSettings(cefSettings =>
                {
                    cefSettings.ApplicationCache = Xilium.CefGlue.CefState.Disabled;
                    //cefSettings.ApplicationCache= Xilium.CefGlue.CefState.Disabled;

                    //  cefSettings.WebSecurity = Xilium.CefGlue.CefState.Disabled;

                    // Configure default browser settings here.
                });
            },
                                            app =>
            {
#if DEBUG
                // Use this setting if your application running in DEBUG mode, it will allow user to open or clode DevTools by right-clicking mouse button and selecting menu items on context menu.
                //app.UseDebuggingMode();
#endif


                app.UseLocalFileResource("http", "demo.app.local", "asserts");
                app.RegisterJavaScriptExtension(() => new WinningBrowerWindowExtension());
                // Clear all cached files such as cookies, histories, localstorages, etc.
                if (args != null && args.Length > 0 && args[0] == "DeleteCache")
                {
                    //RunServiceProxy.InvokProxy();

                    app.ClearCacheFile();
                }
                Thread.Sleep(600);
                //var thisProcess = Process.GetCurrentProcess();
                //if (Process.GetProcessesByName(thisProcess.ProcessName).Length == 1)
                //{
                //    if (Process.GetProcessesByName(thisProcess.ProcessName)[0].Id != thisProcess.Id)
                //    {
                //        Process.GetProcessesByName(thisProcess.ProcessName)[0].Kill();
                //    }
                //}

                app.UseSingleInstance(() =>
                {
                    //MessageBox.Show("只能运行一个程序");

                    RunServiceProxy.SetWebAppFrmFront();
                    return;
                });

                // Set a main window class inherit Formium here to start appliation message loop.
                app.UseMainWindow(context =>
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);


                    ShortCutHelper.SetWinningBrowerShortcut(Wnconfig.GetShortName(), Application.ExecutablePath);


                    // context.MainForm = new Form();
                    //Xilium.CefGlue.CefRuntime.AddCrossOriginWhitelistEntry("*", "http", "*", true);
                    //mfrm= new MainForm();
                    TaskCompletionSource <object> source = new TaskCompletionSource <object>();
                    Thread thread = new Thread(() =>
                    {
                        try
                        {
                            RunServiceProxy.InvokProxy();
                            source.SetResult("启动成功");
                        }
                        catch (Exception ex)
                        {
                            source.SetException(ex);
                        }
                    });
                    //thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                    AutoUpdate();
                    return(new MainForm());
                });
            })
            // Build the NanUI runtime
            .Build()
            // Run the main process
            .Run();
        }