SPFarm 类

代表Microsoft SharePoint Foundation场。

继承层次结构

System.Object
  Microsoft.SharePoint.Administration.SPAutoSerializingObject
    Microsoft.SharePoint.Administration.SPPersistedObject
      Microsoft.SharePoint.Administration.SPPersistedUpgradableObject
        Microsoft.SharePoint.Administration.SPFarm

命名空间:  Microsoft.SharePoint.Administration
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
<GuidAttribute("674DA553-EA77-44a3-B9F8-3F70D786DE6A")> _
<UpgradableAttribute> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
Public Class SPFarm _
    Inherits SPPersistedUpgradableObject _
    Implements IBackupRestoreConfiguration, IBackupRestore, IMigratable
用法
Dim instance As SPFarm
[GuidAttribute("674DA553-EA77-44a3-B9F8-3F70D786DE6A")]
[UpgradableAttribute]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public class SPFarm : SPPersistedUpgradableObject, IBackupRestoreConfiguration, 
    IBackupRestore, IMigratable

备注

SPFarm是用于在配置数据存储区进行交互的可扩展的配置对象模型中的顶级节点。它包含所有服务器、 服务和解决方案安装在服务器场中的全局设置。使用ServersServicesSolutions属性以检索这些集合。

若要访问在当前服务器场对象,您可以在SPFarm.Local上使用成员。例如,若要返回一个SPServiceCollection对象,代表在当前服务器场中的服务的集合,请使用SPFarm.Local.Services。此外,您可以使用SPPersistedObject类中派生的类的Farm属性,或者可以使用SPSolution类的Farm属性来获取当前对象,或者解决方案的服务器场。

示例

下面的示例注册一个自定义的作业定义在当前服务器场中每个 Web 应用程序上。

Dim farm As SPFarm = SPFarm.Local
Dim service As SPWebService = farm.Services.GetValue < SPWebService > ""

Dim webApp As SPWebApplication

For Each webApp In  service.WebApplications
    Dim job As SPJobDefinition

    For Each job In  webApp.JobDefinitions

        If job.Name = "MyCustomJobDefinitionName" Then
            j.Delete()
        End If
    Next job

    Dim newJob As New MyCustomJobDefinition("MyCustomJobDefinitionName", webApp)
    Dim schedule As SPSchedule = SPSchedule.FromString("every 5 minutes between 0 and 59")
    newJob.Schedule = schedule

    newJob.Update()
Next webApp
SPFarm farm = SPFarm.Local;
SPWebService service = farm.Services.GetValue<SPWebService>("");

foreach (SPWebApplication webApp in service.WebApplications)
{
    foreach (SPJobDefinition job in webApp.JobDefinitions)
    {
        if (job.Name == "MyCustomJobDefinitionName")
        {
            j.Delete();
        }
    }

    MyCustomJobDefinition newJob = new 
        MyCustomJobDefinition("MyCustomJobDefinitionName", webApp);
    SPSchedule schedule = SPSchedule.FromString("every 5 minutes between 0 and 59");
    newJob.Schedule = schedule;

    newJob.Update();
}

线程安全性

该类型的任何公共 静态 (已共享 在 Visual Basic 中) 成员都是线程安全的。不保证任何实例成员都是线程安全的。

另请参阅

引用

SPFarm 成员

Microsoft.SharePoint.Administration 命名空间