-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
MDevoldere
committed
Sep 15, 2018
1 parent
6af33bb
commit b91845d
Showing
50 changed files
with
2,275 additions
and
517 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -286,4 +286,3 @@ __pycache__/ | |
*.btm.cs | ||
*.odx.cs | ||
*.xsd.cs | ||
*.ivan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} | ||
} |
Oops, something went wrong.