Browse Source

Finishing of MYOBPosterEngine

Kenric Nugteren 1 year ago
parent
commit
9a1df4cb87

+ 7 - 0
InABox.Core/Postable/PostResult.cs

@@ -48,8 +48,15 @@ namespace InABox.Core
         public void AddFragment<TPostableFragment>(TPostableFragment fragment, PostedStatus status)
             where TPostableFragment : IPostableFragment<TPostable>, IPostable
         {
+            var type = fragment.GetType();
+            if (!fragments.TryGetValue(type, out var fragmentsList))
+            {
+                fragmentsList = new List<IPostableFragment<TPostable>>();
+                fragments[type] = fragmentsList;
+            }
             fragment.Post();
             fragment.PostedStatus = status;
+            fragmentsList.Add(fragment);
         }
 
         public void AddFragment(IPostableFragment<TPostable> fragment)

+ 1 - 1
InABox.Poster.MYOB/MYOBPosterEngine.cs

@@ -217,7 +217,7 @@ public abstract class MYOBPosterEngine<TPostable, TSettings> :
             var fileCredentials = new CompanyFileCredentials(globalSettings.CompanyFileUserID, globalSettings.CompanyFilePassword);
             data.CompanyFile = companyFile;
             data.CompanyFileCredentials = fileCredentials;
-            data.ActiveCompanyFile = data.CompanyFileService.Get(companyFile, fileCredentials);
+            // data.ActiveCompanyFile = data.CompanyFileService.Get(companyFile, fileCredentials);
         }
         Poster.ConnectionData = data;
 

+ 13 - 1
InABox.Poster.MYOB/MYOBPosterUtils.cs

@@ -8,6 +8,7 @@ using MYOB.AccountRight.SDK.Services.GeneralLedger;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Reflection;
 using System.Text;
 using System.Threading.Tasks;
 using MYOBBaseEntity = MYOB.AccountRight.SDK.Contracts.Version2.BaseEntity;
@@ -153,7 +154,7 @@ public static class MYOBPosterUtils
 
     public static string FormatApiException(ApiCommunicationException e)
     {
-        if(e.Errors.Count > 0)
+        if(e.Errors is not null && e.Errors.Count > 0)
         {
             var message = string.Join('\n', e.Errors.Select(x =>
             {
@@ -219,6 +220,17 @@ public static class MYOBPosterUtils
                 throw new PostCancelledException();
             }
         }
+        catch(TargetInvocationException e)
+        {
+            if(e.InnerException is not null)
+            {
+                return Result.Error(e.InnerException);
+            }
+            else
+            {
+                return Result.Error<Exception>(e);
+            }
+        }
         catch(Exception e)
         {
             return Result.Error(e);