Skip to content

Commit

Permalink
Legacy Update
Browse files Browse the repository at this point in the history
  • Loading branch information
MDevoldere committed Sep 15, 2018
1 parent 6af33bb commit b91845d
Show file tree
Hide file tree
Showing 50 changed files with 2,275 additions and 517 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,3 @@ __pycache__/
*.btm.cs
*.odx.cs
*.xsd.cs
*.ivan
4 changes: 2 additions & 2 deletions NetSpeedTray/NetInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class NetInterface

public string StateText { get { return State.Text; } }

public string TrafficeDown { get { return Traffice.BytesReceivedSpeedText; } }
public string TrafficeDown { get { return Traffice.SpeedDownText; } }

public string TrafficeUp { get { return Traffice.BytesSentSpeedText; } }
public string TrafficeUp { get { return Traffice.SpeedUpText; } }


IPInterfaceProperties ipProperties;
Expand Down
22 changes: 19 additions & 3 deletions NetSpeedTray/NetInterfaceList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,20 @@ public class NetInterfaceList : List<NetInterface>

public NetInterface SelectedInterface { get; private set; }

protected NetworkInterface nic;

protected StringBuilder sb;

/*public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}*/


public NetInterfaceList() : base()
{
Expand All @@ -39,12 +51,13 @@ public NetInterface GetFirstUpInterface()
public override string ToString()
{
sb = new StringBuilder();
sb.Append("Interfaces (").Append(CountUp.ToString()).Append("/").Append(Count.ToString()).Append(")");
sb.Append("Networks (").Append(CountUp.ToString()).Append("/").Append(Count.ToString()).Append(")");
return sb.ToString();
}

public void UpdateList()
{
nic = null;
CountUp = 0;
FirstUp = -1;
Clear();
Expand All @@ -54,12 +67,14 @@ public void UpdateList()
return;
}

foreach(NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
for(int i = 0; i < NetworkInterface.GetAllNetworkInterfaces().Length; i++)
{
nic = NetworkInterface.GetAllNetworkInterfaces()[i];

if (nic.NetworkInterfaceType != NetworkInterfaceType.Tunnel
&& nic.NetworkInterfaceType != NetworkInterfaceType.Loopback)
{
NetInterface ni = new NetInterface(nic, Count);
NetInterface ni = new NetInterface(nic, i);

if (ni.State.Up)
{
Expand All @@ -74,6 +89,7 @@ public void UpdateList()
ni.Update();
Add(ni);
}

}

if (FirstUp == -1)
Expand Down
72 changes: 0 additions & 72 deletions NetSpeedTray/NetInterfaceManager.cs

This file was deleted.

123 changes: 123 additions & 0 deletions NetSpeedTray/NetListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Net.NetworkInformation;

namespace Devoldere.NetSpeedTray
{
public interface INetObserver
{
void NetUpdate();
}

public class NetListener
{
static protected readonly Timer AppTimer = new Timer { Interval = 10000, Enabled = false };

static protected readonly Timer NetTimer = new Timer { Interval = 1000, Enabled = false };

static public NetInterfaceList InterfaceList { get; private set; } = new NetInterfaceList();

static protected List<INetObserver> appObs = new List<INetObserver>();

static protected List<INetObserver> netObs = new List<INetObserver>();

#region Timers

static public void Start()
{
AppTimer.Tick += AppTimer_Tick;
NetTimer.Tick += NetTimer_Tick;
AppTimer.Start();
NetTimer.Start();
}

static public void Stop()
{
AppTimer.Tick -= AppTimer_Tick;
NetTimer.Tick -= NetTimer_Tick;
AppTimer.Stop();
NetTimer.Stop();
}

/// <summary>
/// Event timer Tick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
static public void AppTimer_Tick(object sender, EventArgs e)
{
foreach (NetInterface ni in InterfaceList)
{
if(ni != null)
ni.Update();
}

Notify(appObs);
}

/// <summary>
/// Event timerTraffice Tick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
static public void NetTimer_Tick(object sender, EventArgs e)
{
foreach (NetInterface ni in InterfaceList)
{
if (ni != null)
ni.UpdateTraffice();
}

Notify(netObs);
}

#endregion

#region Observers

static public void AppRegister(INetObserver obs)
{
if (!appObs.Contains(obs))
{
appObs.Add(obs);
}
}

static public void NetRegister(INetObserver obs)
{
if (!netObs.Contains(obs))
{
netObs.Add(obs);
}
}

static public void Notify(List<INetObserver> observers)
{
foreach (INetObserver obs in observers)
{
if (obs != null)
{
obs.NetUpdate();
}
}
}

static public void Release(INetObserver obs)
{
if (netObs.Contains(obs))
{
netObs.Remove(obs);
}

if (appObs.Contains(obs))
{
appObs.Remove(obs);
}
}

#endregion

}
}
Loading

0 comments on commit b91845d

Please sign in to comment.