コード例 #1
0
        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);
        }
コード例 #2
0
 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();
 }
コード例 #3
0
 public JsonDataEnumerable(JsonDataProvider <T> provider)
 {
     Provider = provider;
 }
コード例 #4
0
 public JsonDataList(JsonDataProvider <T> provider) : base(provider)
 {
 }