Пример #1
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();
                }
            }
        }
        public override void Initialize(IApplicationContext applicationContext)
        {
            base.Initialize(applicationContext);

            this.Migrator = TpmMigrator <TItemViewModel, TEntity> .CreateMigrator(applicationContext);

            var cachedItems =
                this.ApplicationContext.GetProperty(this.MigrationItemsContextPropertyName) as ObservableCollection <TItemViewModel>;

            if (this.ApplicationContext.LastNavigation != NavigateAction.Next && cachedItems != null)
            {
                this.MigrationItems = cachedItems;
            }
            else
            {
                var selectionItems = this.ApplicationContext.GetProperty(this.SelectionItemsContextPropertyName) as IEnumerable <SelectionItemViewModel <TEntity> >;
                IEnumerable <SelectionItemViewModel <TEntity> > selectedItems = null;
                if (selectionItems != null && selectionItems.Count() != 0)
                {
                    selectedItems = selectionItems.Where(item => item.IsSelected);
                    if ((selectedItems == null || !selectedItems.Any()))
                    {
                        var lastNavigation = this.ApplicationContext.LastNavigation;
                        if (lastNavigation == NavigateAction.Next)
                        {
                            var item1 = this as SchemaMigrationPageViewModel;
                            var item2 = this as MapMigrationPageViewModel;
                            if (item1 == null && item2 == null)
                            {
                                MessageBox.Show("Nothing selected. Please select to proceed. ");
                                if (applicationContext.GetProperty("MigrationCriteria").ToString() == "Partner")
                                {
                                    this.ApplicationContext.GetService <WizardNavigationViewModel>().MoveToPreviousStep();
                                }
                                else
                                {
                                    this.ApplicationContext.GetService <ApplicationWizardNavigationViewModel>().MoveToPreviousStep();
                                }
                            }
                            else
                            {
                                this.MigrationItems = new ObservableCollection <TItemViewModel>();
                                this.ApplicationContext.SetProperty(this.MigrationItemsContextPropertyName, this.MigrationItems);
                                if (applicationContext.GetProperty("MigrationCriteria").ToString() == "Partner")
                                {
                                    this.ApplicationContext.GetService <WizardNavigationViewModel>().MoveToNextStep();
                                }
                                else
                                {
                                    this.ApplicationContext.GetService <ApplicationWizardNavigationViewModel>().MoveToNextStep();
                                }
                            }
                        }
                        else if (lastNavigation == NavigateAction.Previous)
                        {
                            this.ApplicationContext.GetService <WizardNavigationViewModel>().MoveToPreviousStep();
                        }
                    }
                    else
                    {
                        try
                        {
                            this.MigrationItems = new ObservableCollection <TItemViewModel>(selectedItems.Select(selectedItem =>
                                                                                                                 Activator.CreateInstance(typeof(TItemViewModel), selectedItem) as TItemViewModel));

                            var agmtItem = this as AgreementMigrationPageViewModel;
                            if (agmtItem != null)
                            {
                                bool consolidateAgreements = Convert.ToBoolean(this.ApplicationContext.GetProperty(AppConstants.ConsolidationEnabled));
                                if (consolidateAgreements)
                                {
                                    AgreementMigrator agmtMigrator = new AgreementMigrator(this.ApplicationContext);
                                    var listConsolidatedAgreements = agmtMigrator.CheckAgreementsToBeConsolidated(this.MigrationItems.ToList() as List <AgreementMigrationItemViewModel>);
                                    var listFinalAgreements        = agmtMigrator.GetAgreementsList(this.MigrationItems.ToList() as List <AgreementMigrationItemViewModel>, listConsolidatedAgreements);
                                    this.MigrationItems = new ObservableCollection <TItemViewModel>(listFinalAgreements as List <TItemViewModel>);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            var statusBarViewModel = this.ApplicationContext.GetService <StatusBarViewModel>();
                            statusBarViewModel.ShowError("Error while trying to identify agreements to consolidate. Reason : " + ExceptionHelper.GetExceptionMessage(ex));
                        }
                        this.ApplicationContext.SetProperty(this.MigrationItemsContextPropertyName, this.MigrationItems);
                        this.MigrateItems();
                    }
                }
                else
                {
                    var lastNavigation = this.ApplicationContext.LastNavigation;
                    if (lastNavigation == NavigateAction.Next)
                    {
                        var item = this as SchemaMigrationPageViewModel;
                        if (item == null)
                        {
                            MessageBox.Show("Nothing to Import.");
                            this.ApplicationContext.GetService <WizardNavigationViewModel>().MoveToPreviousStep();
                        }
                        else
                        {
                            this.MigrationItems = new ObservableCollection <TItemViewModel>();
                            this.ApplicationContext.SetProperty(this.MigrationItemsContextPropertyName, this.MigrationItems);
                            this.ApplicationContext.GetService <WizardNavigationViewModel>().MoveToNextStep();
                        }
                    }
                    else if (lastNavigation == NavigateAction.Previous)
                    {
                        this.ApplicationContext.GetService <WizardNavigationViewModel>().MoveToPreviousStep();
                    }
                }
            }
        }
Пример #3
0
        private async Task ExportAgreements()
        {
            try
            {
                AuthenticationResult        authresult  = this.ApplicationContext.GetProperty("IntegrationAccountAuthorization") as AuthenticationResult;
                Dictionary <string, string> schemasInIA = await AgreementMigrator.GetAllSchemasInIA(this.ApplicationContext.GetService <IntegrationAccountDetails>(), authresult);

                Dictionary <KeyValuePair <string, string>, string> partnerIdentitiesInIA = await AgreementMigrator.GetAllPartnerIdentitiesInIA(this.ApplicationContext.GetService <IntegrationAccountDetails>(), authresult);

                this.ApplicationContext.SetProperty("SchemasInIntegrationAccount", schemasInIA);
                this.ApplicationContext.SetProperty("PartnerIdentitiesInIntegrationAccount", partnerIdentitiesInIA);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Following error occured : " + ExceptionHelper.GetExceptionMessage(ex));
                TraceProvider.WriteLine("Following error occured : " + ExceptionHelper.GetExceptionMessage(ex));
            }
            try
            {
                if (importedAgreements != null)
                {
                    foreach (var agreement in importedAgreements)
                    {
                        try
                        {
                            await aMigrator.ExportToIA(agreement, this.ApplicationContext.GetService <IntegrationAccountDetails>());
                        }
                        catch (Exception ex)
                        {
                            agreement.ExportStatus     = MigrationStatus.Failed;
                            agreement.ExportStatusText = ex.Message;
                            TraceProvider.WriteLine(string.Format("An exception occured:{0}", ex.Message));
                            TraceProvider.WriteLine();
                        }
                        finally
                        {
                            ExportedItems.Where(item => item.ArtifactName == agreement.Name).First().ExportStatus     = agreement.ExportStatus;
                            ExportedItems.Where(item => item.ArtifactName == agreement.Name).First().ExportStatusText = agreement.ExportStatusText;
                            countArtifactsMigrated++;
                            UpdateProgress();
                        }
                    }

                    foreach (var item in importedAgreements)
                    {
                        if (item.ExportStatus == MigrationStatus.Failed)
                        {
                            StatusBarViewModel.StatusInfoType = StatusInfoType.Error;
                            StatusBarViewModel.ShowError("Error(s) were encountered. Please refer the Status Tool Tip / Log File for more details.");
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                StatusBarViewModel.StatusInfoType = StatusInfoType.Error;
                StatusBarViewModel.ShowError("Error was encountered. Reason: " + ex.Message);
                TraceProvider.WriteLine("Error was encountered. Reason: " + ex.InnerException.StackTrace);
            }
        }