/// <summary>
        /// Perform tasks like allocating resources or acquiring connections
        /// </summary>
        /// <param name="parameters">Startup paramters defined in the configuration</param>
        /// <param name="cacheId">Define for which cache provider is configured</param>
        public void Init(IDictionary parameters, string cacheId)
        {
            object connString = parameters["connstring"];

            sqlDatasource = new SqlDataSource();
            sqlDatasource.Connect(connString == null ? "" : connString.ToString());
        }
Ejemplo n.º 2
0
        public void Start(string connectionString, string cacheName)
        {
            bool tryNextTransaction = true;

            transactionTable = new Dictionary <string, bool>();

            // initialize the cache
            transactionCache = InitiliazeCache(cacheName, null);

            // initialize the datasource
            dataSource = new SqlDataSource();
            dataSource.Connect(connectionString);

            // initialize the respective manager
            // transacion manager is required to give input of the customer where as fraud manager has the logic of completeing
            // the transaction and publishing result
            transactionManger = InitiliazeTransactionManager(transactionCache);

            // assing a  transaction completed event with transaction manager, so we will know if transaction has been completed.

            transactionManger.PublishTransactionResult += PublishTransactionResult; // assign an event for transaction completed

            Console.WriteLine("Press Enter to continue");
            Console.ReadLine();

            do
            {
                try
                {
                    Console.WriteLine("\n");
                    //create a random customer instance
                    Customer customer = GetCustomer(new Random().Next(111, 115));

                    Console.WriteLine($"Do you want to make Transaction of '${customer.CardInfo.TransactionAmount}' for " +
                                      $"'{ customer.CardInfo.CardHolder}'? Press Y/yes to continue or N/No to cancel.");

                    string validTransaction = Console.ReadLine();

                    if (validTransaction.Equals("y", StringComparison.InvariantCultureIgnoreCase) || validTransaction.Equals("yes", StringComparison.InvariantCultureIgnoreCase))
                    {
                        bool transactionInProress = true;

                        //perform transaction through manager
                        var transsactionID = transactionManger.TryTransaction(customer);

                        AddTransactionID(transsactionID);

                        while (transactionInProress) // wait till transaction is completed
                        {
                            if (TransactionExist(transsactionID) && GetTransaction(transsactionID))
                            {
                                transactionInProress = false;
                            }
                            // wait for transaction completion
                        }

                        RemoveTransactionID(transsactionID);
                    }
                    Console.WriteLine("Do you want to make another Transaction? press Y or yes to continue.");

                    string input = Console.ReadLine();

                    tryNextTransaction = input.Equals("y", StringComparison.InvariantCultureIgnoreCase) || input.Equals("yes", StringComparison.InvariantCultureIgnoreCase);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            } while (tryNextTransaction);
        }