public static JobDescription GetJob(JobInstance job, QueryFactory queryFactory)
        {
            // In this function, we don't directly deserialize query parameters because
            // that could break old job definitions once the job format changes. It's
            // save to read parameters from the xml representation directly.

            var res = new JobDescription();
            res.Job = job;

            if (queryJobDefinitions.ContainsKey(job.JobDefinitionReference.Guid))
            {
                res.JobType = JobType.Query;

                // debug code
                if (job.Parameters.ContainsKey("Query"))
                {
                    var xml = new XmlDocument();
                    xml.LoadXml(job.Parameters["Query"].XmlValue);

                    res.Query = GetXmlInnerText(xml, "Query/QueryString");
                    res.SchemaName = GetXmlInnerText(xml, "Query/Destination/Table/SchemaName");
                    res.ObjectName = GetXmlInnerText(xml, "Query/Destination/Table/ObjectName");
                }
                else
                {
                    // This is probably a wrong job in the database
                }
            }
            else if (exportJobDefinitions.ContainsKey(job.JobDefinitionReference.Guid))
            {
                res.JobType = JobType.ExportTable;

                if (job.Parameters.ContainsKey("Parameters"))
                {
                    var xml = new XmlDocument();
                    xml.LoadXml(job.Parameters["Parameters"].XmlValue);

                    res.SchemaName = GetXmlInnerText(xml, "ExportTable/Source/SchemaName");
                    res.ObjectName = GetXmlInnerText(xml, "ExportTable/Source/ObjectName");
                    res.Path = GetXmlInnerText(xml, "ExportTable/Destination/Path");
                }
            }
            else
            {
                res.JobType = JobType.Unknown;
            }

            return res;
        }
        private static void GetQueryJobDescription(JobInstance job, JobDescription jobDescription)
        {
            jobDescription.JobType = JobType.Query;

            // debug code
            if (job.Parameters.ContainsKey("Query"))
            {
                var xml = new XmlDocument();
                xml.LoadXml(job.Parameters["Query"].XmlValue);

                jobDescription.Query = GetXmlInnerText(xml, "Query/QueryString");
                jobDescription.SchemaName = GetXmlInnerText(xml, "Query/Destination/SchemaName");
                jobDescription.ObjectName = GetXmlInnerText(xml, "Query/Destination/TableName");
            }
            else
            {
                // This is probably a wrong job in the database
            }
        }
        public static JobDescription GetJobDescription(JobInstance job)
        {
            // In this function, we don't directly deserialize query parameters because
            // that could break old job definitions once the job format changes. It's
            // save to read parameters from the xml representation directly.

            var jobDescription = new JobDescription();
            jobDescription.Job = job;

            try
            {
                if (queryJobDefinitions.ContainsKey(job.JobDefinitionReference.Guid))
                {
                    GetQueryJobDescription(job, jobDescription);
                }
                else if (exportJobDefinitions.ContainsKey(job.JobDefinitionReference.Guid))
                {
                    GetExportJobDescription(job, jobDescription);
                }
                else
                {
                    jobDescription.JobType = JobType.Unknown;
                }
            }
            catch (Exception)
            {
                jobDescription.JobType = JobType.Unknown;
            }

            return jobDescription;
        }
        private static void GetExportJobDescription(JobInstance job, JobDescription jobDescription)
        {
            jobDescription.JobType = JobType.ExportTable;

            if (job.Parameters.ContainsKey("Parameters"))
            {
                var xml = new XmlDocument();
                xml.LoadXml(job.Parameters["Parameters"].XmlValue);

                jobDescription.SchemaName = GetXmlInnerText(xml, "ExportTables/Sources/TableOrView/SchemaName");
                jobDescription.ObjectName = GetXmlInnerText(xml, "ExportTables/Sources/TableOrView/ObjectName");
                jobDescription.Path = GetXmlInnerText(xml, "ExportTables/Destinations/DataFileBase/Uri");
            }
        }