How can I determine whether or not to add project items using IWizard?
Posted
by taarskog
on Stack Overflow
See other posts from Stack Overflow
or by taarskog
Published on 2010-06-14T12:20:56Z
Indexed on
2010/06/14
12:22 UTC
Read the original article
Hit count: 178
Hi, I am generating entity wrappers in VS2010 based on dynamic objects in a CRM system. In addition to the entity code, I want to add an EntityBase of which all entities inherit from. If the file exists in the project from before, it should not be added. I am using an IWizard implementation to give the generator the object names etc.
Is it possible in the IWizard implementation to determine whether or not to add an item if it exists in the project from before? How do I get a hold of the project handle and its items in or before the ShouldAddProjectItem method?
My code so far (not completed):
public class EntityWizardImplementation : IWizard
{
public void BeforeOpeningFile(ProjectItem projectItem)
{
//Note: Nothing here.
}
public void ProjectFinishedGenerating(Project project)
{
//Note: Nothing here.
}
public void ProjectItemFinishedGenerating(ProjectItem projectItem)
{
//Note: Nothing here.
}
public void RunFinished()
{
//Note: Nothing here.
}
public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
{
try
{
var window = new WizardWindow();
// Replace parameters gathered from the wizard
replacementsDictionary.Add("$crmEntity$", window.CrmEntity);
replacementsDictionary.Add("$crmOrganization$", window.CrmOrganization);
replacementsDictionary.Add("$crmMetadataServiceUrl$", window.CrmMetadataUrl);
window.Close();
}
catch (SoapException se)
{
MessageBox.Show(se.ToString());
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}
public bool ShouldAddProjectItem(string filePath)
{
// This is where I assume it is correct to handle the preexisting file.
return true;
}
}
© Stack Overflow or respective owner