private void _trayIcon_DoubleClick(object sender, EventArgs e) { ///application is not opened yet, open new form if (Application.OpenForms.OfType <MetroOptionsDlg>().Count() < 1) { var repomanager = new MetroOptionsDlg(this, MetroOptionsDlg.Page.Repositories); repomanager.RepoListingChanged += (o, args) => { _trayIcon.ContextMenu = new ContextMenu(BuildContextMenu()); }; repomanager.Closed += (o, args) => { if (_trayIcon != null) { _trayIcon.ContextMenu = new ContextMenu(BuildContextMenu()); } }; repomanager.ShowDialog(); } else { ///Application is already open, bring the application form on top var form = Application.OpenForms.OfType <MetroOptionsDlg>().First(); form.TopMost = true; form.Show(); form.Focus(); form.BringToFront(); form.TopMost = false; } }
private void _trayIcon_DoubleClick(object sender, EventArgs e) { var repomanager = new MetroOptionsDlg(this, MetroOptionsDlg.Page.Repositories); repomanager.Closed += (o, args) => { if (_trayIcon != null) { _trayIcon.ContextMenu = new ContextMenu(BuildContextMenu()); } }; repomanager.ShowDialog(); }
private void ShowAboutMenuItemHandler(object sender, EventArgs e) { var optionsdlg = new MetroOptionsDlg(this, MetroOptionsDlg.Page.About); optionsdlg.Closed += (o, args) => { if (_trayIcon != null) { _trayIcon.ContextMenu = new ContextMenu(BuildContextMenu()); } }; optionsdlg.Show(); }
private void ShowOptionsMenuItemHandler(object sender, EventArgs e) { if (Application.OpenForms.OfType <MetroOptionsDlg>().Count() > 0) { var form = Application.OpenForms.OfType <MetroOptionsDlg>().First(); form.SetTab(MetroOptionsDlg.Page.GlobalOptions); } else { var optionsDlg = new MetroOptionsDlg(this, MetroOptionsDlg.Page.GlobalOptions); optionsDlg.RepoListingChanged += (o, args) => { _trayIcon.ContextMenu = new ContextMenu(BuildContextMenu()); }; optionsDlg.Closed += (o, args) => { if (_trayIcon != null) { _trayIcon.ContextMenu = new ContextMenu(BuildContextMenu()); } }; var res = optionsDlg.ShowDialog(); if (res != DialogResult.OK) { return; } if (GlobalOptions.Instance.RepositoryUpdateInterval <= 0) { _updateIntervalTimer?.Stop(); return; } if (_updateIntervalTimer == null) { _updateIntervalTimer = new Timer(GlobalOptions.Instance.RepositoryUpdateInterval * 1000) { AutoReset = true }; _updateIntervalTimer.Elapsed += (sender1, args) => { ServiceClient.DownloadAllUpdateInfo(); }; } _updateIntervalTimer.Stop(); _updateIntervalTimer.Interval = GlobalOptions.Instance.RepositoryUpdateInterval * 1000; _updateIntervalTimer.Start(); } }
private void ManageRepositoriesMenuItemHandler(object sender, EventArgs e) { if (Application.OpenForms.OfType <MetroOptionsDlg>().Count() > 0) { var form = Application.OpenForms.OfType <MetroOptionsDlg>().First(); form.SetTab(MetroOptionsDlg.Page.Repositories); } else { var repomanager = new MetroOptionsDlg(this, MetroOptionsDlg.Page.Repositories); repomanager.RepoListingChanged += (o, args) => { _trayIcon.ContextMenu = new ContextMenu(BuildContextMenu()); }; repomanager.Closed += (o, args) => { if (_trayIcon != null) { _trayIcon.ContextMenu = new ContextMenu(BuildContextMenu()); } }; repomanager.ShowDialog(); } }
private void ShowAboutMenuItemHandler(object sender, EventArgs e) { if (Application.OpenForms.OfType <MetroOptionsDlg>().Count() > 0) { var form = Application.OpenForms.OfType <MetroOptionsDlg>().First(); form.SetTab(MetroOptionsDlg.Page.About); } else { var optionsdlg = new MetroOptionsDlg(this, MetroOptionsDlg.Page.About); optionsdlg.RepoListingChanged += (o, args) => { _trayIcon.ContextMenu = new ContextMenu(BuildContextMenu()); }; optionsdlg.Closed += (o, args) => { if (_trayIcon != null) { _trayIcon.ContextMenu = new ContextMenu(BuildContextMenu()); } }; optionsdlg.Show(); } }
public GinApplicationContext() { _trayIcon = new NotifyIcon { Visible = true, Icon = Resources.gin_icon_desaturated }; ServiceClient = new GinServiceClient(new InstanceContext(this)); var saveFilePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\g-node\GinWindowsClient"; if (!Directory.Exists(saveFilePath)) { Directory.CreateDirectory(saveFilePath); } #region Environment Variables //Tell the service to use the current users' AppData folders for logging and config data ServiceClient.SetEnvironmentVariables( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\g-node\gin\", Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\g-node\gin\"); #endregion #region Login if (!UserCredentials.Load()) { var getUserCreds = new MetroGetUserCredentialsDlg(this); var result = getUserCreds.ShowDialog(); //The Dialog will log us in and save the user credentials if (result == DialogResult.Cancel) { Exit(this, EventArgs.Empty); } } else if (!ServiceClient.Login(UserCredentials.Instance.Username, UserCredentials.Instance.Password)) { MessageBox.Show(Resources.GinApplicationContext_Error_while_trying_to_log_in_to_GIN, Resources.GinApplicationContext_Gin_Client_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); var getUserCreds = new MetroGetUserCredentialsDlg(this); var result = getUserCreds.ShowDialog(); //The Dialog will log us in and save the user credentials if (result == DialogResult.Cancel) { Exit(this, EventArgs.Empty); } } UserCredentials.Save(); #endregion #region Read options if (!GlobalOptions.Load()) { var optionsDlg = new MetroOptionsDlg(this, MetroOptionsDlg.Page.GlobalOptions); var result = optionsDlg.ShowDialog(); if (result == DialogResult.Cancel) { Exit(this, EventArgs.Empty); } } if (GlobalOptions.Instance.RepositoryUpdateInterval > 0) { _updateIntervalTimer = new Timer(GlobalOptions.Instance.RepositoryUpdateInterval * 1000 * 60) { AutoReset = true }; _updateIntervalTimer.Elapsed += (sender, args) => { ServiceClient.DownloadAllUpdateInfo(); }; } GlobalOptions.Save(); #endregion #region Set up repositories if (File.Exists(saveFilePath + @"\SavedRepositories.json")) { try { var text = File.OpenText(saveFilePath + @"\SavedRepositories.json").ReadToEnd(); var repos = JsonConvert.DeserializeObject <GinRepositoryData[]>(text); foreach (var repo in repos) { ServiceClient.AddRepository(repo.PhysicalDirectory.FullName, repo.Mountpoint.FullName, repo.Name, repo.Address, GlobalOptions.Instance.RepositoryCheckoutOption == GlobalOptions.CheckoutOption.FullCheckout, false); } } catch { } } else { ManageRepositoriesMenuItemHandler(null, EventArgs.Empty); } #endregion _trayIcon.DoubleClick += _trayIcon_DoubleClick; _trayIcon.ContextMenu = new ContextMenu(BuildContextMenu()); _trayIcon.Icon = Resources.gin_icon; _updateIntervalTimer?.Start(); }
public GinApplicationContext() { _trayIcon = new NotifyIcon { Visible = true, Icon = Resources.gin_icon_desaturated }; var service = new GinClientWindowsService(_trayIcon); _serviceThread = new Thread(service.Start); _serviceThread.Start(); SystemEvents.SessionEnded += SystemEvents_SessionEnded; var myBinding = new WSDualHttpBinding { ClientBaseAddress = new Uri(@"http://*****:*****@"\g-node\WinGIN"; if (!Directory.Exists(saveFilePath)) { Directory.CreateDirectory(saveFilePath); } #region Environment Variables //Tell the service to use the current users' AppData folders for logging and config data ServiceClient.SetEnvironmentVariables( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\g-node\gin\", Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\g-node\gin\"); #endregion #region Login if (!UserCredentials.Load()) { var getUserCreds = new MetroGetUserCredentialsDlg(this); var result = getUserCreds.ShowDialog(); //The Dialog will log us in and save the user credentials if (result == DialogResult.Cancel) { Exit(this, EventArgs.Empty); return; } } else { var servString = ServiceClient.GetServers(); var ServerDic = JsonConvert.DeserializeObject <Dictionary <string, ServerConf> >(servString); foreach (var server in ServerDic) { ///search for login for server var selectedLogin = UserCredentials.Instance.loginList.Find(x => x.Server == server.Key); if (selectedLogin != null) { ///try login for servers if (!ServiceClient.Login(selectedLogin.Username, selectedLogin.Password, selectedLogin.Server)) { if (server.Value.Default) { ///if login fails for default server, try to get new login info MessageBox.Show(Resources.GinApplicationContext_Error_while_trying_to_log_in_to_GIN, Resources.GinApplicationContext_Gin_Client_Error, MessageBoxButtons.OK, MessageBoxIcon.Error); var getUserCreds = new MetroGetUserCredentialsDlg(this); var result = getUserCreds.ShowDialog(); ///The Dialog will log us in and save the user credentials if (result == DialogResult.Cancel) { Exit(this, EventArgs.Empty); return; } } } } } } UserCredentials.Save(); #endregion #region Read options if (!GlobalOptions.Load()) { var optionsDlg = new MetroOptionsDlg(this, MetroOptionsDlg.Page.GlobalOptions); optionsDlg.RepoListingChanged += (o, args) => { _trayIcon.ContextMenu = new ContextMenu(BuildContextMenu()); }; var result = optionsDlg.ShowDialog(); if (result == DialogResult.Cancel) { Exit(this, EventArgs.Empty); } } if (GlobalOptions.Instance.RepositoryUpdateInterval > 0) { _updateIntervalTimer = new Timer(GlobalOptions.Instance.RepositoryUpdateInterval * 1000 * 60) { AutoReset = true }; _updateIntervalTimer.Elapsed += (sender, args) => { ServiceClient.DownloadAllUpdateInfo(); }; } else { ///no automatic updates; check the service every 45 minutes to prevent service time out _updateIntervalTimer = new Timer(45 * 1000 * 60) { AutoReset = true }; _updateIntervalTimer.Elapsed += (sender, args) => { ServiceClient.IsAlive(); }; } GlobalOptions.Save(); #endregion #region Set up repositories if (File.Exists(saveFilePath + @"\SavedRepositories.json")) { try { using (var saveFile = File.OpenText(saveFilePath + @"\SavedRepositories.json")) { var text = saveFile.ReadToEnd(); var repos = JsonConvert.DeserializeObject <GinRepositoryData[]>(text); foreach (var repo in repos) { ServiceClient.AddRepository(repo.PhysicalDirectory.FullName, repo.Mountpoint.FullName, repo.Name, repo.Address, GlobalOptions.Instance.RepositoryCheckoutOption == GlobalOptions.CheckoutOption.FullCheckout, false); } } } catch { } } else { ManageRepositoriesMenuItemHandler(null, EventArgs.Empty); } #endregion _trayIcon.DoubleClick += _trayIcon_DoubleClick; _trayIcon.ContextMenu = new ContextMenu(BuildContextMenu()); _trayIcon.Icon = Resources.gin_icon; _updateIntervalTimer?.Start(); }