Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Wednesday, May 18, 2016

Visual Studio POSH snippet, DocuComment

I am trying to get into more Visual Studio (as that is what "real" programmers use).... and to my delight, I found out that PowerShell is more supported than ever before in VS 2015.  Perhaps I can finally put away my childish things (ISE) and move onto something much more unnecessarily complicated.   So when I read about "code snippets" I was excited... but....

 No matter how much I searched, I could not find one for a simple "documentation block."  You know, the one with the ".Synopsis", and ".Example" that we are supposed to use in our scripts, but never do?  Perhaps I can make the world a better place by figuring it out and allowing others to use it.  Now you have no excuse to not document your code better, you are just three clicks away from having the "DocuComment" block created for you!

You will need to put the code below in to a file with an extension of ".snippet" and import it into VS.
(Details of this can be found at: https://msdn.microsoft.com/en-us/library/9ybhaktf(v=vs.100).aspx )

DocuComment.snippet :

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>DocuComment Block</Title>
      <Shortcut>docucomment</Shortcut>
      <Description>Code snippet for a comment block.</Description>
      <Author>Bryan Loveless bryan.loveless@gmail.com</Author>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
        <SnippetType>SurroundsWithStatement</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Declarations>
        <Literal>
          <ID>param1</ID>
          <ToolTip>DocuComment</ToolTip>
          <Default>
            .SYNOPSIS

            synopsis of script, overall idea



            .DESCRIPTION

            description of overall script, more detail than synopsis



            .PARAMETER parameternamehere

            parameter description, if required, possible values



            .PARAMETER path

            parameter path



            .EXAMPLE

            example of script use, return behavior.



            .EXAMPLE

            another exmample if there are more.  This can be repeated for as many examples as you want



            .NOTES

            other misc notes, perhaps permissions needed, dates of script.
          </Default>
        </Literal>
      </Declarations>
      <References />
      <Code Language="PowerShell">
        <![CDATA[<#
$param1$
$selected$ $end$
#>]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

Tuesday, June 26, 2012

Well, it could have been much worse.


I thought I would share a hyper-v war stor.

Yesterday someone from central IT called me, as he was going to update SCVMM to 2012.  I said, sounds great!  It wasn’t.

We believed that it shouldn’t bring anything down, as SCVMM mostly just monitors, so it shouldn’t be a big deal at all.  About 3 hours later, I get a call from my DBA.  Production SQL is down, along with a host of other VMs.  The dreaded “missing config file” error.  Now, I should mention that my vms are on a 3 node Win 2k8 R2 DC cluster.  Rebooting physical machines, and moving the drives around to “working” nodes didn’t work.  I could still browse to the VHDs and the config files.  Hyper-v then reported that there was a problem with a corrupted file.

So as we sitting around, thinking about backup tapes and considering how to update our resume, I remembered that once I just had rebuilt the config file for a machine that did this in the past.  Now this current machine that was failing to start had several pass through disks, memory settings, various NIC configurations that I didn’t want to have to recreate.  I decided to look into the XML config file.  Sure enough, it ended with :
“<settings>
    <global>
      <logical_id type="string">78F….D-4FC2-someotherGUIDdigitshereFB</logical_id>
    </global>
    <memory>
      <bank>
        <limit type="integer">12288</limit>
        <reservation type="integer">12288</reservation>
        <size type="integer">12288</size>
      </bank>
    </memory>
    <processors>
      <count type="integer">4</count>
      <features>
        <limit type="bool">True</limit>
      </features>
      <limit type="integer">100000</limit>
      <limit_cpuid type="bool">False</limit_cpuid>
      <reservation type="integer">0</reservation>
      <weight type="integer">200</weight>
    </processors>
    <stopped_at_host_shutdown type="bool">False</stopped_at_host_shutdo

Now I am no programming wiz, but I know that you at least have to close XML tags, or computers get angry.  Some quick googlin’ turned up:


So I made a backup copy of the current broken XML doc, then properly ended the XML tags that were missing.  I then crossed some fingers, right clicked “bring online” and POOF! It worked.
My heart started beating again, and my cell phone quit vibrating.