public string SerializeJobCreationDetails(JobCreateParameters job)
        {
            if (job.IsNull())
            {
                throw new ArgumentNullException("job");
            }

            if (job.StatusFolder.IsNullOrEmpty())
            {
                job.StatusFolder = "(ignore)";
            }
            var asHiveJob      = job as HiveJobCreateParameters;
            var asMapReduceJob = job as MapReduceJobCreateParameters;
            var jobType        = asHiveJob.IsNotNull() ? "Hive" : "MapReduce";

            if (asHiveJob.IsNull() && asMapReduceJob.IsNull())
            {
                throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "Unsupported job type :{0}", job.GetType().FullName));
            }

            var jobName = asHiveJob == null ? asMapReduceJob.JobName : asHiveJob.JobName;

            if (jobName.IsNullOrEmpty())
            {
                throw new ArgumentException("A jobDetails name is required when submitting a jobDetails.", "job");
            }

            dynamic dynaXml = DynaXmlBuilder.Create();

            dynaXml.b
            .xmlns("http://schemas.datacontract.org/2004/07/Microsoft.ClusterServices.RDFEProvider.ResourceExtensions.JobSubmission.Models")
            .xmlns.i("http://www.w3.org/2001/XMLSchema-instance")
            .xmlns.a("http://schemas.microsoft.com/2003/10/Serialization/Arrays")
            .xmlns.s("http://www.w3.org/2001/XMLSchema")
            .ClientJobRequest
            .b
            .End();

            if (asMapReduceJob.IsNotNull() && asMapReduceJob.ClassName.IsNotNullOrEmpty())
            {
                dynaXml.ApplicationName(asMapReduceJob.ClassName);
            }
            else
            {
                dynaXml.ApplicationName.End();
            }

            dynaXml.Arguments
            .b
            .sp("arguments")
            .d
            .End();

            if (asMapReduceJob.IsNotNull() && asMapReduceJob.JarFile.IsNotNullOrEmpty())
            {
                dynaXml.JarFile(asMapReduceJob.JarFile);
            }
            else
            {
                dynaXml.JarFile.End();
            }

            dynaXml.JobName(jobName)
            .JobType(jobType.ToString())
            .OutputStorageLocation(job.StatusFolder)
            .Parameters
            .b
            .sp("parameters")
            .d
            .Query
            .b
            .sp("query")
            .d
            .Resources
            .b
            .sp("resources")
            .d
            .End();

            dynaXml.d.d.End();

            if (asHiveJob.IsNotNull() && asHiveJob.Query.IsNotNull())
            {
                dynaXml.rp("query")
                .text(asHiveJob.Query);

                if (asHiveJob.Defines.IsNotNull())
                {
                    foreach (var parameter in asHiveJob.Defines)
                    {
                        dynaXml.rp("parameters")
                        .JobRequestParameter
                        .b
                        .Key(parameter.Key)
                        .Value
                        .b
                        .at.xmlns.i.type("s:string")
                        .text(parameter.Value)
                        .d
                        .d
                        .End();
                    }
                }
            }
            if (asMapReduceJob.IsNotNull() && asMapReduceJob.Arguments.IsNotNull())
            {
                foreach (var argument in asMapReduceJob.Arguments)
                {
                    dynaXml.rp("arguments").xmlns.a.@string(argument);
                }

                if (asMapReduceJob.Defines.IsNotNull())
                {
                    foreach (var parameter in asMapReduceJob.Defines)
                    {
                        dynaXml.rp("parameters")
                        .JobRequestParameter
                        .b
                        .Key(parameter.Key)
                        .Value
                        .b
                        .at.xmlns.i.type("s:string")
                        .text(parameter.Value)
                        .d
                        .d
                        .End();
                    }
                }
            }

            if (job.Files.IsNotNull())
            {
                foreach (var resource in job.Files)
                {
                    dynaXml.rp("resources")
                    .JobRequestParameter
                    .b
                    .Key(resource)
                    .Value
                    .b
                    .at.xmlns.i.type("s:string")
                    .text(resource)
                    .d
                    .d
                    .End();
                }
            }
            return(dynaXml.ToString());
        }