private static TcpPackage WrapTransactionStart(ClientMessage.TransactionStart msg)
        {
            var dto = new TransactionStart(msg.EventStreamId, msg.ExpectedVersion,
                                           msg.RequireLeader);

            return(CreateWriteRequestPackage(TcpCommand.TransactionStart, msg, dto));
        }
Exemplo n.º 2
0
 private void transActionStartToolStripMenuItem_Click(object sender, EventArgs e)
 {
     ClearDebug();
     PAYNLSDK.API.Transaction.Start.Request fixture = TransactionStart.GetFixture();
     AddDebug("Fixture loaded.");
     AddDebug("JSON:");
     AddDebug(fixture.ToString());
     //AddDebug("PARAMS:");
     //AddDebug(fixture.ToQueryString());
     AddDebug("-----");
     AddDebug("DONE");
 }
Exemplo n.º 3
0
        private void TransActionStartToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ClearDebug();
            var fixture = new TransactionStart(ClientService).GetFixture();

            AddDebug("Fixture loaded.");
            AddDebug("JSON:");
            AddDebug(fixture.ToString());
            AddDebug("PARAMS:");
            AddDebug(fixture.ToQueryString());
            AddDebug("-----");
            AddDebug("DONE");
        }
Exemplo n.º 4
0
        public void Handle(ClientMessage.TransactionStart message)
        {
            var manager = new TransactionStart(
                _bus,
                _prepareTimeout,
                message.Envelope,
                message.InternalCorrId,
                message.CorrelationId,
                message.EventStreamId,
                message.ExpectedVersion,
                _commitSource);

            _currentRequests.Add(message.InternalCorrId, manager);
            _currentTimedRequests.Add(message.InternalCorrId, Stopwatch.StartNew());
            manager.Start();
        }
Exemplo n.º 5
0
 private void transactionStartproductsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     ClearDebug();
     PAYNLSDK.API.Transaction.Start.Request fixture = TransactionStart.GetFixtureNoProductLines();
     AddDebug("Fixture loaded.");
     AddDebug("JSON:");
     AddDebug(fixture.ToString());
     //AddDebug("PARAMS:");
     //string qs = fixture.ToQueryString();
     //AddDebug(qs);
     //NameValueCollection nvc = HttpUtility.ParseQueryString(qs);
     //string json = JsonConvert.SerializeObject(NvcToDictionary(nvc, true));
     AddDebug("-----");
     //DumpNvc(nvc);
     AddDebug("-----");
     AddDebug("DONE");
 }
Exemplo n.º 6
0
        private void transactionStartproductsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ClearDebug();
            PAYNLSDK.API.Transaction.Start.Request fixture = TransactionStart.GetFixtureNoProductLines();
            AddDebug("Fixture loaded.");
            AddDebug("JSON:");
            AddDebug(fixture.ToString());
            AddDebug("PARAMS:");
            string qs = fixture.ToQueryString(APISettings.ServiceID);

            AddDebug(qs);
            var parameters = HttpUtility.ParseQueryString(qs);

            // string json = JsonConvert.SerializeObject(parametersToDictionary(parameters, true));
            AddDebug("-----");
            //AddDebug("PARAMS AS JSON");
            //AddDebug(json);
            Dumpparameters(parameters);
            AddDebug("-----");
            AddDebug("DONE");
        }
Exemplo n.º 7
0
        private void startuseFixtureToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                ClearDebug();
                PAYNLSDK.API.Transaction.Start.Request fixture = TransactionStart.GetFixtureNoProductLines();
                InitRequestDebug(fixture);
                DumpNvc(fixture.GetParameters());

                MyStaticPayNlClient.Client.PerformRequest(fixture);
                DebugRawResponse(fixture);
                tbMain.Text = fixture.Response.ToString();

                string url = fixture.Response.Transaction.PaymentUrl;
                System.Diagnostics.Process.Start(url);
            }
            catch (PayNlException ee)
            {
                AddDebug("~~EXCEPTION~~");
                AddDebug(ee.Message);
            }
        }
Exemplo n.º 8
0
        private void TransactionStartproductsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ClearDebug();
            var fixture = new TransactionStart(ClientService).GetFixtureNoProductLines();

            AddDebug("Fixture loaded.");
            AddDebug("JSON:");
            AddDebug(fixture.ToString());
            AddDebug("PARAMS:");
            var qs = fixture.ToQueryString();

            AddDebug(qs);
            var nvc  = HttpUtility.ParseQueryString(qs);
            var json = JsonConvert.SerializeObject(NvcToDictionary(nvc, true));

            AddDebug("-----");
            AddDebug("PARAMS AS JSON");
            AddDebug(json);
            DumpNvc(nvc);
            AddDebug("-----");
            AddDebug("DONE");
        }
Exemplo n.º 9
0
        private async void StartuseFixtureToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                ClearDebug();
                var fixture = new TransactionStart(ClientService).GetFixtureNoProductLines();
                InitRequestDebug(fixture);
                DumpNvc(fixture.GetParameters());

                await ClientService.PerformPostRequestAsync(fixture);

                DebugRawResponse(fixture);
                tbMain.Text = fixture.Response.ToString();

                var url = fixture.Response.Transaction.PaymentURL;
                System.Diagnostics.Process.Start(url);
            }
            catch (ErrorException ee)
            {
                AddDebug("~~EXCEPTION~~");
                AddDebug(ee.Message);
            }
        }
Exemplo n.º 10
0
        private async void startuseFixtureToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                ClearDebug();
                PAYNLSDK.API.Transaction.Start.Request fixture = TransactionStart.GetFixtureNoProductLines();
                InitRequestDebug(fixture);
                Dumpparameters(fixture.GetParameters(APISettings.ServiceID));

                await APISettings.Client.PerformRequestAsync(fixture);

                DebugRawResponse(fixture);
                tbMain.Text = fixture.Response.ToString();

                string url = fixture.Response.Transaction.PaymentURL;
                OpenUrl(url);
            }
            catch (ErrorException ee)
            {
                AddDebug("~~EXCEPTION~~");
                AddDebug(ee.Message);
            }
        }
Exemplo n.º 11
0
        public bool Execute(CommandProcessorContext context, string[] args)
        {
            var eventStreamId   = "test-stream";
            var expectedVersion = ExpectedVersion.Any;
            int eventsCnt       = 10;

            if (args.Length > 0)
            {
                if (args.Length > 3)
                {
                    return(false);
                }
                eventStreamId = args[0];
                if (args.Length > 1)
                {
                    expectedVersion = args[1].ToUpper() == "ANY" ? ExpectedVersion.Any : int.Parse(args[1]);
                }
                if (args.Length > 2)
                {
                    eventsCnt = int.Parse(args[1]);
                }
            }

            context.IsAsync();

            var  sw            = new Stopwatch();
            var  stage         = Stage.AcquiringTransactionId;
            long transactionId = -1;
            var  writtenEvents = 0;

            context._tcpTestClient.CreateTcpConnection(
                context,
                connectionEstablished: conn => {
                context.Log.Information("[{remoteEndPoint}, L{localEndPoint}]: Starting transaction...",
                                        conn.RemoteEndPoint, conn.LocalEndPoint);
                sw.Start();

                var tranStart = new TransactionStart(eventStreamId, expectedVersion, false);
                var package   = new TcpPackage(TcpCommand.TransactionStart, Guid.NewGuid(), tranStart.Serialize());
                conn.EnqueueSend(package.AsByteArray());
            },
                handlePackage: (conn, pkg) => {
                switch (stage)
                {
                case Stage.AcquiringTransactionId: {
                    if (pkg.Command != TcpCommand.TransactionStartCompleted)
                    {
                        context.Fail(reason: string.Format("Unexpected TCP package: {0}.", pkg.Command));
                        return;
                    }

                    var dto = pkg.Data.Deserialize <TransactionStartCompleted>();
                    if (dto.Result != OperationResult.Success)
                    {
                        var msg = string.Format("Error while starting transaction: {0} ({1}).", dto.Message,
                                                dto.Result);
                        context.Log.Information("Error while starting transaction: {message} ({e}).", dto.Message,
                                                dto.Result);
                        context.Fail(reason: msg);
                    }
                    else
                    {
                        context.Log.Information("Successfully started transaction. TransactionId: {transactionId}.",
                                                dto.TransactionId);
                        context.Log.Information("Now sending transactional events. TransactionId: {transactionId}",
                                                dto.TransactionId);

                        transactionId = dto.TransactionId;
                        stage         = Stage.Writing;
                        for (int i = 0; i < eventsCnt; ++i)
                        {
                            var writeDto = new TransactionWrite(
                                transactionId,
                                new[] {
                                    new NewEvent(Guid.NewGuid().ToByteArray(),
                                                 "TakeSomeSpaceEvent",
                                                 0, 0,
                                                 Common.Utils.Helper.UTF8NoBom.GetBytes(Guid.NewGuid().ToString()),
                                                 Common.Utils.Helper.UTF8NoBom.GetBytes(Guid.NewGuid().ToString()))
                                },
                                false);
                            var package = new TcpPackage(TcpCommand.TransactionWrite, Guid.NewGuid(),
                                                         writeDto.Serialize());
                            conn.EnqueueSend(package.AsByteArray());
                        }
                    }

                    break;
                }

                case Stage.Writing: {
                    if (pkg.Command != TcpCommand.TransactionWriteCompleted)
                    {
                        context.Fail(reason: string.Format("Unexpected TCP package: {0}.", pkg.Command));
                        return;
                    }

                    var dto = pkg.Data.Deserialize <TransactionWriteCompleted>();
                    if (dto.Result != OperationResult.Success)
                    {
                        context.Log.Information("Error while writing transactional event: {message} ({e}).",
                                                dto.Message, dto.Result);
                        var msg = String.Format("Error while writing transactional event: {0} ({1}).",
                                                dto.Message, dto.Result);
                        context.Fail(reason: msg);
                    }
                    else
                    {
                        writtenEvents += 1;
                        if (writtenEvents == eventsCnt)
                        {
                            context.Log.Information("Written all events. Committing...");

                            stage         = Stage.Committing;
                            var commitDto = new TransactionCommit(transactionId, false);
                            var package   = new TcpPackage(TcpCommand.TransactionCommit, Guid.NewGuid(),
                                                           commitDto.Serialize());
                            conn.EnqueueSend(package.AsByteArray());
                        }
                    }

                    break;
                }

                case Stage.Committing: {
                    if (pkg.Command != TcpCommand.TransactionCommitCompleted)
                    {
                        context.Fail(reason: string.Format("Unexpected TCP package: {0}.", pkg.Command));
                        return;
                    }

                    sw.Stop();

                    var dto = pkg.Data.Deserialize <TransactionCommitCompleted>();
                    if (dto.Result != OperationResult.Success)
                    {
                        var msg = string.Format("Error while committing transaction: {0} ({1}).", dto.Message,
                                                dto.Result);
                        context.Log.Information("Error while committing transaction: {message} ({e}).", dto.Message,
                                                dto.Result);
                        context.Log.Information("Transaction took: {elapsed}.", sw.Elapsed);
                        context.Fail(reason: msg);
                    }
                    else
                    {
                        context.Log.Information("Successfully committed transaction [{transactionId}]!",
                                                dto.TransactionId);
                        context.Log.Information("Transaction took: {elapsed}.", sw.Elapsed);
                        PerfUtils.LogTeamCityGraphData(string.Format("{0}-latency-ms", Keyword),
                                                       (int)Math.Round(sw.Elapsed.TotalMilliseconds));
                        context.Success();
                    }

                    conn.Close();
                    break;
                }

                default:
                    throw new ArgumentOutOfRangeException();
                }
            },
                connectionClosed: (connection, error) => context.Fail(reason: "Connection was closed prematurely."));
            context.WaitForCompletion();
            return(true);
        }
Exemplo n.º 12
0
 public void OnTransactionStart(RpcInprocTransaction trans)
 {
     TransactionStart.Invoke(trans);
 }