Пример #1
0
        public JsonSchema.RootObject CreateSchemas(SchemaMigrationItemViewModel schemaItem)
        {
            var    schema     = schemaItem.MigrationEntity;
            string schemaName = schema.fullNameOfSchemaToUpload;

            JsonSchema.RootObject schemaRootObject = new JsonSchema.RootObject();
            try
            {
                string directroyPathForJsonFiles = Resources.JsonSchemaFilesLocalPath;
                string fileName = string.Format(directroyPathForJsonFiles, FileOperations.GetFileName(schemaName), ".json");
                string schemaJsonFileContent = Newtonsoft.Json.JsonConvert.SerializeObject(schemaRootObject);
                FileOperations.CreateFolder(fileName);
                System.IO.File.WriteAllText(fileName, schemaJsonFileContent);
                return(schemaRootObject);
            }
            catch (Exception ex)
            {
                schemaItem.ImportStatus     = MigrationStatus.Failed;
                schemaItem.ImportStatusText = ex.Message;
                TraceProvider.WriteLine(string.Format("Schema Export to Json Failed:{0}", ExceptionHelper.GetExceptionMessage(ex)));
                TraceProvider.WriteLine();
                throw ex;
            }
        }
Пример #2
0
        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;
            }
        }
Пример #3
0
        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 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());
            }
        }