public async Task CanRequestCardPayment()
        {
            var firstCardPayment         = TestHelper.CreateCardPaymentRequest();
            var firstCardPaymentResponse = await _api.Payments.RequestAsync(firstCardPayment);

            var idSource             = new IdSource(firstCardPaymentResponse.Payment.Source.AsCard().Id);
            var cardIdPaymentRequest = new PaymentRequest <IdSource>(
                idSource,
                Currency.GBP,
                100
                )
            {
                Capture  = false,
                Customer = ToRequest(firstCardPaymentResponse.Payment.Customer)
            };

            PaymentResponse apiResponseForCustomerSourcePayment = await _api.Payments.RequestAsync(cardIdPaymentRequest);

            apiResponseForCustomerSourcePayment.Payment.ShouldNotBeNull();
            apiResponseForCustomerSourcePayment.Payment.Approved.ShouldBeTrue();
            apiResponseForCustomerSourcePayment.Payment.Id.ShouldNotBeNullOrEmpty();
            apiResponseForCustomerSourcePayment.Payment.Id.ShouldNotBe(firstCardPaymentResponse.Payment.Id);
            apiResponseForCustomerSourcePayment.Payment.ActionId.ShouldNotBeNullOrEmpty();
            apiResponseForCustomerSourcePayment.Payment.Amount.ShouldBe(cardIdPaymentRequest.Amount.Value);
            apiResponseForCustomerSourcePayment.Payment.Currency.ShouldBe(cardIdPaymentRequest.Currency);
            apiResponseForCustomerSourcePayment.Payment.Reference.ShouldBe(cardIdPaymentRequest.Reference);
            apiResponseForCustomerSourcePayment.Payment.Customer.ShouldNotBeNull();
            apiResponseForCustomerSourcePayment.Payment.Customer.Id.ShouldNotBeNullOrEmpty();
            apiResponseForCustomerSourcePayment.Payment.Customer.Email.ShouldNotBeNullOrEmpty();
            apiResponseForCustomerSourcePayment.Payment.Customer.Id.ShouldBe(firstCardPaymentResponse.Payment?.Customer?.Id);
            apiResponseForCustomerSourcePayment.Payment.Source.AsCard().Id.ShouldBe(firstCardPaymentResponse.Payment?.Source?.AsCard().Id);
            apiResponseForCustomerSourcePayment.Payment.CanCapture().ShouldBeTrue();
            apiResponseForCustomerSourcePayment.Payment.CanVoid().ShouldBeTrue();
        }
    private bool CreateNewFile(DataSet dsNewFile)
    {
        if (dsNewFile == null)
        {
            throw new IndException("Data Set NULL");
        }
        if (dsNewFile.Tables[0].Rows.Count == 0)
        {
            if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "CannotDelete"))
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "CannotDelete", "setTimeout(\"alert('The file could not be created because is empty!')\",100);", true);
            }
            return(false);
        }
        //throw new IndException("There is no more room on the disc");
        Imports imp = new Imports(CurrentConnectionManager);

        imp.IdImport = IdImport;
        DataSet ds = imp.GetAll(true);

        if (ds == null)
        {
            throw new IndException("DataSet null!");
        }

        if (ds.Tables.Count == 0)
        {
            throw new IndException("No tables in dataset");
        }

        //if file name is bigger than 4 -- (.extension)
        if (ds.Tables[0].Rows[0]["FileName"].ToString().Length <= 4)
        {
            return(false);
        }

        string dirUrlProcessed  = ConfigurationManager.AppSettings["UploadFolder"];
        string dirPathProcessed = Server.MapPath("../../" + dirUrlProcessed);
        string fileName         = ds.Tables[0].Rows[0]["FileName"].ToString().Substring(0, ds.Tables[0].Rows[0]["FileName"].ToString().Length - 4);
        string PathToFile       = dirPathProcessed + @"\" + fileName + "_" + IdSource.ToString() + "_" + DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + ".csv";

        string[] filesArr = Directory.GetFiles(dirPathProcessed);
        for (int i = 0; i <= filesArr.Length - 1; i++)
        {
            if (Path.GetExtension(filesArr[i].ToString()).ToLower() != ".csv")
            {
                continue;
            }
            if (filesArr[i].ToString().Contains(fileName))
            {
                File.Delete(filesArr[i].ToString());
            }
        }
        WriteToFile(PathToFile, dsNewFile);
        if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "ButtonUpdateScript"))
        {
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "ButtonUpdateScript", "alert('Modifications have been saved! You can retry to process file.');", true);
        }
        return(true);
    }
Beispiel #3
0
        public virtual async Task RebuildAsync <TState, TGrain>(IdSource source, CancellationToken ct = default) where TState : IDomainState <TState>, new()
        {
            Guard.NotNull(source);

            await store.GetSnapshotStore <TState>().ClearAsync();

            await InsertManyAsync <TState, TGrain>(source, ct);
        }
Beispiel #4
0
        public virtual async Task RebuildAsync <T, TState>(IdSource source, CancellationToken ct = default) where T : DomainObjectBase <TState> where TState : class, IDomainState <TState>, new()
        {
            Guard.NotNull(source, nameof(source));

            await store.GetSnapshotStore <TState>().ClearAsync();

            await InsertManyAsync <T, TState>(source, ct);
        }
Beispiel #5
0
        private static void DefragUnindexed(DefragmentServicesImpl services)
        {
            IdSource unindexedIDs = services.UnindexedIDs();

            while (unindexedIDs.HasMoreIds())
            {
                int origID = unindexedIDs.NextId();
                DefragmentContextImpl.ProcessCopy(services, origID, new _ISlotCopyHandler_208());
            }
        }
Beispiel #6
0
        public void CanCreateIdSource()
        {
            var source = new IdSource("src_xxx")
            {
                Cvv = "0757"
            };

            source.Id.ShouldBe("src_xxx");
            source.Cvv.ShouldBe("0757");
        }
 public TvDbImportWorker(ITvDbApi tvDbApi, ITvDbDomainConverter tvDbDomainConverter, ITvSeriesContext tvSeriesContext,
                         ILogger <ITvDbImportWorker> logger, IConfiguration configuration)
 {
     _tvDbApi = tvDbApi;
     _tvDbApi.GetJwtToken();
     _tvDbDomainConverter = tvDbDomainConverter;
     _tvSeriesContext     = tvSeriesContext;
     _logger            = logger;
     _configuration     = configuration;
     _maxRefreshRetries = Convert.ToInt32(_configuration.GetSection("ImportWorker").GetSection("TvDb").GetSection("MaxRefreshRetries").Value);
     _idSource          = (IdSource)Enum.Parse(typeof(IdSource), _configuration.GetSection("ImportWorker").GetSection("TvDb").GetSection("IdSource").Value, true);
     _isInitialized     = false;
 }
Beispiel #8
0
        public virtual async Task InsertManyAsync <TState, TGrain>(IdSource source, CancellationToken ct = default) where TState : IDomainState <TState>, new()
        {
            Guard.NotNull(source);

            var worker = new ActionBlock <Guid>(async id =>
            {
                try
                {
                    var state = new TState
                    {
                        Version = EtagVersion.Empty
                    };

                    var persistence = store.WithSnapshotsAndEventSourcing(typeof(TGrain), id, (TState s) => state = s, e =>
                    {
                        state = state.Apply(e);

                        state.Version++;
                    });

                    await persistence.ReadAsync();
                    await persistence.WriteSnapshotAsync(state);
                }
                catch (DomainObjectNotFoundException)
                {
                    return;
                }
            },
                                                new ExecutionDataflowBlockOptions
            {
                MaxDegreeOfParallelism = Environment.ProcessorCount * 2
            });

            var handledIds = new HashSet <Guid>();

            using (localCache.StartContext())
            {
                await source(new Func <Guid, Task>(async id =>
                {
                    if (handledIds.Add(id))
                    {
                        await worker.SendAsync(id, ct);
                    }
                }));

                worker.Complete();

                await worker.Completion;
            }
        }
Beispiel #9
0
 public MovieDbImportWorker(IMovieDbApi movieDbApi, IMovieDbDomainConverter movieDbDomainConverter,
                            ITvDbApi tvDbApi, ITvDbDomainConverter tvDbDomainConverter, ITvSeriesContext tvSeriesContext,
                            IMovieDbImportServiceDbHelper movieDbImportServiceDbHelper, ILogger <IMovieDbImportWorker> logger, IConfiguration configuration)
 {
     _movieDbApi             = movieDbApi;
     _movieDbDomainConverter = movieDbDomainConverter;
     _tvDbApi                      = tvDbApi;
     _tvDbDomainConverter          = tvDbDomainConverter;
     _tvSeriesContext              = tvSeriesContext;
     _movieDbImportServiceDbHelper = movieDbImportServiceDbHelper;
     _logger        = logger;
     _configuration = configuration;
     _idSource      = (IdSource)Enum.Parse(typeof(IdSource), _configuration.GetSection("ImportWorker").GetSection("MovieDb").GetSection("IdSource").Value, true);
     _popularPages  = 1;
     _isInitialized = false;
 }
Beispiel #10
0
        public virtual async Task InsertManyAsync <T, TState>(IdSource source, CancellationToken ct = default) where T : DomainObjectBase <TState> where TState : class, IDomainState <TState>, new()
        {
            Guard.NotNull(source);

            var worker = new ActionBlock <Guid>(async id =>
            {
                try
                {
                    var domainObject = (T)serviceProvider.GetService(typeof(T));

                    domainObject.Setup(id);

                    await domainObject.EnsureLoadedAsync();
                    await domainObject.RebuildStateAsync();
                }
                catch (DomainObjectNotFoundException)
                {
                    return;
                }
            },
                                                new ExecutionDataflowBlockOptions
            {
                MaxDegreeOfParallelism = Environment.ProcessorCount * 2
            });

            var handledIds = new HashSet <Guid>();

            using (localCache.StartContext())
            {
                await source(new Func <Guid, Task>(async id =>
                {
                    if (handledIds.Add(id))
                    {
                        await worker.SendAsync(id, ct);
                    }
                }));

                worker.Complete();

                await worker.Completion;
            }
        }
Beispiel #11
0
        private async Task InsertManyAsync <T, TState>(IStore <TState> store, IdSource source, CancellationToken ct = default) where T : DomainObject <TState> where TState : class, IDomainState <TState>, new()
        {
            var parallelism = Environment.ProcessorCount;

            const int BatchSize = 100;

            var workerBlock = new ActionBlock <DomainId[]>(async ids =>
            {
                await using (var context = store.WithBatchContext(typeof(T)))
                {
                    await context.LoadAsync(ids);

                    foreach (var id in ids)
                    {
                        try
                        {
                            var domainObject = Factory <T, TState> .Create(serviceProvider, context);

                            domainObject.Setup(id);

                            await domainObject.RebuildStateAsync();
                        }
                        catch (DomainObjectNotFoundException)
                        {
                            return;
                        }
                    }
                }
            },
                                                           new ExecutionDataflowBlockOptions
            {
                MaxDegreeOfParallelism = parallelism,
                MaxMessagesPerTask     = 1,
                BoundedCapacity        = parallelism
            });

            var batchBlock = new BatchBlock <DomainId>(BatchSize, new GroupingDataflowBlockOptions
            {
                BoundedCapacity = BatchSize
            });

            batchBlock.LinkTo(workerBlock, new DataflowLinkOptions
            {
                PropagateCompletion = true
            });

            var handledIds = new HashSet <DomainId>();

            using (localCache.StartContext())
            {
                await source(id =>
                {
                    if (handledIds.Add(id))
                    {
                        return(batchBlock.SendAsync(id, ct));
                    }

                    return(Task.CompletedTask);
                });

                batchBlock.Complete();

                await workerBlock.Completion;
            }
        }