Contents
Code Snippets and Templates

Creating Custom Code Snippets

A code snippet must be composed using the xml schema and format illustrated below (for additional examples please refer to the snippet files located in the Snippets folder, under the application installation folder). In order to create a new custom code snippet, the following steps must be followed: First, create a new file with the extension .snippet, enter the xml content with all custom entries, and save it. The name of the file will be displayed in the Combine user interface. Then, in order to make use of the snippet in Combine, you must load it into Combine.


To create a custom code snippet, the following xml entries should be considered:
1. Title - not used in Combine 1.0, but will be used in future versions. It is recommended that the Title field will be identical to the snippet file name.
2. Shortcut, Description, Author - not used in Combine 1.0, but will be used in future versions.
3. Snippet Type - must be Expansion, as in the example below.
4. Literal - each Literal represents a snippet variable. Once the code snippet is opened in Combine, users can automatically replace the value of the variable throughout the snippet script using built-in Combine features.
5. ID (under Literal) - the name of the snippet variable as it appears in the script. When composing the snippet script, the variables must appear in the format $VariableName$. In the example below, one variable name is Database_Name, and the string $Database_Name$ is used to instantiate it in the script.
6. ToolTip - not used in Combine 1.0. This feature will be used in future versions, and the content of the ToolTip will be displayed whenever the user hovers over the snippet variable with the mouse.
7. Code - the SQL and T-SQL content of the code snippet should be placed under the Code xml element, after the CDATA (the CDATA clause is used to include text that will not be parsed as xml and will appear in Combine as entered).


Note: If the xml schema or content you entered is incorrect, either Combine will not load the snippet to the user interface properly, or the snippet will be loaded but will not behave as expected. To test your xml format, simply load the snippet into Combine and verify that it is added and can be used correctly.


<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
       <CodeSnippet Format="1.0.0">
             <Header>
                   <Title>Create Database (Basic)</Title>
                   <Shortcut>CrDBB</Shortcut>
                   <Description></Description>
                   <Author></Author>
                   <SnippetTypes>
                         <SnippetType>Expansion</SnippetType>
                   </SnippetTypes>
             </Header>
             <Snippet>
                   <Declarations>
                         <Literal>
                               <ID>Database_Name</ID>
                               <ToolTip>Name of the new database</ToolTip>
                               <Default>DatabaseName</Default>
                         </Literal>
                         <Literal>
                               <ID>Database_To_Use</ID>
                               <ToolTip>Database to use in the USE clause</ToolTip>
                               <Default>Master</Default>
                         </Literal>
                   </Declarations>
                   <Code Language="sql"><![CDATA[
/* =====================================================
Create Database (Basic) Template
======================================================= */

USE $Database_To_Use$
GO

-- Drop the database if it already exists IF EXISTS (
SELECT *
FROM sys.databases
WHERE [name] = N'$Database_Name$')

DROP DATABASE [$Database_Name$]
GO

CREATE DATABASE [$Database_Name$]
GO
]]>
                   </Code>
             </Snippet>
       </CodeSnippet>
</CodeSnippets>




© 2001-2017 JNetDirect, Inc. All Rights Reserved.