Esempio n. 1
0
        /// <summary>
        /// Main :)
        /// </summary>
        /// <param name="args"><name> <alliance> <search server port> <airline servers port> <flights search server URI #2> <input file></param>
        static void Main(string[] args)
        {
            CacheData cache = new CacheData();

            if (args.Length != 6)
            {
                Console.WriteLine("Bad arguments");
                Console.WriteLine("TicketSellingServer.exe <name> <alliance> <search server port> <airline servers port> <flights search server URI #2> <input file>");
                return;
            }

            string url = null;

            AirlineServer.Seller seller = null;

            // Check the input:
            try
            {
                url = @"http://" + args[4];
                Convert.ToInt32(args[2]);
                Convert.ToInt32(args[3]);
                new Uri(url);
                seller = readSellerFile(args[5], args[0]);
            }
            catch (Exception e)
            {
                Console.WriteLine("Bad arguments: " + e.Message);
                return;
            }

            string zkAddress = null;

            try
            {
                zkAddress = readZooKeeperAddress();
            }
            catch
            {
                Console.WriteLine("Error: bad configuration file!");
                return;
            }

            String ip = "localhost";

            // Read arguments
            string intraClusterAddress = @"http://" + ip + ":" + args[3] + @"/IntraClusterService";
            string sellerAddress       = @"http://" + ip + ":" + args[2] + @"/SellerService";

            // Builder
            IntraClusterService ics = new IntraClusterService(cache, seller, url, sellerAddress, args[1]);

            AirlineReplicationModule.Instance.initialize(zkAddress, args[1], args[0], new Uri(intraClusterAddress), ics.respondIfNewNode, ics.respondIfSomeoneLeft);
            SellerService sa = new SellerService();

            AirlineReplicationModule.Instance.waitForNameRegister();
            ics.setName(AirlineReplicationModule.Instance.MachineName);
            try
            {
                using (ServiceHost sellerHost = new ServiceHost(sa, new Uri(sellerAddress)))
                {
                    using (ServiceHost intraHost = new ServiceHost(ics, new Uri(intraClusterAddress)))
                    {
                        ServiceEndpoint sellerEndPoint = sellerHost.AddServiceEndpoint(typeof(ISellerService), new BasicHttpBinding(), sellerAddress);
                        ServiceEndpoint intraEndPoint  = intraHost.AddServiceEndpoint(typeof(ISellerClusterService), new BasicHttpBinding(), intraClusterAddress);

                        // add http get support
                        ServiceMetadataBehavior Ismb = new ServiceMetadataBehavior();
                        Ismb.HttpGetEnabled = true;
                        sellerHost.Description.Behaviors.Add(Ismb);
                        sellerHost.Description.Behaviors.Find <ServiceBehaviorAttribute>().InstanceContextMode            = InstanceContextMode.Single;
                        sellerHost.Description.Behaviors.Find <ServiceBehaviorAttribute>().IncludeExceptionDetailInFaults = true;
                        intraHost.Description.Behaviors.Add(Ismb);

                        ExOpBehavior cacheBehavior = new ExOpBehavior(cache);
                        foreach (OperationDescription description in sellerEndPoint.Contract.Operations)
                        {
                            if (description.Name.Equals("getTrips"))
                            {
                                description.Behaviors.Add(cacheBehavior);
                            }
                        }

                        //intraHost.Description.Behaviors.Add(new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true });
                        intraHost.Description.Behaviors.Find <ServiceBehaviorAttribute>().InstanceContextMode            = InstanceContextMode.Single;
                        intraHost.Description.Behaviors.Find <ServiceBehaviorAttribute>().IncludeExceptionDetailInFaults = true;

                        // Open the service
                        sellerHost.Open();
                        intraHost.Open();



                        // Keeping the service alive till pressing ENTER
                        Console.ReadKey();

                        // time to say goodbye
                        sellerHost.Close();
                        intraHost.Close();
                    }
                }
            }

            catch (Exception e)
            {
                Console.WriteLine("Failed executing because:");
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 2
0
 public ExOpBehavior(CacheData cachedata)
 {
     cache = cachedata;
 }
Esempio n. 3
0
 public ExOpInvoker(CacheData inputCache, IOperationInvoker invoker)
 {
     this.invoker = invoker;
     cache        = inputCache;
 }