public Task ClearStateAsync(string grainType, Orleans.Runtime.GrainReference grainReference, IGrainState grainState) { var fileInfo = GetFileInfo(grainType, grainReference); fileInfo.Delete(); return(TaskDone.Done); }
public Task WriteStateAsync(string grainType, Orleans.Runtime.GrainReference grainReference, Orleans.IGrainState grainState) { var json = JsonConvert.SerializeObject(grainState.AsDictionary()); var fileInfo = GetFileInfo(grainType, grainReference); using (var stream = fileInfo.OpenWrite()) using (var writer = new StreamWriter(stream)) { return(writer.WriteAsync(json)); } }
public async Task ReadStateAsync(string grainType, Orleans.Runtime.GrainReference grainReference, Orleans.IGrainState grainState) { var fileInfo = GetFileInfo(grainType, grainReference); if (!fileInfo.Exists) { return; } using (var stream = fileInfo.OpenText()) { var json = await stream.ReadToEndAsync(); var data = JsonConvert.DeserializeObject <Dictionary <string, object> >(json); grainState.SetAll(data); } }
FileInfo GetFileInfo(string grainType, Orleans.Runtime.GrainReference grainReference) { return(new FileInfo(Path.Combine(directory, string.Format("{0}-{1}.json", grainType, grainReference.ToKeyString())))); }