Sujeewa Ediriweera

SPAC

SharePoint Auto Coder  v1.0 Beta (SPAC)
SPAC C# Template Design Hand Book

By Sujeewa Ediriweera
Email :Sujeewa.ediriwera@gmail.com
Twitter:Isujeewa
LinkedIn:sujeewa.ediriweera

 

MS World version :SPAC Template Design Hand Book

Over view
SPAC is a code generation tool which developers can easily generate custom code to be used in custom SharePoint development projects. SPAC can generate code for a given language of choice based on a predefined code template. Developers can choose to define the code template and then with few clicks SPAC will generate the code based on the defined template.

This document describes all key words and examples how to use SPAC 2010 v1.0 beta templates.

Key Word Description 1.0
//SPAC all rights received This text should pasted at the very first line of the template. Otherwise code generation engine will ignore the template. Yes
<%ListName%> List name of the current SPAC context. This will return the physical list name without spaces in-between two words.Eg://SPAC all rights received.>>Foreach <%lists%>>>{

<%ListName%>

>>}

Over view:

SharePoint current context has only one list Named Company Details

SPAC Code :

Note: This key word only identify inside Foreach <%lists%> loop

Eg:

//SPAC all rights received.

>>Foreach <%lists%>

>>{

//Type Represents <%ListName%> entity

Public class <%ListName%>

{

}

>>}

Output:

Public class ComapnyDetails

{

}

Yes
<%listName%> List name of the current SPAC context. This will return the physical list name without spaces in-between two words and first latter lower caseEg://SPAC all rights received.>>Foreach <%lists%>>>{

<%listName%>

>>}

Overview:

SharePoint current context has only one list Named Company Details

SPAC Code :

Note: This key word only identify inside Foreach <%lists%> loop

Eg:

//SPAC all rights received.

>>Foreach <%lists%>

>>{

//Type Represents <%ListName%> entity service

public class <%ListName%>Service

{

public void Save(<%ListName%> <%listName%>)

{

}

}

>>}

Output:

Public class ComapnyDetailService

{

Public void Save (ComapnyDetailService comapnyDetailService )

{

}

}

Yes
<%ListTitle%> List title of the current SPAC context. This will return the list title name as it is.Note: this key word identifies only inside >>Foreach <%lists%> blockEg://SPAC all rights received.>>Foreach <%lists%>

>>{

<%ListTitle%>

>>}

Overview

SharePoint environment current context contains lists

Company Details

Employee

Department

SPAC Code :

//SPAC all rights received.

>>Foreach <%lists%>

>>{

<%ListTitle%>

>>}

Output :

Company Details

Employee

Department

<%ListGuid%> List Guid of the current SPAC context.Note: this key word identifies only inside >>Foreach <%lists%> block Y
<%FieldName%> Field name of the current SPAC context. This will return the physical field name without spaces in-between two words.Note: This key word only identify inside >>Foreach <%fields%> loopEg ://SPAC all rights received.>>Foreach <%lists%>

>>{

>>Foreach <%fields%>

>>{

<%FieldName%>

>>}

>>}

Overview  :

SharePoint current context has only one list Named Company Details. This list has three fields Company Name data type text, Start Date data type DateTime,Active data type Boolean

SPAC Code :

//SPAC all rights received.

>>Foreach <%lists%>

>>{

//Type Represents <%ListName%> entity

Public class <%ListName%>

{

>>Foreach <%fields%>

>>{

//<%FieldName%> property

public <%DataType%>  <%FieldName%> {get;set;}

>>}

}

>>}

Out put

//Type Represents ComapnyDetail entity

Public class ComapnyDetail

{

// CompanyName property

public string CompanyName {get;set;}

// StartDate property

public DateTime StartDate {get;set;}

// Active property
public bool Active {get;set;}

}

Y
<%InternalFieldName%> Internal Field name of the current SPAC context. This will return the physicalEg://SPAC all rights received.>>Foreach <%lists%>>>{

>>Foreach <%fields%>

>>{

<%InternalFieldName%>

>>}

>>}

Over view  :

SharePoint current context has only one list Named Company Details. This list has three fields Company Name, Start Date data,Active

SPAC Code :

//SPAC all rights received.

>>Foreach <%lists%>

>>{

//Type Represents <%ListName%>Fields

Public static class <%ListName%>Fields

{

>>Foreach <%fields%>

>>{

public string <%FieldName%> =”<%InternalFieldName%>” ;

>>}

}

>>}

Output :

//Type Represents ComapnyDetailFields

public static class ComapnyDetailFields

{

public string CompanyName =”Company_x0020_Name”;

public string StartDate=”Start_x0020_Date”;

public string Active=”Active”;

}

Yes
<%fieldName%> Field name of the current SPAC context. This will return the physical field name without spaces in-between two words and first letter lower case.Note: This key word only identify inside >>Foreach <%fields%> loopEg://SPAC all rights received.>>Foreach <%lists%>

>>{

>>Foreach <%fields%>

>>{

<%fieldName%>

>>}

>>}

Overview  :

SharePoint current context has only one list Named Company Details. This list has three fields Company Name data type text, Start Date data type DateTime,Active data type Boolean

SPAC Code :

//SPAC all rights received.

>>Foreach <%lists%>

>>{

//Type Represents <%ListName%> entity

Public class <%ListName%>

{

>>Foreach <%fields%>

>>{

//<%FieldName%> property

public <%DataType%>  _<%fieldName%> ;

>>}

}

>>}

Output :

//Type Represents ComapnyDetail entity

Public class ComapnyDetail

{

// CompanyName property

public string _companyName ;

// StartDate property

public DateTime _startDate ;

// Active property
public bool _active ;

}

Yes
<%RequiredField%> Determine whether the current field is required field or not.Note: This key word only identify inside >>Foreach <%fields%> loopEg://SPAC all rights received.>>Foreach <%lists%>

>>{

>>Foreach <%fields%>

>>{

<%RequiredField%>

>>}

>>}

Overview  :

SharePoint current context has one list Named Company Details. This list has three fields Company Name data type text required, Start Date data type DateTime required, Active data type Boolean optional

Code

//SPAC all rights received.

>>Foreach <%lists%>

>>{

>>Foreach <%fields%>

>>{

>>if(<%RequiredField%>==True)

>>{

<%FieldName%> is required field.

>>}

>>Else

>>{

<%FieldName%> not a is required field.

>>}

>>}

>>}

Output :

Company Name is required field.

Start Date is required field.

Active is not a required field.

Yes
<%FieldLookupListGuid%> Return the lookup list GUID for lookup field.
Note: This key word only identify inside >>Foreach <%fields%> loop//SPAC all rights received.>>Foreach <%lists%>>>{>>Foreach <%fields%>

>>{

<%FieldLookupListGuid%>

>>}

>>}

Overview  :

SharePoint current context has Employee and Department lists. Employee list has lookup to Department.

Code :

//SPAC all rights received.

>>Foreach <%lists%>

>>{

>>Foreach <%fields%>

>>{

>>if(<%SPFieldType%>==Lookup)

>>{

<%listName%> list’s  <%FieldName%> field is lookup to <%FieldLookupListGuid%> list.

>>}

>>Else

>>{

>>}

>>}

>>}

Output :

Employee list’s Department field is lookup to {abcd-ad34d-ddda-adeg33} list

Yes
<%FieldTitle%> Field title of the current SPAC context. This will return the field  title as it is.//SPAC all rights received.>>Foreach <%lists%>>>{>>Foreach <%fields%>

>>{

<%FieldTitle%>

>>}

>>}

Overview :

SharePoint current context has only one list Named Company Details. This list has three fields Company Name, Start Date data, Active

SPAC Code :

//SPAC all rights received.

>>Foreach <%lists%>

>>{

//Type Represents <%ListName%>Field Titles

Public static class <%ListName%>FieldNames

{

>>Foreach <%fields%>

>>{

public string <%FieldName%> =”<%FieldTitle%>” ;

>>}

}

>>}

Output :

//Type Represents ComapnyDetailFields

public static class ComapnyDetailFieldNames

{

public string CompanyName =”Company Name”;

public string StartDate=”Start Date”;

public string Active=”Active”;

}

Yes
>>Foreach For each look identifier .Used to iterate through lists and list fields//SPAC all rights received.>>Foreach <%lists%>>>{>>}

>>Foreach <%fields%>

>>{

>>}

Eg:

Overview :

SharePoint environment current context contains lists

Company Details

Employee

Department

Code :

//SPAC all rights received

>>Foreach <%lists%>

>>{

//SharePoint list <%ListName%>

>>}

Output :

//SharePoint list CompanyDetail

//SharePoint list Employee

//SharePoint list Department

Yes
== Used in >>if for string compression. This will check for  left hand side argument equal with the right hand side of the argument in the if conditionEg://SPAC all rights received.>>if(xxx==xxx)>>{

>>}

>>Else

>>{

>>}

!= Used in >>if for string compression. This will check for  left hand side argument not equal with the right hand side of the argument in the if conditionEg://SPAC all rights received.>>if(xxx!=xxx)>>{

>>}

>>Else

>>{

>>}

>>if If condition identifier .This version has only ‘==’  and ‘!=’ string  comparison. If condition needs else block.Note: If condition should be used under >>Foreach loop and at any given time If block and Else block should be there. Cannot use if condition without having else block in SPAC version 1.0If condition inside if condition supports in SPAC version 1.0//SPAC all rights received.>>if(xxx==xxx)

>>{

>>}

>>Else

>>{

>>}

>>if(xxx!=xxx)

>>{

>>}

>>Else

>>{

>>}

Eg:

Overview :

SharePoint environment current context contains lists

Company Details

Employee

Department

SPAC Code

//SPAC all rights received.

>>Foreach <%lists%>

>>{

>>if(<%ListName%>==Employee)

>>{

//SharePoint list <%ListName%> found

>>}

>>Else

>>{

>>}

>>}

Output :

//SharePoint list Employee found

Yes
>>{ Code block’s start identifier. Used to identify For each loop start position and IF condition start position Yes
>>} Code block’s end identifier. Used to identify For each loop end position and IF condition end position Yes
<%lists%> Used to identify lists in current context .This key word used along with >>Foreach loop.Eg ://SPAC all rights received.>>Foreach <%lists%>>>{

>>}

Over view :

SharePoint environment current context contains lists

Company Details

Employee

Department

Code :

//SPAC all rights received.

>>Foreach <%lists%>

>>{

//SharePoint list <%ListName%>

>>}

Output :

//SharePoint list Company Detail

//SharePoint list Employee

//SharePoint list Department

Yes
<%fields%> Used to identify list fields in current context.This key word used along with >>Foreach loop.Note : >>Foreach <%fields%> should be used under >>Foreach <%lists%>//SPAC all rights received.Eg :>>Foreach <%lists%>

>>{

//your code

>>Foreach <%fields%>

>>{

//your code

>>}

>>}

Overview  :

SharePoint current context has only one list Named Company Details. This list has three fields Company Name data type text, Start Date data type DateTime,Active data type Boolean

SPAC Code :

//SPAC all rights received.

>>Foreach <%lists%>

>>{

//Type Represents <%ListName%> entity

Public class <%ListName%>

{

>>Foreach <%fields%>

>>{

//<%FieldName%> property

public <%DataType%>  _<%fieldName%> ;

>>}

}

>>}

Output :

//Type Represents ComapnyDetail entity

Public class ComapnyDetail

{

// CompanyName property

public string _companyName ;

// StartDate property

public DateTime _startDate ;

// Active property
public bool _active ;

}

Yes
<%ConvertTo%> Returns relevant covert data type to current field .This supports basic data types. Yes
<<{ IO operation code block’s start identifier. Used in <<Save Yes
<<} IO operation code block’s end identifier. Used in <<Save Yes
<<Save When every user need to save generated code as physical file user need to wrap the code with <<Save blockEg://SPAC all rights received.<<Save(xxx.cs)<<{

//Any thing inside this code block will save as text inside xxx.cs file

<<}

Overview :

SharePoint environment current context contains lists

Company Details

Employee

Department

Code :

//SPAC all rights received.

>>Foreach <%lists%>

>>{

<<Save(<%ListName%>.cs)

<<{

//Type Represents <%ListName%> entity

Public class <%ListName%>

{

>>Foreach <%fields%>

>>{

//<%FieldName%> property

public <%DataType%>  <%FieldName%> {get;set;}

>>}

}

<<}

>>}

Out put

Following physical files will be crated under destination folder

CompanyDetails.cs

Employee.cs

Department.cs

Yes
Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: