Reporting project added

This commit is contained in:
s_falahati 2018-09-11 13:31:44 +04:30
parent 4c3301f364
commit 477b04e5ed
7 changed files with 468 additions and 1 deletions

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
</configuration>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<Costura />
</Weavers>

View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{76DF2BCF-911B-4820-B63E-8F3468DB5E79}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>HeliosDisplayManagement.Reporting</RootNamespace>
<AssemblyName>HeliosDisplayManagement.Reporting</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Costura, Version=3.1.0.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
<HintPath>..\packages\Costura.Fody.3.1.0\lib\net46\Costura.dll</HintPath>
</Reference>
<Reference Include="NvAPIWrapper, Version=0.6.0.3, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NvAPIWrapper.Net.0.6.0.4\lib\net45\NvAPIWrapper.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="WindowsDisplayAPI, Version=1.1.0.1, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\WindowsDisplayAPI.1.1.0.2\lib\net45\WindowsDisplayAPI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HeliosDisplayManagement.Shared\HeliosDisplayManagement.Shared.csproj">
<Project>{1cacda43-01c7-4cd4-bf6e-9421a29510fc}</Project>
<Name>HeliosDisplayManagement.Shared</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="FodyWeavers.xml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Fody.3.1.3\build\Fody.targets" Condition="Exists('..\packages\Fody.3.1.3\build\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Fody.3.1.3\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.3.1.3\build\Fody.targets'))" />
<Error Condition="!Exists('..\packages\Costura.Fody.3.1.0\build\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.3.1.0\build\Costura.Fody.targets'))" />
</Target>
<Import Project="..\packages\Costura.Fody.3.1.0\build\Costura.Fody.targets" Condition="Exists('..\packages\Costura.Fody.3.1.0\build\Costura.Fody.targets')" />
</Project>

View File

@ -0,0 +1,327 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using WindowsDisplayAPI;
using WindowsDisplayAPI.DisplayConfig;
using HeliosDisplayManagement.Shared;
using NvAPIWrapper.GPU;
using NvAPIWrapper.Mosaic;
namespace HeliosDisplayManagement.Reporting
{
internal class Program
{
private static StreamWriter _writer;
private static void Dump<T>(
IEnumerable<T> items,
string title,
Tuple<Func<T, object>, string>[] actions = null,
int deepIn = 0)
{
Console.WriteLine(title);
_writer.WriteLine(title + new string('=', Console.BufferWidth - title.Length));
var totalTime = TimeSpan.Zero;
var stopWatch = new Stopwatch();
stopWatch.Start();
foreach (var item in items)
{
var actionResults = actions?.Select(tuple =>
new Tuple<string, object>(tuple.Item2, tuple.Item1.Invoke(item))).ToArray();
stopWatch.Stop();
WriteObject(item, 0, stopWatch.Elapsed, actionResults, deepIn);
totalTime += stopWatch.Elapsed;
stopWatch.Reset();
stopWatch.Start();
}
stopWatch.Stop();
totalTime += stopWatch.Elapsed;
Console.Write(@"-- Elapsed: {0}", totalTime);
_writer.WriteLine(@"-- Total Elapsed: {0}", totalTime);
Console.WriteLine();
_writer.WriteLine();
}
private static void Main(string[] args)
{
_writer = new StreamWriter(new FileStream(
string.Format("HeliosDisplayManagement.Reporting.{0}.log", Process.GetCurrentProcess().Id),
FileMode.CreateNew));
try
{
Dump(DisplayAdapter.GetDisplayAdapters(), "WindowsDisplayAPI.DisplayAdapter.GetDisplayAdapters()");
}
catch (Exception e)
{
WriteException(e);
}
try
{
Dump(Display.GetDisplays(), "WindowsDisplayAPI.Display.GetDisplays()", new[]
{
new Tuple<Func<Display, object>, string>(display => display.GetPossibleSettings(),
"GetPossibleSettings()")
});
}
catch (Exception e)
{
WriteException(e);
}
try
{
Dump(UnAttachedDisplay.GetUnAttachedDisplays(),
"WindowsDisplayAPI.UnAttachedDisplay.GetUnAttachedDisplays()");
}
catch (Exception e)
{
WriteException(e);
}
try
{
Dump(PathDisplayAdapter.GetAdapters(), "WindowsDisplayAPI.DisplayConfig.PathDisplayAdapter.GetAdapters()",
new[]
{
new Tuple<Func<PathDisplayAdapter, object>, string>(adapter => adapter.ToDisplayAdapter(),
"ToDisplayAdapter()")
});
}
catch (Exception e)
{
WriteException(e);
}
try
{
Dump(PathDisplaySource.GetDisplaySources(),
"WindowsDisplayAPI.DisplayConfig.PathDisplaySource.GetDisplaySources()", new[]
{
new Tuple<Func<PathDisplaySource, object>, string>(source => source.ToDisplayDevices(),
"ToDisplayDevices()")
});
}
catch (Exception e)
{
WriteException(e);
}
try
{
Dump(PathDisplayTarget.GetDisplayTargets(),
"WindowsDisplayAPI.DisplayConfig.PathDisplayTarget.GetDisplayTargets()", new[]
{
new Tuple<Func<PathDisplayTarget, object>, string>(target => target.ToDisplayDevice(),
"ToDisplayDevice()")
});
}
catch (Exception e)
{
WriteException(e);
}
try
{
if (PathInfo.IsSupported)
{
Dump(PathInfo.GetActivePaths(), "WindowsDisplayAPI.DisplayConfig.PathInfo.GetActivePaths()", null, 2);
}
}
catch (Exception e)
{
WriteException(e);
}
try
{
Dump(LogicalGPU.GetLogicalGPUs(), "NvAPIWrapper.GPU.LogicalGPU.GetLogicalGPUs()", null, 1);
}
catch (Exception e)
{
WriteException(e);
}
try
{
Dump(PhysicalGPU.GetPhysicalGPUs(), "NvAPIWrapper.GPU.PhysicalGPU.GetPhysicalGPUs()");
}
catch (Exception e)
{
WriteException(e);
}
try
{
Dump(NvAPIWrapper.Display.Display.GetDisplays(), "NvAPIWrapper.Display.Display.GetDisplays()", new[]
{
new Tuple<Func<NvAPIWrapper.Display.Display, object>, string>(display => display.GetSupportedViews(),
"GetSupportedViews()")
});
}
catch (Exception e)
{
WriteException(e);
}
try
{
Dump(NvAPIWrapper.Display.UnAttachedDisplay.GetUnAttachedDisplays(),
"NvAPIWrapper.Display.UnAttachedDisplay.GetUnAttachedDisplays()");
}
catch (Exception e)
{
WriteException(e);
}
try
{
Dump(NvAPIWrapper.Display.PathInfo.GetDisplaysConfig(), "NvAPIWrapper.Display.PathInfo.GetDisplaysConfig()",
null, 3);
}
catch (Exception e)
{
WriteException(e);
}
try
{
Dump(GridTopology.GetGridTopologies(), "NvAPIWrapper.Mosaic.GridTopology.GetGridTopologies()", null, 3);
}
catch (Exception e)
{
WriteException(e);
}
try
{
Dump(Profile.GetAllProfiles(), "HeliosDisplayManagement.Shared.Profile.GetAllProfiles()", null, 99);
}
catch (Exception e)
{
WriteException(e);
}
_writer.Flush();
_writer.Close();
_writer.Dispose();
Console.WriteLine(@"Done, press enter to exit.");
Console.ReadLine();
}
private static void WriteException(Exception ex)
{
_writer.WriteLine("{0} - Error: {1}", ex.GetType().Name, ex.Message);
}
private static void WriteObject(
object obj,
int padding = 0,
TimeSpan elapsed = default(TimeSpan),
Tuple<string, object>[] extraProperties = null,
int deepIn = 0)
{
try
{
if (padding == 0)
{
if (!elapsed.Equals(TimeSpan.Zero))
{
var elapsedFormated = string.Format("_{0}_", elapsed);
_writer.WriteLine(elapsedFormated +
new string('_', Console.BufferWidth - elapsedFormated.Length));
}
else
{
_writer.WriteLine(new string('_', Console.BufferWidth));
}
_writer.WriteLine("({0}) {{", obj.GetType().Name);
}
if (obj.GetType().IsValueType || obj is string)
{
_writer.WriteLine(new string(' ', padding * 3 + 2) + obj);
}
else if (obj is IEnumerable)
{
var i = 0;
foreach (var arrayItem in (IEnumerable) obj)
{
_writer.WriteLine(new string(' ', padding * 3 + 2) + "[{0}]: ({1}) {{", i, arrayItem?.GetType().Name);
WriteObject(arrayItem, padding + 1, default(TimeSpan), null, deepIn - 1);
_writer.WriteLine(new string(' ', padding * 3 + 2) + "},");
i++;
}
}
else
{
foreach (var propertyInfo in obj.GetType().GetProperties().OrderBy(info => info.Name))
{
if (propertyInfo.CanRead)
{
object value;
try
{
value = propertyInfo.GetValue(obj);
}
catch (TargetInvocationException ex)
{
value = ex.InnerException?.GetType().ToString();
}
catch (Exception ex)
{
value = ex.GetType().ToString();
}
if (deepIn > 0 &&
value != null &&
!value.GetType().IsValueType &&
value.GetType() != typeof(string))
{
_writer.WriteLine(new string(' ', padding * 3 + 2) + "{0}: ({1}) {{", propertyInfo.Name, propertyInfo.PropertyType.Name);
WriteObject(value, padding + 1, default(TimeSpan), null, deepIn - 1);
_writer.WriteLine(new string(' ', padding * 3 + 2) + "},");
}
else
{
_writer.WriteLine(
$"{new string(' ', padding * 3 + 2)}{propertyInfo.Name}: {value ?? "[NULL]"},");
}
}
}
}
if (extraProperties != null)
{
foreach (var extraProperty in extraProperties)
{
_writer.WriteLine(new string(' ', padding * 3 + 2) + "{0}: ({1}) {{", extraProperty.Item1, extraProperty.Item2?.GetType().Name);
WriteObject(extraProperty.Item2, padding + 1, default(TimeSpan), null, deepIn);
_writer.WriteLine(new string(' ', padding * 3 + 2) + "},");
}
}
if (padding == 0)
{
_writer.WriteLine("};");
_writer.WriteLine(new string('_', Console.BufferWidth));
}
}
catch (Exception ex)
{
WriteException(ex);
}
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("HeliosDisplayManagement.Reporting")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HeliosDisplayManagement.Reporting")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("76df2bcf-911b-4820-b63e-8f3468db5e79")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Costura.Fody" version="3.1.0" targetFramework="net462" />
<package id="Fody" version="3.1.3" targetFramework="net462" developmentDependency="true" />
<package id="NvAPIWrapper.Net" version="0.6.0.4" targetFramework="net462" />
<package id="WindowsDisplayAPI" version="1.1.0.2" targetFramework="net462" />
</packages>

View File

@ -1,6 +1,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2003
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeliosDisplayManagement", "HeliosDisplayManagement\HeliosDisplayManagement.csproj", "{608D941A-B431-400C-A91D-C6F971C29577}"
EndProject
@ -14,6 +16,7 @@ Project("{E729F059-12D4-455F-A2A4-FDA8DD25E08A}") = "HeliosDisplayManagement.Set
{1CACDA43-01C7-4CD4-BF6E-9421A29510FC} = {1CACDA43-01C7-4CD4-BF6E-9421A29510FC}
{55D4FF65-EDC7-48EF-933E-B6E7F3809B68} = {55D4FF65-EDC7-48EF-933E-B6E7F3809B68}
EndProjectSection
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeliosDisplayManagement.Reporting", "HeliosDisplayManagement.Reporting\HeliosDisplayManagement.Reporting.csproj", "{76DF2BCF-911B-4820-B63E-8F3468DB5E79}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -35,9 +38,15 @@ Global
{1CACDA43-01C7-4CD4-BF6E-9421A29510FC}.Release|AnyCPU.Build.0 = Release|Any CPU
{8B2508A9-8167-46D0-83C7-D24BE7407910}.Debug|AnyCPU.ActiveCfg = x64 Release
{8B2508A9-8167-46D0-83C7-D24BE7407910}.Release|AnyCPU.ActiveCfg = x64 Release
{8B2508A9-8167-46D0-83C7-D24BE7407910}.Release|AnyCPU.Build.0 = x64 Release
{76DF2BCF-911B-4820-B63E-8F3468DB5E79}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU
{76DF2BCF-911B-4820-B63E-8F3468DB5E79}.Debug|AnyCPU.Build.0 = Debug|Any CPU
{76DF2BCF-911B-4820-B63E-8F3468DB5E79}.Release|AnyCPU.ActiveCfg = Release|Any CPU
{76DF2BCF-911B-4820-B63E-8F3468DB5E79}.Release|AnyCPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2F7B8012-31EA-46A2-9B55-7BE90D969F61}
EndGlobalSection
EndGlobal