Compare commits
103 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e59d6e3f39 | |||
| 0499ac5bb9 | |||
| 15c77a14ec | |||
| 4e8ce63ed9 | |||
| 6575eb3139 | |||
| 807fa0ee54 | |||
| f6d8b2c988 | |||
| 635aa484a7 | |||
| 9206ede6eb | |||
| 1881974311 | |||
| 050ad1ad9c | |||
| d0fc1235a9 | |||
| 44d6531bda | |||
| ef30383abb | |||
| 4a3ae05f39 | |||
| 3ac5b5f081 | |||
| fc5b81014b | |||
| 827f68b0c6 | |||
| 1a11a67248 | |||
| 95a5e83b73 | |||
| 070ce10fae | |||
| 7ceabb226b | |||
| a3e4ca9ea1 | |||
| 2de11e8560 | |||
| f9273193d2 | |||
| 16ce7cefb4 | |||
| b8c77aba7b | |||
| 729ae1604e | |||
| 72c0450d40 | |||
| 92e5ce837a | |||
| fb898e4bde | |||
| 2e8f8c6c8d | |||
| 98ced01b0f | |||
| ed27887c08 | |||
| 88e70cee26 | |||
| f5c6fcd75f | |||
| e24be59878 | |||
| 8e957dc054 | |||
| b9902f4847 | |||
| a4fd7eb05c | |||
| 873d32518c | |||
| 6d80a5d553 | |||
| 2fe83f1202 | |||
| 640bed074a | |||
| 8deb5a449f | |||
| 67207b15dd | |||
| ea5a8a8f8d | |||
| 2059053a03 | |||
| 81210f77b1 | |||
| 5244b2f3fb | |||
| 62ef1b0613 | |||
| a7053d8104 | |||
| 0af7d299c9 | |||
| 5cd2983fe4 | |||
| e1d859ea48 | |||
| e3cbfca06a | |||
| 72a4f58bb7 | |||
| 7634feebb9 | |||
| db7df7123f | |||
| 523ec9b7f5 | |||
| 47e26eda7d | |||
| eeb58c27bd | |||
| c38aa902fe | |||
| 73e7fe89f1 | |||
| 7660b9ce88 | |||
| 089500fcb4 | |||
| 0385c04136 | |||
| 7b97e3249e | |||
| 7379b52334 | |||
| c3c9bb88ab | |||
| 87c5878ec9 | |||
| 64d7c9531b | |||
| 629ad33767 | |||
| f32b4e4f03 | |||
| e43ef3dca5 | |||
| 0457466bd0 | |||
| 474757af5e | |||
| 4da5466de9 | |||
| 2f8f4492ea | |||
| 2fb562de19 | |||
| 9bc7a542b4 | |||
| 923d889a8f | |||
| d7116687f5 | |||
| 71ab81e11a | |||
| 1a46040210 | |||
| d3e4e53c1b | |||
| 437366fd67 | |||
| 3531b72793 | |||
| 856396a031 | |||
| 11afa74e58 | |||
| 8847f3f9b7 | |||
| 1f1cbfd1e5 | |||
| c5b76ee077 | |||
| e72b3ca600 | |||
| 14353a0ef8 | |||
| eac18b2e78 | |||
| b49c70a039 | |||
| 4c90dc1661 | |||
| 8b918a57de | |||
| dcb9c65267 | |||
| 2a8e876c60 | |||
| 4958b8404a | |||
| a4d45e03e0 |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,8 +1,8 @@
|
||||
*.exe
|
||||
*.dll
|
||||
*.pdb
|
||||
*/bin/*
|
||||
*/obj/*
|
||||
*.csproj.user
|
||||
**/bin/**
|
||||
**/obj/**
|
||||
*.suo
|
||||
.vs
|
||||
*.user
|
||||
|
||||
8
.gitmodules
vendored
Normal file
8
.gitmodules
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
[submodule "VAR.Json"]
|
||||
path = VAR.Json
|
||||
url = https://datacube.duckdns.org/git/VAR/VAR.Json.git
|
||||
branch = master
|
||||
[submodule "VAR.HttpServer"]
|
||||
path = VAR.HttpServer
|
||||
url = https://datacube.duckdns.org/git/VAR/VAR.HttpServer.git
|
||||
branch = master
|
||||
13
.idea/.idea.VAR.Toolbox/.idea/.gitignore
generated
vendored
Normal file
13
.idea/.idea.VAR.Toolbox/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/contentModel.xml
|
||||
/.idea.VAR.Json.iml
|
||||
/modules.xml
|
||||
/projectSettingsUpdater.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
3
.idea/.idea.VAR.Toolbox/.idea/dictionaries/VAR.xml
generated
Normal file
3
.idea/.idea.VAR.Toolbox/.idea/dictionaries/VAR.xml
generated
Normal file
@@ -0,0 +1,3 @@
|
||||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="VAR" />
|
||||
</component>
|
||||
4
.idea/.idea.VAR.Toolbox/.idea/encodings.xml
generated
Normal file
4
.idea/.idea.VAR.Toolbox/.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||
</project>
|
||||
8
.idea/.idea.VAR.Toolbox/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.VAR.Toolbox/.idea/indexLayout.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
||||
8
.idea/.idea.VAR.Toolbox/.idea/vcs.xml
generated
Normal file
8
.idea/.idea.VAR.Toolbox/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/VAR.HttpServer" vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/VAR.Json" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
1
VAR.HttpServer
Submodule
1
VAR.HttpServer
Submodule
Submodule VAR.HttpServer added at f7c1a581e7
1
VAR.Json
Submodule
1
VAR.Json
Submodule
Submodule VAR.Json added at 0332af453a
39
VAR.Toolbox.TestPlugin/FrmTestPlugin.Designer.cs
generated
Normal file
39
VAR.Toolbox.TestPlugin/FrmTestPlugin.Designer.cs
generated
Normal file
@@ -0,0 +1,39 @@
|
||||
namespace VAR.Toolbox.TestPlugin
|
||||
{
|
||||
partial class FrmTestPlugin
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "FrmTestPlugin";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
17
VAR.Toolbox.TestPlugin/FrmTestPlugin.cs
Normal file
17
VAR.Toolbox.TestPlugin/FrmTestPlugin.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Windows.Forms;
|
||||
using VAR.Toolbox.UI;
|
||||
|
||||
namespace VAR.Toolbox.TestPlugin
|
||||
{
|
||||
public partial class FrmTestPlugin : Form, IToolForm
|
||||
{
|
||||
public FrmTestPlugin()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public string ToolName => "Test";
|
||||
|
||||
public bool HasIcon => false;
|
||||
}
|
||||
}
|
||||
14
VAR.Toolbox.TestPlugin/Notes.md
Normal file
14
VAR.Toolbox.TestPlugin/Notes.md
Normal file
@@ -0,0 +1,14 @@
|
||||
## Preparation
|
||||
|
||||
* Build as class library.
|
||||
* Add reference to ```VAR.Toolbox``` for interface declarations and utilities.
|
||||
* Use the interfaces to extend functionality:
|
||||
* ```IToolForm```: Tool window.
|
||||
* ```IToolPanel```: Tool panels in the main window. Try to fit all on 200px width.
|
||||
* ```ITextCoder```: Text codification clases.
|
||||
* ```IProxyCmdExecutor```: Proxy command executors, mainly for remote executions.
|
||||
|
||||
## Usage
|
||||
|
||||
Put the generated assembly near ```VAR.Toolbox.exe``` it will load as plug-ins any assembly that starts
|
||||
with ```VAR.Toolbox```
|
||||
35
VAR.Toolbox.TestPlugin/Properties/AssemblyInfo.cs
Normal file
35
VAR.Toolbox.TestPlugin/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
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("VAR.Toolbox.TestPlugin")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("VAR.Toolbox.TestPlugin")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2019")]
|
||||
[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("74fe172a-d63c-460e-b15f-debf4150bab1")]
|
||||
|
||||
// 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")]
|
||||
65
VAR.Toolbox.TestPlugin/VAR.Toolbox.TestPlugin.csproj
Normal file
65
VAR.Toolbox.TestPlugin/VAR.Toolbox.TestPlugin.csproj
Normal file
@@ -0,0 +1,65 @@
|
||||
<?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>{74FE172A-D63C-460E-B15F-DEBF4150BAB1}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>VAR.Toolbox.TestPlugin</RootNamespace>
|
||||
<AssemblyName>VAR.Toolbox.TestPlugin</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<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' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="FrmTestPlugin.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="FrmTestPlugin.Designer.cs">
|
||||
<DependentUpon>FrmTestPlugin.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VAR.Toolbox\VAR.Toolbox.csproj">
|
||||
<Project>{e8dab98d-4fd0-4d40-b29a-62b4c2fca4d7}</Project>
|
||||
<Name>VAR.Toolbox</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Notes.md" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -1,10 +1,12 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.28917.181
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VAR.Toolbox", "VAR.Toolbox\VAR.Toolbox.csproj", "{E8DAB98D-4FD0-4D40-B29A-62B4C2FCA4D7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VAR.Toolbox.TestPlugin", "VAR.Toolbox.TestPlugin\VAR.Toolbox.TestPlugin.csproj", "{74FE172A-D63C-460E-B15F-DEBF4150BAB1}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -15,8 +17,15 @@ Global
|
||||
{E8DAB98D-4FD0-4D40-B29A-62B4C2FCA4D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E8DAB98D-4FD0-4D40-B29A-62B4C2FCA4D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E8DAB98D-4FD0-4D40-B29A-62B4C2FCA4D7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{74FE172A-D63C-460E-B15F-DEBF4150BAB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{74FE172A-D63C-460E-B15F-DEBF4150BAB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{74FE172A-D63C-460E-B15F-DEBF4150BAB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{74FE172A-D63C-460E-B15F-DEBF4150BAB1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {08F0DAFF-33C5-4164-9454-62623789F7EB}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
63
VAR.Toolbox.sln.DotSettings
Normal file
63
VAR.Toolbox.sln.DotSettings
Normal file
@@ -0,0 +1,63 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_IFELSE/@EntryValue">NotRequired</s:String>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/TRAILING_COMMA_IN_MULTILINE_LISTS/@EntryValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/TRAILING_COMMA_IN_SINGLELINE_LISTS/@EntryValue">True</s:Boolean>
|
||||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/EMPTY_BLOCK_STYLE/@EntryValue">TOGETHER_SAME_LINE</s:String>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_EXISTING_EMBEDDED_BLOCK_ARRANGEMENT/@EntryValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_EMBEDDED_BLOCK_ON_SAME_LINE/@EntryValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_AFTER_TYPECAST_PARENTHESES/@EntryValue">False</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/HtmlFormatter/ALLOW_FAR_ALIGNMENT/@EntryValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/HtmlFormatter/NormalizeTagNames/@EntryValue">True</s:Boolean>
|
||||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/HtmlFormatter/ProcessingInstructionAttributeIndenting/@EntryValue">OneStep</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/HtmlFormatter/TagAttributeIndenting/@EntryValue">OneStep</s:String>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/HtmlFormatter/TagSpaceBeforeHeaderEnd1/@EntryValue">True</s:Boolean>
|
||||
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForBuiltInTypes/@EntryValue">UseVarWhenEvident</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForOtherTypes/@EntryValue">UseVarWhenEvident</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AES/@EntryIndexedValue">AES</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AM/@EntryIndexedValue">AM</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=AUX/@EntryIndexedValue">AUX</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=BPP/@EntryIndexedValue">BPP</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DC/@EntryIndexedValue">DC</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DES/@EntryIndexedValue">DES</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=EPM/@EntryIndexedValue">EPM</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GDI/@EntryIndexedValue">GDI</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ID/@EntryIndexedValue">ID</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IP/@EntryIndexedValue">IP</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=RECT/@EntryIndexedValue">RECT</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=RGB/@EntryIndexedValue">RGB</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SCART/@EntryIndexedValue">SCART</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SPDIF/@EntryIndexedValue">SPDIF</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SQL/@EntryIndexedValue">SQL</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SRCCOPY/@EntryIndexedValue">SRCCOPY</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TCP/@EntryIndexedValue">TCP</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=URL/@EntryIndexedValue">URL</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=USB/@EntryIndexedValue">USB</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=VAR/@EntryIndexedValue">VAR</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WMIC/@EntryIndexedValue">WMIC</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=YRYBY/@EntryIndexedValue">YRYBY</s:String>
|
||||
<s:Boolean x:Key="/Default/CodeStyle/Naming/CSharpNaming/ApplyAutoDetectedRules/@EntryValue">False</s:Boolean>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Constants/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=EnumMember/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb"><ExtraRule Prefix="T" Suffix="" Style="AaBb_AaBb" /></Policy></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Interfaces/@EntryIndexedValue"><Policy Inspect="True" Prefix="I" Suffix="" Style="AaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=LocalConstants/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Locals/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Method/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Parameters/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue"><Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue"><Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue"><Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=Property/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PublicFields/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=StaticReadonly/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb_AaBb" /></s:String>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=bitblt/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Deserializa/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Screenshooter/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=tbps/@EntryIndexedValue">True</s:Boolean>
|
||||
</wpf:ResourceDictionary>
|
||||
79
VAR.Toolbox/Code/BaseFactory.cs
Normal file
79
VAR.Toolbox/Code/BaseFactory.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public abstract class BaseFactory<T> where T : INamed
|
||||
{
|
||||
// ReSharper disable once StaticMemberInGenericType
|
||||
private static Dictionary<string, Type> _dictTypes;
|
||||
|
||||
private static Dictionary<string, Type> GetDict()
|
||||
{
|
||||
if (_dictTypes != null)
|
||||
{
|
||||
return _dictTypes;
|
||||
}
|
||||
|
||||
Type iType = typeof(T);
|
||||
IEnumerable<Type> types = ReflectionUtils.GetTypesOfInterface(iType);
|
||||
_dictTypes = types.ToDictionary(t =>
|
||||
{
|
||||
T type = (T)System.Runtime.Serialization.FormatterServices.GetUninitializedObject(t);
|
||||
return type.Name;
|
||||
});
|
||||
|
||||
return _dictTypes;
|
||||
}
|
||||
|
||||
public static string[] GetNames()
|
||||
{
|
||||
Dictionary<string, Type> dict = GetDict();
|
||||
return dict.Select(p => p.Key).ToArray();
|
||||
}
|
||||
|
||||
public static T CreateFromName(string name)
|
||||
{
|
||||
Dictionary<string, Type> dict = GetDict();
|
||||
if (dict.ContainsKey(name) == false)
|
||||
{
|
||||
throw new NotImplementedException(string.Format("Cant create {1} with this name: {0}", name,
|
||||
typeof(T).Name));
|
||||
}
|
||||
|
||||
Type type = dict[name];
|
||||
|
||||
T instance = (T)Activator.CreateInstance(type);
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static T CreateFromConfig(string config)
|
||||
{
|
||||
Dictionary<string, Type> dict = GetDict();
|
||||
int indexOfColon = config.IndexOf(':');
|
||||
string name = config.Substring(0, indexOfColon < 0 ? config.Length : indexOfColon);
|
||||
string nextConfig = config.Substring(indexOfColon + 1);
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
return (T)(object)null;
|
||||
}
|
||||
|
||||
if (dict.ContainsKey(name) == false)
|
||||
{
|
||||
throw new NotImplementedException(string.Format("Cant create {1} with this config: {0}", config,
|
||||
typeof(T).Name));
|
||||
}
|
||||
|
||||
Type type = dict[name];
|
||||
|
||||
T instance = (T)Activator.CreateInstance(type, new object[] { nextConfig });
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
public interface INamed
|
||||
{
|
||||
string Name { get; }
|
||||
}
|
||||
}
|
||||
6
VAR.Toolbox/Code/Bots/AutomationBotFactory.cs
Normal file
6
VAR.Toolbox/Code/Bots/AutomationBotFactory.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace VAR.Toolbox.Code.Bots
|
||||
{
|
||||
public abstract class AutomationBotFactory: BaseFactory<IAutomationBot>
|
||||
{
|
||||
}
|
||||
}
|
||||
32
VAR.Toolbox/Code/Bots/DummyBot.cs
Normal file
32
VAR.Toolbox/Code/Bots/DummyBot.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Drawing;
|
||||
using VAR.Toolbox.Code.Configuration;
|
||||
|
||||
namespace VAR.Toolbox.Code.Bots
|
||||
{
|
||||
public class DummyBot : IAutomationBot
|
||||
{
|
||||
public string Name => "Dummy";
|
||||
|
||||
public IConfiguration GetDefaultConfiguration()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Init(IOutputHandler output, IConfiguration config)
|
||||
{
|
||||
output.Clean();
|
||||
}
|
||||
|
||||
public Bitmap Process(Bitmap bmpInput, IOutputHandler output)
|
||||
{
|
||||
return bmpInput;
|
||||
}
|
||||
|
||||
public string ResponseKeys()
|
||||
{
|
||||
// https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.sendkeys?view=netframework-4.8
|
||||
//return "{UP}";
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
VAR.Toolbox/Code/Bots/IAutomationBot.cs
Normal file
13
VAR.Toolbox/Code/Bots/IAutomationBot.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System.Drawing;
|
||||
using VAR.Toolbox.Code.Configuration;
|
||||
|
||||
namespace VAR.Toolbox.Code.Bots
|
||||
{
|
||||
public interface IAutomationBot: INamed
|
||||
{
|
||||
IConfiguration GetDefaultConfiguration();
|
||||
void Init(IOutputHandler output, IConfiguration config);
|
||||
Bitmap Process(Bitmap bmpInput, IOutputHandler output);
|
||||
string ResponseKeys();
|
||||
}
|
||||
}
|
||||
894
VAR.Toolbox/Code/Bots/TetrisBot.cs
Normal file
894
VAR.Toolbox/Code/Bots/TetrisBot.cs
Normal file
@@ -0,0 +1,894 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using VAR.Toolbox.Code.Configuration;
|
||||
|
||||
namespace VAR.Toolbox.Code.Bots
|
||||
{
|
||||
public class TetrisBot : IAutomationBot
|
||||
{
|
||||
private TetrisGrid _grid;
|
||||
|
||||
private List<TetrisShape> _currentShape;
|
||||
private TetrisGrid _workGrid0;
|
||||
private TetrisGrid _workGrid1;
|
||||
private double[] _columnEvaluation;
|
||||
|
||||
private bool _shapeFound;
|
||||
private int _shapeX;
|
||||
private int _shapeY;
|
||||
private double _bestEvaluation = double.MinValue;
|
||||
private int _bestXOffset;
|
||||
private int _bestRotation;
|
||||
|
||||
public string Name => "Tetris";
|
||||
|
||||
private const int DefaultGridWidth = 10;
|
||||
private const int DefaultGridHeight = 20;
|
||||
private const int DefaultShotCooldownFrames = 2;
|
||||
|
||||
public IConfiguration GetDefaultConfiguration()
|
||||
{
|
||||
var defaultConfiguration = new MemoryBackedConfiguration();
|
||||
defaultConfiguration.Set("GridWidth", DefaultGridWidth);
|
||||
defaultConfiguration.Set("GridHeight", DefaultGridHeight);
|
||||
defaultConfiguration.Set("ShotCooldownFrames", DefaultShotCooldownFrames);
|
||||
return defaultConfiguration;
|
||||
}
|
||||
|
||||
public void Init(IOutputHandler output, IConfiguration config)
|
||||
{
|
||||
int gridWidth = config.Get("GridWidth", DefaultGridWidth);
|
||||
int gridHeight = config.Get("GridHeight", DefaultGridHeight);
|
||||
_shotCooldownFrames = config.Get("ShotCooldownFrames", DefaultShotCooldownFrames);
|
||||
|
||||
_grid = new TetrisGrid(gridWidth, gridHeight);
|
||||
_workGrid0 = new TetrisGrid(gridWidth, gridHeight);
|
||||
_workGrid1 = new TetrisGrid(gridWidth, gridHeight);
|
||||
_columnEvaluation = new double[gridWidth];
|
||||
_currentShape = new List<TetrisShape>
|
||||
{
|
||||
new TetrisShape(),
|
||||
new TetrisShape(),
|
||||
new TetrisShape(),
|
||||
new TetrisShape(),
|
||||
};
|
||||
output.Clean();
|
||||
output.AddLine($"TetrisBot: Starting {DateTime.UtcNow:s}");
|
||||
}
|
||||
|
||||
public Bitmap Process(Bitmap bmpInput, IOutputHandler output)
|
||||
{
|
||||
_grid.SampleFromBitmap(bmpInput);
|
||||
SearchShape();
|
||||
SearchBestAction();
|
||||
|
||||
// Show information
|
||||
_workGrid0.SampleOther(_grid, TetrisGrid.CellSolid, TetrisGrid.CellSolid);
|
||||
if (_shapeFound)
|
||||
{
|
||||
_currentShape[0].PutOnGrid(_workGrid0, _shapeX, _shapeY, TetrisGrid.CellEmpty);
|
||||
_currentShape[_bestRotation].Drop(_workGrid0, _shapeX + _bestXOffset, _shapeY, TetrisGrid.CellShapeA);
|
||||
_currentShape[0].PutOnGrid(_workGrid0, _shapeX, _shapeY, TetrisGrid.CellShapeB);
|
||||
}
|
||||
|
||||
_workGrid0.Draw(bmpInput, 0.75f);
|
||||
_workGrid0.SampleOther(_grid, TetrisGrid.CellSolid, TetrisGrid.CellSolid);
|
||||
_workGrid0.RemoveGround();
|
||||
_workGrid0.Draw(bmpInput, 0.25f);
|
||||
|
||||
return bmpInput;
|
||||
}
|
||||
|
||||
private void SearchShape()
|
||||
{
|
||||
_workGrid0.SampleOther(_grid, TetrisGrid.CellSolid, TetrisGrid.CellSolid);
|
||||
_workGrid0.RemoveGround();
|
||||
_shapeFound = false;
|
||||
for (int y = 0; y < _grid.Height; y++)
|
||||
{
|
||||
for (int x = 0; x < _grid.Width; x++)
|
||||
{
|
||||
TetrisShape matchedShape =
|
||||
TetrisShape.DefaultShapes.FirstOrDefault(s => s.MatchOnGrid(_workGrid0, x, y));
|
||||
if (matchedShape != null)
|
||||
{
|
||||
_workGrid1.SampleOther(_workGrid0, TetrisGrid.CellSolid, TetrisGrid.CellSolid);
|
||||
matchedShape.PutOnGrid(_workGrid1, x, y, TetrisGrid.CellEmpty);
|
||||
if (matchedShape.CheckIntersection(_workGrid1, x, y + 1)) { continue; }
|
||||
|
||||
// Shape found
|
||||
_currentShape[0].Copy(matchedShape);
|
||||
for (int i = 1; i < 4; i++)
|
||||
{
|
||||
_currentShape[i].RotateClockWise(_currentShape[i - 1]);
|
||||
}
|
||||
|
||||
_shapeX = x;
|
||||
_shapeY = y;
|
||||
_shapeFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (_shapeFound) { break; }
|
||||
}
|
||||
}
|
||||
|
||||
private void SearchBestAction()
|
||||
{
|
||||
_bestEvaluation = double.MinValue;
|
||||
_bestXOffset = 0;
|
||||
_bestRotation = 0;
|
||||
if (!_shapeFound)
|
||||
{
|
||||
_workGrid0.SampleOther(_grid, TetrisGrid.CellSolid, TetrisGrid.CellSolid);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (int rotation = 0; rotation < 4; rotation++)
|
||||
{
|
||||
for (int x = 0; x < _grid.Width; x++)
|
||||
{
|
||||
_workGrid0.SampleOther(_grid, TetrisGrid.CellSolid, TetrisGrid.CellSolid);
|
||||
_currentShape[0].PutOnGrid(_workGrid0, _shapeX, _shapeY, TetrisGrid.CellEmpty);
|
||||
|
||||
if (_currentShape[rotation].Drop(_workGrid0, x, _shapeY, TetrisGrid.CellShapeA))
|
||||
{
|
||||
double newEvaluation = _workGrid0.Evaluate();
|
||||
_columnEvaluation[x] = newEvaluation;
|
||||
}
|
||||
else
|
||||
{
|
||||
_columnEvaluation[x] = double.MinValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Search valid X range
|
||||
int minX = _shapeX;
|
||||
while (minX >= 0 && _columnEvaluation[minX] > double.MinValue) { minX--; }
|
||||
|
||||
minX++;
|
||||
int maxX = _shapeX;
|
||||
while (maxX < _grid.Width && _columnEvaluation[maxX] > double.MinValue) { maxX++; }
|
||||
|
||||
maxX--;
|
||||
|
||||
// Apply best value inside valid X range
|
||||
for (int x = minX; x <= maxX; x++)
|
||||
{
|
||||
if (_columnEvaluation[x] > _bestEvaluation)
|
||||
{
|
||||
_bestEvaluation = _columnEvaluation[x];
|
||||
_bestXOffset = x - _shapeX;
|
||||
_bestRotation = rotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int _shotCooldownFrames;
|
||||
private int _shotCooldown;
|
||||
|
||||
public string ResponseKeys()
|
||||
{
|
||||
if (_shapeFound == false) { return string.Empty; }
|
||||
|
||||
if (_bestRotation == 0 && _bestXOffset == 0 && _bestEvaluation > double.MinValue)
|
||||
{
|
||||
if (_shotCooldown <= 0)
|
||||
{
|
||||
_shotCooldown = _shotCooldownFrames;
|
||||
return " ";
|
||||
}
|
||||
else
|
||||
{
|
||||
_shotCooldown--;
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
_shotCooldown = _shotCooldownFrames;
|
||||
|
||||
if (_bestRotation != 0 && _bestXOffset < 0) { return "{UP}{LEFT}"; }
|
||||
|
||||
if (_bestRotation != 0 && _bestXOffset > 0) { return "{UP}{RIGHT}"; }
|
||||
|
||||
if (_bestRotation != 0) { return "{UP}"; }
|
||||
|
||||
if (_bestXOffset < 0) { return "{LEFT}"; }
|
||||
|
||||
if (_bestXOffset > 0) { return "{RIGHT}"; }
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public class TetrisShape
|
||||
{
|
||||
private const int ShapeSize = 4;
|
||||
|
||||
private readonly byte[][] _cells;
|
||||
|
||||
private int _count;
|
||||
|
||||
public TetrisShape(byte[][] cells = null)
|
||||
{
|
||||
_cells = new byte[ShapeSize][];
|
||||
for (int y = 0; y < ShapeSize; y++)
|
||||
{
|
||||
_cells[y] = new byte[ShapeSize];
|
||||
}
|
||||
|
||||
_count = 0;
|
||||
if (cells != null)
|
||||
{
|
||||
for (int j = 0; j < ShapeSize; j++)
|
||||
{
|
||||
if (j >= cells.Length) { break; }
|
||||
|
||||
for (int i = 0; i < ShapeSize; i++)
|
||||
{
|
||||
if (i >= cells[j].Length) { break; }
|
||||
|
||||
_cells[j][i] = cells[j][i];
|
||||
if (_cells[j][i] != 0) { _count++; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int GetCount()
|
||||
{
|
||||
return _count;
|
||||
}
|
||||
|
||||
private static List<TetrisShape> _defaultShapes;
|
||||
|
||||
public static List<TetrisShape> DefaultShapes
|
||||
{
|
||||
get
|
||||
{
|
||||
return _defaultShapes ?? (_defaultShapes = new List<TetrisShape>
|
||||
{
|
||||
// I
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, 1, 1, 1, },
|
||||
}),
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, },
|
||||
new byte[] { 1, },
|
||||
new byte[] { 1, },
|
||||
new byte[] { 1, },
|
||||
}),
|
||||
|
||||
// J
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, },
|
||||
new byte[] { 1, 1, 1, },
|
||||
}),
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, 1, },
|
||||
new byte[] { 1, },
|
||||
new byte[] { 1, },
|
||||
}),
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, 1, 1, },
|
||||
new byte[] { 0, 0, 1, },
|
||||
}),
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 0, 1, },
|
||||
new byte[] { 0, 1, },
|
||||
new byte[] { 1, 1, },
|
||||
}),
|
||||
|
||||
// L
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 0, 0, 1, },
|
||||
new byte[] { 1, 1, 1, },
|
||||
}),
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, },
|
||||
new byte[] { 1, },
|
||||
new byte[] { 1, 1, },
|
||||
}),
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, 1, 1, },
|
||||
new byte[] { 1, },
|
||||
}),
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, 1, },
|
||||
new byte[] { 0, 1, },
|
||||
new byte[] { 0, 1, },
|
||||
}),
|
||||
|
||||
// S
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 0, 1, 1, },
|
||||
new byte[] { 1, 1, },
|
||||
}),
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, },
|
||||
new byte[] { 1, 1, },
|
||||
new byte[] { 0, 1, },
|
||||
}),
|
||||
|
||||
// T
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 0, 1, },
|
||||
new byte[] { 1, 1, 1, },
|
||||
}),
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, },
|
||||
new byte[] { 1, 1, },
|
||||
new byte[] { 1, },
|
||||
}),
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, 1, 1, },
|
||||
new byte[] { 0, 1, },
|
||||
}),
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 0, 1, },
|
||||
new byte[] { 1, 1, },
|
||||
new byte[] { 0, 1, },
|
||||
}),
|
||||
|
||||
// Z
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, 1, },
|
||||
new byte[] { 0, 1, 1, },
|
||||
}),
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 0, 1, },
|
||||
new byte[] { 1, 1, },
|
||||
new byte[] { 1, },
|
||||
}),
|
||||
|
||||
// O
|
||||
new TetrisShape(new[]
|
||||
{
|
||||
new byte[] { 1, 1, },
|
||||
new byte[] { 1, 1, },
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsValid()
|
||||
{
|
||||
if (_count != 4) { return false; }
|
||||
|
||||
bool matchesAnyDefault = DefaultShapes.Any(CompareShape);
|
||||
return matchesAnyDefault;
|
||||
}
|
||||
|
||||
public void Copy(TetrisShape shape)
|
||||
{
|
||||
for (int j = 0; j < ShapeSize; j++)
|
||||
{
|
||||
for (int i = 0; i < ShapeSize; i++)
|
||||
{
|
||||
_cells[j][i] = shape._cells[j][i];
|
||||
_count = shape._count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool CompareShape(TetrisShape shape)
|
||||
{
|
||||
for (int j = 0; j < ShapeSize; j++)
|
||||
{
|
||||
for (int i = 0; i < ShapeSize; i++)
|
||||
{
|
||||
if (_cells[j][i] != shape._cells[j][i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void SampleFromGrid(TetrisGrid grid, int x, int y, byte value)
|
||||
{
|
||||
_count = 0;
|
||||
for (int j = 0; j < ShapeSize; j++)
|
||||
{
|
||||
for (int i = 0; i < ShapeSize; i++)
|
||||
{
|
||||
if (grid.Get(x + i, y + j) == value)
|
||||
{
|
||||
_cells[j][i] = 1;
|
||||
_count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
_cells[j][i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void PutOnGrid(TetrisGrid grid, int x, int y, byte value)
|
||||
{
|
||||
for (int j = 0; j < ShapeSize; j++)
|
||||
{
|
||||
for (int i = 0; i < ShapeSize; i++)
|
||||
{
|
||||
if (_cells[j][i] == 0) { continue; }
|
||||
|
||||
grid.Set(x + i, y + j, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool CheckIntersection(TetrisGrid grid, int x, int y)
|
||||
{
|
||||
for (int j = 0; j < ShapeSize; j++)
|
||||
{
|
||||
for (int i = 0; i < ShapeSize; i++)
|
||||
{
|
||||
if (_cells[j][i] == 0) { continue; }
|
||||
|
||||
if (grid.Get(x + i, y + j) != 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Drop(TetrisGrid grid, int x, int y, byte value)
|
||||
{
|
||||
if (CheckIntersection(grid, x, y)) { return false; }
|
||||
|
||||
while (CheckIntersection(grid, x, y + 1) == false)
|
||||
{
|
||||
y++;
|
||||
}
|
||||
|
||||
PutOnGrid(grid, x, y, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool SearchFirstCell(byte value, out int x, out int y)
|
||||
{
|
||||
x = -1;
|
||||
y = -1;
|
||||
for (int j = 0; j < ShapeSize && y == -1; j++)
|
||||
{
|
||||
for (int i = 0; i < ShapeSize && y == -1; i++)
|
||||
{
|
||||
if (_cells[j][i] == value)
|
||||
{
|
||||
y = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (y == -1) { return false; }
|
||||
|
||||
for (int i = 0; i < ShapeSize && x == -1; i++)
|
||||
{
|
||||
for (int j = 0; j < ShapeSize && x == -1; j++)
|
||||
{
|
||||
if (_cells[j][i] == value)
|
||||
{
|
||||
x = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (x == -1) { return false; }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void Offset(int x, int y)
|
||||
{
|
||||
_count = 0;
|
||||
for (int j = 0; j < ShapeSize; j++)
|
||||
{
|
||||
for (int i = 0; i < ShapeSize; i++)
|
||||
{
|
||||
if ((j + y) < ShapeSize && (i + x) < ShapeSize)
|
||||
{
|
||||
_cells[j][i] = _cells[j + y][i + x];
|
||||
if (_cells[j][i] != 0)
|
||||
{
|
||||
_count++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_cells[j][i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RotateClockWise(TetrisShape shape)
|
||||
{
|
||||
for (int j = 0; j < ShapeSize; j++)
|
||||
{
|
||||
for (int i = 0; i < ShapeSize; i++)
|
||||
{
|
||||
_cells[i][ShapeSize - (j + 1)] = shape._cells[j][i];
|
||||
}
|
||||
}
|
||||
|
||||
_count = shape._count;
|
||||
|
||||
if (SearchFirstCell(1, out int offsetX, out int offsetY))
|
||||
{
|
||||
Offset(offsetX, offsetY);
|
||||
}
|
||||
}
|
||||
|
||||
public void Print(IOutputHandler output)
|
||||
{
|
||||
for (int y = 0; y < ShapeSize; y++)
|
||||
{
|
||||
StringBuilder sbLine = new StringBuilder();
|
||||
for (int x = 0; x < ShapeSize; x++)
|
||||
{
|
||||
sbLine.Append(_cells[y][x] == 0 ? ".." : "[]");
|
||||
}
|
||||
|
||||
output.AddLine(sbLine.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public bool MatchOnGrid(TetrisGrid grid, int x, int y)
|
||||
{
|
||||
for (int j = 0; j < ShapeSize; j++)
|
||||
{
|
||||
for (int i = 0; i < ShapeSize; i++)
|
||||
{
|
||||
int currentCell = grid.Get(x + i, y + j);
|
||||
if (_cells[j][i] == 0)
|
||||
{
|
||||
if (currentCell != 0 && currentCell != 0xFF)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (currentCell == 0 || currentCell == 0xFF)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class TetrisGrid
|
||||
{
|
||||
public const byte CellEmpty = 0;
|
||||
public const byte CellSolid = 1;
|
||||
public const byte CellShapeA = 2;
|
||||
public const byte CellShapeB = 3;
|
||||
|
||||
private readonly int _gridWidth;
|
||||
private readonly int _gridHeight;
|
||||
|
||||
public int Width => _gridWidth;
|
||||
public int Height => _gridHeight;
|
||||
|
||||
private readonly byte[][] _grid;
|
||||
|
||||
private readonly int[] _heights;
|
||||
|
||||
public TetrisGrid(int gridWidth, int gridHeight)
|
||||
{
|
||||
_gridWidth = gridWidth;
|
||||
_gridHeight = gridHeight;
|
||||
_grid = new byte[_gridHeight][];
|
||||
for (int y = 0; y < _gridHeight; y++)
|
||||
{
|
||||
_grid[y] = new byte[_gridWidth];
|
||||
}
|
||||
|
||||
_heights = new int[_gridWidth];
|
||||
}
|
||||
|
||||
public byte Get(int x, int y)
|
||||
{
|
||||
if (x >= _gridWidth || x < 0) { return 0xFF; }
|
||||
|
||||
if (y >= _gridHeight || y < 0) { return 0xFF; }
|
||||
|
||||
return _grid[y][x];
|
||||
}
|
||||
|
||||
public void Set(int x, int y, byte value)
|
||||
{
|
||||
if (x >= _gridWidth || x < 0) { return; }
|
||||
|
||||
if (y >= _gridHeight || y < 0) { return; }
|
||||
|
||||
_grid[y][x] = value;
|
||||
}
|
||||
|
||||
public void SampleFromBitmap(Bitmap bmp)
|
||||
{
|
||||
float xStep = bmp.Width / (float)_gridWidth;
|
||||
float yStep = bmp.Height / (float)_gridHeight;
|
||||
float xOff0 = xStep / 2;
|
||||
float xOff1 = xOff0 / 2;
|
||||
float xOff2 = xOff0 + xOff1;
|
||||
float yOff0 = yStep / 2;
|
||||
float yOff1 = yOff0 / 2;
|
||||
float yOff2 = yOff0 + yOff1;
|
||||
for (int y = 0; y < _gridHeight; y++)
|
||||
{
|
||||
for (int x = 0; x < _gridWidth; x++)
|
||||
{
|
||||
Color color = bmp.GetPixel(
|
||||
x: (int)((x * xStep) + xOff0),
|
||||
y: (int)((y * yStep) + yOff0));
|
||||
if (color.R > 128 || color.G > 128 || color.B > 128)
|
||||
{
|
||||
Color color0 = bmp.GetPixel(
|
||||
x: (int)((x * xStep) + xOff1),
|
||||
y: (int)((y * yStep) + yOff1));
|
||||
Color color1 = bmp.GetPixel(
|
||||
x: (int)((x * xStep) + xOff1),
|
||||
y: (int)((y * yStep) + yOff2));
|
||||
Color color2 = bmp.GetPixel(
|
||||
x: (int)((x * xStep) + xOff2),
|
||||
y: (int)((y * yStep) + yOff1));
|
||||
Color color3 = bmp.GetPixel(
|
||||
x: (int)((x * xStep) + xOff2),
|
||||
y: (int)((y * yStep) + yOff2));
|
||||
if (
|
||||
(color0.R > 128 || color0.G > 128 || color0.B > 128) &&
|
||||
(color1.R > 128 || color1.G > 128 || color1.B > 128) &&
|
||||
(color2.R > 128 || color2.G > 128 || color2.B > 128) &&
|
||||
(color3.R > 128 || color3.G > 128 || color3.B > 128) &&
|
||||
true)
|
||||
{
|
||||
_grid[y][x] = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_grid[y][x] = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_grid[y][x] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveGround()
|
||||
{
|
||||
for (int i = 0; i < _gridWidth; i++)
|
||||
{
|
||||
if (_grid[_gridHeight - 1][i] == 1)
|
||||
{
|
||||
FloodFill(i, _gridHeight - 1, CellSolid, CellEmpty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FloodFill(int x, int y, byte expectedValue, byte fillValue)
|
||||
{
|
||||
if (x >= _gridWidth || x < 0) { return; }
|
||||
|
||||
if (y >= _gridHeight || y < 0) { return; }
|
||||
|
||||
if (_grid[y][x] != expectedValue) { return; }
|
||||
|
||||
_grid[y][x] = fillValue;
|
||||
FloodFill(x - 1, y - 1, expectedValue, fillValue);
|
||||
FloodFill(x - 1, y + 0, expectedValue, fillValue);
|
||||
FloodFill(x - 1, y + 1, expectedValue, fillValue);
|
||||
FloodFill(x + 0, y - 1, expectedValue, fillValue);
|
||||
FloodFill(x + 0, y + 1, expectedValue, fillValue);
|
||||
FloodFill(x + 1, y - 1, expectedValue, fillValue);
|
||||
FloodFill(x + 1, y + 0, expectedValue, fillValue);
|
||||
FloodFill(x + 1, y + 1, expectedValue, fillValue);
|
||||
}
|
||||
|
||||
public void SampleOther(TetrisGrid grid, byte value, byte setValue)
|
||||
{
|
||||
for (int y = 0; y < _gridHeight; y++)
|
||||
{
|
||||
for (int x = 0; x < _gridWidth; x++)
|
||||
{
|
||||
if (grid._grid[y][x] == value)
|
||||
{
|
||||
_grid[y][x] = setValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
_grid[y][x] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool SearchFirstCell(byte value, out int x, out int y)
|
||||
{
|
||||
x = -1;
|
||||
y = -1;
|
||||
for (int j = 0; j < _gridHeight && y == -1; j++)
|
||||
{
|
||||
for (int i = 0; i < _gridWidth && y == -1; i++)
|
||||
{
|
||||
if (_grid[j][i] == value)
|
||||
{
|
||||
y = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (y == -1) { return false; }
|
||||
|
||||
for (int i = 0; i < _gridWidth && x == -1; i++)
|
||||
{
|
||||
for (int j = 0; j < _gridHeight && x == -1; j++)
|
||||
{
|
||||
if (_grid[j][i] == value)
|
||||
{
|
||||
x = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (x == -1) { return false; }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool IsCompleteLine(int y)
|
||||
{
|
||||
bool complete = true;
|
||||
for (int x = 0; x < _gridWidth; x++)
|
||||
{
|
||||
if (_grid[y][x] == 0)
|
||||
{
|
||||
complete = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return complete;
|
||||
}
|
||||
|
||||
public double Evaluate(
|
||||
double aggregateHeightWeight = -0.510066,
|
||||
double completeLinesWeight = 0.760666,
|
||||
double holesWeight = -0.35663,
|
||||
double bumpinessWeight = -0.184483)
|
||||
{
|
||||
// Calculate aggregate height
|
||||
for (int i = 0; i < _gridWidth; i++)
|
||||
{
|
||||
int j = 0;
|
||||
while (j < _gridHeight && _grid[j][i] == CellEmpty) { j++; }
|
||||
|
||||
_heights[i] = _gridHeight - j;
|
||||
}
|
||||
|
||||
double aggregateHeight = _heights.Sum();
|
||||
|
||||
// Calculate complete lines
|
||||
int completeLines = 0;
|
||||
for (int y = 0; y < _gridHeight; y++)
|
||||
{
|
||||
if (IsCompleteLine(y)) { completeLines++; }
|
||||
}
|
||||
|
||||
// Calculate holes
|
||||
int holes = 0;
|
||||
for (int x = 0; x < _gridWidth; x++)
|
||||
{
|
||||
bool block = false;
|
||||
for (int y = 1; y < _gridHeight; y++)
|
||||
{
|
||||
if (_grid[y][x] != CellEmpty && IsCompleteLine(y) == false)
|
||||
{
|
||||
block = true;
|
||||
}
|
||||
else if (_grid[y][x] == CellEmpty && block)
|
||||
{
|
||||
holes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate bumpiness
|
||||
int bumpiness = 0;
|
||||
for (int i = 1; i < _gridWidth; i++)
|
||||
{
|
||||
bumpiness += Math.Abs(_heights[i] - _heights[i - 1]);
|
||||
}
|
||||
|
||||
// Evaluate formula
|
||||
double evaluationValue =
|
||||
aggregateHeightWeight * aggregateHeight +
|
||||
completeLinesWeight * completeLines +
|
||||
holesWeight * holes +
|
||||
bumpinessWeight * bumpiness +
|
||||
0;
|
||||
return evaluationValue;
|
||||
}
|
||||
|
||||
public void Draw(Bitmap bmp, float dotWith = 0.5f)
|
||||
{
|
||||
float xStep = bmp.Width / (float)_gridWidth;
|
||||
float yStep = bmp.Height / (float)_gridHeight;
|
||||
float halfXStep = xStep * dotWith;
|
||||
float halfYStep = yStep * dotWith;
|
||||
float offX = (xStep - halfXStep) / 2;
|
||||
float offY = (yStep - halfYStep) / 2;
|
||||
|
||||
using (Pen borderPen = new Pen(Color.DarkGray))
|
||||
using (Graphics g = Graphics.FromImage(bmp))
|
||||
{
|
||||
for (int y = 0; y < _gridHeight; y++)
|
||||
{
|
||||
for (int x = 0; x < _gridWidth; x++)
|
||||
{
|
||||
Brush br = null;
|
||||
if (_grid[y][x] == CellEmpty)
|
||||
{
|
||||
br = Brushes.Black;
|
||||
}
|
||||
else if (_grid[y][x] == CellSolid)
|
||||
{
|
||||
br = Brushes.Blue;
|
||||
}
|
||||
else if (_grid[y][x] == CellShapeA)
|
||||
{
|
||||
br = Brushes.Red;
|
||||
}
|
||||
else if (_grid[y][x] == CellShapeB)
|
||||
{
|
||||
br = Brushes.Green;
|
||||
}
|
||||
|
||||
if (br == null) { continue; }
|
||||
|
||||
g.DrawRectangle(borderPen, (xStep * x) + offX - 1, (yStep * y) + offY - 1, halfXStep + 2,
|
||||
halfYStep + 2);
|
||||
g.FillRectangle(br, (xStep * x) + offX, (yStep * y) + offY, halfXStep, halfYStep);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
116
VAR.Toolbox/Code/Configuration/FileBackedConfiguration.cs
Normal file
116
VAR.Toolbox/Code/Configuration/FileBackedConfiguration.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace VAR.Toolbox.Code.Configuration
|
||||
{
|
||||
public class FileBackedConfiguration : IConfiguration
|
||||
{
|
||||
private readonly MemoryBackedConfiguration _config = new MemoryBackedConfiguration();
|
||||
|
||||
private readonly string _name;
|
||||
|
||||
public FileBackedConfiguration(string name = null)
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
|
||||
private static string GetConfigFileName(string name = null)
|
||||
{
|
||||
string location = System.Reflection.Assembly.GetEntryAssembly()?.Location;
|
||||
string path = Path.GetDirectoryName(location);
|
||||
string filenameWithoutExtension = Path.GetFileNameWithoutExtension(location);
|
||||
string configFile = string.IsNullOrEmpty(name)
|
||||
? $"{path}/{filenameWithoutExtension}.cfg"
|
||||
: $"{path}/{filenameWithoutExtension}_{name}.cfg";
|
||||
return configFile;
|
||||
}
|
||||
|
||||
private static string[] GetConfigurationLines(string name = null)
|
||||
{
|
||||
string configFile = GetConfigFileName(name);
|
||||
string[] config = File.Exists(configFile) == false
|
||||
? Array.Empty<string>()
|
||||
: File.ReadAllLines(configFile);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
public void Load(IConfiguration other = null)
|
||||
{
|
||||
_config.Clear();
|
||||
if (other != null)
|
||||
{
|
||||
foreach (string key in other.GetKeys())
|
||||
{
|
||||
_config.Set(key, other.Get(key, null));
|
||||
}
|
||||
}
|
||||
|
||||
string[] configLines = GetConfigurationLines(_name);
|
||||
foreach (string configLine in configLines)
|
||||
{
|
||||
int idxSplit = configLine.IndexOf('|');
|
||||
if (idxSplit < 0) { continue; }
|
||||
|
||||
string configName = configLine.Substring(0, idxSplit);
|
||||
string configData = configLine.Substring(idxSplit + 1);
|
||||
|
||||
_config.Set(configName, configData);
|
||||
}
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
StringBuilder sbConfig = new StringBuilder();
|
||||
foreach (string key in _config.GetKeys())
|
||||
{
|
||||
sbConfig.AppendFormat("{0}|{1}\n", key, _config.Get(key, string.Empty));
|
||||
}
|
||||
|
||||
string configFileName = GetConfigFileName(_name);
|
||||
File.WriteAllText(configFileName, sbConfig.ToString());
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetKeys()
|
||||
{
|
||||
return _config.GetKeys();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_config.Clear();
|
||||
}
|
||||
|
||||
public string Get(string key, string defaultValue)
|
||||
{
|
||||
return _config.Get(key, defaultValue);
|
||||
}
|
||||
|
||||
public int Get(string key, int defaultValue)
|
||||
{
|
||||
return _config.Get(key, defaultValue);
|
||||
}
|
||||
|
||||
public bool Get(string key, bool defaultValue)
|
||||
{
|
||||
return _config.Get(key, defaultValue);
|
||||
}
|
||||
|
||||
public void Set(string key, string value)
|
||||
{
|
||||
_config.Set(key, value);
|
||||
}
|
||||
|
||||
public void Set(string key, int value)
|
||||
{
|
||||
_config.Set(key, value);
|
||||
}
|
||||
|
||||
public void Set(string key, bool value)
|
||||
{
|
||||
_config.Set(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
16
VAR.Toolbox/Code/Configuration/IConfiguration.cs
Normal file
16
VAR.Toolbox/Code/Configuration/IConfiguration.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace VAR.Toolbox.Code.Configuration
|
||||
{
|
||||
public interface IConfiguration
|
||||
{
|
||||
IEnumerable<string> GetKeys();
|
||||
void Clear();
|
||||
bool Get(string key, bool defaultValue);
|
||||
int Get(string key, int defaultValue);
|
||||
string Get(string key, string defaultValue);
|
||||
void Set(string key, bool value);
|
||||
void Set(string key, int value);
|
||||
void Set(string key, string value);
|
||||
}
|
||||
}
|
||||
102
VAR.Toolbox/Code/Configuration/MemoryBackedConfiguration.cs
Normal file
102
VAR.Toolbox/Code/Configuration/MemoryBackedConfiguration.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace VAR.Toolbox.Code.Configuration
|
||||
{
|
||||
public class MemoryBackedConfiguration : IConfiguration
|
||||
{
|
||||
private readonly Dictionary<string, string> _configItems = new Dictionary<string, string>();
|
||||
|
||||
public IEnumerable<string> GetKeys()
|
||||
{
|
||||
return _configItems == null
|
||||
? new List<string>()
|
||||
: _configItems.Select(p => p.Key);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_configItems.Clear();
|
||||
}
|
||||
|
||||
public string Get(string key, string defaultValue)
|
||||
{
|
||||
if (_configItems == null) { return defaultValue; }
|
||||
|
||||
return _configItems.ContainsKey(key) ? _configItems[key] : defaultValue;
|
||||
}
|
||||
|
||||
public int Get(string key, int defaultValue)
|
||||
{
|
||||
if (_configItems == null) { return defaultValue; }
|
||||
|
||||
if (_configItems.ContainsKey(key))
|
||||
{
|
||||
if (int.TryParse(_configItems[key], out int value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public bool Get(string key, bool defaultValue)
|
||||
{
|
||||
if (_configItems == null) { return defaultValue; }
|
||||
|
||||
if (_configItems.ContainsKey(key))
|
||||
{
|
||||
string value = _configItems[key];
|
||||
return (value == "true");
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void Set(string key, string value)
|
||||
{
|
||||
if (_configItems == null) { return; }
|
||||
|
||||
if (_configItems.ContainsKey(key))
|
||||
{
|
||||
_configItems[key] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
_configItems.Add(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void Set(string key, int value)
|
||||
{
|
||||
if (_configItems == null) { return; }
|
||||
|
||||
if (_configItems.ContainsKey(key))
|
||||
{
|
||||
_configItems[key] = Convert.ToString(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
_configItems.Add(key, Convert.ToString(value));
|
||||
}
|
||||
}
|
||||
|
||||
public void Set(string key, bool value)
|
||||
{
|
||||
if (_configItems == null) { return; }
|
||||
|
||||
if (_configItems.ContainsKey(key))
|
||||
{
|
||||
_configItems[key] = value ? "true" : "false";
|
||||
}
|
||||
else
|
||||
{
|
||||
_configItems.Add(key, value ? "true" : "false");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,26 +11,32 @@
|
||||
/// Pan control.
|
||||
/// </summary>
|
||||
Pan = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Tilt control.
|
||||
/// </summary>
|
||||
Tilt,
|
||||
|
||||
/// <summary>
|
||||
/// Roll control.
|
||||
/// </summary>
|
||||
Roll,
|
||||
|
||||
/// <summary>
|
||||
/// Zoom control.
|
||||
/// </summary>
|
||||
Zoom,
|
||||
|
||||
/// <summary>
|
||||
/// Exposure control.
|
||||
/// </summary>
|
||||
Exposure,
|
||||
|
||||
/// <summary>
|
||||
/// Iris control.
|
||||
/// </summary>
|
||||
Iris,
|
||||
|
||||
/// <summary>
|
||||
/// Focus control.
|
||||
/// </summary>
|
||||
@@ -47,10 +53,12 @@
|
||||
/// No control flag.
|
||||
/// </summary>
|
||||
None = 0x0,
|
||||
|
||||
/// <summary>
|
||||
/// Auto control Flag.
|
||||
/// </summary>
|
||||
Auto = 0x0001,
|
||||
|
||||
/// <summary>
|
||||
/// Manual control Flag.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
namespace VAR.Toolbox.Code.DirectShow
|
||||
{
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
/// <summary>
|
||||
@@ -16,7 +15,7 @@
|
||||
/// Gets the range and default value of a specified camera property.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="Property">Specifies the property to query.</param>
|
||||
/// <param name="property">Specifies the property to query.</param>
|
||||
/// <param name="pMin">Receives the minimum value of the property.</param>
|
||||
/// <param name="pMax">Receives the maximum value of the property.</param>
|
||||
/// <param name="pSteppingDelta">Receives the step size for the property.</param>
|
||||
@@ -27,7 +26,7 @@
|
||||
///
|
||||
[PreserveSig]
|
||||
int GetRange(
|
||||
[In] CameraControlProperty Property,
|
||||
[In] CameraControlProperty property,
|
||||
[Out] out int pMin,
|
||||
[Out] out int pMax,
|
||||
[Out] out int pSteppingDelta,
|
||||
@@ -39,35 +38,35 @@
|
||||
/// Sets a specified property on the camera.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="Property">Specifies the property to set.</param>
|
||||
/// <param name="property">Specifies the property to set.</param>
|
||||
/// <param name="lValue">Specifies the new value of the property.</param>
|
||||
/// <param name="Flags">Specifies the desired control setting, as a member of the CameraControlFlags enumeration.</param>
|
||||
/// <param name="flags">Specifies the desired control setting, as a member of the CameraControlFlags enumeration.</param>
|
||||
///
|
||||
/// <returns>Return's <b>HRESULT</b> error code.</returns>
|
||||
///
|
||||
[PreserveSig]
|
||||
int Set(
|
||||
[In] CameraControlProperty Property,
|
||||
[In] CameraControlProperty property,
|
||||
[In] int lValue,
|
||||
[In] CameraControlFlags Flags
|
||||
[In] CameraControlFlags flags
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current setting of a camera property.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="Property">Specifies the property to retrieve.</param>
|
||||
/// <param name="property">Specifies the property to retrieve.</param>
|
||||
/// <param name="lValue">Receives the value of the property.</param>
|
||||
/// <param name="Flags">Receives a member of the CameraControlFlags enumeration.
|
||||
/// <param name="flags">Receives a member of the CameraControlFlags enumeration.
|
||||
/// The returned value indicates whether the setting is controlled manually or automatically.</param>
|
||||
///
|
||||
/// <returns>Return's <b>HRESULT</b> error code.</returns>
|
||||
///
|
||||
[PreserveSig]
|
||||
int Get(
|
||||
[In] CameraControlProperty Property,
|
||||
[In] CameraControlProperty property,
|
||||
[Out] out int lValue,
|
||||
[Out] out CameraControlFlags Flags
|
||||
[Out] out CameraControlFlags flags
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
#pragma warning disable IDE1006
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace VAR.Toolbox.Code.DirectShow
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
namespace VAR.Toolbox.Code.DirectShow
|
||||
{
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
/// <summary>
|
||||
@@ -60,8 +59,10 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
[PreserveSig]
|
||||
int GetStreamCaps(
|
||||
[In] int index,
|
||||
[Out, MarshalAs(UnmanagedType.LPStruct)] out AMMediaType mediaType,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)] VideoStreamConfigCaps streamConfigCaps
|
||||
[Out, MarshalAs(UnmanagedType.LPStruct)]
|
||||
out AMMediaType mediaType,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)]
|
||||
VideoStreamConfigCaps streamConfigCaps
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -19,12 +19,12 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
/// Returns the class identifier (CLSID) for the component object.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="ClassID">Points to the location of the CLSID on return.</param>
|
||||
/// <param name="classID">Points to the location of the CLSID on return.</param>
|
||||
///
|
||||
/// <returns>Return's <b>HRESULT</b> error code.</returns>
|
||||
///
|
||||
[PreserveSig]
|
||||
int GetClassID([Out] out Guid ClassID);
|
||||
int GetClassID([Out] out Guid classID);
|
||||
|
||||
// --- IMediaFilter Methods
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// ReSharper disable IdentifierTypo
|
||||
|
||||
namespace VAR.Toolbox.Code.DirectShow
|
||||
{
|
||||
using System;
|
||||
@@ -48,14 +50,15 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
///
|
||||
[PreserveSig]
|
||||
int SetOutputFileName(
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)] Guid type,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)]
|
||||
Guid type,
|
||||
[In, MarshalAs(UnmanagedType.LPWStr)] string fileName,
|
||||
[Out] out IBaseFilter baseFilter,
|
||||
[Out] out IntPtr fileSinkFilter
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Searche the graph for a specified interface, starting from a specified filter.
|
||||
/// Search the graph for a specified interface, starting from a specified filter.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="category">GUID that specifies the search criteria.</param>
|
||||
@@ -68,11 +71,15 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
///
|
||||
[PreserveSig]
|
||||
int FindInterface(
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)] Guid category,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)] Guid type,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)]
|
||||
Guid category,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)]
|
||||
Guid type,
|
||||
[In] IBaseFilter baseFilter,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceID,
|
||||
[Out, MarshalAs(UnmanagedType.IUnknown)] out object retInterface
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)]
|
||||
Guid interfaceID,
|
||||
[Out, MarshalAs(UnmanagedType.IUnknown)]
|
||||
out object retInterface
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
@@ -89,9 +96,12 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
///
|
||||
[PreserveSig]
|
||||
int RenderStream(
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)] Guid category,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)] Guid mediaType,
|
||||
[In, MarshalAs(UnmanagedType.IUnknown)] object source,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)]
|
||||
Guid category,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)]
|
||||
Guid mediaType,
|
||||
[In, MarshalAs(UnmanagedType.IUnknown)]
|
||||
object source,
|
||||
[In] IBaseFilter compressor,
|
||||
[In] IBaseFilter renderer
|
||||
);
|
||||
@@ -114,9 +124,12 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
///
|
||||
[PreserveSig]
|
||||
int ControlStream(
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)] Guid category,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)] Guid mediaType,
|
||||
[In, MarshalAs(UnmanagedType.Interface)] IBaseFilter filter,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)]
|
||||
Guid category,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)]
|
||||
Guid mediaType,
|
||||
[In, MarshalAs(UnmanagedType.Interface)]
|
||||
IBaseFilter filter,
|
||||
[In] long start,
|
||||
[In] long stop,
|
||||
[In] short startCookie,
|
||||
@@ -173,13 +186,17 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
///
|
||||
[PreserveSig]
|
||||
int FindPin(
|
||||
[In, MarshalAs(UnmanagedType.IUnknown)] object source,
|
||||
[In, MarshalAs(UnmanagedType.IUnknown)]
|
||||
object source,
|
||||
[In] PinDirection pinDirection,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)] Guid category,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)] Guid mediaType,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)]
|
||||
Guid category,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)]
|
||||
Guid mediaType,
|
||||
[In, MarshalAs(UnmanagedType.Bool)] bool unconnected,
|
||||
[In] int index,
|
||||
[Out, MarshalAs(UnmanagedType.Interface)] out IPin pin
|
||||
[Out, MarshalAs(UnmanagedType.Interface)]
|
||||
out IPin pin
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
namespace VAR.Toolbox.Code.DirectShow
|
||||
{
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
/// <summary>
|
||||
@@ -25,7 +24,8 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
///
|
||||
[PreserveSig]
|
||||
int Next([In] int cFilters,
|
||||
[Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IBaseFilter[] filters,
|
||||
[Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)]
|
||||
IBaseFilter[] filters,
|
||||
[Out] out int filtersFetched);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
namespace VAR.Toolbox.Code.DirectShow
|
||||
{
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
/// <summary>
|
||||
@@ -24,7 +23,8 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
///
|
||||
[PreserveSig]
|
||||
int Next([In] int cPins,
|
||||
[Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IPin[] pins,
|
||||
[Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)]
|
||||
IPin[] pins,
|
||||
[Out] out int pinsFetched);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
namespace VAR.Toolbox.Code.DirectShow
|
||||
{
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
/// <summary>
|
||||
@@ -23,7 +22,8 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
///
|
||||
[PreserveSig]
|
||||
int Load([In, MarshalAs(UnmanagedType.LPWStr)] string fileName,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)] AMMediaType mediaType);
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)]
|
||||
AMMediaType mediaType);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the current file.
|
||||
@@ -36,6 +36,7 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
///
|
||||
[PreserveSig]
|
||||
int GetCurFile([Out, MarshalAs(UnmanagedType.LPWStr)] out string fileName,
|
||||
[Out, MarshalAs(UnmanagedType.LPStruct)] AMMediaType mediaType);
|
||||
[Out, MarshalAs(UnmanagedType.LPStruct)]
|
||||
AMMediaType mediaType);
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,9 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
/// <returns>Return's <b>HRESULT</b> error code.</returns>
|
||||
///
|
||||
[PreserveSig]
|
||||
int ConnectDirect([In] IPin pinOut, [In] IPin pinIn, [In, MarshalAs(UnmanagedType.LPStruct)] AMMediaType mediaType);
|
||||
int ConnectDirect([In] IPin pinOut, [In] IPin pinIn,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)]
|
||||
AMMediaType mediaType);
|
||||
|
||||
/// <summary>
|
||||
/// Breaks the existing pin connection and reconnects it to the same pin.
|
||||
|
||||
@@ -73,7 +73,9 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
/// <returns>Return's <b>HRESULT</b> error code.</returns>
|
||||
///
|
||||
[PreserveSig]
|
||||
int ConnectDirect([In] IPin pinOut, [In] IPin pinIn, [In, MarshalAs(UnmanagedType.LPStruct)] AMMediaType mediaType);
|
||||
int ConnectDirect([In] IPin pinOut, [In] IPin pinIn,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)]
|
||||
AMMediaType mediaType);
|
||||
|
||||
/// <summary>
|
||||
/// Breaks the existing pin connection and reconnects it to the same pin.
|
||||
@@ -226,7 +228,8 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
[PreserveSig]
|
||||
int ReconnectEx(
|
||||
[In] IPin pin,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)] AMMediaType mediaType
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)]
|
||||
AMMediaType mediaType
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
@@ -245,6 +248,5 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
[In] int flags,
|
||||
[In] IntPtr context
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,9 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
/// <returns>Return's <b>HRESULT</b> error code.</returns>
|
||||
///
|
||||
[PreserveSig]
|
||||
int ConnectDirect([In] IPin pinOut, [In] IPin pinIn, [In, MarshalAs(UnmanagedType.LPStruct)] AMMediaType mediaType);
|
||||
int ConnectDirect([In] IPin pinOut, [In] IPin pinIn,
|
||||
[In, MarshalAs(UnmanagedType.LPStruct)]
|
||||
AMMediaType mediaType);
|
||||
|
||||
/// <summary>
|
||||
/// Breaks the existing pin connection and reconnects it to the same pin.
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
namespace VAR.Toolbox.Code.DirectShow
|
||||
{
|
||||
using System;
|
||||
#pragma warning disable IDE1006
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace VAR.Toolbox.Code.DirectShow
|
||||
{
|
||||
/// <summary>
|
||||
/// The interface provides methods for controlling the flow of data through the filter graph.
|
||||
/// It includes methods for running, pausing, and stopping the graph.
|
||||
@@ -45,7 +46,7 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="timeout">Duration of the time-out, in milliseconds, or INFINITE to specify an infinite time-out.</param>
|
||||
/// <param name="filterState">Ìariable that receives a member of the <b>FILTER_STATE</b> enumeration.</param>
|
||||
/// <param name="filterState">Variable that receives a member of the <b>FILTER_STATE</b> enumeration.</param>
|
||||
///
|
||||
/// <returns>Return's <b>HRESULT</b> error code.</returns>
|
||||
///
|
||||
@@ -85,7 +86,8 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
///
|
||||
[PreserveSig]
|
||||
int get_FilterCollection(
|
||||
[Out, MarshalAs(UnmanagedType.IDispatch)] out object collection);
|
||||
[Out, MarshalAs(UnmanagedType.IDispatch)]
|
||||
out object collection);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a collection of all the filters listed in the registry.
|
||||
@@ -97,7 +99,8 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
///
|
||||
[PreserveSig]
|
||||
int get_RegFilterCollection(
|
||||
[Out, MarshalAs(UnmanagedType.IDispatch)] out object collection);
|
||||
[Out, MarshalAs(UnmanagedType.IDispatch)]
|
||||
out object collection);
|
||||
|
||||
/// <summary>
|
||||
/// Pauses the filter graph, allowing filters to queue data, and then stops the filter graph.
|
||||
|
||||
@@ -34,7 +34,8 @@
|
||||
/// <returns>Return's <b>HRESULT</b> error code.</returns>
|
||||
///
|
||||
[PreserveSig]
|
||||
int GetEvent([Out, MarshalAs(UnmanagedType.I4)] out DsEvCode lEventCode, [Out] out IntPtr lParam1, [Out] out IntPtr lParam2, int msTimeout);
|
||||
int GetEvent([Out, MarshalAs(UnmanagedType.I4)] out DsEvCode lEventCode, [Out] out IntPtr lParam1,
|
||||
[Out] out IntPtr lParam2, int msTimeout);
|
||||
|
||||
/// <summary>
|
||||
/// Waits for the filter graph to render all available data.
|
||||
@@ -85,14 +86,14 @@
|
||||
/// Registers a window to process event notifications.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="hwnd">Handle to the window, or <see cref="IntPtr.Zero"/> to stop receiving event messages.</param>
|
||||
/// <param name="hWnd">Handle to the window, or <see cref="IntPtr.Zero"/> to stop receiving event messages.</param>
|
||||
/// <param name="lMsg">Window message to be passed as the notification.</param>
|
||||
/// <param name="lInstanceData">Value to be passed as the <i>lParam</i> parameter for the <i>lMsg</i> message.</param>
|
||||
///
|
||||
/// <returns>Return's <b>HRESULT</b> error code.</returns>
|
||||
///
|
||||
[PreserveSig]
|
||||
int SetNotifyWindow(IntPtr hwnd, int lMsg, IntPtr lInstanceData);
|
||||
int SetNotifyWindow(IntPtr hWnd, int lMsg, IntPtr lInstanceData);
|
||||
|
||||
/// <summary>
|
||||
/// Enables or disables event notifications.
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// ReSharper disable IdentifierTypo
|
||||
|
||||
namespace VAR.Toolbox.Code.DirectShow
|
||||
{
|
||||
using System;
|
||||
@@ -88,4 +90,3 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
int GetSyncSource([Out] out IReferenceClock pClock);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,8 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
[PreserveSig]
|
||||
int Read(
|
||||
[In, MarshalAs(UnmanagedType.LPWStr)] string propertyName,
|
||||
[In, Out, MarshalAs(UnmanagedType.Struct)] ref object pVar,
|
||||
[In, Out, MarshalAs(UnmanagedType.Struct)]
|
||||
ref object pVar,
|
||||
[In] IntPtr pErrorLog);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// ReSharper disable CommentTypo
|
||||
// ReSharper disable IdentifierTypo
|
||||
|
||||
namespace VAR.Toolbox.Code.DirectShow
|
||||
{
|
||||
using System;
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
int SampleCB(double sampleTime, IntPtr sample);
|
||||
|
||||
/// <summary>
|
||||
/// Callback method that receives a pointer to the sample bufferþ
|
||||
/// Callback method that receives a pointer to the sample buffer
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="sampleTime">Starting time of the sample, in seconds.</param>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// ReSharper disable CommentTypo
|
||||
|
||||
namespace VAR.Toolbox.Code.DirectShow
|
||||
{
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
namespace VAR.Toolbox.Code.DirectShow
|
||||
{
|
||||
#pragma warning disable IDE1006
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace VAR.Toolbox.Code.DirectShow
|
||||
{
|
||||
/// <summary>
|
||||
/// The interface sets properties on the video window.
|
||||
/// </summary>
|
||||
@@ -93,7 +95,7 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
/// Queries whether the video renderer automatically shows the video window when it receives video data.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="autoShow">REceives window auto show flag.</param>
|
||||
/// <param name="autoShow">Receives window auto show flag.</param>
|
||||
///
|
||||
/// <returns>Return's <b>HRESULT</b> error code.</returns>
|
||||
///
|
||||
@@ -255,7 +257,7 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
int get_Height(out int height);
|
||||
|
||||
/// <summary>
|
||||
/// Specifies a parent window for the video windowþ
|
||||
/// Specifies a parent window for the video window
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="owner">Specifies a handle to the parent window.</param>
|
||||
@@ -266,7 +268,7 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
int put_Owner(IntPtr owner);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the video window's parent window, if anyþ
|
||||
/// Retrieves the video window's parent window, if any
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="owner">Parent window's handle.</param>
|
||||
@@ -358,7 +360,7 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
/// Forwards a message to the video window.
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="hwnd">Handle to the window.</param>
|
||||
/// <param name="hWnd">Handle to the window.</param>
|
||||
/// <param name="msg">Specifies the message.</param>
|
||||
/// <param name="wParam">Message parameter.</param>
|
||||
/// <param name="lParam">Message parameter.</param>
|
||||
@@ -366,10 +368,10 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
/// <returns>Return's <b>HRESULT</b> error code.</returns>
|
||||
///
|
||||
[PreserveSig]
|
||||
int NotifyOwnerMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam);
|
||||
int NotifyOwnerMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the position of the video windowþ
|
||||
/// Sets the position of the video window
|
||||
/// </summary>
|
||||
///
|
||||
/// <param name="left">Specifies the x-coordinate, in pixels.</param>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace VAR.Toolbox.Code.DirectShow
|
||||
// ReSharper disable CommentTypo
|
||||
|
||||
namespace VAR.Toolbox.Code.DirectShow
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies the physical type of pin (audio or video).
|
||||
@@ -10,62 +12,77 @@
|
||||
/// connection type should not be changed (input) or was not determined (output).
|
||||
/// </summary>
|
||||
Default = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies a tuner pin for video.
|
||||
/// </summary>
|
||||
VideoTuner = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies a composite pin for video.
|
||||
/// </summary>
|
||||
VideoComposite,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies an S-Video (Y/C video) pin.
|
||||
/// </summary>
|
||||
VideoSVideo,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies an RGB pin for video.
|
||||
/// </summary>
|
||||
VideoRGB,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies a YRYBY (Y, R–Y, B–Y) pin for video.
|
||||
/// </summary>
|
||||
VideoYRYBY,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies a serial digital pin for video.
|
||||
/// </summary>
|
||||
VideoSerialDigital,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies a parallel digital pin for video.
|
||||
/// </summary>
|
||||
VideoParallelDigital,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies a SCSI (Small Computer System Interface) pin for video.
|
||||
/// </summary>
|
||||
VideoSCSI,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies an AUX (auxiliary) pin for video.
|
||||
/// </summary>
|
||||
VideoAUX,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies an IEEE 1394 pin for video.
|
||||
/// </summary>
|
||||
Video1394,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies a USB (Universal Serial Bus) pin for video.
|
||||
/// </summary>
|
||||
VideoUSB,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies a video decoder pin.
|
||||
/// </summary>
|
||||
VideoDecoder,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies a video encoder pin.
|
||||
/// </summary>
|
||||
VideoEncoder,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies a SCART (Peritel) pin for video.
|
||||
/// </summary>
|
||||
VideoSCART,
|
||||
|
||||
/// <summary>
|
||||
/// Not used.
|
||||
/// </summary>
|
||||
@@ -75,38 +92,47 @@
|
||||
/// Specifies a tuner pin for audio.
|
||||
/// </summary>
|
||||
AudioTuner = 4096,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies a line pin for audio.
|
||||
/// </summary>
|
||||
AudioLine,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies a microphone pin.
|
||||
/// </summary>
|
||||
AudioMic,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies an AES/EBU (Audio Engineering Society/European Broadcast Union) digital pin for audio.
|
||||
/// </summary>
|
||||
AudioAESDigital,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies an S/PDIF (Sony/Philips Digital Interface Format) digital pin for audio.
|
||||
/// </summary>
|
||||
AudioSPDIFDigital,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies a SCSI pin for audio.
|
||||
/// </summary>
|
||||
AudioSCSI,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies an AUX pin for audio.
|
||||
/// </summary>
|
||||
AudioAUX,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies an IEEE 1394 pin for audio.
|
||||
/// </summary>
|
||||
Audio1394,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies a USB pin for audio.
|
||||
/// </summary>
|
||||
AudioUSB,
|
||||
|
||||
/// <summary>
|
||||
/// Specifies an audio decoder pin.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
// ReSharper disable IdentifierTypo
|
||||
// ReSharper disable CommentTypo
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace VAR.Toolbox.Code.DirectShow
|
||||
{
|
||||
using System;
|
||||
@@ -47,14 +51,12 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
/// <summary>
|
||||
/// If <b>true</b>, samples are of a fixed size.
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.Bool)]
|
||||
public bool FixedSizeSamples = true;
|
||||
[MarshalAs(UnmanagedType.Bool)] public bool FixedSizeSamples = true;
|
||||
|
||||
/// <summary>
|
||||
/// If <b>true</b>, samples are compressed using temporal (interframe) compression.
|
||||
/// </summary>
|
||||
[MarshalAs(UnmanagedType.Bool)]
|
||||
public bool TemporalCompression;
|
||||
[MarshalAs(UnmanagedType.Bool)] public bool TemporalCompression;
|
||||
|
||||
/// <summary>
|
||||
/// Size of the sample in bytes. For compressed data, the value can be zero.
|
||||
@@ -429,6 +431,7 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
[Flags, ComVisible(false)]
|
||||
internal enum AnalogVideoStandard
|
||||
{
|
||||
// ReSharper disable InconsistentNaming
|
||||
None = 0x00000000, // This is a digital sensor
|
||||
NTSC_M = 0x00000001, // 75 IRE Setup
|
||||
NTSC_M_J = 0x00000002, // Japan, 0 IRE Setup
|
||||
@@ -449,7 +452,9 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
SECAM_K1 = 0x00020000,
|
||||
SECAM_L = 0x00040000,
|
||||
SECAM_L1 = 0x00080000,
|
||||
|
||||
PAL_N_COMBO = 0x00100000 // Argentina
|
||||
// ReSharper restore InconsistentNaming
|
||||
}
|
||||
|
||||
[Flags, ComVisible(false)]
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
namespace VAR.Toolbox.Code.DirectShow
|
||||
{
|
||||
#pragma warning disable IDE0018
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace VAR.Toolbox.Code.DirectShow
|
||||
{
|
||||
/// <summary>
|
||||
/// Some miscellaneous functions.
|
||||
/// </summary>
|
||||
@@ -18,24 +20,20 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
///
|
||||
/// <returns>Returns filter's pin.</returns>
|
||||
///
|
||||
public static IPin GetPin(IBaseFilter filter, PinDirection dir, int num)
|
||||
private static IPin GetPin(IBaseFilter filter, PinDirection dir, int num)
|
||||
{
|
||||
IPin[] pin = new IPin[1];
|
||||
IEnumPins pinsEnum = null;
|
||||
|
||||
// enum filter pins
|
||||
if (filter.EnumPins(out pinsEnum) == 0)
|
||||
if (filter.EnumPins(out IEnumPins pinsEnum) == 0)
|
||||
{
|
||||
PinDirection pinDir;
|
||||
int n;
|
||||
|
||||
try
|
||||
{
|
||||
// get next pin
|
||||
while (pinsEnum.Next(1, pin, out n) == 0)
|
||||
while (pinsEnum.Next(1, pin, out int _) == 0)
|
||||
{
|
||||
// query pin`s direction
|
||||
pin[0].QueryDirection(out pinDir);
|
||||
pin[0].QueryDirection(out PinDirection pinDir);
|
||||
|
||||
if (pinDir == dir)
|
||||
{
|
||||
@@ -53,6 +51,7 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
Marshal.ReleaseComObject(pinsEnum);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
// ReSharper disable CommentTypo
|
||||
|
||||
// ReSharper disable IdentifierTypo
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace VAR.Toolbox.Code.DirectShow
|
||||
{
|
||||
using System;
|
||||
@@ -7,7 +12,7 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
/// DirectShow class IDs.
|
||||
/// </summary>
|
||||
[ComVisible(false)]
|
||||
static internal class Clsid
|
||||
internal static class Clsid
|
||||
{
|
||||
/// <summary>
|
||||
/// System device enumerator.
|
||||
@@ -57,7 +62,6 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
|
||||
public static readonly Guid NullRenderer =
|
||||
new Guid(0xC1F400A4, 0x3F08, 0x11d3, 0x9F, 0x0B, 0x00, 0x60, 0x08, 0x03, 0x9E, 0x37);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -65,7 +69,7 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
/// </summary>
|
||||
///
|
||||
[ComVisible(false)]
|
||||
static internal class FormatType
|
||||
internal static class FormatType
|
||||
{
|
||||
/// <summary>
|
||||
/// VideoInfo.
|
||||
@@ -91,7 +95,7 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
/// </summary>
|
||||
///
|
||||
[ComVisible(false)]
|
||||
static internal class MediaType
|
||||
internal static class MediaType
|
||||
{
|
||||
/// <summary>
|
||||
/// Video.
|
||||
@@ -144,7 +148,7 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
/// </summary>
|
||||
///
|
||||
[ComVisible(false)]
|
||||
static internal class MediaSubType
|
||||
internal static class MediaSubType
|
||||
{
|
||||
/// <summary>
|
||||
/// YUY2 (packed 4:2:2).
|
||||
@@ -260,7 +264,7 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
/// </summary>
|
||||
///
|
||||
[ComVisible(false)]
|
||||
static internal class PinCategory
|
||||
internal static class PinCategory
|
||||
{
|
||||
/// <summary>
|
||||
/// Capture pin.
|
||||
@@ -279,7 +283,6 @@ namespace VAR.Toolbox.Code.DirectShow
|
||||
///
|
||||
public static readonly Guid Preview =
|
||||
new Guid(0xfb6c4282, 0x0353, 0x11d1, 0x90, 0x5f, 0x00, 0x00, 0xc0, 0xcc, 0x16, 0xba);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
40
VAR.Toolbox/Code/EventDispatcher.cs
Normal file
40
VAR.Toolbox/Code/EventDispatcher.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public static class EventDispatcher
|
||||
{
|
||||
private static List<IEventListener> _eventListeners;
|
||||
|
||||
private static IEnumerable<IEventListener> GetEventListeners()
|
||||
{
|
||||
if (_eventListeners != null)
|
||||
{
|
||||
return _eventListeners;
|
||||
}
|
||||
|
||||
Type iEventListener = typeof(IEventListener);
|
||||
IEnumerable<Type> eventListeners = ReflectionUtils.GetTypesOfInterface(iEventListener);
|
||||
_eventListeners = new List<IEventListener>();
|
||||
foreach (Type eventListener in eventListeners)
|
||||
{
|
||||
if (Activator.CreateInstance(eventListener) is IEventListener eventListenerInstance)
|
||||
{
|
||||
_eventListeners.Add(eventListenerInstance);
|
||||
}
|
||||
}
|
||||
|
||||
return _eventListeners;
|
||||
}
|
||||
|
||||
public static void EmitEvent(string eventName, object eventData)
|
||||
{
|
||||
IEnumerable<IEventListener> eventListeners = GetEventListeners();
|
||||
foreach (IEventListener eventListener in eventListeners)
|
||||
{
|
||||
eventListener.ProcessEvent(eventName, eventData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
121
VAR.Toolbox/Code/GlobalKeyboardHook.cs
Normal file
121
VAR.Toolbox/Code/GlobalKeyboardHook.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Windows.Forms;
|
||||
using VAR.Toolbox.Code.Windows;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public class GlobalKeyboardHook
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
private bool _capturing = false;
|
||||
private bool _captureAll = false;
|
||||
|
||||
/// <summary>
|
||||
/// The collections of keys to watch for
|
||||
/// </summary>
|
||||
private readonly List<Keys> _hookedKeys = new List<Keys>();
|
||||
|
||||
/// <summary>
|
||||
/// Handle to the hook, need this to unhook and call the next hook
|
||||
/// </summary>
|
||||
private IntPtr _hHook = IntPtr.Zero;
|
||||
|
||||
#endregion Declarations
|
||||
|
||||
#region Private methods
|
||||
|
||||
/// <summary>
|
||||
/// The callback for the keyboard hook
|
||||
/// </summary>
|
||||
/// <param name="code">The hook code, if it isn't >= 0, the function shouldn't do anyting</param>
|
||||
/// <param name="wParam">The event type</param>
|
||||
/// <param name="lParam">The keyhook event information</param>
|
||||
/// <returns></returns>
|
||||
private int HookProc(int code, int wParam, ref User32.keyboardHookStruct lParam) {
|
||||
try
|
||||
{
|
||||
if (code >= 0)
|
||||
{
|
||||
Keys key = (Keys)lParam.vkCode;
|
||||
if (_hookedKeys.Contains(key) || _captureAll)
|
||||
{
|
||||
KeyEventArgs kea = new KeyEventArgs(key);
|
||||
if ((wParam == User32.WM_KEYDOWN || wParam == User32.WM_SYSKEYDOWN) && (KeyDown != null))
|
||||
{
|
||||
KeyDown(this, kea);
|
||||
}
|
||||
else if ((wParam == User32.WM_KEYUP || wParam == User32.WM_SYSKEYUP) && (KeyUp != null))
|
||||
{
|
||||
KeyUp(this, kea);
|
||||
}
|
||||
|
||||
if (kea.Handled)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
|
||||
return User32.CallNextHookEx(_hHook, code, wParam, ref lParam);
|
||||
}
|
||||
|
||||
#endregion Private methods
|
||||
|
||||
#region Public events
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when one of the hooked keys is pressed
|
||||
/// </summary>
|
||||
public event KeyEventHandler KeyDown;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when one of the hooked keys is released
|
||||
/// </summary>
|
||||
public event KeyEventHandler KeyUp;
|
||||
|
||||
#endregion Public events
|
||||
|
||||
#region Public methods
|
||||
|
||||
public void Start(bool all = false)
|
||||
{
|
||||
if (_capturing) { return; }
|
||||
|
||||
_captureAll = all;
|
||||
|
||||
//IntPtr hInstance = User32.LoadLibrary("User32");
|
||||
//_hHook = User32.SetWindowsHookEx(User32.WH_KEYBOARD_LL, HookProc, hInstance, 0);
|
||||
IntPtr iModule = System.Runtime.InteropServices.Marshal.GetHINSTANCE(
|
||||
System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0]);
|
||||
_hHook = User32.SetWindowsHookEx(User32.WH_KEYBOARD_LL, HookProc, iModule, 0);
|
||||
|
||||
_capturing = true;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (_capturing == false) { return; }
|
||||
|
||||
User32.UnhookWindowsHookEx(_hHook);
|
||||
_capturing = false;
|
||||
}
|
||||
|
||||
public bool IsCapturing()
|
||||
{
|
||||
return _capturing;
|
||||
}
|
||||
|
||||
public void AddHook(Keys key)
|
||||
{
|
||||
_hookedKeys.Add(key);
|
||||
}
|
||||
|
||||
#endregion Public methods
|
||||
}
|
||||
}
|
||||
@@ -3,17 +3,20 @@ using System.Text;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public class HexUtils
|
||||
public static class HexUtils
|
||||
{
|
||||
public static byte[] HexStringToBytes(string input)
|
||||
{
|
||||
int[] hexValues = new int[] {
|
||||
int[] hexValues = new int[]
|
||||
{
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
|
||||
};
|
||||
if (input.Length % 2 == 1)
|
||||
{
|
||||
throw new Exception("Unenven number of hex digits");
|
||||
throw new Exception("Uneven number of hex digits");
|
||||
}
|
||||
|
||||
byte[] bytes = new byte[input.Length / 2];
|
||||
int count = input.Length;
|
||||
for (int x = 0, i = 0; i < count; i += 2, x += 1)
|
||||
@@ -38,6 +41,7 @@ namespace VAR.Toolbox.Code
|
||||
sbOutput.Append(HexAlphabet[(b >> 4)]);
|
||||
sbOutput.Append(HexAlphabet[(b & 0xF)]);
|
||||
}
|
||||
|
||||
return sbOutput.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
7
VAR.Toolbox/Code/IEventListener.cs
Normal file
7
VAR.Toolbox/Code/IEventListener.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public interface IEventListener
|
||||
{
|
||||
void ProcessEvent(string eventName, object eventData);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
{
|
||||
public interface IOutputHandler
|
||||
{
|
||||
void OutputLine(string line);
|
||||
void Clean();
|
||||
void AddLine(string line, object data = null);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public interface IProxyCmdExecutor
|
||||
{
|
||||
bool ExecuteCmd(string cmd, IOutputHandler outputHandler);
|
||||
}
|
||||
}
|
||||
@@ -3,22 +3,21 @@ using System.IO;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public class Logger
|
||||
public static class Logger
|
||||
{
|
||||
/// <summary>
|
||||
/// Obtiene el StreamWritter de salida
|
||||
/// Obtiene el StreamWriter de salida
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static StreamWriter GetOutputStreamWritter()
|
||||
private static StreamWriter GetOutputStreamWriter()
|
||||
{
|
||||
try
|
||||
{
|
||||
string location = System.Reflection.Assembly.GetEntryAssembly().Location;
|
||||
string location = System.Reflection.Assembly.GetEntryAssembly()?.Location;
|
||||
string path = Path.GetDirectoryName(location);
|
||||
string filenameWithoutExtension = Path.GetFileNameWithoutExtension(location);
|
||||
|
||||
string fileOut = string.Format("{0}/{1}.{2}.txt", path, filenameWithoutExtension,
|
||||
DateTime.UtcNow.ToString("yyyy-MM"));
|
||||
string fileOut = $"{path}/{filenameWithoutExtension}.{DateTime.UtcNow:yyyy-MM}.txt";
|
||||
return File.AppendText(fileOut);
|
||||
}
|
||||
catch (Exception)
|
||||
@@ -28,10 +27,10 @@ namespace VAR.Toolbox.Code
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cierra el StreamWritter de salida
|
||||
/// Cierra el StreamWriter de salida
|
||||
/// </summary>
|
||||
/// <param name="stream">The stream.</param>
|
||||
private static void CloseOutputStreamWritter(StreamWriter stream)
|
||||
private static void CloseOutputStreamWriter(StreamWriter stream)
|
||||
{
|
||||
if (stream != null)
|
||||
{
|
||||
@@ -50,6 +49,7 @@ namespace VAR.Toolbox.Code
|
||||
{
|
||||
stream.WriteLine(line);
|
||||
}
|
||||
|
||||
Console.Out.WriteLine(line);
|
||||
}
|
||||
|
||||
@@ -57,60 +57,70 @@ namespace VAR.Toolbox.Code
|
||||
/// Logea el marcador
|
||||
/// </summary>
|
||||
/// <param name="text">The text.</param>
|
||||
public static void Marker(String text)
|
||||
public static void Marker(string text)
|
||||
{
|
||||
try
|
||||
{
|
||||
StreamWriter outStream = GetOutputStreamWritter();
|
||||
StreamWriter outStream = GetOutputStreamWriter();
|
||||
WriteLine(outStream, string.Empty);
|
||||
WriteLine(outStream, String.Format("---------------------------- {0} -----------------------", text));
|
||||
WriteLine(outStream, String.Format("\\- Date: {0}", DateTime.UtcNow.ToString("s")));
|
||||
WriteLine(outStream, $"---------------------------- {text} -----------------------");
|
||||
WriteLine(outStream, $"\\- Date: {DateTime.UtcNow:s}");
|
||||
WriteLine(outStream, string.Empty);
|
||||
CloseOutputStreamWritter(outStream);
|
||||
CloseOutputStreamWriter(outStream);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
/* Nom Nom Nom */
|
||||
}
|
||||
catch (Exception) { /* Nom Nom Nom */}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Logea el texto especificado
|
||||
/// </summary>
|
||||
/// <param name="text">The text.</param>
|
||||
public static void Log(String text)
|
||||
public static void Log(string text)
|
||||
{
|
||||
try
|
||||
{
|
||||
StreamWriter outStream = GetOutputStreamWritter();
|
||||
WriteLine(outStream, String.Format("{0} -- {1}", DateTime.UtcNow.ToString("s"), text));
|
||||
CloseOutputStreamWritter(outStream);
|
||||
StreamWriter outStream = GetOutputStreamWriter();
|
||||
WriteLine(outStream, $"{DateTime.UtcNow:s} -- {text}");
|
||||
CloseOutputStreamWriter(outStream);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
/* Nom Nom Nom */
|
||||
}
|
||||
catch (Exception) { /* Nom Nom Nom */}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Logea una excepcion
|
||||
/// Logea una excepción
|
||||
/// </summary>
|
||||
/// <param name="ex">The Exception.</param>
|
||||
public static void Log(Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
StreamWriter outStream = GetOutputStreamWritter();
|
||||
StreamWriter outStream = GetOutputStreamWriter();
|
||||
WriteLine(outStream, string.Empty);
|
||||
WriteLine(outStream, String.Format("!!!!!!!!!!!!!!!!!!!!!!!!!!!! {0} !!!!!!!!!!!!!!!!!!!!!!!", "Exception"));
|
||||
WriteLine(outStream, String.Format("\\- Date: {0}", DateTime.UtcNow.ToString("s")));
|
||||
WriteLine(outStream,
|
||||
"!!!!!!!!!!!!!!!!!!!!!!!!!!!! Exception !!!!!!!!!!!!!!!!!!!!!!!");
|
||||
WriteLine(outStream, $"\\- Date: {DateTime.UtcNow:s}");
|
||||
WriteLine(outStream, string.Empty);
|
||||
Exception exAux = ex;
|
||||
while (exAux != null)
|
||||
{
|
||||
WriteLine(outStream, String.Format("Message: {0}", exAux.Message));
|
||||
WriteLine(outStream, String.Format("Stacktrace: {0}", exAux.StackTrace));
|
||||
WriteLine(outStream, $"Message: {exAux.Message}");
|
||||
WriteLine(outStream, $"Stacktrace: {exAux.StackTrace}");
|
||||
exAux = exAux.InnerException;
|
||||
}
|
||||
CloseOutputStreamWritter(outStream);
|
||||
}
|
||||
catch (Exception) { /* Nom Nom Nom */}
|
||||
}
|
||||
|
||||
CloseOutputStreamWriter(outStream);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
/* Nom Nom Nom */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,16 +4,18 @@ using VAR.Toolbox.Code.Windows;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public class Mouse
|
||||
public static class Mouse
|
||||
{
|
||||
public static void Move(int dx, int dy)
|
||||
{
|
||||
User32.INPUT input = new User32.INPUT();
|
||||
input.Type = User32.INPUT_MOUSE;
|
||||
User32.INPUT input = new User32.INPUT
|
||||
{
|
||||
Type = User32.INPUT_MOUSE
|
||||
};
|
||||
input.Data.Mouse.X = dx;
|
||||
input.Data.Mouse.Y = dy;
|
||||
input.Data.Mouse.Flags = User32.MOUSEEVENTF_MOVE;
|
||||
User32.INPUT[] inputs = new User32.INPUT[] { input };
|
||||
User32.INPUT[] inputs = new[] { input };
|
||||
if (User32.SendInput(1, inputs, Marshal.SizeOf(typeof(User32.INPUT))) == 0)
|
||||
throw new Exception();
|
||||
}
|
||||
@@ -27,23 +29,28 @@ namespace VAR.Toolbox.Code
|
||||
|
||||
public static void SetButton(MouseButtons button, bool down)
|
||||
{
|
||||
User32.INPUT input = new User32.INPUT();
|
||||
input.Type = User32.INPUT_MOUSE;
|
||||
User32.INPUT input = new User32.INPUT
|
||||
{
|
||||
Type = User32.INPUT_MOUSE
|
||||
};
|
||||
input.Data.Mouse.X = 0;
|
||||
input.Data.Mouse.Y = 0;
|
||||
if (button == MouseButtons.Left)
|
||||
{
|
||||
input.Data.Mouse.Flags = down ? User32.MOUSEEVENTF_LEFTDOWN : User32.MOUSEEVENTF_LEFTUP;
|
||||
}
|
||||
|
||||
if (button == MouseButtons.Middle)
|
||||
{
|
||||
input.Data.Mouse.Flags = down ? User32.MOUSEEVENTF_MIDDLEDOWN : User32.MOUSEEVENTF_MIDDLEUP;
|
||||
}
|
||||
|
||||
if (button == MouseButtons.Right)
|
||||
{
|
||||
input.Data.Mouse.Flags = down ? User32.MOUSEEVENTF_RIGHTDOWN : User32.MOUSEEVENTF_RIGHTUP;
|
||||
}
|
||||
User32.INPUT[] inputs = new User32.INPUT[] { input };
|
||||
|
||||
User32.INPUT[] inputs = new[] { input };
|
||||
if (User32.SendInput(1, inputs, Marshal.SizeOf(typeof(User32.INPUT))) == 0)
|
||||
throw new Exception();
|
||||
}
|
||||
@@ -57,8 +64,7 @@ namespace VAR.Toolbox.Code
|
||||
|
||||
public static void GetPosition(out UInt32 x, out UInt32 y)
|
||||
{
|
||||
User32.POINT lpPoint;
|
||||
User32.GetCursorPos(out lpPoint);
|
||||
User32.GetCursorPos(out User32.POINT lpPoint);
|
||||
x = lpPoint.X;
|
||||
y = lpPoint.Y;
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public class ProxyCmdExecutorDummy : IProxyCmdExecutor
|
||||
{
|
||||
public bool ExecuteCmd(string cmdString, IOutputHandler outputHandler)
|
||||
{
|
||||
outputHandler.OutputLine(string.Format("DummyExecution: {0}", cmdString));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public class ProxyCmdExecutorFactory
|
||||
{
|
||||
public static IProxyCmdExecutor CreateFromConfig(string config)
|
||||
{
|
||||
if (string.IsNullOrEmpty(config) || config.StartsWith("Dummy:"))
|
||||
{
|
||||
return new ProxyCmdExecutorDummy();
|
||||
}
|
||||
if (config.StartsWith("SqlServer:"))
|
||||
{
|
||||
string configSqlServer = config.Substring("SqlServer:".Length);
|
||||
return new ProxyCmdExecutorThroughSQLServer(configSqlServer);
|
||||
}
|
||||
if (config.StartsWith("WMIC:"))
|
||||
{
|
||||
string configWMIC = config.Substring("WMIC:".Length);
|
||||
return new ProxyCmdExecutorWMIC(configWMIC);
|
||||
}
|
||||
throw new NotImplementedException(string.Format("Cant create IProxyCmdExecutor with this config: {0}", config));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
using System;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public class ProxyCmdExecutorThroughSQLServer : IProxyCmdExecutor
|
||||
{
|
||||
private string _connectionString = null;
|
||||
|
||||
public ProxyCmdExecutorThroughSQLServer(string connectionString)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
}
|
||||
|
||||
public bool ExecuteCmd(string cmdString, IOutputHandler outputHandler)
|
||||
{
|
||||
SqlConnection cnx = new SqlConnection(_connectionString);
|
||||
SqlCommand cmd = cnx.CreateCommand();
|
||||
cmd.CommandText = "exec master.dbo.xp_cmdshell @cmd";
|
||||
cmd.Parameters.Add(new SqlParameter("cmd", cmdString));
|
||||
cnx.Open();
|
||||
SqlDataReader reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
string output = Convert.ToString(reader[0]);
|
||||
outputHandler.OutputLine(output);
|
||||
}
|
||||
cnx.Close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
VAR.Toolbox/Code/ProxyCmdExecutors/BaseProxyCmdExecutor.cs
Normal file
21
VAR.Toolbox/Code/ProxyCmdExecutors/BaseProxyCmdExecutor.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
|
||||
namespace VAR.Toolbox.Code.ProxyCmdExecutors
|
||||
{
|
||||
public abstract class BaseProxyCmdExecutor : IProxyCmdExecutor
|
||||
{
|
||||
public abstract string Name { get; }
|
||||
|
||||
public virtual bool Disable()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public virtual bool Enable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract bool ExecuteCmd(string cmd, IOutputHandler outputHandler);
|
||||
}
|
||||
}
|
||||
11
VAR.Toolbox/Code/ProxyCmdExecutors/IProxyCmdExecutor.cs
Normal file
11
VAR.Toolbox/Code/ProxyCmdExecutors/IProxyCmdExecutor.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace VAR.Toolbox.Code.ProxyCmdExecutors
|
||||
{
|
||||
public interface IProxyCmdExecutor : INamed
|
||||
{
|
||||
bool ExecuteCmd(string cmd, IOutputHandler outputHandler);
|
||||
|
||||
bool Enable();
|
||||
|
||||
bool Disable();
|
||||
}
|
||||
}
|
||||
24
VAR.Toolbox/Code/ProxyCmdExecutors/ProxyCmdExecutorDummy.cs
Normal file
24
VAR.Toolbox/Code/ProxyCmdExecutors/ProxyCmdExecutorDummy.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
namespace VAR.Toolbox.Code.ProxyCmdExecutors
|
||||
{
|
||||
public class ProxyCmdExecutorDummy : BaseProxyCmdExecutor
|
||||
{
|
||||
private readonly string _config;
|
||||
public override string Name => "Dummy";
|
||||
|
||||
public ProxyCmdExecutorDummy(string config)
|
||||
{
|
||||
if (config == null)
|
||||
{
|
||||
throw new System.ArgumentNullException(nameof(config));
|
||||
}
|
||||
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public override bool ExecuteCmd(string cmdString, IOutputHandler outputHandler)
|
||||
{
|
||||
outputHandler.AddLine($"DummyExecution: {cmdString} | {_config}");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
namespace VAR.Toolbox.Code.ProxyCmdExecutors
|
||||
{
|
||||
public abstract class ProxyCmdExecutorFactory : BaseFactory<IProxyCmdExecutor> { }
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace VAR.Toolbox.Code.ProxyCmdExecutors
|
||||
{
|
||||
public class ProxyCmdExecutorThroughSQLServer : BaseProxyCmdExecutor
|
||||
{
|
||||
public override string Name => "SqlServer";
|
||||
|
||||
private readonly string _connectionString;
|
||||
|
||||
public ProxyCmdExecutorThroughSQLServer(string connectionString)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
}
|
||||
|
||||
public override bool ExecuteCmd(string cmdString, IOutputHandler outputHandler)
|
||||
{
|
||||
SqlConnection cnx = new SqlConnection(_connectionString);
|
||||
SqlCommand cmd = cnx.CreateCommand();
|
||||
cmd.CommandText = "exec master.dbo.xp_cmdshell @cmd";
|
||||
cmd.Parameters.Add(new SqlParameter("cmd", cmdString));
|
||||
cnx.Open();
|
||||
SqlDataReader reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
string output = Convert.ToString(reader[0]);
|
||||
outputHandler.AddLine(output);
|
||||
}
|
||||
|
||||
cnx.Close();
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Enable()
|
||||
{
|
||||
try
|
||||
{
|
||||
SqlConnection cnx = new SqlConnection(_connectionString);
|
||||
SqlCommand cmd = cnx.CreateCommand();
|
||||
cmd.CommandText = @"
|
||||
EXEC sp_configure 'show advanced options', '1'
|
||||
RECONFIGURE
|
||||
EXEC sp_configure 'xp_cmdshell', '1'
|
||||
RECONFIGURE
|
||||
";
|
||||
cnx.Open();
|
||||
cmd.ExecuteNonQuery();
|
||||
cnx.Close();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Disable()
|
||||
{
|
||||
try
|
||||
{
|
||||
SqlConnection cnx = new SqlConnection(_connectionString);
|
||||
SqlCommand cmd = cnx.CreateCommand();
|
||||
cmd.CommandText = @"
|
||||
EXEC sp_configure 'show advanced options', '1'
|
||||
RECONFIGURE
|
||||
EXEC sp_configure 'xp_cmdshell', '0'
|
||||
RECONFIGURE
|
||||
";
|
||||
cnx.Open();
|
||||
cmd.ExecuteNonQuery();
|
||||
cnx.Close();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,22 @@
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
namespace VAR.Toolbox.Code.ProxyCmdExecutors
|
||||
{
|
||||
public class ProxyCmdExecutorWMIC : IProxyCmdExecutor
|
||||
public class ProxyCmdExecutorWMIC : BaseProxyCmdExecutor
|
||||
{
|
||||
private string _configWMIC;
|
||||
public override string Name => "WMIC";
|
||||
|
||||
private readonly string _configWMIC;
|
||||
|
||||
public ProxyCmdExecutorWMIC(string configWMIC)
|
||||
{
|
||||
_configWMIC = configWMIC;
|
||||
}
|
||||
|
||||
public bool ExecuteCmd(string cmd, IOutputHandler outputHandler)
|
||||
public override bool ExecuteCmd(string cmd, IOutputHandler outputHandler)
|
||||
{
|
||||
string parameters = string.Format(" /node:\"{0}\" process call create \"cmd.exe /c \\\"{1}\\\"\"", _configWMIC.Replace("\"", "\\\""), cmd.Replace("\"", "\\\""));
|
||||
string parameters =
|
||||
$" /node:\"{_configWMIC.Replace("\"", "\\\"")}\" process call create \"cmd.exe /c \\\"{cmd.Replace("\"", "\\\"")}\\\"\"";
|
||||
Process process = new Process();
|
||||
process.StartInfo.UseShellExecute = false;
|
||||
process.StartInfo.RedirectStandardOutput = true;
|
||||
21
VAR.Toolbox/Code/ReflectionUtils.cs
Normal file
21
VAR.Toolbox/Code/ReflectionUtils.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public static class ReflectionUtils
|
||||
{
|
||||
public static IEnumerable<Type> GetTypesOfInterface(Type interfaceType)
|
||||
{
|
||||
return AppDomain.CurrentDomain
|
||||
.GetAssemblies()
|
||||
.SelectMany(x => x.GetTypes())
|
||||
.Where(x =>
|
||||
x.IsAbstract == false &&
|
||||
x.IsInterface == false &&
|
||||
interfaceType.IsAssignableFrom(x) &&
|
||||
true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,27 +6,47 @@ using VAR.Toolbox.Code.Windows;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public class Screenshooter
|
||||
public static class Screenshoter
|
||||
{
|
||||
public static Bitmap CaptureScreen(Bitmap bmp = null)
|
||||
public static Bitmap CaptureControl(Control ctrl, Bitmap bmp = null)
|
||||
{
|
||||
// Determine the size of the "virtual screen", which includes all monitors.
|
||||
int screenLeft = SystemInformation.VirtualScreen.Left;
|
||||
int screenTop = SystemInformation.VirtualScreen.Top;
|
||||
int screenWidth = SystemInformation.VirtualScreen.Width;
|
||||
int screenHeight = SystemInformation.VirtualScreen.Height;
|
||||
if (ctrl == null) { return bmp; }
|
||||
|
||||
// Create a bitmap of the appropriate size to receive the screenshot.
|
||||
if (bmp == null || bmp?.Width != screenWidth || bmp?.Height != screenHeight)
|
||||
{
|
||||
bmp = new Bitmap(screenWidth, screenHeight);
|
||||
Point picCapturerOrigin = ctrl.PointToScreen(new Point(0, 0));
|
||||
bmp = CaptureScreen(bmp, picCapturerOrigin.X, picCapturerOrigin.Y, ctrl.Width, ctrl.Height);
|
||||
return bmp;
|
||||
}
|
||||
|
||||
public static Bitmap CaptureScreen(Bitmap bmp = null, int? left = null, int? top = null, int? width = null,
|
||||
int? height = null)
|
||||
{
|
||||
if (width <= 0 || height <= 0) { return bmp; }
|
||||
|
||||
// Determine the size of the "virtual screen", which includes all monitors.
|
||||
left = left ?? SystemInformation.VirtualScreen.Left;
|
||||
top = top ?? SystemInformation.VirtualScreen.Top;
|
||||
width = width ?? SystemInformation.VirtualScreen.Width;
|
||||
height = height ?? SystemInformation.VirtualScreen.Height;
|
||||
|
||||
// Create a bitmap of the appropriate size to receive the screenshot.
|
||||
if (bmp == null || bmp.Width != width || bmp.Height != height)
|
||||
{
|
||||
bmp = new Bitmap((int)width, (int)height);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Draw the screenshot into our bitmap.
|
||||
using (Graphics g = Graphics.FromImage(bmp))
|
||||
{
|
||||
g.CopyFromScreen(screenLeft, screenTop, 0, 0, bmp.Size);
|
||||
g.CopyFromScreen((int)left, (int)top, 0, 0, bmp.Size);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
/* Nom Nom Nom */
|
||||
}
|
||||
|
||||
return bmp;
|
||||
}
|
||||
|
||||
@@ -52,8 +72,8 @@ namespace VAR.Toolbox.Code
|
||||
User32.GetWindowRect(handle, ref windowRect);
|
||||
int left = windowRect.left;
|
||||
int top = windowRect.top;
|
||||
int width = windowRect.right - windowRect.left;
|
||||
int height = windowRect.bottom - windowRect.top;
|
||||
int width = windowRect.right - left;
|
||||
int height = windowRect.bottom - top;
|
||||
// create a device context we can copy to
|
||||
IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc);
|
||||
// create a bitmap we can copy it to,
|
||||
@@ -76,8 +96,5 @@ namespace VAR.Toolbox.Code
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public class TextCoderFactory
|
||||
{
|
||||
public static string[] GetSupportedCoders()
|
||||
{
|
||||
return new string[] {
|
||||
TextCoderBase64ToAscii.Name,
|
||||
TextCoderBase64ToUtf8.Name,
|
||||
TextCoderHexToUtf8.Name,
|
||||
TextCoderHexToAscii.Name,
|
||||
};
|
||||
}
|
||||
|
||||
public static ITextCoder CreateFromName(string name)
|
||||
{
|
||||
if (name == TextCoderBase64ToAscii.Name)
|
||||
{
|
||||
return new TextCoderBase64ToAscii();
|
||||
}
|
||||
if (name == TextCoderBase64ToUtf8.Name)
|
||||
{
|
||||
return new TextCoderBase64ToUtf8();
|
||||
}
|
||||
if (name == TextCoderHexToUtf8.Name)
|
||||
{
|
||||
return new TextCoderHexToUtf8();
|
||||
}
|
||||
if (name == TextCoderHexToAscii.Name)
|
||||
{
|
||||
return new TextCoderHexToAscii();
|
||||
}
|
||||
throw new NotImplementedException(string.Format("Cant create ITextCoder with this name: {0}", name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace VAR.Toolbox.Code
|
||||
namespace VAR.Toolbox.Code.TextCoders
|
||||
{
|
||||
public interface ITextCoder
|
||||
public interface ITextCoder : INamed
|
||||
{
|
||||
bool NeedsKey { get; }
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
namespace VAR.Toolbox.Code.TextCoders
|
||||
{
|
||||
public class TextCoderBase64ToAscii : ITextCoder
|
||||
{
|
||||
public const string Name = "Base64ToAscii";
|
||||
public string Name => "Base64ToAscii";
|
||||
|
||||
public bool NeedsKey { get { return false; } }
|
||||
public bool NeedsKey => false;
|
||||
|
||||
public string Decode(string input, string key)
|
||||
{
|
||||
@@ -1,13 +1,13 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
namespace VAR.Toolbox.Code.TextCoders
|
||||
{
|
||||
public class TextCoderBase64ToUtf8 : ITextCoder
|
||||
{
|
||||
public const string Name = "Base64ToUtf8";
|
||||
public string Name => "Base64ToUtf8";
|
||||
|
||||
public bool NeedsKey { get { return false; } }
|
||||
public bool NeedsKey => false;
|
||||
|
||||
public string Decode(string input, string key)
|
||||
{
|
||||
4
VAR.Toolbox/Code/TextCoders/TextCoderFactory.cs
Normal file
4
VAR.Toolbox/Code/TextCoders/TextCoderFactory.cs
Normal file
@@ -0,0 +1,4 @@
|
||||
namespace VAR.Toolbox.Code.TextCoders
|
||||
{
|
||||
public abstract class TextCoderFactory : BaseFactory<ITextCoder> { }
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
using System.Text;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
namespace VAR.Toolbox.Code.TextCoders
|
||||
{
|
||||
public class TextCoderHexToAscii : ITextCoder
|
||||
{
|
||||
public const string Name = "HexToAscii";
|
||||
public string Name => "HexToAscii";
|
||||
|
||||
public bool NeedsKey { get { return false; } }
|
||||
public bool NeedsKey => false;
|
||||
|
||||
public string Decode(string input, string key)
|
||||
{
|
||||
@@ -20,6 +20,5 @@ namespace VAR.Toolbox.Code
|
||||
byte[] toEncodeAsBytes = Encoding.ASCII.GetBytes(input);
|
||||
return HexUtils.BytesToHexString(toEncodeAsBytes);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
using System.Text;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
namespace VAR.Toolbox.Code.TextCoders
|
||||
{
|
||||
public class TextCoderHexToUtf8 : ITextCoder
|
||||
{
|
||||
public const string Name = "HexToUtf8";
|
||||
public string Name => "HexToUtf8";
|
||||
|
||||
public bool NeedsKey { get { return false; } }
|
||||
public bool NeedsKey => false;
|
||||
|
||||
public string Decode(string input, string key)
|
||||
{
|
||||
178
VAR.Toolbox/Code/WebServicesUtils.cs
Normal file
178
VAR.Toolbox/Code/WebServicesUtils.cs
Normal file
@@ -0,0 +1,178 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public static class WebServicesUtils
|
||||
{
|
||||
private static readonly CookieContainer _cookieJar = new CookieContainer();
|
||||
|
||||
public static string CallApi(string urlService, string urlApiMethod, Dictionary<string, string> parameters,
|
||||
object content, CookieContainer cookieJar = null, string stringContent = null,
|
||||
Dictionary<string, string> customHeaders = null, string verb = "POST",
|
||||
bool disableCertificateValidation = false)
|
||||
{
|
||||
if (urlService?.StartsWith("!") == true)
|
||||
{
|
||||
urlService = urlService.Substring(1);
|
||||
disableCertificateValidation = true;
|
||||
}
|
||||
|
||||
if (cookieJar == null) { cookieJar = _cookieJar; }
|
||||
|
||||
try
|
||||
{
|
||||
var sbRequestUrl = new StringBuilder();
|
||||
sbRequestUrl.Append(urlService);
|
||||
if (urlService != null && urlService.EndsWith("/") && urlApiMethod.StartsWith("/"))
|
||||
{
|
||||
sbRequestUrl.Append(urlApiMethod.Substring(1));
|
||||
}
|
||||
else
|
||||
{
|
||||
sbRequestUrl.Append(urlApiMethod);
|
||||
}
|
||||
|
||||
if (parameters != null)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> pair in parameters)
|
||||
{
|
||||
sbRequestUrl.AppendFormat("&{0}={1}", pair.Key,
|
||||
pair.Value == null ? string.Empty : HttpServer.HttpUtility.UrlEncode(pair.Value));
|
||||
}
|
||||
}
|
||||
|
||||
if (sbRequestUrl.Length > 2048)
|
||||
{
|
||||
throw new Exception($"CallApi: Request URL longer than 2048: url: \"{sbRequestUrl}\"");
|
||||
}
|
||||
|
||||
var http = (HttpWebRequest)WebRequest.Create(new Uri(sbRequestUrl.ToString()));
|
||||
|
||||
#if UNIFIKAS_COMMONS
|
||||
if (disableCertificateValidation)
|
||||
{
|
||||
http.ServerCertificateValidationCallback =
|
||||
(sender, certificate, chain, sslPolicyErrors) => { return true; };
|
||||
}
|
||||
#else
|
||||
if (disableCertificateValidation)
|
||||
{
|
||||
throw new NotImplementedException("ApiHelper.CallApi: Can't disable certificate validation");
|
||||
}
|
||||
#endif
|
||||
http.CookieContainer = cookieJar;
|
||||
http.Accept = "application/json";
|
||||
http.ContentType = "application/json; charset=utf-8";
|
||||
http.Method = verb;
|
||||
if (customHeaders != null)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> customHeader in customHeaders)
|
||||
{
|
||||
http.Headers[customHeader.Key] = customHeader.Value;
|
||||
}
|
||||
}
|
||||
|
||||
if (verb == "POST")
|
||||
{
|
||||
string parsedContent = Json.JsonWriter.WriteObject(content);
|
||||
if (string.IsNullOrEmpty(stringContent) == false)
|
||||
{
|
||||
parsedContent = stringContent;
|
||||
}
|
||||
|
||||
UTF8Encoding encoding = new UTF8Encoding();
|
||||
byte[] bytes = encoding.GetBytes(parsedContent);
|
||||
|
||||
Task<Stream> requestStreamTask = http.GetRequestStreamAsync();
|
||||
requestStreamTask.Wait();
|
||||
Stream requestStream = requestStreamTask.Result;
|
||||
requestStream.Write(bytes, 0, bytes.Length);
|
||||
requestStream.Flush();
|
||||
}
|
||||
|
||||
Task<WebResponse> responseTask = http.GetResponseAsync();
|
||||
responseTask.Wait();
|
||||
WebResponse response = responseTask.Result;
|
||||
var stream = response.GetResponseStream();
|
||||
if (stream == null) { return null; }
|
||||
|
||||
var sr = new StreamReader(stream);
|
||||
return sr.ReadToEnd();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// ReSharper disable once PossibleIntendedRethrow
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
public static string CallSoapMethod(string url, string method, Dictionary<string, object> parameters,
|
||||
string namespaceUrl = "http://tempuri.org", ICredentials credentials = null)
|
||||
{
|
||||
// Los servicios SOAP se llaman siempre a través de HTTP.
|
||||
if (url.ToLower().StartsWith("https://"))
|
||||
{
|
||||
url = $"http://{url.Substring("https://".Length)}";
|
||||
}
|
||||
|
||||
// Construir petición
|
||||
var sbData = new StringBuilder();
|
||||
sbData.AppendFormat("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
|
||||
sbData.AppendFormat(
|
||||
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">");
|
||||
sbData.AppendFormat("<soap:Body>");
|
||||
sbData.AppendFormat("<{0} xmlns=\"{1}\">", method, namespaceUrl);
|
||||
foreach (KeyValuePair<string, object> parameter in parameters)
|
||||
{
|
||||
if (parameter.Value != null && !(parameter.Value is DBNull))
|
||||
{
|
||||
sbData.AppendFormat("<{0}>{1}</{0}>", parameter.Key, parameter.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
sbData.AppendFormat("<{0} i:nil=\"true\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" />",
|
||||
parameter.Key);
|
||||
}
|
||||
}
|
||||
|
||||
sbData.AppendFormat("</{0}>", method);
|
||||
sbData.AppendFormat("</soap:Body>");
|
||||
sbData.AppendFormat("</soap:Envelope>");
|
||||
Console.WriteLine(sbData.ToString());
|
||||
byte[] postData = Encoding.UTF8.GetBytes(sbData.ToString());
|
||||
|
||||
// Realizar petición
|
||||
var client = new WebClient();
|
||||
if (credentials != null)
|
||||
{
|
||||
client.Credentials = credentials;
|
||||
}
|
||||
|
||||
client.Headers.Add("Accept", "text/xml");
|
||||
client.Headers.Add("Accept-Charset", "UTF-8");
|
||||
client.Headers.Add("Content-Type", "text/xml; charset=UTF-8");
|
||||
client.Headers.Add("SOAPAction",
|
||||
namespaceUrl.ToLower().StartsWith("http")
|
||||
? $"\"{namespaceUrl}/{method}\""
|
||||
: $"\"{namespaceUrl}:{method}\"");
|
||||
|
||||
byte[] data;
|
||||
try
|
||||
{
|
||||
data = client.UploadData(url, "POST", postData);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"Failure calling SoapService: URL: {url}", ex);
|
||||
}
|
||||
|
||||
string strData = Encoding.UTF8.GetString(data);
|
||||
return strData;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,9 @@
|
||||
using System;
|
||||
#pragma warning disable IDE0018
|
||||
#pragma warning disable IDE0059
|
||||
// ReSharper disable SuspiciousTypeConversion.Global
|
||||
// ReSharper disable ConvertToAutoProperty
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
@@ -7,26 +12,23 @@ using System.Runtime.InteropServices.ComTypes;
|
||||
using VAR.Toolbox.Code.DirectShow;
|
||||
using VAR.Toolbox.Code.Windows;
|
||||
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public class Webcam
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
private IFilterGraph2 graph;
|
||||
private ICaptureGraphBuilder2 capture;
|
||||
private IMediaControl control;
|
||||
private IBaseFilter sourceFilter;
|
||||
private IBaseFilter samplegrabberfilter;
|
||||
private IBaseFilter nullrenderer;
|
||||
private readonly IMediaControl _control;
|
||||
private readonly IBaseFilter _sourceFilter;
|
||||
private readonly IBaseFilter _sampleGrabberFilter;
|
||||
private readonly IBaseFilter _nullRenderer;
|
||||
|
||||
private Grabber grabber;
|
||||
private readonly int _width;
|
||||
private readonly int _height;
|
||||
private readonly int _bpp;
|
||||
|
||||
private int width = 0;
|
||||
private int height = 0;
|
||||
private int bpp = 0;
|
||||
|
||||
private bool active = false;
|
||||
private bool _active;
|
||||
|
||||
private static Dictionary<string, string> _deviceDescriptions;
|
||||
|
||||
@@ -34,11 +36,13 @@ namespace VAR.Toolbox.Code
|
||||
|
||||
#region Properties
|
||||
|
||||
public int Width { get { return width; } }
|
||||
public int Height { get { return height; } }
|
||||
public int BPP { get { return bpp; } }
|
||||
public int Width => _width;
|
||||
|
||||
public bool Active { get { return active; } }
|
||||
public int Height => _height;
|
||||
|
||||
public int BPP => _bpp;
|
||||
|
||||
public bool Active => _active;
|
||||
|
||||
#endregion Properties
|
||||
|
||||
@@ -46,49 +50,48 @@ namespace VAR.Toolbox.Code
|
||||
|
||||
public Webcam(string monikerString)
|
||||
{
|
||||
int result;
|
||||
|
||||
graph = CreateInstanceFromClsid<IFilterGraph2>(Clsid.FilterGraph);
|
||||
capture = CreateInstanceFromClsid<ICaptureGraphBuilder2>(Clsid.CaptureGraphBuilder2);
|
||||
control = (IMediaControl)graph;
|
||||
IFilterGraph2 graph = CreateInstanceFromClsid<IFilterGraph2>(Clsid.FilterGraph);
|
||||
ICaptureGraphBuilder2 capture = CreateInstanceFromClsid<ICaptureGraphBuilder2>(Clsid.CaptureGraphBuilder2);
|
||||
_control = (IMediaControl)graph;
|
||||
capture.SetFiltergraph((IGraphBuilder)graph);
|
||||
|
||||
IBindCtx bindCtx = null;
|
||||
IMoniker moniker = null;
|
||||
|
||||
int n = 0;
|
||||
|
||||
if (Win32.CreateBindCtx(0, out bindCtx) != 0)
|
||||
if (Win32.CreateBindCtx(0, out IBindCtx bindCtx) != 0)
|
||||
{
|
||||
throw new Exception("Failed to create binding context");
|
||||
}
|
||||
if (Win32.MkParseDisplayName(bindCtx, monikerString, ref n, out moniker) != 0)
|
||||
|
||||
if (Win32.MkParseDisplayName(bindCtx, monikerString, ref n, out IMoniker moniker) != 0)
|
||||
{
|
||||
throw new Exception("Failed to create binding moniker");
|
||||
}
|
||||
|
||||
graph.AddSourceFilterForMoniker(moniker, bindCtx, monikerString, out sourceFilter);
|
||||
graph.AddSourceFilterForMoniker(moniker, bindCtx, monikerString, out _sourceFilter);
|
||||
|
||||
samplegrabberfilter = CreateInstanceFromClsid<IBaseFilter>(Clsid.SampleGrabber);
|
||||
graph.AddFilter(samplegrabberfilter, string.Format("SampleGrabber {0}", monikerString));
|
||||
_sampleGrabberFilter = CreateInstanceFromClsid<IBaseFilter>(Clsid.SampleGrabber);
|
||||
graph.AddFilter(_sampleGrabberFilter, $"SampleGrabber {monikerString}");
|
||||
|
||||
ISampleGrabber sampleGrabber = (ISampleGrabber)samplegrabberfilter;
|
||||
ISampleGrabber sampleGrabber = (ISampleGrabber)_sampleGrabberFilter;
|
||||
|
||||
// Set media type
|
||||
AMMediaType mediaType = new AMMediaType();
|
||||
mediaType.MajorType = MediaType.Video;
|
||||
mediaType.SubType = MediaSubType.RGB24;
|
||||
AMMediaType mediaType = new AMMediaType
|
||||
{
|
||||
MajorType = MediaType.Video,
|
||||
SubType = MediaSubType.RGB24
|
||||
};
|
||||
sampleGrabber.SetMediaType(mediaType);
|
||||
|
||||
grabber = new Grabber(this);
|
||||
result = sampleGrabber.SetCallback(grabber, 1);
|
||||
var grabber = new Grabber(this);
|
||||
int result = sampleGrabber.SetCallback(grabber, 1);
|
||||
if (result < 0) throw new Exception("Failure creating Webcam device");
|
||||
|
||||
//set the null renderer
|
||||
nullrenderer = CreateInstanceFromClsid<IBaseFilter>(Clsid.NullRenderer);
|
||||
graph.AddFilter(nullrenderer, string.Format("NullRenderer {0}", monikerString));
|
||||
_nullRenderer = CreateInstanceFromClsid<IBaseFilter>(Clsid.NullRenderer);
|
||||
graph.AddFilter(_nullRenderer, $"NullRenderer {monikerString}");
|
||||
|
||||
result = capture.RenderStream(PinCategory.Preview, MediaType.Video, sourceFilter, samplegrabberfilter, nullrenderer);
|
||||
result = capture.RenderStream(PinCategory.Preview, MediaType.Video, _sourceFilter, _sampleGrabberFilter,
|
||||
_nullRenderer);
|
||||
if (result < 0) throw new Exception("Failure creating Webcam device");
|
||||
|
||||
AMMediaType queryMediaType = new AMMediaType();
|
||||
@@ -97,14 +100,15 @@ namespace VAR.Toolbox.Code
|
||||
{
|
||||
if (queryMediaType.FormatType == FormatType.VideoInfo)
|
||||
{
|
||||
VideoInfoHeader videoInfo = (VideoInfoHeader)Marshal.PtrToStructure(queryMediaType.FormatPtr, typeof(VideoInfoHeader));
|
||||
width = videoInfo.BmiHeader.Width;
|
||||
height = videoInfo.BmiHeader.Height;
|
||||
bpp = videoInfo.BmiHeader.BitCount;
|
||||
VideoInfoHeader videoInfo =
|
||||
(VideoInfoHeader)Marshal.PtrToStructure(queryMediaType.FormatPtr, typeof(VideoInfoHeader));
|
||||
_width = videoInfo.BmiHeader.Width;
|
||||
_height = videoInfo.BmiHeader.Height;
|
||||
_bpp = videoInfo.BmiHeader.BitCount;
|
||||
}
|
||||
}
|
||||
|
||||
control.Run();
|
||||
_control.Run();
|
||||
Stop();
|
||||
}
|
||||
|
||||
@@ -114,41 +118,37 @@ namespace VAR.Toolbox.Code
|
||||
|
||||
public void Start()
|
||||
{
|
||||
control.Run();
|
||||
int result;
|
||||
result = nullrenderer.Run(0);
|
||||
_control.Run();
|
||||
int result = _nullRenderer.Run(0);
|
||||
if (result < 0) throw new Exception("Webcam Start failure");
|
||||
result = samplegrabberfilter.Run(0);
|
||||
result = _sampleGrabberFilter.Run(0);
|
||||
if (result < 0) throw new Exception("Webcam Start failure");
|
||||
result = sourceFilter.Run(0);
|
||||
result = _sourceFilter.Run(0);
|
||||
if (result < 0) throw new Exception("Webcam Start failure");
|
||||
active = true;
|
||||
_active = true;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
int result;
|
||||
result = sourceFilter.Stop();
|
||||
int result = _sourceFilter.Stop();
|
||||
if (result < 0) throw new Exception("Webcam Stop failure");
|
||||
result = samplegrabberfilter.Stop();
|
||||
result = _sampleGrabberFilter.Stop();
|
||||
if (result < 0) throw new Exception("Webcam Stop failure");
|
||||
result = nullrenderer.Stop();
|
||||
result = _nullRenderer.Stop();
|
||||
if (result < 0) throw new Exception("Webcam Stop failure");
|
||||
control.Stop();
|
||||
active = false;
|
||||
_control.Stop();
|
||||
_active = false;
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> ListDevices()
|
||||
{
|
||||
if (_deviceDescriptions != null) { return _deviceDescriptions; }
|
||||
|
||||
int result;
|
||||
Dictionary<string, string> devices = new Dictionary<string, string>();
|
||||
ICreateDevEnum devEnum = CreateInstanceFromClsid<ICreateDevEnum>(Clsid.SystemDeviceEnum);
|
||||
|
||||
IEnumMoniker enumMon = null;
|
||||
Guid category = FilterCategory.VideoInputDevice;
|
||||
result = devEnum.CreateClassEnumerator(ref category, out enumMon, 0);
|
||||
int result = devEnum.CreateClassEnumerator(ref category, out IEnumMoniker enumMon, 0);
|
||||
if (result != 0)
|
||||
throw new ApplicationException("No devices of the category");
|
||||
|
||||
@@ -162,14 +162,15 @@ namespace VAR.Toolbox.Code
|
||||
break;
|
||||
|
||||
// Add device description
|
||||
string deviceName = new String(GetMonikerName(devMoniker[0]).ToCharArray());
|
||||
string deviceString = new String(GetMonikerString(devMoniker[0]).ToCharArray());
|
||||
string deviceName = new string(GetMonikerName(devMoniker[0]).ToCharArray());
|
||||
string deviceString = new string(GetMonikerString(devMoniker[0]).ToCharArray());
|
||||
devices.Add(deviceName, deviceString);
|
||||
|
||||
// Release COM object
|
||||
Marshal.ReleaseComObject(devMoniker[0]);
|
||||
devMoniker[0] = null;
|
||||
}
|
||||
|
||||
_deviceDescriptions = devices;
|
||||
|
||||
Marshal.ReleaseComObject(devEnum);
|
||||
@@ -197,8 +198,7 @@ namespace VAR.Toolbox.Code
|
||||
//
|
||||
private static string GetMonikerString(IMoniker moniker)
|
||||
{
|
||||
string str;
|
||||
moniker.GetDisplayName(null, null, out str);
|
||||
moniker.GetDisplayName(null, null, out string str);
|
||||
return str;
|
||||
}
|
||||
|
||||
@@ -208,14 +208,13 @@ namespace VAR.Toolbox.Code
|
||||
private static string GetMonikerName(IMoniker moniker)
|
||||
{
|
||||
Object bagObj = null;
|
||||
IPropertyBag bag = null;
|
||||
|
||||
try
|
||||
{
|
||||
Guid bagId = typeof(IPropertyBag).GUID;
|
||||
// get property bag of the moniker
|
||||
moniker.BindToStorage(null, null, ref bagId, out bagObj);
|
||||
bag = (IPropertyBag)bagObj;
|
||||
IPropertyBag bag = (IPropertyBag)bagObj;
|
||||
|
||||
// read FriendlyName
|
||||
object val = "";
|
||||
@@ -237,11 +236,9 @@ namespace VAR.Toolbox.Code
|
||||
finally
|
||||
{
|
||||
// release all COM objects
|
||||
bag = null;
|
||||
if (bagObj != null)
|
||||
{
|
||||
Marshal.ReleaseComObject(bagObj);
|
||||
bagObj = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -260,10 +257,10 @@ namespace VAR.Toolbox.Code
|
||||
|
||||
private class Grabber : ISampleGrabberCB
|
||||
{
|
||||
private Webcam _parent;
|
||||
private readonly Webcam _parent;
|
||||
|
||||
private Bitmap[] _frames = null;
|
||||
private int _numFrames = 10;
|
||||
private readonly Bitmap[] _frames;
|
||||
private readonly int _numFrames = 10;
|
||||
private int _currentFrameIndex = -1;
|
||||
|
||||
public Grabber(Webcam parent)
|
||||
@@ -276,11 +273,13 @@ namespace VAR.Toolbox.Code
|
||||
{
|
||||
_currentFrameIndex = (_currentFrameIndex + 1) % _numFrames;
|
||||
Bitmap currentBitmap = _frames[_currentFrameIndex];
|
||||
if (currentBitmap == null || currentBitmap?.Width != _parent.width || currentBitmap?.Height != _parent.height)
|
||||
if (currentBitmap == null || currentBitmap.Width != _parent._width ||
|
||||
currentBitmap.Height != _parent._height)
|
||||
{
|
||||
currentBitmap = new Bitmap(_parent.width, _parent.height, PixelFormat.Format24bppRgb);
|
||||
currentBitmap = new Bitmap(_parent._width, _parent._height, PixelFormat.Format24bppRgb);
|
||||
_frames[_currentFrameIndex] = currentBitmap;
|
||||
}
|
||||
|
||||
return currentBitmap;
|
||||
}
|
||||
|
||||
@@ -294,12 +293,12 @@ namespace VAR.Toolbox.Code
|
||||
if (_parent.NewFrame != null)
|
||||
{
|
||||
// create new image
|
||||
Bitmap _image = GetNextFrame();
|
||||
Rectangle _imageRect = new Rectangle(0, 0, _parent.width, _parent.height);
|
||||
Bitmap image = GetNextFrame();
|
||||
Rectangle imageRect = new Rectangle(0, 0, _parent._width, _parent._height);
|
||||
|
||||
// lock bitmap data
|
||||
BitmapData imageData = _image.LockBits(
|
||||
_imageRect,
|
||||
BitmapData imageData = image.LockBits(
|
||||
imageRect,
|
||||
ImageLockMode.ReadWrite,
|
||||
PixelFormat.Format24bppRgb);
|
||||
|
||||
@@ -309,10 +308,10 @@ namespace VAR.Toolbox.Code
|
||||
|
||||
unsafe
|
||||
{
|
||||
byte* dst = (byte*)imageData.Scan0.ToPointer() + dstStride * (_parent.height - 1);
|
||||
byte* dst = (byte*)imageData.Scan0.ToPointer() + dstStride * (_parent._height - 1);
|
||||
byte* src = (byte*)buffer.ToPointer();
|
||||
|
||||
for (int y = 0; y < _parent.height; y++)
|
||||
for (int y = 0; y < _parent._height; y++)
|
||||
{
|
||||
Win32.memcpy(dst, src, srcStride);
|
||||
dst -= dstStride;
|
||||
@@ -321,10 +320,10 @@ namespace VAR.Toolbox.Code
|
||||
}
|
||||
|
||||
// unlock bitmap data
|
||||
_image.UnlockBits(imageData);
|
||||
image.UnlockBits(imageData);
|
||||
|
||||
// notify parent
|
||||
_parent.NewFrame?.Invoke(this, _image);
|
||||
_parent.NewFrame?.Invoke(this, image);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
33
VAR.Toolbox/Code/WindowHandling.cs
Normal file
33
VAR.Toolbox/Code/WindowHandling.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Windows.Forms;
|
||||
using VAR.Toolbox.Code.Windows;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public static class WindowHandling
|
||||
{
|
||||
public static void WindowSetTopLevel(Form form, bool top = true)
|
||||
{
|
||||
User32.SetWindowPos(form.Handle, top
|
||||
? User32.HWND_TOPMOST
|
||||
: User32.HWND_NOTOPMOST,
|
||||
0, 0, 0, 0, User32.TOPMOST_FLAGS);
|
||||
}
|
||||
|
||||
public static bool ApplicationIsActivated()
|
||||
{
|
||||
var activatedHandle = User32.GetForegroundWindow();
|
||||
if (activatedHandle == IntPtr.Zero)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var procId = Process.GetCurrentProcess().Id;
|
||||
User32.GetWindowThreadProcessId(activatedHandle, out int activeProcId);
|
||||
return activeProcId == procId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,15 +11,20 @@ namespace VAR.Toolbox.Code.Windows
|
||||
public static extern bool BitBlt(IntPtr hObject, int nXDest, int nYDest,
|
||||
int nWidth, int nHeight, IntPtr hObjectSource,
|
||||
int nXSrc, int nYSrc, int dwRop);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
public static extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int nWidth,
|
||||
int nHeight);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
public static extern bool DeleteDC(IntPtr hDC);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
public static extern bool DeleteObject(IntPtr hObject);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable FieldCanBeMadeReadOnly.Global
|
||||
// ReSharper disable IdentifierTypo
|
||||
|
||||
namespace VAR.Toolbox.Code.Windows
|
||||
{
|
||||
@@ -22,14 +28,11 @@ namespace VAR.Toolbox.Code.Windows
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct MOUSEKEYBDHARDWAREINPUT
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public HARDWAREINPUT Hardware;
|
||||
[FieldOffset(0)] public HARDWAREINPUT Hardware;
|
||||
|
||||
[FieldOffset(0)]
|
||||
public KEYBDINPUT Keyboard;
|
||||
[FieldOffset(0)] public KEYBDINPUT Keyboard;
|
||||
|
||||
[FieldOffset(0)]
|
||||
public MOUSEINPUT Mouse;
|
||||
[FieldOffset(0)] public MOUSEINPUT Mouse;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -92,7 +95,7 @@ namespace VAR.Toolbox.Code.Windows
|
||||
[DllImport("User32.dll")]
|
||||
public static extern int SendInput(int nInputs, INPUT[] pInputs, int cbSize);
|
||||
|
||||
// <summary>
|
||||
/// <summary>
|
||||
/// Struct representing a point.
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
@@ -110,18 +113,16 @@ namespace VAR.Toolbox.Code.Windows
|
||||
public static extern bool GetCursorPos(out POINT lpPoint);
|
||||
|
||||
[DllImport("User32.dll")]
|
||||
public static extern Boolean SetCursorPos(UInt32 X, UInt32 Y);
|
||||
public static extern Boolean SetCursorPos(UInt32 x, UInt32 y);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct LASTINPUTINFO
|
||||
{
|
||||
public static readonly int SizeOf = Marshal.SizeOf(typeof(LASTINPUTINFO));
|
||||
|
||||
[MarshalAs(UnmanagedType.U4)]
|
||||
public UInt32 cbSize;
|
||||
[MarshalAs(UnmanagedType.U4)] public UInt32 cbSize;
|
||||
|
||||
[MarshalAs(UnmanagedType.U4)]
|
||||
public UInt32 dwTime;
|
||||
[MarshalAs(UnmanagedType.U4)] public UInt32 dwTime;
|
||||
}
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
@@ -138,7 +139,7 @@ namespace VAR.Toolbox.Code.Windows
|
||||
public const int HT_CAPTION = 0x2;
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
|
||||
public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool ReleaseCapture();
|
||||
@@ -154,11 +155,111 @@ namespace VAR.Toolbox.Code.Windows
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr GetDesktopWindow();
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr GetWindowDC(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr GetWindowRect(IntPtr hWnd, ref RECT rect);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool SetForegroundWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr GetForegroundWindow();
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||
public static extern int GetWindowThreadProcessId(IntPtr handle, out int processId);
|
||||
|
||||
public static string GetActiveWindowTitle()
|
||||
{
|
||||
const int NChars = 256;
|
||||
StringBuilder buff = new StringBuilder(NChars);
|
||||
IntPtr handle = GetForegroundWindow();
|
||||
|
||||
if (GetWindowText(handle, buff, NChars) > 0)
|
||||
{
|
||||
return buff.ToString();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
|
||||
public static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
|
||||
public const UInt32 SWP_NOSIZE = 0x0001;
|
||||
public const UInt32 SWP_NOMOVE = 0x0002;
|
||||
public const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE;
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy,
|
||||
uint uFlags);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// defines the callback type for the hook
|
||||
/// </summary>
|
||||
public delegate int keyboardHookProc(int code, int wParam, ref keyboardHookStruct lParam);
|
||||
|
||||
public struct keyboardHookStruct {
|
||||
public int vkCode;
|
||||
public int scanCode;
|
||||
public int flags;
|
||||
public int time;
|
||||
public int dwExtraInfo;
|
||||
}
|
||||
|
||||
public const int WH_KEYBOARD_LL = 13;
|
||||
public const int WM_KEYDOWN = 0x100;
|
||||
public const int WM_KEYUP = 0x101;
|
||||
public const int WM_SYSKEYDOWN = 0x104;
|
||||
public const int WM_SYSKEYUP = 0x105;
|
||||
|
||||
/// <summary>
|
||||
/// Sets the windows hook, do the desired event, one of hInstance or threadId must be non-null
|
||||
/// </summary>
|
||||
/// <param name="idHook">The id of the event you want to hook</param>
|
||||
/// <param name="callback">The callback.</param>
|
||||
/// <param name="hInstance">The handle you want to attach the event to, can be null</param>
|
||||
/// <param name="threadId">The thread you want to attach the event to, can be null</param>
|
||||
/// <returns>a handle to the desired hook</returns>
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr SetWindowsHookEx(int idHook, keyboardHookProc callback, IntPtr hInstance, uint threadId);
|
||||
|
||||
/// <summary>
|
||||
/// Unhooks the windows hook.
|
||||
/// </summary>
|
||||
/// <param name="hInstance">The hook handle that was returned from SetWindowsHookEx</param>
|
||||
/// <returns>True if successful, false otherwise</returns>
|
||||
[DllImport("user32.dll")]
|
||||
public static extern bool UnhookWindowsHookEx(IntPtr hInstance);
|
||||
|
||||
/// <summary>
|
||||
/// Calls the next hook.
|
||||
/// </summary>
|
||||
/// <param name="idHook">The hook id</param>
|
||||
/// <param name="nCode">The hook code</param>
|
||||
/// <param name="wParam">The wparam.</param>
|
||||
/// <param name="lParam">The lparam.</param>
|
||||
/// <returns></returns>
|
||||
[DllImport("user32.dll")]
|
||||
public static extern int CallNextHookEx(IntPtr idHook, int nCode, int wParam, ref keyboardHookStruct lParam);
|
||||
|
||||
/// <summary>
|
||||
/// Loads the library.
|
||||
/// </summary>
|
||||
/// <param name="lpFileName">Name of the library</param>
|
||||
/// <returns>A handle to the library</returns>
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern IntPtr LoadLibrary(string lpFileName);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,13 @@
|
||||
using System;
|
||||
#pragma warning disable IDE1006
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
|
||||
// ReSharper disable IdentifierTypo
|
||||
// ReSharper disable StringLiteralTypo
|
||||
// ReSharper disable CommentTypo
|
||||
|
||||
namespace VAR.Toolbox.Code.Windows
|
||||
{
|
||||
public static class Win32
|
||||
@@ -49,7 +55,7 @@ namespace VAR.Toolbox.Code.Windows
|
||||
/// <returns>Return's the value of <b>dst</b> - pointer to destination.</returns>
|
||||
///
|
||||
[DllImport("ntdll.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static unsafe extern int memcpy(
|
||||
public static extern unsafe int memcpy(
|
||||
byte* dst,
|
||||
byte* src,
|
||||
int count);
|
||||
@@ -88,7 +94,8 @@ namespace VAR.Toolbox.Code.Windows
|
||||
IntPtr lpvReserved);
|
||||
|
||||
[DllImport("PowrProf.dll")]
|
||||
public static extern Boolean SetSuspendState(Boolean Hibernate, Boolean ForceCritical, Boolean DisableWakeEvent);
|
||||
public static extern Boolean
|
||||
SetSuspendState(Boolean hibernate, Boolean forceCritical, Boolean disableWakeEvent);
|
||||
|
||||
public static uint GetLastInputTime()
|
||||
{
|
||||
@@ -102,6 +109,7 @@ namespace VAR.Toolbox.Code.Windows
|
||||
uint lastInputTick = lastInputInfo.dwTime;
|
||||
idleTime = envTicks - lastInputTick;
|
||||
}
|
||||
|
||||
return ((idleTime > 0) ? (idleTime / 1000) : 0);
|
||||
}
|
||||
}
|
||||
|
||||
11
VAR.Toolbox/Code/WorkLog/IWorkLogImporter.cs
Normal file
11
VAR.Toolbox/Code/WorkLog/IWorkLogImporter.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VAR.Toolbox.Code.WorkLog
|
||||
{
|
||||
public interface IWorkLogImporter : INamed
|
||||
{
|
||||
List<WorkLogItem> Import(Form form);
|
||||
bool Export(List<WorkLogItem> items, Form form);
|
||||
}
|
||||
}
|
||||
145
VAR.Toolbox/Code/WorkLog/VARTextWorkLogImporter.cs
Normal file
145
VAR.Toolbox/Code/WorkLog/VARTextWorkLogImporter.cs
Normal file
@@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VAR.Toolbox.Code.WorkLog
|
||||
{
|
||||
public class VARTextWorkLogImporter : IWorkLogImporter
|
||||
{
|
||||
public string Name => "VARText";
|
||||
|
||||
//TODO: VARTextWorkLogImporter: Export WorkLigItem.Tags
|
||||
public bool Export(List<WorkLogItem> items, Form form)
|
||||
{
|
||||
SaveFileDialog saveFileDialog = new SaveFileDialog();
|
||||
DialogResult dialogResult = saveFileDialog.ShowDialog(form);
|
||||
if (dialogResult != DialogResult.OK) { return false; }
|
||||
|
||||
if (File.Exists(saveFileDialog.FileName) == false)
|
||||
{
|
||||
File.Delete(saveFileDialog.FileName);
|
||||
}
|
||||
|
||||
using (StreamWriter streamWriter = new StreamWriter(saveFileDialog.FileName))
|
||||
{
|
||||
DateTime lastDateTime = DateTime.MinValue;
|
||||
int lastWeekOfYear = -1;
|
||||
List<WorkLogItem> itemsOrdered = items.OrderBy(x => x.DateStart).ToList();
|
||||
foreach (WorkLogItem item in itemsOrdered)
|
||||
{
|
||||
int weekOfYear = CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(item.DateStart,
|
||||
CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
|
||||
if (weekOfYear != lastWeekOfYear)
|
||||
{
|
||||
streamWriter.WriteLine();
|
||||
streamWriter.WriteLine();
|
||||
streamWriter.WriteLine("--- {0:0000}-{1:00}-{2:00}", item.DateStart.Year, item.DateStart.Month,
|
||||
item.DateStart.Day);
|
||||
lastWeekOfYear = weekOfYear;
|
||||
}
|
||||
|
||||
if (lastDateTime.Day != item.DateStart.Day)
|
||||
{
|
||||
streamWriter.WriteLine();
|
||||
lastDateTime = item.DateStart;
|
||||
}
|
||||
|
||||
streamWriter.WriteLine("{0:00}_{1:00}_{2:00} - {3:00}_{4:00}_{5:00} {6}", item.DateStart.Day,
|
||||
item.DateStart.Hour, item.DateStart.Minute, item.DateEnd.Day, item.DateEnd.Hour,
|
||||
item.DateEnd.Minute, item.Activity);
|
||||
if (string.IsNullOrEmpty(item.Description) == false)
|
||||
{
|
||||
streamWriter.WriteLine($" {item.Description}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//TODO: VARTextWorkLogImporter: Import WorkLigItem.Tags
|
||||
public List<WorkLogItem> Import(Form form)
|
||||
{
|
||||
OpenFileDialog openFileDialog = new OpenFileDialog();
|
||||
DialogResult dialogResult = openFileDialog.ShowDialog(form);
|
||||
if (dialogResult != DialogResult.OK) { return null; }
|
||||
|
||||
if (File.Exists(openFileDialog.FileName) == false) { return null; }
|
||||
|
||||
string[] allLines = File.ReadAllLines(openFileDialog.FileName);
|
||||
Regex regex = new Regex(@"(\d\d)_(\d\d)_(\d\d)\s-\s(\d\d)_(\d\d)_(\d\d)\s(.*)");
|
||||
|
||||
DateTime currentDateStart = DateTime.MinValue;
|
||||
WorkLogItem currentWorkLog = null;
|
||||
List<WorkLogItem> workLog = new List<WorkLogItem>();
|
||||
|
||||
foreach (string line in allLines)
|
||||
{
|
||||
string lineAux = line.Trim();
|
||||
if (string.IsNullOrEmpty(lineAux)) { continue; }
|
||||
|
||||
if (lineAux.StartsWith("--- "))
|
||||
{
|
||||
string strDate = lineAux.Substring(4);
|
||||
string[] strDateParts = strDate.Split('-');
|
||||
if (strDateParts.Length >= 3 && strDateParts[0].Length == 4 && strDateParts[1].Length == 2 &&
|
||||
strDateParts[2].Length == 2)
|
||||
{
|
||||
currentDateStart = new DateTime(Convert.ToInt32(strDateParts[0]),
|
||||
Convert.ToInt32(strDateParts[1]), Convert.ToInt32(strDateParts[2]), 0, 0, 0);
|
||||
}
|
||||
else { }
|
||||
}
|
||||
else if (lineAux.StartsWith("--"))
|
||||
{
|
||||
if (currentWorkLog != null)
|
||||
{
|
||||
currentWorkLog.Description += lineAux + "\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Match match = regex.Match(lineAux);
|
||||
if (match.Groups.Count < 7)
|
||||
{
|
||||
if (currentWorkLog != null)
|
||||
{
|
||||
currentWorkLog.Description += lineAux + "\n";
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
int startDay = Convert.ToInt32(match.Groups[1].Value);
|
||||
int startHour = Convert.ToInt32(match.Groups[2].Value);
|
||||
int startMinute = Convert.ToInt32(match.Groups[3].Value);
|
||||
int endDay = Convert.ToInt32(match.Groups[4].Value);
|
||||
int endHour = Convert.ToInt32(match.Groups[5].Value);
|
||||
int endMinute = Convert.ToInt32(match.Groups[6].Value);
|
||||
string activity = match.Groups[7].Value;
|
||||
|
||||
DateTime dateTime = currentDateStart;
|
||||
if (dateTime.Day > startDay)
|
||||
{
|
||||
dateTime = dateTime.AddMonths(1);
|
||||
}
|
||||
|
||||
currentWorkLog = new WorkLogItem
|
||||
{
|
||||
DateStart = new DateTime(dateTime.Year, dateTime.Month, startDay, startHour, startMinute, 0),
|
||||
DateEnd = new DateTime(dateTime.Year, dateTime.Month, endDay, endHour, endMinute, 0),
|
||||
Activity = activity,
|
||||
Description = string.Empty,
|
||||
};
|
||||
workLog.Add(currentWorkLog);
|
||||
}
|
||||
}
|
||||
|
||||
return workLog;
|
||||
}
|
||||
}
|
||||
}
|
||||
4
VAR.Toolbox/Code/WorkLog/WorkLogImporterFactory.cs
Normal file
4
VAR.Toolbox/Code/WorkLog/WorkLogImporterFactory.cs
Normal file
@@ -0,0 +1,4 @@
|
||||
namespace VAR.Toolbox.Code.WorkLog
|
||||
{
|
||||
public abstract class WorkLogImporterFactory : BaseFactory<IWorkLogImporter> { }
|
||||
}
|
||||
18
VAR.Toolbox/Code/WorkLog/WorkLogItem.cs
Normal file
18
VAR.Toolbox/Code/WorkLog/WorkLogItem.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace VAR.Toolbox.Code.WorkLog
|
||||
{
|
||||
public class WorkLogItem
|
||||
{
|
||||
public DateTime DateStart { get; set; }
|
||||
public DateTime DateEnd { get; set; }
|
||||
public string Activity { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Tags { get; set; }
|
||||
|
||||
public bool Overlaps(WorkLogItem other)
|
||||
{
|
||||
return (other.DateEnd < DateStart || other.DateStart > DateEnd) == false;
|
||||
}
|
||||
}
|
||||
}
|
||||
94
VAR.Toolbox/Controls/CButton.cs
Normal file
94
VAR.Toolbox/Controls/CButton.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VAR.Toolbox.Controls
|
||||
{
|
||||
public class CButton : Button
|
||||
{
|
||||
private readonly Brush _foreColorBrush;
|
||||
private readonly Brush _foreColorDisableBrush;
|
||||
private readonly Brush _backColorBrush;
|
||||
private readonly Brush _backColorOverBrush;
|
||||
private readonly Brush _backColorDownBrush;
|
||||
|
||||
private bool _mouseIsDown;
|
||||
private bool _mouseIsOver;
|
||||
|
||||
public CButton()
|
||||
{
|
||||
_foreColorBrush = new SolidBrush(Color.FromArgb(255, 192, 192, 192));
|
||||
_foreColorDisableBrush = new SolidBrush(Color.FromArgb(255, 96, 96, 96));
|
||||
_backColorBrush = new SolidBrush(Color.FromArgb(255, 64, 64, 64));
|
||||
_backColorOverBrush = new SolidBrush(Color.FromArgb(255, 128, 0, 0));
|
||||
_backColorDownBrush = new SolidBrush(Color.FromArgb(255, 192, 64, 64));
|
||||
}
|
||||
|
||||
protected override void OnLostFocus(EventArgs e)
|
||||
{
|
||||
_mouseIsDown = false;
|
||||
base.OnLostFocus(e);
|
||||
}
|
||||
|
||||
protected override void OnMouseEnter(EventArgs eventargs)
|
||||
{
|
||||
_mouseIsOver = true;
|
||||
base.OnMouseEnter(eventargs);
|
||||
}
|
||||
|
||||
protected override void OnMouseLeave(EventArgs eventargs)
|
||||
{
|
||||
_mouseIsOver = false;
|
||||
base.OnMouseLeave(eventargs);
|
||||
}
|
||||
|
||||
protected override void OnMouseMove(MouseEventArgs mevent)
|
||||
{
|
||||
if (mevent.Button != MouseButtons.None)
|
||||
{
|
||||
Rectangle r = ClientRectangle;
|
||||
_mouseIsDown = r.Contains(mevent.X, mevent.Y);
|
||||
}
|
||||
|
||||
base.OnMouseMove(mevent);
|
||||
}
|
||||
|
||||
protected override void OnMouseDown(MouseEventArgs mevent)
|
||||
{
|
||||
_mouseIsDown = true;
|
||||
base.OnMouseDown(mevent);
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseEventArgs mevent)
|
||||
{
|
||||
_mouseIsDown = false;
|
||||
base.OnMouseUp(mevent);
|
||||
}
|
||||
|
||||
private readonly StringFormat _stringFormat = new StringFormat
|
||||
{ Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
|
||||
|
||||
protected override void OnPaint(PaintEventArgs pevent)
|
||||
{
|
||||
Rectangle rectangle = new Rectangle(0, 0, Width, Height);
|
||||
if (Enabled)
|
||||
{
|
||||
if (_mouseIsDown)
|
||||
{
|
||||
pevent.Graphics.FillRectangle(_backColorDownBrush, rectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
pevent.Graphics.FillRectangle(_mouseIsOver ? _backColorOverBrush : _backColorBrush, rectangle);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pevent.Graphics.FillRectangle(_backColorBrush, rectangle);
|
||||
}
|
||||
|
||||
pevent.Graphics.DrawString(Text, Font, Enabled ? _foreColorBrush : _foreColorDisableBrush, rectangle,
|
||||
_stringFormat);
|
||||
}
|
||||
}
|
||||
}
|
||||
27
VAR.Toolbox/Controls/CComboBox.cs
Normal file
27
VAR.Toolbox/Controls/CComboBox.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VAR.Toolbox.Controls
|
||||
{
|
||||
public class CComboBox : ComboBox
|
||||
{
|
||||
public CComboBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
BackColor = Color.FromArgb(255, 0, 0, 0);
|
||||
ForeColor = Color.FromArgb(255, 192, 192, 192);
|
||||
|
||||
FlatStyle = FlatStyle.Flat;
|
||||
}
|
||||
|
||||
protected override void OnPaint(PaintEventArgs pevent)
|
||||
{
|
||||
Rectangle rectangle = new Rectangle(0, 0, Width, Height);
|
||||
pevent.Graphics.FillRectangle(Brushes.CadetBlue, rectangle);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
VAR.Toolbox/Controls/CDateTimePicker.cs
Normal file
18
VAR.Toolbox/Controls/CDateTimePicker.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace VAR.Toolbox.Controls
|
||||
{
|
||||
public class CDateTimePicker : System.Windows.Forms.DateTimePicker
|
||||
{
|
||||
public CDateTimePicker()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
BackColor = Color.DarkSlateGray;
|
||||
ForeColor = Color.Gray;
|
||||
}
|
||||
}
|
||||
}
|
||||
59
VAR.Toolbox/Controls/CGroupBox.cs
Normal file
59
VAR.Toolbox/Controls/CGroupBox.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VAR.Toolbox.Controls
|
||||
{
|
||||
public class CGroupBox : GroupBox
|
||||
{
|
||||
public CGroupBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
BackColor = Color.FromArgb(255, 32, 32, 32);
|
||||
ForeColor = Color.FromArgb(255, 192, 192, 192);
|
||||
BorderColor = Color.FromArgb(255, 64, 64, 64);
|
||||
FlatStyle = FlatStyle.Flat;
|
||||
}
|
||||
|
||||
private Color _borderColor = Color.Black;
|
||||
|
||||
public Color BorderColor
|
||||
{
|
||||
get => _borderColor;
|
||||
set => _borderColor = value;
|
||||
}
|
||||
|
||||
private SolidBrush _brushBackColor;
|
||||
private SolidBrush _brushForeColor;
|
||||
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
if (_brushBackColor == null || _brushBackColor.Color != BackColor)
|
||||
{
|
||||
_brushBackColor = new SolidBrush(BackColor);
|
||||
}
|
||||
|
||||
if (_brushForeColor == null || _brushForeColor.Color != ForeColor)
|
||||
{
|
||||
_brushForeColor = new SolidBrush(ForeColor);
|
||||
}
|
||||
|
||||
Size tSize = TextRenderer.MeasureText(Text, Font);
|
||||
|
||||
Rectangle borderRect = new Rectangle(0, 0, Width, Height);
|
||||
borderRect.Y = (borderRect.Y + (tSize.Height / 2));
|
||||
borderRect.Height = (borderRect.Height - (tSize.Height / 2));
|
||||
ControlPaint.DrawBorder(e.Graphics, borderRect, _borderColor, ButtonBorderStyle.Solid);
|
||||
|
||||
Rectangle textRect = new Rectangle(0, 0, Width, Height);
|
||||
textRect.X = (textRect.X + 6);
|
||||
textRect.Width = tSize.Width;
|
||||
textRect.Height = tSize.Height;
|
||||
e.Graphics.FillRectangle(_brushBackColor, textRect);
|
||||
e.Graphics.DrawString(Text, Font, _brushForeColor, textRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
VAR.Toolbox/Controls/CSplitContainer.cs
Normal file
18
VAR.Toolbox/Controls/CSplitContainer.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace VAR.Toolbox.Controls
|
||||
{
|
||||
public class CSplitContainer : System.Windows.Forms.SplitContainer
|
||||
{
|
||||
public CSplitContainer()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
BackColor = Color.FromArgb(255, 32, 32, 32);
|
||||
ForeColor = Color.FromArgb(255, 192, 192, 192);
|
||||
}
|
||||
}
|
||||
}
|
||||
40
VAR.Toolbox/Controls/ControlsUtils.cs
Normal file
40
VAR.Toolbox/Controls/ControlsUtils.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VAR.Toolbox.Controls
|
||||
{
|
||||
public static class ControlsUtils
|
||||
{
|
||||
public static float GetFontSize(Control ctrl, float size)
|
||||
{
|
||||
return size * 96f / ctrl.CreateGraphics().DpiX;
|
||||
}
|
||||
|
||||
private delegate void SetControlPropertyThreadSafeDelegate(
|
||||
Control control,
|
||||
string propertyName,
|
||||
object propertyValue);
|
||||
|
||||
public static void SetControlPropertyThreadSafe(
|
||||
Control control,
|
||||
string propertyName,
|
||||
object propertyValue)
|
||||
{
|
||||
if (control.InvokeRequired)
|
||||
{
|
||||
control.Invoke(new SetControlPropertyThreadSafeDelegate
|
||||
(SetControlPropertyThreadSafe),
|
||||
new[] { control, propertyName, propertyValue });
|
||||
}
|
||||
else
|
||||
{
|
||||
control.GetType().InvokeMember(
|
||||
propertyName,
|
||||
BindingFlags.SetProperty,
|
||||
null,
|
||||
control,
|
||||
new[] { propertyValue });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,13 +8,7 @@ namespace VAR.Toolbox.Controls
|
||||
{
|
||||
#region Declarations
|
||||
|
||||
private Image _imageShow = null;
|
||||
|
||||
// Image projection
|
||||
private double offsetX = 0;
|
||||
private double offsetY = 0;
|
||||
private double scaleX = 1.0f;
|
||||
private double scaleY = 1.0f;
|
||||
private Image _imageShow;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -22,13 +16,14 @@ namespace VAR.Toolbox.Controls
|
||||
|
||||
public Image ImageShow
|
||||
{
|
||||
get { return _imageShow; }
|
||||
// ReSharper disable once InconsistentlySynchronizedField
|
||||
get => _imageShow;
|
||||
set
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
_imageShow = value;
|
||||
this.Invalidate();
|
||||
Invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,6 +33,11 @@ namespace VAR.Toolbox.Controls
|
||||
#region Control life cycle
|
||||
|
||||
public CtrImageViewer()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
BackColor = Color.Black;
|
||||
}
|
||||
@@ -52,7 +52,7 @@ namespace VAR.Toolbox.Controls
|
||||
{
|
||||
base.OnResize(e);
|
||||
//Redraw(null);
|
||||
this.Invalidate();
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -65,11 +65,12 @@ namespace VAR.Toolbox.Controls
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lock (_imageShow)
|
||||
{
|
||||
if (graph == null)
|
||||
{
|
||||
graph = this.CreateGraphics();
|
||||
graph = CreateGraphics();
|
||||
}
|
||||
|
||||
// Calcular dimensiones a dibujar y centrar
|
||||
@@ -77,49 +78,44 @@ namespace VAR.Toolbox.Controls
|
||||
int imgDrawHeight;
|
||||
float imgDrawX = 0;
|
||||
float imgDrawY = 0;
|
||||
float relation = (float)_imageShow.Width / (float)_imageShow.Height;
|
||||
float relation = _imageShow.Width / (float)_imageShow.Height;
|
||||
if (relation > 0)
|
||||
{
|
||||
// Imagen mas ancha que alta
|
||||
imgDrawHeight = (int)(this.Width / relation);
|
||||
if (imgDrawHeight > this.Height)
|
||||
imgDrawHeight = (int)(Width / relation);
|
||||
if (imgDrawHeight > Height)
|
||||
{
|
||||
imgDrawHeight = this.Height;
|
||||
imgDrawWidth = (int)(this.Height * relation);
|
||||
imgDrawX = ((this.Width - imgDrawWidth) / 2.0f);
|
||||
imgDrawHeight = Height;
|
||||
imgDrawWidth = (int)(Height * relation);
|
||||
imgDrawX = ((Width - imgDrawWidth) / 2.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
imgDrawWidth = this.Width;
|
||||
imgDrawY = ((this.Height - imgDrawHeight) / 2.0f);
|
||||
imgDrawWidth = Width;
|
||||
imgDrawY = ((Height - imgDrawHeight) / 2.0f);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Imagen mas alta que ancha
|
||||
imgDrawWidth = (int)(this.Width * relation);
|
||||
if (imgDrawWidth > this.Width)
|
||||
imgDrawWidth = (int)(Width * relation);
|
||||
if (imgDrawWidth > Width)
|
||||
{
|
||||
imgDrawWidth = this.Width;
|
||||
imgDrawHeight = (int)(this.Height / relation);
|
||||
imgDrawY = ((this.Height - imgDrawHeight) / 2.0f);
|
||||
imgDrawWidth = Width;
|
||||
imgDrawHeight = (int)(Height / relation);
|
||||
imgDrawY = ((Height - imgDrawHeight) / 2.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
imgDrawHeight = this.Height;
|
||||
imgDrawX = ((this.Width - imgDrawWidth) / 2.0f);
|
||||
imgDrawHeight = Height;
|
||||
imgDrawX = ((Width - imgDrawWidth) / 2.0f);
|
||||
}
|
||||
}
|
||||
|
||||
graph.DrawImage(_imageShow, imgDrawX, imgDrawY, imgDrawWidth, imgDrawHeight);
|
||||
offsetX = imgDrawX;
|
||||
offsetY = imgDrawY;
|
||||
scaleX = (double)imgDrawWidth / (double)_imageShow.Width;
|
||||
scaleY = (double)imgDrawHeight / (double)_imageShow.Height;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using VAR.Toolbox.Code;
|
||||
|
||||
namespace VAR.Toolbox.Controls
|
||||
{
|
||||
public class CtrOutput : Control
|
||||
public class CtrOutput : Control, IOutputHandler
|
||||
{
|
||||
private ListBox _listBox;
|
||||
private ListBoxMonospace _listBox;
|
||||
|
||||
private Timer _timer;
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace VAR.Toolbox.Controls
|
||||
{
|
||||
public string Text { get; set; }
|
||||
public object Data { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Text;
|
||||
@@ -32,17 +33,12 @@ namespace VAR.Toolbox.Controls
|
||||
|
||||
private void InitializeControls()
|
||||
{
|
||||
_listBox = new ListBox
|
||||
_listBox = new ListBoxMonospace
|
||||
{
|
||||
Dock = DockStyle.Fill,
|
||||
FormattingEnabled = true,
|
||||
Font = new System.Drawing.Font("Consolas", 9),
|
||||
BackColor = Color.Black,
|
||||
ForeColor = Color.Gray,
|
||||
SelectionMode = SelectionMode.MultiExtended,
|
||||
};
|
||||
_listBox.MouseDoubleClick += _listBox_MouseDoubleClick;
|
||||
_listBox.KeyDown += _listBox_KeyDown;
|
||||
_listBox.MouseDoubleClick += ListBox_MouseDoubleClick;
|
||||
_listBox.KeyDown += ListBox_KeyDown;
|
||||
Controls.Add(_listBox);
|
||||
|
||||
_timer = new Timer
|
||||
@@ -50,7 +46,7 @@ namespace VAR.Toolbox.Controls
|
||||
Interval = 100,
|
||||
Enabled = true
|
||||
};
|
||||
_timer.Tick += _timer_Tick;
|
||||
_timer.Tick += Timer_Tick;
|
||||
|
||||
Disposed += CtrOutput_Disposed;
|
||||
}
|
||||
@@ -68,10 +64,11 @@ namespace VAR.Toolbox.Controls
|
||||
CopyToClipboard();
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.ProcessCmdKey(ref msg, keyData);
|
||||
}
|
||||
|
||||
private void _listBox_KeyDown(object sender, KeyEventArgs e)
|
||||
private void ListBox_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Control && e.KeyCode == Keys.C)
|
||||
{
|
||||
@@ -86,18 +83,19 @@ namespace VAR.Toolbox.Controls
|
||||
{
|
||||
sbText.AppendLine(item.Text);
|
||||
}
|
||||
|
||||
if (sbText.Length > 0)
|
||||
{
|
||||
Clipboard.SetText(sbText.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private void _listBox_MouseDoubleClick(object sender, MouseEventArgs e)
|
||||
private void ListBox_MouseDoubleClick(object sender, MouseEventArgs e)
|
||||
{
|
||||
DoubleClick?.Invoke(sender, e);
|
||||
}
|
||||
|
||||
private void _timer_Tick(object sender, EventArgs e)
|
||||
private void Timer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
if (_updated)
|
||||
{
|
||||
@@ -105,8 +103,8 @@ namespace VAR.Toolbox.Controls
|
||||
}
|
||||
}
|
||||
|
||||
private bool _updated = false;
|
||||
private List<OutputItem> _pendingOutput = new List<OutputItem>();
|
||||
private bool _updated;
|
||||
private readonly List<OutputItem> _pendingOutput = new List<OutputItem>();
|
||||
|
||||
private void UpdatePosition()
|
||||
{
|
||||
@@ -118,6 +116,7 @@ namespace VAR.Toolbox.Controls
|
||||
{
|
||||
_listBox.Items.Add(item);
|
||||
}
|
||||
|
||||
_pendingOutput.Clear();
|
||||
_listBox.ResumeLayout();
|
||||
|
||||
@@ -130,10 +129,12 @@ namespace VAR.Toolbox.Controls
|
||||
}
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
|
||||
private static extern IntPtr SendMessage(HandleRef hWnd, Int32 Msg, IntPtr wParam, IntPtr lParam);
|
||||
private static extern IntPtr SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
private static void EnableRepaint(HandleRef handle, bool enable)
|
||||
{
|
||||
// ReSharper disable once InconsistentNaming
|
||||
// ReSharper disable once IdentifierTypo
|
||||
const int WM_SETREDRAW = 0x000B;
|
||||
SendMessage(handle, WM_SETREDRAW, new IntPtr(enable ? 1 : 0), IntPtr.Zero);
|
||||
}
|
||||
@@ -167,6 +168,7 @@ namespace VAR.Toolbox.Controls
|
||||
public string GetCurrentText()
|
||||
{
|
||||
if (_listBox.SelectedItems.Count == 0) { return null; }
|
||||
|
||||
OutputItem item = (OutputItem)_listBox.SelectedItems[0];
|
||||
return item?.Text;
|
||||
}
|
||||
@@ -174,6 +176,7 @@ namespace VAR.Toolbox.Controls
|
||||
public object GetCurrentData()
|
||||
{
|
||||
if (_listBox.SelectedItems.Count == 0) { return null; }
|
||||
|
||||
OutputItem item = (OutputItem)_listBox.SelectedItems[0];
|
||||
return item?.Data;
|
||||
}
|
||||
|
||||
21
VAR.Toolbox/Controls/Frame.cs
Normal file
21
VAR.Toolbox/Controls/Frame.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace VAR.Toolbox.Controls
|
||||
{
|
||||
public class Frame : System.Windows.Forms.Form
|
||||
{
|
||||
public Frame()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
Font = new Font(Font.Name, ControlsUtils.GetFontSize(this, 8.25f), Font.Style, Font.Unit,
|
||||
Font.GdiCharSet, Font.GdiVerticalFont);
|
||||
AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
BackColor = Color.FromArgb(255, 32, 32, 32);
|
||||
ForeColor = Color.FromArgb(255, 192, 192, 192);
|
||||
}
|
||||
}
|
||||
}
|
||||
38
VAR.Toolbox/Controls/ListBoxMonospace.cs
Normal file
38
VAR.Toolbox/Controls/ListBoxMonospace.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VAR.Toolbox.Controls
|
||||
{
|
||||
public class ListBoxMonospace : ListBox
|
||||
{
|
||||
public ListBoxMonospace()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
FormattingEnabled = true;
|
||||
Font = new Font("Consolas", ControlsUtils.GetFontSize(this, 9));
|
||||
BackColor = Color.Black;
|
||||
ForeColor = Color.Gray;
|
||||
BorderStyle = BorderStyle.FixedSingle;
|
||||
SelectionMode = SelectionMode.MultiExtended;
|
||||
}
|
||||
|
||||
protected override void OnMouseWheel(MouseEventArgs e)
|
||||
{
|
||||
((HandledMouseEventArgs)e).Handled = true;
|
||||
const int Rows = 5;
|
||||
if (e.Delta > 0)
|
||||
{
|
||||
if (TopIndex < Rows) { TopIndex = 0; }
|
||||
else { TopIndex -= Rows; }
|
||||
}
|
||||
else
|
||||
{
|
||||
TopIndex += Rows;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
37
VAR.Toolbox/Controls/ListBoxNormal.cs
Normal file
37
VAR.Toolbox/Controls/ListBoxNormal.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VAR.Toolbox.Controls
|
||||
{
|
||||
public class ListBoxNormal : ListBox
|
||||
{
|
||||
public ListBoxNormal()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
FormattingEnabled = true;
|
||||
Font = new Font("Microsoft Sans Serif", ControlsUtils.GetFontSize(this, 8.25f));
|
||||
BackColor = Color.Black;
|
||||
ForeColor = Color.Gray;
|
||||
BorderStyle = BorderStyle.FixedSingle;
|
||||
}
|
||||
|
||||
protected override void OnMouseWheel(MouseEventArgs e)
|
||||
{
|
||||
((HandledMouseEventArgs)e).Handled = true;
|
||||
const int Rows = 5;
|
||||
if (e.Delta > 0)
|
||||
{
|
||||
if (TopIndex < Rows) { TopIndex = 0; }
|
||||
else { TopIndex -= Rows; }
|
||||
}
|
||||
else
|
||||
{
|
||||
TopIndex += Rows;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
VAR.Toolbox/Controls/SubFrame.cs
Normal file
21
VAR.Toolbox/Controls/SubFrame.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace VAR.Toolbox.Controls
|
||||
{
|
||||
public class SubFrame : System.Windows.Forms.UserControl
|
||||
{
|
||||
public SubFrame()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
Font = new Font(Font.Name, ControlsUtils.GetFontSize(this, 8.25f), Font.Style, Font.Unit,
|
||||
Font.GdiCharSet, Font.GdiVerticalFont);
|
||||
AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
|
||||
BackColor = Color.FromArgb(255, 32, 32, 32);
|
||||
ForeColor = Color.FromArgb(255, 192, 192, 192);
|
||||
}
|
||||
}
|
||||
}
|
||||
21
VAR.Toolbox/Controls/TextBoxMonospace.cs
Normal file
21
VAR.Toolbox/Controls/TextBoxMonospace.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VAR.Toolbox.Controls
|
||||
{
|
||||
public class TextBoxMonospace : TextBox
|
||||
{
|
||||
public TextBoxMonospace()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
Font = new Font("Consolas", ControlsUtils.GetFontSize(this, 9.0f));
|
||||
BackColor = Color.FromArgb(255, 0, 0, 0);
|
||||
ForeColor = Color.FromArgb(255, 192, 192, 192);
|
||||
BorderStyle = BorderStyle.FixedSingle;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
VAR.Toolbox/Controls/TextBoxNormal.cs
Normal file
21
VAR.Toolbox/Controls/TextBoxNormal.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VAR.Toolbox.Controls
|
||||
{
|
||||
public class TextBoxNormal : TextBox
|
||||
{
|
||||
public TextBoxNormal()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
Font = new Font("Microsoft Sans Serif", ControlsUtils.GetFontSize(this, 8.25f));
|
||||
BackColor = Color.FromArgb(255, 0, 0, 0);
|
||||
ForeColor = Color.FromArgb(255, 192, 192, 192);
|
||||
BorderStyle = BorderStyle.FixedSingle;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
using VAR.Toolbox.Code;
|
||||
using VAR.Toolbox.UI;
|
||||
@@ -15,6 +19,16 @@ namespace VAR.Toolbox
|
||||
{
|
||||
Application.ThreadException += Application_ThreadException;
|
||||
|
||||
// Load plug-ins
|
||||
string executingAssemblyPath = Assembly.GetExecutingAssembly().Location;
|
||||
string dirName = Path.GetDirectoryName(executingAssemblyPath);
|
||||
string execName = Path.GetFileNameWithoutExtension(executingAssemblyPath);
|
||||
if (dirName != null)
|
||||
{
|
||||
string[] assemblyPaths = Directory.GetFiles(dirName, $"{execName}*.dll");
|
||||
foreach (string assemblyPath in assemblyPaths) { AssemblyLoadFull(assemblyPath); }
|
||||
}
|
||||
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
try
|
||||
@@ -33,5 +47,39 @@ namespace VAR.Toolbox
|
||||
Logger.Log(e.Exception);
|
||||
Application.Exit();
|
||||
}
|
||||
|
||||
private static void AssemblyLoadFull(string fullPath, List<string> allAssemblyNames = null)
|
||||
{
|
||||
if (allAssemblyNames == null)
|
||||
{
|
||||
allAssemblyNames = AppDomain.CurrentDomain.GetAssemblies().Select(a => a.GetName().Name).ToList();
|
||||
}
|
||||
|
||||
Assembly asm = null;
|
||||
try
|
||||
{
|
||||
asm = Assembly.LoadFrom(fullPath);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
|
||||
if (asm == null) { return; }
|
||||
|
||||
allAssemblyNames.Add(asm.GetName().Name);
|
||||
|
||||
// Load dependencies
|
||||
string dirPath = Path.GetDirectoryName(fullPath);
|
||||
AssemblyName[] asmNames = asm.GetReferencedAssemblies();
|
||||
foreach (AssemblyName asmName in asmNames)
|
||||
{
|
||||
if (allAssemblyNames.Contains(asmName.Name) == false)
|
||||
{
|
||||
string fullPathAux = $"{dirPath}/{asmName.Name}.dll";
|
||||
AssemblyLoadFull(fullPathAux, allAssemblyNames);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("VAR.Toolbox")]
|
||||
[assembly: AssemblyCopyright("Copyright © VAR 2017-2018")]
|
||||
[assembly: AssemblyCopyright("Copyright © VAR 2017-2022")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user