Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
0
 public virtual bool RegisterUser(UserNodeCore context, User user, string serviceNodeAddress, string callbackAddress)
 {
     return false;
 }
Ejemplo n.º 3
0
 public RegisterUserCommand(User newUser)
 {
     this.newUser = newUser;
 }
Ejemplo n.º 4
0
 public UserNode(User user, string userLocationName)
     : base(user.UserName)
 {
     this.user = user;
     this.userLocationName = userLocationName;
 }
Ejemplo n.º 5
0
 public void RegisterUser(User user, string registrarAddress)
 {
     state.RegisterUser(this, user, registrarAddress, "http://localhost:2222");
 }
Ejemplo n.º 6
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();
            }
        }
Ejemplo n.º 7
0
        public static void CreateUsers()
        {
            User daniele = new User
            {
                UserName = "******",
                Password = "******",
                Name = "Daniele",
                UserSex = User.Sex.m,
                BirthDate = new DateTime(1986, 04, 08),
                Email = "*****@*****.**",
                Smoker = false,
                SignupDate = DateTime.Today.AddDays(-30)
            };

            User ubuntu = new User
            {
                UserName = "******",
                Password = "******",
                Name = "Ubuntu",
                UserSex = User.Sex.m,
                BirthDate = new DateTime(1987, 06, 12),
                Email = "*****@*****.**",
                Smoker = false,
                SignupDate = DateTime.Today.AddDays(-30),
                Whereabouts = "Linux for human being"
            };

            User[] users =
                new User[] { daniele, ubuntu
                           };

            userList.AddRange(users);
        }
Ejemplo n.º 8
0
        public Result RegisterUser(User newUser)
        {
            // Enter the critical section in upgradeable mode.
            userDatabaseLock.EnterUpgradeableReadLock();
            try
            {
                userDatabase = XDocument.Load(userDatabasePath);

                // Determine if the provided username has been already taken
                var sameUserName = (from u in userDatabase.Descendants("User")
                                    where u.Attribute("principal").Value.Equals(newUser.UserName)
                                    select u);

                // The username is already present. The user must choose another one.
                if (sameUserName.Count() != 0)
                {
                    Result error = new RegisterErrorResult();
                    error.Comment = "Sorry, this UserName is already present.";
                    return error;
                }
                else //Register the user
                {
                    // Build the final username.
                    string darPoolingUsername = newUser.UserName + "@" + baseHTTPAddress + NodeName;
                    // Extract the next ID from the database
                    int nextAvailableID = Convert.ToInt32(
                                     (from user in userDatabase.Descendants("User")
                                      orderby Convert.ToInt32(user.Element("UserID").Value) descending
                                      select user.Element("UserID").Value).FirstOrDefault()) + 1;

                    newUser.UserID = nextAvailableID;

                    // Create the XML entity that represent the User in the database.
                    XElement newXmlUser = new XElement("User",
                        new XElement("UserID", newUser.UserID),
                        new XElement("UserName", darPoolingUsername),
                        new XElement("Password", newUser.PasswordHash), // FIXME: should store hash, not password
                        new XElement("Name", newUser.Name),
                        new XElement("Sex", newUser.UserSex),
                        new XElement("BirthDate", newUser.BirthDate),
                        new XElement("Email", newUser.Email),
                        new XElement("Smoker", newUser.Smoker),
                        new XElement("SignupDate", newUser.SignupDate),
                        new XElement("Whereabouts", newUser.Whereabouts)
                    );

                    // Maintain the info about the provided username
                    newXmlUser.SetAttributeValue("principal", newUser.UserName);

                    //Register the user: upgrade to Write mode
                    userDatabaseLock.EnterWriteLock();
                    //Console.WriteLine("{0} thread obtains the write lock", Thread.CurrentThread.Name);
                    try
                    {
                        userDatabase.Element("Users").Add(newXmlUser);
                        userDatabase.Save(userDatabasePath);
                    }
                    finally
                    {
                        //Console.WriteLine("{0} thread releases the write lock", Thread.CurrentThread.Name);
                        userDatabaseLock.ExitWriteLock();
                    }

                    RegisterOkResult success = new RegisterOkResult();
                    success.Comment = "User successfully registered! Your username is : " + darPoolingUsername;
                    success.FinalUsername = darPoolingUsername;
                    return success;

                } // End else

            } // End try upgradable
            finally
            {
                //Console.WriteLine("{0} thread releases the upgradeable lock", Thread.CurrentThread.Name);
                userDatabaseLock.ExitUpgradeableReadLock();
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Create some sample users and save them into
        /// the user database of a ServiceNodeCore.
        /// </summary>
        public static void PopulateUserDB()
        {
            Console.WriteLine("Initializing Users DB... \n");

            #region Create some sample user
            User daniele = 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 = ""
            };

            User antonio = new User
            {
                UserName = "******",
                Password = "******",
                Name = "Antonio",
                UserSex = User.Sex.m,
                BirthDate = new DateTime(1987, 06, 12),
                Email = "*****@*****.**",
                Smoker = false,
                SignupDate = DateTime.Now.AddDays(-30),
                Whereabouts = ""
            };
            #endregion

            User[] users =new User[] { daniele, antonio };
            userList.AddRange(users);

            ServiceNodeCore firstNode = sncList.First();
            ServiceNodeCore lastNode = sncList.Last();
            Thread[] threads = new Thread[4];

            //Thread registerThread;

            foreach (ServiceNodeCore snc in sncList)
            {
                snc.RegisterUser(daniele);
                snc.RegisterUser(antonio);

            }

            /*
            threads[0] = new Thread(() => firstNode.RegisterUser(daniele));
            threads[0].Name = "Register Daniele";

            threads[1] = new Thread(() => lastNode.RegisterUser(antonio));
            threads[1].Name = "Register Antonio";

            //threads[2] = new Thread(() => firstNode.RegisterUser(dummy));
            //threads[2].Name = "Register Dummy";
            //threads[2].Start();

            /*
            threads[2] = new Thread(() => firstNode.Join("Shaoran","shaoran"));
            threads[2].Name = "Join Daniele";

            threads[3] = new Thread(() => firstNode.Unjoin("Shaoran"));
            threads[3].Name = "UnJoin Daniele ";

            // Testing the concurrency
            threads[0].Start();
            threads[1].Start();
            */
            //Thread.Sleep(200);
            //threads[2].Start();
            //Thread.Sleep(1000);
            //Thread.Sleep(500);
            //threads[3].Start();

            //Console.WriteLine("Done!");
        }