/// <summary> /// Gets the ExportJobs for the particular map schema type for a domain and root map. /// </summary> /// <param name="mapType">OPTIONALLY: The map schema type</param> /// <param name="domainUid">The DomainUid for the exports</param> /// <param name="rootMapUid">The RootMapUid for the exports</param> /// <returns>A list of all the ExportJobs that match the criteria supplied as arguments</returns> private ExportJobsResponse GetExportJobsImp(MapType? mapType, Guid domainUid, Guid rootMapUid) { ExportJobsResponse response = new ExportJobsResponse(); response.ExportJobs = new Dictionary<Guid, ExportJob>(); try { Guid webID = SPContext.Current.Web.ID; Guid siteID = SPContext.Current.Site.ID; SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(siteID)) { using (SPWeb web = site.OpenWeb(webID)) { if (web != null) { SPList exportsList = web.TryGetList(web.GetServerRelativeListUrlPrefix() + "GlymaExports"); //TODO get the name from a constant if (exportsList != null) { SPQuery query = new SPQuery(); if (mapType.HasValue) { query.Query = "<Where><And><And>" + "<Eq><FieldRef Name='DomainUid' /><Value Type='Text'>" + domainUid.ToString() + "</Value></Eq>" + "<Eq><FieldRef Name='RootMapUid' /><Value Type='Text'>" + rootMapUid.ToString() + "</Value></Eq>" + "</And><Eq><FieldRef Name='MapType' /><Value Type='Text'>" + mapType.ToString() + "</Value></Eq></And></Where>" + "<OrderBy><FieldRef Name='Created' Ascending='TRUE'></FieldRef></OrderBy>"; } else { query.Query = "<Where><And>" + "<Eq><FieldRef Name='DomainUid' /><Value Type='Text'>" + domainUid.ToString() + "</Value></Eq>" + "<Eq><FieldRef Name='RootMapUid' /><Value Type='Text'>" + rootMapUid.ToString() + "</Value></Eq>" + "</And></Where>" + "<OrderBy><FieldRef Name='Created' Ascending='TRUE'></FieldRef></OrderBy>"; } //get the exports for this domain/rootmap in ascending order SPListItemCollection exports = exportsList.GetItems(query); foreach (SPListItem export in exports) { ExportJob exportJob = GetExportJob(export); response.ExportJobs.Add(exportJob.Id, exportJob); if (exportJob.Status == ExportStatus.Error) { //maintenance task if the export job had an error clear the TimerJobWorkItem if it was left behind CleanupErrorWorkItems(exportJob, site, web); } } } else { throw new Exception("Failed to find the Glyma Exports list."); } } else { throw new Exception("The SPWeb was not found."); } } } }); } catch (Exception ex) { ExportError error = new ExportError() { ErrorMessage = "Failed to get the export jobs for the site." }; throw new FaultException<ExportError>(error, ex.ToString()); } return response; }
/// <summary> /// Gets the ExportJobs for the particular map schema type for a domain and root map. /// </summary> /// <param name="mapType">OPTIONALLY: The map schema type</param> /// <param name="domainUid">The DomainUid for the exports</param> /// <param name="rootMapUid">The RootMapUid for the exports</param> /// <returns>A list of all the ExportJobs that match the criteria supplied as arguments</returns> private ExportJobsResponse GetExportJobsImp(MapType?mapType, Guid domainUid, Guid rootMapUid) { ExportJobsResponse response = new ExportJobsResponse(); response.ExportJobs = new Dictionary <Guid, ExportJob>(); try { Guid webID = SPContext.Current.Web.ID; Guid siteID = SPContext.Current.Site.ID; SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(siteID)) { using (SPWeb web = site.OpenWeb(webID)) { if (web != null) { SPList exportsList = web.TryGetList(web.GetServerRelativeListUrlPrefix() + "GlymaExports"); //TODO get the name from a constant if (exportsList != null) { SPQuery query = new SPQuery(); if (mapType.HasValue) { query.Query = "<Where><And><And>" + "<Eq><FieldRef Name='DomainUid' /><Value Type='Text'>" + domainUid.ToString() + "</Value></Eq>" + "<Eq><FieldRef Name='RootMapUid' /><Value Type='Text'>" + rootMapUid.ToString() + "</Value></Eq>" + "</And><Eq><FieldRef Name='MapType' /><Value Type='Text'>" + mapType.ToString() + "</Value></Eq></And></Where>" + "<OrderBy><FieldRef Name='Created' Ascending='TRUE'></FieldRef></OrderBy>"; } else { query.Query = "<Where><And>" + "<Eq><FieldRef Name='DomainUid' /><Value Type='Text'>" + domainUid.ToString() + "</Value></Eq>" + "<Eq><FieldRef Name='RootMapUid' /><Value Type='Text'>" + rootMapUid.ToString() + "</Value></Eq>" + "</And></Where>" + "<OrderBy><FieldRef Name='Created' Ascending='TRUE'></FieldRef></OrderBy>"; } //get the exports for this domain/rootmap in ascending order SPListItemCollection exports = exportsList.GetItems(query); foreach (SPListItem export in exports) { ExportJob exportJob = GetExportJob(export); response.ExportJobs.Add(exportJob.Id, exportJob); if (exportJob.Status == ExportStatus.Error) { //maintenance task if the export job had an error clear the TimerJobWorkItem if it was left behind CleanupErrorWorkItems(exportJob, site, web); } } } else { throw new Exception("Failed to find the Glyma Exports list."); } } else { throw new Exception("The SPWeb was not found."); } } } }); } catch (Exception ex) { ExportError error = new ExportError() { ErrorMessage = "Failed to get the export jobs for the site." }; throw new FaultException <ExportError>(error, ex.ToString()); } return(response); }