public XmlDataExporter(VhfProject project, bool includeContacts, RecordProcessingScope recordProcessingScope) { ExportInfo = new Epi.ImportExport.ProjectPackagers.ExportInfo(); _project = project; _includeContacts = includeContacts; _scope = recordProcessingScope; double totalMajorItems = 2; if (!_includeContacts) { totalMajorItems--; } Filters = new Dictionary <string, SyncFileFilters>(); FieldsToNull = new Dictionary <string, List <string> >(); foreach (View form in Project.Views) { FieldsToNull.Add(form.Name, new List <string>()); Filters.Add(form.Name, new SyncFileFilters(Project.CollectedData.GetDatabase())); if (!_includeContacts && form.Name.Equals(Core.Constants.CONTACT_FORM_NAME, StringComparison.OrdinalIgnoreCase)) { continue; } totalMajorItems++; // 1 for each form } StartDate = new DateTime(2000, 1, 1); EndDate = DateTime.Today.AddDays(3); _majorProgressIncrement = 100 / totalMajorItems; }
/// <summary> /// Initiates form packaging and returns the corresponding package in Xml format. /// </summary> /// <remarks> /// The returned Xml is not encrypted and not compressed. The calling object is responsible for that, should it be desired. /// </remarks> public XmlDocument PackageForm() { if (StatusChanged != null) { StatusChanged("Starting package processing..."); } ExportInfo = new Epi.ImportExport.ProjectPackagers.ExportInfo(); ExportInfo.UserID = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString(); ExportInfo.ExportInitiated = DateTime.Now; ExportInfo.FormsProcessed = 0; CheckForProblems(); // check to see if problems exist in the data or metadata that is about to be exported IdList = new Dictionary <string, XmlElement>(); XmlDocument xmlDataPackage = new XmlDocument(); XmlElement root = xmlDataPackage.CreateElement("DataPackage"); CreateRootAttributes(xmlDataPackage, root); // Process the parent form first, before getting to any relational forms... root.AppendChild(CreateXmlFormElement(xmlDataPackage, SourceForm)); ExportInfo.FormsProcessed++; // ... now that we've processed the parent, we want to process each related form. But we want to process // those related forms in order, based on how far away they are from the parent (the root). This is necessary // so that we can take the GUIDs from the last parent processed and use them to delete orphans. List <View> formsToProcess = new List <View>(); SortedDictionary <int, List <View> > forms = new SortedDictionary <int, List <View> >(); // Iterate over all the views in the source project... foreach (View form in SourceProject.Views) { // Don't process the parent, since we already did that above if (form.Name == SourceForm.Name) { continue; } // If the form is a descendant of the source form... if (Epi.ImportExport.ImportExportHelper.IsFormDescendant(form, SourceForm)) { // Include this form in the dictionary of forms to process // Note: We're sorting these so that the forms are generated in top-to-bottom order in the Xml int level = Epi.ImportExport.ImportExportHelper.GetFormDescendantLevel(form, SourceForm, 0); if (!forms.ContainsKey(level)) { forms.Add(level, new List <View>()); } forms[level].Add(form); } } foreach (KeyValuePair <int, List <View> > kvp in forms) { foreach (View form in kvp.Value) { CurrentDistanceFromRoot = kvp.Key; root.AppendChild(CreateXmlFormElement(xmlDataPackage, form)); PreviousDistanceFromRoot = kvp.Key; ExportInfo.FormsProcessed++; } } xmlDataPackage.AppendChild(root); if (StatusChanged != null) { StatusChanged(PackagerStrings.PACKAGE_CREATED); } return(xmlDataPackage); }