public static OfflineJiraProvider Initialize(string backupLocation, JiraSettings settings)
        {
            if (!Directory.Exists(backupLocation))
            {
                throw new ArgumentException("backupLocation not correct");
            }
            OfflineJiraProvider provider = new OfflineJiraProvider();

            provider.backupDirectory = new DirectoryInfo(backupLocation);
            provider.Settings        = settings;
            Logger.Log(LogLevel.Info, "Loading backup files into ram");
            FileInfo[] files = provider.backupDirectory.GetFiles();
            foreach (FileInfo file in files)
            {
                if (file.Name == "activeobjects.xml")
                {
                    provider.activeObjects = XDocument.Load(file.FullName);
                }
                else if (file.Name == "entities.xml")
                {
                    provider.entities = XDocument.Load(file.FullName);
                }
            }
            return(provider);
        }
        private void ExecuteMigration(CommandOption user, CommandOption password, CommandOption useOfflineBackup, CommandOption url, CommandOption configFile, bool forceFresh, CommandOption continueOnCritical)
        {
            var itemsCount = 0;
            var exportedItemsCount = 0;
            var sw = new Stopwatch();
            sw.Start();

            try
            {
                string configFileName = configFile.Value();
                ConfigReaderJson configReaderJson = new ConfigReaderJson(configFileName);
                var config = configReaderJson.Deserialize();

                InitSession(config, continueOnCritical.Value());

                // Migration session level settings
                // where the logs and journal will be saved, logs aid debugging, journal is for recovery of interupted process
                string migrationWorkspace = config.Workspace;

                var downloadOptions = (DownloadOptions)config.DownloadOptions;

                var jiraSettings = new JiraSettings(user.Value(), password.Value(), url.Value(), config.SourceProject)
                {
                    BatchSize = config.BatchSize,
                    UserMappingFile = config.UserMappingFile != null ? Path.Combine(migrationWorkspace, config.UserMappingFile) : string.Empty,
                    AttachmentsDir = Path.Combine(migrationWorkspace, config.AttachmentsFolder),
                    JQL = config.Query,
                    UsingJiraCloud = config.UsingJiraCloud
                };
                IJiraProvider jiraProvider = null;
                if (useOfflineBackup.HasValue())
                {
                    jiraProvider = OfflineJiraProvider.Initialize(useOfflineBackup.Value(), jiraSettings);
                }
                else
                {
                    jiraProvider = JiraProvider.Initialize(jiraSettings);
                }

                itemsCount = jiraProvider.GetItemCount(jiraSettings.JQL);

                BeginSession(configFileName, config, forceFresh, jiraProvider, itemsCount);

                jiraSettings.EpicLinkField = jiraProvider.GetCustomId(config.EpicLinkField);
                if (string.IsNullOrEmpty(jiraSettings.EpicLinkField))
                {
                    Logger.Log(LogLevel.Warning, $"Epic link field missing for config field '{config.EpicLinkField}'.");
                }
                jiraSettings.SprintField = jiraProvider.GetCustomId(config.SprintField);
                if (string.IsNullOrEmpty(jiraSettings.SprintField))
                {
                    Logger.Log(LogLevel.Warning, $"Sprint link field missing for config field '{config.SprintField}'.");
                }

                var mapper = new JiraMapper(jiraProvider, config);
                var localProvider = new WiItemProvider(migrationWorkspace);
                var exportedKeys = new HashSet<string>(Directory.EnumerateFiles(migrationWorkspace, "*.json").Select(f => Path.GetFileNameWithoutExtension(f)));
                var skips = forceFresh ? new HashSet<string>(Enumerable.Empty<string>()) : exportedKeys;

                var issues = jiraProvider.EnumerateIssues(jiraSettings.JQL, skips, downloadOptions);

                foreach (var issue in issues)
                {
                    if (issue == null)
                        continue;

                    WiItem wiItem = mapper.Map(issue);
                    if (wiItem != null)
                    {
                        localProvider.Save(wiItem);
                        exportedItemsCount++;
                        Logger.Log(LogLevel.Debug, $"Exported as type '{wiItem.Type}'.");
                    }
                }
            }
            catch (CommandParsingException e)
            {
                Logger.Log(LogLevel.Error, $"Invalid command line option(s): {e}");
            }
            catch (Exception e)
            {
                Logger.Log(e, $"Unexpected migration error.");
            }
            finally
            {
                EndSession(itemsCount, sw);
            }
        }