예제 #1
0
        static async Task MainCoreAsync(string[] args)
        {
            var sw = Stopwatch.StartNew();

            // Apply initial settings
            ApplyInitialConfiguration();

            // Validate argumanges
            LogTitle("Start : Evaluate Arguments. Override with EnvironmentVariables if missing argument.");
            EvaluateArguments(args);

            // Set UploadCallback
            if (!Silent)
            {
                // アップロード時のコールバック登録
                UploadCallback = e => Log($"{e.PercentDone}%, {e.FilePath}, {nameof(KeyPrefix)} : {KeyPrefix}, {e}");
            }

            // Obtain local files
            LogTitle("Start : Obtain Local items.");
            var localFileInfos = new EnumerableFileSystem(ExcludeDirectories, ExcludeFiles)
                                 .EnumerateFiles(LocalRoot)
                                 .ToArray();

            var obtainLocal = sw.Elapsed;

            Log($@"Complete : Obtain Local items.", obtainLocal);
            sw.Restart();

            // Get Credential
            // Missing CredentialProfile : Use IAM Instance Profile
            // Found CredentialProfile : Use as ProfileName
            LogTitle("Start : Obtain credential");
            var s3 = string.IsNullOrEmpty(CredentialProfile)
                ? new S3Client(Option)
                : new S3Client(Option, AmazonCredential.GetCredential(CredentialProfile));

            // Begin Synchronization
            LogTitle("Start : Synchronization");
            var result = await s3.SyncWithLocal(localFileInfos, BucketName, KeyPrefix, IgnoreKeyPrefix, UploadCallback);

            // Show result
            LogTitle($@"Show : Synchronization result as follows.");
            Warn(result.ToMarkdown());
            var synchronization = sw.Elapsed;

            Log($@"Complete : Synchronization.", synchronization);

            // Total result
            Log($@"Total :", (obtainLocal + synchronization));
        }
예제 #2
0
        public FeedSubmissionInfo SubmitFeed(EFeedType FeedType, string FeedContent, bool PurgeAndReplace)
        {
            switch (PurgeAndReplace)
            {
            case true:
                this.Throttle(ERequestType.SubmitFeedPurgeAndReplace);
                break;

            case false:
                this.Throttle();
                break;
            }

            AmazonCredential            Credentials = this.GetCredential();
            MarketplaceWebServiceClient Client      = this.GetClient(Credentials);
            SubmitFeedRequest           Request     = new SubmitFeedRequest()
            {
                Merchant        = Credentials.MerchantID,
                FeedType        = EnumStringHandler.GetEnumString <EFeedType>(FeedType),
                FeedContent     = new MemoryStream(Encoding.ASCII.GetBytes(FeedContent)),
                PurgeAndReplace = PurgeAndReplace
            };
            SubmitFeedResponse Response = Client.SubmitFeed(Request);

            if (Response.IsSetSubmitFeedResult())
            {
                SubmitFeedResult Result = Response.SubmitFeedResult;
                if (Result.IsSetFeedSubmissionInfo())
                {
                    return(Result.FeedSubmissionInfo);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
예제 #3
0
        public ReportRequestInfo RequestReport(EReportType ReportType, DateTime StartDate, DateTime EndDate)
        {
            this.Throttle();
            AmazonCredential            Credentials = this.GetCredential();
            MarketplaceWebServiceClient Client      = this.GetClient(Credentials);

            RequestReportRequest Request = new RequestReportRequest()
            {
                Merchant   = Credentials.MerchantID,
                ReportType = EnumStringHandler.GetEnumString <EReportType>(ReportType)
            };

            if (StartDate != default(DateTime))
            {
                Request.StartDate = StartDate;
            }
            if (EndDate != default(DateTime))
            {
                Request.EndDate = EndDate;
            }

            RequestReportResponse Response = Client.RequestReport(Request);

            if (Response.IsSetRequestReportResult())
            {
                RequestReportResult Result = Response.RequestReportResult;
                if (Result.IsSetReportRequestInfo())
                {
                    return(Result.ReportRequestInfo);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
예제 #4
0
        public Stream GetReport(string ReportId)
        {
            this.Throttle();
            AmazonCredential            Credentials = this.GetCredential();
            MarketplaceWebServiceClient Client      = this.GetClient(Credentials);
            MemoryStream     ReportStream           = new MemoryStream();
            GetReportRequest Request = new GetReportRequest()
            {
                Merchant = Credentials.MerchantID,
                ReportId = ReportId,
                Report   = ReportStream
            };
            GetReportResponse Response = Client.GetReport(Request);

            if (Response.IsSetGetReportResult())
            {
                return(ReportStream);
            }
            else
            {
                return(null);
            }
        }
예제 #5
0
        private Credential convertToModel(credential credential)
        {
            Credential model = null;

            if (credential is amazoncredential)
            {
                var item = credential as amazoncredential;
                model = new AmazonCredential
                {
                    AccessKeyId       = item.AccessKeyId,
                    AssociateId       = item.AssociateId,
                    CompanyId         = item.CompanyId,
                    Id                = item.Id,
                    IsDefault         = item.IsDefault,
                    IsEnabled         = item.IsEnabled,
                    MarketplaceId     = item.MarketplaceId,
                    MarketplaceType   = item.MarketplaceType,
                    MerchantId        = item.MerchantId,
                    Mode              = item.Mode,
                    Name              = item.Name,
                    SearchAccessKeyId = item.SearchAccessKeyId,
                    SearchSecretKey   = item.SearchSecretKey,
                    SecretKey         = item.SecretKey,
                    ServiceEndPoint   = item.ServiceEndPoint
                };
            }
            else if (credential is ebaycredential)
            {
                var item = credential as ebaycredential;
                model = new eBayCredential
                {
                    ApplicationId   = item.ApplicationId,
                    DeveloperId     = item.DeveloperId,
                    CertificationId = item.CertificationId,
                    UserToken       = item.UserToken,
                    CompanyId       = item.CompanyId,
                    Id              = item.Id,
                    IsDefault       = item.IsDefault,
                    IsEnabled       = item.IsEnabled,
                    MarketplaceId   = item.MarketplaceId,
                    MarketplaceType = item.MarketplaceType,
                    Mode            = item.Mode,
                    Name            = item.Name,
                    ServiceEndPoint = item.ServiceEndPoint
                };
            }
            else if (credential is bigcommercecredential)
            {
                var item = credential as bigcommercecredential;
                model = new BigCommerceCredential
                {
                    Username        = item.Username,
                    ApiKey          = item.ApiKey,
                    CompanyId       = item.CompanyId,
                    Id              = item.Id,
                    IsDefault       = item.IsDefault,
                    IsEnabled       = item.IsEnabled,
                    MarketplaceId   = item.MarketplaceId,
                    MarketplaceType = item.MarketplaceType,
                    Mode            = item.Mode,
                    Name            = item.Name,
                    ServiceEndPoint = item.ServiceEndPoint
                };
            }
            else
            {
                throw new InvalidCastException(string.Format("Unknown credential type \'{0}\' for casting!", credential.MarketplaceType));
            }

            return(model);
        }
예제 #6
0
        private Order[] ListOrders(DateTime CreatedAfter, DateTime CreatedBefore, DateTime LastUpdatedAfter, DateTime LastUpdatedBefore, EOrderStatus[] OrderStatus)
        {
            string           NextToken               = string.Empty;
            AmazonCredential Credentials             = this.GetCredential();
            MarketplaceWebServiceOrdersClient Client = this.GetClient(Credentials);
            ListOrdersRequest Request = new ListOrdersRequest()
            {
                SellerId      = Credentials.SellerID,
                MarketplaceId = new List <string>()
                {
                    Credentials.MarketplaceID
                },
            };

            if (CreatedAfter != default(DateTime) && CreatedBefore != default(DateTime))
            {
                Request.CreatedAfter  = CreatedAfter;
                Request.CreatedBefore = CreatedBefore;
            }
            if (LastUpdatedAfter != default(DateTime) && LastUpdatedBefore != default(DateTime))
            {
                Request.LastUpdatedAfter  = LastUpdatedAfter;
                Request.LastUpdatedBefore = LastUpdatedBefore;
            }
            if (OrderStatus != null)
            {
                Request.OrderStatus = OrderStatus.Select(Item => Item.ToString()).ToList();
            }

            List <Order> Orders         = new List <Order>();
            Task         ListOrdersTask = new Task(() =>
            {
                while (true)
                {
                    switch (string.IsNullOrWhiteSpace(NextToken))
                    {
                    case true:
                        this.Throttle(ERequestType.ListOrders);
                        ListOrdersResponse Response = Client.ListOrders(Request);
                        if (Response.IsSetListOrdersResult())
                        {
                            ListOrdersResult Result = Response.ListOrdersResult;
                            if (Result.IsSetOrders())
                            {
                                foreach (var Order in Result.Orders)
                                {
                                    Orders.Add(Order);
                                }
                            }

                            if (Result.IsSetNextToken())
                            {
                                NextToken = Result.NextToken;
                            }
                            else
                            {
                                goto EndOfLoop;
                            }
                        }
                        break;

                    case false:
                        this.Throttle(ERequestType.ListOrders);
                        ListOrdersByNextTokenRequest RequestNextToken = new ListOrdersByNextTokenRequest()
                        {
                            SellerId  = Credentials.SellerID,
                            NextToken = NextToken
                        };
                        ListOrdersByNextTokenResponse ResponseNextToken = Client.ListOrdersByNextToken(RequestNextToken);
                        if (ResponseNextToken.IsSetListOrdersByNextTokenResult())
                        {
                            ListOrdersByNextTokenResult ResultNextToken = ResponseNextToken.ListOrdersByNextTokenResult;
                            if (ResultNextToken.IsSetOrders())
                            {
                                foreach (var Order in ResultNextToken.Orders)
                                {
                                    Orders.Add(Order);
                                }
                            }

                            if (ResultNextToken.IsSetNextToken())
                            {
                                NextToken = ResultNextToken.NextToken;
                            }
                            else
                            {
                                goto EndOfLoop;
                            }
                        }
                        break;
                    }
                }
                EndOfLoop:
                Console.Write("");
            });

            ListOrdersTask.Start();
            ListOrdersTask.Wait((int)Math.Ceiling(TimeSpan.FromMinutes(Definitions.Timeout_Minutes).Add(TimeSpan.FromHours(Definitions.Timeout_Hours)).TotalMilliseconds));
            return(Orders.ToArray());
        }
예제 #7
0
        private FeedSubmissionInfo[] CancelFeedSubmissions(string[] FeedSubmissionIds, EFeedType[] FeedTypeList, DateTime SubmittedFromDate, DateTime SubmittedToDate)
        {
            this.Throttle();
            AmazonCredential             Credentials = this.GetCredential();
            MarketplaceWebServiceClient  Client      = this.GetClient(Credentials);
            CancelFeedSubmissionsRequest Request     = default(CancelFeedSubmissionsRequest);

            if (FeedSubmissionIds != null)
            {
                Request = new CancelFeedSubmissionsRequest()
                {
                    Merchant             = Credentials.MerchantID,
                    FeedSubmissionIdList = new IdList()
                    {
                        Id = FeedSubmissionIds.ToList()
                    }
                }
            }
            ;
            else if (FeedTypeList != null)
            {
                Request = new CancelFeedSubmissionsRequest()
                {
                    Merchant     = Credentials.MerchantID,
                    FeedTypeList = new TypeList()
                    {
                        Type = FeedTypeList.Select(Item => EnumStringHandler.GetEnumString <EFeedType>(Item)).ToList()
                    }
                }
            }
            ;
            else if (SubmittedFromDate != default(DateTime) && SubmittedFromDate != default(DateTime))
            {
                Request = new CancelFeedSubmissionsRequest()
                {
                    Merchant          = Credentials.MerchantID,
                    SubmittedFromDate = SubmittedFromDate,
                    SubmittedToDate   = SubmittedToDate
                }
            }
            ;
            else
            {
                throw new ArgumentException("Error, invalid arguments provided!");
            }
            CancelFeedSubmissionsResponse Response = Client.CancelFeedSubmissions(Request);

            if (Response.IsSetCancelFeedSubmissionsResult())
            {
                CancelFeedSubmissionsResult Result = Response.CancelFeedSubmissionsResult;
                if (Result.IsSetCount())
                {
                    if (Result.Count > 0)
                    {
                        Console.WriteLine($"Successfully canceled [{Result.Count}] feeds!");
                    }
                }

                if (Result.IsSetFeedSubmissionInfo())
                {
                    return(Result.FeedSubmissionInfo.ToArray());
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
예제 #8
0
        private FeedSubmissionInfo[] _GetFeedSubmissionList(string[] FeedSubmissionIdList, EFeedType[] FeedTypeList, EFeedProcessingStatus[] FeedProcessingStatusList, DateTime SubmittedFromDate, DateTime SubmittedToDate)
        {
            string                       NextToken   = string.Empty;
            AmazonCredential             Credentials = this.GetCredential();
            MarketplaceWebServiceClient  Client      = this.GetClient(Credentials);
            GetFeedSubmissionListRequest Request     = new GetFeedSubmissionListRequest()
            {
                Merchant = Credentials.MerchantID,
                MaxCount = 100
            };

            if (FeedSubmissionIdList != null)
            {
                Request.FeedSubmissionIdList = new IdList()
                {
                    Id = FeedSubmissionIdList.ToList()
                }
            }
            ;
            else if (FeedTypeList != null)
            {
                Request.FeedTypeList = new TypeList()
                {
                    Type = FeedTypeList.Select(Item => EnumStringHandler.GetEnumString <EFeedType>(Item)).ToList()
                }
            }
            ;
            else if (FeedProcessingStatusList != null)
            {
                Request.FeedProcessingStatusList = new StatusList()
                {
                    Status = FeedProcessingStatusList.Select(Item => EnumStringHandler.GetEnumString <EFeedProcessingStatus>(Item)).ToList()
                }
            }
            ;
            else if (SubmittedFromDate != default(DateTime) && SubmittedToDate != default(DateTime))
            {
                Request.SubmittedFromDate = SubmittedFromDate;
                Request.SubmittedToDate   = SubmittedToDate;
            }

            List <FeedSubmissionInfo> Info = new List <FeedSubmissionInfo>();
            Task GetFeedSubmissionListTask = new Task(() =>
            {
                while (true)
                {
                    switch (NextToken == string.Empty)
                    {
                    case true:
                        this.Throttle(ERequestType.GetFeedSubmissionList);
                        GetFeedSubmissionListResponse Response = Client.GetFeedSubmissionList(Request);
                        if (Response.IsSetGetFeedSubmissionListResult())
                        {
                            GetFeedSubmissionListResult Result = Response.GetFeedSubmissionListResult;
                            if (Result.IsSetFeedSubmissionInfo())
                            {
                                foreach (var FeedInfo in Result.FeedSubmissionInfo)
                                {
                                    Info.Add(FeedInfo);
                                }
                            }

                            if (Result.HasNext)
                            {
                                NextToken = Result.NextToken;
                            }
                            else
                            {
                                goto EndOfLoop;
                            }
                        }
                        break;

                    case false:
                        this.Throttle(ERequestType.GetFeedSubmissionListByNextToken);
                        GetFeedSubmissionListByNextTokenRequest RequestNextToken = new GetFeedSubmissionListByNextTokenRequest()
                        {
                            Merchant  = Credentials.MerchantID,
                            NextToken = NextToken,
                        };
                        GetFeedSubmissionListByNextTokenResponse ResponseNextToken = Client.GetFeedSubmissionListByNextToken(RequestNextToken);
                        if (ResponseNextToken.IsSetGetFeedSubmissionListByNextTokenResult())
                        {
                            GetFeedSubmissionListByNextTokenResult ResultNextToken = ResponseNextToken.GetFeedSubmissionListByNextTokenResult;
                            if (ResultNextToken.IsSetFeedSubmissionInfo())
                            {
                                foreach (var FeedInfo in ResultNextToken.FeedSubmissionInfo)
                                {
                                    Info.Add(FeedInfo);
                                }
                            }

                            if (ResultNextToken.HasNext)
                            {
                                NextToken = ResultNextToken.NextToken;
                            }
                            else
                            {
                                goto EndOfLoop;
                            }
                        }
                        break;
                    }
                }
                EndOfLoop:
                Console.Write("");
            });

            GetFeedSubmissionListTask.Start();
            GetFeedSubmissionListTask.Wait((int)Math.Ceiling(TimeSpan.FromMinutes(Definitions.Timeout_Minutes).Add(TimeSpan.FromHours(Definitions.Timeout_Hours)).TotalMilliseconds));
            return(Info.ToArray());
        }