Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Common.Logger().LogInfo("Client started", string.Empty, string.Empty);
            // ClientForm f = new ClientForm();
            // Application.Run(f);
            // Client c = new Client();
            //  c.Start();

            try
            {
                bool res;

                PADI_Client.Init();
                //  res = PADI_Client.TxBegin();
                //  PADI_Client.Status();
                //  PADI_Client.TxAbort();
                //  Console.ReadLine();
                // res = PADI_Client.Fail("tcp://127.0.0.1:25051/PADI_Worker");
                // res = PADI_Client.Recover("tcp://127.0.0.1:25051/PADI_Worker");
                // Thread.Sleep(5000);

                /*    res = PADI_Client.TxBegin();
                 *   PadInt pi_a = PADI_Client.CreatePadInt(0);
                 *   PadInt pi_b = PADI_Client.CreatePadInt(1);
                 *   PadInt pi_c = PADI_Client.CreatePadInt(2);
                 *    pi_a.Write(33);
                 *    pi_b.Write(34);
                 *    pi_c.Write(35);
                 *   res = PADI_Client.TxCommit();
                 *   PADI_Client.Status(); */


                res = PADI_Client.TxBegin();
                PadInt pi_a = PADI_Client.AccessPadInt(0);
                if (pi_a == null)
                {
                    pi_a = PADI_Client.CreatePadInt(0);
                }
                PadInt pi_b = PADI_Client.AccessPadInt(1);
                if (pi_b == null)
                {
                    pi_b = PADI_Client.CreatePadInt(1);
                }
                PadInt pi_c = PADI_Client.AccessPadInt(2);
                if (pi_c == null)
                {
                    pi_c = PADI_Client.CreatePadInt(2);
                }
                pi_a.Write(101);
                pi_b.Write(102);
                pi_c.Write(103);
                res = PADI_Client.TxCommit();
                PADI_Client.Status();

                Console.WriteLine("Press enter to check timeout");
                Console.ReadLine();

                res  = PADI_Client.TxBegin();
                pi_c = PADI_Client.AccessPadInt(2);
                pi_c.Write(500);
                Console.WriteLine("Checking whether this will automatically timeout");
                Console.ReadLine();
                res = PADI_Client.TxCommit();
                PADI_Client.Status();

                Console.ReadLine();

                int index = 1500;
                while (true)
                {
                    try
                    {
                        res  = PADI_Client.TxBegin();
                        pi_a = PADI_Client.AccessPadInt(0);
                        pi_b = PADI_Client.AccessPadInt(1);
                        pi_c = PADI_Client.AccessPadInt(2);
                        if (index % 6 == 0)
                        {
                            Console.WriteLine(pi_a.Read() + ", " + pi_b.Read() + ", " + pi_c.Read());
                        }
                        Thread.Sleep(500);
                        pi_a.Write(index);
                        pi_b.Write(index * 3);
                        pi_c.Write(index * 5);
                        if (index == 1700)
                        {
                            Console.WriteLine("Enter to finish....");
                            Console.ReadLine();
                            PADI_Client.TxCommit();
                            break;
                        }
                        index++;
                        PADI_Client.TxCommit();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }

                PADI_Client.Status();



                /*     res = PADI_Client.TxBegin();
                 *   pi_a = PADI_Client.CreatePadInt(4);
                 *   pi_a.Write(200);
                 *   PADI_Client.Status();
                 *   Console.ReadLine();
                 *   pi_a = PADI_Client.CreatePadInt(5);
                 *   pi_a.Write(300);
                 *   res = PADI_Client.TxCommit();
                 *   PADI_Client.Status();
                 *
                 *   Console.ReadLine();  */

                /*    PADI_Client.TxBegin();
                 *  PadInt a = PADI_Client.AccessPadInt(5);
                 *  Console.WriteLine(a.Read());
                 *
                 *  PadInt b = PADI_Client.AccessPadInt(3);
                 *  Console.WriteLine(b.Read());
                 *  PADI_Client.TxCommit();
                 *  PADI_Client.Status(); */

                /*  res = PADI_Client.TxBegin();
                 * PADI_Client.Freeze("tcp://localhost:25051/PADI_Worker");
                 * pi_a = PADI_Client.AccessPadInt(0);
                 * pi_b = PADI_Client.AccessPadInt(1);
                 * pi_a.Write(36);
                 * pi_b.Write(37);
                 * Console.WriteLine("a = " + pi_a.Read());
                 * Console.WriteLine("b = " + pi_b.Read());
                 * res = PADI_Client.Recover("tcp://localhost:25051/PADI_Worker");
                 * PADI_Client.Status();
                 * // The following 3 lines assume we have 2 servers: one at port 2001 and another at port 2002
                 * // res = PADI_Client.Freeze("tcp://localhost:25052/PADI_Worker");
                 * // res = PADI_Client.Recover("tcp://localhost:25052/PADI_Worker");
                 *
                 * res = PADI_Client.TxCommit();*/
            }
            catch (TxException ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("Transaction aborted : " + PADI_Client.TxAbort());
                PADI_Client.Status();
            }
            catch (Exception ex)
            {
                // Console.WriteLine(ex.Message);
                //Console.WriteLine("Transaction aborted : " + PADI_Client.TxAbort());
                // PADI_Client.TxAbort();
            }
            finally
            {
                Console.WriteLine("-----------Client execution ended----------");
                Console.ReadLine();
            }
        }
Exemplo n.º 2
0
        public void Start()
        {
            try
            {
                //operationArray = ConfigurationManager.AppSettings[APP_SET_TASK].Split(SEP_CHAR_COMMA);
                string commands = tbxOperations.Text.Trim();
                if (!String.IsNullOrEmpty(commands))
                {
                    operationArray = commands.Split(SEP_CHAR_COMMA);
                    string[] tmp;
                    PadInt   padInt = null;
                    foreach (var operation in operationArray)
                    {
                        tmp = operation.Split(SEP_CHAR_COLON);
                        bool status = false;
                        switch (tmp[0])
                        {
                        case BEGIN_TRANSACTION:
                            status = PADI_Client.TxBegin();
                            UpdateResultPanel("Transaction started. " + status);
                            break;

                        case END_TRANSACTION:
                            status = PADI_Client.TxCommit();
                            UpdateResultPanel("Transaction committed. " + status);
                            break;

                        case CREATE_PADINT:
                            padInt = PADI_Client.CreatePadInt(Int32.Parse(tmp[1]));
                            break;

                        case ACCESS_PADINT:
                            padInt = PADI_Client.AccessPadInt(Int32.Parse(tmp[1]));
                            break;

                        case READ:
                            if (padInt != null)
                            {
                                UpdateResultPanel("Read value = " + padInt.Read());
                            }
                            else
                            {
                                UpdateResultPanel("PadInt is null - READ");
                            }
                            break;

                        case WRITE:
                            if (padInt != null)
                            {
                                padInt.Write(Int32.Parse(tmp[1]));
                                UpdateResultPanel("Write issued = " + tmp[1]);
                            }
                            else
                            {
                                Console.WriteLine("PadInt is null - WRITE");
                            }
                            break;

                        case STATUS_DUMP:
                            PADI_Client.Status();
                            UpdateResultPanel("Dumped Status");
                            break;
                        }
                    }
                }
            }
            catch (TxException ex)
            {
                UpdateResultPanel(ex.Message);
            }
            catch (Exception ex)
            {
                UpdateResultPanel(ex.Message);
            }
        }
Exemplo n.º 3
0
        public void Start()
        {
            try
            {
                for (int i = 0; i < Int32.Parse(ConfigurationManager.AppSettings[APP_SET_SLEEP_TIME]); i++)
                {
                    Console.WriteLine("Starts : " + (Int32.Parse(ConfigurationManager.AppSettings[APP_SET_SLEEP_TIME]) - i));
                    Thread.Sleep(1000);
                }
                operationArray = ConfigurationManager.AppSettings[APP_SET_TASK].Split(SEP_CHAR_COMMA);
                string[] tmp;
                PadInt   padInt = null;
                foreach (var operation in operationArray)
                {
                    tmp = operation.Split(SEP_CHAR_HYPHEN);
                    bool status = false;
                    switch (tmp[0])
                    {
                    case BEGIN_TRANSACTION:
                        status = PADI_Client.TxBegin();
                        Console.WriteLine("Transaction started. " + status);
                        break;

                    case END_TRANSACTION:
                        status = PADI_Client.TxCommit();
                        Console.WriteLine("Transaction committed. " + status);
                        break;

                    case CREATE_PADINT:
                        padInt = PADI_Client.CreatePadInt(Int32.Parse(tmp[1]));
                        break;

                    case ACCESS_PADINT:
                        padInt = PADI_Client.AccessPadInt(Int32.Parse(tmp[1]));
                        break;

                    case READ:
                        if (padInt != null)
                        {
                            Console.WriteLine("Read value = " + padInt.Read());
                        }
                        else
                        {
                            Console.WriteLine("PadInt is null - READ");
                        }
                        break;

                    case WRITE:
                        if (padInt != null)
                        {
                            padInt.Write(Int32.Parse(tmp[1]));
                            Console.WriteLine("Write issued = " + tmp[1]);
                        }
                        else
                        {
                            Console.WriteLine("PadInt is null - WRITE");
                        }
                        break;

                    case STATUS_DUMP:
                        PADI_Client.Status();
                        Console.WriteLine("Dumped Status");
                        break;

                    case FREEZE:
                        PADI_Client.Freeze(tmp[1]);
                        break;

                    case FAIL:
                        PADI_Client.Fail(tmp[1]);
                        break;

                    case RECOVER:
                        PADI_Client.Recover(tmp[1]);
                        Thread.Sleep(5000);     //wait until it stables
                        break;

                    default:
                        Console.WriteLine("Invalid input");
                        break;
                    }
                }
            }
            catch (TxException ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("Transaction aborted : " + PADI_Client.TxAbort());
                PADI_Client.Status();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("Transaction aborted : " + PADI_Client.TxAbort());
                PADI_Client.TxAbort();
            }
            finally
            {
                Console.WriteLine("-----------Client execution ended----------");
                Console.ReadLine();
            }
        }