Пример #1
0
        internal static Func <IDictionary <string, object>, bool> GetComparer <T>(string rangeParamName, T fromValue, T toValue) where T : IComparable
        {
            Comparer comparer    = Comparer.DefaultInvariant;
            bool     sameRange   = comparer.Compare(fromValue, toValue) == 0; // FromValue == ToValue
            bool     insideRange = comparer.Compare(fromValue, toValue) < 0;  // FromValue < ToValue
            Func <IDictionary <string, object>, bool> compareClause;

            if (sameRange)
            {
                compareClause = data =>
                {
                    if (data == null || data.Count <= 0)
                    {
                        return(false);
                    }

                    if (!data.ContainsKey(rangeParamName))
                    {
                        var error = string.Format("Cannot find column '{0}' for range query from {1} to {2} in Data={3}",
                                                  rangeParamName, fromValue, toValue, StorageProviderUtils.PrintData(data));
                        throw new KeyNotFoundException(error);
                    }
                    T obj = (T)data[rangeParamName];
                    return(comparer.Compare(obj, fromValue) == 0);
                };
            }
            else if (insideRange)
            {
                compareClause = data =>
                {
                    if (data == null || data.Count <= 0)
                    {
                        return(false);
                    }

                    if (!data.ContainsKey(rangeParamName))
                    {
                        var error = string.Format("Cannot find column '{0}' for range query from {1} to {2} in Data={3}",
                                                  rangeParamName, fromValue, toValue, StorageProviderUtils.PrintData(data));
                        throw new KeyNotFoundException(error);
                    }
                    T obj = (T)data[rangeParamName];
                    return(comparer.Compare(obj, fromValue) >= 0 && comparer.Compare(obj, toValue) <= 0);
                };
            }
            else
            {
                compareClause = data =>
                {
                    if (data == null || data.Count <= 0)
                    {
                        return(false);
                    }

                    if (!data.ContainsKey(rangeParamName))
                    {
                        var error = string.Format("Cannot find column '{0}' for range query from {1} to {2} in Data={3}",
                                                  rangeParamName, fromValue, toValue, StorageProviderUtils.PrintData(data));
                        throw new KeyNotFoundException(error);
                    }
                    T obj = (T)data[rangeParamName];
                    return(comparer.Compare(obj, fromValue) >= 0 || comparer.Compare(obj, toValue) <= 0);
                };
            }
            return(compareClause);
        }
Пример #2
0
 /// <summary>
 /// Return a hash value derived from the input grain type and id values.
 /// </summary>
 /// <param name="grainType">Fully qualified class type name for this grain</param>
 /// <param name="grainReference">GrainI reference for this grain</param>
 /// <returns>Stable hash value for this grain</returns>
 protected virtual int HashFunction(string grainType, GrainReference grainReference)
 {
     return(StorageProviderUtils.PositiveHash(grainReference, storageProviders.Length));
 }