aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2023-02-13 07:20:18 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2023-02-13 07:20:18 +0300
commit6484cac4f025bd84f7ffa2b2030d729dafe09d3d (patch)
tree9c6ff3a127362a05f1d7eccb8f00b4a692479e57
parent6fe49f6ad196b7ca8d83939d11209a1f3edbd80e (diff)
Move Sku class to nuget package
-rw-r--r--src/Models/Sku.cs116
-rw-r--r--src/RhSolutions-AddIn.dna4
-rw-r--r--src/RhSolutions.csproj1
3 files changed, 4 insertions, 117 deletions
diff --git a/src/Models/Sku.cs b/src/Models/Sku.cs
deleted file mode 100644
index 99fcce6..0000000
--- a/src/Models/Sku.cs
+++ /dev/null
@@ -1,116 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-using System;
-using System.Text.RegularExpressions;
-
-namespace RhSolutions.Models
-{
- public class Sku
- {
- private const string matchPattern = @"([1\D]|\b)(?<Article>\d{6})([1\s-]|)(?<Variant>\d{3})\b";
- private string _article;
- private string _variant;
-
- public Sku(string article, string variant)
- {
- Article = article;
- Variant = variant;
- }
-
- public string Id
- {
- get
- {
- return $"1{Article}1{Variant}";
- }
- set
- {
- if (TryParse(value, out IEnumerable<Sku> skus))
- {
- if (skus.Count() > 1)
- {
- throw new ArgumentException($"More than one valid sku detected: {value}");
- }
- else
- {
- this.Article = skus.First().Article;
- this.Variant = skus.First().Variant;
- }
- }
- else
- {
- throw new ArgumentException($"Invalid sku input: {value}");
- }
- }
- }
- public string Article
- {
- get
- {
- return _article;
- }
- set
- {
- if (value == null || value.Length != 6 || value.Where(c => char.IsDigit(c)).Count() != 6)
- {
- throw new ArgumentException($"Wrong Article: {Article}");
- }
- else
- {
- _article = value;
- }
- }
- }
- public string Variant
- {
- get
- {
- return _variant;
- }
- set
- {
- if (value == null || value.Length != 3 || value.Where(c => char.IsDigit(c)).Count() != 3)
- {
- throw new ArgumentException($"Wrong Variant: {Variant}");
- }
- else _variant = value;
- }
- }
- public static IEnumerable<Sku> GetValidSkus(string line)
- {
- MatchCollection matches = Regex.Matches(line, matchPattern);
- if (matches.Count == 0)
- {
- yield break;
- }
- else
- {
- foreach (Match m in matches)
- {
- yield return new Sku(m.Groups["Article"].Value, m.Groups["Variant"].Value);
- }
- }
- }
-
- public static bool TryParse(string line, out IEnumerable<Sku> skus)
- {
- MatchCollection matches = Regex.Matches(line, matchPattern);
- if (matches.Count == 0)
- {
- skus = Enumerable.Empty<Sku>();
- return false;
- }
-
- else
- {
- skus = GetValidSkus(line);
- return true;
- }
- }
-
- public override string ToString()
- {
- return $"1{Article}1{Variant}";
- }
- }
-} \ No newline at end of file
diff --git a/src/RhSolutions-AddIn.dna b/src/RhSolutions-AddIn.dna
index a75d6e1..5322868 100644
--- a/src/RhSolutions-AddIn.dna
+++ b/src/RhSolutions-AddIn.dna
@@ -3,8 +3,10 @@
<ExternalLibrary Path="RhSolutions.AddIn.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" IncludePdb="false" />
<Reference Path="ExcelDna.IntelliSense.dll" Pack="true" />
<Reference Path="Newtonsoft.Json.dll" Pack="true" />
+ <Reference Path="RhSolutions.Sku.dll" Pack="true" />
- <!--
+
+ <!--
The RuntimeVersion attribute above allows only the following setting:
* RuntimeVersion="v4.0" - for .NET 4.5 or higher
diff --git a/src/RhSolutions.csproj b/src/RhSolutions.csproj
index 8db6006..60182f6 100644
--- a/src/RhSolutions.csproj
+++ b/src/RhSolutions.csproj
@@ -17,6 +17,7 @@
<PackageReference Include="ExcelDna.Interop" Version="15.0.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
+ <PackageReference Include="RhSolutions.Sku" Version="0.1.1" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>
</Project> \ No newline at end of file