private void Remove() { // resources with dependencies must be removed first this.SortResources(); foreach (BizTalkResource r in this.resources) { using (Deployment.Group btsGroup = new Deployment.Group()) { try { btsGroup.DBName = this.Database; btsGroup.DBServer = this.DatabaseServer; Deployment.Application btsApplication = btsGroup.Applications[this.Application]; btsApplication.Log += this.DeploymentLog; btsApplication.UILevel = 2; btsApplication.RemoveResource(string.Empty, r.FullName); } catch { btsGroup.Abort(); throw; } } } }
private void CheckExists() { using (Deployment.Group btsGroup = new Deployment.Group()) { try { btsGroup.DBName = this.Database; btsGroup.DBServer = this.DatabaseServer; Deployment.Application btsApplication = btsGroup.Applications[this.Application]; btsApplication.Log += this.DeploymentLog; btsApplication.UILevel = 2; if (this.Resources.Any(talkResource => !btsApplication.ResourceCollection.ToList().Exists(r => r.Luid == talkResource.FullName))) { this.Exists = false; return; } this.Exists = true; } catch { btsGroup.Abort(); throw; } } }
private void Add() { using (Deployment.Group btsGroup = new Deployment.Group()) { try { btsGroup.DBName = this.Database; btsGroup.DBServer = this.DatabaseServer; Deployment.Application btsApplication = btsGroup.Applications[this.Application]; btsApplication.Log += this.DeploymentLog; btsApplication.UILevel = 1; this.SortResources(); if (this.Gac) { // gac asssemblies this.Resources.ForEach(r => this.AddAssembly(r)); } this.Resources.ForEach(r => btsApplication.AddResource(r.ResourceType, r.FullName, r.Properties, this.Force)); } catch { btsGroup.Abort(); throw; } } }
private void ExportToMsi() { if (string.IsNullOrEmpty(this.Application)) { this.Log.LogError("Application is required"); return; } if (this.MsiPath == null) { this.Log.LogError("Destination is required"); return; } if (this.Resources == null) { this.Resources = new ITaskItem[] { }; } if (!this.CheckExists(this.Application)) { this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "Application does not exist: {0}", this.Application)); return; } this.LogTaskMessage(string.Format(CultureInfo.InvariantCulture, "Exporting Application {0} to {1}", this.Application, this.MsiPath)); using (Group group = new Group()) { group.DBName = this.Database; group.DBServer = this.DatabaseServer; Microsoft.BizTalk.ApplicationDeployment.ApplicationCollection apps = group.Applications; apps.UiLevel = 2; Microsoft.BizTalk.ApplicationDeployment.Application appl = apps[this.Application]; List <Resource> exportedResources = new List <Resource>(); foreach (Resource resource in appl.ResourceCollection.Cast <Resource>().Where(resource => !resource.Properties.ContainsKey("IsSystem") || !((bool)resource.Properties["IsSystem"]))) { if (this.IncludeGlobalPartyBinding && resource.Luid.Equals("Application/" + this.Application, StringComparison.OrdinalIgnoreCase)) { resource.Properties["IncludeGlobalPartyBinding"] = this.IncludeGlobalPartyBinding; } // only export specified resources if (this.Resources.Length != 0 && !this.Resources.Any(item => item.ItemSpec == resource.Luid)) { continue; } this.LogTaskMessage(string.Format(CultureInfo.InvariantCulture, "Exporting Resource {0}", resource.Luid)); exportedResources.Add(resource); } appl.Export(this.MsiPath.ItemSpec, exportedResources); } }
private void ImportFromMsi() { if (this.MsiPath == null) { // -Package Required. The path and file name of the Windows Installer package. this.Log.LogError("MSI source is required"); return; } this.LogTaskMessage(string.Format(CultureInfo.InvariantCulture, "Importing from {0}", this.MsiPath.ItemSpec)); if (string.IsNullOrEmpty(this.Application)) { // -ApplicationName Optional. The name of the BizTalk application. this.Application = this.explorer.DefaultApplication.Name; this.LogTaskMessage(string.Format(CultureInfo.InvariantCulture, "Using default application {0}", this.Application)); } // create application if it doesn't exist if (!this.CheckExists(this.Application)) { OM.Application newapp = this.explorer.AddNewApplication(); newapp.Name = this.Application; this.explorer.SaveChanges(); this.LogTaskMessage(string.Format(CultureInfo.InvariantCulture, "Creating new application {0}", this.Application)); } using (Group group = new Group()) { group.DBName = this.Database; group.DBServer = this.DatabaseServer; Microsoft.BizTalk.ApplicationDeployment.Application appl = group.Applications[this.Application]; // used to specify custom properties for import, i.e. TargetEnvironment IDictionary <string, object> requestProperties = null; if (!string.IsNullOrEmpty(this.Environment)) { // -Environment Optional. The environment to deploy. requestProperties = new Dictionary <string, object> { { "TargetEnvironment", this.Environment } }; this.LogTaskMessage(string.Format(CultureInfo.InvariantCulture, "Target environment {0} specified", this.Environment)); } // the overload that takes request properties also requires this IInstallPackage package = DeploymentUnit.ScanPackage(this.MsiPath.ItemSpec); ICollection <string> applicationReferences = package.References; // -Overwrite Optional. Update existing resources. If not specified and resource exists, import will fail. appl.Import(this.MsiPath.ItemSpec, requestProperties, applicationReferences, this.Overwrite); this.LogTaskMessage(string.Format(CultureInfo.InvariantCulture, "Successfully imported {0} into application {1}", this.MsiPath.ItemSpec, this.Application)); } }
public string GetApplicationVersion(string application) { try { BtsCatalogExplorer btsExplorer = (BtsCatalogExplorer)grp.CatalogExplorer; Microsoft.BizTalk.ApplicationDeployment.ApplicationCollection apps = grp.Applications; Microsoft.BizTalk.ApplicationDeployment.Application app = apps[application]; if (null != app) { return(app.Description); } } catch (Exception exception) { throw new Exception(string.Format("BizTalkGroup.GetApplicationVersion failed: {0}", exception.Message), exception); } finally { } return("0.0.0.0"); }
private void DeleteApplication(ITaskItem application) { if (!this.CheckExists(application.ItemSpec)) { return; } using (Group group = new Group()) { group.DBName = this.Database; group.DBServer = this.DatabaseServer; Microsoft.BizTalk.ApplicationDeployment.ApplicationCollection apps = group.Applications; apps.UiLevel = 2; Microsoft.BizTalk.ApplicationDeployment.Application deadapp = apps[application.ItemSpec]; this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Application: {0} - {1}", application.ItemSpec, this.TaskAction)); apps.Remove(deadapp); } this.explorer.SaveChanges(); }