/// <summary>
        /// Handles the DoWorker event for the worker
        /// </summary>
        /// <param name="sender">Object that fired the event</param>
        /// <param name="e">.NET supplied event parameters</param>
        private void importWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            lock (syncLock)
            {
                foreach (string packagePath in packagePaths)
                {
                    try
                    {
                        string str = Configuration.DecryptFileToString(packagePath, txtPassword.Text);

                        if (!str.StartsWith("[[EPIINFO"))
                        {
                            #region LEGACY_IMPORT
                            List<string> paths = new List<string>();
                            paths.Add(packagePath);
                            ProjectUnpackager projectUnpackager = new ProjectUnpackager(destinationView, paths, password);
                            projectUnpackager.SetProgressBar += new SetProgressBarDelegate(CallbackIncrementProgressBar);
                            projectUnpackager.SetStatus += new UpdateStatusEventHandler(CallbackSetStatusMessage);
                            projectUnpackager.AddStatusMessage += new UpdateStatusEventHandler(CallbackAddStatusMessage);
                            projectUnpackager.SetMaxProgressBarValue += new SetMaxProgressBarValueDelegate(CallbackSetupProgressBar);
                            projectUnpackager.FinishUnpackage += new SimpleEventHandler(CallbackFinishUnpackaging);
                            projectUnpackager.Update = update;
                            projectUnpackager.Append = append;

                            try
                            {
                                if (!(string.IsNullOrEmpty(customSalt) && string.IsNullOrEmpty(customInitVector)))
                                {
                                    projectUnpackager.SetCustomDecryptionParameters(customSalt, customInitVector, customIterations);
                                }
                                projectUnpackager.UnpackageProjects();
                            }
                            catch (Exception ex)
                            {
                                e.Result = ex;
                            }
                            #endregion // LEGACY_IMPORT
                        }
                        else
                        {
                            str = str.Remove(0, 24);

                            string plainText = ImportExportHelper.UnZip(str);

                            XmlDocument xmlDataPackage = new XmlDocument();
                            xmlDataPackage.LoadXml(plainText);

                            XmlNodeList xnList = xmlDataPackage.SelectNodes("/DataPackage/Form/KeyFields");

                            if (xnList.Count == 0 || (xnList.Count == 1 && xnList[0].ChildNodes.Count == 0))
                            {
                                XmlDataUnpackager xmlUP = new Epi.ImportExport.ProjectPackagers.XmlDataUnpackager(destinationView, xmlDataPackage);
                                xmlUP.StatusChanged += new UpdateStatusEventHandler(CallbackSetStatusMessage);
                                xmlUP.UpdateProgress += new SetProgressBarDelegate(CallbackSetProgressBar);
                                xmlUP.ResetProgress += new SimpleEventHandler(CallbackResetProgressBar);
                                xmlUP.MessageGenerated += new UpdateStatusEventHandler(CallbackAddStatusMessage);
                                xmlUP.ImportFinished += new EventHandler(xmlUP_ImportFinished);
                                xmlUP.Append = append;
                                xmlUP.Update = update;
                                xmlUP.Unpackage();
                            }
                            else
                            {
                                XmlMultiKeyDataUnpackager xmlUP = new Epi.ImportExport.ProjectPackagers.XmlMultiKeyDataUnpackager(destinationView, xmlDataPackage);
                                xmlUP.StatusChanged += new UpdateStatusEventHandler(CallbackSetStatusMessage);
                                xmlUP.UpdateProgress += new SetProgressBarDelegate(CallbackSetProgressBar);
                                xmlUP.ResetProgress += new SimpleEventHandler(CallbackResetProgressBar);
                                xmlUP.MessageGenerated += new UpdateStatusEventHandler(CallbackAddStatusMessage);
                                xmlUP.ImportFinished += new EventHandler(xmlUP_ImportFinished);

                                xmlUP.Append = append;
                                xmlUP.Update = update;
                                xmlUP.Unpackage();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        e.Result = ex;
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Handles the DoWorker event for the worker
        /// </summary>
        /// <param name="sender">Object that fired the event</param>
        /// <param name="e">.NET supplied event parameters</param>
        private void importWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            lock (syncLock)
            {
                foreach (string packagePath in packagePaths)
                {
                    try
                    {
                        string str = Configuration.DecryptFileToString(packagePath, txtPassword.Text);

                        if (!str.StartsWith("[[EPIINFO"))
                        {
                            #region LEGACY_IMPORT
                            List <string> paths = new List <string>();
                            paths.Add(packagePath);
                            ProjectUnpackager projectUnpackager = new ProjectUnpackager(destinationView, paths, password);
                            projectUnpackager.SetProgressBar         += new SetProgressBarDelegate(CallbackIncrementProgressBar);
                            projectUnpackager.SetStatus              += new UpdateStatusEventHandler(CallbackSetStatusMessage);
                            projectUnpackager.AddStatusMessage       += new UpdateStatusEventHandler(CallbackAddStatusMessage);
                            projectUnpackager.SetMaxProgressBarValue += new SetMaxProgressBarValueDelegate(CallbackSetupProgressBar);
                            projectUnpackager.FinishUnpackage        += new SimpleEventHandler(CallbackFinishUnpackaging);
                            projectUnpackager.Update = update;
                            projectUnpackager.Append = append;

                            try
                            {
                                if (!(string.IsNullOrEmpty(customSalt) && string.IsNullOrEmpty(customInitVector)))
                                {
                                    projectUnpackager.SetCustomDecryptionParameters(customSalt, customInitVector, customIterations);
                                }
                                projectUnpackager.UnpackageProjects();
                            }
                            catch (Exception ex)
                            {
                                e.Result = ex;
                            }
                            #endregion // LEGACY_IMPORT
                        }
                        else
                        {
                            str = str.Remove(0, 24);

                            string plainText = ImportExportHelper.UnZip(str);

                            XmlDocument xmlDataPackage = new XmlDocument();
                            xmlDataPackage.LoadXml(plainText);

                            XmlNodeList xnList = xmlDataPackage.SelectNodes("/DataPackage/Form/KeyFields");

                            if (xnList.Count == 0 || (xnList.Count == 1 && xnList[0].ChildNodes.Count == 0))
                            {
                                XmlDataUnpackager xmlUP = new Epi.ImportExport.ProjectPackagers.XmlDataUnpackager(destinationView, xmlDataPackage);
                                xmlUP.StatusChanged    += new UpdateStatusEventHandler(CallbackSetStatusMessage);
                                xmlUP.UpdateProgress   += new SetProgressBarDelegate(CallbackSetProgressBar);
                                xmlUP.ResetProgress    += new SimpleEventHandler(CallbackResetProgressBar);
                                xmlUP.MessageGenerated += new UpdateStatusEventHandler(CallbackAddStatusMessage);
                                xmlUP.ImportFinished   += new EventHandler(xmlUP_ImportFinished);
                                xmlUP.Append            = append;
                                xmlUP.Update            = update;
                                xmlUP.Unpackage();
                            }
                            else
                            {
                                XmlMultiKeyDataUnpackager xmlUP = new Epi.ImportExport.ProjectPackagers.XmlMultiKeyDataUnpackager(destinationView, xmlDataPackage);
                                xmlUP.StatusChanged    += new UpdateStatusEventHandler(CallbackSetStatusMessage);
                                xmlUP.UpdateProgress   += new SetProgressBarDelegate(CallbackSetProgressBar);
                                xmlUP.ResetProgress    += new SimpleEventHandler(CallbackResetProgressBar);
                                xmlUP.MessageGenerated += new UpdateStatusEventHandler(CallbackAddStatusMessage);
                                xmlUP.ImportFinished   += new EventHandler(xmlUP_ImportFinished);

                                xmlUP.Append = append;
                                xmlUP.Update = update;
                                xmlUP.Unpackage();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        e.Result = ex;
                    }
                }
            }
        }