当前位置: 首页>>代码示例>>C#>>正文


C# IGrainState.SetAll方法代码示例

本文整理汇总了C#中IGrainState.SetAll方法的典型用法代码示例。如果您正苦于以下问题:C# IGrainState.SetAll方法的具体用法?C# IGrainState.SetAll怎么用?C# IGrainState.SetAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IGrainState的用法示例。


在下文中一共展示了IGrainState.SetAll方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReadStateAsync

        public async Task ReadStateAsync(string grainType, GrainReference grainId, IGrainState grainState)
        {
            try
            {
                var blobName = BlobStorageProvider.GetBlobName(grainType, grainId);
                var blob = container.GetBlockBlobReference(blobName);
                var text = await blob.DownloadTextAsync();
                if (string.IsNullOrWhiteSpace(text))
                {
                    return;
                }

                var data = JsonConvert.DeserializeObject(text, grainState.GetType());
                var dict = ((IGrainState)data).AsDictionary();
                grainState.SetAll(dict);
            }
            catch (StorageException ex)
            {
                ;
            }
            catch (Exception ex)
            {
                Log.Error(0, ex.ToString());
            }
        }
开发者ID:justinliew,项目名称:OrleansBlobStorageProvider,代码行数:25,代码来源:BlobStorageProvider.cs

示例2: ReadStateAsync

		public async Task ReadStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
		{
			var tableResult = await _table.ExecuteAsync(TableOperation.Retrieve<DynamicTableEntity>(grainReference.ToKeyString(), grainType));
			if (tableResult.Result == null)
			{
				return;
			}
			var entity = tableResult.Result as DynamicTableEntity;

			var serializer = new JsonSerializer();
			using (var memoryStream = new MemoryStream())
			{
				foreach (var propertyName in entity.Properties.Keys.Where(p => p.StartsWith("d")).OrderBy(p => p))
				{
					var dataPart = entity.Properties[propertyName];
					await memoryStream.WriteAsync(dataPart.BinaryValue, 0, dataPart.BinaryValue.Length);
				}

				memoryStream.Position = 0;
				using (var bsonReader = new BsonReader(memoryStream))
				{
					var data = serializer.Deserialize<Dictionary<string, object>>(bsonReader);
					grainState.SetAll(data);
				}
			}
		}
开发者ID:justinliew,项目名称:Orleans.StorageEx,代码行数:26,代码来源:AzureTableStorageEx.cs

示例3: ReadStateAsync

        public async Task ReadStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
        {
            var stateName = grainState.GetType().Name;
            var key = grainReference.ToKeyString();
            var id = string.Format(CultureInfo.InvariantCulture, "{0}/{1}", stateName, key);

            using (IAsyncDocumentSession session = this.documentStore.OpenAsyncSession())
            {
                var state = await session.LoadAsync<RavenJObject>(id);
                if (state != null)
                {
                    grainState.SetAll(state.ToDictionary(x => x.Key, x => x.Value.Value<object>()));
                }
            }
        }
开发者ID:ReubenBond,项目名称:orleans.storageprovider.ravendb,代码行数:15,代码来源:RavenDBStorageProvider.cs

示例4: ReadStateAsync

        public async Task ReadStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
        {
            try
            {
                var collection = await this.EnsureCollection(grainType);
                var documents = await this.Client.ReadDocumentFeedAsync(collection.DocumentsLink);
                var documentId = grainReference.ToKeyString();
                GrainStateDocument document = documents.Where(d => d.Id == documentId).FirstOrDefault();

                if(document != null)
                    grainState.SetAll(document.State);
            }
            catch (Exception ex)
            {
                Log.Error(0, "Error in ReadStateAsync", ex);
            }            
        }
开发者ID:SmartFire,项目名称:orleans.storageprovider.documentdb,代码行数:17,代码来源:DocumentDBStorageProvider.cs

示例5: ConvertFromStorageFormat

 /// <summary>
 /// Deserialize from Azure storage format
 /// </summary>
 /// <param name="grainState">The grain state data to be deserialized in to</param>
 /// <param name="entity">The Azure table entity the stored data</param>
 internal void ConvertFromStorageFormat(IGrainState grainState, GrainStateEntity entity)
 {
     Dictionary<string, object> dataValues = null;
     try
     {
         if (entity.Data != null)
         {
             // Rehydrate
             dataValues = SerializationManager.DeserializeFromByteArray<Dictionary<string, object>>(entity.Data);
         }
         else if (entity.StringData != null)
         {
             dataValues = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(entity.StringData, jsonSettings);
         }
         if (dataValues != null)
         {
             grainState.SetAll(dataValues);
         }
         // Else, no data found
     }
     catch (Exception exc)
     {
         var sb = new StringBuilder();
         if (entity.Data != null)
         {
             sb.AppendFormat("Unable to convert from storage format GrainStateEntity.Data={0}", entity.Data);
         }
         else if (entity.StringData != null)
         {
             sb.AppendFormat("Unable to convert from storage format GrainStateEntity.StringData={0}", entity.StringData);
         }
         if (dataValues != null)
         {
             int i = 1;
             foreach (var dvKey in dataValues.Keys)
             {
                 object dvValue = dataValues[dvKey];
                 sb.AppendLine();
                 sb.AppendFormat("Data #{0} Key={1} Value={2} Type={3}", i, dvKey, dvValue, dvValue.GetType());
                 i++;
             }
         }
         Log.Error(0, sb.ToString(), exc);
         throw new AggregateException(sb.ToString(), exc);
     }
 }
开发者ID:stanroze,项目名称:orleans,代码行数:51,代码来源:AzureTableStorage.cs

示例6: ConvertFromStorageFormat

 /// <summary>
 /// Constructs a grain state instance by deserializing a JSON document.
 /// </summary>
 /// <param name="grainState">Grain state to be populated for storage.</param>
 /// <param name="entityData">JSON storage format representaiton of the grain state.</param>
 protected static void ConvertFromStorageFormat(IGrainState grainState, string entityData)
 {
     object data = JsonConvert.DeserializeObject(entityData, grainState.GetType(), GrainStateMongoDataManager.JsonSetting);
     var dict = ((IGrainState)data).AsDictionary();
     grainState.SetAll(dict);
 }
开发者ID:sharpe5,项目名称:Orleans.Storage.MongoDB,代码行数:11,代码来源:MongoDBStorage.cs

示例7: ConvertFromStorageFormat

 /// <summary>
 /// Constructs a grain state instance by deserializing a JSON document.
 /// </summary>
 /// <param name="grainState">Grain state to be populated for storage.</param>
 /// <param name="entityData">JSON storage format representaiton of the grain state.</param>
 protected static void ConvertFromStorageFormat(IGrainState grainState, string entityData)
 {
     var setting = new JsonSerializerSettings();
     object data = JsonConvert.DeserializeObject(entityData, grainState.GetType());
     var dict = ((IGrainState)data).AsDictionary();
     grainState.SetAll(dict);
 }
开发者ID:SmartFire,项目名称:Orleans.Storage.Couchbase,代码行数:12,代码来源:CouchbaseStorage.cs

示例8: ConvertFromStorageFormat

 /// <summary>
 /// Constructs a grain state instance by deserializing a JSON document.
 /// </summary>
 /// <param name="grainState">Grain state to be populated for storage.</param>
 /// <param name="entityData">JSON storage format representaiton of the grain state.</param>
 protected static void ConvertFromStorageFormat(IGrainState grainState, string entityData)
 {
     JavaScriptSerializer deserializer = new JavaScriptSerializer();
     object data = deserializer.Deserialize(entityData, grainState.GetType());
     var dict = ((IGrainState)data).AsDictionary();
     grainState.SetAll(dict);
 }
开发者ID:stanroze,项目名称:orleans,代码行数:12,代码来源:BaseJSONStorageProvider.cs


注:本文中的IGrainState.SetAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。