// Launches the startup task protected override async void OnResume() { base.OnResume(); if (CheckInternet.HasConnexion() || CheckIsDownload()) { MainThread.BeginInvokeOnMainThread(() => { SetContentView(Resource.Layout.splash); mProgress = FindViewById <ProgressBar>(Resource.Id.SplashProgressBar); mProgress.Visibility = ViewStates.Visible; }); SimulateStartup(); } else { if (await CheckInternet.ShowMessageIfNotConnected(this) == Controller.ShowDialog.MessageResult.YES) { OnResume(); } else { StopApplication(); } } }
/// <summary> /// 通过获取服务器时间检查网络是否通畅,获取成功,返回true,否则返回false。 /// </summary> /// <returns></returns> private bool CheckNetWork() { ShowMessage = "正在连接远程服务……"; if (!CheckInternet.CheckLocal()) { ShowMessage = "连接网络失败,请检查网卡状态或网线是否接好!"; return(false); } if (ConfigurationManager.ConnectionStrings["EndpointAddress"] != null) { string endpointAddress = AESAlgorithm.AESDecrypt(ConfigurationManager.ConnectionStrings["EndpointAddress"].ConnectionString); //net.tcp://192.168.1.100:8201/ string straddress = endpointAddress.Replace("net.tcp://", ""); straddress = straddress.Substring(0, straddress.Length - 1); if (!CheckInternet.CheckPort(straddress.Split(':')[0], straddress.Split(':')[1])) { ShowMessage = "服务器连接失败,请检查服务器设置或网络配置!"; return(false); } string pingip = ConfigurationManager.AppSettings["PingIP"]; IPAddress ip; if (ConfigurationManager.AppSettings["PingServer"] != null && ConfigurationManager.AppSettings["PingServer"] == "1" && IPAddress.TryParse(pingip, out ip)) { CheckInternet.PingIp(pingip); } } else { ShowMessage = "获取服务器地址失败,请检查终端配置!"; return(false); } try { DateTime dt = ServiceDateTime.Now; } catch (Exception ex) { WriteLog.Write("连接数据传输服务失败:" + ex.Message); ShowMessage = "连接远程服务遇到错误,请检查服务器服务是否启动。"; return(false); } return(true); }
private async void DownloadIfNecessary() { if (CheckInternet.HasConnexion() || CheckIsDownload()) { ProgressBar.IsVisible = true; await SimulateStartup(); } else { if (await DisplayAlert("Erreur", "Pas de connection internet, activer le Wifi ou les données mobiles et rééssayer!", "Réésayer", "Quitter")) { DownloadIfNecessary(); } else { StopApplication(); } } }
static void Main() { //Starting visual and text styles Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(true); SetApplicationExceptions(); //Set for logging events when the application shuts down ILogger.AddToLog(ResourceInformation.ApplicationName, "Running main form now!"); //Initialize CefSharp VoidCef.InitializeCefSharp(); //Initialize settings manager Settings.SettingsManager.InitializeValues(); OpenForm(); //Opens a new borwser window //Checks if the application exist var exists = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)).Length > 1; if (exists) { ILogger.AddToLog(ResourceInformation.ApplicationName, "Detected another instance of the browser open! Sending client package and closing browser..."); //New TCP client to send data to local server TcpClient client = new TcpClient(); client.Connect("localhost", 6189); client.Client.Send(Encoding.UTF8.GetBytes("newpage")); //Closing application and client client.Close(); Application.Exit(); } InitializeInvokeObject(); //Initialize the invoke object for the start of the application. //Check if there is an active internet connection if (!CheckInternet.CheckForInternetConnection()) { ILogger.AddToLog("ERROR", "Connection to the internet was not found!"); MessageBox.Show("Connection to the internet was not found! this browser is currently closing.", ResourceInformation.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } InitializeLocalServer(); //Loads the local server used to open a new form when a new application is open. InitializeStripe(); //Initialize the stripe API //Initializing History IHistory.LoadFromFile(); StartFormTimer(); //Starts a timer to check when no forms are open Settings.Settings.downloadItem.InitializeDownloadItems(); //Initialize download items from local storage. Thread thread = new Thread(new ThreadStart(() => { //Initializes server connections ServerConnections.InitializeServerConnections(); })); thread.Start(); //Running the application loop. Application.Run(); }