public async Task AddKey(SessionKeyItem keyItem)
        {
            var sessionKeyItems = await StateManager.GetOrAddAsync <IReliableDictionary <SessionKeyItemId, SessionKeyItem> >(SessionKeyDictionaryName);

            ServiceEventSource.Current.Message($"Method started {nameof(SessionKeys)}->AddKey() at: {DateTime.UtcNow}");
            using (var tx = StateManager.CreateTransaction())
            {
                await sessionKeyItems.AddOrUpdateAsync(tx, keyItem.Id, keyItem, (key, value) => keyItem);

                await tx.CommitAsync();
            }
            ServiceEventSource.Current.Message($"Method ended {nameof(SessionKeys)}->AddKey() at: {DateTime.UtcNow}");
        }
 public void StoreElement(XElement element, string friendlyName)
 {
     try {
         var partitions = getPartitions().GetAwaiter().GetResult();
         foreach (var partition in partitions)
         {
             long minKey      = (partition.PartitionInformation as Int64RangePartitionInformation).LowKey;
             var  keysService = ServiceProxy.Create <ISessionKeysService>(KeyServiceUri, new ServicePartitionKey(minKey));
             var  newKey      = new SessionKeyItem(friendlyName, element.ToString());
             keysService.AddKey(newKey);
         }
     }
     catch (Exception ex) {
         ServiceEventSource.Current.Message($"{nameof(SFDataprotectionKeyRepository)}->StoreElement() failed to save Data Protection Keys with error: {ex.ToString()}");
     }
 }
Пример #3
0
 /// <summary>
 /// We need to fix here some point related to the id as id or id as GetPartitionKey()
 /// Need to optimize this part to deal with auto ids
 /// </summary>
 /// <param name="element"></param>
 /// <param name="friendlyName"></param>
 public void StoreElement(XElement element, string friendlyName)
 {
     try
     {
         var partitions = GetPartitions().GetAwaiter().GetResult();
         foreach (var partition in partitions)
         {
             var newKey      = new SessionKeyItem(friendlyName, element.ToString());
             var keysService = ServiceProxy.Create <ISessionKeysService>(_keyServiceUri, newKey.Id.GetPartitionKey());
             keysService.AddKey(newKey);
         }
     }
     catch (Exception ex)
     {
         ServiceEventSource.Current.Message($"{nameof(ServiceFabricDataProtectionRepository)}->StoreElement() failed to save Data Protection Keys with error: {ex.ToString()}");
     }
 }