Symphony Framework
Symphony CollectionFromFile v3 2
Symphony Templates > Symphony CollectionFromFile v3 2
Template file name Symphony_CollectionFromFile_v3_2.tpl

The Symphony_CollectionFromFile (version 3.2) generates a collection class and the associated code to populate the collection from a data file.  The created class is a populated collection of Symphony.Conductor.Content.SelectionItem.  Each collection item contains a ItemValue (or ItemStringValue for alpha based collections) and Description.  The ItemValue/ItemStringValue property can be data-bound to the SelectedValuePath of a ComboBox/drop-down list.  The Description is the element displayed (DisplayMemeberPath for a WPF ComboBox) within the visible list.

It is recommended that your generated code from the Symphony_CollectionFromFile template is created into a project sub-folder called Content.
 CodeGen Template Tokens
Token Comments
NAMESPACE Specifies the namespace within which to create the class.
 Symphony Tokens
      

Symphony tokens are applied to fields in the repository in the Long Description.  They allow for additional field processing by CodeGen.  You must define both the token and value, enclosed within <> brackets.  For example <SYMPHONY_MAX_DISPLAY_LENGTH=100>

You can define any number of Symphony tokens in the long description.  There is no separation character required.

   
Token Comments

SELECTIONDESCRIPTION

Specify the field within the repository structure to assign to the Description property of the Symphony.Conductor.Content.SelectionItem instance.
SELECTIONFIELD Specify the field within the repository structure to assign to the ItemValue (or ItemStringValue for alpha fields) property of the Symphony.Conductor.Content.SelectionItem instance.
MODELNAMESPACE The namespace within your application that contains the structure specific FileIO class the generated code will use to read the records from the data file.
DATAIONAMESPACE The namespace within your application that contains the structure specific Data Object class the generated code will use while reading data from the data file.
RPSDATAFILES Optionally define the repository main and text files, comma separated.
TRIMFUNCTION Optionally define a trim function to trim the ItemStringValue before inserting the data into the collection.  If you are defining the CodeGen commands in a batch script file and using a Synergy function such as %atrim() and the trim function you must use %%atrim to ensure the correct code is generated.
If specifying the MODELNAMESPACE and DATAIONAMESPACE and they are the same, only specify one to prevent duplicate import statements in the generated code.
 CodeGen Command Examples
Create standard collection
codegen e -r -s GROUP -t Symphony_CollectionFromFile_v3_2 -o %ROOT%ControlLibrary\Content -n ControlLibrary.Content -ut SELECTIONFIELD=group_id SELECTIONDESCRIPTION=Description MODELNAMESPACE=ControlLibrary.Data TRIMFUNCTION=%atrim
 Example
;;****************************************************************************
;;
;; WARNING: This code was code generated. Any changes that you
;;          make to this code will be overwritten if the code is regenerated!
;;
;; Template author:    Richard C. Morris : RCP Consultants.
;;
;; Template Name:    Symphony Framework : SYMPHONY_COLLECTIONFROMFILE_V3_2.tpl
;;
;;****************************************************************************

import System
import System.Collections.Generic
import System.Text

import Symphony.Conductor.DataIO
import Symphony.Conductor.Content
import ControlLibrary.Data
import ControlLibrary.Data



namespace ControlLibrary.Content

    public class GROUP_Collection extends SelectionItemList

        public method GROUP_Collection
            endparams
        proc

            if (internalList == ^null)
                ControlLibrary.Content.GROUP_Collection.buildInternalList()

            data item    ,@SelectionItem

            foreach item in internalList
            begin
                this.add(item)
            end

        endmethod

        private static internalList    ,@SelectionItemList

        private static method buildInternalList    ,void
            endparams

        .include 'group' repository , record='group'

        proc
            data dObj    ,@Group_Data    ,new Group_Data()
            data dIO    ,@Group_FileIO

            internalList = new SelectionItemList()

            try
            begin
                dIO = new Group_FileIO()
                data result    ,FileAccessResults
                result = dIO.ReadFirstRecord(dObj)
                while (result == FileAccessResults.Success)
                begin
                    Group = dObj.SynergyRecord
                    internalList.Add(new SelectionItem((string)Group.Description, %atrim(Group.group_id)))
                    result = dIO.ReadNextRecord(dObj)
                end
            end
            catch (e, @Exception)
            begin
                internalList.Add(new SelectionItem("<No items to display>"))
            end
            endtry
        endmethod
        
    endclass
endnamespace


See Also

Reference