Example #1
0
 public override bool SearchTrip(UserNodeCore context, QueryBuilder qb)
 {
     Command command = new SearchTripCommand(qb);
     context.ServiceProxy.HandleDarPoolingRequest(command);
     return true;
 }
        public void HandleForwardedRangeSearch(Command command, string senderAddress, QueryBuilder query)
        {
            if (debug)
                Console.WriteLine("{0} {1} node received FWD_RangeSearch", LogTimestamp, receiver.NodeName.ToUpper());

            //AddFwdCommandService(fwdCommand.CommandID, rootSenderAddress);
        }
Example #3
0
 public virtual bool SearchTrip(UserNodeCore context, QueryBuilder qb)
 {
     return false;
 }
 public void SearchTrip(QueryBuilder qb)
 {
     state.SearchTrip(this, qb);
 }
Example #5
0
 public SearchTripCommand(QueryBuilder query)
 {
     this.queryBuilder = query;
 }
        // 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();
            }
        }
Example #7
0
 public SearchTripCommand(QueryBuilder query)
 {
     this.queryBuilder = query;
 }
        private IEnumerable<Trip> FilterQuery(QueryBuilder filterTrip, IEnumerable<Trip> filteringQuery)
        {
            /* Prefiltering */
            filteringQuery = from i in filteringQuery
                             where i.Smoke == filterTrip.Smoke && i.Music == filterTrip.Music
                             select i;
            filteringQuery = from i in filteringQuery
                             where DateTime.Compare(filterTrip.DepartureDateTime, i.DepartureDateTime) < 0 &&
                                   DateTime.Compare(filterTrip.ArrivalDateTime, i.ArrivalDateTime) < 0
                             select i;

            if (filterTrip.Owner != null)
            {
                filteringQuery = from i in filteringQuery
                                 where i.Owner == filterTrip.Owner
                                 select i;
            }

            if (filterTrip.ArrivalName != null)
            {
                filteringQuery = from i in filteringQuery
                                 where i.ArrivalName == filterTrip.ArrivalName.ToLower()
                                 select i;
            }

            if (filterTrip.Cost > 0)
            {
                filteringQuery = from i in filteringQuery
                                 where i.Cost < filterTrip.Cost
                                 select i;
            }

            IEnumerable<Trip> filteredQuery = filteringQuery;
            return filteredQuery;
        }
        public Result SearchTrip(QueryBuilder queryTrip)
        {
            // Error! Search range cannot be a negative number!
            if (queryTrip.Range < 0)
            {
                SearchTripError error = new SearchTripError();
                error.Comment = "Search range must be a non-negative number!";
                return error;
            }

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

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

                return forwardRequest;
            }

            // The Search has no range criteria. We can perform a simple search or
            // a simple forward request.
            if (queryTrip.Range == 0)
            {
                Console.WriteLine("Testing Range 0");
                List<Trip> matchingTrip = GetTripZeroRange(queryTrip);

                SearchTripResult searchResult = new SearchTripResult(matchingTrip);
                searchResult.OriginalQueryID = queryTrip.ID;
                Console.WriteLine("{0} {1} Trip(s) were found in {2}", serviceImpl.LogTimestamp, matchingTrip.Count, NodeName);

                return searchResult;

            }
            // The client specified a range for search: we need to do a more complex search
            // and potentially a multiple forwarding.
            else
            {

                Location departureLoc = GMapsAPI.addressToLocation(queryTrip.DepartureName);
                LocationRange departureLocRange = new LocationRange(departureLoc.Latitude, departureLoc.Longitude, queryTrip.Range);

                List<Trip> matchingTrip = GetTripWithRange(queryTrip, departureLocRange);

                SearchTripResult searchResult = new SearchTripResult(matchingTrip);
                searchResult.OriginalQueryID = queryTrip.ID;
                Console.WriteLine("{0} {1} Trip(s) were found in {2}", serviceImpl.LogTimestamp, matchingTrip.Count, NodeName);

                /** Check if there are other neighbour nodes within the range of search. */
                string[] targetNeighbours = NeighbourNodesInRange(departureLocRange);
                if (targetNeighbours.Length > 0)
                {
                    foreach (string n in targetNeighbours)
                    {
                        Console.WriteLine("{0} is in range.", n);
                    }

                    return new NullResult();

                }
                else
                {
                    //Console.WriteLine("No neighbour is in range.");
                    return searchResult;

                }

            }
        }
        public List<Trip> GetTripZeroRange(QueryBuilder filterTrip)
        {
            tripDatabaseLock.EnterReadLock();
            try
            {
                tripDatabase = XDocument.Load(tripDatabasePath);

                var baseQuery = (from t in tripDatabase.Descendants("Trip")
                                 where t.Element("DepartureName").Value.Equals(filterTrip.DepartureName.ToLower()) &&
                                       Convert.ToInt32(t.Element("FreeSits").Value) > 0
                                 select new Trip()
                                 {
                                     ID = Convert.ToInt32(t.Element("ID").Value),
                                     Owner = t.Element("Owner").Value,
                                     DepartureName = t.Element("DepartureName").Value,
                                     DepartureDateTime = Convert.ToDateTime(t.Element("DepartureDateTime").Value),
                                     ArrivalName = t.Element("ArrivalName").Value,
                                     ArrivalDateTime = Convert.ToDateTime(t.Element("ArrivalDateTime").Value),
                                     Smoke = Convert.ToBoolean(t.Element("Smoke").Value),
                                     Music = Convert.ToBoolean(t.Element("Music").Value),
                                     Cost = Convert.ToDouble(t.Element("Cost").Value),
                                     FreeSits = Convert.ToInt32(t.Element("FreeSits").Value),
                                     Notes = t.Element("Notes").Value,
                                     Modifiable = Convert.ToBoolean(t.Element("Modifiable").Value)
                                 });

                IEnumerable<Trip> filteredQuery = FilterQuery(filterTrip, baseQuery);
                return filteredQuery.ToList();
            }
            finally
            {
                tripDatabaseLock.ExitReadLock();
            }
        }