private void Apply() { NetIconImage.IconStyle selectedIconStyle; if (optLines.Checked) { selectedIconStyle = NetIconImage.IconStyle.Lines; } else if (optGrow.Checked) { selectedIconStyle = NetIconImage.IconStyle.Grow; } else { throw new Exception("No selected icon style"); } AppRegistry.SaveIconType( Application.CompanyName, Application.ProductName, "NetworkNotificationIconStyle", selectedIconStyle); m_networkAnimation.SetIconStyle(selectedIconStyle); int intNewTimerInterval = Convert.ToInt32(trackBarTimerInterval.Value * 100); AppRegistry.SaveIntValue( Application.CompanyName, Application.ProductName, "NetworkNotificationTimerInterval", intNewTimerInterval); m_networkAnimation.SetTimerInterval(intNewTimerInterval); int intIndicatorPacketSize = Convert.ToInt32(trackBarIndicatorPacketSize.Value * 128); AppRegistry.SaveIntValue( Application.CompanyName, Application.ProductName, "NetworkNotificatioIndicatorPacketSize", intIndicatorPacketSize); }
private void frmSettings_Load(object sender, EventArgs e) { InitPictures(); NetIconImage.IconStyle iconStyle = AppRegistry.GetIconStyle( Application.CompanyName, Application.ProductName, "NetworkNotificationIconStyle", NetIconImage.IconStyle.Grow); switch (iconStyle) { case NetIconImage.IconStyle.Lines: optLines.Checked = true; break; case NetIconImage.IconStyle.Grow: optGrow.Checked = true; break; } int intTimerInterval = AppRegistry.GetIntValue( Application.CompanyName, Application.ProductName, "NetworkNotificationTimerInterval", NetworkAnimation.DEFAULT_TIMER_INTERVAL); timer1.Interval = intTimerInterval; timer1.Start(); trackBarTimerInterval.Value = Convert.ToInt32(intTimerInterval / TIME_INTERVAL_GRANULARITY_MS); trackBarTimerInterval.Minimum = 100 / TIME_INTERVAL_GRANULARITY_MS; // 100 ms trackBarTimerInterval.Maximum = 4000 / TIME_INTERVAL_GRANULARITY_MS; // 4 seconds trackBarTimerInterval_Scroll(this, EventArgs.Empty); // Trigger change and UI update int intIndicatorPacketSize = AppRegistry.GetIntValue( Application.CompanyName, Application.ProductName, "NetworkNotificatioIndicatorPacketSize", NetworkAnimation.DEFAULT_INDICATOR_PACKET_SIZE); trackBarIndicatorPacketSize.Value = Convert.ToInt32(intIndicatorPacketSize / PACKET_SIZE_GRANULARITY_MS); trackBarIndicatorPacketSize.Minimum = 128 / PACKET_SIZE_GRANULARITY_MS; // 128 bytes trackBarIndicatorPacketSize.Maximum = 8192 / PACKET_SIZE_GRANULARITY_MS; // 8 MB trackBarIndicatorPacketSize_Scroll(this, EventArgs.Empty); // Trigger change and UI update }
public NetworkAnimation() { int intTimerInterval = AppRegistry.GetIntValue( Application.CompanyName, Application.ProductName, "NetworkNotificatioTimerInterval", DEFAULT_TIMER_INTERVAL); m_timer.Tick += m_timer_Tick; SetTimerInterval(intTimerInterval); m_timer.Start(); //Set event handler for connection status and check initialy Computer c = new Computer(); if (c.Network.IsAvailable) { OnNetworkAvailable(new NetworkStatusChangedEventArgs(true)); m_bNetworkAvailable = true; } else { OnNetworkUnavailable(new NetworkStatusChangedEventArgs(true)); m_bNetworkAvailable = false; } NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged; }
private void WriteTotalNetworkBytes() { int intIndicatorPacketSize = AppRegistry.GetIntValue( Application.CompanyName, Application.ProductName, "NetworkNotificatioIndicatorPacketSize", DEFAULT_INDICATOR_PACKET_SIZE); //Aggregate values long lBytesReceived = 0; long lBytesSend = 0; foreach (NetworkInterface adapter in NetworkInterfaces) { IPInterfaceProperties properties = adapter.GetIPProperties(); if (!adapter.Supports(NetworkInterfaceComponent.IPv4)) { continue; } IPv4InterfaceStatistics ipv4stats = adapter.GetIPv4Statistics(); lBytesReceived += ipv4stats.BytesReceived; lBytesSend += ipv4stats.BytesSent; } //Check if this is the first time if (m_lBytesReceived == long.MinValue) { m_lBytesReceived = lBytesReceived; } if (m_lBytesSent == long.MinValue) { m_lBytesSent = lBytesSend; } //Update Icons if (m_bNetworkAvailable) { if (lBytesSend - m_lBytesSent > intIndicatorPacketSize && lBytesReceived - m_lBytesReceived > intIndicatorPacketSize) { //Update values for next time m_lBytesReceived = lBytesReceived; m_lBytesSent = lBytesSend; OnTrafficSentReceived(EventArgs.Empty); } else if (lBytesSend - m_lBytesSent > intIndicatorPacketSize) { //Update values for next time m_lBytesSent = lBytesSend; OnTrafficSent(EventArgs.Empty); } else if (lBytesReceived - m_lBytesReceived > intIndicatorPacketSize) { //Update values for next time m_lBytesReceived = lBytesReceived; OnTrafficReceived(EventArgs.Empty); } else { //m_intIconIndex = 0; OnNetworkAvailable(new NetworkStatusChangedEventArgs(false)); } } else { OnNetworkUnavailable(new NetworkStatusChangedEventArgs(false)); } }