i have one razor mvc project template with wizard concept. i want to pass some string from wizard application to .cshtml file. i have passed using RunStarted method of wizard application. Please check code below.
public void RunStarted(object automationObject, Dictionary<string,
string> replacementsDictionary, WizardRunKind runKind, object[] customParams) { try { dte = automationObject as DTE;
if (pSelect.Contains("True"))
AddAssembly("Common-Mobile");
if (pSelect.Contains("False"))
AddAssembly("Common");
foreach (string product in products)
{
if (product != string.Empty)
{
switch (product)
{
case "Tools":
AddAssembly(product);
break;
case "Grid":
AddAssembly(product);
break;
case "Chart":
AddAssembly(product);
break;
case "Gauge":
AddAssembly(product);
break;
case "Schedule":
AddAssembly(product);
break;
case "Diagram":
AddAssembly(product);
break;
case "DocIO":
AddAssembly(product);
break;
case "Pdf":
AddAssembly(product);
break;
case "XlsIO":
AddAssembly(product);
break;
case "PdfViewer":
AddAssembly(product);
break;
case "OlapGrid":
AddAssembly(product);
break;
case "Mobile-Chart":
AddAssembly(product);
break;
case "Mobile-Grid":
AddAssembly(product);
break;
case "Mobile-Tools":
AddAssembly(product);
break;
case "Mobile-Gauge":
AddAssembly(product);
break;
}
}
}
if (sAspRazor.Equals("Site.tt"))
{
destfile = uDoc + @"\Site.tt";
vigneshtr11
Member
40 Points
38 Posts
How to pass string from IWizrad run started method to razor mvc project template (.cshtml file)
Apr 16, 2012 09:27 AM|LINK
i have one razor mvc project template with wizard concept. i want to pass some string from wizard application to .cshtml file. i have passed using RunStarted method of wizard application. Please check code below.
public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
{
try
{
dte = automationObject as DTE;
.............................................................................................................
replacementsDictionary.Add("$ProductA$", "Mobile");
.................................................................
}
catch()
{
}
}
in Template .cshtml file please check the code.
<html>
<head> </head>
<body>
"$ProductA$"
</body>
</html>
but the the value of "$ProductA$" is not replaced in .cshtml page. but it was working fine in .Aspx page .CS page. how can do that in .cshtml.
urgent requirement.
Please anyone help.
Thanks..
vigneshtr11
Member
40 Points
38 Posts
Re: How to pass string from IWizrad run started method to razor mvc project template (.cshtml fil...
Apr 16, 2012 09:27 AM|LINK
i have already using this kind of coding
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
public class Wizardclass : IWizard
{
#region private members
private MainWindow wizardFrm;
private string customMessage;
private string sXmlPath = @"Products.xml";
private string[] products;
private string configPath;
private IEnumerable<string> pSelect;
private DTE dte;
private string masterPath;
private string textTransformLocation = string.Empty;
private string sAspRazor;
private string uDoc;
private string destfile;
private string srcMaster;
private string destMasterFile;
#endregion
public void BeforeOpeningFile(ProjectItem projectItem)
{
}
public void ProjectFinishedGenerating(Project project)
{
customMessage = wizardFrm.get_CustomMessage();
uDoc = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
if (customMessage != string.Empty && !customMessage.Equals("CloseApp"))
{
ProjectItem pConfigItem = project.ProjectItems.Item(9);
ProjectItem pMasterItem = dte.Solution.FindProjectItem(sAspRazor);
configPath = pConfigItem.Properties.Item("FullPath").Value;
masterPath = pMasterItem.Properties.Item("FullPath").Value;
if (pSelect.Contains("True"))
AddAssembly("Common-Mobile");
if (pSelect.Contains("False"))
AddAssembly("Common");
foreach (string product in products)
{
if (product != string.Empty)
{
switch (product)
{
case "Tools":
AddAssembly(product);
break;
case "Grid":
AddAssembly(product);
break;
case "Chart":
AddAssembly(product);
break;
case "Gauge":
AddAssembly(product);
break;
case "Schedule":
AddAssembly(product);
break;
case "Diagram":
AddAssembly(product);
break;
case "DocIO":
AddAssembly(product);
break;
case "Pdf":
AddAssembly(product);
break;
case "XlsIO":
AddAssembly(product);
break;
case "PdfViewer":
AddAssembly(product);
break;
case "OlapGrid":
AddAssembly(product);
break;
case "Mobile-Chart":
AddAssembly(product);
break;
case "Mobile-Grid":
AddAssembly(product);
break;
case "Mobile-Tools":
AddAssembly(product);
break;
case "Mobile-Gauge":
AddAssembly(product);
break;
}
}
}
if (sAspRazor.Equals("Site.tt"))
{
destfile = uDoc + @"\Site.tt";
srcMaster = uDoc + @"\Site.Master";
}
else
{
destfile = uDoc + @"\_Layout.tt";
srcMaster = uDoc + @"\_Layout.cshtml";
}
RegistryKey regKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion");
if ((regKey != null))
{
textTransformLocation = (string)regKey.GetValue("CommonFilesDir") + @"\Microsoft Shared\TextTemplating\10.0\TextTransform.exe";
}
File.Copy(masterPath, destfile, true);
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.UseShellExecute = true;
proc.EnableRaisingEvents = false;
// Set text transform program (this could change according to the Windows version)
proc.StartInfo.FileName = textTransformLocation;
// Specify T4 template file
proc.StartInfo.Arguments = destfile;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.Start();
proc.WaitForExit();
destMasterFile =sAspRazor.Equals("Site.tt") ? masterPath.Replace("Site.tt", "Site.Master") : masterPath.Replace("_Layout.tt", "_Layout.cshtml");
File.Copy(srcMaster, destMasterFile,true);
project.ProjectItems.AddFromFile(destMasterFile);
pMasterItem.Remove();
File.Delete(pMasterItem.Properties.Item("FullPath").Value);
File.Delete(destfile);
File.Delete(srcMaster);
}
}
private void AddAssembly(string prod)
{
Project project = dte.Solution.Projects.Item(1);
VSProject vsproject = project.Object;
IEnumerable<XElement> elementref;
//Assembly ass = Assembly.GetExecutingAssembly();
XElement xElement = XElement.Load(sXmlPath);
IEnumerable<XElement> address = from el in xElement.Elements("Product") where (string)el.Attribute("name") == prod select el;
XElement element = address.First();
XElement elementAssembly = element.Element("assemblies");
XElement elementNameSpace = element.Element("namespaces");
XElement elementhttpHandler = element.Element("httpHandlers");
XElement elementHandler = element.Element("handlers");
if (element.Element("References") != null)
{
elementref = element.Element("References").Elements();
foreach (XElement e1 in elementref)
vsproject.References.Add(e1.Value);
}
XElement xconfigElement = XElement.Load(configPath);
XElement xmlAssembly = xconfigElement.Element("system.web").Element("compilation").Element("assemblies");
XElement xmlNamespace = xconfigElement.Element("system.web").Element("pages").Element("namespaces");
XElement xmlHandlers = xconfigElement.Element("system.web").Element("httpHandlers");
XElement xmlserverHandlers = xconfigElement.Element("system.webServer").Element("handlers");
Addhandlers(xmlAssembly, elementAssembly, "assembly");
Addhandlers(xmlNamespace, elementNameSpace, "namespace");
Addhandlers(xmlHandlers, elementhttpHandler, "type");
Addhandlers(xmlserverHandlers, elementHandler, "type");
xconfigElement.Save(configPath);
}
private void Addhandlers(XElement destElement, XElement srcElement, string attr)
{
if (srcElement != null)
{
srcElement.Elements().ToList().ForEach(x =>
{
if (destElement != null && destElement.Elements() != null)
{
bool isExist = false;
destElement.Elements().ToList().ForEach(p =>
{
if (p != null && p.Attribute(attr) != null && x != null && x.Attribute(attr) != null && p.Attribute(attr).Value == x.Attribute(attr).Value)
{
isExist = true;
}
});
if (!isExist)
destElement.AddFirst(x);
}
});
}
}
public void ProjectItemFinishedGenerating(ProjectItem projectItem)
{
}
public void RunFinished()
{
}
public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
{
try
{
dte = automationObject as DTE;
//Call win form created in the project to accept user input
wizardFrm = new MainWindow();
wizardFrm.ShowDialog();
customMessage = wizardFrm.get_CustomMessage();
if(customMessage != string.Empty && customMessage.Equals("CloseApp"))
{
this.wizardFrm.Close();
Application.Current.MainWindow.Close();
}
else
{
products = customMessage.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
pSelect = products.Select(p => p.StartsWith("Mobile").ToString());
string sScriptCombine = Convert.ToString(wizardFrm.get_CompressScript()).ToLower();
string sStyleCombine = Convert.ToString(wizardFrm.get_CompressStyle()).ToLower();
string DeskTheme = wizardFrm.get_DeskTheme();
string MobTheme = wizardFrm.get_MobileTheme();
DeskTheme = string.IsNullOrEmpty(DeskTheme) ? "None" : DeskTheme;
MobTheme = string.IsNullOrEmpty(MobTheme) ? "None" : MobTheme;
MessageBox.Show("RunStart");
//customParams[customParams.Length-1] = "$Product$=Syncfusion";
MessageBox.Show(customParams.Length.ToString());
MessageBox.Show(customParams.FirstOrDefault().ToString());
MessageBox.Show(customParams.LastOrDefault().ToString());
if (pSelect.Contains("True"))
{
replacementsDictionary.Add("$ProductA$", "Mobile");
replacementsDictionary.Add("$MobTheme$", MobTheme);
replacementsDictionary.Add("$sMobStyleCombine$", sStyleCombine);
replacementsDictionary.Add("$sMobScriptCombine$", sScriptCombine);
}
else
{
replacementsDictionary.Add("$ProductA$", "");
}
if (pSelect.Contains("False"))
{
replacementsDictionary.Add("$ProductB$", "Desktop");
replacementsDictionary.Add("$DeskTheme$", DeskTheme);
replacementsDictionary.Add("$sDeskStyleCombine$", sStyleCombine);
replacementsDictionary.Add("$sDeskScriptCombine$", sScriptCombine);
}
else
{
replacementsDictionary.Add("$ProductB$", "");
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
public bool ShouldAddProjectItem(string filePath)
{
customMessage = wizardFrm.get_CustomMessage();
if ((filePath.Equals("Site.tt") || filePath.Equals("_Layout.tt")))
sAspRazor = filePath;
if (customMessage != string.Empty && !customMessage.Equals("CloseApp"))
{
return true;
}
else
{
return false;
}
}
}
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
From above coding i want to replace $ProductA$ string Index.cshtml page to "Mobile"
how to replace the string .cshtml page using wizard concept.
Thanks,
</div>ignatandrei
All-Star
134539 Points
21585 Posts
Moderator
MVP
Re: How to pass string from IWizrad run started method to razor mvc project template (.cshtml fil...
Apr 17, 2012 03:45 AM|LINK
remove the