public bool BeginSyncTransaction ()
		{
			// TODO: Check connection and auth (is getting root/user resources a sufficient check?)
			root = RootInfo.GetRoot (rootUri, connection);
			user = UserInfo.GetUser (root.User.ApiRef, connection);
			if (user.LatestSyncRevision.HasValue)
				LatestRevision = user.LatestSyncRevision.Value;
			else
				VerifyLatestSyncRevision (user.LatestSyncRevision);

			if (string.IsNullOrEmpty (user.CurrentSyncGuid))
				throw new TomboySyncException ("No sync GUID for user provided in server response");
			
			pendingCommits = new List<NoteInfo> ();
			return true;
		}
Exemple #2
0
		public static UserInfo ParseJson (string jsonString)
		{
			Hyena.Json.Deserializer deserializer =
				new Hyena.Json.Deserializer (jsonString);
			object obj = deserializer.Deserialize ();

			Hyena.Json.JsonObject jsonObj =
				obj as Hyena.Json.JsonObject;
			if (jsonObj == null)
				throw new ArgumentException ("jsonString does not contain a valid UserInfo representation");

			// TODO: Checks
			UserInfo user = new UserInfo ();
			user.UserName = (string) jsonObj ["user-name"];
			user.FirstName = (string) jsonObj ["first-name"];
			user.LastName = (string) jsonObj ["last-name"];
			
			object val;
			if (jsonObj.TryGetValue ("latest-sync-revision", out val))
				user.LatestSyncRevision = (int) val;
			else
				user.LatestSyncRevision = -1;
			
			if (jsonObj.TryGetValue ("current-sync-guid", out val))
				user.CurrentSyncGuid = (string) val;

			Hyena.Json.JsonObject notesRefJsonObj =
				(Hyena.Json.JsonObject) jsonObj ["notes-ref"];
			user.Notes =
				ResourceReference.ParseJson (notesRefJsonObj);

			if (jsonObj.TryGetValue ("friends-ref", out val)) {
				user.Notes =
					ResourceReference.ParseJson ((Hyena.Json.JsonObject) val);
			}

			return user;
		}
		public bool UpdatesAvailableSince (int revision)
		{
			root = RootInfo.GetRoot (rootUri, connection);
			user = UserInfo.GetUser (root.User.ApiRef, connection);
			return user.LatestSyncRevision.HasValue &&
				user.LatestSyncRevision.Value > revision;
		}