예제 #1
0
        public object Deserialize(global::MongoDB.Bson.IO.BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
        {
            if (!nominalType.IsAssignableFrom(typeof(JobDetailImpl)) || actualType != typeof(JobDetailImpl))
            {
                var message = string.Format("Can't deserialize a {0} with {1}.", nominalType.FullName, this.GetType().Name);
                throw new BsonSerializationException(message);
            }

            var bsonType = bsonReader.GetCurrentBsonType();

            if (bsonType == BsonType.Document)
            {
                bsonReader.ReadStartDocument();

                BsonSerializer.Deserialize(bsonReader, typeof(JobKey));
                bsonReader.ReadString("_t");

                Assembly assembly        = Assembly.Load(bsonReader.ReadString("_assembly"));
                Type     jobType         = assembly.GetType(bsonReader.ReadString("_class"));
                string   name            = bsonReader.ReadString("Name");
                string   group           = bsonReader.ReadString("Group");
                bool     requestRecovery = bsonReader.ReadBoolean("RequestRecovery");
                bool     durable         = bsonReader.ReadBoolean("Durable");

                IJobDetail jobDetail = new JobDetailImpl(name, group, jobType, durable, requestRecovery);

                bsonReader.ReadBsonType();
                JobDataMap map = (JobDataMap)BsonSerializer.Deserialize(bsonReader, typeof(JobDataMap));

                /*bsonReader.ReadBsonType();
                 * string description = (string)BsonSerializer.Deserialize(bsonReader, typeof(string));*/

                jobDetail = jobDetail.GetJobBuilder()
                            .UsingJobData(map)
                            /*.WithDescription(description)*/
                            .Build();

                bsonReader.ReadEndDocument();

                return(jobDetail);
            }
            else if (bsonType == BsonType.Null)
            {
                bsonReader.ReadNull();
                return(null);
            }
            else
            {
                var message = string.Format("Can't deserialize a {0} from BsonType {1}.", nominalType.FullName, bsonType);
                throw new BsonSerializationException(message);
            }
        }
        public object Deserialize(global::MongoDB.Bson.IO.BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
        {
            if (!nominalType.IsAssignableFrom(typeof(JobDetailImpl)) || actualType != typeof(JobDetailImpl))
            {
                var message = string.Format("Can't deserialize a {0} with {1}.", nominalType.FullName, this.GetType().Name);
                throw new BsonSerializationException(message);
            }

            var bsonType = bsonReader.GetCurrentBsonType();
            if (bsonType == BsonType.Document)
            {
                bsonReader.ReadStartDocument();

                BsonSerializer.Deserialize(bsonReader, typeof(JobKey));
                bsonReader.ReadString("_t");

                Assembly assembly = Assembly.Load(bsonReader.ReadString("_assembly"));
                Type jobType = assembly.GetType(bsonReader.ReadString("_class"));

                IJobDetail jobDetail = new JobDetailImpl(
                    bsonReader.ReadString("Name"),
                    bsonReader.ReadString("Group"),
                    jobType,
                    bsonReader.ReadBoolean("RequestRecovery"),
                    bsonReader.ReadBoolean("Durable"));

                bsonReader.ReadBsonType();
                JobDataMap map = (JobDataMap)BsonSerializer.Deserialize(bsonReader, typeof(JobDataMap));
                /*bsonReader.ReadBsonType();
                string description = (string)BsonSerializer.Deserialize(bsonReader, typeof(string));*/

                jobDetail = jobDetail.GetJobBuilder()
                    .UsingJobData(map)
                    /*.WithDescription(description)*/
                    .Build();

                bsonReader.ReadEndDocument();

                return jobDetail;
            }
            else if (bsonType == BsonType.Null)
            {
                bsonReader.ReadNull();
                return null;
            }
            else
            {
                var message = string.Format("Can't deserialize a {0} from BsonType {1}.", nominalType.FullName, bsonType);
                throw new BsonSerializationException(message);
            }
        }
예제 #3
0
        public override IJobDetail Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            BsonReader bsonReader  = (BsonReader)context.Reader;
            Type       nominalType = args.NominalType;

            var bsonType = bsonReader.GetCurrentBsonType();

            if (bsonType == BsonType.Document)
            {
                bsonReader.ReadStartDocument();

                BsonSerializer.Deserialize(bsonReader, typeof(JobKey));
                bsonReader.ReadString(TYPE);

                Assembly assembly        = Assembly.Load(bsonReader.ReadString(ASSEMBLY));
                Type     jobType         = assembly.GetType(bsonReader.ReadString(CLASS));
                string   name            = bsonReader.ReadString(NAME);
                string   group           = bsonReader.ReadString(GROUP);
                bool     requestRecovery = bsonReader.ReadBoolean(REQUEST_RECOVERY);
                bool     durable         = bsonReader.ReadBoolean(DURABLE);

                IJobDetail jobDetail = new JobDetailImpl(name, group, jobType, durable, requestRecovery);

                bsonReader.ReadBsonType();
                JobDataMap map = (JobDataMap)BsonSerializer.Deserialize(bsonReader, typeof(JobDataMap));

                /*bsonReader.ReadBsonType();
                 * string description = (string)BsonSerializer.Deserialize(bsonReader, typeof(string));*/

                jobDetail = jobDetail.GetJobBuilder()
                            .UsingJobData(map)
                            /*.WithDescription(description)*/
                            .Build();

                bsonReader.ReadEndDocument();

                return(jobDetail);
            }
            else if (bsonType == BsonType.Null)
            {
                bsonReader.ReadNull();
                return(null);
            }
            else
            {
                var message = string.Format(DESERIALIZE_ERROR_MESSAGE, nominalType.FullName, bsonType);
                throw new BsonSerializationException(message);
            }
        }