Distributed .NET with Microsoft Orleans by Bhupesh Guptha Muthiyalu Suneel Kumar Kunani
Author:Bhupesh Guptha Muthiyalu, Suneel Kumar Kunani
Language: eng
Format: epub
Publisher: Packt Publishing Pvt Ltd
Published: 2022-04-29T00:00:00+00:00
In the preceding code snippet, we are checking for the existence of the directory with the name of the grain type and then checking for the existence of the file with the grain ID as the name. If the file is present, then we compare the ETag of the incoming state with the storage provider ETag. If the ETag matches, we will overwrite the state on the provider with the incoming state by calling WriteToFileAsync. WriteToFileAsync writes the grain state to Azure Files and returns the updated ETag. For the implementation of WriteToFileAsync, please refer to the sample code of this book on GitHub. If the ETag does not match, that means the state is not consistent. We will throw the InconsistentStateException exception to the caller so that the caller can refresh the state and retry the write operation.
Let's now implement the ReadStateAsync method. ReadStateAsync will be called at the time of grain activation to load the state or when explicitly called, ReadStateAsync will read the state. Add the ReadStateAsync method to the AzureFileGrainStorage class as shown in the following code snippet:public async Task ReadStateAsync(string grainType,
GrainReference grainReference, IgrainState
grainState)
{
string id = this.GetFileName(grainReference);
try
{
var directory =
this._shareClient.GetDirectoryClient(grainType);
if (await directory.ExistsAsync())
{
var file = directory.GetFileClient(id);
if (await file.ExistsAsync())
{
ShareFileDownloadInfo download = await
file.DownloadAsync();
using (StreamReader reader = new
StreamReader(download.Content))
using (JsonTextReader jsonReader = new
JsonTextReader(reader))
{
JsonSerializer ser = new
JsonSerializer();
grainState.State =
ser.Deserialize(jsonReader,
grainState.State.GetType());
}
grainState.RecordExists = true;
grainState.ETag =
download.Details.ETag.ToString();
}
}
if (grainState.State == null)
{
grainState.State =
Activator.CreateInstance
(grainState.State.GetType());
grainState.RecordExists = true;
}
}
catch (Exception exc)
{
throw;
}
}
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Exploring Deepfakes by Bryan Lyon and Matt Tora(7712)
Robo-Advisor with Python by Aki Ranin(7611)
Offensive Shellcode from Scratch by Rishalin Pillay(6095)
Microsoft 365 and SharePoint Online Cookbook by Gaurav Mahajan Sudeep Ghatak Nate Chamberlain Scott Brewster(5007)
Ego Is the Enemy by Ryan Holiday(4956)
Management Strategies for the Cloud Revolution: How Cloud Computing Is Transforming Business and Why You Can't Afford to Be Left Behind by Charles Babcock(4438)
Python for ArcGIS Pro by Silas Toms Bill Parker(4173)
Elevating React Web Development with Gatsby by Samuel Larsen-Disney(3876)
Machine Learning at Scale with H2O by Gregory Keys | David Whiting(3612)
Learning C# by Developing Games with Unity 2021 by Harrison Ferrone(3284)
Speed Up Your Python with Rust by Maxwell Flitton(3231)
Liar's Poker by Michael Lewis(3220)
OPNsense Beginner to Professional by Julio Cesar Bueno de Camargo(3195)
Extreme DAX by Michiel Rozema & Henk Vlootman(3169)
Agile Security Operations by Hinne Hettema(3122)
Linux Command Line and Shell Scripting Techniques by Vedran Dakic and Jasmin Redzepagic(3108)
Essential Cryptography for JavaScript Developers by Alessandro Segala(3082)
Cryptography Algorithms by Massimo Bertaccini(3001)
AI-Powered Commerce by Andy Pandharikar & Frederik Bussler(2981)
