Quick Start

1. Install CIPl

2. Create a command line app in Visual Studio called CIPlQuickStart

3. Add CIP4.Core.dll and CIP4.Simple.dll to the project's references section

4. Replace the content of the Program.cs with the following text:

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CIP4.Common;
using CIP4.Item;
using CIP4.Simple;


namespace CIPlQuickStart
{
    class Program
    {
        static void Main(string[] args)
        {
            PersonType p = new PersonType
            {
                Name = "foo",
                Address = new AddressType
                {
                    Street = " bar 1",
                    City = "Gonzoville",
                    Zip = 12345
                }
            };

            Directory.CreateDirectory("c:\\temp\\PeopleData");

            PersonType.Wrapper.SaveItems(new List<PersonType> { p });

            PersonType pp = PersonType.Wrapper.GetViaExternalID(new ExternalIDType("foo"));

            Console.WriteLine(PersonType.Wrapper.GetXmlForObject(pp));

        }
    }

    [CIP4Item(AddAllProperties=true, Collection="People"),
        CIP4FileConnection(BaseDirectoryPath = "c:\\temp\\PeopleData")]
    public class PersonType
    {
        public static StrongWrapper<PersonType> Wrapper = new StrongWrapper<PersonType>(Globals.DefaultLogger);
        [CIP4ExternalID]
        public string Name { get; set; }
        public AddressType Address { get; set; }
    }

    [CIP4Item(AddAllProperties = true)]
    public class AddressType
    {
        public string Street { get; set; }
        public string City { get; set; }
        public int Zip { get; set; }
    }
}
    
        

When you run the app you should see something like the following:

17:50:44 Trace.InitializingProvider - Initalizing Provider: BaseDirectoryPath=c:\temp\PeopleData
17:50:44 Trace.LoadedProvider - Loaded provider BaseDirectoryPath=c:\temp\PeopleData
17:50:44 Warning.SpontaneousSerializer - Serializer for C:\Users\patrick.thompson\Documents\Visual Studio 2008\Projects\CIPlQuickStart\CIPlQuickStart\bin\Debug\
CIPlQuickStart.exe seems to be out of date - attempting to build a new one - watch for fireworks
17:50:44 Trace.Generic - Serializer generated for PersonType, AddressType
>>>>>>>>>>>>> tedious details omitted <<<<<<<<<<<<<<<<<<
17:50:44 Trace.Generic - Finished compiling \CIPlQuickStart\bin\Debug\CIPlQuickStart_CIP4XmlSerializer.dll
17:50:44 Trace.ActionStart - Started SaveItems
17:50:44 Trace.ItemsUpdated - Items foo updated
17:50:44 Information.SaveItems - 1 items saved in People
17:50:44 Trace.ActionStart - Started GetItems
17:50:44 Information.GetItems - Get 1 items from People
<Item xmlns="http://channelintelligence.com/CIPlItem1.xsd"><Valid>1</Valid>
<ItemStatus>100</ItemStatus><ExternalID>foo</ExternalID><ModifiedDate>2010-10-03T17:50:44.8251919-07:00</ModifiedDate>
<PersonType xmlns="http://channelintelligence.com/CIPlOther1.xsd">
<Address><AddressType><City><String>Gonzoville</String></City>
<Street><String> bar 1</String></Street><Zip><Int32>12345</Int32></Zip></AddressType></Address>
<Name><String>foo</String></Name></PersonType></Item>

When you run the app for the first time, CIP4 will generate the serializer needed by the app - hence the compile, the text provided from "Trace.ActionStart - Started SaveItems" onwards reflects the normal operation of the program.

Quck Start Exensions

Delete any existing people when the application first runs

PersonType.Wrapper.DeleteCollection();

Add a List of alternate Addresses to PersonType - for example

public List<AddressType> AlternateAddresses { get; set; }

Make AddressType a supertype of USAddress and EUAddress, where the former has zip and the latter has PostCode.

Store the People collection in another type of data store. For example:

[CIP4Item(AddAllProperties=true, Collection="People"), CIP4DictionaryConnection(BaseDirectoryPath = "c:\\temp\\PeopleData")] public class PersonType

Limit the number of status messages returned and throw an exception on an error:

 

            PersonType.Wrapper.Logger = delegate(MajorEnum status, MinorEnum minorStatus, string message, object[] paras)
            {
                if (status == MajorEnum.Error)
                    throw new ApplicationException(string.Format("{0}: {1}", minorStatus, string.Format(message, paras)));
                if (status == MajorEnum.Information && minorStatus != MinorEnum.GetItems)
                    Console.WriteLine(string.Format("\n{0}: {1}", minorStatus, string.Format(message, paras)));
                return LoggerResponseEnum.keepGoing;
            };


 

You can run the CIP4.Installer to establish new types of data store such as MongoDB, Cassandra, various flavors of Sql or cloud stores such as Mosso or S3. The CIP4Installer will guide you through the parameters requried for each of the DataProvider types and will providfe the parameters you need for the CIP4XXXConnectionAttribute object.

Note that in practice, you will usually provide connection information as a part of the execution of the application, not hardwired in a class declaration. CIP4 provides several mechanisms for doing this that are described in the section on Connection Handling.

The MiniSessionDemo.zip file contains a slightly more elaborate version of this program.

Last edited Oct 27, 2010 at 8:55 PM by PatrickThompson, version 15

Comments

No comments yet.