< NotificationHandlerAssembly > AlertHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d59ecf2a3bd66904 </ NotificationHandlerAssembly >
< NotificationHandlerClassName > AlertHandler.Class1 </ NotificationHandlerClassName >
< NotificationHandlerProperties ></ NotificationHandlerProperties >
* This source code was highlighted with Source Code Highlighter .
< Properties >
< ImmediateNotificationExcludedFields > ID;Author;Editor;Modified_x0020_By;Created_x0020_By;_UIVersionString;ContentType;TaskGroup;IsCurrent;Attachments;NumComments; </ ImmediateNotificationExcludedFields >
< DigestNotificationExcludedFields > ID;Author;Editor;Modified_x0020_By;Created_x0020_By;_UIVersionString;ContentType;TaskGroup;IsCurrent;Attachments;NumComments; </ DigestNotificationExcludedFields >
< NotificationHandlerAssembly > AlertHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d59ecf2a3bd66904 </ NotificationHandlerAssembly >
< NotificationHandlerClassName > AlertHandler.Class1 </ NotificationHandlerClassName >
< NotificationHandlerProperties ></ NotificationHandlerProperties >
</ Properties >
* This source code was highlighted with Source Code Highlighter .
< AlertTemplate Type ="Custom" Name ="OSS.Search" AlwaysNotify ="True" DefaultTitle ="Search" >
< EventTypes IsVisible ="True" >
< EventType Mask ="0x1" Selected ="true" > $Resources:Microsoft.Office.Server.Search,SearchResults_ATEventDiscovered; </ EventType >
< EventType Mask ="0x2" > $Resources:Microsoft.Office.Server.Search,SearchResults_ATEventModified; </ EventType >
< EventType Mask ="0x3" > $Resources:Microsoft.Office.Server.Search,SearchResults_ATEventAll; </ EventType >
</ EventTypes >
< Frequency IsVisible ="true" ShowImmediate ="false" ShowDaily ="true" ShowWeekly ="true" ShowTime ="false" DefaultFrequency ="Daily" />
< Filters IsVisible ="false" />
< Properties >
< NotificationHandlerAssembly > mySearchAlert, Version=1.0.0.0, Culture=neutral, PublicKeyToken=aa1e89f3cc0ef56b </ NotificationHandlerAssembly >
< NotificationHandlerClassName > mySearchAlert.MySearchAlertHandler </ NotificationHandlerClassName >
< NotificationHandlerProperties ></ NotificationHandlerProperties >
< UpdateHandlerAssembly > mySearchAlert, Version=1.0.0.0, Culture=neutral, PublicKeyToken=aa1e89f3cc0ef56b </ UpdateHandlerAssembly >
< UpdateHandlerClassName > mySearchAlert.MySearchUpdateAlertHandler </ UpdateHandlerClassName >
< UpdateHandlerProperties ></ UpdateHandlerProperties >
</ Properties >
</ AlertTemplate >
* This source code was highlighted with Source Code Highlighter .
< AlertTemplate Type ="Custom" Name ="OSS.Search" AlwaysNotify ="True" DefaultTitle ="Search" >
< EventTypes IsVisible ="True" >
< EventType Mask ="0x1" Selected ="true" > $Resources:Microsoft.Office.Server.Search,SearchResults_ATEventDiscovered; </ EventType >
< EventType Mask ="0x2" > $Resources:Microsoft.Office.Server.Search,SearchResults_ATEventModified; </ EventType >
< EventType Mask ="0x3" > $Resources:Microsoft.Office.Server.Search,SearchResults_ATEventAll; </ EventType >
</ EventTypes >
< Frequency IsVisible ="true" ShowImmediate ="false" ShowDaily ="true" ShowWeekly ="true" ShowTime ="false" DefaultFrequency ="Daily" />
< Filters IsVisible ="false" />
< Properties >
< NotificationHandlerAssembly > Microsoft.Office.Server.Search, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c </ NotificationHandlerAssembly >
< NotificationHandlerClassName > Microsoft.Office.Server.Search.Query.SearchAlertHandler </ NotificationHandlerClassName >
< NotificationHandlerProperties ></ NotificationHandlerProperties >
< UpdateHandlerAssembly > Microsoft.Office.Server.Search, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c </ UpdateHandlerAssembly >
< UpdateHandlerClassName > Microsoft.Office.Server.Search.Query.SearchAlertHandler </ UpdateHandlerClassName >
< UpdateHandlerProperties ></ UpdateHandlerProperties >
</ Properties >
</ AlertTemplate >
* This source code was highlighted with Source Code Highlighter .
public class MySearchAlertHandler : IAlertNotifyHandler
//
public bool OnNotification(SPAlertHandlerParams alertHandler)
{
...
return CustomAlertNotification(alertHandler);
...
}
public bool CustomAlertNotification(SPAlertHandlerParams alertHandlerParams)
{
string myBody = "" ;
SPSite site = null ;
int searchAlertNotificationQuota = 200;
TimeSpan span;
SPAlert a = alertHandlerParams.a;
site = new SPSite(alertHandlerParams.siteUrl+ alertHandlerParams.webUrl;);
// alertTime span
DateTime alertTime = a.AlertTime;
if (a.AlertFrequency == SPAlertFrequency.Weekly)
{
span = TimeSpan .FromDays(7.0);
}
else
{
span = TimeSpan .FromDays(1.0);
}
if ((alertTime + span) <= DateTime .Now)
{
return true ;
}
using (SPWeb web = site.OpenWeb())
{
// ( ) queryText
string queryText = Utils.GetValueFromXML(a.Properties[ "p_query" ], "QueryText" );
SPSite s1 = new SPSite (alertHandlerParams.siteUrl+alertHandlerParams.webUrl );
Query q1 = new KeywordQuery(s1);
q1.QueryText = queryText;
// alert2,
SearchAlert alert2 = new SearchAlert(s1,q1);
alert2.ChangeType = AlertChangeType.DiscoveredOrModified;
alert2.InnerAlert.AlertFrequency = alertHandlerParams.a.AlertFrequency ;
alert2.InnerAlert.Title = "Temp#1" ;
alert2.InnerAlert.EventType = alertHandlerParams.a.EventType;
alert2.InnerAlert.User = s1.OpenWeb().CurrentUser ;
alert2.InnerAlert.AlertType = alertHandlerParams.a.AlertType;
alert2.Update();
// query alert2 queryText
using (Microsoft.Office.Server.Search.Query.Query query = alert2.CreateSearchQuery ())
{
ResultTableCollection tables;
query.QueryText = queryText;
query.RowLimit = searchAlertNotificationQuota;
query.TrimDuplicates = false ;
// , , , .
, Reflection internal AlertInfo query, LastUpdateTime
AlertInfo ai = new AlertInfo();
ai.ChangeType = alert2.ChangeType;
ai.LastUpdateTime = alertTime - span;
Type t1 = query.GetType();
if (t1.GetProperty( "AlertInfo" , System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance) == null )
throw new ArgumentOutOfRangeException( "propName" , string .Format( "Property {0} was not found in Type {1}" ,
"AlertInfo" , query.GetType().FullName));
t1.InvokeMember( "AlertInfo" , System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.SetProperty |
System.Reflection.BindingFlags.Instance, null , query, new object [] { ai });
// query
ResultTable result = null ;
try
{
tables = query.Execute();
}
catch
{
alert2.Delete();
return false ;
}
result = tables[ResultType.RelevantResults];
// result - alert2 -
alert2.Delete();
// DataTable . - WorkId, Rank, Title, Author, Size, Path, Description, Write, SiteName, CollapsingStatus, HitHighlightedSummary, HitHighlightedProperties, ContentClass, IsDocument, PictureThumbnailURL
// DiscoveredTime
System.Data.DataTable myTable = new System.Data.DataTable();
myTable.Load(result2, System.Data.LoadOption.OverwriteChanges);
foreach (System.Data.DataRow myrow in myTable.Rows)
{
if ( Convert .ToDateTime(myrow[ "DiscoveredTime" ]) > alertTime - span)
{
//
}
else
{
//
}
}
// , SQL, FullTextSqlQuery
FullTextSqlQuery fts = new FullTextSqlQuery(site2);
fts.QueryText = "SELECT WorkId, Rank, Title, Author, Size, Path, Description, Write, SiteName, CollapsingStatus, HitHighlightedSummary, HitHighlightedProperties, ContentClass, IsDocument, PictureThumbnailURL, PopularSocialTags, PictureWidth, PictureHeight, DatePictureTaken, ServerRedirectedURL, ErgebnisKenntnis, LetzterKontakt, Kandidatenmail FROM SCOPE() WHERE Path='" + myrow[ "Path" ].ToString() + "'" ;
fts.ResultTypes = ResultType.RelevantResults;
fts.RowLimit = 300;
ResultTableCollection rtc = fts.Execute();
* This source code was highlighted with Source Code Highlighter .
SPUtility.SendEmail(web, false , false , string .Format( "{0}" , alertHandlerParams.headers[ "To" ]),
string .Format( "{0}" , alertHandlerParams.headers[ "Subject" ]), myBody);
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/123863/
All Articles