예제 #1
0
        public CassandraTypeSerializerAttribute(Type serializer)
        {
            // Contract, targetted implementation type must implement our interface
            if (!typeof(ICassandraTypeSerializer).IsAssignableFrom(serializer))
            {
                throw new ArgumentException(string.Format("{0} does not implement ICassandraTypeSerializer interface", serializer));
            }

            // Store the type for consumer-code introspection
            TypeSerializer = serializer;

            // Get the public constructors
            var ctors = serializer.GetConstructors();

            // Determine if there is a constructor which passed the serialized object's type
            var typeCtor = ctors.Where(ctor =>
            {
                var prms = ctor.GetParameters();
                return(prms.Length == 1 && prms.First().ParameterType == typeof(Type));
            }).FirstOrDefault();

            // Determine if there is a constructor which passed the serialized object's type as well as access to the default serializer and deserializer (recursable)
            var recurseCtor = ctors.Where(ctor =>
            {
                var prms = ctor.GetParameters().ToArray();
                return(prms.Length == 3 && prms[0].ParameterType == typeof(Type) && prms[1].ParameterType == typeof(Func <Type, Func <object, byte[]> >) && prms[2].ParameterType == typeof(Func <Type, Func <byte[], object> >));
            }).FirstOrDefault();

            // Populate the Serializer field with the appropriate delegate
            if (recurseCtor != null)
            {
                Serializer = (type, defaultSerializer, defaultDeserializer) => EnlightenmentMgr.CreateSerializer(serializer, type, defaultSerializer, defaultDeserializer);
            }
            else if (typeCtor != null)
            {
                Serializer = (type, defaultSerializer, defaultDeserializer) => EnlightenmentMgr.CreateSerializer(serializer, type);
            }
            else
            {
                Serializer = (type, defaultSerializer, defaultDeserializer) => EnlightenmentMgr.CreateSerializer(serializer);
            }
        }
예제 #2
0
// ReSharper restore StaticFieldInGenericType

        public static TI Create <TI>(string customType, params object[] prms)
        {
            if (string.IsNullOrEmpty(customType))
            {
                string emptyTypeMsg = string.Format("Expecting nickname or qualified class name for '{0}'", typeof(TI).AssemblyQualifiedName);
                throw new ArgumentException(emptyTypeMsg);
            }

            Type type;

            if (!_descriptor.Definition.TryGetValue(customType, out type))
            {
                type = Type.GetType(customType);
            }

            if (null == type || !typeof(TI).IsAssignableFrom(type))
            {
                string invalidTypeMsg = string.Format("'{0}' is not a valid type", customType);
                throw new ArgumentException(invalidTypeMsg);
            }

            return(EnlightenmentMgr.Create <TI>(type, prms));
        }
예제 #3
0
        public static ICqlCommandBuilderBuild ToPropertyBag(this ICqlCommandBuilderTo @this)
        {
            var factory = EnlightenmentMgr.PropertyBagDataMapperFactory();

            return(@this.Set(factory));
        }
예제 #4
0
 public static void Shutdown()
 {
     EnlightenmentMgr.ClusterManager().Shutdown();
 }
예제 #5
0
 public static void Configure(CassandraSharpConfig config)
 {
     EnlightenmentMgr.ClusterManager().Configure(config);
 }
예제 #6
0
 public static ICluster GetCluster(string name)
 {
     return(EnlightenmentMgr.ClusterManager().GetCluster(name));
 }
예제 #7
0
 public static ICluster GetCluster(ClusterConfig clusterConfig)
 {
     return(EnlightenmentMgr.ClusterManager().GetCluster(clusterConfig));
 }
        public static ICqlCommandBuilderTo FromPoco(this ICqlCommandBuilderFrom @this)
        {
            var factory = EnlightenmentMgr.PocoDataMapperFactory();

            return(@this.Set(factory));
        }
예제 #9
0
        public static ICqlCommandBuilderBuild ToOrdinal(this ICqlCommandBuilderTo @this)
        {
            var factory = EnlightenmentMgr.OrdinalDataMapperFactory();

            return(@this.Set(factory));
        }
예제 #10
0
 public ICqlCommand Build()
 {
     return(EnlightenmentMgr.CommandFactory().Create(_cluster, _factoryFrom, _factoryTo));
 }
예제 #11
0
 public static Task AsFuture(this IObservable <NonQuery> observable, CancellationToken?token = null)
 {
     return(EnlightenmentMgr.Future().AsFuture(observable, token));
 }
예제 #12
0
 public static Task <IList <T> > AsFuture <T>(this IObservable <T> observable, CancellationToken?token = null)
 {
     return(EnlightenmentMgr.Future().AsFuture(observable, token));
 }