/// <exception cref="System.IO.IOException"/> private NMStateStoreService.RecoveredUserResources LoadUserLocalizedResources(LeveldbIterator iter, string keyPrefix) { NMStateStoreService.RecoveredUserResources userResources = new NMStateStoreService.RecoveredUserResources (); while (iter.HasNext()) { KeyValuePair <byte[], byte[]> entry = iter.PeekNext(); string key = JniDBFactory.AsString(entry.Key); if (!key.StartsWith(keyPrefix)) { break; } if (key.StartsWith(LocalizationFilecacheSuffix, keyPrefix.Length)) { userResources.privateTrackerState = LoadResourceTrackerState(iter, keyPrefix + LocalizationFilecacheSuffix ); } else { if (key.StartsWith(LocalizationAppcacheSuffix, keyPrefix.Length)) { int appIdStartPos = keyPrefix.Length + LocalizationAppcacheSuffix.Length; int appIdEndPos = key.IndexOf('/', appIdStartPos); if (appIdEndPos < 0) { throw new IOException("Unable to determine appID in resource key: " + key); } ApplicationId appId = ConverterUtils.ToApplicationId(Sharpen.Runtime.Substring(key , appIdStartPos, appIdEndPos)); userResources.appTrackerStates[appId] = LoadResourceTrackerState(iter, Sharpen.Runtime.Substring (key, 0, appIdEndPos + 1)); } else { throw new IOException("Unexpected user resource key " + key); } } } return(userResources); }
public override NMStateStoreService.RecoveredLocalizationState LoadLocalizationState () { lock (this) { NMStateStoreService.RecoveredLocalizationState result = new NMStateStoreService.RecoveredLocalizationState (); foreach (KeyValuePair <NMMemoryStateStoreService.TrackerKey, NMMemoryStateStoreService.TrackerState > e in trackerStates) { NMMemoryStateStoreService.TrackerKey tk = e.Key; NMMemoryStateStoreService.TrackerState ts = e.Value; // check what kind of tracker state we have and recover appropriately // public trackers have user == null // private trackers have a valid user but appId == null // app-specific trackers have a valid user and valid appId if (tk.user == null) { result.publicTrackerState = LoadTrackerState(ts); } else { NMStateStoreService.RecoveredUserResources rur = result.userResources[tk.user]; if (rur == null) { rur = new NMStateStoreService.RecoveredUserResources(); result.userResources[tk.user] = rur; } if (tk.appId == null) { rur.privateTrackerState = LoadTrackerState(ts); } else { rur.appTrackerStates[tk.appId] = LoadTrackerState(ts); } } } return(result); } }