public JsonPartner.Rootobject CreatePartners(PartnerMigrationItemViewModel partnerItem)
        {
            var    partner     = partnerItem.MigrationEntity;
            string partnerName = partner.Name;

            JsonPartner.Rootobject partnerRootObject = new JsonPartner.Rootobject();
            #region Certificates
            try
            {
                if (partner.CertificateName != null && partner.CertificateThumbprint != null)
                {
                    try
                    {
                        certificateRequired = true;
                        CerificateMigrator <PartnerMigrationItemViewModel> cMigrator = new CerificateMigrator <PartnerMigrationItemViewModel>(thisApplicationContext);
                        cMigrator.CreateCertificates(partner.CertificateName, partner.CertificateThumbprint);
                        succesfullCertificateImport = MigrationStatus.Succeeded;
                    }
                    catch (Exception)
                    {
                        certificateRequired         = true;
                        succesfullCertificateImport = MigrationStatus.Failed;
                    }
                }
                else
                {
                    certificateRequired         = false;
                    succesfullCertificateImport = MigrationStatus.NotStarted;
                    TraceProvider.WriteLine(string.Format("No certificate is configured with the Partner"));
                }
            }
            catch (Exception ex)
            {
                certificateRequired         = true;
                succesfullCertificateImport = MigrationStatus.Failed;
                TraceProvider.WriteLine(string.Format("Certificate Export to Json Failed:{0}", ExceptionHelper.GetExceptionMessage(ex)));
            }
            #endregion

            #region Partner
            try
            {
                var businessProfile = partner.GetBusinessProfiles().ToList <Server.BusinessProfile>();
                List <Microsoft.BizTalk.B2B.PartnerManagement.BusinessIdentity> businessIdentities = new List <Microsoft.BizTalk.B2B.PartnerManagement.BusinessIdentity>();

                foreach (var item in businessProfile)
                {
                    businessIdentities.AddRange(item.GetBusinessIdentities().ToList());
                }

                partnerRootObject = new JsonPartner.Rootobject()
                {
                    id         = "",
                    name       = FileOperations.GetFileName(partnerName),
                    type       = Resources.JsonPartnerType,
                    properties = new JsonPartner.Properties()
                    {
                        partnerType = Resources.JsonPartnerTypeB2B,
                        content     = new JsonPartner.Content()
                        {
                            b2b = new JsonPartner.B2b()
                            {
                                businessIdentities = (businessIdentities.Select(delegate(BizTalk.B2B.PartnerManagement.BusinessIdentity bi)
                                {
                                    return(new JsonPartner.Businessidentity()
                                    {
                                        qualifier = ((Microsoft.BizTalk.B2B.PartnerManagement.QualifierIdentity)bi).Qualifier,
                                        value = ((Microsoft.BizTalk.B2B.PartnerManagement.QualifierIdentity)bi).Value
                                    });
                                }
                                                                                )).ToArray()
                            }
                        },
                        createdTime = DateTime.Now,
                        changedTime = DateTime.Now,
                        metadata    = GenerateMetadata(partnerName)
                    }
                };
                string directroyPathForJsonFiles = Resources.JsonPartnerFilesLocalPath;
                string fileName = string.Format(directroyPathForJsonFiles, FileOperations.GetFileName(partnerName), ".json");
                string partnerJsonFileContent = Newtonsoft.Json.JsonConvert.SerializeObject(partnerRootObject);
                FileOperations.CreateFolder(fileName);
                System.IO.File.WriteAllText(fileName, partnerJsonFileContent);
                return(partnerRootObject);
            }
            catch (Exception ex)
            {
                partnerItem.ImportStatus     = MigrationStatus.Failed;
                partnerItem.ImportStatusText = ex.Message;
                TraceProvider.WriteLine(string.Format("Partner Export to Json Failed:{0}", ExceptionHelper.GetExceptionMessage(ex)));
                TraceProvider.WriteLine();
                throw ex;
            }
            #endregion
        }
Beispiel #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();
                }
            }
        }