public void SetTransactionDetails(ServerTransaction _transaction)
 {
     transaction = _transaction;
     if (!string.IsNullOrEmpty(transaction.transactionName))
     {
         purchaseName.Text = transaction.transactionName;
     }
     else
     {
         purchaseName.Text = "Item name not available";
     }
     if (!string.IsNullOrEmpty(transaction.transactionType))
     {
         purchaseDate.Text = DateTime.ParseExact(transaction.transactionDate, "MM/dd/yyyy hh:mm:ss tt", CultureInfo.CurrentCulture.DateTimeFormat).ToString("MMM dd, yyyy");
     }
     else
     {
         purchaseDate.Text = "Date not generated";
     }
     if (!string.IsNullOrEmpty(transaction.transactionID))
     {
         purchaseID.Text = "ID : " + transaction.transactionID;
     }
     else
     {
         purchaseID.Text = "ID not generated";
     }
     if (!string.IsNullOrEmpty(transaction.transactionImage))
     {
         purchaseImage.Source = transaction.transactionImage;
         //logoGrid.BackgroundColor = Color.Transparent;
         Regex  initials = new Regex(@"(\b[a-zA-Z])[a-zA-Z]* ?");
         string init     = initials.Replace(transaction.transactionName, "$1");
         if (init.Length > 3)
         {
             init = init.Substring(0, 3);
         }
         logoText.Text = init.ToUpper();
     }
     else
     {
         purchaseImage.Source = "";
         //logoGrid.BackgroundColor = Color.FromHex("#31c3ee");
         Regex  initials = new Regex(@"(\b[a-zA-Z])[a-zA-Z]* ?");
         string init     = initials.Replace(transaction.transactionName, "$1");
         if (init.Length > 3)
         {
             init = init.Substring(0, 3);
         }
         logoText.Text = init.ToUpper();
     }
     if (!string.IsNullOrEmpty(transaction.transactionPrice))
     {
         purchasePrice.Text = "$" + transaction.transactionPrice;
     }
     else
     {
         purchasePrice.Text = "$0.00";
     }
 }
예제 #2
0
        public void SetTransaction(ServerTransaction transaction)
        {
            currentTransaction = transaction;
            //currentTransaction.transactionPrice = "0.00";
            switch (currentTransaction.transactionType)
            {
            case "Sale":
                SetSaleTransaction();
                break;

            case "Donation":
                SetDonationTransaction();
                break;
            }

            /*if (transaction.transactionHaveRefund == "Yes")
             * {
             *  purchaseRefund.Text = "Refund Available";
             * }
             * else
             * {
             *  purchaseRefund.Text = "Refund Not Available";
             * }*/
            SetCardDetails();
            SetShippingDetails();
            SetItemPrice();
        }
예제 #3
0
    public string RequestServerInfo(string serverURL)
    {
        string requestID = GenerateRequestID(serverURL);

        if (!transactions.ContainsKey(requestID) || transactions[requestID].errorLog != null)
        {
            transactions [requestID] = new ServerTransaction <ResponseType> (serverURL + BuildQueryString(), ParseResponse);
        }
        return(requestID);
    }
예제 #4
0
            public void Write(int txId, int value)
            {
                lock (myServer.StateLockObj) {
                    if (myServer.isFail)
                    {
                        Console.WriteLine("[!WRITE] Error: DataServer " + myServer.name + " is set to [Fail] mode!");
                        Console.WriteLine("---");
                        while (true)
                        {
                            ;
                        }
                    }
                    else if (myServer.isFreeze)
                    {
                        lock (SingletonCounter.Instance) {
                            SingletonCounter.Instance.incrementLockCounter();
                            Monitor.Wait(SingletonCounter.Instance);
                        }
                        Console.WriteLine("[!WRITE] Error: DataServer " + myServer.name + " is set to [Freeze] mode!");
                        Console.WriteLine("---");
                    }
                }
                ServerTransaction transaction = null;

                if (!myServer.Transactions.ContainsKey(txId))
                {
                    transaction = new ServerTransaction(txId, this);
                    myServer.Transactions.Add(txId, transaction);
                    myServer.MasterServer.join(txId, myServer.URL);
                }
                transaction = myServer.Transactions[txId];
                Console.WriteLine("[Write] Tx{0} is Trying to acquire lock for PadInt {1}",
                                  txId, Id);

                try {
                    myServer.lockManager.setLock(this.Id, txId, LockType.EXCLUSIVE);
                } catch (TimeoutException toe) {
                    throw new TxException(txId, toe.Msg);
                }
                // to do in abort case
                //myServer.MasterServer.TxAbort(txId);
                //throw new TxException(txId, "Transaction abort on write due to Deadlock");

                Console.WriteLine("[Write] Tx{0} Acquired lock for PadInt {1}",
                                  txId, Id);

                // if not yet saved, save it for future rollback
                if (!transaction.containsPadInt(this))
                {
                    transaction.Add(this);
                }
                this.Value = value;
                Console.WriteLine("[Write] Transaction " + txId + " created in " + myServer.name);
            }
예제 #5
0
            public int Read(int txId)
            {
                lock (myServer.StateLockObj) {
                    if (myServer.isFail)
                    {
                        Console.WriteLine("[!READ] Error: DataServer " + myServer.name + " is set to [Fail] mode!");
                        Console.WriteLine("---");
                        while (true)
                        {
                            ;
                        }
                    }
                    else if (myServer.isFreeze)
                    {
                        lock (SingletonCounter.Instance) {
                            SingletonCounter.Instance.incrementLockCounter();
                            Monitor.Wait(SingletonCounter.Instance);
                        }
                        Console.WriteLine("[!READ] Error: DataServer " + myServer.name + " is set to [Freeze] mode!");
                        Console.WriteLine("---");
                    }
                }

                ServerTransaction transaction = null;

                if (!myServer.Transactions.ContainsKey(txId))
                {
                    transaction = new ServerTransaction(txId, this);
                    myServer.Transactions.Add(txId, transaction);
                    myServer.MasterServer.join(txId, myServer.URL);
                    Console.WriteLine("[Read] Transaction " + txId + " created in " + myServer.name);
                }
                else
                {
                    transaction = myServer.Transactions[txId];
                }

                Console.WriteLine("[Read] Tx{0} is Trying to acquire lock for PadInt {1}",
                                  txId, Id);

                try {
                    myServer.lockManager.setLock(this.Id, txId, LockType.SHARED);
                } catch (TimeoutException toe) {
                    throw new TxException(txId, toe.Msg);
                }

                Console.WriteLine("[Read] Tx{0} Acquired lock for PadInt {1}",
                                  txId, Id);

                return(this.value);
            }
예제 #6
0
        private async void connectButton_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            DisableAll();
            var statusLabel = new ToolStripStatusLabel("Connecting");

            statusBar.Items.Add(statusLabel);
            if (_connected)
            {
                DisconnectUser();
            }
            try
            {
                _certificate = identitiesListBox.SelectedItem as UserCertificate;
                if (await ServerTransaction.Connect(_certificate))
                {
                    await ConnectUser();

                    var login = _certificate.CommonName;
                    loginLabel.Text = login;

                    var message = string.Format("Successfull logged as {0}", login);
                    MessageBox.Show(message, "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    _currentUser = _certificate;
                }
                else
                {
                    MessageBox.Show("Failed to authenticate", "Login failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            catch (AuthenticationError)
            {
                MessageBox.Show("Failed to authenticate", "Login failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (CloudException cloud)
            {
                MessageBox.Show(cloud.Message, "Cloud problem", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (Exception)
            {
                MessageBox.Show("Unexcepted error occured. Click OK to contiune", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            EnableIdentity();
            if (_connected)
            {
                EnableGroups();
            }
            statusBar.Items.Remove(statusLabel);
            Cursor = Cursors.Arrow;
        }
예제 #7
0
        private async void newGroupButton_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            DisableAll();
            var statusLabel = new ToolStripStatusLabel("Creating new group");

            statusBar.Items.Add(statusLabel);

            using (var newGroupForm = new NewGroupForm())
            {
                if (newGroupForm.ShowDialog() == DialogResult.OK)
                {
                    var newGroupInfo = newGroupForm.NewGroupInfo;
                    try
                    {
                        await ServerTransaction.CreateNewGroup(newGroupInfo, _certificate);

                        var message = string.Format("Group {0} created", newGroupInfo.Name);
                        MessageBox.Show(message, "New group");
                        await UpdateGroupList();
                    }
                    catch (UnknownCommadError error)
                    {
                        MessageBox.Show(error.Message);
                    }
                    catch (ServerResponseError error)
                    {
                        MessageBox.Show(error.Message);
                    }
                    catch (AuthenticationError error)
                    {
                        MessageBox.Show(error.Message);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Unexcepted error occured. Click OK to contiune", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }

            EnableIdentity();
            EnableGroups();
            if (_connectedToGroup)
            {
                EnableUsers();
                EnabledFiles();
            }
            statusBar.Items.Remove(statusLabel);
            Cursor = Cursors.Arrow;
        }
        public async Task <ServerTransaction> GetServerTransactionAsync(int id)
        {
            ServerTransaction transaction = null;
            await connection.QueryAsync <ServerTransaction, ServerTransaction.Command, ServerTransaction>("dbo.GetServerProductTransaction",
                                                                                                          (t, c) =>
            {
                if (transaction == null)
                {
                    transaction          = t;
                    transaction.Commands = new List <ServerTransaction.Command>();
                }
                transaction.Commands.Add(c);
                return(null);
            }, new { Id = id }, commandType : CommandType.StoredProcedure);

            return(transaction);
        }
예제 #9
0
        public void SetDomainSubscriptionTransaction(ServerTransaction transaction, string transactionSubscriptionType)
        {
            typeOfSubscription = transactionSubscriptionType;
            currentTransaction = transaction;
            SetSubscriptionTransaction();

            /*if (transaction.transactionHaveRefund == "Yes")
             * {
             *  purchaseRefund.Text = "Refund Available";
             * }
             * else
             * {
             *  purchaseRefund.Text = "Refund Not Available";
             * }*/
            SetCardDetails();
            SetShippingDetails();
            SetItemPrice();
        }
예제 #10
0
            public bool doCommit(int TxId)
            {
                lock (_stateLockObj) {
                    if (isFail)
                    {
                        Console.WriteLine("[!doCommit] Error: DataServer " + name + " is set to [Fail] mode!");
                        Console.WriteLine("---");
                        while (true)
                        {
                            ;
                        }
                    }
                    else if (isFreeze)
                    {
                        lock (SingletonCounter.Instance) {
                            SingletonCounter.Instance.incrementLockCounter();
                            Monitor.Wait(SingletonCounter.Instance);
                        }
                    }
                }
                Console.WriteLine("[doCommit] Master Request with id " + TxId);
                Console.WriteLine("---");
                if (!this.Transactions.ContainsKey(TxId))
                {
                    Console.WriteLine("Error transaction not found : " + TxId);
                    return(false);
                }
                ServerTransaction transaction = transactions[TxId];

                if (_isPrimary)
                {
                    transaction.updatetobackup();
                    SerializableDictionary <int, int> updates = new SerializableDictionary <int, int>();
                    updates = transaction.Valuestobackup;
                    _slaveServer.receiveupdatefromprimary(updates, TxId);
                }
                //transaction.
                //Let's release the locks (reverse order?)
                _lockManager.unLock(TxId);
                return(true);
            }
예제 #11
0
            public bool doAbort(int TxId)
            {
                lock (_stateLockObj) {
                    if (isFail)
                    {
                        Console.WriteLine("[!doAbort] Error: DataServer " + name + " is set to [Fail] mode!");
                        Console.WriteLine("---");
                        while (true)
                        {
                            ;
                        }
                        //throw new RemotingException("Server is in Fail Mode");
                    }
                    else if (isFreeze)
                    {
                        lock (SingletonCounter.Instance) {
                            SingletonCounter.Instance.incrementLockCounter();
                            Monitor.Wait(SingletonCounter.Instance);
                        }
                    }
                }
                Console.WriteLine("[doAbort] Master Request with id " + TxId);
                Console.WriteLine("---");
                if (!this.Transactions.ContainsKey(TxId))
                {
                    Console.WriteLine("Error transaction not found : " + TxId);
                    return(false);
                }
                ServerTransaction transaction = Transactions[TxId];

                transaction.rollback();
                //Let's release the locks (reverse order?)
                _lockManager.unLock(TxId);
                transactions.Remove(TxId);
                return(true);
            }
예제 #12
0
        private async void newUserButton_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            DisableAll();
            var statusLabel = new ToolStripStatusLabel("Creating new user");

            statusBar.Items.Add(statusLabel);
            using (var newUserForm = new NewUserForm())
            {
                if (newUserForm.ShowDialog() == DialogResult.OK)
                {
                    var newUserInfo = newUserForm.NewUserInfo;
                    var pathToSave  = newUserForm.PathToSave;
                    try
                    {
                        DisconnectUser();
                        await ServerTransaction.CreateNewUser(newUserInfo, pathToSave);

                        _certificate = new UserCertificate(pathToSave);
                        _currentUser = _certificate;

                        Process addCertificateProcess = new Process();
                        addCertificateProcess.EnableRaisingEvents = false;
                        addCertificateProcess.StartInfo.FileName  = pathToSave;
                        addCertificateProcess.Start();

                        loginLabel.Text = _currentUser.CommonName;

                        var message = string.Format("Welcome {0}.", _currentUser.CommonName);
                        MessageBox.Show(message, "New user", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        _identitiesList.Add(_certificate);

                        await ConnectUser();
                    }
                    catch (UnknownCommadError error)
                    {
                        MessageBox.Show(error.Message);
                    }
                    catch (ServerResponseError error)
                    {
                        MessageBox.Show(error.Message);
                    }
                    catch (AuthenticationError error)
                    {
                        MessageBox.Show(error.Message);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Unexcepted error occured. Click OK to contiune", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
            EnableIdentity();
            if (_connected)
            {
                EnableGroups();
            }
            statusBar.Items.Remove(statusLabel);
            Cursor = Cursors.Arrow;
        }
예제 #13
0
        public async void PurchaseDetail(ServerTransaction _transaction)
        {
            transaction = _transaction;
            domainEmail = (await App.serverData.GetDomainFromServer(transaction.firmID)).domainEmail;
            await((HomeLayout)App.Current.MainPage).SetLoading(true, "loading transaction...");
            if (string.IsNullOrEmpty(domainEmail))
            {
                contactSender.IsVisible = false;
            }
            if (!string.IsNullOrEmpty(transaction.transactionName))
            {
                purchaseItemName.Text = transaction.transactionName.Replace("@", ",");
            }
            else
            {
                purchaseItemName.Text = "Item name not available";
            }
            if (!string.IsNullOrEmpty(transaction.transactionType))
            {
                purchaseDate.Text = DateTime.ParseExact(transaction.transactionDate, "MM/dd/yyyy hh:mm:ss tt", CultureInfo.CurrentCulture.DateTimeFormat).ToString("MMM dd, yyyy");
            }
            else
            {
                purchaseDate.Text = "Date not generated";
            }
            if (!string.IsNullOrEmpty(transaction.transactionID))
            {
                purchaseID.Text = transaction.transactionID;
            }
            else
            {
                purchaseID.Text = "ID not generated";
            }
            if (!string.IsNullOrEmpty(transaction.transactionImage))
            {
                purchaseItemImage.Source = transaction.transactionImage;
                //logoGrid.BackgroundColor = Color.Transparent;
                Regex  initials = new Regex(@"(\b[a-zA-Z])[a-zA-Z]* ?");
                string init     = initials.Replace(transaction.transactionName, "$1");
                if (init.Length > 3)
                {
                    init = init.Substring(0, 3);
                }
                logoText.Text = init.ToUpper();
            }
            else
            {
                purchaseItemImage.Source = "";
                //logoGrid.BackgroundColor = Color.FromHex("#31c3ee");
                Regex  initials = new Regex(@"(\b[a-zA-Z])[a-zA-Z]* ?");
                string init     = initials.Replace(transaction.transactionName, "$1");
                if (init.Length > 3)
                {
                    init = init.Substring(0, 3);
                }
                logoText.Text = init.ToUpper();
            }
            if (transaction.transactionType != "Subscription")
            {
                purchaseType.Text = transaction.transactionType;
            }
            else
            {
                purchaseType.Text = transaction.transactionType + "( " + transaction.transactionTracking + " Payment )";
            }
            if (!string.IsNullOrEmpty(transaction.transactionPrice))
            {
                purchaseAmount.Text = "$" + transaction.transactionPrice;
            }
            else
            {
                purchaseAmount.Text = "$0.00";
            }
            if (!string.IsNullOrEmpty(transaction.transactionID))
            {
                purchasePaymentCardType.Text = await App.serverData.GetTransactionInformation(transaction.transactionID, "trans_cardType");
            }
            if (!string.IsNullOrEmpty(transaction.transactionShippingAddress))
            {
                purchaseShippingAddress.Text = transaction.transactionShippingAddress;
            }
            else
            {
                purchaseShippingAddress.Text = "Address not provided";
            }
            if (!string.IsNullOrEmpty(transaction.transactionShippingType))
            {
                purchaseShippingType.Text = transaction.transactionShippingType;
            }
            else
            {
                purchaseShippingType.Text = "Type not specified";
            }
            if (!string.IsNullOrEmpty(transaction.transactionTracking))
            {
                purchaseTracking.Text = transaction.transactionTracking;
            }
            else
            {
                purchaseTracking.Text = "Sender yet to provide tracking details.";
            }

            if (transaction.transactionHaveRefund == "Yes")
            {
                purchaseRefund.Text = "Refund Available";
            }
            else
            {
                purchaseRefund.Text = "Refund Not Available";
            }

            if (transaction.transactionType != "Sale")
            {
                ((StackLayout)purchaseQuantity.Parent).IsVisible = false;
                shippingInformation.IsVisible = false;
            }
            else
            {
                purchaseQuantity.Text = transaction.transactionQuantity.Replace("@", "-");
            }

            if (transaction.transactionType == "Subscription")
            {
                cancelSubscriptionLayout.IsVisible = true;
                string subStatus = await App.serverData.GetSubscriptionStatus(transaction.transactionMerchantID, "sub_status");

                if (subStatus.Equals("Canceled") || subStatus.Equals("Expired") && transaction.transactionTracking != "Single")
                {
                    cancelSubscription.IsEnabled = false;
                    if (subStatus.Equals("Canceled"))
                    {
                        cancelSubscription.Text = "Subscription Canceled";
                    }
                    else
                    {
                        cancelSubscription.Text = "Subscription Expired";
                    }
                }
                else if (transaction.transactionTracking == "Single")
                {
                    cancelSubscriptionLayout.IsVisible = false;
                }
            }
            else
            {
                cancelSubscriptionLayout.IsVisible = false;
            }
            await((HomeLayout)App.Current.MainPage).SetLoading(false, "");
        }