Merge branch 'dev'

This commit is contained in:
Sergey Chebotar 2021-11-11 16:54:02 +03:00
commit 475d981364
12 changed files with 976 additions and 0 deletions

454
.gitignore vendored Normal file
View File

@ -0,0 +1,454 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# Tye
.tye/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# 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
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# 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
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
##
## Visual studio for Mac
##
# globs
Makefile.in
*.userprefs
*.usertasks
config.make
config.status
aclocal.m4
install-sh
autom4te.cache/
*.tar.gz
tarballs/
test-results/
# Mac bundle stuff
*.dmg
*.app
# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
# JetBrains Rider
.idea/
*.sln.iml
##
## Visual Studio Code
##
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

38
CancellationDisposable.cs Normal file
View File

@ -0,0 +1,38 @@
using System;
using System.Threading;
namespace Rehau.Sku.Assist
{
sealed class CancellationDisposable : IDisposable
{
readonly CancellationTokenSource cts;
public CancellationDisposable(CancellationTokenSource cts)
{
if (cts == null)
{
throw new ArgumentNullException("cts");
}
this.cts = cts;
}
public CancellationDisposable()
: this(new CancellationTokenSource())
{
}
public CancellationToken Token
{
get { return cts.Token; }
}
public void Dispose()
{
cts.Cancel();
}
}
}

21
DefaultDisposable.cs Normal file
View File

@ -0,0 +1,21 @@
using System;
namespace Rehau.Sku.Assist
{
sealed class DefaultDisposable : IDisposable
{
public static readonly DefaultDisposable Instance = new DefaultDisposable();
DefaultDisposable()
{
}
public void Dispose()
{
}
}
}

133
ExcelTaskUtil.cs Normal file
View File

@ -0,0 +1,133 @@
using ExcelDna.Integration;
using System.Threading.Tasks;
using System;
using System.Threading;
namespace Rehau.Sku.Assist
{
internal static class ExcelTaskUtil
{
public static object Run<TResult>(string callerFunctionName, object callerParameters, Func<CancellationToken, Task<TResult>> taskSource)
{
return ExcelAsyncUtil.Observe(callerFunctionName, callerParameters, delegate
{
var cts = new CancellationTokenSource();
var task = taskSource(cts.Token);
return new ExcelTaskObservable<TResult>(task, cts);
});
}
public static object Run<TResult>(string callerFunctionName, object callerParameters, Func<Task<TResult>> taskSource)
{
return ExcelAsyncUtil.Observe(callerFunctionName, callerParameters, delegate
{
var task = taskSource();
return new ExcelTaskObservable<TResult>(task);
});
}
class ExcelTaskObservable<TResult> : IExcelObservable
{
readonly Task<TResult> _task;
readonly CancellationTokenSource _cts;
public ExcelTaskObservable(Task<TResult> task)
{
_task = task;
}
public ExcelTaskObservable(Task<TResult> task, CancellationTokenSource cts)
: this(task)
{
_cts = cts;
}
public IDisposable Subscribe(IExcelObserver observer)
{
switch (_task.Status)
{
case TaskStatus.RanToCompletion:
observer.OnNext(_task.Result);
observer.OnCompleted();
break;
case TaskStatus.Faulted:
observer.OnError(_task.Exception.InnerException);
break;
case TaskStatus.Canceled:
observer.OnError(new TaskCanceledException(_task));
break;
default:
_task.ContinueWith(t =>
{
switch (t.Status)
{
case TaskStatus.RanToCompletion:
observer.OnNext(t.Result);
observer.OnCompleted();
break;
case TaskStatus.Faulted:
observer.OnError(t.Exception.InnerException);
break;
case TaskStatus.Canceled:
observer.OnError(new TaskCanceledException(t));
break;
}
});
break;
}
if (_cts != null)
{
return new CancellationDisposable(_cts);
}
return DefaultDisposable.Instance;
}
}
sealed class DefaultDisposable : IDisposable
{
public static readonly DefaultDisposable Instance = new DefaultDisposable();
DefaultDisposable()
{
}
public void Dispose()
{
}
}
sealed class CancellationDisposable : IDisposable
{
readonly CancellationTokenSource cts;
public CancellationDisposable(CancellationTokenSource cts)
{
if (cts == null)
{
throw new ArgumentNullException("cts");
}
this.cts = cts;
}
public CancellationDisposable()
: this(new CancellationTokenSource())
{
}
public CancellationToken Token
{
get { return cts.Token; }
}
public void Dispose()
{
cts.Cancel();
}
}
}
}

24
Functions.cs Normal file
View File

@ -0,0 +1,24 @@
using ExcelDna.Integration;
namespace Rehau.Sku.Assist
{
public class Functions : IExcelAddIn
{
[ExcelFunction(description: "Получение наименования и артикула позиции")]
public static string RAUNAME(string request)
{
SkuAssist.EnsureHttpInitialized();
return SkuAssist.GetSku(request);
}
public void AutoClose()
{
ExcelIntegration.RegisterUnhandledExceptionHandler(
delegate (object ex) { return string.Format("!!!ERROR: {0}", ex.ToString()); });
}
public void AutoOpen()
{
}
}
}

View File

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

View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="ExcelDnaProps">
<!--
If you change properties in this file, they may not come into effect until you:
* Rebuild the solution/project
or
* Close Visual Studio
* Delete .vs folder, if exists
* Delete ProjectName.csproj.user (or equivalent for VB, F#, etc.), if exists
* Delete SolutionName.suo, if exists
* Open your solution/project again in Visual Studio
-->
<!--
Configuration properties for debugging Excel-DNA add-ins
-->
<PropertyGroup>
<!--
Enable/Disable setting the debug options when building the project
-->
<RunExcelDnaSetDebuggerOptions Condition="'$(RunExcelDnaSetDebuggerOptions)' == ''">true</RunExcelDnaSetDebuggerOptions>
<!--
Override the path of EXCEL.EXE used for debugging the project, if you need
By default, it will use the latest version of Excel it can find on the machine
-->
<ExcelDnaExcelExePath Condition="'$(ExcelDnaExcelExePath)' == ''"></ExcelDnaExcelExePath>
<!--
Override the name of the .XLL add-in to use when debugging the project, if you need
By default, it will use the first unpacked .xll add-in that matches the bitness of EXCEL.EXE
-->
<ExcelDnaAddInForDebugging Condition="'$(ExcelDnaAddInForDebugging)' == ''"></ExcelDnaAddInForDebugging>
</PropertyGroup>
<!--
Configuration properties for building .dna files
-->
<PropertyGroup>
<!--
Enable/Disable automatic generation of platform-specific versions of .dna files
-->
<ExcelDnaCreate32BitAddIn Condition="'$(ExcelDnaCreate32BitAddIn)' == ''">true</ExcelDnaCreate32BitAddIn>
<ExcelDnaCreate64BitAddIn Condition="'$(ExcelDnaCreate64BitAddIn)' == ''">true</ExcelDnaCreate64BitAddIn>
<!--
Define the suffix used for each platform-specific file e.g. MyAddIn64.dna
-->
<ExcelDna32BitAddInSuffix Condition="'$(ExcelDna32BitAddInSuffix)' == ''"></ExcelDna32BitAddInSuffix>
<ExcelDna64BitAddInSuffix Condition="'$(ExcelDna64BitAddInSuffix)' == ''">64</ExcelDna64BitAddInSuffix>
</PropertyGroup>
<PropertyGroup>
<!--
Enable/Disable using Excel-DNA with PackageReference projects (not officially supported)
-->
<ExcelDnaAllowPackageReferenceProjectStyle Condition="'$(ExcelDnaAllowPackageReferenceProjectStyle)' == ''">false</ExcelDnaAllowPackageReferenceProjectStyle>
</PropertyGroup>
<!--
Configuration properties for packing .dna files
-->
<PropertyGroup>
<!--
Enable/Disable packing of .dna files
-->
<RunExcelDnaPack Condition="'$(RunExcelDnaPack)' == ''">true</RunExcelDnaPack>
<!--
Suffix used for packed .xll files e.g. MyAddIn-packed.xll
-->
<ExcelDnaPackXllSuffix Condition="'$(ExcelDnaPackXllSuffix)' == ''">-packed</ExcelDnaPackXllSuffix>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<DnaLibrary Name="Rehau.Sku.Assist Add-In" RuntimeVersion="v4.0" xmlns="http://schemas.excel-dna.net/addin/2020/07/dnalibrary">
<ExternalLibrary Path="Rehau.Sku.Assist.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" IncludePdb="false" />
<!--
The RuntimeVersion attribute above allows only the following setting:
* RuntimeVersion="v4.0" - for .NET 4.5 or higher
You can have IntelliSense (autocomplete) and validation for this file.
See https://github.com/Excel-DNA/ExcelDna/tree/master/Distribution/XmlSchemas/
Additional referenced assemblies can be specified by adding 'Reference' tags.
These libraries will not be examined and registered with Excel as add-in libraries,
but will be packed into the -packed.xll file and loaded at runtime as needed.
For example:
<Reference Path="Another.Library.dll" Pack="true" />
Excel-DNA also allows the XML for ribbon UI extensions to be specified in the .dna file.
See the main Excel-DNA site at https://excel-dna.net for downloads of the full distribution.
-->
</DnaLibrary>

81
Rehau.Sku.Assist.csproj Normal file
View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{18A2FF67-0E46-4A86-B872-29F2B3F23ADF}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Rehau.Sku.Assist</RootNamespace>
<AssemblyName>Rehau.Sku.Assist</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="AngleSharp, Version=0.16.1.0, Culture=neutral, PublicKeyToken=e83494dcdc6d31ea, processorArchitecture=MSIL">
<HintPath>packages\AngleSharp.0.16.1\lib\net472\AngleSharp.dll</HintPath>
</Reference>
<Reference Include="ExcelDna.Integration, Version=1.1.0.0, Culture=neutral, PublicKeyToken=f225e9659857edbe, processorArchitecture=MSIL">
<HintPath>packages\ExcelDna.Integration.1.5.0\lib\net452\ExcelDna.Integration.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Core" />
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Text.Encoding.CodePages, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>packages\System.Text.Encoding.CodePages.5.0.0\lib\net461\System.Text.Encoding.CodePages.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CancellationDisposable.cs" />
<Compile Include="DefaultDisposable.cs" />
<Compile Include="ExcelTaskUtil.cs" />
<Compile Include="Functions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SkuAssist.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Rehau.Sku.Assist-AddIn.dna" />
<None Include="packages.config" />
<None Include="Properties\ExcelDna.Build.props" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="packages\ExcelDna.AddIn.1.5.0\build\ExcelDna.AddIn.targets" Condition="Exists('packages\ExcelDna.AddIn.1.5.0\build\ExcelDna.AddIn.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\ExcelDna.AddIn.1.5.0\build\ExcelDna.AddIn.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\ExcelDna.AddIn.1.5.0\build\ExcelDna.AddIn.targets'))" />
</Target>
</Project>

25
Rehau.Sku.Assist.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31829.152
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rehau.Sku.Assist", "Rehau.Sku.Assist.csproj", "{18A2FF67-0E46-4A86-B872-29F2B3F23ADF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{18A2FF67-0E46-4A86-B872-29F2B3F23ADF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{18A2FF67-0E46-4A86-B872-29F2B3F23ADF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{18A2FF67-0E46-4A86-B872-29F2B3F23ADF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{18A2FF67-0E46-4A86-B872-29F2B3F23ADF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3CF61093-14A6-4A2D-AC13-53EBA2253BAA}
EndGlobalSection
EndGlobal

56
SkuAssist.cs Normal file
View File

@ -0,0 +1,56 @@
using System.Net.Http;
using System.Threading.Tasks;
using AngleSharp;
using System.Linq;
using System.Net;
namespace Rehau.Sku.Assist
{
static class SkuAssist
{
static private HttpClient _httpClient;
public static void EnsureHttpInitialized()
{
if (_httpClient == null)
{
_httpClient = new HttpClient();
}
}
public static string GetSku(string request)
{
string url = "https://shop-rehau.ru/catalogsearch/result/?q=" + request;
HttpResponseMessage response = GetResponse(url).Result;
var document = GetDocument(response).Result;
var name = document
.All
.Where(e => e.ClassName == "product-item__desc-top")
.Select(e => new { sku = e.Children[0].TextContent, name = e.Children[1].TextContent.Trim(new[] { '\n', ' ' }) })
.Where(t => !t.sku.Any(c => char.IsLetter(c)))
.FirstOrDefault();
return name == null ? "Не найдено" : $"{name.name} ({name.sku})";
}
private static async Task<HttpResponseMessage> GetResponse(string url)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
HttpResponseMessage response = await _httpClient.GetAsync(url);
response.EnsureSuccessStatusCode();
return response;
}
private static async Task<AngleSharp.Dom.IDocument> GetDocument(HttpResponseMessage response)
{
IConfiguration config = Configuration.Default;
IBrowsingContext context = BrowsingContext.New(config);
string source = await response.Content.ReadAsStringAsync();
return await context.OpenAsync(req => req.Content(source));
}
}
}

9
packages.config Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AngleSharp" version="0.16.1" targetFramework="net48" />
<package id="ExcelDna.AddIn" version="1.5.0" targetFramework="net48" />
<package id="ExcelDna.Integration" version="1.5.0" targetFramework="net48" />
<package id="System.Buffers" version="4.5.1" targetFramework="net48" />
<package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net48" />
<package id="System.Text.Encoding.CodePages" version="5.0.0" targetFramework="net48" />
</packages>