mirror of
https://github.com/ckaczor/Common.git
synced 2026-01-13 17:22:40 -05:00
Initial commit
This commit is contained in:
63
.gitattributes
vendored
Normal file
63
.gitattributes
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
###############################################################################
|
||||
# Set default behavior to automatically normalize line endings.
|
||||
###############################################################################
|
||||
* text=auto
|
||||
|
||||
###############################################################################
|
||||
# Set default behavior for command prompt diff.
|
||||
#
|
||||
# This is need for earlier builds of msysgit that does not have it on by
|
||||
# default for csharp files.
|
||||
# Note: This is only used by command line
|
||||
###############################################################################
|
||||
#*.cs diff=csharp
|
||||
|
||||
###############################################################################
|
||||
# Set the merge driver for project and solution files
|
||||
#
|
||||
# Merging from the command prompt will add diff markers to the files if there
|
||||
# are conflicts (Merging from VS is not affected by the settings below, in VS
|
||||
# the diff markers are never inserted). Diff markers may cause the following
|
||||
# file extensions to fail to load in VS. An alternative would be to treat
|
||||
# these files as binary and thus will always conflict and require user
|
||||
# intervention with every merge. To do so, just uncomment the entries below
|
||||
###############################################################################
|
||||
#*.sln merge=binary
|
||||
#*.csproj merge=binary
|
||||
#*.vbproj merge=binary
|
||||
#*.vcxproj merge=binary
|
||||
#*.vcproj merge=binary
|
||||
#*.dbproj merge=binary
|
||||
#*.fsproj merge=binary
|
||||
#*.lsproj merge=binary
|
||||
#*.wixproj merge=binary
|
||||
#*.modelproj merge=binary
|
||||
#*.sqlproj merge=binary
|
||||
#*.wwaproj merge=binary
|
||||
|
||||
###############################################################################
|
||||
# behavior for image files
|
||||
#
|
||||
# image files are treated as binary by default.
|
||||
###############################################################################
|
||||
#*.jpg binary
|
||||
#*.png binary
|
||||
#*.gif binary
|
||||
|
||||
###############################################################################
|
||||
# diff behavior for common document formats
|
||||
#
|
||||
# Convert binary document formats to text before diffing them. This feature
|
||||
# is only available from the command line. Turn it on by uncommenting the
|
||||
# entries below.
|
||||
###############################################################################
|
||||
#*.doc diff=astextplain
|
||||
#*.DOC diff=astextplain
|
||||
#*.docx diff=astextplain
|
||||
#*.DOCX diff=astextplain
|
||||
#*.dot diff=astextplain
|
||||
#*.DOT diff=astextplain
|
||||
#*.pdf diff=astextplain
|
||||
#*.PDF diff=astextplain
|
||||
#*.rtf diff=astextplain
|
||||
#*.RTF diff=astextplain
|
||||
156
.gitignore
vendored
Normal file
156
.gitignore
vendored
Normal file
@@ -0,0 +1,156 @@
|
||||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.sln.docstates
|
||||
|
||||
# Build results
|
||||
|
||||
[Dd]ebug/
|
||||
[Rr]elease/
|
||||
x64/
|
||||
build/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
|
||||
# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets
|
||||
!packages/*/build/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.log
|
||||
*.scc
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# NCrunch
|
||||
*.ncrunch*
|
||||
.*crunch*.local.xml
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.Publish.xml
|
||||
|
||||
# NuGet Packages Directory
|
||||
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
|
||||
#packages/
|
||||
|
||||
# Windows Azure Build Output
|
||||
csx
|
||||
*.build.csdef
|
||||
|
||||
# Windows Store app package directory
|
||||
AppPackages/
|
||||
|
||||
# Others
|
||||
sql/
|
||||
*.Cache
|
||||
ClientBin/
|
||||
[Ss]tyle[Cc]op.*
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.[Pp]ublish.xml
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file to a newer
|
||||
# Visual Studio version. Backup files are not needed, because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
|
||||
# SQL Server files
|
||||
App_Data/*.mdf
|
||||
App_Data/*.ldf
|
||||
|
||||
|
||||
#LightSwitch generated files
|
||||
GeneratedArtifacts/
|
||||
_Pvt_Extensions/
|
||||
ModelManifest.xml
|
||||
|
||||
# =========================
|
||||
# Windows detritus
|
||||
# =========================
|
||||
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Mac desktop service store files
|
||||
.DS_Store
|
||||
BIN
ChrisKaczor.pfx
Normal file
BIN
ChrisKaczor.pfx
Normal file
Binary file not shown.
217
Common.csproj
Normal file
217
Common.csproj
Normal file
@@ -0,0 +1,217 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>Common</RootNamespace>
|
||||
<AssemblyName>Common</AssemblyName>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<SccProjectName>SAK</SccProjectName>
|
||||
<SccLocalPath>SAK</SccLocalPath>
|
||||
<SccAuxPath>SAK</SccAuxPath>
|
||||
<SccProvider>SAK</SccProvider>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>ChrisKaczor.pfx</AssemblyOriginatorKeyFile>
|
||||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
|
||||
<TargetFrameworkProfile>
|
||||
</TargetFrameworkProfile>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>.\bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>.\bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<CodeAnalysisLogFile>bin\Debug\Common.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
|
||||
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
|
||||
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
|
||||
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
|
||||
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<CodeAnalysisLogFile>bin\Release\Common.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
|
||||
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
|
||||
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
|
||||
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
|
||||
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<CodeAnalysisLogFile>bin\Debug\Common.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
|
||||
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
|
||||
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
|
||||
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
|
||||
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
|
||||
<CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<CodeAnalysisLogFile>bin\Release\Common.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
|
||||
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
|
||||
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
|
||||
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
|
||||
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
|
||||
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.configuration" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.IO">
|
||||
<HintPath>packages\Microsoft.Bcl.1.1.8\lib\net40\System.IO.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime">
|
||||
<HintPath>packages\Microsoft.Bcl.1.1.8\lib\net40\System.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.Remoting" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.Threading.Tasks">
|
||||
<HintPath>packages\Microsoft.Bcl.1.1.8\lib\net40\System.Threading.Tasks.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.XML" />
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DateTimeExtensions.cs" />
|
||||
<Compile Include="Trace\BeginEndTracer.cs" />
|
||||
<Compile Include="Extensions\Extensions.cs" />
|
||||
<Compile Include="Helpers\ApplicationIsolation.cs" />
|
||||
<Compile Include="Helpers\DelayedMethod.cs" />
|
||||
<Compile Include="Helpers\Reflection.cs" />
|
||||
<Compile Include="Internet\Browser.cs" />
|
||||
<Compile Include="Internet\FtpClient.cs" />
|
||||
<Compile Include="Internet\TelnetClient.cs" />
|
||||
<Compile Include="IO\FileCompare.cs" />
|
||||
<Compile Include="IO\InterprocessMessage.cs" />
|
||||
<Compile Include="IO\Keyboard.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Trace\Tracer.cs" />
|
||||
<Compile Include="Settings\Extensions.cs" />
|
||||
<Compile Include="Settings\GenericSettingsProvider.cs" />
|
||||
<Compile Include="Xml\XmlExtensions.cs" />
|
||||
<AppDesigner Include="Properties\" />
|
||||
<Compile Include="Xml\XmlSanitizingStream.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 2.0 %28x86%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.0 %28x86%29</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.VisualBasic.PowerPacks.10.0">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Microsoft Visual Basic PowerPacks 10.0</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="ChrisKaczor.pfx" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<PostBuildEvent>D:\Code\Personal\Versioner\bin\Release\Versioner.exe "$(ProjectDir)Properties\AssemblyInfo.cs" 2</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<Import Project="..\FilePusher\packages\Microsoft.Bcl.Build.1.0.13\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\FilePusher\packages\Microsoft.Bcl.Build.1.0.13\tools\Microsoft.Bcl.Build.targets')" />
|
||||
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
|
||||
<Error Condition="!Exists('..\FilePusher\packages\Microsoft.Bcl.Build.1.0.13\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
|
||||
<Error Condition="Exists('..\FilePusher\packages\Microsoft.Bcl.Build.1.0.13\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
|
||||
</Target>
|
||||
<Import Project="packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
|
||||
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
|
||||
<Error Condition="!Exists('packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
|
||||
<Error Condition="Exists('packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
|
||||
</Target>
|
||||
</Project>
|
||||
34
Common.sln
Normal file
34
Common.sln
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.30110.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Common.csproj", "{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Debug|x64.Build.0 = Debug|x64
|
||||
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Debug|x86.Build.0 = Debug|x86
|
||||
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Release|x64.ActiveCfg = Release|x64
|
||||
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Release|x64.Build.0 = Release|x64
|
||||
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Release|x86.ActiveCfg = Release|x86
|
||||
{17864D82-457D-4A0A-BC10-1D07F2B3A5D6}.Release|x86.Build.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
15
DateTimeExtensions.cs
Normal file
15
DateTimeExtensions.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace Common
|
||||
{
|
||||
public static class DateTimeExtensions
|
||||
{
|
||||
public static DateTime FromUnixTime(double unixTime)
|
||||
{
|
||||
// Unix timestamp is seconds past epoch
|
||||
DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);
|
||||
dtDateTime = dtDateTime.AddSeconds(unixTime).ToLocalTime();
|
||||
return dtDateTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
45
Extensions/Extensions.cs
Normal file
45
Extensions/Extensions.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Common.Extensions
|
||||
{
|
||||
public static class Extensions
|
||||
{
|
||||
public static bool GetBitValue(this int integer, int bit)
|
||||
{
|
||||
return (integer & (1 << bit)) != 0;
|
||||
}
|
||||
|
||||
public static int SetBitValue(this int integer, int bit, bool value)
|
||||
{
|
||||
if (value)
|
||||
integer |= 1 << bit;
|
||||
else
|
||||
integer &= ~(1 << bit);
|
||||
|
||||
return integer;
|
||||
}
|
||||
|
||||
public static string ToJson<T>(this T obj) where T : class
|
||||
{
|
||||
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
|
||||
using (MemoryStream stream = new MemoryStream())
|
||||
{
|
||||
serializer.WriteObject(stream, obj);
|
||||
return Encoding.Default.GetString(stream.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
public static Task<T> WithTimeout<T>(this Task<T> task, int duration)
|
||||
{
|
||||
return Task.Factory.StartNew(() =>
|
||||
{
|
||||
bool b = task.Wait(duration);
|
||||
if (b) return task.Result;
|
||||
return default(T);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
40
Helpers/ApplicationIsolation.cs
Normal file
40
Helpers/ApplicationIsolation.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Security.AccessControl;
|
||||
using System.Security.Principal;
|
||||
using System.Threading;
|
||||
|
||||
namespace Common.Helpers
|
||||
{
|
||||
public static class ApplicationIsolation
|
||||
{
|
||||
public static IDisposable GetIsolationHandle()
|
||||
{
|
||||
string applicationName = Assembly.GetEntryAssembly().GetName().Name;
|
||||
|
||||
return GetIsolationHandle(applicationName);
|
||||
}
|
||||
|
||||
public static IDisposable GetIsolationHandle(string applicationName)
|
||||
{
|
||||
// Create mutex security settings
|
||||
MutexSecurity mutexSecurity = new MutexSecurity();
|
||||
|
||||
// Create a world security identifier
|
||||
SecurityIdentifier securityIdentifier = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
|
||||
|
||||
// Create an access rule for the mutex
|
||||
MutexAccessRule mutexAccessRule = new MutexAccessRule(securityIdentifier, MutexRights.FullControl, AccessControlType.Allow);
|
||||
|
||||
// Add the access rule to the mutex security settings
|
||||
mutexSecurity.AddAccessRule(mutexAccessRule);
|
||||
|
||||
// Create the mutex and see if it was newly created
|
||||
bool createdNew;
|
||||
Mutex mutex = new Mutex(false, applicationName, out createdNew, mutexSecurity);
|
||||
|
||||
// Return the mutex if it is new
|
||||
return createdNew ? mutex : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Helpers/DelayedMethod.cs
Normal file
36
Helpers/DelayedMethod.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Timers;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace Common.Helpers
|
||||
{
|
||||
public class DelayedMethod
|
||||
{
|
||||
public delegate void DelayedMethodDelegate();
|
||||
|
||||
private readonly Timer _delayTimer;
|
||||
private readonly DelayedMethodDelegate _methodDelegate;
|
||||
private readonly Dispatcher _dispatcher;
|
||||
|
||||
public DelayedMethod(int interval, DelayedMethodDelegate methodDelegate)
|
||||
{
|
||||
_dispatcher = Dispatcher.CurrentDispatcher;
|
||||
_methodDelegate = methodDelegate;
|
||||
|
||||
_delayTimer = new Timer(interval) { AutoReset = false };
|
||||
_delayTimer.Elapsed += handleDelayTimerElapsed;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_delayTimer.Stop();
|
||||
_delayTimer.Start();
|
||||
}
|
||||
|
||||
private void handleDelayTimerElapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
// Make sure we're on the right thread
|
||||
if (!_dispatcher.CheckAccess())
|
||||
_dispatcher.Invoke(_methodDelegate);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Helpers/Reflection.cs
Normal file
18
Helpers/Reflection.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace Common.Helpers
|
||||
{
|
||||
public static class Reflection
|
||||
{
|
||||
public static string GetPropertyName<T>(Expression<Func<T>> propertyExpression)
|
||||
{
|
||||
MemberExpression memberExpression = (propertyExpression.Body as MemberExpression);
|
||||
|
||||
if (memberExpression == null)
|
||||
return null;
|
||||
|
||||
return memberExpression.Member.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
62
IO/FileCompare.cs
Normal file
62
IO/FileCompare.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Common.IO
|
||||
{
|
||||
public class FileCompare
|
||||
{
|
||||
#region Comparison
|
||||
|
||||
public bool Compare(string fileName1, string fileName2)
|
||||
{
|
||||
FileStream fileStream1 = null;
|
||||
FileStream fileStream2 = null;
|
||||
bool compareStatus = true;
|
||||
|
||||
try
|
||||
{
|
||||
// Create file streams for each file
|
||||
fileStream1 = new FileStream(fileName1, FileMode.Open);
|
||||
fileStream2 = new FileStream(fileName2, FileMode.Open);
|
||||
|
||||
// If the files aren't the same length then don't bother with more
|
||||
if (fileStream1.Length != fileStream2.Length)
|
||||
throw new ApplicationException();
|
||||
|
||||
// Start comparing the bytes of each file
|
||||
int fileByte1;
|
||||
do
|
||||
{
|
||||
// Read a byte from the first file
|
||||
fileByte1 = fileStream1.ReadByte();
|
||||
|
||||
// Read a byte from the second file
|
||||
int fileByte2 = fileStream2.ReadByte();
|
||||
|
||||
// If the bytes don't match then stop
|
||||
if (fileByte1 != fileByte2)
|
||||
throw new ApplicationException();
|
||||
}
|
||||
while (fileByte1 != -1);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Compare failed
|
||||
compareStatus = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Close both of the file streams
|
||||
if (fileStream1 != null)
|
||||
fileStream1.Close();
|
||||
|
||||
if (fileStream2 != null)
|
||||
fileStream2.Close();
|
||||
}
|
||||
|
||||
return compareStatus;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
107
IO/InterprocessMessage.cs
Normal file
107
IO/InterprocessMessage.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Remoting;
|
||||
using System.Runtime.Remoting.Channels;
|
||||
using System.Runtime.Remoting.Channels.Ipc;
|
||||
using System.Threading;
|
||||
|
||||
namespace Common.IO
|
||||
{
|
||||
#region Sender
|
||||
|
||||
/// <summary>
|
||||
/// Helper class for sending a simple interprocess string message
|
||||
/// </summary>
|
||||
public static class InterprocessMessageSender
|
||||
{
|
||||
public static void SendMessage(string message)
|
||||
{
|
||||
string applicationName = Assembly.GetEntryAssembly().GetName().Name;
|
||||
|
||||
SendMessage(applicationName, message);
|
||||
}
|
||||
|
||||
public static void SendMessage(string applicationName, string message)
|
||||
{
|
||||
// Create the client channel
|
||||
IpcClientChannel clientChannel = new IpcClientChannel();
|
||||
|
||||
// Register the client chanel
|
||||
ChannelServices.RegisterChannel(clientChannel, false);
|
||||
|
||||
// Build a URL string for the remote listener
|
||||
string messageUrl = string.Format("ipc://{0}/MessageListener", applicationName);
|
||||
|
||||
// Get an instance of the remote listener
|
||||
InterprocessMessageListener messageListener = (InterprocessMessageListener) Activator.GetObject(typeof(InterprocessMessageListener), messageUrl);
|
||||
|
||||
// Inform the remote object of the message
|
||||
messageListener.HandleMessage(message);
|
||||
|
||||
// Unregister the channel
|
||||
ChannelServices.UnregisterChannel(clientChannel);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Listener
|
||||
|
||||
/// <summary>
|
||||
/// Helper class for receiving a simple interprocess string message
|
||||
/// </summary>
|
||||
public class InterprocessMessageListener : MarshalByRefObject
|
||||
{
|
||||
#region Event argument
|
||||
|
||||
public class InterprocessMessageEventArgs : EventArgs
|
||||
{
|
||||
public string Message { get; private set; }
|
||||
|
||||
public InterprocessMessageEventArgs(string message)
|
||||
{
|
||||
Message = message;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
// The synchronization context of the thread that requested the event
|
||||
private readonly SynchronizationContext _syncContext;
|
||||
|
||||
// Event to be raised when a message has been received
|
||||
public event EventHandler<InterprocessMessageEventArgs> MessageReceived = delegate { };
|
||||
|
||||
public override object InitializeLifetimeService()
|
||||
{
|
||||
// Keep the listener around forever
|
||||
return null;
|
||||
}
|
||||
|
||||
public InterprocessMessageListener(string applicationName)
|
||||
{
|
||||
// Store the synchronization context of the current thread
|
||||
_syncContext = SynchronizationContext.Current;
|
||||
|
||||
// Create and register an IPC channel
|
||||
IpcServerChannel serverChannel = new IpcServerChannel(applicationName);
|
||||
ChannelServices.RegisterChannel(serverChannel, false);
|
||||
|
||||
// Expose the message listener for remoting
|
||||
RemotingConfiguration.RegisterWellKnownServiceType(typeof(InterprocessMessageListener), "MessageListener", WellKnownObjectMode.Singleton);
|
||||
RemotingServices.Marshal(this, "MessageListener");
|
||||
}
|
||||
|
||||
public void HandleMessage(string message)
|
||||
{
|
||||
// Fire the event on the original thread
|
||||
_syncContext.Send(delegate
|
||||
{
|
||||
// Raise an event with the contents of the message
|
||||
MessageReceived(this, new InterprocessMessageEventArgs(message));
|
||||
}, message);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
18
IO/Keyboard.cs
Normal file
18
IO/Keyboard.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Windows.Forms;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Common.IO
|
||||
{
|
||||
public static class Keyboard
|
||||
{
|
||||
[DllImport("user32.dll")]
|
||||
private static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey);
|
||||
|
||||
public static bool IsKeyPressed(Keys keys)
|
||||
{
|
||||
short state = GetAsyncKeyState(keys);
|
||||
|
||||
return ((state & 0x8000) == 0x8000);
|
||||
}
|
||||
}
|
||||
}
|
||||
42
Internet/Browser.cs
Normal file
42
Internet/Browser.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace Common.Internet
|
||||
{
|
||||
public class Browser
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public string Command { get; private set; }
|
||||
public string DefaultIcon { get; private set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
|
||||
public static Dictionary<string, Browser> DetectInstalledBrowsers()
|
||||
{
|
||||
var browsers = new Dictionary<string, Browser>();
|
||||
|
||||
RegistryKey browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Clients\StartMenuInternet");
|
||||
if (browserKeys == null)
|
||||
browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Clients\StartMenuInternet");
|
||||
|
||||
string[] browserNames = browserKeys.GetSubKeyNames();
|
||||
|
||||
foreach (string browserName in browserNames)
|
||||
{
|
||||
Browser browser = new Browser();
|
||||
RegistryKey browserKey = browserKeys.OpenSubKey(browserName);
|
||||
browser.Name = (string) browserKey.GetValue(null);
|
||||
RegistryKey browserKeyPath = browserKey.OpenSubKey(@"shell\open\command");
|
||||
browser.Command = (string) browserKeyPath.GetValue(null);
|
||||
RegistryKey browserIconPath = browserKey.OpenSubKey(@"DefaultIcon");
|
||||
browser.DefaultIcon = (string) browserIconPath.GetValue(null);
|
||||
browsers.Add(browserName, browser);
|
||||
}
|
||||
|
||||
return browsers;
|
||||
}
|
||||
}
|
||||
}
|
||||
256
Internet/FtpClient.cs
Normal file
256
Internet/FtpClient.cs
Normal file
@@ -0,0 +1,256 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Common.Internet
|
||||
{
|
||||
public class FtpClient
|
||||
{
|
||||
#region Private constants
|
||||
|
||||
private const int DATA_SIZE = 4096;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private member variables
|
||||
|
||||
private Socket _controlSocket; // The socket for sending control messsages
|
||||
private Socket _dataSocket; // The socket for transferring data
|
||||
private int _timeout = 30000; // The default send and receive timeouts
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private socket management code
|
||||
|
||||
private Socket connectSocket(string server, int port)
|
||||
{
|
||||
// Resolve the server name into an IP Host
|
||||
IPHostEntry ipHost = Dns.GetHostEntry(server);
|
||||
|
||||
// Get the first address from the host
|
||||
IPAddress ipAddress = ipHost.AddressList[0];
|
||||
|
||||
// Create an end point on the host at the requested port
|
||||
IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, port);
|
||||
|
||||
// Create a TCP socket to the end point on the host
|
||||
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
|
||||
// Set the send and receive timeouts requested
|
||||
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, _timeout);
|
||||
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, _timeout);
|
||||
|
||||
// Make the connection
|
||||
socket.Connect(ipEndPoint);
|
||||
|
||||
return socket;
|
||||
}
|
||||
|
||||
private static void disconnectSocket(ref Socket targetSocket)
|
||||
{
|
||||
if (targetSocket != null)
|
||||
{
|
||||
targetSocket.Shutdown(SocketShutdown.Both);
|
||||
targetSocket.Close();
|
||||
targetSocket = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static void sendSocketMessage(Socket targetSocket, string message)
|
||||
{
|
||||
sendSocketMessage(targetSocket, message, true);
|
||||
}
|
||||
|
||||
private static void sendSocketMessage(Socket targetSocket, string message, bool trailingNewline)
|
||||
{
|
||||
// Default to sending just the message
|
||||
string send = message;
|
||||
|
||||
// If a trailing newline is requested then add that to the string
|
||||
if (trailingNewline) send += "\r\n";
|
||||
|
||||
// Convert the requested message into a byte array
|
||||
byte[] rawData = Encoding.ASCII.GetBytes(send);
|
||||
|
||||
// Send the message and get the byte count back
|
||||
targetSocket.Send(rawData);
|
||||
}
|
||||
|
||||
private static string receiveSocketMessage(Socket sourceSocket, bool stripTrailingNewline)
|
||||
{
|
||||
// Initialize the decoded string message to return
|
||||
string message = string.Empty;
|
||||
|
||||
// Initialize the array of all lines
|
||||
string[] lines;
|
||||
|
||||
do
|
||||
{
|
||||
// Initialize the byte array buffer
|
||||
byte[] line = new byte[DATA_SIZE];
|
||||
|
||||
// Retrieve the data and get the byte count
|
||||
int bytesReceived = sourceSocket.Receive(line);
|
||||
|
||||
// Decode the string into a string for the current line
|
||||
string sLine = Encoding.ASCII.GetString(line, 0, bytesReceived);
|
||||
|
||||
// Replace the CR/LF pairs with just a LF
|
||||
sLine.Replace("\r\n", "\n");
|
||||
|
||||
// Split the message into an array of lines (we might get more than one)
|
||||
lines = sLine.Split('\n');
|
||||
|
||||
// Add this line to the main return string
|
||||
message += sLine;
|
||||
} while (lines[lines.Length - 2].Substring(3, 1) == "-");
|
||||
|
||||
// If requested to remove the trailing newline we should do it now
|
||||
if (stripTrailingNewline && message.EndsWith("\n"))
|
||||
{
|
||||
message = message.Remove(message.Length - 1, 1);
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
public int GetResponseCode(string message)
|
||||
{
|
||||
// Get the FTP response code from the string message
|
||||
return Convert.ToInt32(message.Substring(1, 3));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public interface methods
|
||||
|
||||
public void Connect(string server)
|
||||
{
|
||||
Connect(server, 21, _timeout);
|
||||
}
|
||||
|
||||
public void Connect(string server, int port, int timeout)
|
||||
{
|
||||
// Store the timeout requested so we can use it later
|
||||
_timeout = timeout * 1000;
|
||||
|
||||
// If we are currently connected in any way we should disconnect
|
||||
if (_controlSocket != null || _dataSocket != null) Disconnect();
|
||||
|
||||
// Create and connect the control socket
|
||||
_controlSocket = connectSocket(server, port);
|
||||
|
||||
// Retrieve the header message
|
||||
receiveSocketMessage(_controlSocket, true);
|
||||
}
|
||||
|
||||
public void Upload(string source)
|
||||
{
|
||||
string targetFile;
|
||||
|
||||
if (source.Contains(@"\"))
|
||||
targetFile = source.Substring(source.LastIndexOf(@"\") + 1);
|
||||
else
|
||||
targetFile = source;
|
||||
|
||||
// Create a stream reader for the file
|
||||
StreamReader streamReader = new StreamReader(source);
|
||||
|
||||
// Upload the file
|
||||
Upload(streamReader.BaseStream, targetFile);
|
||||
}
|
||||
|
||||
public void Upload(Stream source, string targetFile)
|
||||
{
|
||||
// Send a command requesting the passive port to connect to
|
||||
sendSocketMessage(_controlSocket, "PASV");
|
||||
|
||||
// Get the response back with the data we need
|
||||
string message = receiveSocketMessage(_controlSocket, true);
|
||||
|
||||
message = message.Replace("(", "<");
|
||||
message = message.Replace(")", ">");
|
||||
|
||||
// Create a regular expression to get the port data out
|
||||
Match match = new Regex("<(?<oct1>.*),(?<oct2>.*),(?<oct3>.*),(?<oct4>.*),(?<highport>.*),(?<lowport>.*)>").Match(message);
|
||||
|
||||
// Reconstruct the IP address the server wants
|
||||
string address = match.Groups["oct1"].Value + "." + match.Groups["oct2"].Value + "." +
|
||||
match.Groups["oct3"].Value + "." + match.Groups["oct4"].Value;
|
||||
|
||||
// Reconstruct the port the server wants
|
||||
int port = Convert.ToInt32(match.Groups["highport"].Value) * 256 +
|
||||
Convert.ToInt32(match.Groups["lowport"].Value);
|
||||
|
||||
// Connect the socket to that port
|
||||
_dataSocket = connectSocket(address, port);
|
||||
|
||||
// Send the command requesting to store a file
|
||||
sendSocketMessage(_controlSocket, "STOR " + targetFile);
|
||||
|
||||
// Get the response back
|
||||
receiveSocketMessage(_controlSocket, false);
|
||||
|
||||
// Bring the stream to the beginning if it supports seek
|
||||
if (source.CanSeek) source.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
// Loop until the end of the file
|
||||
while (source.Length != source.Position)
|
||||
{
|
||||
// Initialize the byte array buffer
|
||||
byte[] rawMessage = new byte[DATA_SIZE];
|
||||
|
||||
// Get data from the stream
|
||||
int bytesRead = source.Read(rawMessage, 0, DATA_SIZE);
|
||||
|
||||
// Send the data down the data socket
|
||||
_dataSocket.Send(rawMessage, bytesRead, 0);
|
||||
}
|
||||
|
||||
// Close the data socket
|
||||
disconnectSocket(ref _dataSocket);
|
||||
|
||||
// Get the response back
|
||||
receiveSocketMessage(_controlSocket, false);
|
||||
}
|
||||
|
||||
public void Download(string sourceFile, string targetFile)
|
||||
{
|
||||
}
|
||||
|
||||
public void Logon(string userName, string password)
|
||||
{
|
||||
// Send the command to indicate the user we want
|
||||
sendSocketMessage(_controlSocket, "USER " + userName);
|
||||
|
||||
receiveSocketMessage(_controlSocket, true);
|
||||
|
||||
// Send the command to indicate the password we want
|
||||
sendSocketMessage(_controlSocket, "PASS " + password);
|
||||
|
||||
receiveSocketMessage(_controlSocket, true);
|
||||
}
|
||||
|
||||
public void Logoff()
|
||||
{
|
||||
// Send the comment to close the current session
|
||||
sendSocketMessage(_controlSocket, "QUIT");
|
||||
|
||||
receiveSocketMessage(_controlSocket, true);
|
||||
}
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
// Close and clear the data socket
|
||||
disconnectSocket(ref _dataSocket);
|
||||
|
||||
// Close and clear the control socket
|
||||
disconnectSocket(ref _controlSocket);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
253
Internet/TelnetClient.cs
Normal file
253
Internet/TelnetClient.cs
Normal file
@@ -0,0 +1,253 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Net.Sockets;
|
||||
using Common.Debug;
|
||||
|
||||
namespace Common.Internet
|
||||
{
|
||||
public class TelnetClient
|
||||
{
|
||||
#region Member variables
|
||||
|
||||
private string _deviceLocation = ""; // Name or IP address of the device
|
||||
private int _devicePort = 80; // Port the device is listening on
|
||||
private SocketState _state; // Async state tracking object
|
||||
private Socket _socket; // Socket for communications with the device
|
||||
|
||||
#endregion
|
||||
|
||||
#region Asynchronous socket state
|
||||
|
||||
private class SocketState
|
||||
{
|
||||
private readonly Socket _socket; // Network socket
|
||||
private readonly byte[] _buffer; // Raw data buffer
|
||||
private readonly int _bufferSize = 1024; // Data buffer size
|
||||
private readonly TelnetClient _client; // Owner client
|
||||
private readonly StringBuilder _stringBuffer; // Buffered data
|
||||
private readonly ManualResetEvent _waitEvent; // Used as a signal when waiting for data
|
||||
|
||||
public SocketState(Socket socket, TelnetClient client, int bufferSize)
|
||||
{
|
||||
// Store the socket
|
||||
_socket = socket;
|
||||
|
||||
// Store the client
|
||||
_client = client;
|
||||
|
||||
// Store the buffer size
|
||||
_bufferSize = bufferSize;
|
||||
|
||||
// Initialize the buffer
|
||||
_buffer = new byte[_bufferSize];
|
||||
|
||||
// Initialize the string buffer
|
||||
_stringBuffer = new StringBuilder();
|
||||
|
||||
// Initialize the wait event
|
||||
_waitEvent = new ManualResetEvent(false);
|
||||
}
|
||||
|
||||
public int BufferSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return _bufferSize;
|
||||
}
|
||||
}
|
||||
|
||||
public Socket Socket
|
||||
{
|
||||
get
|
||||
{
|
||||
return _socket;
|
||||
}
|
||||
}
|
||||
|
||||
public TelnetClient Client
|
||||
{
|
||||
get
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] Buffer
|
||||
{
|
||||
get
|
||||
{
|
||||
return _buffer;
|
||||
}
|
||||
}
|
||||
|
||||
public StringBuilder StringBuffer
|
||||
{
|
||||
get
|
||||
{
|
||||
return _stringBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
public ManualResetEvent WaitEvent
|
||||
{
|
||||
get
|
||||
{
|
||||
return _waitEvent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Delegates
|
||||
|
||||
public delegate void DataEventHandler(string data);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
public event DataEventHandler DataReceived;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Connection
|
||||
|
||||
public void Connect(string location, int port)
|
||||
{
|
||||
// Remember the location and port
|
||||
_deviceLocation = location;
|
||||
_devicePort = port;
|
||||
|
||||
// Create the socket
|
||||
_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
|
||||
// Connect the socket
|
||||
_socket.Connect(_deviceLocation, _devicePort);
|
||||
|
||||
// Setup our state object
|
||||
_state = new SocketState(_socket, this, 1024);
|
||||
|
||||
// Start an asynchronous receive
|
||||
_socket.BeginReceive(_state.Buffer, 0, _state.BufferSize, SocketFlags.None, new AsyncCallback(receiveCallback), _state);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Disconnection
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
// If we have a socket...
|
||||
if (null != _socket)
|
||||
{
|
||||
// ...disconnect it
|
||||
_socket.Disconnect(false);
|
||||
_socket = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Asynchronous callback
|
||||
|
||||
private static void receiveCallback(IAsyncResult asyncResult)
|
||||
{
|
||||
// Retrieve the socket state object
|
||||
SocketState socketState = (SocketState) asyncResult.AsyncState;
|
||||
|
||||
// Read data from the socket
|
||||
int bytesRead = socketState.Socket.EndReceive(asyncResult);
|
||||
|
||||
if (bytesRead > 0)
|
||||
{
|
||||
// Decode the data into a string
|
||||
string stringBuffer = Encoding.UTF8.GetString(socketState.Buffer, 0, bytesRead);
|
||||
|
||||
// Add the string to the buffer
|
||||
socketState.StringBuffer.Append(stringBuffer);
|
||||
|
||||
// Raise the DataReceived event with the data
|
||||
if (socketState.Client.DataReceived != null)
|
||||
socketState.Client.DataReceived(stringBuffer);
|
||||
|
||||
Tracer.WriteLine("Data received: {0}", stringBuffer);
|
||||
|
||||
socketState.WaitEvent.Set();
|
||||
|
||||
// Get more data from the socket
|
||||
socketState.Socket.BeginReceive(socketState.Buffer, 0, socketState.BufferSize, 0, new AsyncCallback(receiveCallback), socketState);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Data sending helpers
|
||||
|
||||
public void Send(string text, params object[] arguments)
|
||||
{
|
||||
// Format the text
|
||||
text = string.Format(text, arguments);
|
||||
|
||||
Tracer.WriteLine("Send: {0}", text);
|
||||
|
||||
// Send the text to the socket
|
||||
_socket.Send(Encoding.UTF8.GetBytes(text));
|
||||
}
|
||||
|
||||
public void SendLine(string text, params object[] arguments)
|
||||
{
|
||||
// Send the text with a newline
|
||||
Send(text + "\n", arguments);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Data retrieval helpers
|
||||
|
||||
public string WaitForLine(string text)
|
||||
{
|
||||
// Add a CR/LF to the string and start waiting
|
||||
return WaitForString(text + "\r\n");
|
||||
}
|
||||
|
||||
public string WaitForString(string text)
|
||||
{
|
||||
// Check to see if the current buffer contains the text
|
||||
while (!_state.StringBuffer.ToString().Contains(text))
|
||||
{
|
||||
Tracer.WriteLine("Waiting for: {0}", text);
|
||||
|
||||
// Wait for more data
|
||||
_state.WaitEvent.Reset();
|
||||
_state.WaitEvent.WaitOne(1000, false);
|
||||
}
|
||||
|
||||
Tracer.WriteLine("String found: {0}", text);
|
||||
|
||||
// Get the text in the buffer from the start to after the string we are waiting for
|
||||
string returnString = _state.StringBuffer.ToString().Substring(0, _state.StringBuffer.ToString().IndexOf(text) + text.Length);
|
||||
|
||||
// Strip off everything before what we are waiting for
|
||||
_state.StringBuffer.Remove(0, _state.StringBuffer.ToString().IndexOf(text) + text.Length);
|
||||
|
||||
// Return the string
|
||||
return returnString;
|
||||
}
|
||||
|
||||
public string ReadLine()
|
||||
{
|
||||
// Wait for the first end of line
|
||||
string line = WaitForString("\r\n");
|
||||
|
||||
// Get rid of the trailing CR/LF
|
||||
line = line.Substring(0, line.Length - 2);
|
||||
|
||||
// Return the line
|
||||
return line;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
31
Properties/AssemblyInfo.cs
Normal file
31
Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
#region Using directives
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
#endregion
|
||||
|
||||
// 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("Common")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Chris Kaczor")]
|
||||
[assembly: AssemblyProduct("Common")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2009 Chris Kaczor")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 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 Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.174.0")]
|
||||
[assembly: CLSCompliant(true)]
|
||||
41
Settings/Extensions.cs
Normal file
41
Settings/Extensions.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
|
||||
using Common.Debug;
|
||||
|
||||
namespace Common.Settings
|
||||
{
|
||||
public static class Extensions
|
||||
{
|
||||
public static void DeleteOldConfigurationFiles(this ApplicationSettingsBase dataSet)
|
||||
{
|
||||
// Get information about where the current configuration data is stored
|
||||
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
|
||||
|
||||
// Create a file object for the configuation file
|
||||
FileInfo configFile = new FileInfo(config.FilePath);
|
||||
|
||||
// If we can't get the parent directories then don't bother
|
||||
if (configFile.Directory == null || configFile.Directory.Parent == null)
|
||||
return;
|
||||
|
||||
// Loop over all directories of the configuration file parent directory
|
||||
foreach (DirectoryInfo directory in configFile.Directory.Parent.GetDirectories())
|
||||
{
|
||||
// Delete the directory if it isn't the current config file directory
|
||||
if (directory.FullName != configFile.Directory.FullName)
|
||||
{
|
||||
try
|
||||
{
|
||||
directory.Delete(true);
|
||||
}
|
||||
catch (IOException exception)
|
||||
{
|
||||
// Another instance is probably accessing it - this directory will be deleted later on another run
|
||||
Tracer.WriteException(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
302
Settings/GenericSettingsProvider.cs
Normal file
302
Settings/GenericSettingsProvider.cs
Normal file
@@ -0,0 +1,302 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
|
||||
namespace Common.Settings
|
||||
{
|
||||
public class GenericSettingsProvider : SettingsProvider, IApplicationSettingsProvider
|
||||
{
|
||||
#region Member variables
|
||||
|
||||
private string _applicationName = string.Empty;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Delegates
|
||||
|
||||
public delegate object OpenDataStoreDelegate();
|
||||
public delegate void CloseDataStoreDelegate(object dataStore);
|
||||
public delegate string GetSettingValueDelegate(object dataStore, string name, string version);
|
||||
public delegate void SetSettingValueDelegate(object dataStore, string name, string version, string value);
|
||||
public delegate List<string> GetVersionListDelegate(object dataStore);
|
||||
public delegate void DeleteSettingsForVersionDelegate(object dataStore, string version);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Callbacks
|
||||
|
||||
public OpenDataStoreDelegate OpenDataStore = null;
|
||||
public CloseDataStoreDelegate CloseDataStore = null;
|
||||
public GetSettingValueDelegate GetSettingValue = null;
|
||||
public SetSettingValueDelegate SetSettingValue = null;
|
||||
public GetVersionListDelegate GetVersionList = null;
|
||||
public DeleteSettingsForVersionDelegate DeleteSettingsForVersion = null;
|
||||
|
||||
#endregion
|
||||
|
||||
#region SettingsProvider members
|
||||
|
||||
public override string ApplicationName
|
||||
{
|
||||
get { return _applicationName; }
|
||||
set { _applicationName = value; }
|
||||
}
|
||||
|
||||
public override void Initialize(string name, NameValueCollection config)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name))
|
||||
name = this.GetType().Name;
|
||||
|
||||
base.Initialize(name, config);
|
||||
}
|
||||
|
||||
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
|
||||
{
|
||||
// Create a new collection for the values
|
||||
SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();
|
||||
|
||||
// Get the current version number
|
||||
string version = getCurrentVersionNumber();
|
||||
|
||||
// Open the data store
|
||||
var dataStore = OpenDataStore();
|
||||
|
||||
// Loop over each property
|
||||
foreach (SettingsProperty property in properties)
|
||||
{
|
||||
// Get the setting value for the current version
|
||||
SettingsPropertyValue value = getPropertyValue(dataStore, property, version);
|
||||
|
||||
// Add the value to the collection
|
||||
values.Add(value);
|
||||
}
|
||||
|
||||
// Close the data store
|
||||
CloseDataStore(dataStore);
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection properties)
|
||||
{
|
||||
// Get the current version number
|
||||
string version = getCurrentVersionNumber();
|
||||
|
||||
// Open the data store
|
||||
var dataStore = OpenDataStore();
|
||||
|
||||
// Loop over each property
|
||||
foreach (SettingsPropertyValue propertyValue in properties)
|
||||
{
|
||||
// If the property isn't dirty or it is null then we can skip it
|
||||
if (!propertyValue.IsDirty || (propertyValue.SerializedValue == null)) { continue; }
|
||||
|
||||
// Set the property value
|
||||
setPropertyValue(dataStore, propertyValue, version);
|
||||
}
|
||||
|
||||
// Close the data store
|
||||
CloseDataStore(dataStore);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Version numbers
|
||||
|
||||
private string getCurrentVersionNumber()
|
||||
{
|
||||
return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
}
|
||||
|
||||
private string getPreviousVersionNumber(object dataStore)
|
||||
{
|
||||
// Get the current version number
|
||||
string currentVersion = getCurrentVersionNumber();
|
||||
|
||||
// Initialize the previous version number
|
||||
string previousVersion = null;
|
||||
|
||||
// Get a distinct list of version numbers
|
||||
List<string> versionList = GetVersionList(dataStore);
|
||||
|
||||
// Remove the current version
|
||||
versionList.Remove(currentVersion);
|
||||
|
||||
// Remove the empty version for the database version
|
||||
versionList.Remove(string.Empty);
|
||||
|
||||
// Sort the list using the Version object and get the first value
|
||||
previousVersion = versionList.OrderByDescending(v => new Version(v)).FirstOrDefault();
|
||||
|
||||
return previousVersion;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Value get and set
|
||||
|
||||
private SettingsPropertyValue getPropertyValue(object dataStore, SettingsProperty property, string version)
|
||||
{
|
||||
// Create the value for the property
|
||||
SettingsPropertyValue value = new SettingsPropertyValue(property);
|
||||
|
||||
// Try to get the setting that matches the name and version
|
||||
string setting = GetSettingValue(dataStore, property.Name, version);
|
||||
|
||||
// If the setting was found then set the value, otherwise leave as default
|
||||
value.SerializedValue = setting;
|
||||
|
||||
// Value is not dirty since we just read it
|
||||
value.IsDirty = false;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private void setPropertyValue(object dataStore, SettingsPropertyValue value, string version)
|
||||
{
|
||||
// Set the value for this version
|
||||
SetSettingValue(dataStore, value.Property.Name, version, value.SerializedValue.ToString());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IApplicationSettingsProvider members
|
||||
|
||||
public void Reset(SettingsContext context)
|
||||
{
|
||||
// Get the current version number
|
||||
string version = getCurrentVersionNumber();
|
||||
|
||||
// Open the data store
|
||||
var dataStore = OpenDataStore();
|
||||
|
||||
// Delete all settings for this version
|
||||
DeleteSettingsForVersion(dataStore, version);
|
||||
|
||||
// Close the data store
|
||||
CloseDataStore(dataStore);
|
||||
}
|
||||
|
||||
public SettingsPropertyValue GetPreviousVersion(SettingsContext context, SettingsProperty property)
|
||||
{
|
||||
// Open the data store
|
||||
var dataStore = OpenDataStore();
|
||||
|
||||
// Get the previous version number
|
||||
string previousVersion = getPreviousVersionNumber(dataStore);
|
||||
|
||||
SettingsPropertyValue value;
|
||||
|
||||
// If there is no previous version we have a return a setting with a null value
|
||||
if (string.IsNullOrEmpty(previousVersion))
|
||||
{
|
||||
// Create a new property value
|
||||
value = new SettingsPropertyValue(property);
|
||||
|
||||
// Set the property value to null
|
||||
value.PropertyValue = null;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
// Return the value from the previous version
|
||||
value = getPropertyValue(dataStore, property, previousVersion);
|
||||
|
||||
// Close the data store
|
||||
CloseDataStore(dataStore);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public void Upgrade(SettingsContext context, SettingsPropertyCollection properties)
|
||||
{
|
||||
// Open the data store
|
||||
var dataStore = OpenDataStore();
|
||||
|
||||
if (dataStore == null)
|
||||
return;
|
||||
|
||||
// Get the previous version number
|
||||
string previousVersion = getPreviousVersionNumber(dataStore);
|
||||
|
||||
// If there is no previous version number just do nothing
|
||||
if (string.IsNullOrEmpty(previousVersion))
|
||||
return;
|
||||
|
||||
// Delete everything for the current version
|
||||
Reset(context);
|
||||
|
||||
// Get the current version number
|
||||
string currentVersion = getCurrentVersionNumber();
|
||||
|
||||
// Loop over each property
|
||||
foreach (SettingsProperty property in properties)
|
||||
{
|
||||
// Get the previous value
|
||||
SettingsPropertyValue previousValue = getPropertyValue(dataStore, property, previousVersion);
|
||||
|
||||
// Set the current value if there was a previous value
|
||||
if (previousValue.SerializedValue != null)
|
||||
setPropertyValue(dataStore, previousValue, currentVersion);
|
||||
}
|
||||
|
||||
// Get a distinct list of version numbers
|
||||
List<string> versionList = GetVersionList(dataStore);
|
||||
|
||||
// Remove the current version
|
||||
versionList.Remove(currentVersion);
|
||||
|
||||
// Delete settings for anything left
|
||||
foreach (string version in versionList)
|
||||
DeleteSettingsForVersion(dataStore, version);
|
||||
|
||||
// Close the data store
|
||||
CloseDataStore(dataStore);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Setting scope helpers
|
||||
|
||||
private bool isApplicationScoped(SettingsProperty property)
|
||||
{
|
||||
return hasSettingScope(property, typeof(ApplicationScopedSettingAttribute));
|
||||
}
|
||||
|
||||
private bool isUserScoped(SettingsProperty property)
|
||||
{
|
||||
return hasSettingScope(property, typeof(UserScopedSettingAttribute));
|
||||
}
|
||||
|
||||
private bool hasSettingScope(SettingsProperty property, Type attributeType)
|
||||
{
|
||||
// Check if the setting is application scoped
|
||||
bool isApplicationScoped = property.Attributes[typeof(ApplicationScopedSettingAttribute)] != null;
|
||||
|
||||
// Check if the setting is user scoped
|
||||
bool isUserScoped = property.Attributes[typeof(UserScopedSettingAttribute)] != null;
|
||||
|
||||
// Both user and application is not allowed
|
||||
if (isUserScoped && isApplicationScoped)
|
||||
throw new Exception("Setting cannot be both application and user scoped: " + property.Name);
|
||||
|
||||
// Must be set to either user or application
|
||||
if (!isUserScoped && !isApplicationScoped)
|
||||
throw new Exception("Setting must be either application or user scoped: " + property.Name);
|
||||
|
||||
// If we want to know if it is application scoped return that value
|
||||
if (attributeType == typeof(ApplicationScopedSettingAttribute))
|
||||
return isApplicationScoped;
|
||||
|
||||
// If we want to know if it is user scoped return that value
|
||||
if (attributeType == typeof(UserScopedSettingAttribute))
|
||||
return isUserScoped;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
70
Trace/BeginEndTracer.cs
Normal file
70
Trace/BeginEndTracer.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Common.Debug
|
||||
{
|
||||
public class BeginEndTracer : IDisposable
|
||||
{
|
||||
private string _sourceClass;
|
||||
private string _sourceMethod;
|
||||
|
||||
private object _endParameter;
|
||||
private bool _endParameterSet;
|
||||
|
||||
private const string EnterPattern = "Enter: {0} - {1}";
|
||||
private const string ExitPattern = "Exit: {0} - {1}";
|
||||
|
||||
private const string EnterPatternWithParameter = "Enter: {0} - {1} - {2}";
|
||||
private const string ExitPatternWithParameter = "Exit: {0} - {1} - {2}";
|
||||
|
||||
public BeginEndTracer(string sourceClass, [CallerMemberName] string sourceMethod = null, object beginParameter = null)
|
||||
{
|
||||
_sourceClass = sourceClass;
|
||||
_sourceMethod = sourceMethod;
|
||||
|
||||
if (beginParameter == null)
|
||||
Tracer.WriteLine(string.Format(EnterPattern, _sourceClass, _sourceMethod));
|
||||
else
|
||||
Tracer.WriteLine(string.Format(EnterPatternWithParameter, _sourceClass, _sourceMethod, beginParameter));
|
||||
}
|
||||
|
||||
public BeginEndTracer(string sourceClass, [CallerMemberName] string sourceMethod = null, params object[] beginParameters)
|
||||
{
|
||||
_sourceClass = sourceClass;
|
||||
_sourceMethod = sourceMethod;
|
||||
|
||||
if (beginParameters == null || beginParameters.Length == 0)
|
||||
Tracer.WriteLine(string.Format(EnterPattern, _sourceClass, _sourceMethod));
|
||||
else if (beginParameters.Length == 1)
|
||||
Tracer.WriteLine(string.Format(EnterPatternWithParameter, _sourceClass, _sourceMethod, beginParameters[0]));
|
||||
else
|
||||
{
|
||||
string[] beginStrings = new string[beginParameters.Length];
|
||||
|
||||
for (int i = 0; i < beginParameters.Length; i++)
|
||||
beginStrings[i] = beginParameters[i].ToString();
|
||||
|
||||
Tracer.WriteLine(string.Format(EnterPatternWithParameter, _sourceClass, _sourceMethod, string.Join(", ", beginStrings)));
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_endParameterSet)
|
||||
Tracer.WriteLine(string.Format(ExitPatternWithParameter, _sourceClass, _sourceMethod, _endParameter));
|
||||
else
|
||||
Tracer.WriteLine(string.Format(ExitPattern, _sourceClass, _sourceMethod));
|
||||
}
|
||||
|
||||
public void SetEndParameter(object parameter)
|
||||
{
|
||||
_endParameter = parameter;
|
||||
|
||||
_endParameterSet = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
243
Trace/Tracer.cs
Normal file
243
Trace/Tracer.cs
Normal file
@@ -0,0 +1,243 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Common.Debug
|
||||
{
|
||||
public static class Tracer
|
||||
{
|
||||
#region File creation date comparer
|
||||
|
||||
public class FileCreationTimeComparer : IComparer<string>
|
||||
{
|
||||
#region IComparer<string> Members
|
||||
|
||||
public int Compare(string x, string y)
|
||||
{
|
||||
DateTime createdX = File.GetCreationTime(x);
|
||||
DateTime createdY = File.GetCreationTime(y);
|
||||
|
||||
return createdY.CompareTo(createdX);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Enumerations
|
||||
|
||||
public enum IndentOption
|
||||
{
|
||||
IncrementIndentLevel,
|
||||
DecrementIndentLevel,
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Member variables
|
||||
|
||||
private static string _mainFileName = "Trace.txt";
|
||||
private static int _indentLevel;
|
||||
private static bool _initialized;
|
||||
private static TextWriterTraceListener _traceListener;
|
||||
private static int _keepRevisions = 3;
|
||||
private static string _outputTemplate = "[{0:MM/dd/yyyy HH:mm:ss.fff} - 0x{1:x3}] {2}{3}";
|
||||
private static string _fileNameTemplate = "{0}_{1}.txt";
|
||||
private static bool _echoToConsole;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
[Obsolete]
|
||||
public static void Initialize()
|
||||
{
|
||||
// Initialize using some generic defaults
|
||||
Initialize(Path.GetDirectoryName(Application.ExecutablePath), "Trace", Process.GetCurrentProcess().Id.ToString(), false);
|
||||
}
|
||||
|
||||
public static void Initialize(string logPath, string rootName, string uniqueId, bool echoToConsole)
|
||||
{
|
||||
_echoToConsole = echoToConsole;
|
||||
|
||||
// Use the file name template build the base file name
|
||||
_mainFileName = string.Format(_fileNameTemplate, rootName, uniqueId);
|
||||
|
||||
// Get the list of old log files
|
||||
string[] oldLogFiles = Directory.GetFiles(logPath, string.Format(_fileNameTemplate, rootName, "*"), SearchOption.TopDirectoryOnly);
|
||||
|
||||
// Sort the list by creation date
|
||||
Array.Sort(oldLogFiles, new FileCreationTimeComparer());
|
||||
|
||||
// Keep only the last X revisions
|
||||
for (int i = _keepRevisions; i < oldLogFiles.Length; i++)
|
||||
{
|
||||
// Delete the file
|
||||
File.Delete(oldLogFiles[i]);
|
||||
}
|
||||
|
||||
// Add the log path
|
||||
_mainFileName = Path.Combine(logPath, _mainFileName);
|
||||
|
||||
// Create the listener
|
||||
_traceListener = new TextWriterTraceListener(_mainFileName);
|
||||
|
||||
// Setup the debug listener
|
||||
Trace.Listeners.Add(_traceListener);
|
||||
|
||||
_initialized = true;
|
||||
|
||||
WriteLine("Application starting");
|
||||
|
||||
// Log the command line
|
||||
logCommandLine();
|
||||
}
|
||||
|
||||
public static void Dispose()
|
||||
{
|
||||
WriteLine("Application ended");
|
||||
|
||||
// Flush the trace
|
||||
Trace.Flush();
|
||||
|
||||
// Remove the listener
|
||||
Trace.Listeners.Remove(_traceListener);
|
||||
|
||||
// Close the listener
|
||||
_traceListener.Close();
|
||||
_traceListener.Dispose();
|
||||
_traceListener = null;
|
||||
|
||||
// Close the trace
|
||||
Trace.Close();
|
||||
|
||||
_initialized = false;
|
||||
}
|
||||
|
||||
public static void WriteException(string message, Exception exception)
|
||||
{
|
||||
WriteLine(message);
|
||||
WriteLine(exception.ToString());
|
||||
}
|
||||
|
||||
public static void WriteException(Exception exception)
|
||||
{
|
||||
WriteLine(exception.ToString());
|
||||
}
|
||||
|
||||
public static void WriteLine(string message)
|
||||
{
|
||||
if (!_initialized)
|
||||
return;
|
||||
|
||||
string sIndent = new string('\t', _indentLevel);
|
||||
|
||||
string sOutput = string.Format(_outputTemplate, DateTime.Now, System.Threading.Thread.CurrentThread.ManagedThreadId, sIndent, message);
|
||||
|
||||
//sOutput = sOutput.Replace("\n", "\\n");
|
||||
//sOutput = sOutput.Replace("\r", "\\r");
|
||||
|
||||
if (_echoToConsole)
|
||||
Console.WriteLine(sOutput);
|
||||
|
||||
Trace.WriteLine(sOutput);
|
||||
Trace.Flush();
|
||||
}
|
||||
|
||||
public static void WriteLine(string message, params object[] arguments)
|
||||
{
|
||||
if (!_initialized)
|
||||
return;
|
||||
|
||||
string sMessage = string.Format(message, arguments);
|
||||
|
||||
WriteLine(sMessage);
|
||||
}
|
||||
|
||||
public static void WriteLine(string message, IndentOption indentLine)
|
||||
{
|
||||
if (!_initialized)
|
||||
return;
|
||||
|
||||
if (indentLine == IndentOption.DecrementIndentLevel)
|
||||
DecrementIndentLevel();
|
||||
|
||||
WriteLine(message);
|
||||
|
||||
if (indentLine == IndentOption.IncrementIndentLevel)
|
||||
IncrementIndentLevel();
|
||||
}
|
||||
|
||||
public static void IncrementIndentLevel()
|
||||
{
|
||||
if (!_initialized)
|
||||
return;
|
||||
|
||||
_indentLevel++;
|
||||
}
|
||||
|
||||
public static void DecrementIndentLevel()
|
||||
{
|
||||
if (!_initialized)
|
||||
return;
|
||||
|
||||
_indentLevel--;
|
||||
}
|
||||
|
||||
public static void Flush()
|
||||
{
|
||||
if (!_initialized)
|
||||
return;
|
||||
|
||||
Trace.Flush();
|
||||
}
|
||||
|
||||
private static void logCommandLine()
|
||||
{
|
||||
// Log all command line arguments
|
||||
WriteLine("Command line arguments:");
|
||||
int argIndex = 0;
|
||||
foreach (string arg in Environment.GetCommandLineArgs())
|
||||
{
|
||||
WriteLine("\tArg {0}: {1}", argIndex++, arg);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public static bool Initialized
|
||||
{
|
||||
get { return _initialized; }
|
||||
}
|
||||
|
||||
public static int KeepRevisions
|
||||
{
|
||||
get { return _keepRevisions; }
|
||||
set { _keepRevisions = value; }
|
||||
}
|
||||
|
||||
public static string OutputTemplate
|
||||
{
|
||||
get { return _outputTemplate; }
|
||||
set { _outputTemplate = value; }
|
||||
}
|
||||
|
||||
public static string FileNameTemplate
|
||||
{
|
||||
get { return _fileNameTemplate; }
|
||||
set { _fileNameTemplate = value; }
|
||||
}
|
||||
|
||||
public static TextWriter Writer
|
||||
{
|
||||
get { return _traceListener.Writer; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
142
Xml/XmlExtensions.cs
Normal file
142
Xml/XmlExtensions.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.XPath;
|
||||
using System.IO;
|
||||
|
||||
namespace Common.Xml
|
||||
{
|
||||
public static class XmlExtensions
|
||||
{
|
||||
public static void WriteElementValue(this XmlWriter writer, string elementName, TimeSpan value)
|
||||
{
|
||||
writer.WriteStartElement(elementName);
|
||||
writer.WriteValue(value.TotalMilliseconds);
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
|
||||
public static void WriteElementValue(this XmlWriter writer, string elementName, object value)
|
||||
{
|
||||
writer.WriteStartElement(elementName);
|
||||
writer.WriteValue(value);
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
|
||||
public static void ReadElementValue(this XmlReader reader, string elementName, ref string value)
|
||||
{
|
||||
try
|
||||
{
|
||||
reader.ReadStartElement(elementName);
|
||||
value = reader.ReadContentAsString();
|
||||
reader.ReadEndElement();
|
||||
}
|
||||
catch (XmlException)
|
||||
{
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReadElementValue(this XmlReader reader, string elementName, ref int value)
|
||||
{
|
||||
try
|
||||
{
|
||||
reader.ReadStartElement(elementName);
|
||||
value = reader.ReadContentAsInt();
|
||||
reader.ReadEndElement();
|
||||
}
|
||||
catch (XmlException)
|
||||
{
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReadElementValue(this XmlReader reader, string elementName, ref DateTime value)
|
||||
{
|
||||
try
|
||||
{
|
||||
reader.ReadStartElement(elementName);
|
||||
value = reader.ReadContentAsDateTime();
|
||||
reader.ReadEndElement();
|
||||
}
|
||||
catch (XmlException)
|
||||
{
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReadElementValue(this XmlReader reader, string elementName, ref bool value)
|
||||
{
|
||||
try
|
||||
{
|
||||
reader.ReadStartElement(elementName);
|
||||
value = reader.ReadContentAsBoolean();
|
||||
reader.ReadEndElement();
|
||||
}
|
||||
catch (XmlException)
|
||||
{
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReadElementValue(this XmlReader reader, string elementName, ref TimeSpan value)
|
||||
{
|
||||
try
|
||||
{
|
||||
reader.ReadStartElement(elementName);
|
||||
int milliseconds = reader.ReadContentAsInt();
|
||||
value = new TimeSpan(0, 0, 0, 0, milliseconds);
|
||||
reader.ReadEndElement();
|
||||
}
|
||||
catch (XmlException)
|
||||
{
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
public static XmlNamespaceManager GetAllNamespaces(this XmlDocument document)
|
||||
{
|
||||
// Create the namespace manager from the name table
|
||||
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(document.NameTable);
|
||||
|
||||
// Create a dictionary of all namespaces
|
||||
Dictionary<string, string> allNamespaces = new Dictionary<string, string>();
|
||||
|
||||
// Create an XPathDocument from the XML of the XmlDocument
|
||||
XPathDocument xPathDocument = new XPathDocument(new StringReader(document.InnerXml));
|
||||
|
||||
// Create an XPathNavigator for the document
|
||||
XPathNavigator xPathNavigator = xPathDocument.CreateNavigator();
|
||||
|
||||
// Loop over all elements
|
||||
while (xPathNavigator.MoveToFollowing(XPathNodeType.Element))
|
||||
{
|
||||
// Get the list of local namespaces
|
||||
var localNamespaces = xPathNavigator.GetNamespacesInScope(XmlNamespaceScope.Local);
|
||||
|
||||
// Add all local namespaces to the master list
|
||||
foreach (var ns in localNamespaces)
|
||||
allNamespaces[ns.Key] = ns.Value;
|
||||
}
|
||||
|
||||
// Loop over all namespaces
|
||||
foreach (var ns in allNamespaces)
|
||||
{
|
||||
// Use the key as the name
|
||||
string namespaceName = ns.Key;
|
||||
|
||||
// If the name is blank then use "default" instead
|
||||
if (string.IsNullOrEmpty(namespaceName))
|
||||
namespaceName = "default";
|
||||
|
||||
// Add the namespace to the manager
|
||||
namespaceManager.AddNamespace(namespaceName, ns.Value);
|
||||
}
|
||||
|
||||
// Add the default namespace if missing
|
||||
if (!namespaceManager.HasNamespace("default"))
|
||||
namespaceManager.AddNamespace("default", "");
|
||||
|
||||
return namespaceManager;
|
||||
}
|
||||
}
|
||||
}
|
||||
225
Xml/XmlSanitizingStream.cs
Normal file
225
Xml/XmlSanitizingStream.cs
Normal file
@@ -0,0 +1,225 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Common.Xml
|
||||
{
|
||||
/// <summary>
|
||||
/// A StreamReader that excludes XML-illegal characters while reading.
|
||||
/// </summary>
|
||||
public class XmlSanitizingStream : StreamReader
|
||||
{
|
||||
/// <summary>
|
||||
/// The charactet that denotes the end of a file has been reached.
|
||||
/// </summary>
|
||||
private const int Eof = -1;
|
||||
|
||||
/// <summary>Create an instance of XmlSanitizingStream.</summary>
|
||||
/// <param name="streamToSanitize">
|
||||
/// The stream to sanitize of illegal XML characters.
|
||||
/// </param>
|
||||
public XmlSanitizingStream(Stream streamToSanitize)
|
||||
: base(streamToSanitize, true)
|
||||
{ }
|
||||
|
||||
public XmlSanitizingStream(Stream streamToSanitize, Encoding encoding)
|
||||
: base(streamToSanitize, encoding)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Get whether an integer represents a legal XML 1.0 or 1.1 character. See
|
||||
/// the specification at w3.org for these characters.
|
||||
/// </summary>
|
||||
/// <param name="xmlVersion">
|
||||
/// The version number as a string. Use "1.0" for XML 1.0 character
|
||||
/// validation, and use "1.1" for XML 1.1 character validation.
|
||||
/// </param>
|
||||
/// <param name="character"> </param>
|
||||
public static bool IsLegalXmlChar(string xmlVersion, int character)
|
||||
{
|
||||
switch (xmlVersion)
|
||||
{
|
||||
case "1.1": // http://www.w3.org/TR/xml11/#charsets
|
||||
{
|
||||
return
|
||||
!(
|
||||
character <= 0x8 ||
|
||||
character == 0xB ||
|
||||
character == 0xC ||
|
||||
(character >= 0xE && character <= 0x1F) ||
|
||||
(character >= 0x7F && character <= 0x84) ||
|
||||
(character >= 0x86 && character <= 0x9F) ||
|
||||
character > 0x10FFFF
|
||||
);
|
||||
}
|
||||
case "1.0": // http://www.w3.org/TR/REC-xml/#charsets
|
||||
{
|
||||
return
|
||||
(
|
||||
character == 0x9 /* == '\t' == 9 */ ||
|
||||
character == 0xA /* == '\n' == 10 */ ||
|
||||
character == 0xD /* == '\r' == 13 */ ||
|
||||
(character >= 0x20 && character <= 0xD7FF) ||
|
||||
(character >= 0xE000 && character <= 0xFFFD) ||
|
||||
(character >= 0x10000 && character <= 0x10FFFF)
|
||||
);
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw new ArgumentOutOfRangeException
|
||||
("xmlVersion", string.Format("'{0}' is not a valid XML version.", xmlVersion));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get whether an integer represents a legal XML 1.0 character. See the
|
||||
/// specification at w3.org for these characters.
|
||||
/// </summary>
|
||||
public static bool IsLegalXmlChar(int character)
|
||||
{
|
||||
return IsLegalXmlChar("1.0", character);
|
||||
}
|
||||
|
||||
public override int Read()
|
||||
{
|
||||
// Read each character, skipping over characters that XML has prohibited
|
||||
|
||||
int nextCharacter;
|
||||
|
||||
do
|
||||
{
|
||||
// Read a character
|
||||
|
||||
if ((nextCharacter = base.Read()) == Eof)
|
||||
{
|
||||
// If the character denotes the end of the file, stop reading
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Skip the character if it's prohibited, and try the next
|
||||
|
||||
while (!IsLegalXmlChar(nextCharacter));
|
||||
|
||||
return nextCharacter;
|
||||
}
|
||||
|
||||
public override int Peek()
|
||||
{
|
||||
// Return the next legl XML character without reading it
|
||||
|
||||
int nextCharacter;
|
||||
|
||||
do
|
||||
{
|
||||
// See what the next character is
|
||||
|
||||
nextCharacter = base.Peek();
|
||||
}
|
||||
while
|
||||
(
|
||||
// If it's prohibited XML, skip over the character in the stream
|
||||
// and try the next.
|
||||
|
||||
!IsLegalXmlChar(nextCharacter) &&
|
||||
(nextCharacter = base.Read()) != Eof
|
||||
);
|
||||
|
||||
return nextCharacter;
|
||||
|
||||
} // method
|
||||
|
||||
#region Read*() method overrides
|
||||
|
||||
// The following methods are exact copies of the methods in TextReader,
|
||||
// extracting by disassembling it in Refelctor
|
||||
|
||||
public override int Read(char[] buffer, int index, int count)
|
||||
{
|
||||
if (buffer == null)
|
||||
{
|
||||
throw new ArgumentNullException("buffer");
|
||||
}
|
||||
if (index < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("index");
|
||||
}
|
||||
if (count < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("count");
|
||||
}
|
||||
if ((buffer.Length - index) < count)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
int num = 0;
|
||||
do
|
||||
{
|
||||
int num2 = Read();
|
||||
if (num2 == -1)
|
||||
{
|
||||
return num;
|
||||
}
|
||||
buffer[index + num++] = (char) num2;
|
||||
}
|
||||
while (num < count);
|
||||
return num;
|
||||
}
|
||||
|
||||
public override int ReadBlock(char[] buffer, int index, int count)
|
||||
{
|
||||
int num;
|
||||
int num2 = 0;
|
||||
do
|
||||
{
|
||||
num2 += num = Read(buffer, index + num2, count - num2);
|
||||
}
|
||||
while ((num > 0) && (num2 < count));
|
||||
return num2;
|
||||
}
|
||||
|
||||
public override string ReadLine()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
while (true)
|
||||
{
|
||||
int num = Read();
|
||||
switch (num)
|
||||
{
|
||||
case -1:
|
||||
if (builder.Length > 0)
|
||||
{
|
||||
return builder.ToString();
|
||||
}
|
||||
return null;
|
||||
|
||||
case 13:
|
||||
case 10:
|
||||
if ((num == 13) && (Peek() == 10))
|
||||
{
|
||||
Read();
|
||||
}
|
||||
return builder.ToString();
|
||||
}
|
||||
builder.Append((char) num);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ReadToEnd()
|
||||
{
|
||||
int num;
|
||||
char[] buffer = new char[0x1000];
|
||||
StringBuilder builder = new StringBuilder(0x1000);
|
||||
while ((num = Read(buffer, 0, buffer.Length)) != 0)
|
||||
{
|
||||
builder.Append(buffer, 0, num);
|
||||
}
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
} // class
|
||||
}
|
||||
5
packages.config
Normal file
5
packages.config
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.Bcl" version="1.1.8" targetFramework="net40" />
|
||||
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net40" />
|
||||
</packages>
|
||||
118
packages/Microsoft.Bcl.1.1.8/License-Stable.rtf
vendored
Normal file
118
packages/Microsoft.Bcl.1.1.8/License-Stable.rtf
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fswiss\fprq2\fcharset0 Tahoma;}{\f1\froman\fprq2\fcharset0 Times New Roman;}{\f2\fswiss\fprq2\fcharset0 Calibri;}{\f3\fnil\fcharset0 Calibri;}{\f4\fnil\fcharset2 Symbol;}}
|
||||
{\colortbl ;\red31\green73\blue125;\red0\green0\blue255;}
|
||||
{\*\listtable
|
||||
{\list\listhybrid
|
||||
{\listlevel\levelnfc0\leveljc0\levelstartat1{\leveltext\'02\'00.;}{\levelnumbers\'01;}\jclisttab\tx360}
|
||||
{\listlevel\levelnfc4\leveljc0\levelstartat1{\leveltext\'02\'01.;}{\levelnumbers\'01;}\jclisttab\tx363}
|
||||
{\listlevel\levelnfc2\leveljc0\levelstartat1{\leveltext\'02\'02.;}{\levelnumbers\'01;}\jclisttab\tx720}\listid1 }
|
||||
{\list\listhybrid
|
||||
{\listlevel\levelnfc0\leveljc0\levelstartat1{\leveltext\'02\'00.;}{\levelnumbers\'01;}\jclisttab\tx363}
|
||||
{\listlevel\levelnfc4\leveljc0\levelstartat1{\leveltext\'02\'01.;}{\levelnumbers\'01;}\jclisttab\tx363}\listid2 }}
|
||||
{\*\listoverridetable{\listoverride\listid1\listoverridecount0\ls1}{\listoverride\listid2\listoverridecount0\ls2}}
|
||||
{\stylesheet{ Normal;}{\s1 heading 1;}{\s2 heading 2;}{\s3 heading 3;}}
|
||||
{\*\generator Riched20 6.2.9200}\viewkind4\uc1
|
||||
\pard\nowidctlpar\sb120\sa120\b\f0\fs24 MICROSOFT SOFTWARE LICENSE TERMS\par
|
||||
|
||||
\pard\brdrb\brdrs\brdrw10\brsp20 \nowidctlpar\sb120\sa120 MICROSOFT .NET LIBRARY \par
|
||||
|
||||
\pard\nowidctlpar\sb120\sa120\fs19 These license terms are an agreement between Microsoft Corporation (or based on where you live, one of its affiliates) and you. Please read them. They apply to the software named above, which includes the media on which you received it, if any. The terms also apply to any Microsoft\par
|
||||
|
||||
\pard{\pntext\f4\'B7\tab}{\*\pn\pnlvlblt\pnf4\pnindent363{\pntxtb\'B7}}\nowidctlpar\fi-363\li720\sb120\sa120\b0 updates,\par
|
||||
{\pntext\f4\'B7\tab}supplements,\par
|
||||
{\pntext\f4\'B7\tab}Internet-based services, and\par
|
||||
{\pntext\f4\'B7\tab}support services\par
|
||||
|
||||
\pard\nowidctlpar\sb120\sa120\b for this software, unless other terms accompany those items. If so, those terms apply.\par
|
||||
BY USING THE SOFTWARE, YOU ACCEPT THESE TERMS. IF YOU DO NOT ACCEPT THEM, DO NOT USE THE SOFTWARE.\par
|
||||
|
||||
\pard\brdrt\brdrs\brdrw10\brsp20 \nowidctlpar\sb120\sa120 IF YOU COMPLY WITH THESE LICENSE TERMS, YOU HAVE THE PERPETUAL RIGHTS BELOW.\par
|
||||
|
||||
\pard
|
||||
{\listtext\f0 1.\tab}\jclisttab\tx360\ls1\nowidctlpar\s1\fi-357\li357\sb120\sa120 INSTALLATION AND USE RIGHTS. \par
|
||||
|
||||
\pard
|
||||
{\listtext\f0 a.\tab}\jclisttab\tx363\ls1\ilvl1\nowidctlpar\s2\fi-363\li720\sb120\sa120 Installation and Use.\b0\fs20 You may install and use any number of copies of the software to design, develop and test your programs.\par
|
||||
{\listtext\f0 b.\tab}\b\fs19 Third Party Programs.\b0\fs20 The software may include third party programs that Microsoft, not the third party, licenses to you under this agreement. Notices, if any, for the third party program are included for your information only.\b\fs19\par
|
||||
|
||||
\pard
|
||||
{\listtext\f0 2.\tab}\jclisttab\tx360\ls1\nowidctlpar\s1\fi-357\li357\sb120\sa120\fs20 ADDITIONAL LICENSING REQUIREMENTS AND/OR USE RIGHTS.\par
|
||||
|
||||
\pard
|
||||
{\listtext\f0 a.\tab}\jclisttab\tx363\ls1\ilvl1\nowidctlpar\s2\fi-363\li720\sb120\sa120 DISTRIBUTABLE CODE.\~ \b0 The software is comprised of Distributable Code. \f1\ldblquote\f0 Distributable Code\f1\rdblquote\f0 is code that you are permitted to distribute in programs you develop if you comply with the terms below.\b\par
|
||||
|
||||
\pard
|
||||
{\listtext\f0 i.\tab}\jclisttab\tx720\ls1\ilvl2\nowidctlpar\s3\fi-357\li1077\sb120\sa120\tx1077 Right to Use and Distribute. \par
|
||||
|
||||
\pard{\pntext\f4\'B7\tab}{\*\pn\pnlvlblt\pnf4\pnindent360{\pntxtb\'B7}}\nowidctlpar\fi-357\li1434\sb120\sa120\b0 You may copy and distribute the object code form of the software.\par
|
||||
{\pntext\f4\'B7\tab}Third Party Distribution. You may permit distributors of your programs to copy and distribute the Distributable Code as part of those programs.\par
|
||||
|
||||
\pard\nowidctlpar\s3\fi-357\li1077\sb120\sa120\tx1077\b ii.\tab Distribution Requirements.\b0 \b For any Distributable Code you distribute, you must\par
|
||||
|
||||
\pard{\pntext\f4\'B7\tab}{\*\pn\pnlvlblt\pnf4\pnindent360{\pntxtb\'B7}}\nowidctlpar\fi-357\li1434\sb120\sa120\b0 add significant primary functionality to it in your programs;\par
|
||||
{\pntext\f4\'B7\tab}require distributors and external end users to agree to terms that protect it at least as much as this agreement;\par
|
||||
{\pntext\f4\'B7\tab}display your valid copyright notice on your programs; and\par
|
||||
{\pntext\f4\'B7\tab}indemnify, defend, and hold harmless Microsoft from any claims, including attorneys\rquote fees, related to the distribution or use of your programs.\par
|
||||
|
||||
\pard\nowidctlpar\s3\fi-357\li1077\sb120\sa120\tx1077\b iii.\tab Distribution Restrictions.\b0 \b You may not\par
|
||||
|
||||
\pard{\pntext\f4\'B7\tab}{\*\pn\pnlvlblt\pnf4\pnindent360{\pntxtb\'B7}}\nowidctlpar\fi-357\li1434\sb120\sa120\b0 alter any copyright, trademark or patent notice in the Distributable Code;\par
|
||||
{\pntext\f4\'B7\tab}use Microsoft\rquote s trademarks in your programs\rquote names or in a way that suggests your programs come from or are endorsed by Microsoft;\par
|
||||
{\pntext\f4\'B7\tab}include Distributable Code in malicious, deceptive or unlawful programs; or\par
|
||||
{\pntext\f4\'B7\tab}modify or distribute the source code of any Distributable Code so that any part of it becomes subject to an Excluded License. An Excluded License is one that requires, as a condition of use, modification or distribution, that\par
|
||||
|
||||
\pard{\pntext\f4\'B7\tab}{\*\pn\pnlvlblt\pnf4\pnindent360{\pntxtb\'B7}}\nowidctlpar\fi-358\li1792\sb120\sa120 the code be disclosed or distributed in source code form; or\cf1\f2\par
|
||||
{\pntext\f4\'B7\tab}\cf0\f0 others have the right to modify it.\cf1\f2\par
|
||||
|
||||
\pard\nowidctlpar\s1\fi-357\li357\sb120\sa120\cf0\b\f0 3.\tab\fs19 SCOPE OF LICENSE. \b0 The software is licensed, not sold. This agreement only gives you some rights to use the software. Microsoft reserves all other rights. Unless applicable law gives you more rights despite this limitation, you may use the software only as expressly permitted in this agreement. In doing so, you must comply with any technical limitations in the software that only allow you to use it in certain ways. You may not\par
|
||||
|
||||
\pard{\pntext\f4\'B7\tab}{\*\pn\pnlvlblt\pnf4\pnindent363{\pntxtb\'B7}}\nowidctlpar\fi-363\li720\sb120\sa120 work around any technical limitations in the software;\par
|
||||
{\pntext\f4\'B7\tab}reverse engineer, decompile or disassemble the software, except and only to the extent that applicable law expressly permits, despite this limitation;\par
|
||||
{\pntext\f4\'B7\tab}publish the software for others to copy;\par
|
||||
{\pntext\f4\'B7\tab}rent, lease or lend the software;\par
|
||||
{\pntext\f4\'B7\tab}transfer the software or this agreement to any third party; or\par
|
||||
{\pntext\f4\'B7\tab}use the software for commercial software hosting services.\par
|
||||
|
||||
\pard\nowidctlpar\s1\fi-357\li357\sb120\sa120\b\fs20 4.\tab\fs19 BACKUP COPY. \b0 You may make one backup copy of the software. You may use it only to reinstall the software.\par
|
||||
\b\fs20 5.\tab\fs19 DOCUMENTATION. \b0 Any person that has valid access to your computer or internal network may copy and use the documentation for your internal, reference purposes.\par
|
||||
\b\fs20 6.\tab\fs19 EXPORT RESTRICTIONS. \b0 The software is subject to United States export laws and regulations. You must comply with all domestic and international export laws and regulations that apply to the software. These laws include restrictions on destinations, end users and end use. For additional information, see {\cf2\ul\fs20{\field{\*\fldinst{HYPERLINK www.microsoft.com/exporting }}{\fldrslt{www.microsoft.com/exporting}}}}\f0\fs19 .\cf2\ul\fs20\par
|
||||
\cf0\ulnone\b 7.\tab\fs19 SUPPORT SERVICES. \b0 Because this software is \ldblquote as is,\rdblquote we may not provide support services for it.\par
|
||||
\b\fs20 8.\tab\fs19 ENTIRE AGREEMENT. \b0 This agreement, and the terms for supplements, updates, Internet-based services and support services that you use, are the entire agreement for the software and support services.\par
|
||||
\b\fs20 9.\tab\fs19 APPLICABLE LAW.\par
|
||||
|
||||
\pard
|
||||
{\listtext\f0 a.\tab}\jclisttab\tx363\ls2\ilvl1\nowidctlpar\s2\fi-363\li720\sb120\sa120 United States. \b0 If you acquired the software in the United States, Washington state law governs the interpretation of this agreement and applies to claims for breach of it, regardless of conflict of laws principles. The laws of the state where you live govern all other claims, including claims under state consumer protection laws, unfair competition laws, and in tort.\par
|
||||
{\listtext\f0 b.\tab}\b Outside the United States. If you acquired the software in any other country, the laws of that country apply.\par
|
||||
|
||||
\pard\nowidctlpar\s1\fi-357\li357\sb120\sa120\fs20 10.\tab\fs19 LEGAL EFFECT. \b0 This agreement describes certain legal rights. You may have other rights under the laws of your country. You may also have rights with respect to the party from whom you acquired the software. This agreement does not change your rights under the laws of your country if the laws of your country do not permit it to do so.\par
|
||||
\b\fs20 11.\tab\fs19 DISCLAIMER OF WARRANTY. THE SOFTWARE IS LICENSED \ldblquote AS-IS.\rdblquote YOU BEAR THE RISK OF USING IT. MICROSOFT GIVES NO EXPRESS WARRANTIES, GUARANTEES OR CONDITIONS. YOU MAY HAVE ADDITIONAL CONSUMER RIGHTS OR STATUTORY GUARANTEES UNDER YOUR LOCAL LAWS WHICH THIS AGREEMENT CANNOT CHANGE. TO THE EXTENT PERMITTED UNDER YOUR LOCAL LAWS, MICROSOFT EXCLUDES THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.\par
|
||||
|
||||
\pard\nowidctlpar\li357\sb120\sa120 FOR AUSTRALIA \endash YOU HAVE STATUTORY GUARANTEES UNDER THE AUSTRALIAN CONSUMER LAW AND NOTHING IN THESE TERMS IS INTENDED TO AFFECT THOSE RIGHTS.\par
|
||||
|
||||
\pard\nowidctlpar\s1\fi-357\li357\sb120\sa120\fs20 12.\tab\fs19 LIMITATION ON AND EXCLUSION OF REMEDIES AND DAMAGES. YOU CAN RECOVER FROM MICROSOFT AND ITS SUPPLIERS ONLY DIRECT DAMAGES UP TO U.S. $5.00. YOU CANNOT RECOVER ANY OTHER DAMAGES, INCLUDING CONSEQUENTIAL, LOST PROFITS, SPECIAL, INDIRECT OR INCIDENTAL DAMAGES.\par
|
||||
|
||||
\pard\nowidctlpar\li357\sb120\sa120\b0 This limitation applies to\par
|
||||
|
||||
\pard{\pntext\f4\'B7\tab}{\*\pn\pnlvlblt\pnf4\pnindent363{\pntxtb\'B7}}\nowidctlpar\fi-363\li720\sb120\sa120 anything related to the software, services, content (including code) on third party Internet sites, or third party programs; and\par
|
||||
{\pntext\f4\'B7\tab}claims for breach of contract, breach of warranty, guarantee or condition, strict liability, negligence, or other tort to the extent permitted by applicable law.\par
|
||||
|
||||
\pard\nowidctlpar\sb120\sa120 It also applies even if Microsoft knew or should have known about the possibility of the damages. The above limitation or exclusion may not apply to you because your country may not allow the exclusion or limitation of incidental, consequential or other damages.\par
|
||||
\lang9 Please note: As this software is distributed in Quebec, Canada, some of the clauses in this agreement are provided below in French.\par
|
||||
Remarque : Ce logiciel \'e9tant distribu\'e9 au Qu\'e9bec, Canada, certaines des clauses dans ce contrat sont fournies ci-dessous en fran\'e7ais.\par
|
||||
|
||||
\pard\nowidctlpar\s1\sb120\sa120\b\lang1033 EXON\'c9RATION DE GARANTIE. \b0 Le logiciel vis\'e9 par une licence est offert \'ab tel quel \'bb. Toute utilisation de ce logiciel est \'e0 votre seule risque et p\'e9ril. Microsoft n\rquote accorde aucune autre garantie expresse. Vous pouvez b\'e9n\'e9ficier de droits additionnels en vertu du droit local sur la protection des consommateurs, que ce contrat ne peut modifier. La ou elles sont permises par le droit locale, les garanties implicites de qualit\'e9 marchande, d\rquote ad\'e9quation \'e0 un usage particulier et d\rquote absence de contrefa\'e7on sont exclues.\par
|
||||
\b LIMITATION DES DOMMAGES-INT\'c9R\'caTS ET EXCLUSION DE RESPONSABILIT\'c9 POUR LES DOMMAGES. \b0 Vous pouvez obtenir de Microsoft et de ses fournisseurs une indemnisation en cas de dommages directs uniquement \'e0 hauteur de 5,00 $ US. Vous ne pouvez pr\'e9tendre \'e0 aucune indemnisation pour les autres dommages, y compris les dommages sp\'e9ciaux, indirects ou accessoires et pertes de b\'e9n\'e9fices.\par
|
||||
|
||||
\pard\nowidctlpar\sb120\sa120\lang9 Cette limitation concerne :\par
|
||||
|
||||
\pard{\pntext\f4\'B7\tab}{\*\pn\pnlvlblt\pnf4\pnindent360{\pntxtb\'B7}}\nowidctlpar\li720\sb120\sa120 tout ce qui est reli\'e9 au logiciel, aux services ou au contenu (y compris le code) figurant sur des sites Internet tiers ou dans des programmes tiers ; et\par
|
||||
{\pntext\f4\'B7\tab}les r\'e9clamations au titre de violation de contrat ou de garantie, ou au titre de responsabilit\'e9 stricte, de n\'e9gligence ou d\rquote une autre faute dans la limite autoris\'e9e par la loi en vigueur.\par
|
||||
|
||||
\pard\nowidctlpar\sb120\sa120 Elle s\rquote applique \'e9galement, m\'eame si Microsoft connaissait ou devrait conna\'eetre l\rquote\'e9ventualit\'e9 d\rquote un tel dommage. Si votre pays n\rquote autorise pas l\rquote exclusion ou la limitation de responsabilit\'e9 pour les dommages indirects, accessoires ou de quelque nature que ce soit, il se peut que la limitation ou l\rquote exclusion ci-dessus ne s\rquote appliquera pas \'e0 votre \'e9gard.\par
|
||||
|
||||
\pard\nowidctlpar\s1\sb120\sa120\b\lang1033 EFFET JURIDIQUE. \b0 Le pr\'e9sent contrat d\'e9crit certains droits juridiques. Vous pourriez avoir d\rquote autres droits pr\'e9vus par les lois de votre pays. Le pr\'e9sent contrat ne modifie pas les droits que vous conf\'e8rent les lois de votre pays si celles-ci ne le permettent pas.\par
|
||||
|
||||
\pard\nowidctlpar\sb120\sa120\b\fs20\lang1036\par
|
||||
|
||||
\pard\sa200\sl276\slmult1\b0\f3\fs22\lang9\par
|
||||
}
|
||||
| ||||