public async Task <bool> MountLU(string RegistrarDeviceId, string LUID) { var myDictionary = await this.StateManager.GetOrAddAsync <IReliableDictionary <string, string> >(RegistrarDeviceId); bool fGotRegInfo = false; using (var tx = this.StateManager.CreateTransaction()) { // Get the current registration info Microsoft.ServiceFabric.Data.ConditionalValue <string> registrationInfo = await myDictionary.TryGetValueAsync(tx, LUID); fGotRegInfo = registrationInfo.HasValue; if (fGotRegInfo) { string regInfo = registrationInfo.Value; // Get the actual registration info string[] arrData = regInfo.Split(new char[] { '_' }); string updatedRegInfo = String.Format("{0}_{1}_{2}", arrData[0], arrData[1], "1"); await myDictionary.SetAsync(tx, LUID, updatedRegInfo); await tx.CommitAsync(); } } return(fGotRegInfo); }
public async Task <bool> UnregisterLU(string RegistrarDeviceId, string LUID) { var myDictionary = await this.StateManager.GetOrAddAsync <IReliableDictionary <string, string> >(RegistrarDeviceId); bool fUnregistered = false; using (var tx = this.StateManager.CreateTransaction()) { // First, delete the dictionary containing the disk blocks Microsoft.ServiceFabric.Data.ConditionalValue <IReliableDictionary <string, byte[]> > dictDisk = await this.StateManager.TryGetAsync <IReliableDictionary <string, byte[]> >(LUID); if (dictDisk.HasValue) { await this.StateManager.RemoveAsync(tx, LUID); } // Next, remove the entry from the registrar dictionary Microsoft.ServiceFabric.Data.ConditionalValue <string> registrationInfo = await myDictionary.TryRemoveAsync(tx, LUID); fUnregistered = registrationInfo.HasValue; // Abort the transaction if we were unable to unregister the disk for some reason. if (!fUnregistered) { tx.Abort(); } else { // If an exception is thrown before calling CommitAsync, the transaction aborts, all changes are // discarded, and nothing is saved to the secondary replicas. await tx.CommitAsync(); } } return(fUnregistered); }