コード例 #1
0
        private GrainReference RoundTripGrainReferenceToKey(GrainReference input)
        {
            string         str    = input.ToKeyString();
            GrainReference output = GrainReference.FromKeyString(str);

            return(output);
        }
コード例 #2
0
ファイル: Exceptions.cs プロジェクト: emilianionascu/orleans
 /// <summary>
 /// Exception thrown when an azure table storage exception is thrown due to update conditions not being satisfied.
 /// </summary>
 protected TableStorageUpdateConditionNotSatisfiedException(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     this.GrainType = info.GetString("GrainType");
     this.GrainId   = GrainReference.FromKeyString(info.GetString("GrainId"));
     this.TableName = info.GetString("TableName");
 }
コード例 #3
0
 private ReminderEntry ConvertFromTableEntry(ReminderTableEntry tableEntry, string eTag)
 {
     try
     {
         return(new ReminderEntry
         {
             GrainRef = GrainReference.FromKeyString(tableEntry.GrainReference),
             ReminderName = tableEntry.ReminderName,
             StartAt = TraceLogger.ParseDate(tableEntry.StartAt),
             Period = TimeSpan.Parse(tableEntry.Period),
             ETag = eTag,
         });
     }
     catch (Exception exc)
     {
         var error = String.Format("Failed to parse ReminderTableEntry: {0}. This entry is corrupt, going to ignore it.",
                                   tableEntry);
         logger.Error(ErrorCode.AzureTable_49, error, exc);
         throw;
     }
     finally
     {
         string serviceIdStr = ReminderTableEntry.ConstructServiceIdStr(remTableManager.ServiceId);
         if (!tableEntry.ServiceId.Equals(serviceIdStr))
         {
             var error = String.Format("Read a reminder entry for wrong Service id. Read {0}, but my service id is {1}. Going to discard it.",
                                       tableEntry, serviceIdStr);
             logger.Warn(ErrorCode.AzureTable_ReadWrongReminder, error);
             throw new OrleansException(error);
         }
     }
 }
コード例 #4
0
        public async Task <List <GrainReference> > Lookup <K>(string grainType, string indexedField, K key)
        {
            await EnsureCollection(grainType);

            FeedOptions queryOptions = new FeedOptions {
                EnableCrossPartitionQuery = true, MaxDegreeOfParallelism = 10, MaxItemCount = -1
            };

            // Now execute the same query via direct SQL
            IQueryable <object> sqlQuery = this.Client.CreateDocumentQuery <object>(
                UriFactory.CreateDocumentCollectionUri(this.DatabaseName, grainType),
                "SELECT c.id FROM c WHERE c.State." + (isFaultTolerant ? "UserState." : "") + indexedField + " = " + (IsNumericType(typeof(K)) ? key.ToString() : ("'" + key + "'")),
                queryOptions);
            var queryRes = await Task.Run(() => sqlQuery.AsEnumerable().ToList());

            List <GrainReference> idList = new List <GrainReference>();

            foreach (var elem in queryRes)
            {
                dynamic elemDyn = elem;
                idList.Add(GrainReference.FromKeyString(elemDyn.id));
            }

            return(idList);
        }
コード例 #5
0
        public void KeysAllowPlusSymbols()
        {
            const string key = "foo+bar+zaz";

            {
                // Verify that grains with string keys can include + symbols in their key.
                var grain    = this.GrainFactory.GetGrain <IStringGrain>(key);
                var grainRef = (GrainReference)grain;
                var key2     = grainRef.GetPrimaryKeyString();
                Assert.Equal(key, key2);

                var grainRef2 = GrainReference.FromKeyString(
                    grainRef.ToKeyString(),
                    this.Client.ServiceProvider.GetRequiredService <IRuntimeClient>());
                Assert.True(grainRef.Equals(grainRef2));
            }

            {
                // Verify that grains with compound keys can include + symbols in their key extension.
                var    primaryKey = Guid.NewGuid();
                var    grain      = this.GrainFactory.GetGrain <IKeyExtensionTestGrain>(primaryKey, keyExtension: key);
                string keyExt;
                var    grainRef         = (GrainReference)grain;
                var    actualPrimaryKey = grainRef.GetPrimaryKey(out keyExt);
                Assert.Equal(primaryKey, actualPrimaryKey);
                Assert.Equal(key, keyExt);

                var grainRef2 = GrainReference.FromKeyString(
                    grainRef.ToKeyString(),
                    this.Client.ServiceProvider.GetRequiredService <IRuntimeClient>());
                Assert.True(grainRef.Equals(grainRef2));
            }
        }
コード例 #6
0
 private static ReminderEntry ConvertFromRow(IDataRecord results)
 {
     return(new ReminderEntry
     {
         GrainRef = GrainReference.FromKeyString(results.GetString(GRAIN_ID_IDX)),
         ReminderName = results.GetString(REMINDER_NAME_IDX),
         StartAt = results.GetDateTime(START_TIME_IDX),
         Period = TimeSpan.FromMilliseconds(results.GetInt32(PERIOD_IDX)),
         ETag = results.GetString(E_TAG_IDX)
     });
 }
コード例 #7
0
 private static ReminderEntry Resolve(Dictionary <string, AttributeValue> item)
 {
     return(new ReminderEntry
     {
         ETag = item[ETAG_PROPERTY_NAME].N,
         GrainRef = GrainReference.FromKeyString(item[GRAIN_REFERENCE_PROPERTY_NAME].S),
         Period = TimeSpan.Parse(item[PERIOD_PROPERTY_NAME].S),
         ReminderName = item[REMINDER_NAME_PROPERTY_NAME].S,
         StartAt = DateTime.Parse(item[START_TIME_PROPERTY_NAME].S)
     });
 }
コード例 #8
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var key = serializer.Deserialize <string>(reader);

            if (string.IsNullOrWhiteSpace(key))
            {
                return(null);
            }

            var result = GrainReference.FromKeyString(key, null);

            this.grainFactory.BindGrainReference(result);
            return(Casters.GetOrAdd(objectType, CreateCasterDelegate)(result));
        }
コード例 #9
0
                public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
                {
                    var jobj = JObject.Load(reader);

                    var key        = (string)jobj["grain"];
                    var resourceId = (string)jobj["facet"];

                    var grainref = GrainReference.FromKeyString(key, null);

                    this.grainFactory.BindGrainReference(grainref);
                    var extension = grainref.AsReference <ITransactionParticipantExtension>();

                    return(new TransactionParticipantExtensionExtensions.TransactionParticipantExtensionWrapper(extension, resourceId));
                }
コード例 #10
0
            internal static ReminderEntry GetReminderEntry(IDataRecord record)
            {
                //Having non-null field, GrainId, means with the query filter options, an entry was found.
                string grainId = record.GetValueOrDefault <string>(nameof(Columns.GrainId));

                if (grainId != null)
                {
                    return(new ReminderEntry
                    {
                        GrainRef = GrainReference.FromKeyString(grainId),
                        ReminderName = record.GetValue <string>(nameof(Columns.ReminderName)),
                        StartAt = record.GetValue <DateTime>(nameof(Columns.StartTime)),
                        Period = TimeSpan.FromMilliseconds(record.GetValue <int>(nameof(Columns.Period))),
                        ETag = GetVersion(record).ToString()
                    });
                }
                return(null);
            }
        private ReminderEntry Parse(RemindersCollection reminder)
        {
            if (reminder != null)
            {
                string grainId = reminder.GrainId;

                if (!string.IsNullOrEmpty(grainId))
                {
                    return(new ReminderEntry
                    {
                        GrainRef = GrainReference.FromKeyString(grainId),
                        ReminderName = reminder.ReminderName,
                        StartAt = reminder.StartTime,
                        Period = TimeSpan.FromMilliseconds(reminder.Period),
                        ETag = reminder.Version.ToString()
                    });
                }
            }

            return(null);
        }
コード例 #12
0
 /// <inheritdoc />
 public GrainReference GetGrainFromKeyString(string key) => GrainReference.FromKeyString(key);
コード例 #13
0
 internal static IObserverEndpoint Proxy(ObserverPath path)
 {
     return(ObserverEndpointFactory.Cast(GrainReference.FromKeyString(path.ToString())));
 }
コード例 #14
0
 /// <inheritdoc />
 public GrainReference GetGrainFromKeyString(string key) => GrainReference.FromKeyString(key, this.runtimeClient);
コード例 #15
0
 internal static IClientEndpoint Proxy(string path)
 {
     return(ClientEndpointFactory.Cast(GrainReference.FromKeyString(path)));
 }
コード例 #16
0
ファイル: GrainFactory.cs プロジェクト: sehra/dotnet-orleans
 /// <inheritdoc />
 public GrainReference GetGrainFromKeyString(string key) => GrainReference.FromKeyString(key, this.GrainReferenceRuntime);
コード例 #17
0
 internal static IClientEndpoint Proxy(string path)
 {
     return(GrainReference.FromKeyString(path).AsReference <IClientEndpoint>());
 }
コード例 #18
0
 public static GrainReference FromKeyString(string key) => GrainReference.FromKeyString(key, null);