Skip to content

Commit 375ab86

Browse files
authored
Merge pull request #673 from kevinvenclovas/main
2 parents 4a686f8 + 23add86 commit 375ab86

File tree

4 files changed

+53
-31
lines changed

4 files changed

+53
-31
lines changed

Source/FikaAmazonAPI/AmazonConnection.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using FikaAmazonAPI.Services;
33
using FikaAmazonAPI.Utils;
44
using System;
5+
using System.Globalization;
6+
using System.Threading;
57

68
namespace FikaAmazonAPI
79
{
@@ -84,10 +86,11 @@ public class AmazonConnection
8486
private UnauthorizedAccessException _NoCredentials = new UnauthorizedAccessException($"Error, you cannot make calls to Amazon without credentials!");
8587

8688
public string RefNumber { get; set; }
87-
public AmazonConnection(AmazonCredential Credentials, string RefNumber = null)
89+
public AmazonConnection(AmazonCredential Credentials, string RefNumber = null, CultureInfo? cultureInfo = null)
8890
{
8991
this.Authenticate(Credentials);
9092
this.RefNumber = RefNumber;
93+
Thread.CurrentThread.CurrentCulture = cultureInfo ?? CultureInfo.InvariantCulture;
9194
}
9295

9396
private void Authenticate(AmazonCredential Credentials)

Source/FikaAmazonAPI/ReportGeneration/DataConverter.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ public static class DateTimeFormat
1616
public const string DATE_AGING_FORMAT = "yyyy-MM-dd";
1717
public const string DATE_LEDGER_FORMAT = "MM/dd/yyyy";
1818
}
19+
20+
public static CultureInfo DataConverterCultureInfo = CultureInfo.CurrentCulture;
21+
1922
public static DateTime? GetDate(string str, string format)
2023
{
2124
if (DateTime.TryParseExact(str, format,
22-
System.Globalization.CultureInfo.InvariantCulture,
25+
DataConverterCultureInfo,
2326
System.Globalization.DateTimeStyles.None,
2427
out DateTime value))
2528
{
@@ -29,23 +32,23 @@ public static class DateTimeFormat
2932
}
3033
public static decimal? GetDecimal(string str)
3134
{
32-
if (decimal.TryParse(str, NumberStyles.Any, CultureInfo.InvariantCulture, out decimal value))
35+
if (decimal.TryParse(str, NumberStyles.Any, DataConverterCultureInfo, out decimal value))
3336
{
3437
return value;
3538
}
3639
return null;
3740
}
3841
public static int? GetInt(string str)
3942
{
40-
if (int.TryParse(str, NumberStyles.Integer, CultureInfo.InvariantCulture, out int value))
43+
if (int.TryParse(str, NumberStyles.Integer, DataConverterCultureInfo, out int value))
4144
{
4245
return value;
4346
}
4447
return null;
4548
}
4649
public static double? GetDouble(string str)
4750
{
48-
if (double.TryParse(str, NumberStyles.Any, CultureInfo.InvariantCulture, out double value))
51+
if (double.TryParse(str, NumberStyles.Any, DataConverterCultureInfo, out double value))
4952
{
5053
return value;
5154
}

Source/FikaAmazonAPI/ReportGeneration/SettlementOrderReport.cs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using System;
1+
using FikaAmazonAPI.AmazonSpApiSDK.Models.Finances;
2+
using FikaAmazonAPI.Utils;
3+
using Newtonsoft.Json.Linq;
4+
using System;
25
using System.Collections.Generic;
36
using System.IO;
47
using System.Linq;
@@ -53,34 +56,33 @@ public static SettlementOrderRow FromCsv(string csvLine, string refNumber)
5356
{
5457
string[] values = csvLine.Split('\t');
5558
var row = new SettlementOrderRow();
56-
row.SettlementId = values[0];
57-
row.SettlementStartDate = DataConverter.GetDate(values[1], DataConverter.DateTimeFormat.DATETIME_FORMAT_UTC_DOT);
58-
row.SettlementEndDate = DataConverter.GetDate(values[2], DataConverter.DateTimeFormat.DATETIME_FORMAT_UTC_DOT);
59-
row.DepositDate = DataConverter.GetDate(values[3], DataConverter.DateTimeFormat.DATETIME_FORMAT_UTC_DOT);
60-
row.TotalAmount = DataConverter.GetDecimal(values[4]);
61-
row.Currency = values[5];
62-
row.TransactionType = values[6];
63-
row.OrderId = values[7];
64-
row.MerchantOrderId = values[8];
65-
row.AdjustmentId = values[9];
66-
row.ShipmentId = values[10];
67-
row.MarketplaceName = values[11];
68-
row.AmountType = values[12];
69-
row.AmountDescription = values[13];
70-
row.Amount = DataConverter.GetDecimal(values[14]);
71-
row.FulfillmentId = values[15];
72-
row.PostedDate = DataConverter.GetDate(values[16], DataConverter.DateTimeFormat.DATE_FORMAT_DOT);
73-
row.PostedDateTime = DataConverter.GetDate(values[17], DataConverter.DateTimeFormat.DATETIME_FORMAT_UTC_DOT);
74-
row.OrderItemCode = values[18];
75-
row.MerchantOrderItemId = values[19];
76-
row.MerchantAdjustmentItemId = values[20];
77-
row.SKU = values[21];
59+
row.SettlementId = values.GetElementAtIndexOrDefault(0);
60+
row.SettlementStartDate = DataConverter.GetDate(values.GetElementAtIndexOrDefault(1), DataConverter.DateTimeFormat.DATETIME_FORMAT_UTC_DOT);
61+
row.SettlementEndDate = DataConverter.GetDate(values.GetElementAtIndexOrDefault(2), DataConverter.DateTimeFormat.DATETIME_FORMAT_UTC_DOT);
62+
row.DepositDate = DataConverter.GetDate(values.GetElementAtIndexOrDefault(3), DataConverter.DateTimeFormat.DATETIME_FORMAT_UTC_DOT);
63+
row.TotalAmount = DataConverter.GetDecimal(values.GetElementAtIndexOrDefault(4));
64+
row.Currency = values.GetElementAtIndexOrDefault(5);
65+
row.TransactionType = values.GetElementAtIndexOrDefault(6);
66+
row.OrderId = values.GetElementAtIndexOrDefault(7);
67+
row.MerchantOrderId = values.GetElementAtIndexOrDefault(8);
68+
row.AdjustmentId = values.GetElementAtIndexOrDefault(9);
69+
row.ShipmentId = values.GetElementAtIndexOrDefault(10);
70+
row.MarketplaceName = values.GetElementAtIndexOrDefault(11);
71+
row.AmountType = values.GetElementAtIndexOrDefault(12);
72+
row.AmountDescription = values.GetElementAtIndexOrDefault(13);
73+
row.Amount = DataConverter.GetDecimal(values.GetElementAtIndexOrDefault(14));
74+
row.FulfillmentId = values.GetElementAtIndexOrDefault(15);
75+
row.PostedDate = DataConverter.GetDate(values.GetElementAtIndexOrDefault(16), DataConverter.DateTimeFormat.DATE_FORMAT_DOT);
76+
row.PostedDateTime = DataConverter.GetDate(values.GetElementAtIndexOrDefault(17), DataConverter.DateTimeFormat.DATETIME_FORMAT_UTC_DOT);
77+
row.OrderItemCode = values.GetElementAtIndexOrDefault(18);
78+
row.MerchantOrderItemId = values.GetElementAtIndexOrDefault(19);
79+
row.MerchantAdjustmentItemId = values.GetElementAtIndexOrDefault(20);
80+
row.SKU = values.GetElementAtIndexOrDefault(21);
7881
row.QuantityPurchased = DataConverter.GetInt(values[22]);
79-
row.PromotionId = values[23];
82+
row.PromotionId = values.GetElementAtIndexOrDefault(23);
8083

8184
row.refNumber = refNumber;
8285

83-
8486
return row;
8587
}
8688
}

Source/FikaAmazonAPI/Utils/Listing.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
4+
using System.Reflection;
35

46
namespace FikaAmazonAPI.Utils
57
{
@@ -18,5 +20,17 @@ public static IList<IList<T>> Slice<T>(IList<T> list, int number)
1820
}
1921
return objListList;
2022
}
23+
24+
public static string GetElementAtIndexOrDefault(this object[] array, int index)
25+
{
26+
if (index >= 0 && index < array.Length)
27+
{
28+
return array[index].ToString();
29+
}
30+
else
31+
{
32+
return null;
33+
}
34+
}
2135
}
2236
}

0 commit comments

Comments
 (0)