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);
        }
Beispiel #2
0
 public InsertTripCommand(Trip trip)
 {
     this.newTrip = trip;
 }
 public void InsertTrip(Trip trip)
 {
     state.InsertTrip(this, trip);
 }
        // 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();
            }
        }
Beispiel #5
0
 public virtual bool InsertTrip(UserNodeCore context, Communication.Trip trip)
 {
     return(false);
 }
        public Result InsertTrip(Trip newTrip)
        {
            Result insertionResult;

            /** Check if the current node is the nearest node to the
             * departure location.
             */
            string targetNode = NearestNodeToDeparture(newTrip.DepartureName);

            if (!targetNode.Equals(NodeName))
            {
                //Console.WriteLine("Decision: sending newTripCommand to : {0}", targetNode);
                ForwardRequiredResult forwardRequest = new ForwardRequiredResult();
                forwardRequest.RequestID = serviceImpl.generateGUID();
                forwardRequest.Destination = baseForwardAddress + targetNode;

                return forwardRequest;

            }
            else
            {
                Location departureLoc = GMapsAPI.addressToLocation(newTrip.DepartureName);
                Location arrivalLoc = GMapsAPI.addressToLocation(newTrip.ArrivalName);

                //Save the trip
                tripDatabaseLock.EnterWriteLock();
                try
                {
                    tripDatabase = XDocument.Load(tripDatabasePath);

                    int nextAvailableID = Convert.ToInt32(
                             (from trip in tripDatabase.Descendants("Trip")
                              orderby Convert.ToInt32(trip.Element("ID").Value) descending
                              select trip.Element("ID").Value).FirstOrDefault()) + 1;

                    newTrip.ID = nextAvailableID;

                    XElement newXmlTrip = new XElement("Trip",
                        new XElement("ID", newTrip.ID),
                        new XElement("Owner", newTrip.Owner),
                        new XElement("DepartureName", newTrip.DepartureName.ToLower()),
                        new XElement("DepartureLatitude",departureLoc.Latitude),
                        new XElement("DepartureLongitude",departureLoc.Longitude),
                        new XElement("DepartureDateTime", newTrip.DepartureDateTime),
                        new XElement("ArrivalName", newTrip.ArrivalName.ToLower()),
                        new XElement("ArrivalLatitude", arrivalLoc.Latitude),
                        new XElement("ArrivalLongitude", arrivalLoc.Longitude),
                        new XElement("ArrivalDateTime", newTrip.ArrivalDateTime),
                        new XElement("Smoke", newTrip.Smoke),
                        new XElement("Music", newTrip.Music),
                        new XElement("Cost", newTrip.Cost),
                        new XElement("FreeSits", newTrip.FreeSits),
                        new XElement("Notes", newTrip.Notes),
                        new XElement("Modifiable", newTrip.Modifiable)
                        );
                    tripDatabase.Element("Trips").Add(newXmlTrip);
                    tripDatabase.Save(tripDatabasePath);

                    Console.WriteLine("{0} Trip saved in {1}", serviceImpl.LogTimestamp, NodeName);
                    insertionResult = new InsertOkResult();
                    insertionResult.Comment = "The trip has been successfully inserted";
                    return insertionResult;
                }
                finally
                {
                    tripDatabaseLock.ExitWriteLock();

                }
            }// end else
        }
Beispiel #7
0
        /// <summary>
        /// Create some sample trips and save them into
        /// the trip database of a ServiceNodeCore. 
        /// </summary>
        public static void PopulateTripDB()
        {
            Console.Write("Initializing Trips DB... ");

            #region Sample trips

            Trip trip1 = new Trip
            {
                Owner = userList.ElementAt(0).UserName,
                DepartureName = "Catania",
                DepartureDateTime = new DateTime(2010, 7, 30, 8, 0, 0),
                ArrivalName = "Messina",
                ArrivalDateTime = new DateTime(2010, 7, 30, 10, 30, 0),
                Smoke = false,
                Music = false,
                Cost = 10,
                FreeSits = 4,
                Notes = "none",
                Modifiable = false
            };
            Trip trip2 = new Trip
            {
                Owner = userList.ElementAt(0).UserName,
                DepartureName = "Catania",
                DepartureDateTime = new DateTime(2010, 8, 4, 8, 0, 0),
                ArrivalName = "Messina",
                ArrivalDateTime = new DateTime(2010, 8, 4, 10, 30, 0),
                Smoke = false,
                Music = false,
                Cost = 100,
                FreeSits = 2,
                Notes = "none",
                Modifiable = false
            };
            Trip trip3 = new Trip
            {
                Owner = userList.ElementAt(0).UserName,
                DepartureName = "Catania",
                DepartureDateTime = new DateTime(2010, 8, 4, 18, 0, 0),
                ArrivalName = "Ragusa",
                ArrivalDateTime = new DateTime(2010, 8, 4, 20, 30, 0),
                Smoke = false,
                Music = false,
                Cost = 80,
                FreeSits = 3,
                Notes = "none",
                Modifiable = false
            };

            #endregion

            Trip[] trips = new Trip[] { trip1, trip2, trip3 };
            tripList.AddRange(trips);

            ServiceNodeCore randomNode = sncList.ElementAt(0);
            foreach (Trip t in tripList)
            {
                randomNode.InsertTrip(t);
            }

            Console.WriteLine("Done!");
        }