/// <summary>
        /// Adds the new test cases to new suites destination.
        /// </summary>
        public void AddNewTestCasesToNewSuitesDestinationInternal()
        {
            if (!string.IsNullOrEmpty(this.MigrationAddTestCasesToSuitesRetryJsonPath) && File.Exists(this.MigrationAddTestCasesToSuitesRetryJsonPath))
            {
                this.testCasesAddToSuitesMigrationLogManager = new MigrationLogManager(this.MigrationAddTestCasesToSuitesRetryJsonPath);
                this.testCasesAddToSuitesMigrationLogManager.LoadCollectionFromExistingFile();
                this.sharedStepsMapping = this.testCasesAddToSuitesMigrationLogManager.GetProssedItemsMappings();
            }
            else
            {
                this.testCasesAddToSuitesMigrationLogManager = new MigrationLogManager("testCasesToSuites", this.DefaultJsonFolder);
            }
            this.ProgressConcurrentQueue.Enqueue("Prepare destination test cases...");
            ITestPlan destinationTestPlan = TestPlanManager.GetTestPlanByName(this.destinationTeamProject, this.SelectedDestinationTestPlan);
            List<TestCase> destinationTestCases = TestCaseManager.GetAllTestCasesInTestPlan(this.destinationTeamProject, destinationTestPlan, false);
            this.ProgressConcurrentQueue.Enqueue("Prepare source test cases...");
            ITestPlan sourceTestPlan = TestPlanManager.GetTestPlanByName(this.sourceTeamProject, this.SelectedSourceTestPlan);
            List<TestCase> sourceTestCases = TestCaseManager.GetAllTestCasesFromSuiteCollection(this.sourcePreferences.TestPlan, this.sourcePreferences.TestPlan.RootSuite.SubSuites);

            foreach (TestCase currentSourceTestCase in sourceTestCases)
            {
                if (this.executionCancellationToken.IsCancellationRequested)
                {
                    break;
                }

                // If it's already processed skip it
                if (this.testCasesAddToSuitesMigrationLogManager.MigrationEntries.Count(e => e.SourceId.Equals(currentSourceTestCase.ITestCase.Id) && e.IsProcessed.Equals(true)) > 0)
                {
                    continue;
                }
                if (currentSourceTestCase.ITestSuiteBase != null && this.ObservableSuitesToBeSkipped.Count(t => t != null && t.NewText != null && t.NewText.Equals(currentSourceTestCase.ITestSuiteBase.Title)) > 0)
                {
                    continue;
                }
                string infoMessage = String.Empty;
                try
                {
                    infoMessage = String.Format("Start Adding to Suite Test Case with Source Id= {0}", currentSourceTestCase.Id);
                    log.Info(infoMessage);
                    this.ProgressConcurrentQueue.Enqueue(infoMessage);

                    if (currentSourceTestCase.ITestSuiteBase == null)
                    {
                        continue;
                    }
                    else
                    {
                        int sourceParentSuiteId = currentSourceTestCase.ITestSuiteBase.Id;
                        if (!this.suitesMapping.ContainsKey(sourceParentSuiteId))
                        {
                            return;
                        }
                        else
                        {
                            int destinationSuiteId = this.suitesMapping[sourceParentSuiteId];
                            ITestSuiteBase destinationSuite = this.destinationTeamProject.TestSuites.Find(destinationSuiteId);
                            if (this.testCasesMapping.ContainsKey(currentSourceTestCase.ITestCase.Id))
                            {
                                TestCase currentDestinationTestCase = destinationTestCases.FirstOrDefault(t => t.Id.Equals(this.testCasesMapping[currentSourceTestCase.ITestCase.Id]));
                                destinationSuite.AddTestCase(currentDestinationTestCase.ITestCase);

                                this.testCasesAddToSuitesMigrationLogManager.Log(currentSourceTestCase.ITestCase.Id, destinationSuite.Id, true);
                                infoMessage = String.Format("Test Case SUCCESSFULLY added to Suite: Test Case Id= {0}, Suite Id= {1}", currentDestinationTestCase.ITestCase.Id, destinationSuite.Id);
                                log.Info(infoMessage);
                                this.ProgressConcurrentQueue.Enqueue(infoMessage);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (currentSourceTestCase != null)
                    {
                        this.testCasesAddToSuitesMigrationLogManager.Log(currentSourceTestCase.ITestCase.Id, -1, false, ex.Message);
                        log.Error(ex);
                        this.ProgressConcurrentQueue.Enqueue(ex.Message);
                    }
                }
                finally
                {
                    this.testCasesAddToSuitesMigrationLogManager.Save();
                    this.MigrationAddTestCasesToSuitesRetryJsonPath = this.testCasesAddToSuitesMigrationLogManager.FullResultFilePath;
                }
            }
        }
        /// <summary>
        /// Migrates the test cases from source to destination.
        /// </summary>
        public void MigrateTestCasesFromSourceToDestinationInternal()
        {
            if (!string.IsNullOrEmpty(this.MigrationTestCasesRetryJsonPath) && File.Exists(this.MigrationTestCasesRetryJsonPath))
            {
                this.testCasesMigrationLogManager = new MigrationLogManager(this.MigrationTestCasesRetryJsonPath);
                this.testCasesMigrationLogManager.LoadCollectionFromExistingFile();
                this.testCasesMapping = this.testCasesMigrationLogManager.GetProssedItemsMappings();
            }
            else
            {
                this.testCasesMigrationLogManager = new MigrationLogManager("testCases", this.DefaultJsonFolder);
            }

            this.ProgressConcurrentQueue.Enqueue("Prepare source test cases...");
            ITestPlan sourceTestPlan = TestPlanManager.GetTestPlanByName(this.sourceTeamProject, this.SelectedSourceTestPlan);
            List<TestCase> sourceTestCases = TestCaseManager.GetAllTestCasesFromSuiteCollection(this.sourcePreferences.TestPlan, this.sourcePreferences.TestPlan.RootSuite.SubSuites);
            TestCaseManager.AddTestCasesWithoutSuites(this.sourceTeamProject, this.sourcePreferences.TestPlan, sourceTestCases);
            foreach (TestCase currentSourceTestCase in sourceTestCases)
            { 
                if (this.executionCancellationToken.IsCancellationRequested)
                {
                    break;
                }

                // If it's already processed skip it
                if (this.testCasesMigrationLogManager.MigrationEntries.Count(e => e.SourceId.Equals(currentSourceTestCase.ITestCase.Id) && e.IsProcessed.Equals(true)) > 0)
                {
                    continue;
                }
                string infoMessage = String.Empty;
                try
                {
                    infoMessage = String.Format("Start Migrating Test Case with Source Id= {0}", currentSourceTestCase.Id);
                    log.Info(infoMessage);
                    this.ProgressConcurrentQueue.Enqueue(infoMessage);

                    //Don't migrate the test case if its suite is in the exclusion list
                    if (currentSourceTestCase.ITestSuiteBase != null && this.ObservableSuitesToBeSkipped.Count(t => t != null && t.NewText != null && t.NewText.Equals(currentSourceTestCase.ITestSuiteBase.Title)) > 0)
                    {
                        continue;
                    }
                    List<TestStep> currentSourceTestCaseTestSteps = TestStepManager.GetTestStepsFromTestActions(this.sourceTeamProject, currentSourceTestCase.ITestCase.Actions);
                    bool shouldCreateTestCase = true;
                    foreach (TestStep currentTestStep in currentSourceTestCaseTestSteps)
                    {
                        if (currentTestStep.IsShared)
                        {
                            //If the test step is shared we change the current shared step id with the newly created shared step in the destination team project
                            if (this.sharedStepsMapping.ContainsKey(currentTestStep.SharedStepId))
                            {
                                currentTestStep.SharedStepId = this.sharedStepsMapping[currentTestStep.SharedStepId];
                            }
                            else
                            {
                                // Don't save if the required shared steps are missing
                                shouldCreateTestCase = false;
                            }
                        }
                    }
                    if (shouldCreateTestCase)
                    {
                        TestCase newTestCase = currentSourceTestCase.Save(this.destinationTeamProject, this.destinationPreferences.TestPlan, true, null, currentSourceTestCaseTestSteps, false, isMigration: true);
                        this.testCasesMapping.Add(currentSourceTestCase.ITestCase.Id, newTestCase.ITestCase.Id);
                        this.testCasesMigrationLogManager.Log(currentSourceTestCase.ITestCase.Id, newTestCase.ITestCase.Id, true);
                        infoMessage = String.Format("Test Case Migrated SUCCESSFULLY: Source Id= {0}, Destination Id= {1}", currentSourceTestCase.ITestCase.Id, newTestCase.ITestCase.Id);
                        log.Info(infoMessage);
                        this.ProgressConcurrentQueue.Enqueue(infoMessage);
                    }
                }
                catch (Exception ex)
                {
                    if (currentSourceTestCase != null)
                    {
                        this.testCasesMigrationLogManager.Log(currentSourceTestCase.ITestCase.Id, -1, false, ex.Message);
                        log.Error(ex);
                        this.ProgressConcurrentQueue.Enqueue(ex.Message);
                    }
                }
                finally
                {
                    this.testCasesMigrationLogManager.Save();
                    this.MigrationTestCasesRetryJsonPath = this.testCasesMigrationLogManager.FullResultFilePath;
                }
            }
        }
 /// <summary>
 /// Displays the not prossed entities.
 /// </summary>
 /// <param name="logManager">The log manager.</param>
 private void DisplayNotProssedEntities(MigrationLogManager logManager)
 {
     List<MigrationRetryEntry> notProssedEntries = logManager.GetNotProssedEntries();
     ModernDialog.ShowMessage(String.Format("Number of not processed: {0}", notProssedEntries.Count), "Warning", MessageBoxButton.OK);
 }
        /// <summary>
        /// Migrates the suites from source to destination internal.
        /// </summary>
        /// <param name="subSuitesCore">The sub suites core.</param>
        /// <param name="parentId">The parent id.</param>
        private void MigrateSuitesFromSourceToDestinationInternal(ITestSuiteCollection subSuitesCore, int parentId)
        {
            if (!string.IsNullOrEmpty(this.MigrationSuitesRetryJsonPath) && File.Exists(this.MigrationSuitesRetryJsonPath))
            {
                this.suitesMigrationLogManager = new MigrationLogManager(this.MigrationSuitesRetryJsonPath);
                this.suitesMigrationLogManager.LoadCollectionFromExistingFile();
                this.suitesMapping = this.suitesMigrationLogManager.GetProssedItemsMappings();
            }
            else
            {
                this.suitesMigrationLogManager = new MigrationLogManager("suites", this.DefaultJsonFolder);
            }

            if (subSuitesCore == null || subSuitesCore.Count == 0)
            {
                return;
            }
            foreach (ITestSuiteBase currentSuite in subSuitesCore)
            {
                if (this.executionCancellationToken.IsCancellationRequested)
                {
                    break;
                }
                // If it's already processed skip it
                if (this.suitesMigrationLogManager.MigrationEntries.Count(e => e.SourceId.Equals(currentSuite.Id) && e.IsProcessed.Equals(true)) > 0)
                {
                    continue;
                }

                string infoMessage = String.Empty;
                try
                {
                    infoMessage = String.Format("Start Migrating Suite with Source Id= {0}", currentSuite.Id);
                    log.Info(infoMessage);
                    this.ProgressConcurrentQueue.Enqueue(infoMessage);
                    int newSuiteId = 0;
                    if (currentSuite != null)
                    {
                        currentSuite.Refresh();
                        //Don't migrate the suite if its suite is in the exclusion list
                        if (this.ObservableSuitesToBeSkipped.Count(t => t != null && t.NewText != null && t.NewText.Equals(currentSuite.Title)) > 0)
                        {
                            continue;
                        }
                        bool canBeAddedNewSuite;
                        newSuiteId = TestSuiteManager.AddChildSuite(this.destinationTeamProject, this.destinationPreferences.TestPlan, parentId, currentSuite.Title, out canBeAddedNewSuite);
                        if (newSuiteId != 0)
                        {
                            this.suitesMapping.Add(currentSuite.Id, newSuiteId);
                        }

                        if (!(currentSuite is IRequirementTestSuite))
                        {
                            IStaticTestSuite suite = currentSuite as IStaticTestSuite;
                            this.MigrateSuitesFromSourceToDestinationInternal(suite.SubSuites, newSuiteId);
                        }
                    }

                    this.suitesMigrationLogManager.Log(currentSuite.Id, newSuiteId, true);
                    infoMessage = String.Format("Suite Migrated SUCCESSFULLY: Source Id= {0}, Destination Id= {1}", currentSuite.Id, newSuiteId);
                    log.Info(infoMessage);
                    this.ProgressConcurrentQueue.Enqueue(infoMessage);
                }
                catch (Exception ex)
                {
                    this.suitesMigrationLogManager.Log(currentSuite.Id, -1, false, ex.Message);
                    log.Error(ex);
                    this.ProgressConcurrentQueue.Enqueue(ex.Message);
                }
                finally
                {
                    this.suitesMigrationLogManager.Save();
                    this.MigrationSuitesRetryJsonPath = this.suitesMigrationLogManager.FullResultFilePath;
                }
            }
            this.IsSuitesMigrationFinished = true;
        }
        /// <summary>
        /// Migrates the shared steps from source to destination.
        /// </summary>
        private void MigrateSharedStepsFromSourceToDestinationInternal()
        {
            if (!string.IsNullOrEmpty(this.MigrationSharedStepsRetryJsonPath) && File.Exists(this.MigrationSharedStepsRetryJsonPath))
            {
                this.sharedStepsMigrationLogManager = new MigrationLogManager(this.MigrationSharedStepsRetryJsonPath);
                this.sharedStepsMigrationLogManager.LoadCollectionFromExistingFile();
                this.sharedStepsMapping = this.sharedStepsMigrationLogManager.GetProssedItemsMappings();
            }
            else
            {
                this.sharedStepsMigrationLogManager = new MigrationLogManager("sharedSteps", this.DefaultJsonFolder);
            }

            List<SharedStep> sourceSharedSteps = SharedStepManager.GetAllSharedStepsInTestPlan(this.sourceTeamProject);
            foreach (SharedStep currentSourceSharedStep in sourceSharedSteps)
            {
                if (this.executionCancellationToken.IsCancellationRequested)
                {
                    break;
                }

                // If it's already processed skip it
                if (this.sharedStepsMigrationLogManager.MigrationEntries.Count(e => e.SourceId.Equals(currentSourceSharedStep.ISharedStep.Id) && e.IsProcessed.Equals(true)) > 0)
                {
                    continue;
                }
                string infoMessage = String.Empty;
                try
                {
                    infoMessage = String.Format("Start Migrating Shared Step with Source Id= {0}", currentSourceSharedStep.Id);
                    log.Info(infoMessage);
                    this.ProgressConcurrentQueue.Enqueue(infoMessage);

                    List<TestStep> testSteps = TestStepManager.GetTestStepsFromTestActions(this.sourceTeamProject, currentSourceSharedStep.ISharedStep.Actions);
                    SharedStep newSharedStep = currentSourceSharedStep.Save(this.destinationTeamProject, true, testSteps, false);
                    newSharedStep.ISharedStep.Refresh();
                    this.sharedStepsMapping.Add(currentSourceSharedStep.ISharedStep.Id, newSharedStep.ISharedStep.Id);

                    this.sharedStepsMigrationLogManager.Log(currentSourceSharedStep.Id, newSharedStep.ISharedStep.Id, true);
                    infoMessage = String.Format("Shared Step Migrated SUCCESSFULLY: Source Id= {0}, Destination Id= {1}", currentSourceSharedStep.Id, newSharedStep.ISharedStep.Id);
                    log.Info(infoMessage);
                    this.ProgressConcurrentQueue.Enqueue(infoMessage);
                }
                catch (Exception ex)
                {
                    this.sharedStepsMigrationLogManager.Log(currentSourceSharedStep.Id, -1, false, ex.Message);
                    log.Error(ex);
                    this.ProgressConcurrentQueue.Enqueue(ex.Message);
                }
                finally
                {
                    this.sharedStepsMigrationLogManager.Save();
                    this.MigrationSharedStepsRetryJsonPath = this.sharedStepsMigrationLogManager.FullResultFilePath;
                }
            }
            this.IsSharedStepsMigrationFinished = true;
        }