public async Task ExportToIA(TEntity item, IntegrationAccountDetails iaDetails) { this.iaDetails = iaDetails; var serverPartnerItem = item as PartnerMigrationItemViewModel; var certItem = item as Certificate; string certName = string.Empty; if (serverPartnerItem != null) { certName = serverPartnerItem.MigrationEntity.CertificateName; } else if (certItem != null) { certName = certItem.certificateName; } try { TraceProvider.WriteLine("Migrating certificate : {0}", certName); await Task.Factory.StartNew(() => { try { AuthenticationResult authresult = thisApplicationContext.GetProperty("IntegrationAccountAuthorization") as AuthenticationResult; bool overwrite = Convert.ToBoolean(thisApplicationContext.GetProperty("OverwriteEnabled")); if (!overwrite) { bool exists = CheckIfCertificateExists(certName, this.iaDetails, authresult).Result; if (exists) { SetStatus(item, MigrationStatus.Partial, string.Format("The Certificate {0} already exists on IA with name {1}. Since the Overwrite option was disabled, the certificate was not overwritten.", certName, FileOperations.GetFileName(certName))); TraceProvider.WriteLine(string.Format("The Certificate {0} already exists on IA with name {1}. Since the Overwrite option was disabled, the certificate was not overwritten.", certName, FileOperations.GetFileName(certName))); TraceProvider.WriteLine(); } else { CheckIfCertificateIsprivate(item, certName, iaDetails); MigrateToCloudIA(FileOperations.GetCertificateJsonFilePath(certName), FileOperations.GetFileName(certName), item, iaDetails, authresult).Wait(); SetStatus(item, MigrationStatus.Succeeded, string.Format("Certificate {0} migrated succesfully", certName)); TraceProvider.WriteLine(string.Format("Certificate Migration Successfull: {0}", certName)); TraceProvider.WriteLine(); } } else { CheckIfCertificateIsprivate(item, certName, iaDetails); MigrateToCloudIA(FileOperations.GetCertificateJsonFilePath(certName), FileOperations.GetFileName(certName), item, iaDetails, authresult).Wait(); SetStatus(item, MigrationStatus.Succeeded, string.Format("Certificate {0} migrated succesfully", certName)); TraceProvider.WriteLine(string.Format("Certificate Migration Successfull: {0}", certName)); TraceProvider.WriteLine(); } } catch (Exception) { //throw ex; } }); } catch (Exception ex) { throw ex; } }
public void CreateCertificates(string certName, string certThumbprint) { try { X509Certificate2 partnerCert; string partnerCertBase64String; bool certFound = false; X509Certificate2Collection collection = new X509Certificate2Collection(); //BiztalkServerDetails BizTalkServerDetails = this.thisApplicationContext.GetService<BiztalkServerDetails>(); //string serverName = BizTalkServerDetails.RemoteServerName; //if (BizTalkServerDetails.UseDifferentAccount) //{ // string domain = BizTalkServerDetails.RemoteDomainName; // string username = BizTalkServerDetails.RemoteUserName; // string password = BizTalkServerDetails.RemoteUserPassword; // using (UserImpersonation user = new UserImpersonation(username, domain, password)) // { // if (user.ImpersonateValidUser()) // { //collection = GetCertificate(certThumbprint, serverName); //if (collection.Count == 0) //{ // certFound = false; //} //else //{ // certFound = true; //} //} //else //{ // throw new Exception(string.Format(@"Failed to read Certificates from the Server {0}\{1}. Invalid Credentails used to read Certificates.", domain, username)); //} // } // } //else //{ string serverName = System.Environment.MachineName; collection = GetCertificate(certThumbprint, serverName); if (collection.Count == 0) { certFound = false; } else { certFound = true; } // } if (certFound) { partnerCert = collection[0]; partnerCertBase64String = Convert.ToBase64String(partnerCert.GetRawCertData()); JsonCertificate.Rootobject certificateRootObject = new JsonCertificate.Rootobject() { name = FileOperations.GetFileName(certName), properties = new JsonCertificate.Properties() { publicCertificate = partnerCertBase64String, metadata = GenerateMetadata(certName) } }; if (partnerCert.HasPrivateKey) { //CHECK IF IT's EXPORTABLE, and ensure you write traces certificateRootObject.properties.key = new JsonCertificate.Key() { keyName = "<KeyNameHere>", keyVersion = "<KeyVersionHere>", keyVault = new JsonCertificate.KeyVault() { id = "<ResourceUriHere>" } }; //TODO: Create KeyVault Secret JSON. string keyvaultjson = this.GetKeyVaultSecretJsonForPrivateKey(partnerCert); string keyvaultfilename = FileOperations.GetKeyVaultJsonFilePath(certName + "Privatekey"); FileOperations.CreateFolder(keyvaultfilename); System.IO.File.WriteAllText(keyvaultfilename, keyvaultjson); } string fileName = FileOperations.GetCertificateJsonFilePath(certName); string partnerJsonFileContent = Newtonsoft.Json.JsonConvert.SerializeObject(certificateRootObject); FileOperations.CreateFolder(fileName); System.IO.File.WriteAllText(fileName, partnerJsonFileContent); TraceProvider.WriteLine(string.Format("Certificate {0} for partner has been succesfully exported to Json with Name {1}", certName, FileOperations.GetFileName(certName))); } else { TraceProvider.WriteLine(string.Format("Certificate Export to Json Failed. Reason : Certificate {0} Not Found in LocalCertificate store in Server {1}", certName, serverName)); throw new Exception(string.Format("Certificate {0} Not Found in LocalCertificate store in Server {1}", certName, serverName)); } } catch (Exception ex) { throw ex; } }
public override async Task ImportAsync(PartnerMigrationItemViewModel serverPartnerItem) { try { var serverPartner = serverPartnerItem.MigrationEntity; TraceProvider.WriteLine(); TraceProvider.WriteLine("Exporting Partner to Json: {0}", serverPartnerItem.MigrationEntity.Name); serverPartnerItem.ImportStatus = MigrationStatus.NotStarted; serverPartnerItem.ExportStatus = MigrationStatus.NotStarted; serverPartnerItem.ImportStatusText = null; serverPartnerItem.ExportStatusText = null; serverPartnerItem.CertificationRequired = false; serverPartnerItem.CertificateImportStatus = MigrationStatus.NotStarted; serverPartnerItem.CertificateExportStatus = MigrationStatus.NotStarted; serverPartnerItem.ExportStatusText = null; await Task.Factory.StartNew(() => { try { CreatePartners(serverPartnerItem); serverPartnerItem.ImportStatus = MigrationStatus.Succeeded; StringBuilder successMessageText = new StringBuilder(); successMessageText.Append(string.Format(Resources.ImportSuccessMessageText, serverPartnerItem.MigrationEntity.Name)); serverPartnerItem.ImportStatusText = successMessageText.ToString(); serverPartnerItem.CertificationRequired = certificateRequired; serverPartnerItem.CertificateImportStatus = succesfullCertificateImport; TraceProvider.WriteLine(string.Format("Partner {0} exported to Json with Name {1}", serverPartnerItem.MigrationEntity.Name, FileOperations.GetFileName(serverPartnerItem.MigrationEntity.Name))); TraceProvider.WriteLine(string.Format("Partner Export to Json Successfull: {0}", serverPartner.Name)); TraceProvider.WriteLine(); } catch (Exception) { //throw ex; } }); } catch (Exception ex) { throw ex; } }
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 }
public override async Task ExportToIA(PartnerMigrationItemViewModel serverPartnerItem, IntegrationAccountDetails iaDetails) { this.iaDetails = iaDetails; try { TraceProvider.WriteLine("Migrating partner : {0}", serverPartnerItem.MigrationEntity.Name); await Task.Factory.StartNew(() => { try { AuthenticationResult authresult = thisApplicationContext.GetProperty("IntegrationAccountAuthorization") as AuthenticationResult; bool overwrite = Convert.ToBoolean(thisApplicationContext.GetProperty("OverwriteEnabled")); if (!overwrite) { bool exists = CheckIfArtifactExists(serverPartnerItem.MigrationEntity.Name, "Partner", this.iaDetails, authresult).Result; if (exists) { serverPartnerItem.ExportStatus = MigrationStatus.Partial; serverPartnerItem.ExportStatusText = string.Format("The Partner {0} already exists on IA with name {1}. Since the Overwrite option was disabled, the partner was not overwritten.", serverPartnerItem.MigrationEntity.Name, FileOperations.GetFileName(serverPartnerItem.MigrationEntity.Name)); TraceProvider.WriteLine(serverPartnerItem.ExportStatusText); TraceProvider.WriteLine(); } else { MigrateToCloudIAPartner(FileOperations.GetPartnerJsonFilePath(serverPartnerItem.MigrationEntity.Name), FileOperations.GetFileName(serverPartnerItem.MigrationEntity.Name), serverPartnerItem, iaDetails, authresult).Wait(); serverPartnerItem.ExportStatus = MigrationStatus.Succeeded; StringBuilder successMessageText = new StringBuilder(); successMessageText.Append(string.Format(Resources.ExportSuccessMessageText, serverPartnerItem.MigrationEntity.Name)); serverPartnerItem.ExportStatusText = successMessageText.ToString(); TraceProvider.WriteLine(string.Format("Partner Migration Successfull: {0}", serverPartnerItem.MigrationEntity.Name)); TraceProvider.WriteLine(); } } else { MigrateToCloudIAPartner(FileOperations.GetPartnerJsonFilePath(serverPartnerItem.MigrationEntity.Name), FileOperations.GetFileName(serverPartnerItem.MigrationEntity.Name), serverPartnerItem, iaDetails, authresult).Wait(); serverPartnerItem.ExportStatus = MigrationStatus.Succeeded; StringBuilder successMessageText = new StringBuilder(); successMessageText.Append(string.Format(Resources.ExportSuccessMessageText, serverPartnerItem.MigrationEntity.Name)); serverPartnerItem.ExportStatusText = successMessageText.ToString(); TraceProvider.WriteLine(string.Format("Partner Migration Successfull: {0}", serverPartnerItem.MigrationEntity.Name)); TraceProvider.WriteLine(); } } catch (Exception) { //throw ex; } }); } catch (Exception) { //throw ex; } }
public static string GetMapUrl(string mapname, IntegrationAccountDetails iaDetails) { string url = String.Format(ConfigurationManager.AppSettings["MapUrl"], iaDetails.SubscriptionId, iaDetails.ResourceGroupName, iaDetails.IntegrationAccountName, FileOperations.GetFileName(mapname)); return(url); }
public override async Task ImportAsync(SchemaMigrationItemViewModel serverSchemaItem) { try { var serverSchema = serverSchemaItem.MigrationEntity; TraceProvider.WriteLine(); TraceProvider.WriteLine("Exporting Schema to Json: {0}", serverSchemaItem.MigrationEntity.fullNameOfSchemaToUpload); serverSchemaItem.ImportStatus = MigrationStatus.NotStarted; serverSchemaItem.ExportStatus = MigrationStatus.NotStarted; serverSchemaItem.ImportStatusText = null; serverSchemaItem.ExportStatusText = null; await Task.Factory.StartNew(() => { try { CreateSchemas(serverSchemaItem); serverSchemaItem.ImportStatus = MigrationStatus.Succeeded; StringBuilder successMessageText = new StringBuilder(); successMessageText.Append(string.Format(Resources.ImportSuccessMessageText, serverSchemaItem.MigrationEntity.fullNameOfSchemaToUpload)); serverSchemaItem.ImportStatusText = successMessageText.ToString(); TraceProvider.WriteLine(string.Format("Schema {0} exported to Json with Name {1}", serverSchemaItem.MigrationEntity.fullNameOfSchemaToUpload, FileOperations.GetFileName(serverSchemaItem.MigrationEntity.fullNameOfSchemaToUpload))); TraceProvider.WriteLine(string.Format("Schema Export to Json Successfull: {0}", serverSchemaItem.Name)); TraceProvider.WriteLine(); } catch (Exception) { //throw ex; } }); } catch (Exception ex) { throw ex; } }
public override async Task ExportToIA(SchemaMigrationItemViewModel serverSchemaItem, IntegrationAccountDetails iaDetails) { this.iaDetails = iaDetails; try { TraceProvider.WriteLine("Migrating schema : {0}", serverSchemaItem.MigrationEntity.fullNameOfSchemaToUpload); await Task.Factory.StartNew(() => { try { AuthenticationResult authresult = thisApplicationContext.GetProperty("IntegrationAccountAuthorization") as AuthenticationResult; bool overwrite = Convert.ToBoolean(thisApplicationContext.GetProperty("OverwriteEnabled")); if (!overwrite) { bool exists = CheckIfArtifactExists(serverSchemaItem.MigrationEntity.fullNameOfSchemaToUpload, "Schema", this.iaDetails, authresult).Result; if (exists) { serverSchemaItem.ExportStatus = MigrationStatus.Partial; serverSchemaItem.ExportStatusText = string.Format("The Schema {0} already exists on IA with name {1}. Since the Overwrite option was disabled, the certificate was not overwritten.", serverSchemaItem.MigrationEntity.fullNameOfSchemaToUpload, FileOperations.GetFileName(serverSchemaItem.MigrationEntity.fullNameOfSchemaToUpload)); TraceProvider.WriteLine(serverSchemaItem.ExportStatusText); TraceProvider.WriteLine(); } else { MigrateToCloudIA(FileOperations.GetSchemaJsonFilePath(serverSchemaItem.MigrationEntity.fullNameOfSchemaToUpload), FileOperations.GetFileName(serverSchemaItem.MigrationEntity.fullNameOfSchemaToUpload), serverSchemaItem, iaDetails, authresult).Wait(); serverSchemaItem.ExportStatus = MigrationStatus.Succeeded; serverSchemaItem.ExportStatusText = string.Format("Schema {0} migrated succesfully", serverSchemaItem.MigrationEntity.fullNameOfSchemaToUpload); TraceProvider.WriteLine(string.Format("Schema Migration Successfull: {0}", serverSchemaItem.MigrationEntity.fullNameOfSchemaToUpload)); TraceProvider.WriteLine(); } } else { MigrateToCloudIA(FileOperations.GetSchemaJsonFilePath(serverSchemaItem.MigrationEntity.fullNameOfSchemaToUpload), FileOperations.GetFileName(serverSchemaItem.MigrationEntity.fullNameOfSchemaToUpload), serverSchemaItem, iaDetails, authresult).Wait(); serverSchemaItem.ExportStatus = MigrationStatus.Succeeded; serverSchemaItem.ExportStatusText = string.Format("Schema {0} migrated succesfully", serverSchemaItem.MigrationEntity.fullNameOfSchemaToUpload); TraceProvider.WriteLine(string.Format("Schema Migration Successfull: {0}", serverSchemaItem.MigrationEntity.fullNameOfSchemaToUpload)); TraceProvider.WriteLine(); } } catch (Exception) { //throw ex; } }); } catch (Exception ex) { throw ex; } }
public void CreatePartnerFiles(string partnerName, AgreementMigrationItemViewModel agreementItem) { string directroyPathForJsonFiles = Resources.MetaDataContextPath; string fileName = string.Format(directroyPathForJsonFiles, partnerName); if (!Directory.Exists(fileName)) { FileOperations.CreateFolder(fileName); } else { Directory.Delete(fileName, true); FileOperations.CreateFolder(fileName); } // Inbound Partner Details string newGuid = CreateNewGuid(); PartnerContext partnrCtxt = new PartnerContext(); partnrCtxt.id = newGuid; inboundPartnerDetails = newGuid; partnrCtxt.recordType = AppConstants.partnerDetails; partnrCtxt.description = "EDI AS2 Partner Details For " + partnerName; partnrCtxt.docKey = new Dockey() { messageFormat = agreementItem.MigrationEntity.Protocol.ToUpper(), senderQualifier = agreementItem.GuestPartnerQualifer, senderIdentifier = agreementItem.GuestPartnerId, receiverQualifier = agreementItem.HostPartnerQualifier, receiverIdentifier = agreementItem.HostPartnerId }; partnrCtxt.as2Config = new As2config() { as2From = "NA", as2To = "NA" }; partnrCtxt.preserveInterchange = new Preserveinterchange() { IB = true, PT = true }; partnrCtxt.preDecodeProcessing = new JArray(); partnrCtxt.postDecodeProcessing = new JArray(); partnrCtxt.preEncodeProcessing = new PreEncodeprocessing[0]; partnrCtxt.postEncodeProcessing = new PostEncodeprocessing[0]; partnrCtxt.epDetailId = CreateNewGuid(); fileName = fileName + partnerName + "_InboundPartnerDetails.json"; if (!File.Exists(fileName)) { File.Create(fileName).Close(); System.IO.File.WriteAllText(fileName, JObject.Parse(JsonConvert.SerializeObject(partnrCtxt)).ToString()); } // Outbound Partner Details newGuid = CreateNewGuid(); PartnerContext obpartnrCtxt = new PartnerContext(); obpartnrCtxt.id = newGuid; outboundPartnerDetails = newGuid; obpartnrCtxt.recordType = AppConstants.partnerDetails; obpartnrCtxt.description = "EDI AS2 Partner Details For " + partnerName; obpartnrCtxt.docKey = new Dockey() { messageFormat = agreementItem.MigrationEntity.Protocol.ToUpper(), senderQualifier = agreementItem.HostPartnerQualifier, senderIdentifier = agreementItem.HostPartnerId, receiverQualifier = agreementItem.GuestPartnerQualifer, receiverIdentifier = agreementItem.GuestPartnerId }; obpartnrCtxt.as2Config = new As2config() { as2From = "NA", as2To = "NA" }; obpartnrCtxt.preDecodeProcessing = new JArray(); obpartnrCtxt.postDecodeProcessing = new JArray(); obpartnrCtxt.preEncodeProcessing = new PreEncodeprocessing[0]; obpartnrCtxt.postEncodeProcessing = new PostEncodeprocessing[0]; obpartnrCtxt.epDetailId = CreateNewGuid(); fileName = string.Empty; fileName = string.Format(directroyPathForJsonFiles, partnerName); fileName = fileName + partnerName + "_OutboundPartnerDetails.json"; if (!File.Exists(fileName)) { File.Create(fileName).Close(); System.IO.File.WriteAllText(fileName, JObject.Parse(JsonConvert.SerializeObject(obpartnrCtxt)).ToString()); } }