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


C# IGrainState.AsDictionary方法代码示例

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


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

示例1: WriteStateAsync

        public async Task WriteStateAsync(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();

                var document = documents.Where(d => d.Id == documentId).FirstOrDefault();

                if(document != null)
                {
                    document.State = grainState.AsDictionary();
                    await this.Client.ReplaceDocumentAsync(document);
                }
                else
                {
                    await this.Client.CreateDocumentAsync(collection.DocumentsLink,
                        new GrainStateDocument { Id = documentId, State = grainState.AsDictionary() });
                }
            }
            catch (Exception ex)
            {
                Log.Error(0, "Error in WriteStateAsync", ex);
            }
        }
开发者ID:SmartFire,项目名称:orleans.storageprovider.documentdb,代码行数:26,代码来源:DocumentDBStorageProvider.cs

示例2: WriteStateAsync

 public async Task WriteStateAsync(string grainType, GrainReference grainId, IGrainState grainState)
 {
     try
     {
         var blobName = BlobStorageProvider.GetBlobName(grainType, grainId);
         var storedData = JsonConvert.SerializeObject(grainState.AsDictionary());
         var blob = container.GetBlockBlobReference(blobName);
         await blob.UploadTextAsync(storedData);
     }
     catch (Exception ex)
     {
         Log.Error(0, ex.ToString());
     }
 }
开发者ID:justinliew,项目名称:OrleansBlobStorageProvider,代码行数:14,代码来源:BlobStorageProvider.cs

示例3: ConvertToStorageFormat

        /// <summary>
        /// Serialize to Azure storage format in either binary or JSON format.
        /// </summary>
        /// <param name="grainState">The grain state data to be serialized</param>
        /// <param name="entity">The Azure table entity the data should be stored in</param>
        /// <remarks>
        /// See:
        /// http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx
        /// for more on the JSON serializer.
        /// </remarks>
        internal void ConvertToStorageFormat(IGrainState grainState, GrainStateEntity entity)
        {
            // Dehydrate
            var dataValues = grainState.AsDictionary();
            int dataSize;

            if (useJsonFormat)
            {
                // http://james.newtonking.com/json/help/index.html?topic=html/T_Newtonsoft_Json_JsonConvert.htm
                string data = Newtonsoft.Json.JsonConvert.SerializeObject(dataValues, jsonSettings);

                if (Log.IsVerbose3) Log.Verbose3("Writing JSON data size = {0} for grain id = Partition={1} / Row={2}",
                    data.Length, entity.PartitionKey, entity.RowKey);
                
                dataSize = data.Length;
                entity.StringData = data;
            }
            else
            {
                // Convert to binary format

                byte[] data = SerializationManager.SerializeToByteArray(dataValues);

                if (Log.IsVerbose3) Log.Verbose3("Writing binary data size = {0} for grain id = Partition={1} / Row={2}",
                    data.Length, entity.PartitionKey, entity.RowKey);
                
                dataSize = data.Length;
                entity.Data = data;
            }
            if (dataSize > MAX_DATA_SIZE)
            {
                var msg = string.Format("Data too large to write to Azure table. Size={0} MaxSize={1}", dataSize, MAX_DATA_SIZE);
                Log.Error(0, msg);
                throw new ArgumentOutOfRangeException("GrainState.Size", msg);
            }
        }
开发者ID:stanroze,项目名称:orleans,代码行数:46,代码来源:AzureTableStorage.cs

示例4: WriteStateAsync

		public Task WriteStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
		{
			var entity = new DynamicTableEntity(grainReference.ToKeyString(), grainType) { ETag = "*" };

			var serializer = new JsonSerializer();
			using (var memoryStream = new MemoryStream())
			{
				using (var bsonWriter = new BsonWriter(memoryStream))
				{
					serializer.Serialize(bsonWriter, grainState.AsDictionary());

					SplitBinaryData(entity, memoryStream.ToArray());
				}
			}

			return _table.ExecuteAsync(TableOperation.InsertOrReplace(entity));
		}
开发者ID:justinliew,项目名称:Orleans.StorageEx,代码行数:17,代码来源:AzureTableStorageEx.cs

示例5: ConvertToStorageFormat

 /// <summary>
 /// Serializes from a grain instance to a JSON document.
 /// </summary>
 /// <param name="grainState">Grain state to be converted into JSON storage format.</param>
 /// <remarks>  
 /// </remarks>
 protected static string ConvertToStorageFormat(string grainType, IGrainState grainState)
 {
     IDictionary<string, object> dataValues = grainState.AsDictionary();
     //store _Type into couchbase
     dataValues["_Type"] = grainType;
     return JsonConvert.SerializeObject(dataValues);
 }
开发者ID:SmartFire,项目名称:Orleans.Storage.Couchbase,代码行数:13,代码来源:CouchbaseStorage.cs

示例6: ConvertToStorageFormat

 /// <summary>
 /// Serializes from a grain instance to a JSON document.
 /// </summary>
 /// <param name="grainState">Grain state to be converted into JSON storage format.</param>
 /// <remarks>
 /// See:
 /// http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx
 /// for more on the JSON serializer.
 /// </remarks>
 protected static string ConvertToStorageFormat(IGrainState grainState)
 {
     IDictionary<string, object> dataValues = grainState.AsDictionary();
     JavaScriptSerializer serializer = new JavaScriptSerializer();
     return serializer.Serialize(dataValues);
 }
开发者ID:stanroze,项目名称:orleans,代码行数:15,代码来源:BaseJSONStorageProvider.cs


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