22// Copyright (C) 2008-Present Thomas F. Abraham. All Rights Reserved.
33// Licensed under the MIT License. See License.txt in the project root.
44
5+ using EnvDTE80 ;
6+ using Microsoft . VisualStudio . Shell ;
7+ using Microsoft . VisualStudio . TemplateWizard ;
8+ using Microsoft . Win32 ;
59using System ;
610using System . Collections . Generic ;
11+ using System . ComponentModel ;
712using System . IO ;
13+ using System . Reflection ;
814using System . Text ;
915using System . Windows . Forms ;
1016using System . Xml ;
11- using EnvDTE ;
12- using EnvDTE80 ;
13- using Microsoft . VisualStudio . TemplateWizard ;
14- using Microsoft . Win32 ;
15- using System . Reflection ;
16- using System . ComponentModel ;
1717
1818namespace DeploymentFramework . VisualStudioAddIn . ProjectWizard
1919{
@@ -39,103 +39,107 @@ public void RunFinished()
3939
4040 public void RunStarted ( object automationObject , Dictionary < string , string > replacementsDictionary , WizardRunKind runKind , object [ ] customParams )
4141 {
42- DTE2 dte = automationObject as DTE2 ;
42+ ThreadHelper . JoinableTaskFactory . Run ( async delegate {
43+ await ThreadHelper . JoinableTaskFactory . SwitchToMainThreadAsync ( ) ;
4344
44- if ( dte == null )
45- {
46- MessageBox . Show (
47- "Cannot convert automation object to DTE2." , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
48- return ;
49- }
45+ DTE2 dte = automationObject as DTE2 ;
5046
51- if ( ! dte . Solution . IsOpen )
52- {
53- MessageBox . Show (
54- "Please open your BizTalk solution, then use the Add New Project dialog on the solution to add this project." ,
55- "Error" ,
56- MessageBoxButtons . OK ,
57- MessageBoxIcon . Error ) ;
58- return ;
59- }
47+ if ( dte == null )
48+ {
49+ MessageBox . Show (
50+ "Cannot convert automation object to DTE2." , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
51+ return ;
52+ }
6053
61- string destinationPath = replacementsDictionary [ "$destinationdirectory$" ] ;
54+ if ( ! dte . Solution . IsOpen )
55+ {
56+ MessageBox . Show (
57+ "Please open your BizTalk solution, then use the Add New Project dialog on the solution to add this project." ,
58+ "Error" ,
59+ MessageBoxButtons . OK ,
60+ MessageBoxIcon . Error ) ;
61+ return ;
62+ }
6263
63- if ( string . IsNullOrEmpty ( destinationPath ) )
64- {
65- MessageBox . Show (
66- "Cannot determine destination directory ($destinationdirectory$ is missing)." ,
67- "Error" ,
68- MessageBoxButtons . OK ,
69- MessageBoxIcon . Error ) ;
70- return ;
71- }
64+ string destinationPath = replacementsDictionary [ "$destinationdirectory$" ] ;
7265
73- string btdfInstallDir =
74- ( string ) Registry . GetValue ( @"HKEY_LOCAL_MACHINE\Software\DeploymentFrameworkForBizTalk" , "InstallPath" , null ) ;
66+ if ( string . IsNullOrEmpty ( destinationPath ) )
67+ {
68+ MessageBox . Show (
69+ "Cannot determine destination directory ($destinationdirectory$ is missing)." ,
70+ "Error" ,
71+ MessageBoxButtons . OK ,
72+ MessageBoxIcon . Error ) ;
73+ return ;
74+ }
7575
76- if ( string . IsNullOrEmpty ( btdfInstallDir ) )
77- {
78- MessageBox . Show (
79- "Cannot find Deployment Framework registry key." , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
80- return ;
81- }
76+ string btdfInstallDir =
77+ ( string ) Registry . GetValue ( @"HKEY_LOCAL_MACHINE\Software\DeploymentFrameworkForBizTalk" , "InstallPath" , null ) ;
8278
83- DeploymentOptions options = new DeploymentOptions ( ) ;
79+ if ( string . IsNullOrEmpty ( btdfInstallDir ) )
80+ {
81+ MessageBox . Show (
82+ "Cannot find Deployment Framework registry key. Please install the Deployment Framework for BizTalk MSI." , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
83+ return ;
84+ }
8485
85- OptionsForm optionsFrm = new OptionsForm ( options ) ;
86- if ( optionsFrm . ShowDialog ( ) != DialogResult . OK )
87- {
88- return ;
89- }
86+ DeploymentOptions options = new DeploymentOptions ( ) ;
87+
88+ OptionsForm optionsFrm = new OptionsForm ( options ) ;
89+ if ( optionsFrm . ShowDialog ( ) != DialogResult . OK )
90+ {
91+ return ;
92+ }
9093
91- string templateDir = Path . Combine ( btdfInstallDir , @"Developer\ProjectTemplate" ) ;
94+ string templateDir = Path . Combine ( btdfInstallDir , @"Developer\ProjectTemplate" ) ;
9295
93- string [ ] templateFiles = Directory . GetFiles ( templateDir , "*.*" , SearchOption . AllDirectories ) ;
96+ string [ ] templateFiles = Directory . GetFiles ( templateDir , "*.*" , SearchOption . AllDirectories ) ;
9497
95- try
96- {
97- CopyDirectory ( templateDir , destinationPath ) ;
98- }
99- catch ( Exception ex )
100- {
101- MessageBox . Show (
102- "Failed to copy Deployment Framework template files to destination folder: " + ex . Message ,
103- "Error" ,
104- MessageBoxButtons . OK ,
105- MessageBoxIcon . Error ) ;
106- return ;
107- }
98+ try
99+ {
100+ CopyDirectory ( templateDir , destinationPath ) ;
101+ }
102+ catch ( Exception ex )
103+ {
104+ MessageBox . Show (
105+ "Failed to copy Deployment Framework template files to destination folder: " + ex . Message ,
106+ "Error" ,
107+ MessageBoxButtons . OK ,
108+ MessageBoxIcon . Error ) ;
109+ return ;
110+ }
108111
109- string solutionName = Path . GetFileNameWithoutExtension ( dte . Solution . FileName ) ;
110- string projectFileName = "Deployment.btdfproj" ;
111- string projectFilePath = Path . Combine ( destinationPath , projectFileName ) ;
112+ string solutionName = Path . GetFileNameWithoutExtension ( dte . Solution . FileName ) ;
113+ string projectFileName = "Deployment.btdfproj" ;
114+ string projectFilePath = Path . Combine ( destinationPath , projectFileName ) ;
112115
113- Dictionary < string , string > replacements = new Dictionary < string , string > ( ) ;
114- replacements . Add ( "[PROJECTNAME]" , solutionName ) ;
116+ Dictionary < string , string > replacements = new Dictionary < string , string > ( ) ;
117+ replacements . Add ( "[PROJECTNAME]" , solutionName ) ;
115118
116- ReplaceInTextFile ( destinationPath , "InstallWizard.xml" , replacements , Encoding . UTF8 ) ;
117- ReplaceInTextFile ( destinationPath , "UnInstallWizard.xml" , replacements , Encoding . UTF8 ) ;
119+ ReplaceInTextFile ( destinationPath , "InstallWizard.xml" , replacements , Encoding . UTF8 ) ;
120+ ReplaceInTextFile ( destinationPath , "UnInstallWizard.xml" , replacements , Encoding . UTF8 ) ;
118121
119- replacements . Add ( "[GUID1]" , Guid . NewGuid ( ) . ToString ( ) ) ;
120- replacements . Add ( "[GUID2]" , Guid . NewGuid ( ) . ToString ( ) ) ;
121- ReplaceInTextFile ( destinationPath , projectFileName , replacements , Encoding . UTF8 ) ;
122+ replacements . Add ( "[GUID1]" , Guid . NewGuid ( ) . ToString ( ) ) ;
123+ replacements . Add ( "[GUID2]" , Guid . NewGuid ( ) . ToString ( ) ) ;
124+ ReplaceInTextFile ( destinationPath , projectFileName , replacements , Encoding . UTF8 ) ;
122125
123- UpdateProjectFile ( projectFilePath , options , optionsFrm . WritePropertiesOnlyWhenNonDefault ) ;
126+ UpdateProjectFile ( projectFilePath , options , optionsFrm . WritePropertiesOnlyWhenNonDefault ) ;
124127
125- try
126- {
127- dte . ExecuteCommand ( "File.OpenFile" , '"' + projectFilePath + '"' ) ;
128- }
129- catch ( Exception )
130- {
131- MessageBox . Show ( "Failed to open .btdfproj file in editor." , "Warning" , MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
132- }
128+ try
129+ {
130+ dte . ExecuteCommand ( "File.OpenFile" , '"' + projectFilePath + '"' ) ;
131+ }
132+ catch ( Exception )
133+ {
134+ MessageBox . Show ( "Failed to open .btdfproj file in editor." , "Warning" , MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
135+ }
133136
134- MessageBox . Show (
135- "A default Deployment Framework for BizTalk project has been configured in " + destinationPath + ". You must edit " + projectFileName + " to configure your specific deployment requirements." ,
136- "Project Created" ,
137- MessageBoxButtons . OK ,
138- MessageBoxIcon . Information ) ;
137+ MessageBox . Show (
138+ "A default Deployment Framework for BizTalk project has been configured in " + destinationPath + ". You must edit " + projectFileName + " to configure your specific deployment requirements." ,
139+ "Project Created" ,
140+ MessageBoxButtons . OK ,
141+ MessageBoxIcon . Information ) ;
142+ } ) ;
139143 }
140144
141145 public bool ShouldAddProjectItem ( string filePath )
0 commit comments