-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
7 changed files
with
462 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.11.35327.3 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Network Monitor", "Network Monitor\Network Monitor.csproj", "{EFCE88DA-0570-4D89-8B0E-24E762AB8F63}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{EFCE88DA-0570-4D89-8B0E-24E762AB8F63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{EFCE88DA-0570-4D89-8B0E-24E762AB8F63}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{EFCE88DA-0570-4D89-8B0E-24E762AB8F63}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{EFCE88DA-0570-4D89-8B0E-24E762AB8F63}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {9C988FCE-3E23-4768-B87B-ACB407B69E4B} | ||
EndGlobalSection | ||
EndGlobal |
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,10 @@ | ||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> | ||
<Costura> | ||
<IncludeAssemblies> | ||
OxyPlot | ||
OxyPlot.Wpf | ||
OxyPlot.Wpf.Shared | ||
System.ComponentModel.Composition | ||
</IncludeAssemblies> | ||
</Costura> | ||
</Weavers> |
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,26 @@ | ||
<Window x:Class="Network_Monitor.MainWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:oxy="http://oxyplot.org/wpf" | ||
WindowStyle="None" | ||
Title="NetWork Monitor" Height="200" Width="400"> | ||
<Border> | ||
<Grid> | ||
<oxy:PlotView Model="{Binding NetworkPlotModel}" Background="Transparent"/> | ||
|
||
<DockPanel> | ||
<TextBlock x:Name="UsageText" FontSize="18" Foreground="RosyBrown" Margin="10,10,0,0"> | ||
<Run Text="Network"/> | ||
<Run x:Name="TextR" Text="{Binding ReceivedUsageText}"/> | ||
<Run x:Name="TextS" Text="{Binding SentUsageText}"/> | ||
</TextBlock> | ||
<TextBlock x:Name="MaxBandText" | ||
Text="{Binding MaxBandText}" | ||
FontSize="9" | ||
Foreground="RosyBrown" | ||
HorizontalAlignment="Right" | ||
Margin="10"/> | ||
</DockPanel> | ||
</Grid> | ||
</Border> | ||
</Window> |
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,73 @@ | ||
using System.ComponentModel; | ||
using System.Windows; | ||
using Widgets.Common; | ||
|
||
namespace Network_Monitor | ||
{ | ||
public partial class MainWindow : Window, IWidgetWindow | ||
{ | ||
public readonly static string WidgetName = "Network Monitor"; | ||
public readonly static string SettingsFile = "settings.networkmonitor.json"; | ||
private readonly Config config = new(SettingsFile); | ||
|
||
public NetworkViewModel ViewModel { get; set; } | ||
private NetworkViewModel.SettingsStruct Settings = NetworkViewModel.Default; | ||
|
||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
LoadSettings(); | ||
ViewModel = new NetworkViewModel() | ||
{ | ||
Settings = Settings | ||
}; | ||
DataContext = ViewModel; | ||
_ = ViewModel.Start(); | ||
Logger.Info($"{WidgetName} is started"); | ||
} | ||
|
||
public void LoadSettings() | ||
{ | ||
try | ||
{ | ||
Settings.ReceivedColor = PropertyParser.ToString(config.GetValue("received_color"), Settings.ReceivedColor); | ||
Settings.SentColor = PropertyParser.ToString(config.GetValue("sent_color"), Settings.SentColor); | ||
Settings.TimeLine = PropertyParser.ToFloat(config.GetValue("graphic_timeline"), Settings.TimeLine); | ||
|
||
UsageText.FontSize = PropertyParser.ToFloat(config.GetValue("usage_font_size")); | ||
UsageText.Foreground = PropertyParser.ToColorBrush(config.GetValue("usage_foreground")); | ||
TextR.Foreground = PropertyParser.ToColorBrush(Settings.ReceivedColor); | ||
TextS.Foreground = PropertyParser.ToColorBrush(Settings.SentColor); | ||
MaxBandText.Foreground = UsageText.Foreground; | ||
MaxBandText.FontSize = UsageText.FontSize / 2; | ||
} | ||
catch (Exception) | ||
{ | ||
config.Add("usage_font_size", UsageText.FontSize); | ||
config.Add("usage_foreground", UsageText.Foreground); | ||
config.Add("received_color", Settings.ReceivedColor); | ||
config.Add("sent_color", Settings.SentColor); | ||
config.Add("graphic_timeline", Settings.TimeLine); | ||
|
||
config.Save(); | ||
} | ||
} | ||
|
||
protected override void OnClosing(CancelEventArgs e) | ||
{ | ||
base.OnClosing(e); | ||
ViewModel.Dispose(); | ||
Logger.Info($"{WidgetName} is closed"); | ||
} | ||
|
||
public WidgetWindow WidgetWindow() | ||
{ | ||
return new WidgetWindow(this, WidgetDefaultStruct()); | ||
} | ||
|
||
public static WidgetDefaultStruct WidgetDefaultStruct() | ||
{ | ||
return new WidgetDefaultStruct(); | ||
} | ||
} | ||
} |
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,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0-windows</TargetFramework> | ||
<RootNamespace>Network_Monitor</RootNamespace> | ||
<Nullable>enable</Nullable> | ||
<UseWPF>true</UseWPF> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Costura.Fody" Version="5.7.0"> | ||
<PrivateAssets>all</PrivateAssets> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
</PackageReference> | ||
<PackageReference Include="OxyPlot.Wpf" Version="2.2.0" /> | ||
<PackageReference Include="System.ComponentModel.Composition" Version="8.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="Widgets.Common"> | ||
<HintPath>..\..\Widgets.Common\Widgets.Common\bin\Debug\net8.0-windows\Widgets.Common.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
|
||
<Target Name="PostBuild" AfterTargets="PostBuildEvent"> | ||
<MakeDir Directories="$(TargetDir)$(AssemblyName)" /> | ||
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(TargetDir)$(AssemblyName)" /> | ||
</Target> | ||
</Project> |
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,21 @@ | ||
using System.ComponentModel.Composition; | ||
using System.Windows; | ||
using Widgets.Common; | ||
|
||
namespace Network_Monitor | ||
{ | ||
[Export(typeof(IPlugin))] | ||
internal class NetworkMonitorPlugin : IPlugin | ||
{ | ||
public string Name => MainWindow.WidgetName; | ||
public string? ConfigFile => MainWindow.SettingsFile; | ||
public WidgetDefaultStruct WidgetDefaultStruct() | ||
{ | ||
return MainWindow.WidgetDefaultStruct(); | ||
} | ||
public WidgetWindow WidgetWindow() | ||
{ | ||
return new MainWindow().WidgetWindow(); | ||
} | ||
} | ||
} |
Oops, something went wrong.