Exemple #1
0
        public Profile loadProfileFromDB(string userName, Profile userProfile)
        {
            //open the DB connection
            db.OpenConnection();

            //exec the query to the users information
            DataTable userInfo = db.ExecuteSQL("SELECT * FROM userInfo WHERE nickname='" + userName + "';");

            //assign all the vars in the class
            userProfile.NickName  = userName;
            userProfile.Sex       = (string)userInfo.Rows[0]["sex"];
            userProfile.Weight    = (int)userInfo.Rows[0]["weight"];
            userProfile.Age       = (int)userInfo.Rows[0]["age"];
            userProfile.Race      = (int)(userInfo.Rows[0]["race"]);
            userProfile.Hair      = (int)userInfo.Rows[0]["hair"];
            userProfile.Height_ft = (int)userInfo.Rows[0]["height_ft"];
            userProfile.Height_in = (int)userInfo.Rows[0]["height_in"];
            userProfile.Interest1 = (int)userInfo.Rows[0]["interest_1"];
            userProfile.Interest2 = (int)userInfo.Rows[0]["interest_2"];
            userProfile.Interest3 = (int)userInfo.Rows[0]["interest_3"];

            //close the DB connection
            db.CloseConnection();

            //return a reference to the newly filled Profile
            return userProfile;
        }
Exemple #2
0
        static void Main(string[] args)
        {
            // THIS IS THE VISUAL STUDIO BUG
            //After apdating the web service we need to commented out the declaration of webService Profile object
            // In order to do so -- uncomment next line , right click , go to defenition in comment the whole declaration
            // of Profile and then declare the lib : using NoIdeas.Lib;
              // NoIdeas.Client.cloudWebRef.Profile

            // This is our webService reference
            // using it we can call all the methods of the web Service
            cloudWebRef.NoIdeasWebService service = new cloudWebRef.NoIdeasWebService();
            // Creating the Profile the same way we will create it on the phone from profile page
            Profile profile = new Profile();

            profile.NickName = "Second one";
            profile.Distance = 90;
             //  NoIdeas.Client.cloudWebRef.MatchedResults[]
            // NoIdeas.Client.cloudWebRef.DatingProfile

            List<MatchedResults> test = service.RunAndFindMatches(profile, null);
              //  NoIdeas.Phone.Lib.MatchedResults[]

               // NoIdeas.Client.cloudWebRef.MatchedResults[]
            foreach(MatchedResults match in test){
                Console.WriteLine(match.Name);
            }
            Console.WriteLine(service.GetNumberOfActiveUsers());

            //Console.WriteLine(service.Url);
               // service.Url = "http://noideaswebservice.cloudapp.net/NoIdeasWebService.asmx";
               // Console.WriteLine(service.Url);
               // Console.WriteLine(service.LoginCheck("test1", "pass"));
               // Console.WriteLine(service.GetUserProfile("kot").Interest);

            Console.ReadLine();

            // Now we going to call UpdateProfile method of the web Service which will
            // Checks if the user has an account; If true set online in DataBase to true
            // and adds user to the activeUser Set; else adds user information to the DataBase and
            // to the active user Set and return true on success and false otherwise

              //  Console.WriteLine( service.UpdateProfile(profile));
            //    Console.WriteLine(service.GetNumberOfActiveUsers());
               // Console.WriteLine(service.EndSession(profile));
               //     Console.WriteLine(service.GetNumberOfActiveUsers());
            Console.ReadLine();
               // NoIdeas.Client.cloudWebRef.Profile
        }
Exemple #3
0
 /// <summary>
 /// Deletes the user form the activeUser set and change the online status in DataBase
 /// </summary>
 /// <param name="profile"></param>
 /// <returns></returns>
 public bool EndSession(Profile profile)
 {
     User user = ProfileToUser(profile);
     // Remove user from the Active Users set
     activeUsers.Remove(user);
     // Turn off theonline bit in DB
     int result = 0;
     try
     {
         db.OpenConnection();
         result = db.ExecuteSql(UpdateUserQuery(profile, 0));
     }
     catch (Exception ex)
     { }
     // No matter what - we have to close DataBase connection
     finally
     {
         db.CloseConnection();
     }
     if (result == 1)
         return true;
     else
         return false;
 }
Exemple #4
0
 /// <remarks/>
 public void RunAndFindMatchesAsync(Profile profile, DatingProfile dprofile) {
     this.RunAndFindMatchesAsync(profile, dprofile, null);
 }
Exemple #5
0
 public List<MatchedResults> RunAndFindMatches(Profile profile, DatingProfile dprofile) {
     object[] results = this.Invoke("RunAndFindMatches", new object[] {
                 profile,
                 dprofile});
     return ((List<MatchedResults>)(results[0]));
 }
Exemple #6
0
 /// <summary>
 /// Returns the query to checj if the user's info is alredy in DB (means existing user)
 /// </summary>
 /// <param name="profile">User profile</param>
 /// <returns>sql query</returns>
 private string CheckForUserQuery(Profile profile)
 {
     string sql = string.Format("Select * From [noIdeas].[dbo].[userInfo] Where nickname ='{0}' ",profile.NickName);
     return sql;
 }
Exemple #7
0
 public bool UpdateProfile(Profile profile)
 {
     object[] results = this.Invoke("UpdateProfile", new object[] {
                 profile});
     return ((bool)(results[0]));
 }
Exemple #8
0
 public bool EndSession(Profile profile)
 {
     object[] results = this.Invoke("EndSession", new object[] {
                 profile});
     return ((bool)(results[0]));
 }
Exemple #9
0
 /// <remarks/>
 public System.IAsyncResult BeginInsertNewUser(Profile profile, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("InsertNewUser", new object[] {
                 profile}, callback, asyncState);
 }
Exemple #10
0
 /// <remarks/>
 public void EndSessionAsync(Profile profile, object userState) {
     if ((this.EndSessionOperationCompleted == null)) {
         this.EndSessionOperationCompleted = new System.Threading.SendOrPostCallback(this.OnEndSessionOperationCompleted);
     }
     this.InvokeAsync("EndSession", new object[] {
                 profile}, this.EndSessionOperationCompleted, userState);
 }
 public bool EndSession(Profile profile)
 {
     WorkerClass worker = new WorkerClass();
     return worker.EndSession(profile);
 }
Exemple #12
0
        public double matchPercentage(String user1, String user2)
        {
            db = new DataBaseWorker(connectionString);
            //get each users profile information
            Profile userOne = new Profile();
            userOne = loadProfileFromDB(user1, userOne);
            Profile userTwo = new Profile();
            userTwo = loadProfileFromDB(user2, userTwo);
            DatingProfile userOneWants = new DatingProfile();
            userOneWants = loadDatingProfileFromDB(user1, userOneWants);
            DatingProfile userTwoWants = new DatingProfile();
            userTwoWants = loadDatingProfileFromDB(user1, userTwoWants);

            //keep a running total of the total points
            double total_points = 0;

            //If height is in range add points (MAX 10)
            //check if userOne is in userTwos range
            if (userOne.Height_ft >= userTwoWants.Min_Height_ft && userOne.Height_ft <= userTwoWants.Max_Height_ft &&
                userOne.Height_in >= userTwoWants.Min_Height_in && userOne.Height_in <= userTwoWants.Min_Height_in)
            {
                total_points += 10;
            }
            //check if userTwo is in userOnes range

            if (userTwo.Height_ft >= userOneWants.Min_Height_ft && userTwo.Height_ft <= userOneWants.Max_Height_ft &&
                userTwo.Height_in >= userOneWants.Min_Height_in && userTwo.Height_in <= userOneWants.Min_Height_in)
            {
                total_points += 10;
            }

            //If weight is in range add points (MAX 10)
            //check if userOne is in userTwos range
            if (userOne.Weight >= userTwoWants.Min_Weight && userOne.Weight <= userTwoWants.Max_Weight)
            {
                total_points += 10;
            }
            //check if userTwo is in userOnes range
            if (userTwo.Weight >= userOneWants.Min_Weight && userTwo.Weight <= userOneWants.Max_Weight)
            {
                total_points += 10;
            }

            //If age is in range add points (MAX 10)
            //check if userOne is in userTwos range
            if (userOne.Age >= userTwoWants.Min_Age && userOne.Age <= userTwoWants.Max_Age)
            {
                total_points += 10;
            }
            //check if userTwo is in userOnes range
            if (userTwo.Age >= userOneWants.Min_Age && userTwo.Age <= userOneWants.Max_Age)
            {
                total_points += 10;
            }

            //10 points for race match
            if (userOne.Race == userTwoWants.Race)
            {
                total_points += 10;
            }
            if (userTwo.Race == userOneWants.Race)
            {
                total_points += 10;
            }

            //10 points for hair match
            if (userOne.Hair == userTwoWants.Hair)
            {
                total_points += 10;
            }
            if (userTwo.Hair == userOneWants.Hair)
            {
                total_points += 10;
            }

            //10 points for each matching interest
            if (userOne.Interest1 == userTwoWants.Interest1)
            {
                total_points += 10;
            }
            if (userTwo.Interest1 == userOneWants.Interest1)
            {
                total_points += 10;
            }
            //interest 2
            if (userOne.Interest2 == userTwoWants.Interest2)
            {
                total_points += 10;
            }
            if (userTwo.Interest2 == userOneWants.Interest2)
            {
                total_points += 10;
            }
            //interest 3
            if (userOne.Interest3 == userTwoWants.Interest3)
            {
                total_points += 10;
            }
            if (userTwo.Interest3 == userOneWants.Interest3)
            {
                total_points += 10;
            }

            return Math.Round((total_points / 160) * 100, 2);
        }
Exemple #13
0
        /// <summary>
        /// Helper method which returns the sql stetament for Updating user Info  
        /// </summary>
        /// <returns></returns>
        private string UpdateUserQuery(Profile profile, int online)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat("UPDATE [noIdeas].[dbo].[userInfo] " +
                "SET [online] = '{0}' Where nickname = '{1}' ",online, profile.NickName);

            return sql.ToString();
        }
Exemple #14
0
 /// <summary>
 /// Creates User object from the Profile
 /// </summary>
 /// <param name="profile">Profile</param>
 /// <returns>User</returns>
 private User ProfileToUser(Profile profile)
 {
     string nickName = profile.NickName;
     double distanceRange = profile.Distance;
     double latitude = profile.Latitude;
     double longitude = profile.Longitude;
     int phone = profile.Phone;
     // Create new User
     User user = new User(nickName, distanceRange, latitude, longitude, phone);
     return user;
 }
Exemple #15
0
        /// <summary>
        /// Returns the query to insert new user Info into the DB
        /// </summary>
        /// <param name="profile"></param>
        /// <returns></returns>
        private string InsertNewUserQuery(Profile profile)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat("INSERT INTO [noIdeas].[dbo].[userInfo]" +
                "([nickname],[firstname],[lastname],[sex],[age],[online],[race],[height_ft],[height_in], " +
                "[weight],[hair],[interest_1],[interest_2],[interest_3],[password],[phone_number]) " +
                "VALUES ('{0}','{1}', '{2}', '{3}','{4}','{5}', '{6}', '{7}', '{8}','{9}','{10}','{11}', '{12}','{13}', '{14}', '{15}' )",
                profile.NickName, profile.Name, profile.LastName, profile.Sex, profile.Age, profile.Online, profile.Race,
                profile.Height_ft, profile.Height_in, profile.Weight, profile.Hair, profile.Interest1, profile.Interest2, profile.Interest3, profile.Password, profile.Phone);

            return sql.ToString();
        }
Exemple #16
0
 /// <remarks/>
 public void RunAndFindMatchesAsync(Profile profile, DatingProfile dprofile, object userState) {
     if ((this.RunAndFindMatchesOperationCompleted == null)) {
         this.RunAndFindMatchesOperationCompleted = new System.Threading.SendOrPostCallback(this.OnRunAndFindMatchesOperationCompleted);
     }
     this.InvokeAsync("RunAndFindMatches", new object[] {
                 profile,
                 dprofile}, this.RunAndFindMatchesOperationCompleted, userState);
 }
Exemple #17
0
 /// <remarks/>
 public void EndSessionAsync(Profile profile) {
     this.EndSessionAsync(profile, null);
 }
 public bool UpdateProfile(Profile profile)
 {
     WorkerClass worker = new WorkerClass();
     return worker.UpdateProfile(profile);
 }
Exemple #19
0
 /// <remarks/>
 public System.IAsyncResult BeginEndSession(Profile profile, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("EndSession", new object[] {
                 profile}, callback, asyncState);
 }
Exemple #20
0
 /// <remarks/>
 public void UpdateProfileAsync(Profile profile) {
     this.UpdateProfileAsync(profile, null);
 }
Exemple #21
0
 /// <remarks/>
 public System.IAsyncResult BeginUpdateProfile(Profile profile, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("UpdateProfile", new object[] {
                 profile}, callback, asyncState);
 }
Exemple #22
0
 /// <remarks/>
 public void UpdateProfileAsync(Profile profile, object userState) {
     if ((this.UpdateProfileOperationCompleted == null)) {
         this.UpdateProfileOperationCompleted = new System.Threading.SendOrPostCallback(this.OnUpdateProfileOperationCompleted);
     }
     this.InvokeAsync("UpdateProfile", new object[] {
                 profile}, this.UpdateProfileOperationCompleted, userState);
 }
Exemple #23
0
 public bool InsertNewUser(Profile profile)
 {
     object[] results = this.Invoke("InsertNewUser", new object[] {
                 profile});
     return ((bool)(results[0]));
 }
Exemple #24
0
 /// <remarks/>
 public void InsertNewUserAsync(Profile profile) {
     this.InsertNewUserAsync(profile, null);
 }
Exemple #25
0
 /// <remarks/>
 public void InsertNewUserAsync(Profile profile, object userState) {
     if ((this.InsertNewUserOperationCompleted == null)) {
         this.InsertNewUserOperationCompleted = new System.Threading.SendOrPostCallback(this.OnInsertNewUserOperationCompleted);
     }
     this.InvokeAsync("InsertNewUser", new object[] {
                 profile}, this.InsertNewUserOperationCompleted, userState);
 }
Exemple #26
0
        /// <summary>
        /// Checks if the user has an account; If true set online in DataBase to true 
        /// and adds user to the activeUser Set; else adds user information to the DataBase and 
        /// to the active user Set
        /// </summary>
        /// <param name="profile">User Profile</param>
        /// <returns>True/False</returns>
        public bool UpdateProfile(Profile profile)
        {
            // Create User from Profile in order to store in activeUsers HashSet
            User user = ProfileToUser(profile);
            // Since activeUser is a set - we don't have to check for duplicates
            //(We overrided Equal and GetHashCode for the User class)
            activeUsers.Add(user);
            int result = 0;
            try
            {
                db.OpenConnection();
                // Check if the user info is already in DB
               DataTable dt = db.ExecuteSQL(CheckForUserQuery(profile));
               if (dt.Rows.Count == 0)
               // It's a new user we will need enter his information to DB
               {
                 result = db.ExecuteSql(InsertNewUserQuery(profile));
               }
               // It's existing user all we need to do change online bit to be true
               else
               {
                  result = db.ExecuteSql(UpdateUserQuery(profile, 1));
               }
            }
            catch (Exception ex)
            {

            }
            // No matter what happed we need to close DataBase connection
            finally
            {
                db.CloseConnection();
            }
            if (result == 1)
                return true;
            else
                return false;
        }