Getting Started with the Preactor Object Model

There are a few basic steps required to get the library running in your project. Details that follow will help guide you through the process.

  1. Add NuGet Preactor.ObjectModel library to your project
  2. Add a using reference to the Preactor.ObjectModel library in your project
  3. Create a static PreactorObjectModel property in your CustomActions class.
  4. Instantiate the PreactorObjectModel property
  5. Load the PreactorObjectModel at the start of every COM method
  6. Familiarisation and Extension of Operations and other Object classes

Please download the sample project on the download page for an example on how to setup the PreactorObjectModel.

Add NuGet Preactor.ObjectModel library to your project

You will have to have NuGet installed on your machine. In the event it is not, you can download it from NuGet.Org

  1. Right click on the References under the project
  2. Select Manage NuGet Packages from the menu
  3. Enter Preactor in the Search options
  4. Install both the Preactor.ObjectModel and Preactor.ObjectModelExtension, then close the window

Add a using reference to the Preactor.ObjectModel library in your project

Above the namespace of the class add the using reference to the Preactor.ObjectModel and Preactor.ObjectModelExtensions.

using Preactor.ObjectModel;
using Preactor.ObjectModelExtensions;

Create a Class Global PreactorObjectModel Variable

Create a PreactorObjectModel static variable in the CustomActions class. This property will need to be set at each entry point into the code, in order for the object to take a fresh copy of the planning board.

public static PreactorObjectModel Pom { get; set; }

Instantiate the PreactorObjectModel Variable

A static class constructor is required to instantiate the PreactorObjectModel object in the CustomActions class.

static CustomActions() {
    Pom = new PreactorObjectModel();
}

Load the PreactorObjectModel

At the start of each entry point call the LoadPreactorObject() method in order for POM to load a fresh copy of the planning board data.

public int MyCustomAction(ref PreactorObj preactorComObject, ref Core pespComObject)
{
    Pom.LoadPreactorObject(PreactorObj)

    //remaining actions
}

Familiarisation and Extension of Operations and other Object classes

When instantiating the PreactorObjectModel the assumption was made that some pre-defined classifications would be present in the Prtdf file. Please see the associated class files for the mappings of PreactorFields to classifications. This will also allow for familiarisation with the default properties for each class.

For example:

[PreactorField("MATERIAL CONTROL ORDER NO", FieldDeclarationType.FieldClassification)]        public string OrderNumber {
    get { return (string)GetValue("OrderNumber"); }
    set { SetValue("OrderNumber", value); }
 }

In most cases you will want to extend the Operation class with your project specific properties. (or even extend other classes, such as the Products, Secondary Constraints, Resources etc... )

This is easily done using inheritance.

  • Create a new public sealed partial class that inherits the base type; in this case Operation
    public sealed partial class Operation : Preactor.ObjectModel.BaseTypes.Operation
  • Adding a property. There are two ways to add a property, depending on whether you want to associated the property with a prdtf field or not.
  • Prtdf Field – You can associated a property with a TDF field using the code below. The FieldDeclartionType can either be "Classification"  or "FieldName", which as the naming suggests specifies whether to use a classification to identify a given field or the name.
    [PreactorField("preactorField", FieldDeclarationType.FieldName)]
     public string propertyName {
        get {return (string)GetValue("propertyName"); }
        set { SetValue("propertyName", value); }
     } 
  • Non Prtdf Field - You can add standard properties to your class as usual. 
    public string myPropertyName { get; set; }
  • This new extended class now needs to be registered with POM against its associated interface.
    static CustomActions() {
        Pom = new PreactorObjectModel();
        Pom.Register<IOperation, Operation>();
    }

Please note that in order to use the "Product" class you have to explicitly specify the associated Format name:

static CustomActions() {
    Pom = new PreactorObjectModel();
    Pom.Register<IOperation, Operation>();
    Pom.Register<IProduct, Product>("Products");
}

General Notes

The most commonly used method in the PreactorObjectModel object is GetAllRecords<T>(). This method will return an IEnumerable<T> where T is the interface we are interested in (i.e. IOperation, IProduct etc..).

If you want to access all the properties of an extended type you will have to cast the returned Interface to the correct type:

Pom.GetAllRecords<IOperation>().Cast<Operation>();

It is suggested that an extension method be created within the project, due to the frequency of this call. This would be done as follows:

public static IEnumerable<Operation> GetAllOperations(this PreactorObjectModel pom)
{
    return Pom.GetAllRecords<IOperation>().Cast<Operation>().ToList();
}

And can be used as shown below:

var allOperations = Pom.GetAllOperations();

Another commonly used method is the GetOperation(recordNumber) and GetOperation(PrimaryKey), these would also benefit from an extension in the event that the Operation call has been extended, such as:

public static Operation GetOperation(this PreactorObjectModel pom, int recordNumber)
{
    return Pom.GetRecord<IOperation>(recordNumber) as Operation;
}

public static Operation GetOperation(this PreactorObjectModel pom, PrimaryKey pk)
{
    return Pom.GetRecord<IOperation>(pk) as Operation;
}

Last edited Sep 11, 2012 at 6:37 AM by bvsms, version 22

Comments

No comments yet.