Example #1
0
        public override bool SearchTrip(UserNodeCore context, QueryBuilder qb)
        {
            Command command = new SearchTripCommand(qb);

            context.ServiceProxy.HandleDarPoolingRequest(command);
            return(true);
        }
Example #2
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;
 }
Example #3
0
        public override bool RegisterUser(UserNodeCore context, User user,
                                          string serviceNodeAddress, string callbackAddress)
        {
            try
            {
                ClientCallback callback = new ClientCallback(context);

                // First of all, set up the connection
                EndpointAddress   endPointAddress = new EndpointAddress(serviceNodeAddress);
                WSDualHttpBinding binding         = new WSDualHttpBinding();
                binding.ClientBaseAddress = new Uri(callbackAddress);
                DuplexChannelFactory <IDarPooling> factory = new DuplexChannelFactory <IDarPooling>(
                    callback, binding, endPointAddress);
                context.ServiceProxy = factory.CreateChannel();
            }
            catch
            {
                context.ServiceProxy = null;
                return(false);
            }

            Command c = new Communication.RegisterUserCommand(user);

            try
            {
                context.ServiceProxy.HandleDarPoolingRequest(c);
            }
            catch (TimeoutException e)
            {
                context.ServiceProxy = null;
                throw e;
            }
            return(true);
        }
Example #4
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);
        }
Example #5
0
        public override bool Unjoin(UserNodeCore context)
        {
            Command command = new UnjoinCommand(context.UserNode.User.UserName);
            context.ServiceProxy.HandleDarPoolingRequest(command);
            context.State = new UnjointState();
            context.ServiceProxy = null;

            return true;
        }
Example #6
0
        public override bool Unjoin(UserNodeCore context)
        {
            Command command = new UnjoinCommand(context.UserNode.User.UserName);

            context.ServiceProxy.HandleDarPoolingRequest(command);
            context.State        = new UnjointState();
            context.ServiceProxy = null;

            return(true);
        }
Example #7
0
        static void InitializeClient()
        {
            CreateUsers();

            /* Clients */
            UserNode catania1UN = new UserNode(userList.ElementAt(0), "Catania");
            UserNode catania2UN = new UserNode(userList.ElementAt(1), "Catania");
            //UserNode milano1UN = new UserNode("4nT0", "Milano");

            UserNodeCore catania1 = new UserNodeCore(catania1UN);
            UserNodeCore catania2 = new UserNodeCore(catania2UN);

            //UserNodeCore milano1 = new UserNodeCore(milano1UN);

            UserNodeCore[] userNodes =
                new UserNodeCore[] { catania1, catania2 };

            uncList.AddRange(userNodes);
        }
Example #8
0
        /* Callback */
        static void StartCommunication()
        {
            Console.WriteLine("*****  Test HTTP CALLBACK Client  *****");
            Console.WriteLine("\n\nPress a key to start the communication");
            Console.ReadLine();

            User         testUser1   = userList.ElementAt(0);
            UserNodeCore testClient1 = uncList.ElementAt(0);

            LoginUserCommand login = new LoginUserCommand(testUser1.UserName, testUser1.Password);

            testClient1.ConnectToService(login);
            Console.WriteLine("\n\n\nClient is now ready to perform some other task");

            User         testUser2   = userList.ElementAt(1);
            UserNodeCore testClient2 = uncList.ElementAt(1);

            Console.WriteLine("\n\n\nProvo a connettermi....");
            testClient2.ConnectToService(login);
            Console.WriteLine("\n\n\nConnessione effettuata!");
        }
Example #9
0
        public override bool Join(UserNodeCore context, string username, string password,
                                  string serviceNodeAddress, string callbackAddress)
        {
            try
            {
                ClientCallback callback = new ClientCallback(context);

                // First of all, set up the connection
                EndpointAddress   endPointAddress = new EndpointAddress(serviceNodeAddress);
                WSDualHttpBinding binding         = new WSDualHttpBinding();
                binding.ClientBaseAddress = new Uri(callbackAddress);
                DuplexChannelFactory <IDarPooling> factory = new DuplexChannelFactory <IDarPooling>(
                    callback, binding, endPointAddress);
                context.ServiceProxy = factory.CreateChannel();
            }
            catch
            {
                context.ServiceProxy = null;
                return(false);
            }

            // Now, hopefully you have a working ServiceProxy.
            string  passwordHash = Communication.Tools.HashString(password);
            Command c            = new JoinCommand(context.UserNode, username, passwordHash);

            try
            {
                context.ServiceProxy.HandleDarPoolingRequest(c);
            }
            catch (TimeoutException e)
            {
                context.ServiceProxy = null;
                throw e;
            }

            // Finally, if Join is NOT successfull, remove reference (UserNodeCore.onResultReceive)
            return(true);
        }
Example #10
0
        public override bool RegisterUser(UserNodeCore context, User user,
            string serviceNodeAddress, string callbackAddress)
        {
            try
            {
                ClientCallback callback = new ClientCallback(context);

                // First of all, set up the connection
                EndpointAddress endPointAddress = new EndpointAddress(serviceNodeAddress);
                WSDualHttpBinding binding = new WSDualHttpBinding();
                binding.ClientBaseAddress = new Uri(callbackAddress);
                DuplexChannelFactory<IDarPooling> factory = new DuplexChannelFactory<IDarPooling>(
                        callback, binding, endPointAddress);
                context.ServiceProxy = factory.CreateChannel();
            }
            catch
            {
                context.ServiceProxy = null;
                return false;
            }

            Command c = new Communication.RegisterUserCommand(user);

            try
            {
                context.ServiceProxy.HandleDarPoolingRequest(c);
            }
            catch (TimeoutException e)
            {
                context.ServiceProxy = null;
                throw e;
            }
            return true;
        }
Example #11
0
 public virtual bool Unjoin(UserNodeCore context)
 {
     return false;
 }
Example #12
0
        public override bool Join(UserNodeCore context, string username, string password,
            string serviceNodeAddress, string callbackAddress)
        {
            try
            {
                ClientCallback callback = new ClientCallback(context);

                // First of all, set up the connection
                EndpointAddress endPointAddress = new EndpointAddress(serviceNodeAddress);
                WSDualHttpBinding binding = new WSDualHttpBinding();
                binding.ClientBaseAddress = new Uri(callbackAddress);
                DuplexChannelFactory<IDarPooling> factory = new DuplexChannelFactory<IDarPooling>(
                        callback, binding, endPointAddress);
                context.ServiceProxy = factory.CreateChannel();
            }
            catch
            {
                context.ServiceProxy = null;
                return false;
            }

            // Now, hopefully you have a working ServiceProxy.
            string passwordHash = Communication.Tools.HashString(password);
            Command c = new JoinCommand(context.UserNode, username, passwordHash);

            try
            {
                context.ServiceProxy.HandleDarPoolingRequest(c);
            }
            catch (TimeoutException e)
            {
                context.ServiceProxy = null;
                throw e;
            }

            // Finally, if Join is NOT successfull, remove reference (UserNodeCore.onResultReceive)
            return true;
        }
Example #13
0
 public virtual bool RegisterUser(UserNodeCore context, User user, string serviceNodeAddress, string callbackAddress)
 {
     return(false);
 }
Example #14
0
 public virtual bool SearchTrip(UserNodeCore context, QueryBuilder qb)
 {
     return false;
 }
Example #15
0
 public ClientCallback(UserNodeCore parent)
 {
     this.parent = parent;
 }
Example #16
0
 public virtual bool Join(UserNodeCore context, string username, string password, string serviceNodeAddress, string callbackAddress)
 {
     return(false);
 }
Example #17
0
 public ClientCallback(UserNodeCore parent)
 {
     this.parent = parent;
 }
Example #18
0
 public virtual bool Join(UserNodeCore context, string username, string password, string serviceNodeAddress, string callbackAddress)
 {
     return false;
 }
Example #19
0
 public virtual bool Unjoin(UserNodeCore context)
 {
     return(false);
 }
Example #20
0
 public virtual bool InsertTrip(UserNodeCore context, Communication.Trip trip)
 {
     return(false);
 }
Example #21
0
 public virtual bool SearchTrip(UserNodeCore context, QueryBuilder qb)
 {
     return(false);
 }
Example #22
0
 public override bool SearchTrip(UserNodeCore context, QueryBuilder qb)
 {
     Command command = new SearchTripCommand(qb);
     context.ServiceProxy.HandleDarPoolingRequest(command);
     return true;
 }
Example #23
0
        static void InitializeClient()
        {
            CreateUsers();

            /* Clients */
            UserNode catania1UN = new UserNode(userList.ElementAt(0), "Catania");
            UserNode catania2UN = new UserNode(userList.ElementAt(1), "Catania");
            //UserNode milano1UN = new UserNode("4nT0", "Milano");

            UserNodeCore catania1 = new UserNodeCore(catania1UN);
            UserNodeCore catania2 = new UserNodeCore(catania2UN);
            //UserNodeCore milano1 = new UserNodeCore(milano1UN);

            UserNodeCore[] userNodes =
                new UserNodeCore[] { catania1, catania2
                                   };

            uncList.AddRange(userNodes);
        }
Example #24
0
 public virtual bool InsertTrip(UserNodeCore context, Communication.Trip trip)
 {
     return false;
 }
Example #25
0
        // 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 #26
0
 public virtual bool RegisterUser(UserNodeCore context, User user, string serviceNodeAddress, string callbackAddress)
 {
     return false;
 }
Example #27
0
        // 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();
            }
        }