A class that sends event notifications whenever the Messages are added.
Inheritance: IGeoProcessorEvents
コード例 #1
0
    /// <summary>
    /// This sample console app demonstrates listening to GP events as they happen
    /// </summary>
    /// <param name="args"></param>
    static void Main(string[] args)
    {
        ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);

      GPMessageEventHandler gpEventHandler = new GPMessageEventHandler();

      //get an instance of the geoprocessor
      Geoprocessor GP = new Geoprocessor();
      //register the event helper in order to be able to listen to GP events
      GP.RegisterGeoProcessorEvents(gpEventHandler);

      //wire the GP events
      gpEventHandler.GPMessage += new MessageEventHandler(OnGPMessage);
      gpEventHandler.GPPreToolExecute += new PreToolExecuteEventHandler(OnGPPreToolExecute);
      gpEventHandler.GPToolboxChanged += new ToolboxChangedEventHandler(OnGPToolboxChanged);
      gpEventHandler.GPPostToolExecute += new PostToolExecuteEventHandler(OnGPPostToolExecute);

      //instruct the geoprocessing engine to overwrite existing datasets
      GP.OverwriteOutput = true;

      //create instance of the 'create random points' tool. Write the output to the machine's temp directory
      CreateFeatureclass createFeatureClass = new CreateFeatureclass(System.IO.Path.GetTempPath(), "RandomPoints.shp");
      //execute the tool
      GP.Execute(createFeatureClass, null);

      //unwire the GP events
      gpEventHandler.GPMessage -= new MessageEventHandler(OnGPMessage);
      gpEventHandler.GPPreToolExecute -= new PreToolExecuteEventHandler(OnGPPreToolExecute);
      gpEventHandler.GPToolboxChanged -= new ToolboxChangedEventHandler(OnGPToolboxChanged);
      gpEventHandler.GPPostToolExecute -= new PostToolExecuteEventHandler(OnGPPostToolExecute);

      //unregister the event helper
      GP.UnRegisterGeoProcessorEvents(gpEventHandler);

      System.Diagnostics.Trace.WriteLine("Done");
    }
コード例 #2
0
        protected override void OnClick()
        {
            if (!Utilities.DoesConfigFileExist)
            {
                //Send a warning that the extension needs to be setup
                MessageBox.Show(string.Format("No Configuration File Available.  Please save config.xml at {0}", Utilities.iFormFolder));
            }

            //Read all the Layers in the MXD and process the Sync Table for that workspace
            IEnumLayer layers = ArcMap.Document.FocusMap.get_Layers();
            ILayer layer = layers.Next();
            SelectionTargetComboBox s_combo = SelectionTargetComboBox.GetSelectionComboBox();
            iFormBuilderAPI.iFormBuilder api = new iFormBuilderAPI.iFormBuilder();
            api.ReadConfiguration(Utilities.iFormConfigFile);
            processedworkspaces = new List<IWorkspace>();

            while (layer != null)
            {
                //if (layer.GetType() == typeof(IFeatureLayer))
                //{
                    IFeatureLayer fLayer = layer as IFeatureLayer;
                    IDataset pDataSet = fLayer.FeatureClass as IDataset;
                    try
                    {
                        if (!processedworkspaces.Contains(pDataSet.Workspace))
                        {
                            GPMessageEventHandler gpEventHandler = new GPMessageEventHandler();
                            //get an instance of the geoprocessor
                            //instruct the geoprocessing engine to overwrite existing datasets
                            GP.OverwriteOutput = true;
                            GP.AddToolbox(Utilities.iFormFolder + "\\" + "iFormTools.tbx");

                            // Create a variant. Data is in the workspace.
                            IVariantArray parameters = new VarArrayClass();
                            parameters.Add(pDataSet.Workspace.PathName);
                            parameters.Add(Utilities.iFormConfigFile);
                            parameters.Add(1);

                            GP.ToolExecuted += new EventHandler<ESRI.ArcGIS.Geoprocessor.ToolExecutedEventArgs>(gpToolExecuted);
                            GP.ExecuteAsync("SynciFormDatabase", parameters);

                            //add this workspace to the processed workspaces
                            processedworkspaces.Add(pDataSet.Workspace);
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Synchronization Failed");
                    }
                    layer = layers.Next();
                //}
            }
        }