public MainForm() { ShrewNotifier.OperationLogged += notifications_OperationLogged; ShrewNotifier.ConnectionStatusChanged += notifications_ConnectionStatusChanged; UpdateChecker.UpdateAvailable += updates_UpdateAvailable; InitializeComponent(); ShrewCredentials credentials = null; try { credentials = ShrewConfiguration.LoadCredentials(); } catch (Exception exc) { MessageBox.Show("Unable to load saved credentials! " + exc.Message, "Error Loading Credentials!", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (credentials != null) { this.usernameTextBox.Text = credentials.username; this.passwordTextBox.Text = credentials.password; this.siteConfigTextBox.Text = credentials.siteConfigPath; this.checkboxConnectOnStart.Checked = credentials.connectOnStart; this.checkBoxSave.Checked = true; if (this.checkboxConnectOnStart.Checked) { connect(); this.WindowState = FormWindowState.Minimized; } } else { this.checkBoxSave.Checked = false; } }
private static void PerformCheck(Object stateInfo) { try { ShrewProperties properties = ShrewConfiguration.LoadProperties(); Version localVersion = Assembly.GetExecutingAssembly().GetName().Version; //userID used to track active user count. WebRequest request = HttpWebRequest.Create(string.Format(VERSION_URL, properties.userId, localVersion.ToString(), getArch())); WebResponse response = request.GetResponse(); StreamReader rdr = new StreamReader(response.GetResponseStream()); char[] buffer = new char[response.ContentLength]; rdr.Read(buffer, 0, (Int32)response.ContentLength); Version latestVersion = new Version(new String(buffer)); bool newVersionAvailable = latestVersion.CompareTo(localVersion) > 0; if (newVersionAvailable && UpdateAvailable != null) { UpdateAvailable(null, new UpdateAvailableArgs(latestVersion)); } properties.lastUpdateCheck = DateTime.UtcNow; ShrewConfiguration.SaveProperties(properties); } catch (Exception) { //Eat all errors } }
private void connect() { if (String.IsNullOrWhiteSpace(this.usernameTextBox.Text) || String.IsNullOrWhiteSpace(this.passwordTextBox.Text) || String.IsNullOrWhiteSpace(this.siteConfigTextBox.Text)) { MessageBox.Show("Site Config Path, Username and Password fields must all be completed before you will be able to connect to your VPN.", "Required Fields", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } statusTextBox.Text = ""; connectPanel.Visible = false; statusPanel.Visible = true; ShrewCredentials credentials = new ShrewCredentials(); credentials.username = this.usernameTextBox.Text; credentials.password = this.passwordTextBox.Text; credentials.siteConfigPath = this.siteConfigTextBox.Text; credentials.connectOnStart = this.checkboxConnectOnStart.Checked; credentials.formLogin = this.formloginTextBox.Text; credentials.authenticateOnConnected = this.checkboxAuth.Checked; connection = new ShrewConnection(credentials); if (checkBoxSave.Checked) { try { ShrewConfiguration.SaveCredentials(credentials); } catch (Exception exc) { MessageBox.Show("Unable to save credentials! " + exc.Message, "Error Saving Credentials!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { ShrewConfiguration.DeleteCredentials(); } connection.Connect(); }
public static void CheckForUpdate() { ShrewProperties properties = ShrewConfiguration.LoadProperties(); if (properties == null) { properties = new ShrewProperties(); properties.userId = Guid.NewGuid(); ShrewConfiguration.SaveProperties(properties); } long initalDelay = 0; if (properties.lastUpdateCheck != null) { initalDelay = (long)properties.lastUpdateCheck.AddMilliseconds(UPDATE_CHECK_INTERVAL_MILLIS) .Subtract(DateTime.UtcNow).TotalMilliseconds; if (initalDelay < 0) { initalDelay = 0; } } updateCheckTimer = new Timer(UpdateChecker.PerformCheck, null, initalDelay, UPDATE_CHECK_INTERVAL_MILLIS); }