protected override void OnExit(ExitEventArgs e) { // the app is already running if (e.ApplicationExitCode == 300) { SingleApp.CloseAndSwitch(); base.OnExit(e); return; } AtomixApp.Stop(); try { Updater.Stop(); } catch (TimeoutException) { Log.Error("Failed to stop the updater due to timeout"); } // update has been requested if (e.ApplicationExitCode == 101) { try { Updater.RunUpdate(); Log.Information("Update scheduled"); } catch (Exception ex) { Log.Error(ex, "Failed to schedule update"); } } Log.Information("Application shutdown"); SingleApp.Close(); base.OnExit(e); }
private void RoadForm_Load(object sender, EventArgs e) { if (SingleApp.AppExist("2571EFFE-7388-4990-AAC3-B645329DDBCE")) { Application.Exit(); } strParkID = ConfigurationManager.AppSettings.Get("ParkID"); mainSC = SynchronizationContext.Current; scCallback = new SendOrPostCallback(MainScCallback); tcpClient = new WcfCommonLib.TcpClient(); tcpClient.QueryEvent += new WcfCommonLib.TcpClient.QueryEventHandler(tcpClient_QueryEvent); tcpClient.MessageEvent += new WcfCommonLib.TcpClient.MessageEventHandler(tcpClient_MessageEvent); dataCallback = new WaitCallback(GetUploadData); wcfClient = new CenterServiceClient(); webServer = new SimpleWebSerer(); webServer.StartServer(); ConnectServer(); SetTimer(timerReconnect, "ReconnectTimer"); SetTimer(timerUploadData, "UploadTimer"); GetInitializeData(); }
protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); // ensure there are no other instances of the app if (!SingleApp.TryStart("AtomixApp")) { Current.Shutdown(300); return; } // init logger Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(Configuration) .CreateLogger(); Log.Information("Application startup"); // init Atomix client app AtomixApp = new AtomixApp(Configuration) .UseQuotesProvider(new BitfinexQuotesProvider(Currencies.Available, BitfinexQuotesProvider.Usd)) .UseTerminal(new Terminal(Configuration)); // init app updater Updater = new Updater() //.UseLocalBinariesProvider(@"Atomix.Client.Wpf.Installer.msi") //.UseLocalVersionProvider(@"version.json") .UseHttpMetadataProvider("https://atomix.me/versions.json", TargetPlatform.Windows) .UseMsiProductProvider("0779aaaa-2411-4948-b5bc-48f81b8c6143"); // init & show main view var mainView = new MainWindow(); mainView.DataContext = new MainViewModel(AtomixApp, mainView); mainView.Show(); mainView.ShowStartDialog(new StartViewModel(AtomixApp, mainView)); MainWindow = mainView; AtomixApp.Start(); try { Updater.Start(); } catch (TimeoutException) { Log.Error("Failed to start the updater due to timeout"); } }
private void CenterForm_Load(object sender, EventArgs e) { if (SingleApp.AppExist("C024F8AB-3F9A-495D-B6B4-044FF802BD5C")) { Application.Exit(); } mainSC = SynchronizationContext.Current; scCallback = new SendOrPostCallback(MainScCallback); svcHost = new ServiceHost(typeof(CenterService)); svcHost.Open(); CenterService.logCB += DisplayLog; webServer = new SimpleWebSerer(); webServer.QueryEvent += new SimpleWebSerer.QueryEventHandler(webServer_QueryEvent); webServer.StartServer(); tcpServer = new WcfCommonLib.TcpServer(); tcpServer.MessageEvent += new TcpServer.MessageEventHandler(tcpServer_MessageEvent); tcpServer.StartServer(); }
static int Main(string[] args) { int result = -2; if (SingleApp.IsRunning()) { return(-3); } try { bool add = false; bool remove = false; bool check = true; if (!IsElevated()) { Program.Log("XenUpdater.exe must be run by an elevated administrator account"); return((int)HRESULT.E_ACCESSDENIED); } // check params for config options... foreach (string arg in args) { switch (arg.ToLower()) { case "add": add = true; check = false; break; case "remove": remove = true; check = false; break; case "check": check = true; break; default: throw new ArgumentException(arg); } } if (add && !remove && !check) { using (Tasks tasks = new Tasks()) { tasks.AddTask(); } } if (remove && !add && !check) { using (Tasks tasks = new Tasks()) { tasks.RemoveTask(); } } if (check && !add && !remove) { AutoUpdate auto = new AutoUpdate(); auto.CheckNow(); } result = 0; } catch (UnauthorizedAccessException e) { Program.Log("Exception: " + e.ToString()); result = (int)HRESULT.E_ACCESSDENIED; } catch (FormatException e) { Program.Log("Exception: " + e.ToString()); result = (int)HRESULT.E_INVALIDARG; } catch (Exception e) { Program.Log("Exception: " + e.ToString()); result = -1; // TODO: Return the HRESULT of this exception } return(result); }