示例#1
0
        public Task ClearStateAsync(string grainType, Orleans.Runtime.GrainReference grainReference, IGrainState grainState)
        {
            var fileInfo = GetFileInfo(grainType, grainReference);

            fileInfo.Delete();
            return(TaskDone.Done);
        }
示例#2
0
        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));
                }
        }
示例#3
0
        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);
            }
        }
示例#4
0
 FileInfo GetFileInfo(string grainType, Orleans.Runtime.GrainReference grainReference)
 {
     return(new FileInfo(Path.Combine(directory, string.Format("{0}-{1}.json", grainType, grainReference.ToKeyString()))));
 }