/// <summary>
        /// Apply the properties set in the form to the arguments object.
        /// </summary>
        public void Apply()
        {
            if (!isFormReadOnly) // If the form is read only, do not update.
            {
                if (templateMode)
                {
                    // If in template mode, use the values from the page to
                    // update the variables.
                    if (myForm.InputRaster != null)
                    {
                        if (myForm.InputRaster is IRasterFunctionVariable)
                        {
                            myRasterVar = (IRasterFunctionVariable)myForm.InputRaster;
                        }
                        else
                        {
                            myRasterVar.Value = myForm.InputRaster;
                        }
                    }
                    myBlendPercentageVar.Value    = myForm.BlendPercentage;
                    myWatermarkImagePathVar.Value = myForm.WatermarkImagePath;
                    myXGapVar.Value = myForm.XGap;
                    myYGapVar.Value = myForm.YGap;
                    // Then set the variables on the arguments object.
                    IRasterFunctionArguments rasterFunctionArgs =
                        (IRasterFunctionArguments)myArgs;
                    rasterFunctionArgs.PutValue("Raster", myRasterVar);
                    rasterFunctionArgs.PutValue("BlendPercentage", myBlendPercentageVar);
                    rasterFunctionArgs.PutValue("XGap", myXGapVar);
                    rasterFunctionArgs.PutValue("YGap", myYGapVar);
                    rasterFunctionArgs.PutValue("WatermarkImagePath", myWatermarkImagePathVar);
                }
                else if (myArgs != null)
                {
                    // If not in template mode, update the arguments object
                    // with the values from the form.
                    myArgs.BlendPercentage    = myForm.BlendPercentage;
                    myArgs.XGap               = myForm.XGap;
                    myArgs.YGap               = myForm.YGap;
                    myArgs.WatermarkImagePath = myForm.WatermarkImagePath;
                    if (myForm.InputRaster != null)
                    {
                        myArgs.Raster = myForm.InputRaster;
                    }
                }
            }

            myForm.IsFormDirty = false;
        }
        /// <summary>
        /// Apply the properties set in the form to the arguments object.
        /// </summary>
        public void Apply()
        {
            if (!isFormReadOnly) // If the form is read only, do not update.
            {
                if (templateMode)
                {
                    // If in template mode, use the values from the page to
                    // update the variables.
                    if (myForm.InputRaster != null)
                    {
                        if (myForm.InputRaster is IRasterFunctionVariable)
                        {
                            myRasterVar = (IRasterFunctionVariable)myForm.InputRaster;
                        }
                        else
                        {
                            myRasterVar.Value = myForm.InputRaster;
                        }
                    }
                    myBandIndicesVar.Value = myForm.BandIndices;
                    // Then set the variables on the arguments object.
                    IRasterFunctionArguments rasterFunctionArgs =
                        (IRasterFunctionArguments)myArgs;
                    rasterFunctionArgs.PutValue("BandIndices", myBandIndicesVar);
                    rasterFunctionArgs.PutValue("Raster", myRasterVar);
                }
                else if (myArgs != null)
                {
                    // If not in template mode, update the arguments object
                    // with the values from the form.
                    myArgs.BandIndices = myForm.BandIndices;
                    if (myForm.InputRaster != null)
                    {
                        myArgs.Raster = myForm.InputRaster;
                    }
                }
            }

            myForm.IsFormDirty = false;
        }
        /// <summary>
        /// Set the necessary objects required for the form. In this case
        /// the form is given an arguments object in edit mode, or is required
        /// to create one in create mode. After getting or creating the arguments
        /// object, template mode is checked for and handled. The template mode
        /// requires all parameters of the arguments object to converted to variables.
        /// </summary>
        /// <param name="objects">Set of objects required for the form.</param>
        public void SetObjects(ESRI.ArcGIS.esriSystem.ISet objects)
        {
            try
            {
                // Recurse through the objects
                objects.Reset();
                for (int i = 0; i < objects.Count; i++)
                {
                    object currObject = objects.Next();
                    // Find the properties to be set.
                    if (currObject is IPropertySet)
                    {
                        IPropertySet uiParameters = (IPropertySet)currObject;
                        object       names, values;
                        uiParameters.GetAllProperties(out names, out values);

                        bool disableForm = false;
                        try { disableForm = Convert.ToBoolean(uiParameters.GetProperty("RFxPropPageIsReadOnly")); }
                        catch (Exception) { }

                        if (disableForm)
                        {
                            isFormReadOnly = true;
                        }
                        else
                        {
                            isFormReadOnly = false;
                        }

                        // Check if the arguments object exists in the property set.
                        object functionArgument = null;
                        try { functionArgument = uiParameters.GetProperty("RFxArgument"); }
                        catch (Exception) { }
                        // If not, the form is in create mode.
                        if (functionArgument == null)
                        {
                            #region Create Mode
                            // Create a new arguments object.
                            myArgs = new NDVICustomFunctionArguments();
                            // Create a new property and set the arguments object on it.
                            uiParameters.SetProperty("RFxArgument", myArgs);
                            // Check if a default raster is supplied.
                            object defaultRaster = null;
                            try { defaultRaster = uiParameters.GetProperty("RFxDefaultInputRaster"); }
                            catch (Exception) { }
                            if (defaultRaster != null) // If it is, set it to the raster property.
                            {
                                myArgs.Raster = defaultRaster;
                            }
                            // Check if the form is in template mode.
                            templateMode = (bool)uiParameters.GetProperty("RFxTemplateEditMode");
                            if (templateMode)
                            {
                                // Since we are in create mode already, new variables have to be
                                // created for each property of the arguments object.
                                #region Create Variables
                                if (defaultRaster != null)
                                {
                                    // If a default raster is supplied and it is a variable,
                                    // there is no need to create one.
                                    if (defaultRaster is IRasterFunctionVariable)
                                    {
                                        myRasterVar = (IRasterFunctionVariable)defaultRaster;
                                    }
                                    else
                                    {
                                        // Create variable object for the InputRaster property.
                                        myRasterVar           = new RasterFunctionVariableClass();
                                        myRasterVar.Value     = defaultRaster;
                                        myRasterVar.Name      = "InputRaster";
                                        myRasterVar.IsDataset = true;
                                    }
                                }

                                // Create a variable for the BandIndices property.
                                myBandIndicesVar      = new RasterFunctionVariableClass();
                                myBandIndicesVar.Name = "BandIndices";
                                // Use the default value from the arguments object
                                myBandIndicesVar.Value = myArgs.BandIndices;

                                // Set the variables created as properties on the arguments object.
                                IRasterFunctionArguments rasterFunctionArgs =
                                    (IRasterFunctionArguments)myArgs;
                                rasterFunctionArgs.PutValue("Raster", myRasterVar);
                                rasterFunctionArgs.PutValue("BandIndices", myBandIndicesVar);
                                #endregion
                            }
                            #endregion
                        }
                        else
                        {
                            #region  Edit Mode
                            // Get the arguments object from the property set.
                            myArgs = (INDVICustomFunctionArguments)functionArgument;
                            // Check if the form is in template mode.
                            templateMode = (bool)uiParameters.GetProperty("RFxTemplateEditMode");
                            if (templateMode)
                            {
                                #region Edit Template
                                // In template edit mode, the variables from the arguments object
                                // are extracted.
                                IRasterFunctionArguments rasterFunctionArgs =
                                    (IRasterFunctionArguments)myArgs;
                                object raster = rasterFunctionArgs.GetValue("Raster");

                                // Create or Open the Raster variable.
                                if (raster is IRasterFunctionVariable)
                                {
                                    myRasterVar = (IRasterFunctionVariable)raster;
                                }
                                else
                                {
                                    myRasterVar       = new RasterFunctionVariableClass();
                                    myRasterVar.Name  = "InputRaster";
                                    myRasterVar.Value = raster;
                                }
                                #endregion
                            }
                            #endregion
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                string errorMsg = exc.Message;
            }
        }
 /// <summary>
 /// Update the variables containing field names to their updated values.
 /// </summary>
 /// <param name="pRow">The row corresponding to the function raster dataset.</param>
 /// <param name="pPropertySet">Property Set to add the list of the names and the updated values to.</param>
 /// <param name="pTemplateArguments">The arguments object containing the properties to update if</param>
 public void Update(IRow pRow, IPropertySet pPropertySet, IRasterFunctionArguments pTemplateArguments)
 {
     Resolve(pRow, pPropertySet);
 }
 /// <summary>
 /// Update the variables containing field names to their updated values.
 /// </summary>
 /// <param name="pRow">The row corresponding to the function raster dataset.</param>
 /// <param name="pPropertySet">Property Set to add the list of the names and the updated values to.</param>
 /// <param name="pTemplateArguments">The arguements object containing the properties to update if</param>
 public void Update(IRow pRow, IPropertySet pPropertySet, IRasterFunctionArguments pTemplateArguments)
 {
     Resolve(pRow, pPropertySet);
 }