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


C# GrainReference类代码示例

本文整理汇总了C#中GrainReference的典型用法代码示例。如果您正苦于以下问题:C# GrainReference类的具体用法?C# GrainReference怎么用?C# GrainReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


GrainReference类属于命名空间,在下文中一共展示了GrainReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: ReadRows

 public ReminderTableData ReadRows(GrainReference grainRef)
 {
     Dictionary<string, ReminderEntry> reminders;
     reminderTable.TryGetValue(grainRef, out reminders);
     return reminders == null ? new ReminderTableData() :
         new ReminderTableData(reminders.Values.ToList());
 }
开发者ID:Rejendo,项目名称:orleans,代码行数:7,代码来源:InMemoryRemindersTable.cs

示例3: ToElasticValue

 public string ToElasticValue(GrainReference gref)
 {
     ///"GrainReference=00000000000000000000000000000000060000006aa96326+abc"
     /// to
     /// "GrainReference^00000000000000000000000000000000060000006aa96326_abc"
     return gref.ToKeyString().Replace("=", "__").Replace("_", "+");
 }
开发者ID:kowalot,项目名称:Pk.OrleansUtils,代码行数:7,代码来源:ElasticReminderEntry.cs

示例4: 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

示例5: 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

示例6: ReadStateAsync

        public async Task ReadStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
        {
            if (!(grainState is IAggregateState))
                throw new NotAggregateStateException(grainState.GetType());

            var stream = this.GetStreamName(grainType, grainReference);

            var sliceStart = 0;
            StreamEventsSlice currentSlice;

            do
            {
                var sliceCount = sliceStart + ReadPageSize;

                currentSlice = await this.Connection.ReadStreamEventsForwardAsync(stream, sliceStart, sliceCount, true);

                if (currentSlice.Status == SliceReadStatus.StreamNotFound)
                    return;

                if (currentSlice.Status == SliceReadStatus.StreamDeleted)
                    throw new StreamDeletedException();

                sliceStart = currentSlice.NextEventNumber;

                foreach (var @event in currentSlice.Events)
                {
                    dynamic deserialisedEvent = DeserializeEvent(@event.Event);
                    StateTransformer.ApplyEvent(deserialisedEvent, grainState as IAggregateState);
                }

            } while (!currentSlice.IsEndOfStream);
        }
开发者ID:timfun,项目名称:orleans.eventsourcing,代码行数:32,代码来源:EventStoreProvider.cs

示例7: ReadRow

 public async Task<ReminderEntry> ReadRow(GrainReference grainRef, string reminderName)
 {
     using (var conn = new SqlConnection(connectionString))
     {
         conn.Open();
         return await ReadRowInternal(grainRef, reminderName, conn, null);
     }
 }
开发者ID:stanroze,项目名称:orleans,代码行数:8,代码来源:SqlReminderTable.cs

示例8: CreateIdFrom

 public static string CreateIdFrom(GrainReference grainRef,string reminderName)
 {
     if (String.IsNullOrEmpty(reminderName))
         throw new ArgumentNullException("reminderName");
     if (grainRef==null)
         throw new ArgumentNullException("grainRef");
     return grainRef.ToKeyString() + "," + reminderName;
 }
开发者ID:kowalot,项目名称:Pk.OrleansUtils,代码行数:8,代码来源:ElasticReminderEntry.cs

示例9: OnStorageActivate

 internal static void OnStorageActivate(IStorageProvider storage, string grainType, GrainReference grain, TimeSpan latency)
 {
     StorageActivateTotal.Increment();
     if (latency > TimeSpan.Zero)
     {
         StorageReadLatency.AddSample(latency);
     }
 }
开发者ID:stanroze,项目名称:orleans,代码行数:8,代码来源:StorageStatisticsGroup.cs

示例10: ReadStateAsync

 /// <summary>
 /// Reads persisted state from the backing store and deserializes it into the the target
 /// grain state object.
 /// </summary>
 /// <param name="grainType">A string holding the name of the grain class.</param>
 /// <param name="grainReference">Represents the long-lived identity of the grain.</param>
 /// <param name="grainState">A reference to an object to hold the persisted state of the grain.</param>
 /// <returns>Completion promise for this operation.</returns>
 public async Task ReadStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
 {
     if (DataManager == null) throw new ArgumentException("DataManager property not initialized");
     var entityData = await DataManager.Read(grainState.GetType().Name, grainReference.ToKeyString());
     if (entityData != null)
     {
         ConvertFromStorageFormat(grainState, entityData);
     }
 }
开发者ID:Joshua-Ferguson,项目名称:orleans,代码行数:17,代码来源:BaseJSONStorageProvider.cs

示例11: ClearStateAsync

        public Task ClearStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
        {
            if (!(grainState is IAggregateState))
                throw new NotAggregateStateException(grainState.GetType());

            var state = grainState as IAggregateState;
            var stream = this.GetStreamName(grainType, grainReference);

            return this.Connection.DeleteStreamAsync(stream, state.Version);
        }
开发者ID:timfun,项目名称:orleans.eventsourcing,代码行数:10,代码来源:EventStoreProvider.cs

示例12: OnRead

 /// <summary>
 /// Throws a storage exception if one has been added for the grain reference for reading.
 /// </summary>
 /// <param name="grainReference"></param>
 /// <returns></returns>
 public Task OnRead(GrainReference grainReference)
 {
     Exception exception;
     if (readFaults.TryGetValue(grainReference, out exception))
     {
         readFaults.Remove(grainReference);
         throw exception;
     }
     return TaskDone.Done;
 }
开发者ID:Rejendo,项目名称:orleans,代码行数:15,代码来源:StorageFaultGrain.cs

示例13: CreateReminder

 private static ReminderEntry CreateReminder(GrainReference grainRef, string reminderName)
 {
     return new ReminderEntry
     {
         GrainRef = grainRef,
         Period = TimeSpan.FromMinutes(1),
         StartAt = DateTime.UtcNow.Add(TimeSpan.FromMinutes(1)),
         ReminderName = reminderName
     };
 }
开发者ID:Robin--,项目名称:orleans,代码行数:10,代码来源:ReminderTablePluginTests.cs

示例14: UpsertReminder

 private static async Task<string> UpsertReminder(IReminderTable reminder, GrainReference grainRef, string reminderName, DateTime startAt, TimeSpan period)
 {
     var reminderRow = new ReminderEntry
                       {
                           GrainRef = grainRef,
                           Period = period,
                           StartAt = startAt,
                           ReminderName = reminderName
                       };
     return await reminder.UpsertRow(reminderRow);
 }
开发者ID:sbambach,项目名称:orleans,代码行数:11,代码来源:ReminderTablePluginTests.cs

示例15: Get

 internal static async Task<ElasticReminderEntry> Get(ElasticClient elastic, GrainReference grainRef, string reminderName)
 {
     var op = await elastic.GetAsync<ElasticReminderEntry>(CreateIdFrom(grainRef, reminderName));
     if (op.IsValid)
     {
         op.Source.ETag = op.Version;
         return op.Source;
     }
     else
         throw new ElasticsearchStorageException();
 }
开发者ID:kowalot,项目名称:Pk.OrleansUtils,代码行数:11,代码来源:ElasticReminderEntry.cs


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