Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
PrzemyslawKlys committed Sep 29, 2024
1 parent 62526a7 commit fefaf55
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
35 changes: 35 additions & 0 deletions Sources/DesktopManager.Example/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
using Spectre.Console;

namespace DesktopManager.Example;
/// <summary>
/// Provides helper methods for displaying properties and adding lines to the console.
/// </summary>
internal class Helpers {
/// <summary>
/// Displays the properties of an object in the console.
/// </summary>
/// <param name="analysisOf">The description of the object being analyzed.</param>
/// <param name="obj">The object whose properties are to be displayed.</param>
public static void ShowProperties(string analysisOf, object obj) {
Console.WriteLine("----");
Console.WriteLine($"Analysis of {analysisOf}:");
Expand All @@ -20,18 +28,39 @@ public static void ShowProperties(string analysisOf, object obj) {
}
}

/// <summary>
/// Adds a line to the console with a specified text and string value.
/// </summary>
/// <param name="text">The text to display.</param>
/// <param name="value">The string value to display.</param>
public static void AddLine(string text, string value) {
AnsiConsole.Write(new Rule($"[blue]{text}[/]: [yellow]{value}[/]"));
}

/// <summary>
/// Adds a line to the console with a specified text and integer value.
/// </summary>
/// <param name="text">The text to display.</param>
/// <param name="value">The integer value to display.</param>
public static void AddLine(string text, int value) {
AnsiConsole.Write(new Rule($"[blue]{text}[/]: [yellow]{value}[/]"));
}

/// <summary>
/// Adds a line to the console with a specified text and unsigned integer value.
/// </summary>
/// <param name="text">The text to display.</param>
/// <param name="value">The unsigned integer value to display.</param>
public static void AddLine(string text, uint value) {
AnsiConsole.Write(new Rule($"[blue]{text}[/]: [yellow]{value}[/]"));
}

/// <summary>
/// Displays the properties of an object or a collection of objects in a table format.
/// </summary>
/// <param name="analysisOf">The description of the object being analyzed.</param>
/// <param name="objs">The object or collection of objects whose properties are to be displayed.</param>
/// <param name="perProperty">Indicates whether to display properties per property.</param>
public static void ShowPropertiesTable(string analysisOf, object objs, bool perProperty = false) {
var table = new Table();
table.Border(TableBorder.Rounded);
Expand Down Expand Up @@ -59,6 +88,12 @@ public static void ShowPropertiesTable(string analysisOf, object objs, bool perP
AnsiConsole.Write(panel);
}

/// <summary>
/// Adds the properties of an object to a table.
/// </summary>
/// <param name="table">The table to which properties are added.</param>
/// <param name="prefix">The prefix for the property names.</param>
/// <param name="obj">The object whose properties are to be added.</param>
private static void AddPropertiesToTable(Table table, string prefix, object obj) {
if (obj == null) {
return;
Expand Down
23 changes: 16 additions & 7 deletions Sources/DesktopManager.Example/Program.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
using DesktopManager;

namespace DesktopManagerSample {
namespace DesktopManager.Example {
/// <summary>
/// The main class for the DesktopManager example application.
/// </summary>
class Program {
/// <summary>
/// The main entry point for the application.
/// </summary>
/// <param name="args">The command-line arguments.</param>
static void Main(string[] args) {

Monitors monitor = new Monitors();
var getMonitors = monitor.GetMonitors();

// Get all monitors
var getMonitors = monitor.GetMonitors();
Helpers.AddLine("Number of monitors", getMonitors.Count);
Helpers.ShowPropertiesTable("GetMonitors() ", getMonitors);

// Get connected monitors
var getMonitorsConnected = monitor.GetMonitorsConnected();
Helpers.AddLine("Number of monitors (connected):", getMonitorsConnected.Count);
Helpers.ShowPropertiesTable("GetMonitorsConnected() ", getMonitorsConnected);

// Get all display devices
var listDisplayDevices = monitor.DisplayDevicesAll();
Console.WriteLine("Count DisplayDevicesAll: " + listDisplayDevices.Count);
Helpers.ShowPropertiesTable("DisplayDevicesAll()", listDisplayDevices);

Console.WriteLine("======");

// Get connected display devices
var getDisplayDevices = monitor.DisplayDevicesConnected();
Console.WriteLine("Count DisplayDevicesConnected: " + getDisplayDevices.Count);
Helpers.ShowPropertiesTable("DisplayDevicesConnected()", getDisplayDevices);

Console.WriteLine("======");

// Get wallpaper position for the first monitor
Console.WriteLine("Wallpaper Position (only first monitor): " + monitor.GetWallpaperPosition());

// Iterate through connected monitors
foreach (var device in monitor.GetMonitorsConnected()) {
Console.WriteLine("3==================================");
Console.WriteLine("MonitorID: " + device.DeviceId);
Expand All @@ -41,7 +51,6 @@ static void Main(string[] args) {

var position1 = device.GetMonitorPosition();
Helpers.ShowPropertiesTable($"Position before move {device.DeviceId}", position1);

}

// Set monitor position
Expand All @@ -60,8 +69,8 @@ static void Main(string[] args) {
testPosition = monitor.GetMonitorPosition(@"\\?\DISPLAY#GSM5BBF#5&22b00b5d&0&UID4352#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}");
Helpers.ShowPropertiesTable("Position after move", testPosition);

// Set wallpaper for the first monitor
monitor.SetWallpaper(1, @"C:\Users\przemyslaw.klys\Downloads\CleanupMonster2.jpg");

}
}
}

0 comments on commit fefaf55

Please sign in to comment.