功能激活的自定义 Sharepoint-Timer 作业的范围 [英] Scope of a feature activated Custom Sharepoint-Timer Job

查看:51
本文介绍了功能激活的自定义 Sharepoint-Timer 作业的范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在使用 SPJobDefinition 为共享点开发自定义计时器作业.

So I'm developing a custom timer job for sharepoint using the SPJobDefinition.

此作业是通过功能接收器激活的.

This job is activated through a feature receiver.

据我所知,SPJobDefinition 在网络应用程序上运行.

As I understand it the SPJobDefinition runs on the web-application.

如果功能范围是基于站点或网络的,是否有任何代码方式来确定在客户作业中通过哪个站点激活该功能?

if the feature scope is site or web based, is there any way code-wise to determine which site the feature is activated through in the Customer Job?

为了更清楚地了解我要实现的目标,作业本身是一个自定义的提醒我"通知作业.我想要做的是能够确定哪些网站已激活此功能,从而确定哪些网站订阅警报通知.

To get a clearer picture of what I'm trying to achieve, the job itself is a custom "Alert Me" notification job. What I'd like to do, is be able to determine which sites have activated this feature, so as to determine which sites to subscribe to the alerts notifications.

但我不知道如何确定哪些网站激活了此功能.

But I have no idea how to determine which sites have this feature activated.

非常感谢任何帮助.

推荐答案

以下是我用来完成您所描述的操作的代码:

Below is code I've used to do just what you are describing:

    public override void Execute(Guid targetInstanceId)
    {
        foreach (SPSite site in this.WebApplication.Sites)
        {
            try
            {
                if (SPSite.Exists(new Uri(site.Url)) && null != site.Features[FeatureId.AlertMeJob])
                {
                    try
                    {
                        ExecuteJob(site);
                    }
                    catch (Exception ex)
                    {
                        // handle exception
                    }
                }
            }
            finally
            {
                site.Dispose();
            }
        }
    }

FeatureId.AlertMeJob 是一个 GUID,表示具有创建作业计划的功能接收器(如果它不存在)的功能.

FeatureId.AlertMeJob is a GUID representing the Feature with the Feature Receiver that creates the job schedule (if it didn't already exist).

这篇关于功能激活的自定义 Sharepoint-Timer 作业的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆