WhatsApp을 설치할 때 이벤트 수신기가 추가되지 않습니다
-
10-12-2019 - |
문제
SharePoint 2010 콘텐츠 유형 및 라이브러리에 대한 이벤트 수신기 세트가 있습니다. 이전에는 WSP 솔루션을 설치할 스크립트를 실행할 때 설치가 자동으로 활성화됩니다. 그러나 나는 이것을하는 다른 방식을 파고, 이제는 Visual Studio에서 디버그 모드로 솔루션을 실행할 때 적절하게 설치 될 것이지만, 앞서 언급 한 전원 쉘 스크립트를 실행할 때 설치하지 않을 것입니다. 사이트에서 확인하고 기능이 활성화되었지만 수행 한 후에는 SPM을 사용하여 이벤트 수신기를 보지 못했습니다.
이벤트 수신기 Elements.xml :
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Receivers ListTemplateId="101">
<Receiver>
<Name>EventReceiverItemCheckedIn</Name>
<Type>ItemCheckedIn</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>SharePointFeatures.EventReceiver.EventReceiver</Class>
<SequenceNumber>1000</SequenceNumber>
</Receiver>
<Receiver>
<Name>EventReceiverItemCheckingIn</Name>
<Type>ItemCheckingIn</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>SharePointFeatures.EventReceiver.EventReceiver</Class>
<SequenceNumber>1001</SequenceNumber>
</Receiver>
<Receiver>
<Name>EventReceiverItemUpdated</Name>
<Type>ItemUpdated</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>SharePointFeatures.EventReceiver.EventReceiver</Class>
<SequenceNumber>1002</SequenceNumber>
</Receiver>
<Receiver>
<Name>EventReceiverItemUpdating</Name>
<Type>ItemUpdating</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>harePointFeatures.EventReceiver.EventReceiver</Class>
<SequenceNumber>1003</SequenceNumber>
</Receiver>
<Receiver>
<Name>EventReceiverItemDeleting</Name>
<Type>ItemDeleting</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>SharePointFeatures.EventReceiver.EventReceiver</Class>
<SequenceNumber>1004</SequenceNumber>
</Receiver>
</Receivers>
</Elements>
.
기능 template.xml :
<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/">
<Properties>
<Property Key="GloballyAvailable" Value="true"/>
<Property Key="AssemblyQualifiedName" Value="$SharePoint.Type.800d2e40-4c00-4517-9ff4-d11da11b6826.AssemblyQualifiedName$"/>
<Property Key="AssemblyFullName" Value="$SharePoint.Project.AssemblyFullName$"/>
</Properties>
</Feature>
.
기능 수신기 코드 :
[Guid("fbe26e13-dba2-4fe6-b947-9f2c34accd39")]
public class FeaturesEventReceiver : SPFeatureReceiver
{
private string EventReceiverClassName;
private string AssemblyFullName;
/// <summary>
/// Feature activated logic
/// </summary>
/// <param name="properties"></param>
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
try
{
SPWeb web = properties.Feature.Parent as SPWeb;
//di-associate EventReceiver from Print only content type
SetAssemblyParams(properties.Feature.Properties);
DisableEventReceiver(web);
//associate EventReceiver to content type as defined in configuration <activefields sharepointcontenttypename="Print Only">
FmiMetadataMappingHandler mappingHandler = WebConfigurationManager.OpenWebConfiguration("/", web.Site.WebApplication.Name).GetSection(Utils.GetConfigSectionNameForWeb(web)) as FmiMetadataMappingHandler;
SPContentType ct = web.ContentTypes[mappingHandler.ActiveFields.SharepointContentTypeName];
if (ct != null)
{
SPEventReceiverDefinition def = ct.EventReceivers.Add();
def.Name = "EventReceiverItemCheckingIn";
def.Type = SPEventReceiverType.ItemCheckingIn;
def.SequenceNumber = 1000;
def.Assembly = AssemblyFullName;
def.Class = EventReceiverClassName;
def.Update();
// bind event receiver to ItemCheckedIn Event
def = ct.EventReceivers.Add();
def.Name = "EventReceiverItemCheckedIn";
def.Type = SPEventReceiverType.ItemCheckedIn;
def.SequenceNumber = 1001;
def.Assembly = AssemblyFullName;
def.Class = EventReceiverClassName;
def.Update();
// bind event receiver to ItemUpdated Event
def = ct.EventReceivers.Add();
def.Name = "EventReceiverItemUpdated";
def.Type = SPEventReceiverType.ItemUpdated;
def.SequenceNumber = 1002;
def.Assembly = AssemblyFullName;
def.Class = EventReceiverClassName;
def.Update();
// bind event receiver to ItemUpdating Event
def = ct.EventReceivers.Add();
def.Name = "EventReceiverItemUpdating";
def.Type = SPEventReceiverType.ItemUpdating;
def.SequenceNumber = 1003;
def.Assembly = AssemblyFullName;
def.Class = EventReceiverClassName;
def.Update();
// bind event receiver to ItemDeleting Event
def = ct.EventReceivers.Add();
def.Name = "CWTEventReceiverItemDeleting";
def.Type = SPEventReceiverType.ItemDeleting;
def.SequenceNumber = 1004;
def.Assembly = AssemblyFullName;
def.Class = EventReceiverClassName;
def.Update();
//update content type with event receiver
ct.Update(true);
Utils.LogMessage("CWT Feature Event Receivers added successfully.");
}
}
catch (Exception ex)
{
Utils.LogError(ex.Message, ex.StackTrace);
}
}
private void SetAssemblyParams(SPFeaturePropertyCollection properties)
{
EventReceiverClassName = properties["AssemblyQualifiedName"].Value;
AssemblyFullName = properties["AssemblyFullName"].Value;
}// end SetAssemblyParams
/// <summary>
/// feature deactivating
/// </summary>
/// <param name="properties"></param>
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SetAssemblyParams(properties.Feature.Properties);
DisableEventReceiver(properties.Feature.Parent as SPWeb);
}
/// <summary>
/// di-associate event receiver from content type
/// </summary>
/// <param name="web"></param>
private void DisableEventReceiver(SPWeb web)
{
try
{
FmiMetadataMappingHandler mappingHandler = WebConfigurationManager.OpenWebConfiguration("/", web.Site.WebApplication.Name).GetSection(Utils.GetConfigSectionNameForWeb(web)) as FmiMetadataMappingHandler;
SPContentType ct = web.ContentTypes[mappingHandler.ActiveFields.SharepointContentTypeName];
string errMsg = string.Empty;
if (ct == null)
{
errMsg = string.Format("{0} has not been created in web {1} ", mappingHandler.ActiveFields.SharepointContentTypeName, web.Title);
Utils.LogError(errMsg);
throw new Exception(errMsg);
}
if (ct != null)
{
SPEventReceiverDefinition[] fmiEvents = new SPEventReceiverDefinition[ct.EventReceivers.Count];
ct.EventReceivers.CopyTo(fmiEvents, 0);
for (int i = 0; i < fmiEvents.Length; i++)
{
if (fmiEvents[i].Class.Equals(EventReceiverClassName, StringComparison.CurrentCultureIgnoreCase))
{
fmiEvents[i].Delete();
Utils.LogError("cwt receiver removed");
}
}
ct.Update(true);
// web.Update();
}
}
catch (Exception ex)
{
Utils.LogError(ex.Message);
}
}
.
* 갱신 *
이제 디버그 모드에서도 설치되지 않습니다. 로그를 살펴보고 설치의 "FeatureAtivated"부분 중에 오류가 발생합니다. 나는 FeatureActivated 및 FeatureDeAtivating에서 시도 / 캐치를 제외한 모든 코드를 제외한 모든 코드를 모두 논평했으며 여전히이 오류가 발생합니다.
오류 메시지 : Type names passed to Assembly.GetType() must not specify an assembly.
해결책
I am still not sure what the problem was, but I made it go away. Maybe this is the real solution I was looking for, I do not know. At any rate, I went through the motions commenting out all of my code except for the actual event handler methods themselves. I then tried running the solution in debug mode. No dice. At that point I basically knew it couldn't have been anything I was really doing (it could have but I "knew" it). So, on a hunch, I rebuilt the solution and packaged it, THEN ran it in debug mode. Voila. I then systematically re-added the various code pieces starting with the feature receiver code and everything has been deploying since. I do, however, continue to package first to prevent my original issue from happening again. I am not sure that's absolutely necessary but it's easier than running into that same problem again.