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.
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(4131)
Ego Is the Enemy by Ryan Holiday(3993)
Offensive Shellcode from Scratch by Rishalin Pillay(3681)
Exploring Deepfakes by Bryan Lyon and Matt Tora(3274)
Robo-Advisor with Python by Aki Ranin(3057)
Learning C# by Developing Games with Unity 2021 by Harrison Ferrone(2876)
Speed Up Your Python with Rust by Maxwell Flitton(2853)
Liar's Poker by Michael Lewis(2812)
Agile Security Operations by Hinne Hettema(2807)
Linux Command Line and Shell Scripting Techniques by Vedran Dakic and Jasmin Redzepagic(2807)
OPNsense Beginner to Professional by Julio Cesar Bueno de Camargo(2806)
Extreme DAX by Michiel Rozema & Henk Vlootman(2791)
Essential Cryptography for JavaScript Developers by Alessandro Segala(2743)
Elevating React Web Development with Gatsby by Samuel Larsen-Disney(2735)
Python for ArcGIS Pro by Silas Toms Bill Parker(2649)
AI-Powered Commerce by Andy Pandharikar & Frederik Bussler(2643)
Incident Response Techniques for Ransomware Attacks by Oleg Skulkin(2630)
Cryptography Algorithms by Massimo Bertaccini(2628)
Distributed .NET with Microsoft Orleans by Bhupesh Guptha Muthiyalu Suneel Kumar Kunani(2628)