void InitializeForm() { lstUsers.Items.Clear(); //SetAppStatus(); hostedNetworkManager = new HostedNetworkManager(); hostedNetworkManager.ThreadedEvents = new UiThreadedEvents(this); hostedNetworkManager.OnConnectionsListChanged += HostedNetworkManagerOnConnectionsListChanged; hostedNetworkManager.OnSharedConnectionChanged += HostedNetworkManagerOnSharedConnectionChanged; hostedNetworkManager.OnWorkingStatusChanged += HostedNetworkManagerOnWorkingStatusChanged; hostedNetworkManager.OnUserUpdated += HostedNetworkManagerOnUserUpdated; hostedNetworkManager.OnUserConnected += HostedNetworkManagerOnUserConnected; hostedNetworkManager.OnUserLeave += HostedNetworkManagerOnUserLeave; hostedNetworkManager.OnFailedToEnableSharing += HostedNetworkManagerOnFailedToEnableSharing; // reading ICS connections list hostedNetworkManager.ReadNetworkConnectionsAsync(); ReadFormSettings(); _icsDomainNameSuffix = SystemTweak.IcsDomainSuffix(); if (AppConfig.AppStartedFromStartup) { if (ValidateForm(false)) { SaveFormSettings(); hostedNetworkManager.StartAsync(); } } }
private void UiShowNoInternetAccess(HostedNetworkManager hostednetwork, Exception exception) { // only if user is requested start manually //if (!_manualStartIsInPrgress) // return; var result = MessageBox.Show( "Hotspot is failed to enable internet sharing automatically after many tries.\n" + "You have to enable the internet sharing manually.\n" + "Do you want to see how?", "Failed to enable windows sharing", MessageBoxButtons.OKCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, AppConfig.Instance.MessageBoxOptions); if (result == DialogResult.OK) { try { var filePath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), AppConfig.HelpNoInternetAccess); Process.Start(new ProcessStartInfo { FileName = filePath, UseShellExecute = true }); } catch (Exception) { } } }
/// <summary> /// Updating cmdSharedConnection /// </summary> void UiUpdateConnectionComboBox(HostedNetworkManager hostednetwork) { var connections = hostednetwork.IcsConnectedConnections; var shared = hostednetwork.SharedConnection; cmdSharedConnection.DisplayMember = "Name"; cmdSharedConnection.ValueMember = "Guid"; cmdSharedConnection.DataSource = null; cmdSharedConnection.Items.Clear(); cmdSharedConnection.DataSource = connections; if (shared == null) { var savedConnName = AppConfig.Instance.ConnectionShare; if (string.IsNullOrWhiteSpace(savedConnName)) { cmdSharedConnection.SelectedIndex = 0; } else { cmdSharedConnection.Text = savedConnName; } } else { cmdSharedConnection.SelectedItem = shared; var newName = cmdSharedConnection.Text; if (!string.IsNullOrWhiteSpace(newName)) { AppConfig.Instance.ConnectionShare = newName; } } }
private void HostedNetworkManagerOnFailedToEnableSharing(HostedNetworkManager hostednetwork, Exception exception) { UiShowNoInternetAccess(hostednetwork, exception); }
private void HostedNetworkManagerOnConnectionsListChanged(HostedNetworkManager hostednetwork) { UiUpdateConnectionComboBox(hostednetwork); }
private void HostedNetworkManagerOnWorkingStatusChanged(HostedNetworkManager hostednetwork) { UiUpdateFormWorkingStatus(hostednetwork); }
private void HostedNetworkManagerOnUserUpdated(HostedNetworkManager hostednetwork) { UiUpdateStationsList(hostednetwork); }
private void HostedNetworkManagerOnUserConnected(HostedNetworkManager hostednetwork, IList <StationUser> newUsers) { UiUpdateStationsList(hostednetwork, newUsers); }
void UiUpdateStationsList(HostedNetworkManager hostednetwork, IList <StationUser> newUsers = null) { bool isFarsi = AppConfig.Instance.IsFarsi; var desc = new List <string>(); lstUsers.Items.Clear(); var hasUsers = hostednetwork.StationUsers.Count > 0; _hasAnyUserShouldReadStatus = false; var usersToNotify = new List <StationUser>(); foreach (var user in hostednetwork.StationUsers) { if (user.Status == StationUser.UserStatus.Connecting || user.HostNameResolved == false) { // this user information is incomplete _hasAnyUserShouldReadStatus = true; } if (user.HostNameResolved && !user.NotifiedConnected) { usersToNotify.Add(user); user.NotifiedConnected = true; } user.SetIcsDomainSuffix(_icsDomainNameSuffix); var listViewItem = new ListViewItem(user.HostNameNoPrefix, 0); listViewItem.Text = user.HostNameNoPrefix; if (!string.IsNullOrEmpty(user.Vendor)) { desc.Add(user.Vendor); } if (!string.IsNullOrEmpty(user.IpAddress)) { desc.Add(user.IpAddress); } if (!string.IsNullOrEmpty(user.MacAddress)) { desc.Add(user.MacAddress); } desc.Add(user.JoinDate.ToString("yyyy/MM/dd HH:mm")); if (isFarsi) { desc.Reverse(); } var descText = Common.JoinList(", ", desc); if (isFarsi) { descText = "\u200E" + descText; } listViewItem.SubItems.Add(descText); listViewItem.ToolTipText = user.HostName + "\r\n" + descText; listViewItem.Tag = user; desc.Clear(); lstUsers.Items.Add(listViewItem); } if (_hasStationUsers != hasUsers) { if (hasUsers) { sysIcon.Icon = Hotspoter.Properties.Resources.AppiconTrayUser; Icon = Hotspoter.Properties.Resources.AppiconTrayUser; } else { Icon = Hotspoter.Properties.Resources.AppiconTray; if (hostednetwork.Status == HostedNetworkManager.WorkingStatus.Stopped) { sysIcon.Icon = Hotspoter.Properties.Resources.AppiconTrayDisabled; } else { sysIcon.Icon = Hotspoter.Properties.Resources.AppiconTray; } } _hasStationUsers = hasUsers; } if (usersToNotify.Count > 0 && chkUsersNotifyNewUser.Checked) { var message = string.Join("\n", usersToNotify.Select(a => a.HostNameNoPrefix + ", " + a.IpAddress.ToString())); message = "The following user(s) are connected:\n" + message; sysIcon.ShowBalloonTip(1000, Hotspoter.Language.App_Name, message, ToolTipIcon.Info); } else if (newUsers != null && chkUsersNotifyUserConnecting.Checked) { sysIcon.ShowBalloonTip(1000, Hotspoter.Language.App_Name, Hotspoter.Language.Balloon_NewUser, ToolTipIcon.Info); } SetRefreshStationsTimer(); }
void UiUpdateFormWorkingStatus(HostedNetworkManager hostednetwork) { bool isBusy = false; bool isStarted = false; switch (hostednetwork.Status) { case HostedNetworkManager.WorkingStatus.Started: tabMain.SelectTab(tabUsers); lblStatus.Text = Hotspoter.Language.Form_StartedStated; lblStatus.ForeColor = Color.Green; btnStartStop.Text = Hotspoter.Language.Form_BtnStoped; pictureBox11.Image = Hotspoter.Properties.Resources.ok; sysIcon.Text = "Hotspoter : Hotspot Is Running"; isBusy = false; isStarted = true; _manualStartIsInPrgress = false; sysIcon.Icon = Hotspoter.Properties.Resources.AppiconTray; break; case HostedNetworkManager.WorkingStatus.Stopped: tabMain.SelectTab(tabHotspot); lblStatus.Text = Hotspoter.Language.Form_StopedStated; lblStatus.ForeColor = Color.Red; btnStartStop.Text = Hotspoter.Language.Form_BtnStarted; sysIcon.Text = "Hotspoter : Hotspot Is Stopped !"; isBusy = false; pictureBox11.Image = Hotspoter.Properties.Resources.oh; isStarted = false; //_manualStartIsInPrgress = false; // reload the connections list hostedNetworkManager.ReadNetworkConnectionsAsync(); sysIcon.Icon = Hotspoter.Properties.Resources.AppiconTrayDisabled; break; case HostedNetworkManager.WorkingStatus.Starting: lblStatus.Text = "Starting..."; lblStatus.ForeColor = Color.DarkRed; btnStartStop.Text = "Starting..."; sysIcon.Text = "Hotspot Share (Starting)"; isBusy = true; isStarted = false; break; case HostedNetworkManager.WorkingStatus.Stopping: lblStatus.Text = "Stopping..."; lblStatus.ForeColor = Color.DarkRed; btnStartStop.Text = "Stopping..."; sysIcon.Text = "Hotspot Share (Stopping)"; isBusy = true; isStarted = false; //_manualStartIsInPrgress = false; break; case HostedNetworkManager.WorkingStatus.StartFailed: tabMain.SelectTab(tabHotspot); lblStatus.Text = "Startup Failed"; lblStatus.ForeColor = Color.Red; btnStartStop.Text = "Try Start"; sysIcon.Text = "Hotspot Share (Start Failed)"; isBusy = false; isStarted = false; _manualStartIsInPrgress = false; // reload the connections list hostedNetworkManager.ReadNetworkConnectionsAsync(); break; case HostedNetworkManager.WorkingStatus.StopFailed: tabMain.SelectTab(tabHotspot); lblStatus.Text = "Stopping Failed"; lblStatus.ForeColor = Color.Red; btnStartStop.Text = "Try Stop"; sysIcon.Text = "Hotspot Share (Stop Failed)"; isBusy = false; isStarted = true; _manualStartIsInPrgress = false; break; } var enableControls = !(isBusy || isStarted); gpbSettings.Enabled = enableControls; gpbInternet.Enabled = enableControls; btnStartStop.Enabled = !isBusy; }