示例#1
0
文件: GetMdJob.cs 项目: tgiqfe/MdJob
        protected override void ProcessRecord()
        {
            List <Job> joblist = JobSerializer.Deserialize(MDPath);

            Item.JsonIndented = true;
            DataSerializer.Serialize <List <Job> >(joblist, Console.Out, DataType.Json);
        }
示例#2
0
        public void SerializationDeserialize()
        {
            string typeName          = JobSerializer.GetTypeName(typeof(TestSerializationJob));
            string data              = @"{""A"":""1854ef1b-3937-476a-8b32-56436a7b6feb"",""B"":""Hello, world!"",""C"":""1982-05-28T07:00:00Z""}";
            TestSerializationJob job = JobSerializer.Deserialize(typeName, data) as TestSerializationJob;

            Assert.IsNotNull(job);
            Assert.AreEqual("1854ef1b-3937-476a-8b32-56436a7b6feb", job.A);
            Assert.AreEqual("Hello, world!", job.B);
            Assert.AreEqual(new DateTime(1982, 5, 28).ToUniversalTime(), job.C);

            Assert.IsNotNull(JobSerializer.Deserialize(typeName, null));
        }
示例#3
0
        protected virtual bool ValidateJobType(string typeName, string data, out IJob job, out string errorMessage)
        {
            bool success = false;

            job          = null;
            errorMessage = string.Empty;

            if (string.IsNullOrEmpty(typeName))
            {
                throw new ArgumentNullException("typeName", "typeName cannot be empty.");
            }

            data = (data ?? string.Empty).Trim();

            if (string.IsNullOrEmpty(data))
            {
                data = "{}";
            }

            try
            {
                job     = JobSerializer.Deserialize(typeName, data);
                success = true;
            }
            catch (ArgumentException)
            {
                errorMessage = "Job type contains invalid type syntax or does not implement IJob.";
            }
            catch (TargetInvocationException)
            {
                errorMessage = "Job type's class initializer threw an exception.";
            }
            catch (TypeLoadException)
            {
                errorMessage = "Failed to load job type.";
            }
            catch (FileNotFoundException)
            {
                errorMessage = "Job type or one of its dependencies was not found.";
            }
            catch (FileLoadException)
            {
                errorMessage = "Job type or one of its dependencies could not be loaded.";
            }
            catch (BadImageFormatException)
            {
                errorMessage = "Job type's assembly that could not be loaded into the current runtime.";
            }

            return(success);
        }
示例#4
0
        public IJob <IJobData> Pull()
        {
            if (jobs.Count > 0)
            {
                var jsonJob = jobs.First();
                var job     = JobSerializer.Deserialize(jsonJob.Value);

                var jobFilePath = Path.Combine(this.queuePath, jsonJob.Key + ".json");
                File.Delete(jobFilePath);

                jobs.Remove(jsonJob.Key);

                return(job);
            }

            return(null);
        }
示例#5
0
        protected override void ProcessRecord()
        {
            List <Job> jobList = JobSerializer.Deserialize(MDPath);

            if (Json)
            {
                Item.JsonIndented = JsonIndented;
                WriteObject(JobSerializer.Serialize(jobList, Item.EXTENSION_JSON));
                Item.JsonIndented = false;
            }
            else if (Xml)
            {
                WriteObject(JobSerializer.Serialize(jobList, Item.EXTENSION_XML));
            }
            else
            {
                WriteObject(JobSerializer.Serialize(jobList, Item.EXTENSION_MD));
            }
        }
示例#6
0
        public IJob <IJobData> Pull()
        {
            var db         = this.client.GetDatabase(DatabaseName);
            var collection = db.GetCollection <BsonDocument>(CollectionName);
            var filter     = Builders <BsonDocument> .Filter.Eq("Status", JobStatus.Enqueued.ToString());

            var update = Builders <BsonDocument> .Update.Set("Status", JobStatus.InProgress.ToString());

            var doc = collection.FindOneAndUpdate(filter, update);

            if (doc != null)
            {
                //lame but works
                string id = doc.GetElement("_id").Value.ToString();
                doc.Remove("_id");
                var jsonJob = doc.ToJson();
                var job     = JobSerializer.Deserialize(jsonJob);
                job.Id = id;

                return(job);
            }

            return(null);
        }