From 3d70d3d50df140c8c9ab1c333758250d81d2c3e3 Mon Sep 17 00:00:00 2001 From: Patrick Gruber Date: Fri, 12 Jun 2020 15:40:06 +0200 Subject: [PATCH 01/10] Added first version of IErpManager --- .../ErpServices/ErpManager/ErpManager.cs | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Files/powerGatePlugin/ErpServices/ErpManager/ErpManager.cs diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/ErpManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/ErpManager.cs new file mode 100644 index 0000000..6bfa3b5 --- /dev/null +++ b/Files/powerGatePlugin/ErpServices/ErpManager/ErpManager.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Net; + +namespace ErpServices.ErpManager +{ + public enum ErpSearchOperator + { + Contains + } + + public enum ErpSearchProperty + { + Number, + Description + } + + public struct ErpMaterialSearchSettings + { + public ErpSearchProperty PropertyName { get; set; } + public ErpSearchOperator Operator { get; set; } + public string SearchValue { get; set; } + } + + public struct ErpLogin + { + public IPEndPoint Server { get; } + public string ConnectionString { get; } + public string Mandant { get; } + public string UserName { get; } + public string Password { get; } + } + + public interface IErpManager : IDisposable + { + ErpLogin Login { get; } + bool IsConnected { get; } + + bool Connect(ErpLogin login); + + // Material functionality + Material GetMaterialyByNumber(string number); + IEnumerable SearchMaterials(IEnumerable query); + Material CreateMaterial(Material material); + Material UpdateMaterial(Material material); + + + // Documents functionality + Document CreateDocumentMetadata(Document documentMetadata); + Document UploadDocumentWithMetadata(MemoryStream fileStream, Document documentMetadata); + Document UpdateDocumentMetadata(Document documentMetadata); + Document UpdateDocumentWithMetadata(MemoryStream fileStream, Document documentMetadata); + + // BOM functionality + BomHeader GetBomByNumber(string number); + BomRow GetBomRowByNumber(string parentNumber, string childNumber); + BomHeader CreateBomWithChildren(BomHeader bom); + BomRow CreateBomRow(BomRow bomRow); + BomHeader UpdateBomHeader(BomHeader bom); + BomRow UpdateBomRow(BomRow bomRow); + BomRow DeleteBomRow(BomRow bomRow); + + } + + public partial class ErpManager : IErpManager + { + } +} \ No newline at end of file From 71c8c3711aa8f5f76bb490f6ebfac4cef3d79279 Mon Sep 17 00:00:00 2001 From: Patrick Gruber Date: Fri, 12 Jun 2020 15:41:51 +0200 Subject: [PATCH 02/10] added csproj change #128 --- Files/powerGatePlugin/ErpServices/ErpServices.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/Files/powerGatePlugin/ErpServices/ErpServices.csproj b/Files/powerGatePlugin/ErpServices/ErpServices.csproj index 4d694d3..c7dc8fb 100644 --- a/Files/powerGatePlugin/ErpServices/ErpServices.csproj +++ b/Files/powerGatePlugin/ErpServices/ErpServices.csproj @@ -59,6 +59,7 @@ + From 62f192bb8179e7b115490f8d12b5589d390df861 Mon Sep 17 00:00:00 2001 From: Patrick Gruber Date: Fri, 19 Jun 2020 09:51:21 +0200 Subject: [PATCH 03/10] Created empty implementations of new Interface --- .../Implementation/ErpBomManager.cs | 43 +++++++++++++++++++ .../Implementation/ErpDocumentManager.cs | 29 +++++++++++++ .../Implementation/ErpItemManager.cs | 29 +++++++++++++ .../ErpManager/Implementation/ErpManager.cs | 22 ++++++++++ .../ErpManager/Interfaces/ErpLogin.cs | 13 ++++++ .../Interfaces/ErpMaterialSearchSettings.cs | 20 +++++++++ .../IErpManager.cs} | 34 +-------------- .../ErpServices/ErpServices.csproj | 8 +++- .../dataStandard.UI/NumSchm.cs | 31 +++++++------ 9 files changed, 181 insertions(+), 48 deletions(-) create mode 100644 Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpBomManager.cs create mode 100644 Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpDocumentManager.cs create mode 100644 Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpItemManager.cs create mode 100644 Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpManager.cs create mode 100644 Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/ErpLogin.cs create mode 100644 Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/ErpMaterialSearchSettings.cs rename Files/powerGatePlugin/ErpServices/ErpManager/{ErpManager.cs => Interfaces/IErpManager.cs} (63%) diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpBomManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpBomManager.cs new file mode 100644 index 0000000..bce77b0 --- /dev/null +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpBomManager.cs @@ -0,0 +1,43 @@ +using System; +using ErpServices.ErpManager.Interfaces; + +namespace ErpServices.ErpManager.Implementation +{ + public partial class ErpManager : IErpManager + { + public BomHeader GetBomByNumber(string number) + { + throw new NotImplementedException(); + } + + public BomRow GetBomRowByNumber(string parentNumber, string childNumber) + { + throw new NotImplementedException(); + } + + public BomHeader CreateBomWithChildren(BomHeader bom) + { + throw new NotImplementedException(); + } + + public BomRow CreateBomRow(BomRow bomRow) + { + throw new NotImplementedException(); + } + + public BomHeader UpdateBomHeader(BomHeader bom) + { + throw new NotImplementedException(); + } + + public BomRow UpdateBomRow(BomRow bomRow) + { + throw new NotImplementedException(); + } + + public BomRow DeleteBomRow(BomRow bomRow) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpDocumentManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpDocumentManager.cs new file mode 100644 index 0000000..4853214 --- /dev/null +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpDocumentManager.cs @@ -0,0 +1,29 @@ +using System; +using System.IO; +using ErpServices.ErpManager.Interfaces; + +namespace ErpServices.ErpManager.Implementation +{ + public partial class ErpManager : IErpManager + { + public Document CreateDocumentMetadata(Document documentMetadata) + { + throw new NotImplementedException(); + } + + public Document UploadDocumentWithMetadata(MemoryStream fileStream, Document documentMetadata) + { + throw new NotImplementedException(); + } + + public Document UpdateDocumentMetadata(Document documentMetadata) + { + throw new NotImplementedException(); + } + + public Document UpdateDocumentWithMetadata(MemoryStream fileStream, Document documentMetadata) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpItemManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpItemManager.cs new file mode 100644 index 0000000..854b25e --- /dev/null +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpItemManager.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using ErpServices.ErpManager.Interfaces; + +namespace ErpServices.ErpManager.Implementation +{ + public partial class ErpManager : IErpManager + { + public Material GetMaterialyByNumber(string number) + { + throw new NotImplementedException(); + } + + public IEnumerable SearchMaterials(IEnumerable query) + { + throw new NotImplementedException(); + } + + public Material CreateMaterial(Material material) + { + throw new NotImplementedException(); + } + + public Material UpdateMaterial(Material material) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpManager.cs new file mode 100644 index 0000000..0659984 --- /dev/null +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpManager.cs @@ -0,0 +1,22 @@ +using System; +using ErpServices.ErpManager.Interfaces; + +namespace ErpServices.ErpManager.Implementation +{ + public partial class ErpManager : IErpManager + { + public void Dispose() + { + throw new NotImplementedException(); + } + + public ErpLogin Login { get; } + public bool IsConnected { get; } + + public bool Connect(ErpLogin login) + { + throw new NotImplementedException(); + } + + } +} \ No newline at end of file diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/ErpLogin.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/ErpLogin.cs new file mode 100644 index 0000000..1a61faf --- /dev/null +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/ErpLogin.cs @@ -0,0 +1,13 @@ +using System.Net; + +namespace ErpServices.ErpManager.Interfaces +{ + public struct ErpLogin + { + public IPEndPoint Server { get; } + public string ConnectionString { get; } + public string Mandant { get; } + public string UserName { get; } + public string Password { get; } + } +} \ No newline at end of file diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/ErpMaterialSearchSettings.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/ErpMaterialSearchSettings.cs new file mode 100644 index 0000000..a458f89 --- /dev/null +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/ErpMaterialSearchSettings.cs @@ -0,0 +1,20 @@ +namespace ErpServices.ErpManager.Interfaces +{ + public struct ErpMaterialSearchSettings + { + public ErpSearchProperty PropertyName { get; set; } + public ErpSearchOperator Operator { get; set; } + public string SearchValue { get; set; } + } + + public enum ErpSearchProperty + { + Number, + Description + } + + public enum ErpSearchOperator + { + Contains + } +} \ No newline at end of file diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/ErpManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs similarity index 63% rename from Files/powerGatePlugin/ErpServices/ErpManager/ErpManager.cs rename to Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs index 6bfa3b5..a7476c4 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/ErpManager.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs @@ -1,37 +1,9 @@ using System; using System.Collections.Generic; using System.IO; -using System.Net; -namespace ErpServices.ErpManager +namespace ErpServices.ErpManager.Interfaces { - public enum ErpSearchOperator - { - Contains - } - - public enum ErpSearchProperty - { - Number, - Description - } - - public struct ErpMaterialSearchSettings - { - public ErpSearchProperty PropertyName { get; set; } - public ErpSearchOperator Operator { get; set; } - public string SearchValue { get; set; } - } - - public struct ErpLogin - { - public IPEndPoint Server { get; } - public string ConnectionString { get; } - public string Mandant { get; } - public string UserName { get; } - public string Password { get; } - } - public interface IErpManager : IDisposable { ErpLogin Login { get; } @@ -62,8 +34,4 @@ public interface IErpManager : IDisposable BomRow DeleteBomRow(BomRow bomRow); } - - public partial class ErpManager : IErpManager - { - } } \ No newline at end of file diff --git a/Files/powerGatePlugin/ErpServices/ErpServices.csproj b/Files/powerGatePlugin/ErpServices/ErpServices.csproj index c7dc8fb..adde3d3 100644 --- a/Files/powerGatePlugin/ErpServices/ErpServices.csproj +++ b/Files/powerGatePlugin/ErpServices/ErpServices.csproj @@ -59,10 +59,16 @@ - + + + + + + + diff --git a/Files/powerGatePlugin/dataStandard.UI/NumSchm.cs b/Files/powerGatePlugin/dataStandard.UI/NumSchm.cs index f5df169..c697587 100644 --- a/Files/powerGatePlugin/dataStandard.UI/NumSchm.cs +++ b/Files/powerGatePlugin/dataStandard.UI/NumSchm.cs @@ -1,29 +1,32 @@ using System.ComponentModel; using System.Xml.Serialization; -public class NumSchm +namespace dataStandard.UI { - [XmlElement("FieldArray", Order = 0)] public string[] FieldArray { get; set; } + public class NumSchm + { + [XmlElement("FieldArray", Order = 0)] public string[] FieldArray { get; set; } - [XmlAttribute] public bool IsAct { get; set; } + [XmlAttribute] public bool IsAct { get; set; } - [XmlAttribute] public bool IsDflt { get; set; } + [XmlAttribute] public bool IsDflt { get; set; } - [XmlAttribute] public bool IsInUse { get; set; } + [XmlAttribute] public bool IsInUse { get; set; } - [XmlAttribute] public bool IsSys { get; set; } + [XmlAttribute] public bool IsSys { get; set; } - [XmlAttribute] public string Name { get; set; } + [XmlAttribute] public string Name { get; set; } - [XmlAttribute] public long SchmID { get; set; } + [XmlAttribute] public long SchmID { get; set; } - [XmlAttribute] public string SysName { get; set; } + [XmlAttribute] public string SysName { get; set; } - [XmlAttribute] public bool ToUpper { get; set; } + [XmlAttribute] public bool ToUpper { get; set; } - [Browsable(false)] - [EditorBrowsable(EditorBrowsableState.Never)] - public NumSchm() - { + [Browsable(false)] + [EditorBrowsable(EditorBrowsableState.Never)] + public NumSchm() + { + } } } \ No newline at end of file From cc880523dfaf9e2124d4fb95dc350b4afde99839 Mon Sep 17 00:00:00 2001 From: Patrick Gruber Date: Fri, 19 Jun 2020 09:53:22 +0200 Subject: [PATCH 04/10] Splitted service from metadata --- .../Implementation/ErpBomManager.cs | 1 + .../Implementation/ErpDocumentManager.cs | 1 + .../Implementation/ErpItemManager.cs | 1 + .../ErpManager/Interfaces/IErpManager.cs | 1 + .../ErpServices/ErpServices.csproj | 12 ++++--- .../ErpServices/Metadata/BomHeader.cs | 26 +++++++++++++++ .../ErpServices/Metadata/BomRow.cs | 26 +++++++++++++++ .../ErpServices/Metadata/Document.cs | 20 ++++++++++++ .../ErpServices/Metadata/Material.cs | 31 ++++++++++++++++++ .../ErpServices/{ => Services}/BomHeaders.cs | 27 ++-------------- .../ErpServices/{ => Services}/BomRows.cs | 27 ++-------------- .../{Document.cs => Services/Documents.cs} | 19 ++--------- .../ErpServices/{ => Services}/Materials.cs | 32 ++----------------- .../powerGatePlugin/ErpServices/WebService.cs | 1 + 14 files changed, 127 insertions(+), 98 deletions(-) create mode 100644 Files/powerGatePlugin/ErpServices/Metadata/BomHeader.cs create mode 100644 Files/powerGatePlugin/ErpServices/Metadata/BomRow.cs create mode 100644 Files/powerGatePlugin/ErpServices/Metadata/Document.cs create mode 100644 Files/powerGatePlugin/ErpServices/Metadata/Material.cs rename Files/powerGatePlugin/ErpServices/{ => Services}/BomHeaders.cs (83%) rename Files/powerGatePlugin/ErpServices/{ => Services}/BomRows.cs (78%) rename Files/powerGatePlugin/ErpServices/{Document.cs => Services/Documents.cs} (89%) rename Files/powerGatePlugin/ErpServices/{ => Services}/Materials.cs (75%) diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpBomManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpBomManager.cs index bce77b0..c11a0f2 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpBomManager.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpBomManager.cs @@ -1,5 +1,6 @@ using System; using ErpServices.ErpManager.Interfaces; +using ErpServices.Metadata; namespace ErpServices.ErpManager.Implementation { diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpDocumentManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpDocumentManager.cs index 4853214..fd0a76d 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpDocumentManager.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpDocumentManager.cs @@ -1,6 +1,7 @@ using System; using System.IO; using ErpServices.ErpManager.Interfaces; +using ErpServices.Metadata; namespace ErpServices.ErpManager.Implementation { diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpItemManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpItemManager.cs index 854b25e..5ecf00f 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpItemManager.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpItemManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using ErpServices.ErpManager.Interfaces; +using ErpServices.Metadata; namespace ErpServices.ErpManager.Implementation { diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs index a7476c4..8975bfe 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using ErpServices.Metadata; namespace ErpServices.ErpManager.Interfaces { diff --git a/Files/powerGatePlugin/ErpServices/ErpServices.csproj b/Files/powerGatePlugin/ErpServices/ErpServices.csproj index adde3d3..ae67978 100644 --- a/Files/powerGatePlugin/ErpServices/ErpServices.csproj +++ b/Files/powerGatePlugin/ErpServices/ErpServices.csproj @@ -59,17 +59,21 @@ + + + - - - + + + - + + diff --git a/Files/powerGatePlugin/ErpServices/Metadata/BomHeader.cs b/Files/powerGatePlugin/ErpServices/Metadata/BomHeader.cs new file mode 100644 index 0000000..0de5ed9 --- /dev/null +++ b/Files/powerGatePlugin/ErpServices/Metadata/BomHeader.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Data.Services.Common; +using LiteDB; + +namespace ErpServices.Metadata +{ + [DataServiceKey("Number")] + [DataServiceEntity] + public class BomHeader + { + public string Number { get; set; } + [BsonIgnore] + public string Description { get; set; } + public string State { get; set; } + public string UnitOfMeasure { get; set; } + public DateTime ModifiedDate { get; set; } + + public List BomRows { get; set; } + + public BomHeader() + { + BomRows = new List(); + } + } +} \ No newline at end of file diff --git a/Files/powerGatePlugin/ErpServices/Metadata/BomRow.cs b/Files/powerGatePlugin/ErpServices/Metadata/BomRow.cs new file mode 100644 index 0000000..c856d54 --- /dev/null +++ b/Files/powerGatePlugin/ErpServices/Metadata/BomRow.cs @@ -0,0 +1,26 @@ +using System; +using System.Data.Services; +using System.Data.Services.Common; +using LiteDB; + +namespace ErpServices.Metadata +{ + [DataServiceKey("ParentNumber","ChildNumber","Position")] + [DataServiceEntity] + [IgnoreProperties("Id")] + public class BomRow + { + public string ParentNumber { get; set; } + public string ChildNumber { get; set; } + public int Position { get; set; } + public string Type { get; set; } + public double Quantity { get; set; } + [BsonIgnore] + public string UnitOfMeasure { get; set; } + [BsonIgnore] + public string Description { get; set; } + public DateTime ModifiedDate { get; set; } + + public string Id => $"{ParentNumber}+{ChildNumber}+{Position.ToString()}"; + } +} \ No newline at end of file diff --git a/Files/powerGatePlugin/ErpServices/Metadata/Document.cs b/Files/powerGatePlugin/ErpServices/Metadata/Document.cs new file mode 100644 index 0000000..340b2eb --- /dev/null +++ b/Files/powerGatePlugin/ErpServices/Metadata/Document.cs @@ -0,0 +1,20 @@ +using System.Data.Services.Common; +using powerGateServer.SDK; + +namespace ErpServices.Metadata +{ + [DataServiceKey("Number")] + [DataServiceEntity] + //[IgnoreProperties("Directory")] + public class Document : Streamable + { + public string Number { get; set; } + public string Description { get; set; } + public string Directory { get; set; } + + public override string GetContentType() + { + return ContentTypes.Application.Pdf; + } + } +} \ No newline at end of file diff --git a/Files/powerGatePlugin/ErpServices/Metadata/Material.cs b/Files/powerGatePlugin/ErpServices/Metadata/Material.cs new file mode 100644 index 0000000..14a9591 --- /dev/null +++ b/Files/powerGatePlugin/ErpServices/Metadata/Material.cs @@ -0,0 +1,31 @@ +using System; +using System.Data.Services.Common; +using LiteDB; + +namespace ErpServices.Metadata +{ + [DataServiceKey("Number")] + [DataServiceEntity] + public class Material + { + public string Number { get; set; } + public string Description { get; set; } + public DateTime ModifiedDate { get; set; } + public string UnitOfMeasure { get; set; } + public string Type { get; set; } + public bool IsBlocked { get; set; } + public string Category { get; set; } + public string Shelf { get; set; } + public double Weight { get; set; } + public string Dimensions { get; set; } + [BsonIgnore] + public bool IsVendorSpecified { + get => !string.IsNullOrEmpty(VendorNumber); + set => _ = value; + } + public string VendorNumber { get; set; } + public string VendorName { get; set; } + public string VendorItemNumber { get; set; } + public decimal Cost { get; set; } + } +} \ No newline at end of file diff --git a/Files/powerGatePlugin/ErpServices/BomHeaders.cs b/Files/powerGatePlugin/ErpServices/Services/BomHeaders.cs similarity index 83% rename from Files/powerGatePlugin/ErpServices/BomHeaders.cs rename to Files/powerGatePlugin/ErpServices/Services/BomHeaders.cs index be24508..bbfbf80 100644 --- a/Files/powerGatePlugin/ErpServices/BomHeaders.cs +++ b/Files/powerGatePlugin/ErpServices/Services/BomHeaders.cs @@ -1,34 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Data.Services.Common; +using System.Collections.Generic; using System.Linq; using System.Reflection; +using ErpServices.Metadata; using LiteDB; using log4net; using powerGateServer.SDK; -namespace ErpServices +namespace ErpServices.Services { - [DataServiceKey("Number")] - [DataServiceEntity] - public class BomHeader - { - public string Number { get; set; } - [BsonIgnore] - public string Description { get; set; } - public string State { get; set; } - public string UnitOfMeasure { get; set; } - public DateTime ModifiedDate { get; set; } - - public List BomRows { get; set; } - - public BomHeader() - { - BomRows = new List(); - } - } - - public class BomHeaders : ServiceMethod { static readonly ILog Log = diff --git a/Files/powerGatePlugin/ErpServices/BomRows.cs b/Files/powerGatePlugin/ErpServices/Services/BomRows.cs similarity index 78% rename from Files/powerGatePlugin/ErpServices/BomRows.cs rename to Files/powerGatePlugin/ErpServices/Services/BomRows.cs index 8fab287..e93509c 100644 --- a/Files/powerGatePlugin/ErpServices/BomRows.cs +++ b/Files/powerGatePlugin/ErpServices/Services/BomRows.cs @@ -1,34 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Data.Services; -using System.Data.Services.Common; +using System.Collections.Generic; using System.Linq; using System.Reflection; +using ErpServices.Metadata; using LiteDB; using log4net; using powerGateServer.SDK; -namespace ErpServices +namespace ErpServices.Services { - [DataServiceKey("ParentNumber","ChildNumber","Position")] - [DataServiceEntity] - [IgnoreProperties("Id")] - public class BomRow - { - public string ParentNumber { get; set; } - public string ChildNumber { get; set; } - public int Position { get; set; } - public string Type { get; set; } - public double Quantity { get; set; } - [BsonIgnore] - public string UnitOfMeasure { get; set; } - [BsonIgnore] - public string Description { get; set; } - public DateTime ModifiedDate { get; set; } - - public string Id => $"{ParentNumber}+{ChildNumber}+{Position.ToString()}"; - } - public class BomRows : ServiceMethod { static readonly ILog Log = diff --git a/Files/powerGatePlugin/ErpServices/Document.cs b/Files/powerGatePlugin/ErpServices/Services/Documents.cs similarity index 89% rename from Files/powerGatePlugin/ErpServices/Document.cs rename to Files/powerGatePlugin/ErpServices/Services/Documents.cs index a553c4a..9cd1685 100644 --- a/Files/powerGatePlugin/ErpServices/Document.cs +++ b/Files/powerGatePlugin/ErpServices/Services/Documents.cs @@ -1,31 +1,16 @@ using System; using System.Collections.Generic; -using System.Data.Services.Common; using System.IO; using System.Linq; using System.Reflection; using System.ServiceModel.Web; +using ErpServices.Metadata; using LiteDB; using log4net; using powerGateServer.SDK; -namespace ErpServices +namespace ErpServices.Services { - [DataServiceKey("Number")] - [DataServiceEntity] - //[IgnoreProperties("Directory")] - public class Document : Streamable - { - public string Number { get; set; } - public string Description { get; set; } - public string Directory { get; set; } - - public override string GetContentType() - { - return ContentTypes.Application.Pdf; - } - } - public class Documents : ServiceMethod, IStreamableServiceMethod { static readonly ILog Log = diff --git a/Files/powerGatePlugin/ErpServices/Materials.cs b/Files/powerGatePlugin/ErpServices/Services/Materials.cs similarity index 75% rename from Files/powerGatePlugin/ErpServices/Materials.cs rename to Files/powerGatePlugin/ErpServices/Services/Materials.cs index 8b904aa..68a4898 100644 --- a/Files/powerGatePlugin/ErpServices/Materials.cs +++ b/Files/powerGatePlugin/ErpServices/Services/Materials.cs @@ -1,39 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Data.Services.Common; +using System.Collections.Generic; using System.Linq; using System.Reflection; +using ErpServices.Metadata; using LiteDB; using log4net; using powerGateServer.SDK; -namespace ErpServices +namespace ErpServices.Services { - [DataServiceKey("Number")] - [DataServiceEntity] - public class Material - { - public string Number { get; set; } - public string Description { get; set; } - public DateTime ModifiedDate { get; set; } - public string UnitOfMeasure { get; set; } - public string Type { get; set; } - public bool IsBlocked { get; set; } - public string Category { get; set; } - public string Shelf { get; set; } - public double Weight { get; set; } - public string Dimensions { get; set; } - [BsonIgnore] - public bool IsVendorSpecified { - get => !string.IsNullOrEmpty(VendorNumber); - set => _ = value; - } - public string VendorNumber { get; set; } - public string VendorName { get; set; } - public string VendorItemNumber { get; set; } - public decimal Cost { get; set; } - } - public class Materials : ServiceMethod { static readonly ILog Log = diff --git a/Files/powerGatePlugin/ErpServices/WebService.cs b/Files/powerGatePlugin/ErpServices/WebService.cs index e0393db..805cad2 100644 --- a/Files/powerGatePlugin/ErpServices/WebService.cs +++ b/Files/powerGatePlugin/ErpServices/WebService.cs @@ -1,5 +1,6 @@ using System.Configuration; using System.Reflection; +using ErpServices.Services; using log4net; using powerGateServer.SDK; From 61a36c7c40a35355bf8010fd7c33fc503322f979 Mon Sep 17 00:00:00 2001 From: Patrick Gruber Date: Thu, 25 Jun 2020 12:06:11 +0200 Subject: [PATCH 05/10] Interface implementation for BOM and ITEMS --- .../Implementation/ErpBomManager.cs | 70 +++++++++++++-- .../Implementation/ErpDocumentManager.cs | 2 + .../Implementation/ErpItemManager.cs | 39 +++++++- .../ErpManager/Implementation/ErpManager.cs | 57 ++++++++++-- .../ErpManager/Interfaces/ErpLogin.cs | 10 +-- .../Interfaces/ErpMaterialSearchSettings.cs | 11 +-- .../ErpManager/Interfaces/IErpManager.cs | 6 +- .../ErpServices/ErpServices.csproj | 4 + .../powerGateServer.SDK.Helper.dll | Bin 0 -> 15360 bytes .../ErpServices/Services/BomHeaders.cs | 81 ++++------------- .../ErpServices/Services/BomRows.cs | 75 ++++------------ .../ErpServices/Services/Documents.cs | 7 +- .../ErpServices/Services/ErpBaseService.cs | 49 ++++++++++ .../ErpServices/Services/Materials.cs | 84 ++++-------------- .../powerGatePlugin/ErpServices/WebService.cs | 36 ++++++-- 15 files changed, 301 insertions(+), 230 deletions(-) create mode 100644 Files/powerGatePlugin/ErpServices/ReferenceAssemblies/powerGateServer.SDK.Helper.dll create mode 100644 Files/powerGatePlugin/ErpServices/Services/ErpBaseService.cs diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpBomManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpBomManager.cs index c11a0f2..28d3ed5 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpBomManager.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpBomManager.cs @@ -1,44 +1,96 @@ -using System; +using System.Collections.Generic; +using System.Linq; using ErpServices.ErpManager.Interfaces; using ErpServices.Metadata; +using LiteDB; namespace ErpServices.ErpManager.Implementation { public partial class ErpManager : IErpManager { - public BomHeader GetBomByNumber(string number) + + public BomHeader GetBomWithChildrenByNumber(string number) + { + return ExecuteOnDatabase(delegate(LiteDatabase database) + { + var bomHeader = database.GetCollection().Find(header => header.Number == number).FirstOrDefault(); + if(bomHeader != null) + bomHeader.BomRows = GetBomRowsByHeaderNumber(bomHeader.Number); + return bomHeader; + }); + } + + List GetBomRowsByHeaderNumber(string parentNumber) { - throw new NotImplementedException(); + return ExecuteOnDatabase(delegate (LiteDatabase database) + { + var bomRows = database.GetCollection() + .Find(x => x.ParentNumber.Equals(parentNumber)) + .OrderBy(x => x.Position) + .ToList(); + + foreach (var bomRow in bomRows) + { + var material = GetMaterialyByNumber(bomRow.ChildNumber); + bomRow.Description = material.Description; + bomRow.UnitOfMeasure = material.UnitOfMeasure; + } + + return bomRows; + }); } public BomRow GetBomRowByNumber(string parentNumber, string childNumber) { - throw new NotImplementedException(); + var bomRows = GetBomRowsByHeaderNumber(parentNumber); + return bomRows.FirstOrDefault(b => b.ChildNumber == childNumber); } public BomHeader CreateBomWithChildren(BomHeader bom) { - throw new NotImplementedException(); + return ExecuteOnDatabase(delegate (LiteDatabase database) + { + database.GetCollection().Insert(bom); + foreach (var bomRow in bom.BomRows) + CreateBomRow(bomRow); + return bom; + }); } public BomRow CreateBomRow(BomRow bomRow) { - throw new NotImplementedException(); + return ExecuteOnDatabase(delegate (LiteDatabase database) + { + database.GetCollection().Insert(bomRow); + return bomRow; + }); } public BomHeader UpdateBomHeader(BomHeader bom) { - throw new NotImplementedException(); + return ExecuteOnDatabase(delegate (LiteDatabase database) + { + database.GetCollection().Update(bom); + return bom; + }); } public BomRow UpdateBomRow(BomRow bomRow) { - throw new NotImplementedException(); + return ExecuteOnDatabase(delegate (LiteDatabase database) + { + database.GetCollection().Update(bomRow); + return bomRow; + }); } public BomRow DeleteBomRow(BomRow bomRow) { - throw new NotImplementedException(); + return ExecuteOnDatabase(delegate (LiteDatabase database) + { + database.GetCollection().Delete(bomRow.Id); + return bomRow; + }); } } } \ No newline at end of file diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpDocumentManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpDocumentManager.cs index fd0a76d..0f98078 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpDocumentManager.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpDocumentManager.cs @@ -2,11 +2,13 @@ using System.IO; using ErpServices.ErpManager.Interfaces; using ErpServices.Metadata; +using LiteDB; namespace ErpServices.ErpManager.Implementation { public partial class ErpManager : IErpManager { + public Document CreateDocumentMetadata(Document documentMetadata) { throw new NotImplementedException(); diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpItemManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpItemManager.cs index 5ecf00f..71aa006 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpItemManager.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpItemManager.cs @@ -1,30 +1,61 @@ using System; using System.Collections.Generic; +using System.Linq; using ErpServices.ErpManager.Interfaces; using ErpServices.Metadata; +using LiteDB; +using powerGateServer.SDK; namespace ErpServices.ErpManager.Implementation { public partial class ErpManager : IErpManager { + public Material GetMaterialyByNumber(string number) { - throw new NotImplementedException(); + return ExecuteOnDatabase(database => database.GetCollection().Find(material => material.Number == number)).FirstOrDefault(); } public IEnumerable SearchMaterials(IEnumerable query) { - throw new NotImplementedException(); + // ToDO: Parse the Query parameter and execute on DB optimized query + return ExecuteOnDatabase(database => database.GetCollection() + .FindAll().ToList()); } public Material CreateMaterial(Material material) { - throw new NotImplementedException(); + if (material.Number.Equals("*")) + material.Number = GetNextNumber(); + Log.InfoFormat("Create material: {0}", material.Number); + ExecuteOnDatabase(database => database.GetCollection().Insert(material)); + return material; + } + + string GetNextNumber() + { + Log.Info(">> GetNextNumber >>"); + var nextNumber = "500000"; + + return ExecuteOnDatabase(delegate(LiteDatabase database) + { + var collection = database.GetCollection(); + + int y; + var material = collection.Find(x => int.TryParse(x.Number, out y)).OrderByDescending(x => x.Number).FirstOrDefault(); + if (material != null) + nextNumber = material.Number; + + var nextIntNumber = int.Parse(nextNumber) + 1; + Log.InfoFormat("GetNextNumber: {0}", nextIntNumber.ToString()); + return (nextIntNumber).ToString(); + }); } public Material UpdateMaterial(Material material) { - throw new NotImplementedException(); + ExecuteOnDatabase(database => database.GetCollection().Update(material)); + return material; } } } \ No newline at end of file diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpManager.cs index 0659984..46fb2ba 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpManager.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpManager.cs @@ -1,22 +1,69 @@ using System; +using System.Linq; +using System.Reflection; using ErpServices.ErpManager.Interfaces; +using ErpServices.Metadata; +using LiteDB; +using log4net; namespace ErpServices.ErpManager.Implementation { public partial class ErpManager : IErpManager { - public void Dispose() + static readonly ILog Log = + LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + public ErpLogin Login { get; private set; } + + public bool IsConnected { - throw new NotImplementedException(); + get + { + if (string.IsNullOrEmpty(Login.ConnectionString)) + return false; + return true; + } } - public ErpLogin Login { get; } - public bool IsConnected { get; } + public ErpManager() + { + BsonMapper.Global.Entity().Id(x => x.Number); + BsonMapper.Global.Entity().Id(x => x.Number); + BsonMapper.Global.Entity().Id(x => x.Number); + BsonMapper.Global.Entity().Id(x => x.Id); + } public bool Connect(ErpLogin login) { - throw new NotImplementedException(); + Log.InfoFormat("Connect to: {0}", login.ConnectionString); + try + { + Login = login; + ExecuteOnDatabase(database => database.GetCollection()); + return true; + } + catch (Exception exception) + { + Log.Error(exception); + return false; + } } + protected T ExecuteOnDatabase(Func operation) + { + if(!IsConnected) + throw new Exception("No connection, first make a Connect()"); + + using (var db = new LiteDatabase(Login.ConnectionString)) + { + return operation(db); + } + } + + public void Dispose() + { + Log.InfoFormat("Disposing ERP Manager.."); + // Logout and clean up + } } } \ No newline at end of file diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/ErpLogin.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/ErpLogin.cs index 1a61faf..a2f2a7b 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/ErpLogin.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/ErpLogin.cs @@ -4,10 +4,10 @@ namespace ErpServices.ErpManager.Interfaces { public struct ErpLogin { - public IPEndPoint Server { get; } - public string ConnectionString { get; } - public string Mandant { get; } - public string UserName { get; } - public string Password { get; } + public IPEndPoint Server { get; set; } + public string ConnectionString { get; set; } + public int Mandant { get; set; } + public string UserName { get; set; } + public string Password { get; set; } } } \ No newline at end of file diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/ErpMaterialSearchSettings.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/ErpMaterialSearchSettings.cs index a458f89..6729423 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/ErpMaterialSearchSettings.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/ErpMaterialSearchSettings.cs @@ -1,9 +1,11 @@ -namespace ErpServices.ErpManager.Interfaces +using powerGateServer.SDK; + +namespace ErpServices.ErpManager.Interfaces { public struct ErpMaterialSearchSettings { public ErpSearchProperty PropertyName { get; set; } - public ErpSearchOperator Operator { get; set; } + public OperatorType? Operator { get; set; } public string SearchValue { get; set; } } @@ -12,9 +14,4 @@ public enum ErpSearchProperty Number, Description } - - public enum ErpSearchOperator - { - Contains - } } \ No newline at end of file diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs index 8975bfe..f1c630a 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs @@ -17,8 +17,7 @@ public interface IErpManager : IDisposable IEnumerable SearchMaterials(IEnumerable query); Material CreateMaterial(Material material); Material UpdateMaterial(Material material); - - + // Documents functionality Document CreateDocumentMetadata(Document documentMetadata); Document UploadDocumentWithMetadata(MemoryStream fileStream, Document documentMetadata); @@ -26,13 +25,12 @@ public interface IErpManager : IDisposable Document UpdateDocumentWithMetadata(MemoryStream fileStream, Document documentMetadata); // BOM functionality - BomHeader GetBomByNumber(string number); + BomHeader GetBomWithChildrenByNumber(string number); BomRow GetBomRowByNumber(string parentNumber, string childNumber); BomHeader CreateBomWithChildren(BomHeader bom); BomRow CreateBomRow(BomRow bomRow); BomHeader UpdateBomHeader(BomHeader bom); BomRow UpdateBomRow(BomRow bomRow); BomRow DeleteBomRow(BomRow bomRow); - } } \ No newline at end of file diff --git a/Files/powerGatePlugin/ErpServices/ErpServices.csproj b/Files/powerGatePlugin/ErpServices/ErpServices.csproj index ae67978..eaaf22f 100644 --- a/Files/powerGatePlugin/ErpServices/ErpServices.csproj +++ b/Files/powerGatePlugin/ErpServices/ErpServices.csproj @@ -51,6 +51,9 @@ ReferenceAssemblies\powerGateServer.SDK.dll False + + ReferenceAssemblies\powerGateServer.SDK.Helper.dll + @@ -73,6 +76,7 @@ + diff --git a/Files/powerGatePlugin/ErpServices/ReferenceAssemblies/powerGateServer.SDK.Helper.dll b/Files/powerGatePlugin/ErpServices/ReferenceAssemblies/powerGateServer.SDK.Helper.dll new file mode 100644 index 0000000000000000000000000000000000000000..7d11837e9648020b71ff8e399b3a19bfb1e0d807 GIT binary patch literal 15360 zcmeHudvsgXmG{2)N>?vOv1G^2!%38f6XA!jLy{&@2spNr7!o_NoficX*}ir}BwgoT zDTzr#ol*+v8z@Z4S3U}q0*gZVDD(q5?Ua&%nYGGl+JT{6Ln-aROas%-w1v)e+Q#$S z`(8crn9l3ZjuP#2_HXaA&p!L?^SF|{<*HAUMnoRGr>2OWM#-0GR8;&F zn-z^ZcD#FSv9~v9VJxJy5iJAachDEMp^V|Z7jL3!sjH6P4CqYw^?AI3^Gl<>H?b=J zFPAR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bN!!Y)6o6=#8v3p}Piw-4tQpDD$hN9fGR|8#6SWG=U&9}^=k$a6vEeE)as zW2pFhCZ5By?VdZ6=g#9QY14ry@J%v{Y|Y4%*?-iI`}^P5A87=(I={30i}pX#@&Azz G``-X!R2B>X literal 0 HcmV?d00001 diff --git a/Files/powerGatePlugin/ErpServices/Services/BomHeaders.cs b/Files/powerGatePlugin/ErpServices/Services/BomHeaders.cs index bbfbf80..f3c1825 100644 --- a/Files/powerGatePlugin/ErpServices/Services/BomHeaders.cs +++ b/Files/powerGatePlugin/ErpServices/Services/BomHeaders.cs @@ -1,95 +1,50 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; -using System.Reflection; +using ErpServices.ErpManager.Interfaces; using ErpServices.Metadata; -using LiteDB; -using log4net; using powerGateServer.SDK; +using powerGateServer.SDK.Helper; namespace ErpServices.Services { - public class BomHeaders : ServiceMethod + public class BomHeaders : ErpBaseService { - static readonly ILog Log = - LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); public override string Name => "BomHeaders"; - public BomHeaders() + public BomHeaders(IErpManager erpManager) : base(erpManager) { - BsonMapper.Global.Entity().Id(x => x.Number); - //BsonMapper.Global.Entity().DbRef(x => x.BomRows); } public override IEnumerable Query(IExpression expression) { - if (expression.Where.Any(b => b.PropertyName.Equals("Number"))) + if (expression.IsSimpleWhereToken()) { - var number = expression.Where.FirstOrDefault(w => w.PropertyName.Equals("Number")); - if (number != null && number.Value != number && number.Value.ToString() != "") - return GetBomHeaders(number.Value.ToString()); + var number = expression.GetWhereValuesAsString("Number"); + Log.InfoFormat("Single query for bom number {0}", number); + var bom = ErpManager.GetBomWithChildrenByNumber(number); + if (bom != null) + return new[] { bom}; + return Enumerable.Empty(); } - return GetBomHeaders(); - } - - public static List GetBomHeaders(string number = null) - { - List bomHeaders; - using (var db = new LiteDatabase(WebService.DatabaseFileLocation)) - { - if (number == null) - { - bomHeaders = db.GetCollection() - .FindAll() - .ToList(); - } - else - { - bomHeaders = db.GetCollection() - .Find(x => x.Number.Equals(number)) - .ToList(); - } - - foreach (var bomHeader in bomHeaders) - { - var material = db.GetCollection() - .FindOne(x => x.Number.Equals(bomHeader.Number)); - bomHeader.Description = material.Description; - bomHeader.BomRows = BomRows.GetBomRows(bomHeader.Number); - } - } - return bomHeaders; + //var searchSettings = GetSearchSettings(expression); + throw new NotSupportedException("Search ERP BOM headers is not supported!"); } public override void Update(BomHeader entity) { - using (var db = new LiteDatabase(WebService.DatabaseFileLocation)) - { - db.GetCollection() - .Update(entity); - } + ErpManager.UpdateBomHeader(entity); } public override void Create(BomHeader entity) { - using (var db = new LiteDatabase(WebService.DatabaseFileLocation)) - { - db.GetCollection() - .Insert(entity.BomRows); - db.GetCollection() - .Insert(entity); - } + ErpManager.CreateBomWithChildren(entity); } public override void Delete(BomHeader entity) { - using (var db = new LiteDatabase(WebService.DatabaseFileLocation)) - { - db.GetCollection() - .Delete(x => x.ParentNumber.Equals(entity.Number)); - db.GetCollection() - .Delete(x => x.Number.Equals(entity.Number)); - } + throw new NotSupportedException(); } } } \ No newline at end of file diff --git a/Files/powerGatePlugin/ErpServices/Services/BomRows.cs b/Files/powerGatePlugin/ErpServices/Services/BomRows.cs index e93509c..f73a3af 100644 --- a/Files/powerGatePlugin/ErpServices/Services/BomRows.cs +++ b/Files/powerGatePlugin/ErpServices/Services/BomRows.cs @@ -1,92 +1,55 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Reflection; +using ErpServices.ErpManager.Interfaces; using ErpServices.Metadata; -using LiteDB; using log4net; using powerGateServer.SDK; +using powerGateServer.SDK.Helper; namespace ErpServices.Services { - public class BomRows : ServiceMethod + public class BomRows : ErpBaseService { static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); public override string Name => "BomRows"; - public BomRows() + public BomRows(IErpManager erpManager) : base(erpManager) { - BsonMapper.Global.Entity().Id(x => x.Id); } public override IEnumerable Query(IExpression expression) { - if (expression.Where.Any(w => w.PropertyName.Equals("ParentNumber"))) + if (expression.IsSimpleWhereToken()) { - var parentNumber = expression.Where.FirstOrDefault(w => w.PropertyName.Equals("ParentNumber")); - if (parentNumber != null && parentNumber.Value != null && parentNumber.Value.ToString() != "") - return GetBomRows(parentNumber.Value.ToString()); + var parentNumber = expression.GetWhereValuesAsString("ParentNumber"); + var childNumber = expression.GetWhereValuesAsString("ChildNumber"); + Log.InfoFormat("Single query for bom row, header number {0} and child number", parentNumber, childNumber); + var bomRow = ErpManager.GetBomRowByNumber(parentNumber, childNumber); + if(bomRow != null) + return new[] { bomRow }; + return Enumerable.Empty(); } - return GetBomRows(); - } - - public static List GetBomRows(string parentNumber = null) - { - List bomRows; - using (var db = new LiteDatabase(WebService.DatabaseFileLocation)) - { - if (parentNumber == null) - { - bomRows = db.GetCollection() - .FindAll() - .OrderBy(x => x.Position) - .ToList(); - } - else - { - bomRows = db.GetCollection() - .Find(x => x.ParentNumber.Equals(parentNumber)) - .OrderBy(x => x.Position) - .ToList(); - } - - foreach (var bomRow in bomRows) - { - var material = db.GetCollection() - .FindOne(x => x.Number.Equals(bomRow.ChildNumber)); - bomRow.Description = material.Description; - bomRow.UnitOfMeasure = material.UnitOfMeasure; - } - } - return bomRows; + //var searchSettings = GetSearchSettings(expression); + throw new NotSupportedException("Search ERP BOM headers is not supported!"); } public override void Update(BomRow entity) { - using (var db = new LiteDatabase(WebService.DatabaseFileLocation)) - { - db.GetCollection() - .Update(entity); - } + ErpManager.UpdateBomRow(entity); } public override void Create(BomRow entity) { - using (var db = new LiteDatabase(WebService.DatabaseFileLocation)) - { - db.GetCollection() - .Insert(entity); - } + ErpManager.CreateBomRow(entity); } public override void Delete(BomRow entity) { - using (var db = new LiteDatabase(WebService.DatabaseFileLocation)) - { - db.GetCollection() - .Delete(x => x.Id.Equals(entity.Id)); - } + ErpManager.DeleteBomRow(entity); } } } \ No newline at end of file diff --git a/Files/powerGatePlugin/ErpServices/Services/Documents.cs b/Files/powerGatePlugin/ErpServices/Services/Documents.cs index 9cd1685..70a4062 100644 --- a/Files/powerGatePlugin/ErpServices/Services/Documents.cs +++ b/Files/powerGatePlugin/ErpServices/Services/Documents.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Reflection; using System.ServiceModel.Web; +using ErpServices.ErpManager.Interfaces; using ErpServices.Metadata; using LiteDB; using log4net; @@ -11,15 +12,15 @@ namespace ErpServices.Services { - public class Documents : ServiceMethod, IStreamableServiceMethod + public class Documents : ErpBaseService, IStreamableServiceMethod { static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); public override string Name => "Documents"; - public Documents() + public Documents(string storeForBinaryFiles, IErpManager erpManager) : base(erpManager) { - BsonMapper.Global.Entity().Id(x => x.Number); + } public override IEnumerable Query(IExpression expression) diff --git a/Files/powerGatePlugin/ErpServices/Services/ErpBaseService.cs b/Files/powerGatePlugin/ErpServices/Services/ErpBaseService.cs new file mode 100644 index 0000000..4c337ba --- /dev/null +++ b/Files/powerGatePlugin/ErpServices/Services/ErpBaseService.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using ErpServices.ErpManager.Interfaces; +using ErpServices.Metadata; +using log4net; +using powerGateServer.SDK; +using powerGateServer.SDK.Helper; + +namespace ErpServices.Services +{ + public abstract class ErpBaseService : ServiceMethod + { + protected IErpManager ErpManager; + + protected static readonly ILog Log = + LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + protected ErpBaseService(IErpManager erpManager) + { + ErpManager = erpManager; + } + + + protected IEnumerable GetSearchSettings(IExpression expression) + { + var query = new List(); + foreach (var whereToken in expression.Where) + { + var searchValue = expression.GetWhereValueByName(whereToken.PropertyName); + + if (!Enum.TryParse(whereToken.PropertyName, out ErpSearchProperty searchProperty)) + { + Log.WarnFormat("Search query for property name '{0}' is not supported by ERP, therefore making bigger search in order to filter the values!", searchValue); + continue; + } + + query.Add(new ErpMaterialSearchSettings + { + Operator = whereToken.Operator, + PropertyName = searchProperty, + SearchValue = searchValue.ToString() + }); + } + return query; + } + + } +} \ No newline at end of file diff --git a/Files/powerGatePlugin/ErpServices/Services/Materials.cs b/Files/powerGatePlugin/ErpServices/Services/Materials.cs index 68a4898..e818d4c 100644 --- a/Files/powerGatePlugin/ErpServices/Services/Materials.cs +++ b/Files/powerGatePlugin/ErpServices/Services/Materials.cs @@ -1,97 +1,51 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; -using System.Reflection; +using ErpServices.ErpManager.Interfaces; using ErpServices.Metadata; -using LiteDB; -using log4net; using powerGateServer.SDK; +using powerGateServer.SDK.Helper; namespace ErpServices.Services { - public class Materials : ServiceMethod + public class Materials : ErpBaseService { - static readonly ILog Log = - LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); public override string Name => "Materials"; - public Materials() - { - BsonMapper.Global.Entity().Id(x => x.Number); - } - public string GetNextNumber() + public Materials(IErpManager erpManager) : base(erpManager) { - Log.Info(">> GetNextNumber >>"); - var nextNumber = "500000"; - - using (var db = new LiteDatabase(WebService.DatabaseFileLocation)) - { - var collection = db.GetCollection(); - - int y; - var material = collection.Find(x => int.TryParse(x.Number, out y)).OrderByDescending(x => x.Number).FirstOrDefault(); - if (material != null) - nextNumber = material.Number; - - var nextIntNumber = int.Parse(nextNumber) + 1; - Log.InfoFormat("GetNextNumber: {0}", nextIntNumber.ToString()); - return (nextIntNumber).ToString(); - } } public override IEnumerable Query(IExpression expression) { - //if (expression.Where.Any(b => b.PropertyName.Equals("Number"))) - //{ - // var number = expression.Where.FirstOrDefault(w => w.PropertyName.Equals("Number")); - // if (number != null && number.Value != number && number.Value.ToString() != "") - // { - // using (var db = new LiteDatabase(WebService.DatabaseFileLocation)) - // { - // return db.GetCollection() - // .Find(x => x.Number.Equals(number.Value)) - // .ToList(); - // } - // } - // return null; - //} - - using (var db = new LiteDatabase(WebService.DatabaseFileLocation)) + if (expression.IsSimpleWhereToken()) { - return db.GetCollection() - .FindAll() - .ToList(); + var number = expression.GetWhereValuesAsString("Number"); + Log.InfoFormat("Single query for item number {0}", number); + var material = ErpManager.GetMaterialyByNumber(number); + + if (material != null) + return new[] { material }; + return Enumerable.Empty(); } + var searchSettings = GetSearchSettings(expression); + return ErpManager.SearchMaterials(searchSettings); } public override void Update(Material entity) { - using (var db = new LiteDatabase(WebService.DatabaseFileLocation)) - { - db.GetCollection() - .Update(entity); - } + ErpManager.UpdateMaterial(entity); } public override void Create(Material entity) { - if (entity.Number.Equals("*")) - entity.Number = GetNextNumber(); - - using (var db = new LiteDatabase(WebService.DatabaseFileLocation)) - { - db.GetCollection() - .Insert(entity); - } + ErpManager.CreateMaterial(entity); } public override void Delete(Material entity) { - using (var db = new LiteDatabase(WebService.DatabaseFileLocation)) - { - db.GetCollection() - .Delete(x => x.Number.Equals(entity.Number)); - } + throw new NotSupportedException(); } } } \ No newline at end of file diff --git a/Files/powerGatePlugin/ErpServices/WebService.cs b/Files/powerGatePlugin/ErpServices/WebService.cs index 805cad2..50391f9 100644 --- a/Files/powerGatePlugin/ErpServices/WebService.cs +++ b/Files/powerGatePlugin/ErpServices/WebService.cs @@ -1,5 +1,7 @@ -using System.Configuration; +using System; +using System.Configuration; using System.Reflection; +using ErpServices.ErpManager.Interfaces; using ErpServices.Services; using log4net; using powerGateServer.SDK; @@ -16,23 +18,39 @@ public class WebService : powerGateServer.SDK.WebService public WebService() { - AddMethod(new Materials()); - AddMethod(new BomHeaders()); - AddMethod(new BomRows()); - AddMethod(new Documents()); + var erpStorageConfiguration = GetErpStorageConfiguration(); + var erpManager = new ErpManager.Implementation.ErpManager(); + var erpLogin = new ErpLogin + { + ConnectionString = erpStorageConfiguration.Settings["FileStorageLocation"].Value, + UserName = "coolOrange", + Password = "Template2020", + Mandant = 2020 + }; + var connected = erpManager.Connect(erpLogin); + if(!connected) + throw new Exception(string.Format("Failed to connect to ERP with Connection-String: {0}", erpLogin.ConnectionString)); + + AddMethod(new Materials(erpManager)); + AddMethod(new BomHeaders(erpManager)); + AddMethod(new BomRows(erpManager)); + + var storeForBinaryFiles = erpStorageConfiguration.Settings["DatabaseFileLocation"].Value; + AddMethod(new Documents(storeForBinaryFiles, erpManager)); } - static WebService() + AppSettingsSection GetErpStorageConfiguration() { Log.Info("Reading .config file"); var configFullName = Assembly.GetExecutingAssembly().Location + ".config"; var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = configFullName }; var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); var section = configuration.GetSection("ErpStorage") as AppSettingsSection; - if (section == null) return; - DatabaseFileLocation = section.Settings["DatabaseFileLocation"].Value; - FileStorageLocation = section.Settings["FileStorageLocation"].Value; + if (section == null) + throw new Exception("Failed to find 'ErpStorage' section inside the config file!"); + Log.Info("Reading .config file successfully done!"); + return section; } } } \ No newline at end of file From 2f1f9c65d36ec0e95e53170d44ff822591b10c28 Mon Sep 17 00:00:00 2001 From: Patrick Gruber Date: Thu, 25 Jun 2020 14:27:55 +0200 Subject: [PATCH 06/10] implemented DOCUMENTS for interface --- .../Vault.Custom/addinVault/powerGateMain.ps1 | 1 - .../Events/ErpService.Lifecycle.ps1 | 6 +- Files/powerGate/Modules/Communication.psm1 | 2 +- .../powerGate/Modules/MaterialFunctions.psm1 | 1 + .../Implementation/ErpBomManager.cs | 1 - .../Implementation/ErpDocumentManager.cs | 49 +++++++++++-- .../Implementation/ErpItemManager.cs | 5 +- .../ErpManager/Implementation/ErpManager.cs | 6 +- .../ErpManager/Interfaces/IErpManager.cs | 7 +- .../ErpServices/Services/Documents.cs | 68 +++++-------------- .../powerGatePlugin/ErpServices/WebService.cs | 11 ++- .../powerJobs/Jobs/ErpService.Create.PDF.ps1 | 1 + .../Modules/Import.Shared.Modules.psm1 | 6 +- 13 files changed, 89 insertions(+), 75 deletions(-) diff --git a/Files/DataStandard/Vault.Custom/addinVault/powerGateMain.ps1 b/Files/DataStandard/Vault.Custom/addinVault/powerGateMain.ps1 index ccf63e9..50cdcea 100644 --- a/Files/DataStandard/Vault.Custom/addinVault/powerGateMain.ps1 +++ b/Files/DataStandard/Vault.Custom/addinVault/powerGateMain.ps1 @@ -34,7 +34,6 @@ function GetEntityNumber($entity) { else { $number = $entity._Number } - if ($number) { $number = $number.ToUpper() } return $number } diff --git a/Files/powerEvents/Events/ErpService.Lifecycle.ps1 b/Files/powerEvents/Events/ErpService.Lifecycle.ps1 index abd53eb..06290d9 100644 --- a/Files/powerEvents/Events/ErpService.Lifecycle.ps1 +++ b/Files/powerEvents/Events/ErpService.Lifecycle.ps1 @@ -22,7 +22,7 @@ function RestrictFileRelease($files) { $def = $defs | Where-Object { $_.DispName -eq $file._NewLifeCycleDefinition } $state = $def.StateArray | Where-Object { $_.DispName -eq $file._NewState } if ($state.ReleasedState) { - $material = Get-ERPObject -EntitySet "Materials" -Key @{"Number" = $file._PartNumber } + $material = GetErpMaterial -Number $file._PartNumber if ($null -eq $material) { $restrictMessage = "An item with the number '$($file._PartNumber)' does not exist in the ERP system." Log -Message $restrictMessage -LogLevel "ERROR" @@ -49,7 +49,7 @@ function RestrictItemRelease($items) { $def = $defs | Where-Object { $_.DispName -eq $item._NewLifeCycleDefinition } $state = $def.StateArray | Where-Object { $_.DispName -eq $item._NewState } if ($itemIncludesFilesToCheck -and $state.ReleasedState) { - $material = Get-ERPObject -EntitySet "Materials" -Key @{"Number" = $item._Number } + $material = GetErpMaterial -Number $item._Number if ($null -eq $material) { $restrictMessage = "An item with the number '$($item._Number)' does not exist in the ERP system." Log -Message $restrictMessage -LogLevel "ERROR" @@ -72,7 +72,7 @@ function AddPdfJob($files, $successful) { if(-not $successful) { return } $releasedFiles = @($files | Where-Object { $supportedPdfExtensions -contains $_._Extension -and $_._ReleasedRevision -eq $true }) foreach($file in $releasedFiles) { - $material = Get-ERPObject -EntitySet "Materials" -Key @{"Number" = $file._PartNumber } + $material = GetErpMaterial -Number $file._PartNumber if ($material) { $jobType = "ErpService.Create.PDF" Log -Message "Adding job '$jobType' for released file '$($file._Name)' to queue." diff --git a/Files/powerGate/Modules/Communication.psm1 b/Files/powerGate/Modules/Communication.psm1 index 1c98f45..8dab0e0 100644 --- a/Files/powerGate/Modules/Communication.psm1 +++ b/Files/powerGate/Modules/Communication.psm1 @@ -2,7 +2,7 @@ Import-Module powerGate #TODO: configure the powerGate server url and port -$powerGateServerName = "localhost" +$powerGateServerName = $ENV:Computername $powerGateServerPort = "8080" $powerGateServerErpPluginUrl = "http://$($powerGateServerName):$($powerGateServerPort)/coolOrange/ErpServices" diff --git a/Files/powerGate/Modules/MaterialFunctions.psm1 b/Files/powerGate/Modules/MaterialFunctions.psm1 index 754725d..c7ad729 100644 --- a/Files/powerGate/Modules/MaterialFunctions.psm1 +++ b/Files/powerGate/Modules/MaterialFunctions.psm1 @@ -8,6 +8,7 @@ function GetErpMaterial($number) { Add-Member -InputObject $erpMaterial -Name "_ErrorMessage" -Value "Number is empty!" -MemberType NoteProperty -Force return $erpMaterial } + $number = $number.ToUpper() $erpMaterial = Get-ERPObject -EntitySet $materialEntitySet -Key @{ Number = $number } $erpMaterial = CheckResponse -entity $erpMaterial diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpBomManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpBomManager.cs index 28d3ed5..dfa2608 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpBomManager.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpBomManager.cs @@ -8,7 +8,6 @@ namespace ErpServices.ErpManager.Implementation { public partial class ErpManager : IErpManager { - public BomHeader GetBomWithChildrenByNumber(string number) { return ExecuteOnDatabase(delegate(LiteDatabase database) diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpDocumentManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpDocumentManager.cs index 0f98078..c8f6c97 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpDocumentManager.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpDocumentManager.cs @@ -1,30 +1,69 @@ using System; using System.IO; +using System.Linq; +using System.ServiceModel.Web; using ErpServices.ErpManager.Interfaces; using ErpServices.Metadata; using LiteDB; +using powerGateServer.SDK; namespace ErpServices.ErpManager.Implementation { public partial class ErpManager : IErpManager { + public Document GetDocumentMetadata(string number) + { + return ExecuteOnDatabase(delegate (LiteDatabase database) + { + var document = database.GetCollection().Find(doc => doc.Number == number).FirstOrDefault(); + return document; + }); + + } public Document CreateDocumentMetadata(Document documentMetadata) { - throw new NotImplementedException(); + return ExecuteOnDatabase(delegate (LiteDatabase database) + { + database.GetCollection().Insert(documentMetadata); + return documentMetadata; + }); } - public Document UploadDocumentWithMetadata(MemoryStream fileStream, Document documentMetadata) + public IStream DownloadDocument(Document documentMetadata) { - throw new NotImplementedException(); + var fileLocation = Path.Combine(BinaryStorage.FullName, documentMetadata.Directory, documentMetadata.FileName); + if (WebOperationContext.Current != null) + WebOperationContext.Current.OutgoingResponse.Headers["Content-Disposition"] = $"filename={Path.GetFileName(fileLocation)}"; + return new powerGateServer.SDK.Streams.FileStream(fileLocation); + } + + public Document UploadDocumentWithMetadata(IStream stream, Document documentMetadata) + { + documentMetadata.Directory = Guid.NewGuid().ToString(); + var path = Path.Combine(BinaryStorage.FullName, documentMetadata.Directory); + if (!Directory.Exists(path)) + Directory.CreateDirectory(path); + + var fullFileName = Path.Combine(path, documentMetadata.FileName); + using (var fileStream = File.Create(fullFileName)) + { + stream.Source.CopyTo(fileStream); + } + + return CreateDocumentMetadata(documentMetadata); } public Document UpdateDocumentMetadata(Document documentMetadata) { - throw new NotImplementedException(); + return ExecuteOnDatabase(delegate (LiteDatabase database) + { + database.GetCollection().Update(documentMetadata); + return documentMetadata; + }); } - public Document UpdateDocumentWithMetadata(MemoryStream fileStream, Document documentMetadata) + public Document ChangeDocumentWithMetadata(IStream stream, Document documentMetadata) { throw new NotImplementedException(); } diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpItemManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpItemManager.cs index 71aa006..d04394a 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpItemManager.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpItemManager.cs @@ -1,16 +1,13 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using ErpServices.ErpManager.Interfaces; using ErpServices.Metadata; using LiteDB; -using powerGateServer.SDK; namespace ErpServices.ErpManager.Implementation { public partial class ErpManager : IErpManager { - public Material GetMaterialyByNumber(string number) { return ExecuteOnDatabase(database => database.GetCollection().Find(material => material.Number == number)).FirstOrDefault(); diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpManager.cs index 46fb2ba..3692549 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpManager.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpManager.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Linq; using System.Reflection; using ErpServices.ErpManager.Interfaces; @@ -10,6 +11,8 @@ namespace ErpServices.ErpManager.Implementation { public partial class ErpManager : IErpManager { + public DirectoryInfo BinaryStorage { get; } + static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -25,8 +28,9 @@ public bool IsConnected } } - public ErpManager() + public ErpManager(DirectoryInfo binaryStorage) { + BinaryStorage = binaryStorage; BsonMapper.Global.Entity().Id(x => x.Number); BsonMapper.Global.Entity().Id(x => x.Number); BsonMapper.Global.Entity().Id(x => x.Number); diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs index f1c630a..f2911d8 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using ErpServices.Metadata; +using powerGateServer.SDK; namespace ErpServices.ErpManager.Interfaces { @@ -19,10 +20,12 @@ public interface IErpManager : IDisposable Material UpdateMaterial(Material material); // Documents functionality + Document GetDocumentMetadata(string number); Document CreateDocumentMetadata(Document documentMetadata); - Document UploadDocumentWithMetadata(MemoryStream fileStream, Document documentMetadata); Document UpdateDocumentMetadata(Document documentMetadata); - Document UpdateDocumentWithMetadata(MemoryStream fileStream, Document documentMetadata); + Document UploadDocumentWithMetadata(IStream stream, Document documentMetadata); + IStream DownloadDocument(Document documentMetadata); + Document ChangeDocumentWithMetadata(IStream stream, Document documentMetadata); // BOM functionality BomHeader GetBomWithChildrenByNumber(string number); diff --git a/Files/powerGatePlugin/ErpServices/Services/Documents.cs b/Files/powerGatePlugin/ErpServices/Services/Documents.cs index 70a4062..4393806 100644 --- a/Files/powerGatePlugin/ErpServices/Services/Documents.cs +++ b/Files/powerGatePlugin/ErpServices/Services/Documents.cs @@ -1,14 +1,13 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Reflection; using System.ServiceModel.Web; using ErpServices.ErpManager.Interfaces; using ErpServices.Metadata; -using LiteDB; using log4net; using powerGateServer.SDK; +using powerGateServer.SDK.Helper; namespace ErpServices.Services { @@ -18,34 +17,24 @@ public class Documents : ErpBaseService, IStreamableServiceMethod "Documents"; - public Documents(string storeForBinaryFiles, IErpManager erpManager) : base(erpManager) + public Documents(IErpManager erpManager) : base(erpManager) { - } public override IEnumerable Query(IExpression expression) { - if (expression.Where.Any(b => b.PropertyName.Equals("Number"))) + if (expression.IsSimpleWhereToken()) { - var number = expression.Where.FirstOrDefault(w => w.PropertyName.Equals("Number")); - if (number != null && number.Value != number && number.Value.ToString() != "") - { - using (var db = new LiteDatabase(WebService.DatabaseFileLocation)) - { - return db.GetCollection() - .Find(x => x.Number.Equals(number.Value)) - .ToList(); - } - } - return null; + var number = expression.GetWhereValuesAsString("Number"); + Log.InfoFormat("Single query for document number {0}", number); + var document = ErpManager.GetDocumentMetadata(number); + if (document != null) + return new[] { document }; + return Enumerable.Empty(); } - using (var db = new LiteDatabase(WebService.DatabaseFileLocation)) - { - return db.GetCollection() - .FindAll() - .ToList(); - } + //var searchSettings = GetSearchSettings(expression); + throw new NotSupportedException("Searching ERP documents is not supported!"); } public override void Create(Document entity) @@ -54,11 +43,7 @@ public override void Create(Document entity) public override void Update(Document entity) { - using (var db = new LiteDatabase(WebService.DatabaseFileLocation)) - { - db.GetCollection() - .Update(entity); - } + ErpManager.UpdateDocumentMetadata(entity); } public override void Delete(Document entity) @@ -70,13 +55,8 @@ public IStream Download(Document entity) { if (WebOperationContext.Current != null) WebOperationContext.Current.OutgoingResponse.Headers.Add("Access-Control-Allow-Origin", "*"); - - var fileLocation = Path.Combine(WebService.FileStorageLocation, entity.Directory, entity.FileName); - - if (WebOperationContext.Current != null) - WebOperationContext.Current.OutgoingResponse.Headers["Content-Disposition"] = $"filename={Path.GetFileName(fileLocation)}"; - - return new powerGateServer.SDK.Streams.FileStream(fileLocation); + var fileStream = ErpManager.DownloadDocument(entity); + return fileStream; } public void Upload(Document entity, IStream stream) @@ -86,27 +66,11 @@ public void Upload(Document entity, IStream stream) try { - entity.Directory = Guid.NewGuid().ToString(); - var path = Path.Combine(WebService.FileStorageLocation, entity.Directory); - - if (!Directory.Exists(path)) - Directory.CreateDirectory(path); - - var fullFileName = Path.Combine(path, entity.FileName); - using (var fileStream = File.Create(fullFileName)) - { - stream.Source.CopyTo(fileStream); - } - - using (var db = new LiteDatabase(WebService.DatabaseFileLocation)) - { - db.GetCollection() - .Insert(entity); - } + ErpManager.UploadDocumentWithMetadata(stream, entity); } catch (Exception ex) { - Console.WriteLine(ex); + Log.Error(ex); throw; } } diff --git a/Files/powerGatePlugin/ErpServices/WebService.cs b/Files/powerGatePlugin/ErpServices/WebService.cs index 50391f9..d9b1c21 100644 --- a/Files/powerGatePlugin/ErpServices/WebService.cs +++ b/Files/powerGatePlugin/ErpServices/WebService.cs @@ -1,5 +1,6 @@ using System; using System.Configuration; +using System.IO; using System.Reflection; using ErpServices.ErpManager.Interfaces; using ErpServices.Services; @@ -19,7 +20,11 @@ public class WebService : powerGateServer.SDK.WebService public WebService() { var erpStorageConfiguration = GetErpStorageConfiguration(); - var erpManager = new ErpManager.Implementation.ErpManager(); + + var storeForBinaryFiles = erpStorageConfiguration.Settings["DatabaseFileLocation"].Value; + var binaryStoreDirectory = new DirectoryInfo(storeForBinaryFiles); + + var erpManager = new ErpManager.Implementation.ErpManager(binaryStoreDirectory); var erpLogin = new ErpLogin { ConnectionString = erpStorageConfiguration.Settings["FileStorageLocation"].Value, @@ -35,8 +40,8 @@ public WebService() AddMethod(new BomHeaders(erpManager)); AddMethod(new BomRows(erpManager)); - var storeForBinaryFiles = erpStorageConfiguration.Settings["DatabaseFileLocation"].Value; - AddMethod(new Documents(storeForBinaryFiles, erpManager)); + + AddMethod(new Documents(erpManager)); } AppSettingsSection GetErpStorageConfiguration() diff --git a/Files/powerJobs/Jobs/ErpService.Create.PDF.ps1 b/Files/powerJobs/Jobs/ErpService.Create.PDF.ps1 index cbc5453..f475c3c 100644 --- a/Files/powerJobs/Jobs/ErpService.Create.PDF.ps1 +++ b/Files/powerJobs/Jobs/ErpService.Create.PDF.ps1 @@ -10,6 +10,7 @@ #=============================================================================# $global:loggingSettings.LogFile = Join-Path $env:LOCALAPPDATA "coolOrange\Projects\ErpService.Create.Pdf-Job.txt" +Write-Host "Set new logging file: $($global:loggingSettings.LogFile)" $hidePDF = $false $workingDirectory = "C:\Temp\$($file._Name)" diff --git a/Files/powerJobs/Modules/Import.Shared.Modules.psm1 b/Files/powerJobs/Modules/Import.Shared.Modules.psm1 index e13916a..33d1bad 100644 --- a/Files/powerJobs/Modules/Import.Shared.Modules.psm1 +++ b/Files/powerJobs/Modules/Import.Shared.Modules.psm1 @@ -1,7 +1,9 @@ -Get-ChildItem -LiteralPath 'C:\ProgramData\coolOrange\Modules\' -File -Recurse -Force -Filter '*.ps*' | ` +Get-ChildItem -LiteralPath 'C:\ProgramData\coolOrange\powerGate\Modules\' -File -Recurse -Force -Filter '*.ps*' | ` ForEach-Object { + Write-Host "Import shared module $($_.FullName)" Import-Module $_.FullName -Global -Force -DisableNameChecking } $global:loggingSettings.LogFile = Join-Path $env:LOCALAPPDATA "coolOrange\Projects\powerJobs.txt" -$global:loggingSettings.WriteHost = $true \ No newline at end of file +$global:loggingSettings.WriteHost = $true +Write-Host "Initialized logging to file: $($global:loggingSettings.LogFile)" \ No newline at end of file From 99c2468afa34659571c3d45a8a79c4cfb321406c Mon Sep 17 00:00:00 2001 From: Patrick Gruber Date: Thu, 25 Jun 2020 14:36:00 +0200 Subject: [PATCH 07/10] fixed namespaces --- .../ErpManager/Implementation/ErpManager.cs | 1 - .../ErpServices/ErpManager/Interfaces/IErpManager.cs | 2 -- .../ErpServices/Services/ErpBaseService.cs | 3 --- Files/powerGatePlugin/ErpServices/WebService.cs | 10 +++------- 4 files changed, 3 insertions(+), 13 deletions(-) diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpManager.cs index 3692549..47c3ff2 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpManager.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Implementation/ErpManager.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using System.Linq; using System.Reflection; using ErpServices.ErpManager.Interfaces; using ErpServices.Metadata; diff --git a/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs b/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs index f2911d8..4c8a5e8 100644 --- a/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs +++ b/Files/powerGatePlugin/ErpServices/ErpManager/Interfaces/IErpManager.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.IO; using ErpServices.Metadata; using powerGateServer.SDK; @@ -8,7 +7,6 @@ namespace ErpServices.ErpManager.Interfaces { public interface IErpManager : IDisposable { - ErpLogin Login { get; } bool IsConnected { get; } bool Connect(ErpLogin login); diff --git a/Files/powerGatePlugin/ErpServices/Services/ErpBaseService.cs b/Files/powerGatePlugin/ErpServices/Services/ErpBaseService.cs index 4c337ba..83431c6 100644 --- a/Files/powerGatePlugin/ErpServices/Services/ErpBaseService.cs +++ b/Files/powerGatePlugin/ErpServices/Services/ErpBaseService.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Reflection; using ErpServices.ErpManager.Interfaces; -using ErpServices.Metadata; using log4net; using powerGateServer.SDK; using powerGateServer.SDK.Helper; @@ -21,7 +20,6 @@ protected ErpBaseService(IErpManager erpManager) ErpManager = erpManager; } - protected IEnumerable GetSearchSettings(IExpression expression) { var query = new List(); @@ -44,6 +42,5 @@ protected IEnumerable GetSearchSettings(IExpression Date: Mon, 1 Feb 2021 09:44:16 +0100 Subject: [PATCH 08/10] fixed merging for "GetSelectedObject" --- .../Vault.Custom/addinVault/powerGateMain.ps1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Files/DataStandard/Vault.Custom/addinVault/powerGateMain.ps1 b/Files/DataStandard/Vault.Custom/addinVault/powerGateMain.ps1 index 1433967..967b698 100644 --- a/Files/DataStandard/Vault.Custom/addinVault/powerGateMain.ps1 +++ b/Files/DataStandard/Vault.Custom/addinVault/powerGateMain.ps1 @@ -23,7 +23,13 @@ function GetSelectedObject { if (-not $selectedObject) { $selectedObject = $VaultContext.CurrentSelectionSet | Select-Object -First 1 } - return $number + if ($selectedObject.TypeId.SelectionContext -eq "FileMaster") { + $entity = Get-VaultFile -FileId $selectedObject.Id + } + elseif ($selectedObject.TypeId.SelectionContext -eq "ItemMaster") { + $entity = Get-VaultItem -ItemId $selectedObject.Id + } + return $entity } function RefreshView { From f0c61308aeb3718b785c046ced5a34e809618460 Mon Sep 17 00:00:00 2001 From: Patrick Gruber Date: Mon, 1 Feb 2021 09:45:42 +0100 Subject: [PATCH 09/10] Fixed merging for "RefreshView" --- .../Vault.Custom/addinVault/powerGateMain.ps1 | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Files/DataStandard/Vault.Custom/addinVault/powerGateMain.ps1 b/Files/DataStandard/Vault.Custom/addinVault/powerGateMain.ps1 index 967b698..1612cbc 100644 --- a/Files/DataStandard/Vault.Custom/addinVault/powerGateMain.ps1 +++ b/Files/DataStandard/Vault.Custom/addinVault/powerGateMain.ps1 @@ -32,17 +32,6 @@ function GetSelectedObject { return $entity } -function RefreshView { - $entity = GetSelectedObject - if ($null -eq $entity) { - return - } - elseif ($selectedObject.TypeId.SelectionContext -eq "ItemMaster") { - $entity = Get-VaultItem -ItemId $selectedObject.Id - } - return $entity -} - function InitBomTab { $entity = GetSelectedObject $number = GetEntityNumber -entity $entity From e352696c2ba9a9aad0282ed0f4829e16c7792244 Mon Sep 17 00:00:00 2001 From: Patrick Gruber Date: Mon, 1 Feb 2021 09:47:39 +0100 Subject: [PATCH 10/10] fixed merging for powerEvents --- .../Events/ErpService.Lifecycle.ps1 | 101 ++++++++---------- 1 file changed, 46 insertions(+), 55 deletions(-) diff --git a/Files/powerEvents/Events/ErpService.Lifecycle.ps1 b/Files/powerEvents/Events/ErpService.Lifecycle.ps1 index 3f4842b..3489084 100644 --- a/Files/powerEvents/Events/ErpService.Lifecycle.ps1 +++ b/Files/powerEvents/Events/ErpService.Lifecycle.ps1 @@ -76,65 +76,56 @@ function RestrictItemRelease($items) { $def = $defs | Where-Object { $_.DispName -eq $item._NewLifeCycleDefinition } $state = $def.StateArray | Where-Object { $_.DispName -eq $item._NewState } if ($itemIncludesFilesToCheck -and $state.ReleasedState) { - <<<<<<< HEAD - $material = GetErpMaterial -Number $item._Number - if ($null -eq $material) { - ======= - $erpMaterial = GetErpMaterial -Number $item._Number - if (-not $erpMaterial -or $false -eq $erpMaterial) { - >>>>>>> master - $restrictMessage = "An item with the number '$($item._Number)' does not exist in the ERP system." - Add-VaultRestriction -EntityName ($item._Name) -Message $restrictMessage - continue - } + $erpMaterial = GetErpMaterial -Number $item._Number + if (-not $erpMaterial -or $false -eq $erpMaterial) { + $restrictMessage = "An item with the number '$($item._Number)' does not exist in the ERP system." + Add-VaultRestriction -EntityName ($item._Name) -Message $restrictMessage + continue + } - $bomRows = GetVaultBomRows -Entity $item - if (-not $bomRows) { continue } + $bomRows = GetVaultBomRows -Entity $item + if (-not $bomRows) { continue } - if (-not $item.Children) { - Add-Member -InputObject $item -Name "Children" -Value $bomRows -MemberType NoteProperty -Force - } - else { - $item.Children = $bomRows - } + if (-not $item.Children) { + Add-Member -InputObject $item -Name "Children" -Value $bomRows -MemberType NoteProperty -Force + } + else { + $item.Children = $bomRows + } - try { - CheckVaultBom $item | Out-Null - } - catch { - $restrictMessage = "$($_)! Please open the BOM dialog" - Add-VaultRestriction -EntityName $item._Number -Message $restrictMessage - } + try { + CheckVaultBom $item | Out-Null } - } - } - catch { - Log -Message $_.Exception.Message -MessageBox -LogLevel "ERROR" - } - Log -End + catch { + $restrictMessage = "$($_)! Please open the BOM dialog" + Add-VaultRestriction -EntityName $item._Number -Message $restrictMessage + } + } + } } + catch { + Log -Message $_.Exception.Message -MessageBox -LogLevel "ERROR" + } + Log -End +} - Register-VaultEvent -EventName UpdateFileStates_Post -Action 'AddPdfJob' - function AddPdfJob($files, $successful) { - Log -Begin - try { - if (-not $successful) { return } - $releasedFiles = @($files | Where-Object { $supportedPdfExtensions -contains $_._Extension -and $_._ReleasedRevision -eq $true }) - foreach ($file in $releasedFiles) { - $material = GetErpMaterial -Number $file._PartNumber - <<<<<<< HEAD - if ($material) { - ======= - if ($false -ne $material -and $material) { - >>>>>>> master - $jobType = "ErpService.Create.PDF" - Log -Message "Adding job '$jobType' for file '$($file._Name)' to queue." - Add-VaultJob -Name $jobType -Parameters @{ "EntityId" = $file.Id; "EntityClassId" = "FILE" } -Description "Create PDF for file '$($file._Name)' and upload to ERP system" - } - } - } - catch { - Log -Message $_.Exception.Message -MessageBox +Register-VaultEvent -EventName UpdateFileStates_Post -Action 'AddPdfJob' +function AddPdfJob($files, $successful) { + Log -Begin + try { + if (-not $successful) { return } + $releasedFiles = @($files | Where-Object { $supportedPdfExtensions -contains $_._Extension -and $_._ReleasedRevision -eq $true }) + foreach ($file in $releasedFiles) { + $material = GetErpMaterial -Number $file._PartNumber + if ($false -ne $material -and $material) { + $jobType = "ErpService.Create.PDF" + Log -Message "Adding job '$jobType' for file '$($file._Name)' to queue." + Add-VaultJob -Name $jobType -Parameters @{ "EntityId" = $file.Id; "EntityClassId" = "FILE" } -Description "Create PDF for file '$($file._Name)' and upload to ERP system" } - Log -End - } \ No newline at end of file + } + } + catch { + Log -Message $_.Exception.Message -MessageBox + } + Log -End +} \ No newline at end of file