示例#1
0
文件: MyWC.cs 项目: vlung/Citicenter
        /// <param name="c">Customer</param>
        /// <param name="flights">array of flight names</param>
        /// <param name="location">room location if room is true</param>
        /// <param name="car">true if request is for a car</param>
        /// <param name="room">true if request is for a room</param>
        /// <returns>price of reservation</returns>
        public bool ReserveItinerary(TP.Customer c, string[] flights, string location, bool car, bool room)
        {
            TP.Transaction tid = TransactionManager.Start();

            try
            {
                if (car)
                {
                    bool result = Cars.Reserve(tid, c, RID.forCar(location));
                    if (!result)
                    {
                        throw new InvalidOperationException();
                    }
                }

                if (room)
                {
                    bool result = Rooms.Reserve(tid, c, RID.forRoom(location));
                    if (!result)
                    {
                        throw new InvalidOperationException();
                    }
                }

                foreach (string flight in flights)
                {
                    bool result = Flights.Reserve(tid, c, RID.forFlight(flight));
                    if (!result)
                    {
                        throw new InvalidOperationException();
                    }
                }

                Commit(tid);
            }
            catch (AbortTransationException)
            {
                Abort(tid);
                return(false);
            }
            catch (ArgumentException)
            {
                Abort(tid);
                return(false);
            }
            catch (DeadLockDetected)
            {
                Abort(tid);
                return(false);
            }
            catch (InvalidOperationException)
            {
                Abort(tid);
                return(false);
            }
            catch (Exception e)
            {
                Abort(tid);
                throw e;
            }

            return(true);
        }
示例#2
0
文件: MyWC.cs 项目: vlung/Citicenter
        /// <summary>

        /*  WC runs as a separate process looping forever,
         *  waiting for the calls from other processes */
        /// </summary>
        static void Main(string[] args)
        {
            WCParser parser = new WCParser();

            if (!parser.Parse(args))
            {
                return;
            }

            //string rmFlightsURL = parser["f"];
            //string rmRoomsURL = parser["r"];
            //string rmCarsURL = parser["c"];
            string tmPort   = parser["tmp"];
            string tmServer = parser["tms"];
            string tmURL    = tmServer + ":" + tmPort + "/TM.soap";

            while (TransactionManager == null)
            {
                try
                {
                    TransactionManager = (TP.TM)Activator.GetObject(typeof(TP.TM), tmServer + ":" + tmPort + "/TM.soap");
                    Transaction tid = TransactionManager.Start();
                    TransactionManager.Abort(tid);
                }
                catch (RemotingException)
                {
                    TransactionManager = null;
                    Console.WriteLine("Waiting 1 second for Transaction Manager \"{0}\"", tmURL);
                    System.Threading.Thread.Sleep(1000);
                }
            }


            Console.WriteLine("Transaction Manager retrieved at {0}", tmURL);
            while (Flights == null || Rooms == null || Cars == null)
            {
                if (Flights == null)
                {
                    Flights = TransactionManager.GetResourceMananger("flight");
                }
                if (Rooms == null)
                {
                    Rooms = TransactionManager.GetResourceMananger("room");
                }
                if (Cars == null)
                {
                    Cars = TransactionManager.GetResourceMananger("car");
                }
            }
            if (Flights != null)
            {
                Console.WriteLine("Got RM with the name:" + Flights.GetName());
            }
            if (Rooms != null)
            {
                Console.WriteLine("Got RM with the name:" + Rooms.GetName());
            }
            if (Cars != null)
            {
                Console.WriteLine("Got RM with the name:" + Cars.GetName());
            }

            HttpChannel httpChannel = new HttpChannel(Int32.Parse(parser["p"]));

            System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(httpChannel, false);
            System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType
                (Type.GetType("MyWC.MyWC")                              // Assembly name
                , "WC.soap"                                             // URI
                , System.Runtime.Remoting.WellKnownObjectMode.Singleton // Instancing mode
                );

            Console.WriteLine("Staring Workflow Controller on port {0}", parser["p"]);


            while (true)
            {
                System.Threading.Thread.Sleep(100000);
            }
        }
示例#3
0
        /// <summary>
        /*  WC runs as a separate process looping forever,
            waiting for the calls from other processes */
        /// </summary>
        static void Main(string[] args)
        {
            WCParser parser = new WCParser();
            if (!parser.Parse(args))
            {
                return;
            }

            //string rmFlightsURL = parser["f"];
            //string rmRoomsURL = parser["r"];
            //string rmCarsURL = parser["c"];
            string tmPort = parser["tmp"];
            string tmServer = parser["tms"];
            tmURL = tmServer + ":" + tmPort + "/TM.soap";

            while (TransactionManager == null)
            {
                try
                {
                    TransactionManager = (TP.TM)Activator.GetObject(typeof(TP.TM), tmServer + ":" + tmPort + "/TM.soap");
                    Transaction tid = TransactionManager.Start();
                    TransactionManager.Abort(tid);
                }
                catch (RemotingException e)
                {
                    TransactionManager = null;
                    Console.WriteLine("Waiting 1 second for Transaction Manager \"{0}\"", tmURL);
                    System.Threading.Thread.Sleep(1000);
                }
            }

            Console.WriteLine("Transaction Manager retrieved at {0}:{1}", tmURL, tmPort);
            while (Flights == null || Rooms == null || Cars == null)
            {
                if (Flights == null)
                    Flights = TransactionManager.GetResourceMananger("flight");
                if (Rooms == null)
                    Rooms = TransactionManager.GetResourceMananger("room");
                if (Cars == null)
                    Cars = TransactionManager.GetResourceMananger("car");
            }
            if (Flights != null)
                Console.WriteLine("Get RM with the name:" + Flights.GetName());
            if (Rooms != null)
                Console.WriteLine("Get RM with the name:" + Rooms.GetName());
            if (Cars != null)
                Console.WriteLine("Get RM with the name:" + Cars.GetName());

            HttpChannel httpChannel = new HttpChannel(Int32.Parse(parser["p"]));
            System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(httpChannel, false);
            RemotingConfiguration.RegisterWellKnownServiceType
                (Type.GetType("MyWC.MyWC")							    // Assembly name
                , "WC.soap"												// URI
                , System.Runtime.Remoting.WellKnownObjectMode.Singleton	// Instancing mode
            );

            Console.WriteLine("Starting Workflow Controller on port {0}", parser["p"]);

            while (true)
            {
                System.Threading.Thread.Sleep(1000);
                try
                {
                    TransactionManager.Ping();
                }
                catch(WebException)
                {
                    TransactionManager = null;
                    ReconnectToTM();
                }
            }
        }