/// <summary> /// Updates the sync status of the given account. /// </summary> /// <since_tizen> 3 </since_tizen> /// <param name="account"> Account for which the sync status needs to be updated.</param> /// <param name="status">Sync State</param> /// <privilege>http://tizen.org/privilege/account.read</privilege> /// <privilege>http://tizen.org/privilege/account.write</privilege> /// <feature>http://tizen.org/feature/account</feature> /// <exception cref="InvalidOperationException">In case of any DB error.</exception> /// <exception cref="ArgumentException"> In case of an invalid parameter.</exception> /// <exception cref="UnauthorizedAccessException"> In case of privilege not defined.</exception> /// <exception cref="NotSupportedException">The required feature is not supported.</exception> public static void UpdateSyncStatusById(Account account, AccountSyncState status) { AccountError err = (AccountError)Interop.AccountService.UpdateAccountSyncStatusById(account.AccountId, (int)status); if (err != AccountError.None) { throw AccountErrorFactory.CreateException(err, "Failed to UpdateSyncStatusById"); } }
// This may throw a DeliciousUnavailableException public AccountSyncState LoadSyncState() { Debug.Assert (requester.Account.IsValid); AccountSyncState syncState = new AccountSyncState (requester.Account); LoadLastSyncTime (syncState); LoadRemoteUpdateInfo (syncState); LoadLocalManifest (syncState); // Avoid an HTTP request if the remote manifest isn't needed. // ShouldCrawl depends on the sync time, remote update info, and local manifest. if (syncState.ShouldCrawl ()) { LoadRemoteManifest (syncState); } else { Log.Debug ("Skipping remote manifest"); } return syncState; }
public void SaveSyncState(AccountSyncState syncState) { SaveLocalManifest (syncState); SaveLastSyncTime (syncState); }
void SaveLastSyncTime(AccountSyncState syncState) { queryable.WriteDataLine (syncState.Account.Username, syncState.LastSyncTime.ToString()); }
void SaveLocalManifest(AccountSyncState syncState) { IList <LocalManifestEntry> manifestList = new List <LocalManifestEntry>(); foreach (KeyValuePair <string, LocalManifestEntry> pair in syncState.LocalManifest) { manifestList.Add (pair.Value); } using (Stream manifestStream = queryable.WriteDataStream (syncState.Account.Username + ".manifest")) { using (StreamWriter writer = new StreamWriter (manifestStream)) { XmlSerializer serializer = new XmlSerializer (manifestList.GetType ()); serializer.Serialize (writer, manifestList); } } }
void LoadRemoteUpdateInfo(AccountSyncState syncState) { syncState.RemoteUpdateInfo = remoteDao.GetUpdateInfo (); Log.Info ("Last remote update: " + syncState.RemoteUpdateInfo.LastUpdateTime); }
void LoadRemoteManifest(AccountSyncState syncState) { Debug.Assert (syncState.RemoteManifest != null); Debug.Assert (syncState.RemoteManifest.Count == 0); Log.Debug ("Downloading remote manifest"); foreach (RemoteManifestEntry entry in remoteDao.GetAllManifestEntries ()) { syncState.RemoteManifest.Add (entry); } Log.Info ("Downloaded " + syncState.RemoteManifest.Count + " manifest entries"); }
// TODO: Instead of loading from a separate text file, we should just build // the local manifest from Beagle's index void LoadLocalManifest(AccountSyncState syncState) { Debug.Assert (syncState.Account.IsValid); Debug.Assert (syncState.LocalManifest != null); Debug.Assert (syncState.LocalManifest.Count == 0); IList <LocalManifestEntry> manifestList; Log.Debug ("Loading local manifest"); try { using (Stream manifestStream = queryable.ReadDataStream (syncState.Account.Username + ".manifest")) { using (StreamReader reader = new StreamReader (manifestStream)) { XmlSerializer serializer = new XmlSerializer (typeof (List <LocalManifestEntry>)); manifestList = serializer.Deserialize (reader) as IList <LocalManifestEntry>; } } foreach (LocalManifestEntry entry in manifestList) { syncState.LocalManifest.Add (entry.UrlHash, entry); } } catch { // No local manifest } Log.Info ("Loaded " + syncState.LocalManifest.Count + " manifest entries"); }
void LoadLastSyncTime(AccountSyncState syncState) { Debug.Assert (syncState.Account.IsValid); try { string lastSyncTimeString = queryable.ReadDataLine (syncState.Account.Username); syncState.LastSyncTime = DateTime.Parse (lastSyncTimeString); } catch { syncState.LastSyncTime = DateTime.MinValue; } Log.Info ("Last sync time: " + syncState.LastSyncTime); }
void SaveStateAndReschedule(AccountSyncState syncState, AccountSyncStateStore store, CrawlPlan crawlPlan) { Log.Info ("Sync finished"); // If the crawl plan completed successfully, then update the // last update time, otherwise leave the last update time the same // so that we can try to crawl again next time around. // The crawl may abort if delicious starts returning 503s if (! crawlPlan.HasNextCommand ()) { syncState.UpdateLastSyncTime (); } try { store.SaveSyncState (syncState); } catch (Exception e) { Log.Error (e, "Error saving sync state"); } RescheduleCrawl (); }