private void SetChunkStateString(ChunkIndex index, string partState) { using (IStorageItem item = GetIndexItem()) { string state = item.GetUserProperty <string>(PROP_LAST_PROCESSED); string[] parts; if (string.IsNullOrEmpty(state)) { parts = new string[index.numberOfChunks]; } else { parts = state.Split(';'); } if (parts.Length != index.numberOfChunks) { Logger.Instance.Error(this, "Wrong number of chunks, got {0}, expected {1}: {2}", parts.Length, index.numberOfChunks, state); } parts[index.chunk] = partState; string combined = string.Join(";", parts); item.SetUserProperty(PROP_LAST_PROCESSED, combined); item.Save(); } }
public void DetermineSequence() { try { // Find the newest chunk ChunkIndex?newestChunkIndex = FindNewestChunkIndex(); if (newestChunkIndex == null) { CurrentSequence = null; } else { Logger.Instance.Trace(this, "Newest chunk: {0}", newestChunkIndex.Value); int?currentSequence = CurrentSequence; if (!currentSequence.HasValue || currentSequence.Value != newestChunkIndex?.numberOfChunks) { // Sequence has changed. Delete contacts Logger.Instance.Trace(this, "Rechunked, deleting contacts"); ClearContacts(); // Determine new sequence if (newestChunkIndex == null) { using (IStorageItem index = GetIndexItem()) { if (index != null) { index.Delete(); } } } else { int numberOfChunks = newestChunkIndex.Value.numberOfChunks; using (IStorageItem index = GetIndexItem()) { index.SetUserProperty(PROP_CURRENT_SEQUENCE, numberOfChunks); index.SetUserProperty(PROP_LAST_PROCESSED, CreateChunkStateString(numberOfChunks)); index.Save(); } } } } } catch (Exception e) { Logger.Instance.Trace(this, "Exception determining sequence: {0}", e); // Delete the index item using (IStorageItem index = GetIndexItem()) index?.Delete(); return; } Logger.Instance.Trace(this, "Current sequence: {0}", CurrentSequence); }
/// <summary> /// 移除指定游戏配置项。 /// </summary> /// <param name="settingName">要移除游戏配置项的名称。</param> /// <returns>是否移除指定游戏配置项成功。</returns> public bool RemoveSetting(string settingName) { if (string.IsNullOrEmpty(settingName)) { throw new GameException("Setting name is invalid."); } if (_collection.Value == null || !_collection.Value.ContainsKey(settingName)) { return(false); } _collection.Value.Remove(settingName); _collection.Save(); return(true); }