示例#1
0
        /// <summary>
        /// Gets all contacts created on server after the last contact was created locally
        /// </summary>
        public async Task SyncUserContacts(string useremail, string serverurl)
        {
            try {
                //- Get User's GlobalID
                UserModel user = await GetUserDetails(useremail);

                if (user == null)
                {
                    throw new Exception("User not found while trying to sync user contacts");
                }

                //- Get the last added contact added to local database
                List <ContactModel> contacts = await GetUserContacts(user.GlobalID);

                if (contacts.Count == 0)
                {
                    return;
                }

                //- Get all contacts created on Server after the last local contact was created
                DateTime        lastContactCreated = contacts[contacts.Count - 1].DateCreated;
                RestDataManager restmanager        = new RestDataManager(serverurl);

                List <UserModel> recentcontacts = await restmanager.GetUserContacts(useremail, lastContactCreated);

                //- add new contacts to local database
                foreach (UserModel u in recentcontacts)
                {
                    await InsertContact(u);
                }
            } catch (Exception ex) {
                Debug.WriteLine(string.Format("The following exception occurred in (ClientDatabaseManager.SyncUserContacts) {0}", ex.Message));
                return;
            }
        }
示例#2
0
        /// <summary>
        /// Syncs the user with server.
        /// </summary>
        public async Task <UserModel> SyncUserWithServer(string email, string serverurl)
        {
            RestDataManager restmanager = new RestDataManager(serverurl);

            UserModel serveruser = null;
            UserModel localuser  = null;

            try {
                Task getserver = Task.Factory.StartNew(async() => {
                    serveruser = await restmanager.GetUserInfo(email);
                });

                Task getlocal = Task.Factory.StartNew(async() => {
                    localuser = await GetUserDetails(email);
                });

                if (serveruser == null)
                {
                    throw new Exception(string.Format("Unable to retrieve user: {0} from server: {1}", email, serverurl));
                }

                //- Insert user locally if not available on client database
                if (localuser == null)
                {
                    InsertUserDetails(serveruser);
                }

                Task.WaitAll(new Task[] { getserver, getlocal });

                //- update local user if changes have been made on the server
                if (serveruser != null && localuser != null && serveruser.LastModified > localuser.LastModified)
                {
                    UpdateUser(serveruser);
                }

                return(serveruser);
            } catch (Exception ex) {
                throw ex;
            }
        }
		/// <summary>
		/// Gets all contacts created on server after the last contact was created locally
		/// </summary>
		public async Task SyncUserContacts(string useremail, string serverurl){

			try {
				//- Get User's GlobalID
				UserModel user = await GetUserDetails (useremail);

				if (user == null)
					throw new Exception ("User not found while trying to sync user contacts");

				//- Get the last added contact added to local database
				List<ContactModel> contacts = await GetUserContacts (user.GlobalID);

				if(contacts.Count == 0)
					return;
				
				//- Get all contacts created on Server after the last local contact was created
				DateTime lastContactCreated = contacts[contacts.Count - 1].DateCreated;
				RestDataManager restmanager = new RestDataManager(serverurl);

				List<UserModel> recentcontacts = await restmanager.GetUserContacts(useremail, lastContactCreated);

				//- add new contacts to local database
				foreach(UserModel u in recentcontacts)
					await InsertContact(u);
				


			} catch (Exception ex) {
				Debug.WriteLine (string.Format ("The following exception occurred in (ClientDatabaseManager.SyncUserContacts) {0}", ex.Message));
				return;
			}


		}
		/// <summary>
		/// Syncs the user with server.
		/// </summary>
		public async Task<UserModel> SyncUserWithServer(string email, string serverurl){
			RestDataManager restmanager = new RestDataManager (serverurl);

			UserModel serveruser = null;
			UserModel localuser = null;

			try {
				Task getserver = Task.Factory.StartNew (async () => {
					serveruser = await restmanager.GetUserInfo (email);
				});

				Task getlocal = Task.Factory.StartNew (async () => {
					localuser = await GetUserDetails (email);
				});

				if(serveruser == null)
					throw new Exception(string.Format("Unable to retrieve user: {0} from server: {1}", email,serverurl));

				//- Insert user locally if not available on client database
				if(localuser == null)
					InsertUserDetails(serveruser);

				Task.WaitAll (new Task[]{ getserver, getlocal });

				//- update local user if changes have been made on the server
				if (serveruser != null && localuser != null && serveruser.LastModified > localuser.LastModified) {
					UpdateUser (serveruser);
				}

				return serveruser;

			} catch (Exception ex) {
				throw ex;
			}

		}