ArcObjects Library Reference  

SimplePointWkspFact

About the Simple point plug-in data source Sample

[C#]

SimplePointWkspFact.cs

using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;

namespace ESRI.ArcGIS.Samples.SimplePointPlugin
{
	/// <summary>
	/// Summary description for SimplePointWkspFact.
	/// </summary>
	/// 
  [ClassInterface(ClassInterfaceType.None)]
  [Guid("6e167940-6d49-485b-a2b8-061c144d805f")]
  [ProgId("SimplePointPlugin.SimplePointWFHelper")]
	[ComVisible(true)]
  public sealed class SimplePointWkspFact : IPlugInWorkspaceFactoryHelper
  {
    #region "Component Category Registration"

    [ComRegisterFunction()]
    public static void RegisterFunction(String regKey)
    {
      PlugInWorkspaceFactoryHelpers.Register(regKey);
    }

    [ComUnregisterFunction()]
    public static void UnregisterFunction(String regKey)
    {
      PlugInWorkspaceFactoryHelpers.Unregister(regKey);
    }
    #endregion


    #region class constructor
    public SimplePointWkspFact()
    {
    }
    #endregion

    #region IPlugInWorkspaceFactoryHelper Members

    public string get_DatasetDescription(esriDatasetType DatasetType)
    {
      switch (DatasetType)
      {
        case esriDatasetType.esriDTTable:
          return "SimplePoint Table";
        case esriDatasetType.esriDTFeatureClass:
          return "SimplePoint Feature Class";
        case esriDatasetType.esriDTFeatureDataset:
          return "SimplePoint Feature Dataset";
        default:
          return null;
      }
    }

    public string get_WorkspaceDescription(bool plural)
    {
      if (plural)
        return "Simple Points";
      else
        return "Simple Point";
    }

    public bool CanSupportSQL
    {
      get { return false; }
    }

    public string DataSourceName
    {
      //HIGHLIGHT: ProgID = esriGeoDatabase.<DataSourceName>WorkspaceFactory
      get { return "SimplePointPlugin"; }
    }

    public bool ContainsWorkspace(string parentDirectory, IFileNames fileNames)
    {
      if (fileNames == null)
        return this.IsWorkspace(parentDirectory);

      if (!System.IO.Directory.Exists(parentDirectory))
        return false;

      string sFileName;
      while ((sFileName = fileNames.Next()) != null)
      {
        if (fileNames.IsDirectory())
          continue;

        if (System.IO.Path.GetExtension(sFileName).Equals(".csp"))
          return true;
      }

      return false;
    }

    public UID WorkspaceFactoryTypeID
    {
      //HIGHLIGHT: Generate a new GUID to identify the workspace factory
      get
      {
        UID wkspFTypeID = new UIDClass();
        wkspFTypeID.Value = "{b8a25f89-2adc-43c0-ac2e-16b3a88e3915}";	//proxy
        return wkspFTypeID;
      }
    }

    public bool IsWorkspace(string wksString)
    {
      //TODO: IsWorkspace is True when folder contains csp files
      if (System.IO.Directory.Exists(wksString))
        return System.IO.Directory.GetFiles(wksString, "*.csp").Length > 0;
      return false;
    }

    public esriWorkspaceType WorkspaceType
    {
      //HIGHLIGHT: WorkspaceType - FileSystem type strongly recommended
      get
      {
        return esriWorkspaceType.esriFileSystemWorkspace;
      }
    }

    public IPlugInWorkspaceHelper OpenWorkspace(string wksString)
    {
      //HIGHLIGHT: OpenWorkspace
      //Don't have to check if wksString contains valid data file. 
      //Any valid folder path is fine since we want paste to work in any folder
      if (System.IO.Directory.Exists(wksString))
      {
        SimplePointWksp openWksp = new SimplePointWksp(wksString);
        return (IPlugInWorkspaceHelper)openWksp;
      }
      return null;
    }

    public string GetWorkspaceString(string parentDirectory, IFileNames fileNames)
    {
      //return the path to the workspace location if 
      if (!System.IO.Directory.Exists(parentDirectory))
        return null;

      if (fileNames == null)	//don't have to check .csp file
        return parentDirectory;

      //HIGHLIGHT: GetWorkspaceString - claim and remove file names from list
      string sFileName;
      bool fileFound = false;
      while ((sFileName = fileNames.Next()) != null)
      {
        if (fileNames.IsDirectory())
          continue;

        if (System.IO.Path.GetExtension(sFileName).Equals(".csp"))
        {
          fileFound = true;
          fileNames.Remove();
        }
      }

      if (fileFound)
        return parentDirectory;
      else
        return null;
    }

    #endregion


  }
}

[Visual Basic .NET]

SimplePointWkspFact.vb

Imports Microsoft.VisualBasic
Imports System
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Imports ESRI.ArcGIS.ADF.CATIDs
Imports ESRI.ArcGIS.ADF
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Geodatabase

	''' <summary>
	''' Summary description for SimplePointWkspFact.
	''' </summary>
	''' 
<ClassInterface(ClassInterfaceType.None), Guid("6e167940-6d49-485b-a2b8-061c144d805f"), ProgId("SimplePointPlugin.SimplePointWFHelper")> _
Public NotInheritable Class SimplePointWkspFact
	Implements IPlugInWorkspaceFactoryHelper
#Region "Component Category Registration"

	<ComRegisterFunction()> _
	Public Shared Sub RegisterFunction(ByVal regKey As String)
		'proxy PluginWorkspaceFactoryHelper
		PlugInWorkspaceFactoryHelpers.Register(regKey)
	End Sub

	<ComUnregisterFunction()> _
	Public Shared Sub UnregisterFunction(ByVal regKey As String)
		PlugInWorkspaceFactoryHelpers.Unregister(regKey)
	End Sub
#End Region

#Region "class constructor"
	Public Sub New()
	End Sub
#End Region

#Region "IPlugInWorkspaceFactoryHelper Members"

	Public ReadOnly Property DatasetDescription(ByVal DatasetType As ESRI.ArcGIS.Geodatabase.esriDatasetType) As String Implements ESRI.ArcGIS.Geodatabase.IPlugInWorkspaceFactoryHelper.DatasetDescription
		Get
			Select Case DatasetType
				Case esriDatasetType.esriDTTable
					Return "SimplePoint Table"
				Case esriDatasetType.esriDTFeatureClass
					Return "SimplePoint Feature Class"
				Case esriDatasetType.esriDTFeatureDataset
					Return "SimplePoint Feature Dataset"
				Case Else
					Return Nothing
			End Select
		End Get
	End Property

	Public ReadOnly Property WorkspaceDescription(ByVal plural As Boolean) As String Implements ESRI.ArcGIS.Geodatabase.IPlugInWorkspaceFactoryHelper.WorkspaceDescription
		Get
			If plural Then
				Return "Simple Points"
			Else
				Return "Simple Point"
			End If
		End Get
	End Property

	Public ReadOnly Property CanSupportSQL() As Boolean Implements IPlugInWorkspaceFactoryHelper.CanSupportSQL
		Get
			Return False
		End Get
	End Property

	Public ReadOnly Property DataSourceName() As String Implements IPlugInWorkspaceFactoryHelper.DataSourceName
		'HIGHLIGHT: ProgID = esriGeoDatabase.<DataSourceName>WorkspaceFactory
		Get
			Return "SimplePointPlugin"
		End Get
	End Property

	Public Function ContainsWorkspace(ByVal parentDirectory As String, ByVal fileNames As IFileNames) As Boolean Implements IPlugInWorkspaceFactoryHelper.ContainsWorkspace
		If fileNames Is Nothing Then
			Return Me.IsWorkspace(parentDirectory)
		End If

		If (Not System.IO.Directory.Exists(parentDirectory)) Then
			Return False
		End If

		Dim sFileName As String
		sFileName = fileNames.Next()
		Do While Not sFileName Is Nothing
			If Not fileNames.IsDirectory() Then
				If System.IO.Path.GetExtension(sFileName).Equals(".csp") Then
					Return True
				End If
			End If
			sFileName = fileNames.Next()
		Loop

		Return False
	End Function

	Public ReadOnly Property WorkspaceFactoryTypeID() As UID Implements IPlugInWorkspaceFactoryHelper.WorkspaceFactoryTypeID
		'HIGHLIGHT: Generate a new GUID to identify the workspace factory
		Get
			Dim wkspFTypeID As UID = New UIDClass()
			wkspFTypeID.Value = "{b8a25f89-2adc-43c0-ac2e-16b3a88e3915}" 'proxy
			Return wkspFTypeID
		End Get
	End Property


	Public Function IsWorkspace(ByVal wksString As String) As Boolean Implements ESRI.ArcGIS.Geodatabase.IPlugInWorkspaceFactoryHelper.IsWorkspace
		'IsWorkspace is True when the folder contains csp files
		If System.IO.Directory.Exists(wksString) Then
			Return System.IO.Directory.GetFiles(wksString, "*.csp").Length > 0
		End If
		Return False
	End Function

	Public ReadOnly Property WorkspaceType() As esriWorkspaceType Implements IPlugInWorkspaceFactoryHelper.WorkspaceType
		'HIGHLIGHT: WorkspaceType - FileSystem type strongly recommended
		Get
			Return esriWorkspaceType.esriFileSystemWorkspace
		End Get
	End Property

	Public Function OpenWorkspace(ByVal wksString As String) As IPlugInWorkspaceHelper Implements IPlugInWorkspaceFactoryHelper.OpenWorkspace
		'HIGHLIGHT: OpenWorkspace
		'Don't have to check if wksString contains valid data file. 
		'Any valid folder path is fine since we want paste to work in any folder
		If System.IO.Directory.Exists(wksString) Then
			Dim openWksp As SimplePointWksp = New SimplePointWksp(wksString)
			Return CType(openWksp, IPlugInWorkspaceHelper)
		End If
		Return Nothing
	End Function

	Public Function GetWorkspaceString(ByVal parentDirectory As String, ByVal fileNames As IFileNames) As String Implements IPlugInWorkspaceFactoryHelper.GetWorkspaceString
		'return the path to the workspace location if 
		If (Not System.IO.Directory.Exists(parentDirectory)) Then
			Return Nothing
		End If

		If fileNames Is Nothing Then 'don't have to check.csp file
			Return parentDirectory
		End If

		'HIGHLIGHT: GetWorkspaceString - claim and remove file names from list
		Dim sFileName As String
		Dim fileFound As Boolean = False
		sFileName = fileNames.Next()

		Do While Not sFileName Is Nothing
			If Not fileNames.IsDirectory() Then
				If System.IO.Path.GetExtension(sFileName).Equals(".csp") Then
					fileFound = True
					fileNames.Remove()
				End If
			End If
			sFileName = fileNames.Next()
		Loop

		If fileFound Then
			Return parentDirectory
		Else
			Return Nothing
		End If
	End Function

#End Region

End Class