T4 Template throws error when inserting a control block - c#

I am using the following line in a text template file
<SettingsFilePath>
<#=GetParameterValue("Blah")#>\Deploy\Settings\DeploymentSetting_<#environment.Name#>_<#=workflow.Name#>.xml
</SettingsFilePath>
When I try to modify this line to insert another expression (environment.Type.ToString()) as follows
<SettingsFilePath>
<#=GetParameterValue("Blah")#>\Deploy\Settings\<#=environment.Type.ToString()#>\DeploymentSetting_<#environment.Name#>_<#=workflow.Name#>.xml
</SettingsFilePath>
I get the following error in Visual Studio compilation of TT Templates
An unexpected start or end tag was found within a block. Make sure that you did not mis-type a start or end tag, and that you do not have any nested blocks in the template.
Does anyone know what I am doing wrong? All the <#= #> blocks are properly matched.

Thanks everyone. I worked around it by using String.format as per Aaron's suggestion
<SettingsFilePath><#=string.Format(#"{0}\Deploy\Settings\{1}\DeploymentSetting_{2}_{3}.xml",GetParameterValue("blah"),environment.Type.ToString(), environment.Name, workflow.Name)#></SettingsFilePath>

Related

UiPath: How to set default values to a String[] variable

I have an exception when I'm trying to launch my workflow. It cames from my array declaration where I apparently don't have the right syntax.
My syntax really looks like the one used in the UiPath tuto I follow :
The tuto syntax:
My syntax:
I don't understand how I'm supposed to write the default values for a simple array of strings...
I'm only trying to pass the values in a Write Line activity, but this shows up when compiling:
If anyone can help, I'm stuck... Thanks
--- EDIT ---
The exception message is the following one:
Message: Compilation failure:
; expected Unvalid expression terms ',' ... many times...
The full results are stored in the Data property of this exception. Correct the errors of the source, then retry the load.
I found the problem: I did not instantiate the array with new String[] at the beginning. I suppose that the tutos are written using VB and not C#, which can explain the difference.
your declaration is correct maybe you have error in the loop here is a working example

HtmlAgilityPack Issue in reading html

I am reading websites in C# and get contents as string....there are some sites which do not have well formed html structure.
I am using HtmlAgilityPack which give me issue in that case.
Can you people suggest me what to use so that it can read whole string and i can get useful informations?
Here is my code
htmlDoc.LoadHtml(s);
if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() > 0)
Why this IF Condition is true for my case
What is the error you're getting? Is it throwing an exception or are you just wanting to see the error? Hard to tell what your actual question is.
You can see the markup errors in the HTML by using the HtmlDoc.ParseErrors property and iterate though them. This will give you the line number, code and type of error.
You can see more info about this property here
https://stackoverflow.com/a/5367455/235644
Edit
Ok so you've updated your question since my reply. You can see the specific error that's returning true in your IF statement by looping through the .ParseErrors are described above.
Second Edit
You can loop though the errors like so:
foreach (var error in htmlDoc.ParseErrors)
{
Debug.WriteLine(error.Line);
Debug.WriteLine(error.Reason);
}
You have to fix the bug in your HTML, and after it is valid you can go on.
Here is the same problem:
Invalid HTML in AgilityPack
If your html is external and you can't fix it, you can first run it through a cleanup preprocessor, then parse it with HtmlAgilityPack.
This will attempt to fix as many issues as possible automatically before HtmlAgilityPack gets to see it. The most popular HTML cleanup tool is Tidy. See the .NET version here:
http://sourceforge.net/projects/tidynet/

Catch text within a rounded bracket with quotes

I am still new to using Regex.
I'm on a project in C # and need to get a value that is within a bracket.
The Code is <$ Execute ['WebF'] $> I want to return the value WebF.
Agredeço much for your help.
#EDIT
My Code is <$Execute['WebF']$> without space
#EDIT
Thanks to doNet :).
Code that returned the value \<\$+Execute+\['(?<DATA>\w+)'\]+\$\>
\<\$\s+Execute\s+\['(?<DATA>\w+)'\]\s+\$\>
Run it with ExplicitCapture and IgnoreCase flags.

C# How can I get from CompilerError instance exact text which caused the error

Could you please tell me how can I get from CompilerError instance exact text which caused the error.
Edited:
What about using
compilerError.FileName
and reading the file with text reader? I am trying to do so but it seems that Compiler doesn't create cs file that doesn't pass the compilation any suggestions?
This CompilerError? : http://msdn.microsoft.com/en-us/library/system.codedom.compiler.compilererror.aspx
There are FileName and Line properties, that's the best you can get.
What are you compiling - is it entirely in-memory (CodeDOM)?
If so you can add code-line pragmas to your object model: http://msdn.microsoft.com/en-us/library/system.codedom.codelinepragma.aspx then you'll be able to link an error to a DOM element.
Or, you can compile from source, then you'll have the source code itself and can get the text from the line number.
The best your going to get is the line number.

Using variables as selectors with Selenium 2 Webdriver by.cssselector

I am using Visual Studio 2010 to write Selenium 2 Webdriver automated tests in C#.
I have searched high and low for examples of using variables as selectors and have found nothing that seems to work. The one example I have found of a variable used as a selector had the variable with $ prefix and enclosed in {}.
An example of what I am trying to do is below:
string surveyName = "Selenium test survey";
Driver.FindElement(By.CssSelector("tr[svd='${surveyName}']"))
I get the error:
OpenQA.Selenium.WebDriverException : Unexpected error. Unable to find element using css: tr[svd='${surveyName}']
If I 'hard code' the selector like this:
Driver.FindElement(By.CssSelector("tr[svd='Selenium test survey']"))
it finds the element.
svd is an attribute of the tr element. I am trying to select a row within a table by the value of this attribute. The text will be different for each test and so must be a variable.
I have tried expressing the variable a number of different ways but had no luck making this work. Any help would be much appreciated.
Thanks.
string surveyName = "Selenium test survey";
Driver.FindElement(By.CssSelector(String.Format("tr[svd='{0}']", surveyName))
will do what you want. This is c# so when it takes a string you can do all kinds of things to get that string

Categories