public bool Remove(T item) { Provider.Context.SyncWaiter.WaitOne(); Provider.Context.SyncBlock(); FileInfo tempFile = Provider.Context.File.CopyTo("temp", true); JsonDataProvider <T> tempProvider = new JsonDataProvider <T>(new JsonDataContext(tempFile)); Stream stream = Provider.Context.File.Create(); JsonTextWriter writer = new JsonTextWriter(new StreamWriter(stream)); JsonSerializer serializer = new JsonSerializer(); bool removed = false; writer.WriteStartArray(); foreach (T element in tempProvider.Data) { if (element.Equals(item)) { removed = true; continue; } serializer.Serialize(writer, element); } writer.WriteEndArray(); writer.Flush(); stream.Close(); tempProvider.Context.Dispose(); tempFile.Delete(); Provider.Context.SyncRelease(); return(removed); }
public JsonDataEnumerator(JsonDataProvider <T> provider) { Provider = provider; syncwaiter = provider.Context.SyncWaiter; Provider.Context.OnSyncBlock += (s, e) => { stream.Close(); }; Provider.Context.OnSyncRelease += (s, e) => { stream = Provider.Context.File.OpenRead(); }; Reset(); }
public JsonDataEnumerable(JsonDataProvider <T> provider) { Provider = provider; }
public JsonDataList(JsonDataProvider <T> provider) : base(provider) { }