Beispiel #1
0
 public override bool InsertTrip(UserNodeCore context, Communication.Trip trip)
 {
     Command command = new InsertTripCommand(trip);
     context.ServiceProxy.HandleDarPoolingRequest(command);
     // This command does not change state
     return true;
 }
        // Console-Client, used for debug purposes
        public static void Main()
        {
            UserNodeCore user = new UserNodeCore(new UserNode("prova"));
            Console.WriteLine("***** DarPooling Client Console Testing  *****\n\n");

            User dummy = new User
            {
                UserName = "******",
                Password = "******",
                Name = "Daniele",
                UserSex = User.Sex.m,
                BirthDate = new DateTime(1986, 04, 08),
                Email = "*****@*****.**",
                Smoker = false,
                SignupDate = DateTime.Now.AddDays(-30),
                Whereabouts = ""
            };

            Trip trip1 = new Trip
            {
                Owner = "daniele@http://localhost:1111/Milano",
                DepartureName = "Aci Trezza",
                DepartureDateTime = new DateTime(2010, 7, 30, 8, 0, 0),
                ArrivalName = "Milano",
                ArrivalDateTime = new DateTime(2010, 7, 30, 10, 30, 0),
                Smoke = false,
                Music = false,
                Cost = 10,
                FreeSits = 4,
                Notes = "none",
                Modifiable = false
            };

            QueryBuilder query1 = new QueryBuilder
            {
                Owner = "daniele@http://localhost:1111/Milano",
                DepartureName = "Aci Trezza",
                /*
                DepartureDateTime = new DateTime(2010, 7, 30, 8, 0, 0),
                ArrivalName = "Milano",
                ArrivalDateTime = new DateTime(2010, 7, 30, 10, 30, 0),
                Smoke = false,
                Music = false,
                Cost = 10,
                FreeSits = 4,
                Notes = "none",
                Modifiable = false
                */
            };

            /*
            // Case 4: LoginForward
            Console.ReadLine();
            Console.WriteLine("Press a key... (Forward expected)");
            Console.ReadLine();
            Console.WriteLine("Key pressed!");
            user.Join("Shaoran@http://localhost:1111/Milano", "shaoran", "http://*****:*****@http://localhost:1111/Milano");
            TestCommands(unjoin);

            Console.ReadLine();
            Console.WriteLine("Press a key... (Register)");
            Console.ReadLine();
            RegisterUserCommand register = new RegisterUserCommand(dummy);
            TestCommands(register);
            //TestCommands(register);
            */
            string city;
            int range;
            while (true)
            {

                EndpointAddress endPointAddress = new EndpointAddress("http://localhost:1155/Catania");
                BasicHttpBinding binding = new BasicHttpBinding();

                ChannelFactory<IDarPoolingMobile> factory = new ChannelFactory<IDarPoolingMobile>(
                        binding, endPointAddress);

                IDarPoolingMobile serviceProxy = factory.CreateChannel();
                string res = serviceProxy.HandleDarPoolingMobileRequest(new UnjoinCommand("pippo"));

                Console.WriteLine("Got :  {0}", res);

                Console.WriteLine("I per insert, S per search, R per search-range:");
                string instruction = Console.ReadLine();
                switch(instruction)
                {
                    case "i":
                    //Console.ReadLine();
                    Console.WriteLine("Insert departure city... (Insert Trip)");
                    city = Console.ReadLine();
                    trip1.DepartureName = city;
                    InsertTripCommand insert = new InsertTripCommand(trip1);
                    TestCommands(insert);
                    break;
                    case "s":
                    Console.WriteLine("Insert departure city... (Search Trip)");
                    city = Console.ReadLine();
                    query1.DepartureName = city;
                    query1.Range = 0;
                    SearchTripCommand search = new SearchTripCommand(query1);
                    TestCommands(search);
                    break;
                    case "r":
                    Console.WriteLine("Insert departure city... (Search Trip)");
                    city = Console.ReadLine();
                    query1.DepartureName = city;
                    Console.WriteLine("Insert search Range... (Search Trip)");
                    range = Convert.ToInt32(Console.ReadLine());
                    query1.Range = range;
                    SearchTripCommand search2 = new SearchTripCommand(query1);
                    TestCommands(search2);
                    break;
                    default:
                    break;

                }
               //Console.ReadLine();
            }
        }