about us      downloads      documentation      contact      home 
 products
 antHR
 workflow studio
 technical toolkits
 content entry
 workflow
 security
 hierarchy
 concepts
 how tos
 reference
 FAQs
previous: Test class  next: Add validation

How to: Create new converter - Test application

  Step 1 : Summary
  Step 2 : Define converter
  Step 3 : Test class
  Step 4 : Test application
  Step 5 : Add validation
  Step 6 : Add config
  Step 7 : Test config

Make an application to test the converter - (page 4 of 7)

Level: developer
Required reading: Defining content, Class markup

Using the same application that we wrote in class markup, we will now add in the code to test the new converter.

using System;
using System.Xml;
using System.Windows.Forms;
using Microsoft.Win32;
using Ant.Security;
using Ant.Security.Windows;
using Ant.Shared;
using Ant.Database;
using Ant.ContentEntry;
using Ant.ContentEntry.Windows;
using Ant.ContentEntry.Persistence;
using Ant.Licensing;
namespace HowTos
{
    /// <summary>
    /// Class which is run to start the application, edit the class and trace the results
    /// </summary>
    public class MainClass
    {
        static Logon logon;
        static public int Main(string[] args)
        {
            ConfigurationKey key = new RegistryConfigurationKey(Registry.LocalMachine.OpenSubKey("Software\\Ant"));
            LicensingManager.Init(key);
            SecurityManager.Init(key);
            if (SecurityManager.Get().HasRemoteConfiguration())
            {
                logon = ShowLogon();
                if (logon == null)
                    return 1;
                key = logon.GetRemoteConfigurationKey();
            }
            Ant.Database.DatabaseManager.Init(key);
            Ant.ContentEntry.ContentEntryManager.Init(key);
            if (!SecurityManager.Get().HasRemoteConfiguration())
            {
                logon = ShowLogon();
                if (logon == null)
                    return 1;
            }
            EditCheckConverter();
            return 0;
        }
        static void EditCheckConverter()
        {
            // Gets the content definition for our class, using user
            ContentDefinition def = new ContentDefinitionFactory(logon.AuthenticatedUser, "ENGLISH", 0).ForClass(typeof(CheckConverter));
            // Construct a version of our class to edit
            CheckConverter checkConverter = new CheckConverter();
            // Construct a form off this object
            ContentEntryWindowsForm form = new ContentEntryWindowsForm("Test", def, XmlHelper.GetInstanceFromObject(def, checkConverter));
            // Show the form and check the OK button was checked
            if (form.ShowDialog() == DialogResult.OK)
            {
                // Map the values back in to the object
                checkConverter = XmlHelper.GetObjectFromInstance(def, form.InstanceData) as CheckConverter;
                
                //Trace out the results
                System.Diagnostics.Trace.WriteLine("Value: "+checkConverter.Val);    
            }
        }
        static void EditTelevisionProgramme()
        {
            // Gets the content definition for our class, using default (null) user
            ContentDefinition def = new ContentDefinitionFactory(logon.AuthenticatedUser, "ENGLISH", 0).ForClass(typeof(TelevisionProgramme));
            // Construct a version of our class to edit
            TelevisionProgramme programme = new TelevisionProgramme();
            // Construct a form off this object
            ContentEntryWindowsForm form = new ContentEntryWindowsForm("Test", def, XmlHelper.GetInstanceFromObject(def, programme));
            // Show the form and check the OK button was checked
            if (form.ShowDialog() == DialogResult.OK)
            {
                // Map the values back in to the object
                programme = XmlHelper.GetObjectFromInstance(def, form.InstanceData) as TelevisionProgramme;
                
                XmlPersistenceDatabase db = new XmlPersistenceDatabase(DatabaseManager.Get().GetDatabase("Main"));
                object databaseKey = db.PutNewInstanceIntoStorage(def, form.InstanceData);
                //Trace out the results
                System.Diagnostics.Trace.WriteLine("Programme name:"+programme.ProgrammeName);    
                System.Diagnostics.Trace.WriteLine("Channel:"+programme.Channel.ToString());    
                System.Diagnostics.Trace.WriteLine("Date:"+programme.Start.ToString("dd-MM-yyyy HH:mm"));    
                System.Diagnostics.Trace.WriteLine("Duration:"+programme.Duration.ToString());    
            }
        }
        static private Logon ShowLogon()
        {
            Logon logon = new Logon();
            DialogResult res;
            try
            {
                res = logon.ShowDialog();
            }
            catch (SecurityException)
            {
                MessageBox.Show("The supplied logon credentials did not match the user database.", "Logon failed");
                return null;
            }
            if (res != DialogResult.OK)
                return null;
            return logon;
        }

    }
}
        
When we run the application we see that the edit form displayed contains a single field which allows any integer to be entered, but does not allow blanks or none integers.


 

Did you find this article helpful? Comments on this page are welcome and can only help us improve the quality of our documentation.
© Ant Organisation Ltd, 2003