Example #1
0
 /// <summary>
 /// Closes the pessimistic voter DAO's transaction,
 /// if it is already open.
 /// </summary>
 public static void cleanUpDAO()
 {
     if (staticPvdao.TransactionStarted())
     {
         staticPvdao.EndTransaction();
     }
 }
Example #2
0
        public void PossitiveConcurrencyTest3()
        {
            PessimisticVoterDAO dao1 = new PessimisticVoterDAO(server, password);
            PessimisticVoterDAO dao2 = new PessimisticVoterDAO(server, password);

            this.daos = this.daos.Concat(new List <PessimisticVoterDAO> {
                dao1, dao2
            });

            uint voter1ID = (uint)this.voters.First().PrimaryKey;
            uint voter2ID = (uint)this.voters.Last().PrimaryKey;

            Debug.Assert(voter1ID != voter2ID);

            dao1.StartTransaction();
            dao1.Read(voter1ID);

            dao2.StartTransaction();
            dao2.Read(voter2ID);
            dao2.Update(voter2ID, true);

            dao1.Update(voter1ID, true);

            dao1.EndTransaction();
            dao2.EndTransaction();
        }
Example #3
0
        /// <summary>
        /// Reacts to connection request.
        /// </summary>
        private void ReactToConnectRequest(object o, EventArgs e)
        {
            SetupInfo setupInfo = new SetupInfo(); //The setup info to be checked and then updated to the setup info in model if valid.

            setupInfo.Ip = view.SetupWindow.IpTextBox;

            uint result;
            bool res = uint.TryParse(view.SetupWindow.TableBox, out result);

            if (!res)
            {
                view.ShowMessageBox("Table number cannot be negative");
                return;
            }
            setupInfo.TableNo = uint.Parse(view.SetupWindow.TableBox);
            if (setupInfo.Ip.Length == 0)
            {
                view.ShowMessageBox("Please type in the target connection");
                return;
            }

            string password = view.SetupWindow.Password; //Password from setup window to be tested.

            try
            {
                //Tests inf there is a connection to the voter box.
                PessimisticVoterDAO pvdao = new PessimisticVoterDAO(setupInfo.Ip, password);
                pvdao.StartTransaction();
                pvdao.EndTransaction();
            }
            catch (Exception e1)
            {
                if (e1.Message.Contains("Access"))
                {
                    view.ShowMessageBox("Incorrect password");
                    return;
                }
                if (e1.Message.Contains("connect"))
                {
                    view.ShowMessageBox("No connection to server. Please check connection or target address.");
                    return;
                }
            }

            //feed the model with setup information.
            model.SetupInfo = setupInfo;
            model.AdminPass = password;

            //Tries to write setup information to the setup.conf file.
            try
            {
                model.WriteToConfig();
            }
            catch (Exception e2)
            {
                view.ShowMessageBox("unable to write to config file. " + e2.StackTrace);
            }
            view.SetupWindow.Hide();
            view.ScannerWindow.Show();
        }
Example #4
0
        public void PositiveConcurrencyTest()
        {
            PessimisticVoterDAO dao1 = new PessimisticVoterDAO(server, password);
            PessimisticVoterDAO dao2 = new PessimisticVoterDAO(server, password);

            this.daos = this.daos.Concat(new List <PessimisticVoterDAO> {
                dao1, dao2
            });

            uint voterID = (uint)this.voters.First().PrimaryKey;

            dao1.StartTransaction();
            dao1.Read(voterID);
            dao1.EndTransaction();

            dao2.StartTransaction();
            dao2.Read(voterID);
            dao2.EndTransaction();
        }
Example #5
0
        public void PositiveConcurrencyTest2()
        {
            PessimisticVoterDAO dao1 = new PessimisticVoterDAO(server, password);
            PessimisticVoterDAO dao2 = new PessimisticVoterDAO(server, password);
            this.daos = this.daos.Concat(new List<PessimisticVoterDAO> { dao1, dao2 });

            uint voterID = (uint)this.voters.First().PrimaryKey;

            dao1.StartTransaction();
            dao1.Read(voterID);
            dao1.Update(voterID, true);
            dao1.EndTransaction();

            dao2.StartTransaction();
            dao2.Read(voterID);
            dao2.EndTransaction();
        }