Multiple CodeSnippet in an XML .snippet file - vb.net

I'm attempting to supplement the help features for my code by providing other developers with code snippets. These produce skeletons of code which demonstrate how to use/call my classes or methods.
I've created a .snippet file and have placed it in the "%Visual Studio Folder%\Code Snippets\Visual Basic\My Snippets" folder. I've used the Code Snippets Manager and ensured that it included this folder so that I can access the snippets.
Everything works well when I have 1 CodeSnippet tag within the root CodeSnippets tag....
When I add more than one CodeSnippet tag to the file (each with their own title, and their own code example) I'm experiencing something strange.
The first CodeSnippet I've added contains code for adding something to my system, the second contains code for editing something in my system, and the third deleting something from the system.
When I use the code snippet by right clicking and selecting "Insert Code Snippet", only the first code snippet in the file shows up as an option. When I select it, the code in the first CodeSnippet is inserted....but so is the code within the other CodeSnippet tags.
Do you have to have a separate XML .snippet file for each code snippet you want to make available?
After reading through MSDN about creating Code Snippets I was under the impression that this could all be done within one file.
It seems that I'm not understanding something very basic here and would love to find the answer but apparently Code Snippets are under used so finding the answer has proven to be a little trickier than I first thought it would be.
Thanks,
-Frinny

Do you have to have a separate XML .snippet file for each code snippet
you want to make available? After
reading through MSDN about creating
Code Snippets I was under the
impression that this could all be done
within one file.
I create and use snippets all the time. I wanted to do exactly what you intend. But, I have never gotten multiple snippets in one file to work. I also was under the impression you could do this. I even found an article, based on the beta version of Visual Studio, that demonstrated how to do this, but it didn't work. Moreover, the documentation states:
CodeSnippet Optional element. -
Parent element for all code snippet
data. There may be zero or more
CodeSnippet elements in a CodeSnippets
element.
I eventually gave up and created separate files. I have not tried multiple snippets in one file with VS2k8 yet.
Update
I cannot get VB to support multiple snippets in one file using VS2k8. I used the following snippet as a test case. Snippet taken from http://msdn.microsoft.com/en-us/library/ms165394.aspx. Only the first CodeSnippet is read/loaded/used. I also counted all CodeSnippet elements in all snippet files (1143) and no file has more than one. Moreover, this snippet duplicates the behavior you noted in your question. Using the snippet inserts both message box statements.
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2008/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>
SECOND Snippet
</Title>
</Header>
<Snippet>
<Code Language="VB">
<![CDATA[MsgBox("SECOND SNIPPET")]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>
FIRST Snippet
</Title>
</Header>
<Snippet>
<Code Language="VB">
<![CDATA[MsgBox("FIRST SNIPPET")]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
More Info
I got to thinking that this has to be a bug that slipped through because Microsoft never put multiple snippets in the provided snippet files that come with Visual Studio, or VB.NET doesn't support multiple snippets due to difficulties integrating with the enhanced statement completion capabilities of the editor.

Related

How to add line breaks to Redmine markdown in code highlighting?

The Redmine textile formatting guide directs us to use code highlighting like so:
<pre><code class="ruby">
Place your code here.
</code></pre>
And while line breaks are preserved within <pre> tags, once I add the <code class="python">, it removes all line breaks and places all the text on a single line. And of course, hacks like (which answered this question) or html tags don't work because it's still wrapped inside <pre>.
I've tried wrapping each individual line with <code></code> all within one <pre></pre>, but that didn't work. I've tried adding double spaces to the end of each line, and additional new lines in between but to no avail.
And while the Redmine guide above says code highlighting relies on Rouge, my version of Redmine uses CodeRay, whose website examples handle line breaks perfectly.
Thanks in advance!
Things are working ok for me. See my screenshots. Perhaps your theme is affecting that.
I'm using Abacus office 1.3.4 theme on Redmine v3.2.
Could any plugins that you have installed be causing that?

Unable to embed a screenshot to the SpecFlow html Report

I am executing my automation scenarios using SpecFlow with Visual Studio.
I want to Embed a custom image to the HTML report which was generated by SpecFlow. That image is a screenshot i am taking whenever scenario is failed in Hooks.
Please help me out.
This is what i am seeing in the html report - enter image description here
Take a look at the SeleniumWebTest sample project here. This sample project shows how to include a screenshot in your report. While the example is Selenium-based, the same principles apply to other frameworks.
A more in-depth explanation of how this works can be found here under "Including Screenshots". Essentially, you need to abuse the console and use it to output your images' file paths.
Any data written to the console is available in your report (this is how the trace details are received by the report). You will need to parse the data written to the console and strip out the file path you want to embed. Make sure that you strip the image path completely so that you don't output the file path as part of the other trace information received from the console.
Edit: I've since discovered that there seems to be an issue with the template in the sample project. The following section in the template is bugged:
class="log">#Raw(FormatTechMessages(traceEvent.TechMessages.TrimEnd()).Replace("SCREENSHOT[ <a href="http://specflow.org/plus/documentation/,-/" data-page=",-"<img width='1000' src=").Replace("</a> ]SCREENSHOT", "</img>"))</pre>
This is because the console no longer seems to be formatting the file as a hyperlink, so the replacement string is never found. Updating this line in ReportTemplate.cshtml seems to have done the trick:
<pre class="log">#Raw(FormatTechMessages(traceEvent.TechMessages.TrimEnd()).Replace("SCREENSHOT[ ", "<img width='1000' src=\"").Replace(" ]SCREENSHOT", "\"</img>"))</pre>
As the console is no longer formatting the file as a hyperlink, you only need to replace the padding (in this case the "SCREENSHOT[]SCREENSHOT") from the string and instead enclose the path with the <IMG> tag. You also need to add the quotes around the file path.

VS13/VS15 - can't import SQL snippet

I would like to create SQL snippet in VS2013 and VS2015. I don't know why, but I've got an error while importing (in both of VS):
"C:\sql.snippet: Missing or unspecified Language attribute"
My snippet:
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2008/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>
My Snippet
</Title>
</Header>
<Snippet>
<Code Language="SQL">
<![CDATA[select * from MyTable]]>
</Code>
</Snippet>
</CodeSnippet>
What's wrong?
The language SQL should be OK https://msdn.microsoft.com/en-US/library/ms171418.aspx#code
I tried to add this snippet to language "Miscrosoft SQL Server Data Tools, T-SQl..."
If I've changed the language attribute to e.g. CSharp it works.
Instead of:
<Code Language="SQL">
Write:
<Code Language="SQL_SSDT">
Visual Studio supports only MSSQL Server Data Tools & T-SQL Language Scripts, not SQL like SSMS does.
Try this.
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>
My Snippet
</Title>
</Header>
<Snippet>
<Code Language="SQL">
<![CDATA[select * from MyTable]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
You could also check this out if it works but still gives a warning.
http://providersweb.blogspot.se/2016/01/visual-studio-snippets-missing-or.html
I have been getting a list of messages in the Snippets output window
when I load a project that a number of snippets had a 'missing or
unspecified language attribute' and could not figure out why these
messages appeared. I had checked the Language attribute on the
snippets and they were correct, but still got the message. I had set
up folders for each language type, but still got the messages. I
finally figured out that I had specified they all were VB snippets in
the Snippet manager and those that were not VB would cause the
messages in the output window, ie when loading a VB project, the
CSharp snippets would generate the error message. I fixed this by
going into the snippet manager and specifying the Language, VB or
CSharp, and adding the snippets to the correct language and removing
them from the invalid language. And now these messages of invalid
language attributes do not appear on my output screen.
The language attribute value you used, SQL, is correct. From the VS2015 Code Snippets Schema Reference:
Errors such as you're seeing can happen if you're editing a snippet file directly in one of the folders known by the Code Snippets Manager. Evidently Visual Studio holds its own metadata in addition to what's in the snippet XML itself. For this reason, it can be best to do the edits in a temporary folder and then use the Import button.
For example, I kept getting the error "Missing or unspecified Language attribute" when saving any edit to my new C# snippet in the My Code Snippets folder—or so I thought. Turned out I was in the Visual Basic\My Code Snippets folder, and there's also a Visual C#\My Code Snippets folder which is where I should have been. This was a silly mistake but it illustrates that the "Language" XML attribute isn't enough, as Visual Studio has its own internal conventions to do with different folders for different snippet types (and who knows what else) which all happens when the Import button is used.
I removed my snippet file to a temporary location, and then added it from there using the Import button. As soon as I did this, the problem went away and the snippet started working normally.

Dojo - Some of my form.dijit's seem to be dead/inactive on one page

I was started to work on my first sample of the dijit.Tree control.
When it didn't work, I added a couple of dijit.form.Textbox'es to the screen, and they didn't work either, even though I have them working fine on a similar form.
Interesting enough, when I killed FireFox and restarted it, I was got a clear message in FireBug console on what was wrong with my tree control, and got it fixed.
But now I'm rather puzzled while the simple dijits like NumberTextBox that I added are not working.
My Samples:
1) http://3wcloud-com-provisioning-qa.appspot.com/testDijitDate - this works great
(except the initial date value not showing - I have a separate question open on that)
2) http://3wcloud-com-provisioning-qa.appspot.com/testDijitTree
I've done several "diff"s on the two files, and I kind find the difference that would cause one to work and one not to work.
Thanks,
Neal
You should put your dojo.require statements immediately in a script block, not wrapped in the onload callback. Also, your input tags should be HTML style without the XHTML style slash (you didn't declare XHTML in your document) though I doubt that's the problem. See if either of those things help.

Objective-c code formatter site to create html that can be embedded into a blog

I'm looking for site similar to http://www.manoli.net/csharpformat/ that allows one to put in c# code snippet and it formats the html to post into your blog with a CSS file.
I need one that actually does this for Objective-C.
You want the GeSHi (Generic Syntax Highlighter) library. It's is excellent, has dozens of languages (including Objective-C, with the ability to automatically linkify classes/protocols to the documentation), and support for many popular CMSs (Django, WordPress, Drupal, Joomla, Mambo, etc).
If you'd like to see it in action, you can check out nearly any wiki page on our local CocoaHeads website. For example: http://cocoaheads.byu.edu/wiki/different-nslog
Assuming you're on a Mac, copying code from Xcode will keep the syntax coloring. Any WYSIWYG blog editor should support that.
In case your blog software isn't WYSIWYG, you can paste into TextEdit and save as HTML. It outputs pretty crappy HTML considering it's just highlighted source code, but it's nonetheless compliant HTML.
Other than that, I don't know of an online service for that.
I use pygments (python) to generate syntax highlight for source code examples embedded in blog.
If your entry text is just the source code it will work the same for what you are after, I tested it to highlight Objective-C as well.
I actually use markdown syntax to type plain text blog post in a file and I copy plain text code examples. Then I run the file via markdown processor, which includes pygments for highlight and store it into a file.
It's as simple as:
include markdown
html = markdown.markdown(text,['codehilite'])
See simple script at the link which just takes file name of your plain text file and creates html file.
Then I can copy/paste the code.
You have to include link or copy the css as well to get the syntax highligh but it's easy.
I do this for blogger, see example how to use markdown with pygments to do syntax highlight.