ArcGIS Buffer geoprocessing
ArcGIS_Buffer_Geoprocessing_CSharp\App_Code\PointTool.cs
// Copyright 2010 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See the use restrictions.
// 

public class PointTool : ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction
{
    #region IMapServerToolAction Members

    void ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools.IMapServerToolAction.ServerAction(
        ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolEventArgs toolEventArgs)
    {
        // Get the map control on which the tool was executed
        ESRI.ArcGIS.ADF.Web.UI.WebControls.Map adfMap =
            (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)toolEventArgs.Control;

        try
        {
            // Get the point drawn by the user
            ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs mapPointEventArgs = 
                toolEventArgs as ESRI.ArcGIS.ADF.Web.UI.WebControls.MapPointEventArgs;
            ESRI.ArcGIS.ADF.Web.Geometry.Point adfPoint = mapPointEventArgs.MapPoint;

            // Get the name of the graphics resource from session that will contain the 
            // user-placed point
            string graphicsResourceName = (string)adfMap.Page.Session["graphicsResourceName"];

            // Get the graphics map functionality for the resource
            ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality graphicsMapFunctionality =
                adfMap.GetFunctionality(graphicsResourceName) as
                ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapFunctionality;

            // Get the name of the graphics layer to which we will add the user-placed point from
            // from session, then use this name to retrieve the graphics layer from the graphics
            // map functionality.
            string pointGraphicsLayerName = (string)adfMap.Page.Session["pointGraphicsLayerName"];
            ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer elementGraphicsLayer =
                graphicsMapFunctionality.GraphicsDataSet.Tables[pointGraphicsLayerName] as
                ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer;

            // If the graphics layer was not found, create it
            if (elementGraphicsLayer == null)
            {
                elementGraphicsLayer = new ESRI.ArcGIS.ADF.Web.Display.Graphics.ElementGraphicsLayer();
                elementGraphicsLayer.TableName = pointGraphicsLayerName;
                graphicsMapFunctionality.GraphicsDataSet.Tables.Add(elementGraphicsLayer);
            }

            // Uncomment to allow only one point to be drawn on the map at a time
            //elementGraphicsLayer.Clear();

            // Create the symbology for the point
            ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol adfSimpleMarkerSymbol =
                new ESRI.ArcGIS.ADF.Web.Display.Symbol.SimpleMarkerSymbol();
            adfSimpleMarkerSymbol.Type = ESRI.ArcGIS.ADF.Web.Display.Symbol.MarkerSymbolType.Triangle;
            adfSimpleMarkerSymbol.Color = System.Drawing.Color.Aqua;
            adfSimpleMarkerSymbol.Width = 12;

            // Create a graphic element based on the point and the symbology
            ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement graphicElement =
                new ESRI.ArcGIS.ADF.Web.Display.Graphics.GraphicElement(adfPoint, adfSimpleMarkerSymbol);

            // Add the element to the graphics layer
            elementGraphicsLayer.Add(graphicElement);

            // Refresh the graphics resource so the newly added graphic is displayed
            adfMap.RefreshResource(graphicsResourceName);
        }
        catch (System.Exception exception)
        {
            ESRI.ArcGIS.ADF.Web.UI.WebControls.CallbackResult errorCallbackResult =
                Utility.CreateErrorCallbackResult(exception);
            adfMap.CallbackResults.Add(errorCallbackResult);
        }
    }

    #endregion
}