Skip to content

Commit

Permalink
One.Toolbox
Browse files Browse the repository at this point in the history
新增显示当前系统使用的IP;
其他内存问题优化;
移除不必要的组件;
  • Loading branch information
panwenbo committed Jan 9, 2024
1 parent 451edfe commit efb4e11
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 442 deletions.
22 changes: 11 additions & 11 deletions One.Core/Helpers/NetHelpers/NetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@ namespace One.Core.Helpers.NetHelpers
public class NetHelper
{
/// <summary> 获取本机所有IPv4地址 </summary>
public static List<IPAddress> GetIPv4AdList()
/// <returns> </returns>
public static List<IPAddress> GetIPv4AddressList()
{
string hostName = Dns.GetHostName();//本机名
string hostName = Dns.GetHostName();
IPAddress[] addressList = Dns.GetHostAddresses(hostName);//会返回所有地址,包括IPv4和IPv6
List<IPAddress> address4List = new List<IPAddress>();
foreach (IPAddress ipa in addressList)
List<IPAddress> ipv4AddressList = new List<IPAddress>();
foreach (IPAddress ipAddress in addressList)
{
if (ipa.AddressFamily == AddressFamily.InterNetwork)
if (ipAddress.AddressFamily == AddressFamily.InterNetwork)
{
//LocalIP = ipa;
//return ipa.ToString();
address4List.Add(ipa);
//return ipa;
ipv4AddressList.Add(ipAddress);
}
}
return address4List;
return ipv4AddressList;
}

/// <summary> 获取本机所有IPv6地址 </summary>
Expand All @@ -48,7 +46,7 @@ public static List<IPAddress> GetIPv6AdList()
return address4List;
}

/// <summary> 获取当前使用的IP,Ping baidu </summary>
/// <summary> 通过Ping baidu 获取当前使用的IP </summary>
/// <returns> </returns>
public static string GetLocalIP()
{
Expand Down Expand Up @@ -272,6 +270,8 @@ public IPAddress BroadcastPoint
get { return GetBroadcastPoint(); }
}

/// <summary> This function calculates and returns the broadcast point IP address based on the given IP address and IPv4 mask. </summary>
/// <returns> The broadcast point IP address as an instance of IPAddress, or null if either the IP or the IPv4 mask is null. </returns>
private IPAddress GetBroadcastPoint()
{
if (IP != null && IPv4Mask != null)
Expand Down
4 changes: 1 addition & 3 deletions One.Toolbox/One.Toolbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<Version>2.6.5</Version>
<Version>2.6.6</Version>
<ImplicitUsings>enable</ImplicitUsings>
<SatelliteResourceLanguages>zh-Hans;en-us</SatelliteResourceLanguages>
<ApplicationIcon>Icon.ico</ApplicationIcon>
Expand All @@ -33,13 +33,11 @@
<PackageReference Include="AvalonEdit" Version="6.3.0.90" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1" />
<PackageReference Include="HandyControl" Version="3.4.0" />
<PackageReference Include="LibUsbDotNet" Version="3.0.102-alpha" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="5.0.2" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="5.0.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.49-beta">
<PrivateAssets>all</PrivateAssets>

</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NLog" Version="5.2.4" />
Expand Down
12 changes: 5 additions & 7 deletions One.Toolbox/ViewModels/BingImage/BingImageVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override void OnNavigatedEnter()
[ObservableProperty]
private ObservableCollection<UsefullImageInfoVM> obImageListInfo = new ObservableCollection<UsefullImageInfoVM>();

private List<UsefullImageInfoVM> ImageList = new List<UsefullImageInfoVM>();
private List<UsefullImageInfoVM> ImageList = [];
//public ObservableCollection<UsefullImageInfoViewModel> ObImageListInfo { get; set; } = new ObservableCollection<UsefullImageInfoViewModel>();

async void InitData()
Expand Down Expand Up @@ -143,7 +143,7 @@ private List<UsefullImageInfoVM> FilterImageInfoAndSave(BingImageOriginalModel b
return listVM;
}

private async Task DownloadImage(UsefullImageInfoVM usefullImageInfos)
private static async Task DownloadImage(UsefullImageInfoVM usefullImageInfos)
{
//查看图片是否已经下载,path为路径
if (File.Exists(usefullImageInfos.LocalImagePath))
Expand All @@ -165,14 +165,12 @@ private async Task DownloadImage(UsefullImageInfoVM usefullImageInfos)
{
return;
}
//创造图片
using (FileStream fileStream = new FileStream(usefullImageInfos.LocalImagePath, FileMode.Create))

using (var fileStream = new FileStream(usefullImageInfos.LocalImagePath, FileMode.Create))
using (var binaryWriter = new BinaryWriter(fileStream))
{
BinaryWriter binaryWriter = new BinaryWriter(fileStream);
//写入图片信息
binaryWriter.Write(timeline);
}

return;
}
}
14 changes: 14 additions & 0 deletions One.Toolbox/ViewModels/Dashboard/DashboardVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ void InitData()
Text = a.hitokoto;
Author = "--" + a.from;
});

_ = Task.Run(GetCurrentUseIP);
}

private void Register()
Expand Down Expand Up @@ -89,4 +91,16 @@ private static async Task<YiyanAPIM> GetEveryDayYiyan()

return timeline;
}

#region StatusBar

[ObservableProperty]
private string currentUseIP;

private void GetCurrentUseIP()
{
CurrentUseIP = One.Core.Helpers.NetHelpers.NetHelper.GetLocalIP();
}

#endregion StatusBar
}
176 changes: 98 additions & 78 deletions One.Toolbox/Views/Dashboard/DashboardPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,83 +11,103 @@
d:Height="548"
d:Width="733"
mc:Ignorable="d">
<ScrollViewer>
<Grid Margin="20">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Border Grid.Row="0" Height="150" CornerRadius="8">
<Border.Background>
<ImageBrush ImageSource="pack://application:,,,/Resources/pexels-johannes-plenio-1103970.jpg" RenderOptions.BitmapScalingMode="HighQuality" Stretch="UniformToFill" />
</Border.Background>
<Border CornerRadius="8">
<Border.Background>
<RadialGradientBrush>
<GradientStop Offset="0" Color="#1F000000" />
<GradientStop Offset="1" Color="#4F000000" />
</RadialGradientBrush>
</Border.Background>
<Grid>
<StackPanel Margin="48,0" HorizontalAlignment="Left" VerticalAlignment="Center" Background="Transparent">
<!--<TextBlock FontSize="18" Foreground="#B7FFFFFF" Text="Windows Presentation Foundation" />-->
<TextBlock FontSize="28" FontWeight="Bold" Foreground="#FFFFFF" Text="One.Toolbox" />
<!--<TextBlock FontSize="18" Foreground="#B7FFFFFF" Text="Build Fluent experiences on Windows using WPF UI." />-->
<StackPanel VerticalAlignment="Center" Orientation="Horizontal">
<TextBlock FontSize="14" Foreground="#B7FFFFFF" Text="{Binding Text}" />
<!--<TextBlock VerticalAlignment="Center" FontSize="12" Text=" " />-->

<TextBlock VerticalAlignment="Center" FontSize="12" Foreground="#B7FFFFFF" Text="{Binding Author}" />
</StackPanel>
</StackPanel>
<TextBlock Margin="12" HorizontalAlignment="Right" VerticalAlignment="Bottom" FontSize="10"
Foreground="#57FFFFFF" Text="Created by pwb" />
<Button HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="Transparent" BorderThickness="0"
Command="{Binding TestCommand}"
Visibility="Visible" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />

</Grid.RowDefinitions>
<Border Style="{StaticResource BorderRegion}">
<ScrollViewer>
<Grid Margin="20">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />

</Grid.RowDefinitions>

<Border Grid.Row="0" Height="150" CornerRadius="8">
<Border.Background>
<ImageBrush ImageSource="pack://application:,,,/Resources/pexels-johannes-plenio-1103970.jpg" RenderOptions.BitmapScalingMode="HighQuality" Stretch="UniformToFill" />
</Border.Background>
<Border CornerRadius="8">
<Border.Background>
<RadialGradientBrush>
<GradientStop Offset="0" Color="#1F000000" />
<GradientStop Offset="1" Color="#4F000000" />
</RadialGradientBrush>
</Border.Background>
<Grid>
<StackPanel Margin="48,0" HorizontalAlignment="Left" VerticalAlignment="Center" Background="Transparent">
<!--<TextBlock FontSize="18" Foreground="#B7FFFFFF" Text="Windows Presentation Foundation" />-->
<TextBlock FontSize="28" FontWeight="Bold" Foreground="#FFFFFF" Text="One.Toolbox" />
<!--<TextBlock FontSize="18" Foreground="#B7FFFFFF" Text="Build Fluent experiences on Windows using WPF UI." />-->
<StackPanel VerticalAlignment="Center" Orientation="Horizontal">
<TextBlock FontSize="14" Foreground="#B7FFFFFF" Text="{Binding Text}" />
<!--<TextBlock VerticalAlignment="Center" FontSize="12" Text=" " />-->

<TextBlock VerticalAlignment="Center" FontSize="12" Foreground="#B7FFFFFF" Text="{Binding Author}" />
</StackPanel>
</StackPanel>
<TextBlock Margin="12" HorizontalAlignment="Right" VerticalAlignment="Bottom" FontSize="10"
Foreground="#57FFFFFF" Text="Created by pwb" />
<Button HorizontalAlignment="Right" VerticalAlignment="Bottom" Background="Transparent" BorderThickness="0"
Command="{Binding TestCommand}"
Visibility="Visible" />
</Grid>
</Border>
</Border>

<Grid Grid.Row="1" Margin="0,24,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
</Grid>
</Border>
</Border>

<Grid Grid.Row="1" Margin="0,24,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
</Grid>

<StackPanel Grid.Row="2" Margin="0,24,0,0">

<TextBlock FontSize="18" FontWeight="DemiBold" Text="One.Core" />

<uc:Hyperlink Padding="4" Content="Documentation" NavigateUri="https://kleinpan.github.io/One/api/index.html" ToolTip="https://kleinpan.github.io/One/api/index.html" />
<uc:Hyperlink Padding="4" Content="GitHub" NavigateUri="https://github.com/KleinPan/One" ToolTip="https://github.com/KleinPan/One" />

<uc:Hyperlink Padding="4" Content="NuGet" NavigateUri="https://www.nuget.org/packages/One.Core/" ToolTip="https://www.nuget.org/packages/One.Core/" />
</StackPanel>
<StackPanel Grid.Row="3" Margin="0,24,0,0">
<TextBlock FontSize="18" FontWeight="DemiBold" Text="One.Control" />

<uc:Hyperlink Content="Documentation" NavigateUri="https://kleinpan.github.io/One/api/index.html" ToolTip="https://kleinpan.github.io/One/api/index.html" />

<uc:Hyperlink Content="GitHub" NavigateUri="https://github.com/KleinPan/One" ToolTip="https://github.com/KleinPan/One" />

<uc:Hyperlink Content="NuGet" NavigateUri="https://www.nuget.org/packages/One.Control/" ToolTip="https://www.nuget.org/packages/One.Control/" />
</StackPanel>

<StackPanel Grid.Row="4" Margin="0,24,0,0">
<TextBlock FontSize="18" FontWeight="DemiBold" Text="One.Toolbox" />
<uc:Hyperlink Content="Documentation" NavigateUri="https://github.com/KleinPan/One" ToolTip="https://github.com/KleinPan/One" />
<uc:Hyperlink Content="GitHub" NavigateUri="https://github.com/KleinPan/One" ToolTip="https://github.com/KleinPan/One" />
</StackPanel>
</Grid>
</ScrollViewer>

<StackPanel Grid.Row="2" Margin="0,24,0,0">

<TextBlock FontSize="18" FontWeight="DemiBold" Text="One.Core" />

<uc:Hyperlink Padding="4" Content="Documentation" NavigateUri="https://kleinpan.github.io/One/api/index.html" ToolTip="https://kleinpan.github.io/One/api/index.html" />
<uc:Hyperlink Padding="4" Content="GitHub" NavigateUri="https://github.com/KleinPan/One" ToolTip="https://github.com/KleinPan/One" />

<uc:Hyperlink Padding="4" Content="NuGet" NavigateUri="https://www.nuget.org/packages/One.Core/" ToolTip="https://www.nuget.org/packages/One.Core/" />
</StackPanel>
<StackPanel Grid.Row="3" Margin="0,24,0,0">
<TextBlock FontSize="18" FontWeight="DemiBold" Text="One.Control" />

<uc:Hyperlink Content="Documentation" NavigateUri="https://kleinpan.github.io/One/api/index.html" ToolTip="https://kleinpan.github.io/One/api/index.html" />

<uc:Hyperlink Content="GitHub" NavigateUri="https://github.com/KleinPan/One" ToolTip="https://github.com/KleinPan/One" />

<uc:Hyperlink Content="NuGet" NavigateUri="https://www.nuget.org/packages/One.Control/" ToolTip="https://www.nuget.org/packages/One.Control/" />
</StackPanel>

<StackPanel Grid.Row="4" Margin="0,24,0,0">
<TextBlock FontSize="18" FontWeight="DemiBold" Text="One.Toolbox" />
<uc:Hyperlink Content="Documentation" NavigateUri="https://github.com/KleinPan/One" ToolTip="https://github.com/KleinPan/One" />
<uc:Hyperlink Content="GitHub" NavigateUri="https://github.com/KleinPan/One" ToolTip="https://github.com/KleinPan/One" />
</StackPanel>

</Grid>
</ScrollViewer>
</Border>


<StatusBar Grid.Row="1">
<StatusBarItem>
<TextBlock Text="{Binding CurrentUseIP,StringFormat={}LocalIP: {0}}"></TextBlock>

</StatusBarItem>
</StatusBar>
</Grid>

</UserControl>
Loading

0 comments on commit efb4e11

Please sign in to comment.