public async void MigrateItems()
        {
            var statusBarViewModel = this.ApplicationContext.GetService <StatusBarViewModel>();

            string progressBarText = string.Empty;
            var    partnerType     = this as PartnerMigrationPageViewModel;
            var    agreementType   = this as AgreementMigrationPageViewModel;
            var    schemaType      = this as SchemaMigrationPageViewModel;
            var    mapType         = this as MapMigrationPageViewModel;

            if (partnerType != null)
            {
                progressBarText = Resources.ImportingPartnersProgressBarText;
                this.ProgressBarViewModel.Update(true, progressBarText);
            }

            if (agreementType != null)
            {
                progressBarText = Resources.ImportingAgreementsProgressBarText;
                this.ProgressBarViewModel.Update(true, progressBarText);
            }

            if (schemaType != null)
            {
                progressBarText = Resources.ImportingSchemasProgressBarText;
                this.ProgressBarViewModel.Update(true, progressBarText);
            }

            if (mapType != null)
            {
                progressBarText = Resources.ImportingMapsProgressBarText;
                this.ProgressBarViewModel.Update(true, progressBarText);
            }

            if (schemaType != null)
            {
                try
                {
                    SchemaMigrator sMigrator = new SchemaMigrator(this.ApplicationContext);
                    await sMigrator.CreateSchemas(this.MigrationItems.ToList() as List <SchemaMigrationItemViewModel>);
                }
                catch (Exception ex)
                {
                    statusBarViewModel.ShowError("(Error) :" + ExceptionHelper.GetExceptionMessage(ex));
                }
            }
            else if (mapType != null)
            {
                try
                {
                    MapMigrator sMigrator = new MapMigrator(this.ApplicationContext);
                    await sMigrator.CreateSchemas(this.MigrationItems.ToList() as List <MapMigrationItemViewModel>);
                }
                catch (Exception ex)
                {
                    statusBarViewModel.ShowError("(Error) :" + ExceptionHelper.GetExceptionMessage(ex));
                }
            }
            else
            {
                foreach (var migrationItem in this.MigrationItems)
                {
                    try
                    {
                        await Migrator.ImportAsync(migrationItem);

                        if (migrationItem.ImportStatus == MigrationStatus.Partial)
                        {
                            migrationItem.ImportStatusText = Resources.MigrationPartialMessageText;
                        }
                    }
                    catch (Exception ex)
                    {
                        migrationItem.ImportStatus     = MigrationStatus.Failed;
                        migrationItem.ImportStatusText = ExceptionHelper.GetExceptionMessage(ex);
                        this.Migrator.RefreshContext();
                    }
                }
            }
            foreach (var item in this.MigrationItems)
            {
                if (item.ImportStatus == MigrationStatus.Failed)
                {
                    statusBarViewModel.StatusInfoType = StatusInfoType.Error;
                    statusBarViewModel.ShowError("Error(s) were encountered. Please refer the Status Tool Tip / Log File for more details.");
                    break;
                }
            }
            this.ProgressBarViewModel.Update(false);
        }
Exemplo n.º 2
0
        public override void Initialize(IApplicationContext applicationContext)
        {
            base.Initialize(applicationContext);
            pMigrator  = new PartnerMigrator(this.ApplicationContext);
            aMigrator  = new AgreementMigrator(this.ApplicationContext);
            sMigrator  = new SchemaMigrator(this.ApplicationContext);
            mMigrator  = new MapMigrator(this.ApplicationContext);
            c1Migrator = new CerificateMigrator <PartnerMigrationItemViewModel>(this.ApplicationContext);
            c2Migrator = new CerificateMigrator <Certificate>(this.ApplicationContext);

            ExportedItems = new ObservableCollection <ExportedArtifact>();

            selectedSchemas = this.ApplicationContext.GetProperty(AppConstants.SelectedSchemasContextPropertyName) as IEnumerable <SchemaMigrationItemViewModel>;
            importedSchemas = selectedSchemas.Where(item => item.ImportStatus == MigrationStatus.Succeeded);

            selectedMaps = this.ApplicationContext.GetProperty(AppConstants.SelectedMapsContextPropertyName) as IEnumerable <MapMigrationItemViewModel>;
            importedMaps = selectedMaps.Where(item => item.ImportStatus == MigrationStatus.Succeeded);

            selectedPartners = this.ApplicationContext.GetProperty(AppConstants.SelectedPartnersContextPropertyName) as IEnumerable <PartnerMigrationItemViewModel>;
            if (applicationContext.GetProperty("MigrationCriteria").ToString() == "Partner")
            {
                importedPartners = selectedPartners.Where(item => item.ImportStatus == MigrationStatus.Succeeded);
            }
            if (applicationContext.GetProperty("MigrationCriteria").ToString() == "Partner")
            {
                importedPartnersWithCertificates = selectedPartners.Where(item => item.CertificationRequired == true && item.CertificateImportStatus == MigrationStatus.Succeeded);
            }

            selectedAgreements = this.ApplicationContext.GetProperty(AppConstants.SelectedAgreementsContextPropertyName) as IEnumerable <AgreementMigrationItemViewModel>;
            if (applicationContext.GetProperty("MigrationCriteria").ToString() == "Partner")
            {
                importedAgreements = selectedAgreements.Where(item => item.ImportStatus == MigrationStatus.Succeeded);
            }

            otherCerts = this.ApplicationContext.GetProperty("OtherCertificates") as List <Certificate>;

            ExportSchemasFlag      = Convert.ToBoolean(this.ApplicationContext.GetProperty("ExportSchemas"));
            ExportMapsFlag         = Convert.ToBoolean(this.ApplicationContext.GetProperty("ExportMaps"));
            ExportCertificatesFlag = Convert.ToBoolean(this.ApplicationContext.GetProperty("ExportCertificates"));
            ExportPartnersFlag     = Convert.ToBoolean(this.ApplicationContext.GetProperty("ExportPartners"));
            ExportAgreementsFlag   = Convert.ToBoolean(this.ApplicationContext.GetProperty("ExportAgreements"));

            bool consolidateAgreements   = Convert.ToBoolean(this.ApplicationContext.GetProperty(AppConstants.ConsolidationEnabled));
            bool generateMetadataContext = Convert.ToBoolean(this.ApplicationContext.GetProperty(AppConstants.ContextGenerationEnabled));

            if (ExportSchemasFlag || ExportCertificatesFlag || ExportPartnersFlag || ExportAgreementsFlag || ExportMapsFlag)
            {
                if (ExportSchemasFlag)
                {
                    foreach (var item in importedSchemas)
                    {
                        ExportedItems.Add(new ExportedArtifact
                        {
                            ArtifactName     = item.MigrationEntity.fullNameOfSchemaToUpload,
                            ArtifactType     = ArtifactTypes.Schema,
                            ExportStatus     = MigrationStatus.NotStarted,
                            ExportStatusText = null
                        });
                    }
                }
                if (ExportMapsFlag)
                {
                    foreach (var item in importedMaps)
                    {
                        ExportedItems.Add(new ExportedArtifact
                        {
                            ArtifactName     = item.MigrationEntity.fullNameOfMapToUpload,
                            ArtifactType     = ArtifactTypes.Map,
                            ExportStatus     = MigrationStatus.NotStarted,
                            ExportStatusText = null
                        });
                    }
                }
                if (ExportCertificatesFlag)
                {
                    foreach (var item in importedPartnersWithCertificates)
                    {
                        ExportedItems.Add(new ExportedArtifact
                        {
                            ArtifactName     = item.MigrationEntity.CertificateName,
                            ArtifactType     = ArtifactTypes.Certificate,
                            ExportStatus     = MigrationStatus.NotStarted,
                            ExportStatusText = null
                        });
                    }
                    if (otherCerts != null)
                    {
                        otherExtractedCerts = otherCerts.Where(item => item.ImportStatus == MigrationStatus.Succeeded);
                        foreach (var item in otherExtractedCerts)
                        {
                            ExportedItems.Add(new ExportedArtifact
                            {
                                ArtifactName     = item.certificateName,
                                ArtifactType     = ArtifactTypes.Certificate,
                                ExportStatus     = MigrationStatus.NotStarted,
                                ExportStatusText = null
                            });
                        }
                    }
                }
                if (ExportPartnersFlag)
                {
                    foreach (var item in importedPartners)
                    {
                        ExportedItems.Add(new ExportedArtifact
                        {
                            ArtifactName     = item.MigrationEntity.Name,
                            ArtifactType     = ArtifactTypes.Partner,
                            ExportStatus     = MigrationStatus.NotStarted,
                            ExportStatusText = null
                        });
                    }
                }

                if (ExportAgreementsFlag)
                {
                    if (consolidateAgreements)
                    {
                        AuthenticationResult authresult = this.ApplicationContext.GetProperty("IntegrationAccountAuthorization") as AuthenticationResult;
                        List <X12AgreementJson.Rootobject> x12AgreementsInIA = AgreementMigrator.GetAllX12AgreementsInIA(this.ApplicationContext.GetService <IntegrationAccountDetails>(), authresult).Result;
                        this.ApplicationContext.SetProperty("X12AgreementsInIntegrationAccount", x12AgreementsInIA);

                        List <EDIFACTAgreementJson.Rootobject> edifactAgreementsInIA = AgreementMigrator.GetAllEdifactAgreementsInIA(this.ApplicationContext.GetService <IntegrationAccountDetails>(), authresult).Result;
                        this.ApplicationContext.SetProperty("EdifactAgreementsInIntegrationAccount", edifactAgreementsInIA);
                    }
                    foreach (var item in importedAgreements)
                    {
                        if (consolidateAgreements)
                        {
                            TraceProvider.WriteLine(string.Format("Checking {0} for Agreement consolidation..", item.Name));
                            AgreementMigrator agmtMigrator = new AgreementMigrator(this.ApplicationContext);
                            try
                            {
                                agmtMigrator.CheckIfAgreementHasToBeConsolidated(item);
                            }
                            catch (Exception ex)
                            {
                                StatusBarViewModel.StatusInfoType = StatusInfoType.Error;
                                StatusBarViewModel.ShowError(string.Format("Error was encountered during the check for consolidating agreement {0} with IA agreements. Reason: {1}. The agreement will be migrated as such", item.Name, ExceptionHelper.GetExceptionMessage(ex)));
                                TraceProvider.WriteLine(string.Format("Error was encountered during the check for consolidating agreement {0} with IA agreements. Reason: {1}. The agreement will be migrated as such", item.Name, ExceptionHelper.GetExceptionMessage(ex)));
                                TraceProvider.WriteLine();
                            }
                        }
                        ExportedItems.Add(new ExportedArtifact
                        {
                            ArtifactName     = item.Name,
                            ArtifactType     = ArtifactTypes.Agreement,
                            ExportStatus     = MigrationStatus.NotStarted,
                            ExportStatusText = null
                        });
                    }
                }
                countArtifactsMigrated       = 0;
                countTotalArtifactsToMigrate = ExportedItems.Count();
                TotalArtifacts  = countTotalArtifactsToMigrate;
                ProgressVisible = false;
                UpdateProgress();
                ExportArtifacts();
            }
            else
            {
                var lastNavigation = this.ApplicationContext.LastNavigation;
                if (lastNavigation == NavigateAction.Next)
                {
                    this.ApplicationContext.GetService <WizardNavigationViewModel>().MoveToNextStep();
                }
                else if (lastNavigation == NavigateAction.Previous)
                {
                    this.ApplicationContext.GetService <WizardNavigationViewModel>().MoveToPreviousStep();
                }
            }
        }