將寫死改成活讀

This commit is contained in:
DangHome 2023-07-03 01:51:09 +08:00
parent a48d7b8d56
commit a8fd8f3f46
27 changed files with 703 additions and 546 deletions

27
CMMModel/CMMModel.csproj Normal file
View File

@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<AssemblyName>CMM.Model</AssemblyName>
<RootNamespace>CMM.Model</RootNamespace>
<Product>ControlMyMonitorManagement</Product>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Company>Dang</Company>
<Copyright>Copyright © DangWang $([System.DateTime]::Now.ToString(yyyy))</Copyright>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<Major>1</Major>
<Minor>0</Minor>
<ProjectStartedDate>$([System.DateTime]::op_Subtraction($([System.DateTime]::get_Now().get_Date()),$([System.DateTime]::new(2017,9,17))).get_TotalDays())</ProjectStartedDate>
<DaysSinceProjectStarted>$([System.DateTime]::Now.ToString(Hmm))</DaysSinceProjectStarted>
<DateTimeSuffix>$([System.DateTime]::Now.ToString(yyyyMMdd))</DateTimeSuffix>
<VersionSuffix>$(Major).$(Minor).$(ProjectStartedDate).$(DaysSinceProjectStarted)</VersionSuffix>
<AssemblyVersion Condition=" '$(DateTimeSuffix)' == '' ">0.0.0.1</AssemblyVersion>
<AssemblyVersion Condition=" '$(DateTimeSuffix)' != '' ">$(VersionSuffix)</AssemblyVersion>
<Version Condition=" '$(DateTimeSuffix)' == '' ">0.0.0.1</Version>
<Version Condition=" '$(DateTimeSuffix)' != '' ">$(DateTimeSuffix)</Version>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,17 @@
using System.Text.Json.Serialization;
public class SMonitorModel
{
[JsonPropertyName("VCP Code")]
public string? VCPCode { get; set; }
[JsonPropertyName("VCP Code Name")]
public string? VCPCodeName { get; set; }
[JsonPropertyName("Read-Write")]
public string? ReadWrite { get; set; }
[JsonPropertyName("Current Value")]
public string? CurrentValue { get; set; }
[JsonPropertyName("Maximum Value")]
public string? MaximumValue { get; set; }
[JsonPropertyName("Possible Values")]
public string? PossibleValues { get; set; }
}

View File

@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>CMM.Service</AssemblyName>
<RootNamespace>CMM.Service</RootNamespace>
<Product>ControlMyMonitorManagement</Product>
<Nullable>enable</Nullable>
<Company>Dang</Company>
<Copyright>Copyright © DangWang $([System.DateTime]::Now.ToString(yyyy))</Copyright>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<Major>1</Major>
<Minor>0</Minor>
<ProjectStartedDate>$([System.DateTime]::op_Subtraction($([System.DateTime]::get_Now().get_Date()),$([System.DateTime]::new(2023,7,2))).get_TotalDays())</ProjectStartedDate>
<DaysSinceProjectStarted>$([System.DateTime]::Now.ToString(Hmm))</DaysSinceProjectStarted>
<DateTimeSuffix>$([System.DateTime]::Now.ToString(yyyyMMdd))</DateTimeSuffix>
<VersionSuffix>$(Major).$(Minor).$(ProjectStartedDate).$(DaysSinceProjectStarted)</VersionSuffix>
<AssemblyVersion Condition=" '$(DateTimeSuffix)' == '' ">0.0.0.1</AssemblyVersion>
<AssemblyVersion Condition=" '$(DateTimeSuffix)' != '' ">$(VersionSuffix)</AssemblyVersion>
<Version Condition=" '$(DateTimeSuffix)' == '' ">0.0.0.1</Version>
<Version Condition=" '$(DateTimeSuffix)' != '' ">$(DateTimeSuffix)</Version>
</PropertyGroup>
<ItemGroup>
<Folder Include="Interface\" />
<Folder Include="Service\" />
</ItemGroup>
</Project>

View File

@ -11,7 +11,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Language", "Language\Langua
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tester", "Tester\Tester.csproj", "{0D34DD73-3282-40EB-8F59-DF190944BF12}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DellMonitorControl", "DellMonitorControl\DellMonitorControl.csproj", "{64E96610-D431-40B9-A00B-55CE195B4B58}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DellMonitorControl", "DellMonitorControl\DellMonitorControl.csproj", "{64E96610-D431-40B9-A00B-55CE195B4B58}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CMMService", "CMMService\CMMService.csproj", "{FEA2B019-32BC-4704-939F-1CD26F373F55}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CMMModel", "CMMModel\CMMModel.csproj", "{88440737-DB6E-4ACA-B1BC-E40350153F96}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -39,6 +43,14 @@ Global
{64E96610-D431-40B9-A00B-55CE195B4B58}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64E96610-D431-40B9-A00B-55CE195B4B58}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64E96610-D431-40B9-A00B-55CE195B4B58}.Release|Any CPU.Build.0 = Release|Any CPU
{FEA2B019-32BC-4704-939F-1CD26F373F55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FEA2B019-32BC-4704-939F-1CD26F373F55}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FEA2B019-32BC-4704-939F-1CD26F373F55}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FEA2B019-32BC-4704-939F-1CD26F373F55}.Release|Any CPU.Build.0 = Release|Any CPU
{88440737-DB6E-4ACA-B1BC-E40350153F96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88440737-DB6E-4ACA-B1BC-E40350153F96}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88440737-DB6E-4ACA-B1BC-E40350153F96}.Release|Any CPU.ActiveCfg = Release|Any CPU
{88440737-DB6E-4ACA-B1BC-E40350153F96}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net7.0-windows</TargetFramework>
<RootNamespace>CMM.Management</RootNamespace>
<UseWPF>true</UseWPF>
<Copyright>Copyright © DangWang $([System.DateTime]::Now.ToString(yyyy))</Copyright>

View File

@ -7,21 +7,8 @@
mc:Ignorable="d">
<Grid>
<Border Background="{DynamicResource H3}" CornerRadius="10" MouseLeave="Border_MouseLeave"/>
<StackPanel>
<StackPanel Name="sp" Margin="10">
<StackPanel Orientation="Vertical" Margin="10,5,5,0">
<TextBlock Text="DELL U3223QE (Center)" Style="{StaticResource TitleStyle}" HorizontalAlignment="Left"/>
<Button Tag="BR974P3" Content="Sleep" Click="ToggleButton_Checked" Style="{StaticResource TextButtonStyle}"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="10,5,5,0">
<TextBlock Text="DELL U3223QE (Right)" Style="{StaticResource TitleStyle}" HorizontalAlignment="Left"/>
<Button Tag="CBBP3P3" Content="Sleep" Click="ToggleButton_Checked" Style="{StaticResource TextButtonStyle}"/>
</StackPanel>
<StackPanel Orientation="Vertical" Margin="10,5,5,0">
<TextBlock Text="DELL UP2716D (Left)" Style="{StaticResource TitleStyle}" HorizontalAlignment="Left"/>
<Button Tag="KV97067ICLCL" Content="Sleep" Click="ToggleButton_Checked" Style="{StaticResource TextButtonStyle}"/>
</StackPanel>
</StackPanel>
</Grid>
</UserControl>

View File

@ -1,7 +1,8 @@
using CMM.Library.Method;
using CMM.Library.ViewModel;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
namespace DellMonitorControl;
@ -16,25 +17,68 @@ public partial class ControlPanel : UserControl
InitializeComponent();
}
public async Task Init()
{
await CMMCommand.ScanMonitor();
var monitors = await CMMCommand.ReadMonitorsData();
foreach (var m in monitors)
{
var status = await CMMCommand.GetMonPowerStatus(m.SerialNumber);
var ctrl = CreatControl(m, status);
sp.Children.Add(ctrl);
}
}
private StackPanel CreatControl(XMonitor monitorModel, string powerStatus)
{
var _sp = new StackPanel();
_sp.Orientation = Orientation.Vertical;
_sp.Margin = new Thickness(10, 5, 5, 0);
var tb = new TextBlock
{
Text = monitorModel.MonitorName,
HorizontalAlignment = HorizontalAlignment.Left,
Style = (Style)FindResource("LableStyle")
};
var btn = new Button
{
Tag = monitorModel.SerialNumber,
Content = powerStatus,
Style = (Style)FindResource("TextButtonStyle")
};
btn.Click += async (s, e) => await ToggleButton_Checked(s, e);
_sp.Children.Add(tb);
_sp.Children.Add(btn);
return _sp;
}
private void Border_MouseLeave(object sender, MouseEventArgs e)
{
}
private async void ToggleButton_Checked(object sender, RoutedEventArgs e)
private async Task ToggleButton_Checked(object sender, RoutedEventArgs e)
{
var toggle = sender as Button;
var tag = toggle?.Tag.ToString();
var content = toggle?.Content as string;
var btn = sender as Button;
var tag = btn?.Tag.ToString();
var content = btn?.Content as string;
if (content == "Sleep")
{
await CMMCommand.Sleep(tag);
toggle!.Content = "PowerOn";
await CMMCommand.PowerOn(tag);
}
else
{
await CMMCommand.PowerOn(tag);
toggle!.Content = "Sleep";
}
await CMMCommand.Sleep(tag);
}
await Task.Delay(1000);
btn!.Content = await CMMCommand.GetMonPowerStatus(tag);
}
}

View File

@ -2,12 +2,27 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<AssemblyName>DellMonitorControl</AssemblyName>
<RootNamespace>DellMonitorControl</RootNamespace>
<Product>DellMonitorControl</Product>
<Product>ControlMyMonitorManagement</Product>
<UseWPF>true</UseWPF>
<Company>Dang</Company>
<Copyright>Copyright © DangWang $([System.DateTime]::Now.ToString(yyyy))</Copyright>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<Major>1</Major>
<Minor>0</Minor>
<ProjectStartedDate>$([System.DateTime]::op_Subtraction($([System.DateTime]::get_Now().get_Date()),$([System.DateTime]::new(2023,7,2))).get_TotalDays())</ProjectStartedDate>
<DaysSinceProjectStarted>$([System.DateTime]::Now.ToString(Hmm))</DaysSinceProjectStarted>
<DateTimeSuffix>$([System.DateTime]::Now.ToString(yyyyMMdd))</DateTimeSuffix>
<VersionSuffix>$(Major).$(Minor).$(ProjectStartedDate).$(DaysSinceProjectStarted)</VersionSuffix>
<AssemblyVersion Condition=" '$(DateTimeSuffix)' == '' ">0.0.0.1</AssemblyVersion>
<AssemblyVersion Condition=" '$(DateTimeSuffix)' != '' ">$(VersionSuffix)</AssemblyVersion>
<Version Condition=" '$(DateTimeSuffix)' == '' ">0.0.0.1</Version>
<Version Condition=" '$(DateTimeSuffix)' != '' ">$(DateTimeSuffix)</Version>
</PropertyGroup>
<ItemGroup>
@ -20,6 +35,12 @@
<ItemGroup>
<PackageReference Include="Hardcodet.Wpf.TaskbarNotification.Net6" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
</ItemGroup>
<ItemGroup>

View File

@ -6,15 +6,16 @@
xmlns:tb="clr-namespace:Hardcodet.Wpf.TaskbarNotification;assembly=Hardcodet.Wpf.TaskbarNotification.Net6"
xmlns:local="clr-namespace:DellMonitorControl"
mc:Ignorable="d"
Loaded="Window_Loaded"
Title="MainWindow" Height="450" Width="800">
<Grid>
<tb:TaskbarIcon x:Name="taskbar"
IconSource="/DellLogo.ico"
ToolTipText="調整效能"
ToolTipText="螢幕開關"
PopupActivation="LeftOrDoubleClick">
<tb:TaskbarIcon.TrayPopup>
<local:ControlPanel/>
<local:ControlPanel x:Name="comtrolPanel"/>
</tb:TaskbarIcon.TrayPopup>
</tb:TaskbarIcon>
</Grid>

View File

@ -10,6 +10,11 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
}
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
this.Hide();
await comtrolPanel.Init();
}
}

View File

@ -15,7 +15,6 @@
</Style.Triggers>
</Style>
<Style x:Key="TextBorderStyle" TargetType="{x:Type Border}">
<Setter Property="Background" Value="{StaticResource F3}"/>
<Setter Property="BorderBrush" Value="#C1272C"/>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net7.0-windows</TargetFramework>
<RootNamespace>CMM.Language</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>

View File

@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
namespace CMM.Library.Base
{
namespace CMM.Library.Base;
/// <summary>
/// Represents a dynamic data collection that provides notifications when items get added, removed, or when the whole list is refreshed.
/// </summary>
@ -67,4 +65,3 @@ namespace CMM.Library.Base
public ObservableRangeCollection(IEnumerable<T> collection)
: base(collection) { }
}
}

View File

@ -1,8 +1,8 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace CMM.Library.Base
{
namespace CMM.Library.Base;
public class PropertyBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
@ -28,4 +28,3 @@ namespace CMM.Library.Base
this.OnPropertyChanged(propertyName);
}
}
}

View File

@ -2,18 +2,13 @@
using CMM.Library.Base;
using CMM.Library.Helpers;
using CMM.Library.Method;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using System.Windows;
namespace CMM.Library.Config
{
namespace CMM.Library.Config;
public class XConfig : PropertyBase
{
[JsonIgnore]
@ -73,4 +68,3 @@ namespace CMM.Library.Config
}
}
}
}

View File

@ -1,12 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace CMM.Library.Helpers;
namespace CMM.Library.Helpers
{
internal class ConsoleHelper
{
const string cmdFileName = "cmd.exe";
@ -24,6 +19,20 @@ namespace CMM.Library.Helpers
}
};
public static async Task<string> ExecuteCommand(string command)
{
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = command;
p.Start();
var output = await p.StandardOutput.ReadToEndAsync();
await p.WaitForExitAsync();
return output;
}
public static async Task<string> CmdCommandAsync(params string[] cmds) =>
await CommandAsync(cmdFileName, cmds);
@ -68,4 +77,3 @@ namespace CMM.Library.Helpers
return result;
}
}
}

View File

@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.IO;
using System.Reflection;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Threading.Tasks;
namespace CMM.Library.Helpers
{
namespace CMM.Library.Helpers;
static class JsonSerializerExtensions
{
public static JsonSerializerOptions defaultSettings = new JsonSerializerOptions()
@ -21,7 +17,7 @@ namespace CMM.Library.Helpers
};
}
internal static class JsonHelper
public static class JsonHelper
{
/// <summary>
/// 複製整個obj全部結構
@ -128,4 +124,3 @@ namespace CMM.Library.Helpers
catch (Exception) { throw; }
}
}
}

View File

@ -1,8 +1,7 @@
using System;
using System.Security.Principal;
using System.Security.Principal;
namespace CMM.Library.Helpers;
namespace CMM.Library.Helpers
{
public class UAC
{
public static void Check()
@ -15,4 +14,3 @@ namespace CMM.Library.Helpers
}
}
}

View File

@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net7.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>CMM.Library</RootNamespace>
<AssemblyName>CMM.Library</AssemblyName>
<Product>ControlMyMonitorManagement</Product>
<UseWPF>true</UseWPF>
<Company>Dang</Company>
@ -34,7 +35,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CMMModel\CMMModel.csproj" />
<ProjectReference Include="..\Language\Language.csproj" />
<ProjectReference Include="..\Tester\Tester.csproj" />
</ItemGroup>
</Project>

View File

@ -1,12 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace CMM.Library.Method;
namespace CMM.Library.Method
{
public static class AssemblyData
{
/// <summary>
@ -45,4 +40,3 @@ namespace CMM.Library.Method
$"{fvi.FilePrivatePart}";
}
}
}

View File

@ -2,6 +2,8 @@
using CMM.Library.Helpers;
using CMM.Library.ViewModel;
using System.IO;
using System.Net.NetworkInformation;
using System.Threading;
namespace CMM.Library.Method;
@ -13,7 +15,6 @@ public static class CMMCommand
static readonly string CMMTmpFolder = Path.Combine(Path.GetTempPath(), $"CMM");
static readonly string CMMexe = Path.Combine(CMMTmpFolder, "ControlMyMonitor.exe");
static readonly string CMMsMonitors = Path.Combine(CMMTmpFolder, "smonitors.tmp");
static readonly string CMMcfg = Path.Combine(CMMTmpFolder, "ControlMyMonitor.cfg");
public static async Task ScanMonitor()
{
@ -21,80 +22,92 @@ public static class CMMCommand
await ConsoleHelper.CmdCommandAsync($"{CMMexe} /smonitors {CMMsMonitors}");
}
public static async Task PowerOn(string MonitorSn)
public static Task PowerOn(string monitorSN)
{
await ConsoleHelper.CmdCommandAsync($"{CMMexe} /SetValue {MonitorSn} D6 1");
return ConsoleHelper.CmdCommandAsync($"{CMMexe} /SetValue {monitorSN} D6 1");
}
public static async Task Sleep(string MonitorSn)
public static Task Sleep(string monitorSN)
{
await ConsoleHelper.CmdCommandAsync($"{CMMexe} /SetValue {MonitorSn} D6 4");
return ConsoleHelper.CmdCommandAsync($"{CMMexe} /SetValue {monitorSN} D6 4");
}
public static async Task ScanMonitorInterfaces(IEnumerable<XMonitor> monitors)
private static async Task<string> GetMonitorValue(string monitorSN)
{
var taskList = new List<Task>();
foreach (var mon in monitors)
{
taskList.Add(Task.Run(async () => await
ScanMonitorInterfaces($"{CMMTmpFolder}\\{mon.SerialNumber}.tmp", mon)));
var cmdFileName = Path.Combine(CMMTmpFolder, $"{Guid.NewGuid()}.bat");
var cmd = $"{CMMexe} /GetValue {monitorSN} D6\r\n" +
$"echo %errorlevel%";
File.WriteAllText(cmdFileName, cmd);
var values = await ConsoleHelper.ExecuteCommand(cmdFileName);
File.Delete(cmdFileName);
return values.Split("\r\n", StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
}
await Task.WhenAll(taskList.ToArray());
public static async Task<string> GetMonPowerStatus(string monitorSN)
{
var status = await GetMonitorValue(monitorSN);
return status switch
{
"1" => "PowerOn",
"4" => "Sleep",
"5" => "PowerOff",
_ => string.Empty
};
}
static async Task ScanMonitorInterfaces(string savePath, XMonitor mon)
public static async Task ScanMonitorStatus(IEnumerable<XMonitor> monitors)
{
await ConsoleHelper.CmdCommandAsync($"{CMMexe} /scomma {savePath} {mon.MonitorID}");
await mon.ReadMonitorStatus(savePath);
var taskList = monitors.Select(x =>
{
return ScanMonitorStatus($"{CMMTmpFolder}\\{x.SerialNumber}.tmp", x);
});
await Task.WhenAll(taskList);
}
static async Task ScanMonitorStatus(string savePath, XMonitor mon)
{
await ConsoleHelper.CmdCommandAsync($"{CMMexe} /sjson {savePath} {mon.MonitorID}");
var monitorModel = JsonHelper.JsonFormFile<IEnumerable<SMonitorModel>>(savePath);
var status = monitorModel.ReadMonitorStatus();
mon.Status = new ObservableRangeCollection<XMonitorStatus>(status);
}
/// <summary>
/// 取得螢幕狀態
/// </summary>
public static async Task ReadMonitorStatus(this XMonitor @this, string filePath)
public static IEnumerable<XMonitorStatus> ReadMonitorStatus(this IEnumerable<SMonitorModel> monitorModel)
{
var statusColle = new ObservableRangeCollection<XMonitorStatus>();
if (!File.Exists(filePath)) return;
foreach (var line in await File.ReadAllLinesAsync(filePath))
foreach (var m in monitorModel)
{
var sp = line.Split(",");
if (sp.Length < 6) continue;
statusColle.Add(new XMonitorStatus
yield return new XMonitorStatus
{
VCP_Code = StrTrim(sp[0]),
VCPCodeName = StrTrim(sp[1]),
Read_Write = StrTrim(sp[2]),
CurrentValue = TryGetInt(sp[3]),
MaximumValue = TryGetInt(sp[4]),
PossibleValues = TryGetArrStr(sp),
});
VCP_Code = m.VCPCode,
VCPCodeName = m.VCPCodeName,
Read_Write = m.ReadWrite,
CurrentValue = TryGetInt(m.CurrentValue),
MaximumValue = TryGetInt(m.MaximumValue),
PossibleValues = TryGetArrStr(m.PossibleValues),
};
}
@this.Status = statusColle;
string StrTrim(string str)
IEnumerable<int> TryGetArrStr(string str)
{
if (string.IsNullOrEmpty(str)) return null;
return str;
}
string TryGetArrStr(string[] strArr)
{
if (strArr.Length < 7) return null;
var outStr = string.Join(",", strArr[5..]);
outStr = outStr.Substring(1, outStr.Length - 2);
return outStr;
return str.Split(",", StringSplitOptions.RemoveEmptyEntries)
.Select(x => TryGetInt(x))
.Where(x => x != null)
.Select(x => (int)x)
.ToList();
}
int? TryGetInt(string str)
{
if (int.TryParse(str, out var value)) return value;
return null;
return int.TryParse(str, out var value)
? value
: null;
}
}

View File

@ -1,13 +1,8 @@
using CMM.Library.Base;
using CMM.Library.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CMM.Library.Method
{
namespace CMM.Library.Method;
public class CMMMgr : PropertyBase
{
public ObservableRangeCollection<XMonitor> Monitors
@ -23,7 +18,6 @@ namespace CMM.Library.Method
var monColle = new ObservableRangeCollection<XMonitor>();
monColle.AddRange(await CMMCommand.ReadMonitorsData());
Monitors = monColle;
await CMMCommand.ScanMonitorInterfaces(monColle);
}
await CMMCommand.ScanMonitorStatus(monColle);
}
}

View File

@ -1,12 +1,7 @@
using CMM.Library.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CMM.Library.ViewModel
{
namespace CMM.Library.ViewModel;
public class XMonitor : PropertyBase
{
/// <summary>
@ -69,4 +64,3 @@ namespace CMM.Library.ViewModel
}
ObservableRangeCollection<XMonitorStatus> _Status = new();
}
}

View File

@ -1,9 +1,4 @@
using CMM.Library.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CMM.Library.ViewModel
{
@ -44,11 +39,11 @@ namespace CMM.Library.ViewModel
}
int? _MaximumValue;
public string PossibleValues
public IEnumerable<int> PossibleValues
{
get => _PossibleValues;
set { SetProperty(ref _PossibleValues, value); }
}
string _PossibleValues;
IEnumerable<int> _PossibleValues;
}
}

38
Tester/CommnadTest.cs Normal file
View File

@ -0,0 +1,38 @@
using CMM.Library.Base;
using CMM.Library.Helpers;
using CMM.Library.Method;
using CMM.Library.ViewModel;
namespace CMM.Tester;
public class CommnadTest
{
[SetUp]
public void Setup()
{
}
[Test]
public async Task Test1()
{
await CMMCommand.ScanMonitor();
var monColle = new ObservableRangeCollection<XMonitor>();
monColle.AddRange(await CMMCommand.ReadMonitorsData());
await CMMCommand.ScanMonitorStatus(monColle);
}
[Test]
public void JsonParserTest()
{
var path = @"C:\Users\shoop\AppData\Local\Temp\CMM\KV97067ICLCL.tmp";
var monitorModel = JsonHelper.JsonFormFile<IEnumerable<SMonitorModel>>(path);
}
[Test]
public async Task GetMonPowerStatus()
{
var status = await CMMCommand.GetMonPowerStatus("CBBP3P3");
}
}

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>CMM.Tester</RootNamespace>
<Product>ControlMyMonitorManagement</Product>
@ -18,4 +18,12 @@
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CMMModel\CMMModel.csproj" />
<ProjectReference Include="..\CMMService\CMMService.csproj" />
<ProjectReference Include="..\Language\Language.csproj" />
<ProjectReference Include="..\Library\Library.csproj" />
</ItemGroup>
</Project>

View File

@ -1,16 +0,0 @@
namespace CMM.Tester
{
public class Tests
{
[SetUp]
public void Setup()
{
}
[Test]
public void Test1()
{
Assert.Pass();
}
}
}