惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
Simon Willison's Weblog
Simon Willison's Weblog
H
Help Net Security
F
Fortinet All Blogs
H
Heimdal Security Blog
S
Schneier on Security
L
LangChain Blog
博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
NISL@THU
NISL@THU
P
Palo Alto Networks Blog
J
Java Code Geeks
博客园 - 【当耐特】
The Last Watchdog
The Last Watchdog
W
WeLiveSecurity
www.infosecurity-magazine.com
www.infosecurity-magazine.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost
I
InfoQ
Recorded Future
Recorded Future
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
CERT Recently Published Vulnerability Notes
T
Tenable Blog
腾讯CDC
C
Check Point Blog
量子位
M
MIT News - Artificial intelligence
GbyAI
GbyAI
罗磊的独立博客
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
B
Blog
小众软件
小众软件
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
CXSECURITY Database RSS Feed - CXSecurity.com
Stack Overflow Blog
Stack Overflow Blog
P
Proofpoint News Feed
P
Privacy & Cybersecurity Law Blog
V2EX - 技术
V2EX - 技术
T
Threatpost
Engineering at Meta
Engineering at Meta
Attack and Defense Labs
Attack and Defense Labs
T
Tailwind CSS Blog
S
Securelist
The Cloudflare Blog
博客园 - 叶小钗
L
LINUX DO - 最新话题
T
Troy Hunt's Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
爱范儿
爱范儿

博客园 - 零零猪

基于Windows Server 2008 R2的Failover Cluster(故障转移群集)部署Sql Server 2008 AA(主主) 模式群集(第二部分) 基于Windows Server 2008 R2的Failover Cluster(故障转移群集)部署Sql Server 2008 AA(主主) 模式群集(第一部分) 整型运算三个恒等式 Office 2010众多客户端产品、服务器产品试用下载 免费发短信,短信云计算?? Asp.Net MVC 1.0 Action Filters Tips 暂时做一个快乐的SOHO族 Asp.Net MVC使用HtmlHelper渲染,并传递FormCollection参数的陷阱 ASP.Net MVC Relational KeyWord 4 Google 【More...】【欢迎补充】 本博客加入“署名-非商业性使用-禁止演绎 2.5 中国大陆”许可协议 Exchange 2007 队列数据库、队列事务日志文件超过临界值(阈值)导致无法接受邮件解决方案 10步完成Windows 2003+SQLServer 2005 群集(Cluster)安装及配置【备案】 C# 3.0通过Linq、Lambda、匿名函数、代理函数实现数据查询 photosynth Trial MOSS 2007 爬网规则 Contentclass常用属性设置 有用的SharePoint英文资源[持续更新] SQL日志收缩(ZZ) Microsoft photosynth(图片三维展示) MOSS2007匿名调查列表使用分页符导致的错误分析
MOSS2007中Feature对象模型操作
零零猪 · 2008-07-18 · via 博客园 - 零零猪

     这几天,因为觉得MOSS2007的Feature操作使用起来很麻烦,所以自定写了个管理MOSS2007Feature的小工具,也对MOSS2007里的Feature的对象模型以及在各个级别内的关系有了了解,现分享一下。
下载小工具:目前只可以在装有moss的机器上运行.

下边就介绍下MOSS2007中Feature对象模型

安装和卸载Feature

     安装和卸载Feature也就是把一个自定义的Feature安装到moss服务器场中,涉及到的和Feature相关的类包括:

Microsoft.SharePoint.Administration.SPFeatureDefinition

Microsoft.SharePoint.Administration.SPFeatureDefinitionCollection

安装feature

     每个服务器场都有一个SPFeatureDefinitionCollection的对象属性,名称为FeatureDefinitions,该集合包含当前服务器场中所有的Feature定义。

     如果需要向服务器场安装一个新的自定义Feature,则可以使用如下代码:

(这个代码等同于installfeature 操作)

SPFarm farm = SPFarm.Local;

farm.FeatureDefinitions.Add("MyFeature/feature.xml", Guid.Empty, true);

     其中,第一个参数是相对"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\FEATURES"下的路径,第二个参数是feature对应solution的guid,如果没有就为空,第三个参数说明是否强制安装。

    也就是说,其实向服务器场中安装一个Feature,其实就是在服务器场的SPFeatureDefinitionCollection的对象属性FeatureDefinitions中添加一个新的SPFeatureDefinition对象。这个时候的Feature其实成为SPFeatureDefinition对象,并没有被激活到特定的应用程序、网站集或者网站中。

卸载Feature

     如果需要在服务器场中卸载一个feature,其实只需要把feature从服务器场的FeatureDefinitions集合中删除即可,实现代码如下:

(这个代码等同于uninstallfeature 操作)

   SPFarm farm = SPFarm.Local;

//通过相对路径删除

farm.FeatureDefinitions.Remove("MyFeature/feature.xml", true);

//通过featureID删除

farm.FeatureDefinitions.Remove(fetureid, true);

    可以通过feature定义文件的相对路径删除,或者通过feature的guid删除。

激活或停用feature

激活或者停用feature需要使用除上述对象模型外的如下对象模型:

Microsoft.SharePoint.SPFeature

Microsoft.SharePoint.SPFeatureCollection

在特定的应用程序、网站集、网站激活Feature

     其实,每个应用程序,网站集、网站下都有一个称为Features的SPFeatureCollection属性。

     这里需要特别注意,该集合所储存的只是已经在当前级别(应用程序、网站集、网站)已经激活的Feature,如果没有被激活的Feature,是不储存在该集合的。

     那在特定的范围内激活某个特定的Feature,首先需要在服务器场的FeatureDefinitions中找到需要被激活的SPFeatureDefinition,并且该Feature定义的范围与当前范围相同,再通过特定范围(应用程序、网站集、网站)的Features属性进行添加,代码如下:

(等同于activatefeature操作)

SPFarm farm = SPFarm.Local;

//通过featurename获取一个feature定义:featuredefiniton,也可以通过guid

SPFeatureDefinition featuredefiniton = farm.FeatureDefinitions["featurename"];、

//需要在站点集激活刚才的feature

SPSite site = new SPSite("url");

//判断是否相同范围

if(featuredefiniton.Scope == SPFeatureScope.Site)

{

//判断是否已经在Features集合中,即:是否已经激活

if(site.Features[featuredefiniton.Id]==null)

{

          //在站点集激活feature,其实就是在Features集合中添加一个在服务器场定义的featuredefinition的gu id

site.Features.Add(featuredefiniton.Id);

}

}

在特定的应用程序、网站集、网站停用活Feature

     那其实停用激活就很简单了,只需要在特定范围内(应用程序、网站集、网站)的Features集合内删除对应的SPFeature就可以了:

(等同于deactivatefeature操作)

SPSite site = new SPSite("url");

site.Features.Remove(featureid);

说明

     其实通过Reflector查看stsadm,我们可以看到操作其实是不完全相同的。比如,对于激活一个feature,其实是通过SPFeature.ActivateDeactivateFeatureAtScope这个方法来做的,不过这个方法是内部方法,不对外提供调用的。其实还有很多操作都是内部方法,不对外提供调用。而且,微软在关键的方法都加入了混淆,所以具体实现是看不到的。

     而对外表现出来的就是通过上述我所描述的方法进行Feature操作的:

     在服务器场对象SPFarm定义了名称为FeatureDefinitions 的SPFeatureDefinitionCollection属性,描述了所有安装在服务器场中的feature,这个时候的feature其实是SPFeatureDefinition

     具体的范围(应用程序、网站集合、网站)对象中的名称为FeaturesSPFeatureCollection属性,只定义了本范围(应用程序、网站集合、网站)已经激活的feature。如果需要激活的话,需要从SPFarm的FeatureDefinitions集合中找到定义,并添加到Features集合中,这个时候的feature是一个SPFeature对象(其实SPFeature对象中也包含了SPFeatureDefinition)。

其他对象模型

     除此之外,还有SPFeatureDependency对象模型,可以查看某个feature的依赖项,注意,这里的依赖项是只依赖于,而不是被依赖。

SPFeatureProperty: Feature属性。

================================================================
转载要求及授权协议:
作者
零零猪(or)Jiessie327(or)JiessieLiang 
出处http://jiessie327.cnblogs.com/
版权:本文版权归作者所有
转载:欢迎转载,为了尊重作者的劳动成果,在【转载】时请按作者要求,指明文章【出处】或给出【原文链接】,谢谢
================================================================

请遵守署名-非商业性使用-禁止演绎 2.5 中国大陆 License.
================================================================