Ejemplo n.º 1
0
        /// <exception cref="System.IO.IOException"/>
        public override NMStateStoreService.RecoveredLocalizationState LoadLocalizationState
            ()
        {
            NMStateStoreService.RecoveredLocalizationState state = new NMStateStoreService.RecoveredLocalizationState
                                                                       ();
            LeveldbIterator iter = null;

            try
            {
                iter = new LeveldbIterator(db);
                iter.Seek(JniDBFactory.Bytes(LocalizationPublicKeyPrefix));
                state.publicTrackerState = LoadResourceTrackerState(iter, LocalizationPublicKeyPrefix
                                                                    );
                iter.Seek(JniDBFactory.Bytes(LocalizationPrivateKeyPrefix));
                while (iter.HasNext())
                {
                    KeyValuePair <byte[], byte[]> entry = iter.PeekNext();
                    string key = JniDBFactory.AsString(entry.Key);
                    if (!key.StartsWith(LocalizationPrivateKeyPrefix))
                    {
                        break;
                    }
                    int userEndPos = key.IndexOf('/', LocalizationPrivateKeyPrefix.Length);
                    if (userEndPos < 0)
                    {
                        throw new IOException("Unable to determine user in resource key: " + key);
                    }
                    string user = Sharpen.Runtime.Substring(key, LocalizationPrivateKeyPrefix.Length,
                                                            userEndPos);
                    state.userResources[user] = LoadUserLocalizedResources(iter, Sharpen.Runtime.Substring
                                                                               (key, 0, userEndPos + 1));
                }
            }
            catch (DBException e)
            {
                throw new IOException(e);
            }
            finally
            {
                if (iter != null)
                {
                    iter.Close();
                }
            }
            return(state);
        }
Ejemplo n.º 2
0
 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);
     }
 }