Пример #1
0
        public static string LoggingIdentifier(this IGrain grain)
        {
            var type = grain.GetType();

            try {
                string temp = null;
                if (typeof(IGrainWithIntegerKey).IsAssignableFrom(type))
                {
                    return($"[{grain.GetPrimaryKeyLong()}] ");
                }
                else if (typeof(IGrainWithIntegerCompoundKey).IsAssignableFrom(type))
                {
                    var key = grain.GetPrimaryKeyLong(out temp);
                    return($"[{key} {temp}] ");
                }
                else if (typeof(IGrainWithGuidKey).IsAssignableFrom(type))
                {
                    return($"[{grain.GetPrimaryKey()}] ");
                }
                else if (typeof(IGrainWithGuidCompoundKey).IsAssignableFrom(type))
                {
                    var key = grain.GetPrimaryKey(out temp);
                    return($"[{key} {temp}] ");
                }
                else if (typeof(IGrainWithStringKey).IsAssignableFrom(type))
                {
                    return($"[{grain.GetPrimaryKeyString()}] ");
                }
            } catch { } // Don't throw for logging methods.

            return(string.Empty);
        }
Пример #2
0
 public static string GetPrimaryKeyStringFromGrain(IGrain grain)
 {
     //TODO: Check to make sure grain is of type IGrainWithStringKey
     string stringPrimaryKey; 
     Guid guidPrimaryKey = grain.GetPrimaryKey(out stringPrimaryKey);
     return stringPrimaryKey;
 }
Пример #3
0
        public static string GetReadableName(IGrain grain)
        {
            string ext1;
            string guidPrefix = grain.GetPrimaryKey(out ext1).ToString().Substring(0, 8);

            return(guidPrefix + " " + ext1);
        }
Пример #4
0
        public static string GetPrimaryKeyStringFromGrain(IGrain grain)
        {
            //TODO: Check to make sure grain is of type IGrainWithStringKey
            string stringPrimaryKey;
            Guid   guidPrimaryKey = grain.GetPrimaryKey(out stringPrimaryKey);

            return(stringPrimaryKey);
        }
Пример #5
0
        /// <summary>
        /// Use instead of IGrain.GetPrimaryKeyString()!
        /// </summary>
        /// <param name="this"></param>
        /// <returns></returns>
        public static Guid ExtractKey(this IGrain @this)
        {
            if (@this is GrainReference)
            {
                return(@this.GetPrimaryKey());
            }

            if (@this is GrainProxy)
            {
                var identity = ExtractGrainIdentityFrom(@this);
                return(identity.PrimaryKey);
            }

            if (@this is Grain)
            {
                return(@this.GetPrimaryKey());
            }

            return(ExtractGrainIdentityFrom(@this).PrimaryKey);
        }
Пример #6
0
        protected void AssertIsInRange(long val, long lowerLimit, long upperLimit, IGrain grain, string reminderName, TimeSpan sleepFor)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("Grain: {0} Grain PrimaryKey: {1}, Reminder: {2}, SleepFor: {3} Time now: {4}",
                            grain, grain.GetPrimaryKey(), reminderName, sleepFor, Time());
            sb.AppendFormat(
                " -- Expecting value in the range between {0} and {1}, and got value {2}.",
                lowerLimit, upperLimit, val);
            this.log.Info(sb.ToString());

            bool tickCountIsInsideRange = lowerLimit <= val && val <= upperLimit;

            Skip.IfNot(tickCountIsInsideRange, $"AssertIsInRange: {sb}  -- WHICH IS OUTSIDE RANGE.");
        }
Пример #7
0
        private Func <object, Task> GetTimerFunc(IProviderRuntime providerRuntime, IGrain grain)
        {
            var grainName = grain.GetType().FullName;
            var pKey      = grain.GetPrimaryKey();

            return(async o =>
            {
                var filterableGrain = grain as IFilterable;
                var result = await filterableGrain.GetFilters();

                if (result != null)
                {
                    var filterGrain = providerRuntime.GrainFactory.GetGrain <ITypeFilterGrain>(grain.GetType().FullName);
                    await filterGrain.RegisterFilter(grainName, $"{pKey}", result);

                    var filterString = string.Join(",", result.Select(p => $"{p.FilterName} : {p.Value}"));
                    _logger.Verbose($"Filters for grain [Type : {grainName}] [Id : {grain.GetPrimaryKey()}][Filter : {filterString}]");
                }
                else
                {
                    _logger.Verbose("Filter was not set yet");
                }
            });
        }
Пример #8
0
        protected void AssertIsInRange(long val, long lowerLimit, long upperLimit, IGrain grain, string reminderName, TimeSpan sleepFor)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("Grain: {0} Grain PrimaryKey: {1}, Reminder: {2}, SleepFor: {3} Time now: {4}",
                            grain.ToString(), grain.GetPrimaryKey(), reminderName, sleepFor, Time());
            sb.AppendFormat(
                " -- Expecting value in the range between {0} and {1}, and got value {2}.",
                lowerLimit, upperLimit, val);
            logger.Info(sb.ToString());

            bool tickCountIsInsideRange = lowerLimit <= val && val <= upperLimit;

            if (!tickCountIsInsideRange)
            {
                Assert.Inconclusive("AssertIsInRange: {0}  -- WHICH IS OUTSIDE RANGE.", sb);
                // Not reached
            }
        }
Пример #9
0
        protected void AssertIsInRange(long val, long lowerLimit, long upperLimit, IGrain grain, string reminderName, TimeSpan sleepFor)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("Grain: {0} Grain PrimaryKey: {1}, Reminder: {2}, SleepFor: {3} Time now: {4}",
                grain.ToString(), grain.GetPrimaryKey(), reminderName, sleepFor, Time());
            sb.AppendFormat(
                " -- Expecting value in the range between {0} and {1}, and got value {2}.",
                lowerLimit, upperLimit, val);
            logger.Info(sb.ToString());

            bool tickCountIsInsideRange = lowerLimit <= val && val <= upperLimit;

            Skip.IfNot(tickCountIsInsideRange, string.Format("AssertIsInRange: {0}  -- WHICH IS OUTSIDE RANGE.", sb));
        }