//------------------------------------------------------------------------------
// Copyright (C) 2008 Invensys Systems Inc.  All rights reserved.
// 
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//------------------------------------------------------------------------------

using System;
using System.Runtime.InteropServices;
using System.Collections;
using ArchestrA.Core;
using ArchestrA.Toolkit;

namespace ArchestrA.Toolkit.Monitor
{
    [Guid("dbed4eb2-a279-4660-9497-448092f54047")]
    /// <summary>
    /// Summary description for MonitorConfigtime
    /// </summary>
    public class MonitorConfigtime : ConfigtimeBase
    {
        #region Attributes - Toolkit generated code
        // The following C# properties have been defined to simplify access to
        // attribute values - do not modify the contents of this region with
        // the code editor.
        private CMxFloat PVHiLimit
        {
            get { return InternalReferenceOnly.PVHiLimit; }
            set { InternalReferenceOnly.PVHiLimit.Set(value); }
        }



        public __PVInputOutput PVInputOutput = null;

        public class __PVInputOutput
        {
            public SupportWrapper Wrapper = new SupportWrapper();

            private CMxReference _ReferenceSecondary = null;

            public CMxReference ReferenceSecondary
            {
                get { if (_ReferenceSecondary == null) { _ReferenceSecondary = new CMxReference(Wrapper, "PVInputOutput.ReferenceSecondary"); } return _ReferenceSecondary; }
                set { if (_ReferenceSecondary == null) { _ReferenceSecondary = new CMxReference(Wrapper, "PVInputOutput.ReferenceSecondary"); } _ReferenceSecondary.Set(value); }
            }

            private CMxReference _Reference = null;

            public CMxReference Reference
            {
                get { if (_Reference == null) { _Reference = new CMxReference(Wrapper, "PVInputOutput.Reference"); } return _Reference; }
                set { if (_Reference == null) { _Reference = new CMxReference(Wrapper, "PVInputOutput.Reference"); } _Reference.Set(value); }
            }

            private CMxBoolean _SeparateFeedbackConfigured = null;

            public CMxBoolean SeparateFeedbackConfigured
            {
                get { if (_SeparateFeedbackConfigured == null) { _SeparateFeedbackConfigured = new CMxBoolean(Wrapper, "PVInputOutput.SeparateFeedbackConfigured"); } return _SeparateFeedbackConfigured; }
                set { if (_SeparateFeedbackConfigured == null) { _SeparateFeedbackConfigured = new CMxBoolean(Wrapper, "PVInputOutput.SeparateFeedbackConfigured"); } _SeparateFeedbackConfigured.Set(value); }
            }

            private CMxDataType _DataType = null;

            public CMxDataType DataType
            {
                get { if (_DataType == null) { _DataType = new CMxDataType(Wrapper, "PVInputOutput.DataType"); } return _DataType; }
                set { if (_DataType == null) { _DataType = new CMxDataType(Wrapper, "PVInputOutput.DataType"); } _DataType.Set(value); }
            }

            public __PVInputOutput(AObjectBase baseClass)
            {
                Wrapper.baseClass = baseClass;
            }

        }

        #endregion Attributes

        #region Internal Reference Only
        //Toolkit code required to access the attributes declared in the Object Class
        private Monitor InternalReferenceOnly = null;
        #endregion Internal Reference Only

        #region Declarations
        //Declare Configtime Class Variables here.
        //Variables declared in this region are available to all methods 
        //in the Configtime Class.


        #endregion Declarations


        public MonitorConfigtime()
        {
            InternalReferenceOnly = new Monitor();
            this.AObjectInstance = InternalReferenceOnly;

            #region Configuration Event Registration - Toolkit generated code
            // Required region for Configuration Events - do not modify 
            // the contents of this region with the code editor.
            this.ConfigtimeInitialize += new ConfigtimeInitializeDelegate(MonitorConfigtime_ConfigtimeInitialize);
            this.ConfigtimeValidate += new ConfigtimeValidateDelegate(MonitorConfigtime_ConfigtimeValidate);
            this.ConfigtimeMigrate += new MigrateDelegate(MonitorConfigtime_ConfigtimeMigrate);
            this.ConfigtimeDynamic += new ConfigtimeDynamicSetHandlerDelegate(MonitorConfigtime_ConfigtimeDynamic);
            this.PreValidate += new ObjectEventDelegate(MonitorConfigtime_PreValidate);
            this.PostCreate += new ObjectEventDelegate(MonitorConfigtime_PostCreate);
            #endregion Configuration Event Registration

            #region Optional Configuration Event Registration - Toolkit generated code
            // Required region for Configuration Events - do not modify 
            // the contents of this region with the code editor.
            // Optional events are enabled by the ObjectAttributes.Events 
            // attribute in the Object class.
            #endregion Optional Configuration Event Registration

            #region Configtime Set Handler Registration – Toolkit generated code
            // Required method for Configtime SetHandlers.  
            // Changes made using the code editor will appear in the Toolkit Editor.
            // 
            // WARNING: Changes made to this region will result in a Shape Change.


            //	TODO: Configtime SetHandler registration
            this.RegisterConfigtimeSetHandler("PVHiLimit", new ConfigtimeSetHandlerDelegate(PVHiLimitSetHandler));
            #endregion Configtime Set Handler Registration

            #region Primitive Wrapper Initialization - Toolkit generated code
            PVInputOutput = new __PVInputOutput(this);
            #endregion Primitive Wrapper Initialization

        }

        private void MonitorConfigtime_ConfigtimeInitialize(object sender)
        {
            //------------------------------------------------------------------------------
            //	TODO: Configtime Event - Initialize
            //
            //  Any custom initialization can be done here, including caching of attribute  
            //  values, primitive IDs etc.
            //------------------------------------------------------------------------------
        }

        private void MonitorConfigtime_ConfigtimeMigrate(object sender, ref MigrateHandler migrate)
        {
            //------------------------------------------------------------------------------
            //	TODO: Configtime Event - Migrate
            //
            //  Migrate executes when importing a template into a Galaxy that contains 
            //  a previous version (major) of the template. The template must be derived or
            //  instantiated for migrate to execute.
            //
            //  Migrate provides access to the previous versions attribute information. 
            //  A typical application for migrate code is to preserve attribute values 
            //  when an attribute name has changed (refer to the Example code below).  
            //  
            //  To enable this event the migrate option must be configured via the Toolkit
            //  Editor or in code (i.e. [ObjectAttributes.AMigrate("1","2")]).
            //
            //  If no implementation is provided, the system will copy all attribute values 
            //  from the old object to the new one by matching the attribute names.
            //------------------------------------------------------------------------------

            #region Example code
            //      //Check major version of previous template
            //      if (migrate.MajorVersion() == 1)
            //      {
            //          //Attribute "Eg_001" has been renamed to "Example_001". 
            //          //Transfer attribute value, lock and security classification
            //          Example_001 = migrate.GetValue("Eg_001");               //Gets value
            //          Example_001.Locked = migrate.GetLocked("Eg_001");       //Gets lock status
            //          Example_001.Security = migrate.GetSecurity("Eg_001");   //Gets Security Classification
            //
            //          //Transfer primitive values
            //          SetValue("Example_001.TrendHi", migrate.GetValue("Eg_001.TrendHi"));
            //          SetValue("Example_001.TrendHi", EATTRIBUTEPROPERTY.idxAttribPropLocked, migrate.GetLocked("Eg_001.TrendHi"));   
            //
            //          //Automatically migrate all child primitives
            //          migrate.AutoMigrateChildPrimitives = true;
            //      }

            #endregion
        }

        private void MonitorConfigtime_ConfigtimeValidate(object sender, ref EPACKAGESTATUS status)
        {
            //------------------------------------------------------------------------------
            //	TODO: Configtime Event - Validate
            //
            //  Validate sets the warning or error text for the object.
            //  It is used to check conditions that would not be checked using
            //	a SetHandler, such as reporting that an object was not
            //  configured, or that combinations of attributes are illegal.
            //      
            //	Other than calling AddWarningMessage or AddErrorMessage, Validate
            //	should never modify the state of the object.
            //------------------------------------------------------------------------------

            #region Example code
            //      if (MyTestDefaultState)
            //      {
            //          //Add a warning message using the dictionay phrase ID "ObjectStillInDefaultState"
            //          AddWarningMessage(GetText("ObjectStillInDefaultState"));
            //          
            //          //Change the status to Warning if the current status is Good
            //          if (status == EPACKAGESTATUS.ePackageGood)
            //          {
            //              status = EPACKAGESTATUS.ePackageWarning;
            //          }
            //      }
            //
            //      if (MyTestAttributeCombinationValid)
            //      {
            //          //Add a warning message using the dictionay phrase ID "AttributeCombinationInvalid"
            //          AddWarningMessage(GetText("AttributeCombinationInvalid"));
            //          
            //          // Change the status to Warning if the current status is Good
            //          if (status == EPACKAGESTATUS.ePackageGood)
            //          {
            //              status = EPACKAGESTATUS.ePackageWarning;
            //          }
            //      }
            #endregion

            //  By default set the object status to Good
            status = EPACKAGESTATUS.ePackageGood;


            //  The following statement will exit validate when validating templates.
            //  Place code that should be validated in templates and instances before this 
            //  statement. Code placed after this statement will execute in instances only.
            if (IsTemplate)
            {
                return;
            }
        }

        private void MonitorConfigtime_ConfigtimeDynamic(object sender, ref ConfigtimeSetHandlerEventArgs e)
        {

            string attrName = Get(e.attributeHandle.shAttributeId, e.attributeHandle.shPrimitiveId, EATTRIBUTEPROPERTY.idxAttribPropName);

            //------------------------------------------------------------------------------
            //	TODO: Configtime Event - Dynamic Set Handler
            //
            //  Implement set handler code for any dynamic attributes you create with set handlers  
            //------------------------------------------------------------------------------

            #region Example
            // if (attrName == "MyDynamic")
            // {
            //     if (e.Value > 10)
            //     {
            //         LogWarning(string.Format("value for {0} must be less or equal to 10", attrName));
            //     }
            //     else
            //     {
            //         SetValue(attrName, e.Value);
            //     }
            //
            //    
            //     return;
            // }   
            #endregion

            // if unhandled a warning is shown as a reminder
            SetValue(e.attributeHandle.shAttributeId, e.attributeHandle.shPrimitiveId, e.Value);
            LogWarning(string.Format("Uknown set handler for attribute '{0}'", attrName));

        }

        private void MonitorConfigtime_PostCreate(object sender, object optionalParameter)
        {
            //------------------------------------------------------------------------------
            //  TODO: Configtime Event - PostCreate
            //
            //  OnPostCreate is called when an object is first created.
            //
            //  One purpose for implementing this method is to insure that the initial
            //  state of the primitive is valid.
            //
            //  This method can be used by a Resuable Primitive to correct invalid initial 
            //  states that can arise when an attribute value has been overridden. If the 
            //  attribute has a SetHandler with validation or side effects the SetHandler  
            //  does not execute as overrides do not trigger SetHandlers.
            //------------------------------------------------------------------------------

            #region Example code
            //          // If statistics are enabled, add the Statistics virtual primitive
            //          // the way the SetHandler would have done it.
            //          if (StatsEnable) 
            //          {
            //	            AddPrimitive("Statistics", "Statistics1", "Statistics1");
            //          }
            #endregion
        }

        private void MonitorConfigtime_PreValidate(object sender, object optionalParameter)
        {
            //------------------------------------------------------------------------------
            //  TODO: Configtime Event - PreValidate 
            // 
            //  PreValidate is called when the object is about to be validated (e.g. when
            //  an edit session is ending and the object is about to be saved.)
            //
            //  A primitive can modify attributes within this method.
            //
            //  Note: It is often not necessary to perform any actions in OnPreValidate.
            //------------------------------------------------------------------------------
        }

        #region Optional Configuration Events
        //------------------------------------------------------------------------------
        //  TODO: Optional Configtime Events
        //  
        //  Use the Toolkit Editor to enable each optional event or add the event to the 
        //  ObjectAttributes.Events attribute in the object class. 
        //
        //  Multiple events can be enabled using the | delimiter.
        //  
        //  Example:
        //  [ObjectAttributes.Events(a.EventHandlerEnum.OnPreDeploy | a.EventHandlerEnum.OnPreDelete)]
        //
        //------------------------------------------------------------------------------

        private void MonitorConfigtime_PreUndeploy(object sender, ref SupportEventArgs e)
        {
            //------------------------------------------------------------------------------
            //  TODO: Configtime Event - PreUndeploy
            //
            //------------------------------------------------------------------------------

        }
        private void MonitorConfigtime_PreUnassign(object sender, ref GeneralEventArgs e)
        {
            //------------------------------------------------------------------------------
            //  TODO: Configtime Event - PreUnassign
            //
            //------------------------------------------------------------------------------

        }
        private void MonitorConfigtime_PreRename(object sender, ref RenameEventArgs e)
        {
            //------------------------------------------------------------------------------
            //  TODO: Configtime Event - PreRename
            //
            //------------------------------------------------------------------------------

        }
        private void MonitorConfigtime_PreDeploy(object sender, ref DeployEventArgs e)
        {
            //------------------------------------------------------------------------------
            //  TODO: Configtime Event - PreDeploy
            //  
            //  Use the Toolkit Editor to enable this event or add OnPreDeploy to the 
            //  ObjectAttributes.Events attribute in the object class. Multiple events can
            //  be enabled using the | delimiter.
            //
            //      Example: [ObjectAttributes.Events(a.EventHandlerEnum.OnPreDeploy)]
            //
            //------------------------------------------------------------------------------

        }
        private void MonitorConfigtime_PreDelete(object sender, ref SupportEventArgs e)
        {
            //------------------------------------------------------------------------------
            //  TODO: Configtime Event - PreDelete
            //
            //------------------------------------------------------------------------------

        }
        private void MonitorConfigtime_PreCheckIn(object sender, ref SupportEventArgs e)
        {
            //------------------------------------------------------------------------------
            //  TODO: Configtime Event - PreCheckIn
            //
            //------------------------------------------------------------------------------

        }
        private void MonitorConfigtime_PreAssignTo(object sender, ref GeneralEventArgs e)
        {
            //------------------------------------------------------------------------------
            //  TODO: Configtime Event - PreAssignTo
            //
            //------------------------------------------------------------------------------

        }
        private void MonitorConfigtime_PostUndeploy(object sender, ref SupportEventArgs e)
        {
            //------------------------------------------------------------------------------
            //  TODO: Configtime Event - PostUndeploy
            //
            //------------------------------------------------------------------------------

        }
        private void MonitorConfigtime_PostUnassignFrom(object sender, ref GeneralEventArgs e)
        {
            //------------------------------------------------------------------------------
            //  TODO: Configtime Event - PostUnassignFrom
            //
            //------------------------------------------------------------------------------

        }
        private void MonitorConfigtime_PostUnassign(object sender, ref GeneralEventArgs e)
        {
            //------------------------------------------------------------------------------
            //  TODO: Configtime Event - PostUnassign
            //
            //------------------------------------------------------------------------------

        }
        private void MonitorConfigtime_PostRename(object sender, ref RenameEventArgs e)
        {
            //------------------------------------------------------------------------------
            //  TODO: Configtime Event - PostRename
            //
            //------------------------------------------------------------------------------

        }
        private void MonitorConfigtime_PostDeploy(object sender, ref SupportEventArgs e)
        {
            //------------------------------------------------------------------------------
            //  TODO: Configtime Event - PostDeploy
            //
            //------------------------------------------------------------------------------

        }
        private void MonitorConfigtime_PostDelete(object sender, ref SupportEventArgs e)
        {
            //------------------------------------------------------------------------------
            //  TODO: Configtime Event - PostDelete
            //
            //------------------------------------------------------------------------------

        }
        private void MonitorConfigtime_PostAssignTo(object sender, ref GeneralEventArgs e)
        {
            //------------------------------------------------------------------------------
            //  TODO: Configtime Event - PostAssignTo
            //
            //------------------------------------------------------------------------------

        }
        private void MonitorConfigtime_PostAssign(object sender, ref GeneralEventArgs e)
        {
            //------------------------------------------------------------------------------
            //  TODO: Configtime Event - PostAssign
            //
            //------------------------------------------------------------------------------

        }
        private void MonitorConfigtime_PostCheckIn(object sender, ref SupportEventArgs e)
        {
            //------------------------------------------------------------------------------
            //  TODO: Configtime Event - PostCheckIn
            //
            //------------------------------------------------------------------------------

        }

        #endregion

        private void PVHiLimitSetHandler(object sender, ref ConfigtimeSetHandlerEventArgs e)
        {
            PVHiLimit.SetHandlerValue = e;
        }
    }
}

