26

Spca2014 debugging remote event receivers van hunen

  • Upload
    nccomms

  • View
    229

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Spca2014 debugging remote event receivers van hunen
Page 2: Spca2014 debugging remote event receivers van hunen

Debugging Remote Event Receivers

#SPCon14

Page 3: Spca2014 debugging remote event receivers van hunen

@ME

• 20 years of industry experience

• Both Dutch and Swedish nationality

• Living in Stockholm, Sweden

• MCSM, MCM, MCT, MCSE, MCSD, MCSA, MCPD, MCITP, MCTS certifications

• Knowit AB

[email protected]

@erwinvanhunen

se.linkedin.com/in/erwinvanhunen

Page 4: Spca2014 debugging remote event receivers van hunen

HANDS UP!

Who is using event receivers today?

Page 5: Spca2014 debugging remote event receivers van hunen

ACS

Users

External System

Custom Web Service

SharePoint

1. User updates SharePoint list

3. Registered event receiver called

2. SharePoint requests a token from ACS

4. Line of business system is updated

5. Event receiver returns

https://github.com/OfficeDev/PnP/blob/master/Documentation/O365DevPnP%20-%20Site%20Provisioning.pptx

Page 6: Spca2014 debugging remote event receivers van hunen

ACS

Users

External System

Custom Web Service

SharePoint

1. User updates SharePoint list

3. Registered event receiver called

2. SharePoint requests a token from ACS

4. Line of business system is updated

6. Event receiver calls back into SharePoint

5. Event receiver requests a token from ACS

https://github.com/OfficeDev/PnP/blob/master/Documentation/O365DevPnP%20-%20Site%20Provisioning.pptx

Page 7: Spca2014 debugging remote event receivers van hunen

A BIT OF THEORY

ASYNCHRONOUS SYNCHRONOUS

• ‘Before’ events

• ItemAdding

• ItemUpdating

• ItemDeleting

• ‘After’ events

• ItemAdded

• ItemUpdated

• ItemDeleted

Page 8: Spca2014 debugging remote event receivers van hunen

SYNCHRONOUS EVENTS

CAN BE CANCELLED

NOT FOR LONG

RUNNING TASKS

• Cancel with no error

• Cancel with error

• Cancel with redirect

Page 9: Spca2014 debugging remote event receivers van hunen

ASYNCHRONOUS EVENTS

CANNOT BE CANCELLED

NOT FOR LONG

RUNNING TASKS

• At least not with a way to inform the user

Page 10: Spca2014 debugging remote event receivers van hunen

EVENTS

ItemAddingItemUpdatingItemDeletingItemCheckingInItemCheckingOutItemUncheckingOutItemAttachmentAddingItemAttachmentDeletingItemFileMovingItemVersionDeleting

FieldAddingFieldUpdatingFieldDeletingListAddingListDeletingSiteDeletingWebDeletingWebMovingWebAddingGroupAddingGroupUpdatingGroupDeletingGroupUserAddingGroupUserDeletingRoleDefinitionAddingRoleDefinitionUpdatingRoleDefinitionDeleting

RoleAssignmentAddingRoleAssignmentDeletingInheritanceBreakingInheritanceResettingItemAddedItemUpdatedItemDeletedItemCheckedInItemCheckedOutItemUncheckedOutItemAttachmentAddedItemAttachmentDeletedItemFileMovedItemFileConvertedItemVersionDeletedFieldAddedFieldUpdatedFieldDeletedListAddedListDeletedSiteDeletedWebDeleted

WebMovedWebProvisionedWebRestoredGroupAddedGroupUpdatedGroupDeletedGroupUserAddedGroupUserDeletedRoleDefinitionAddedRoleDefinitionUpdatedRoleDefinitionDeletedRoleAssignmentAddedRoleAssignmentDeletedInheritanceBrokenInheritanceResetEntityInstanceAddedEntityInstanceUpdatedEntityInstanceDeletedAppInstalledAppUpgradedAppUninstalling

Page 11: Spca2014 debugging remote event receivers van hunen

APP EVENTS APPINSTALLED APPUPGRADED APPUNINSTALLING

• Executed when the app is installed in a site

• Caveat: when using push installations the event will only run once!

• Executed when the user decides to upgrade the app

• Executed when the user decides to uninstall the app

• While debugging, make sure that the webservice/app is up and running

Page 12: Spca2014 debugging remote event receivers van hunen

GOOD TO KNOW!

Events might be called several times

App events need to respond within a certain timeout. If no answer, the server will retry.

You have to handle that in your code, e.g. keep state, check if artifacts already exist before trying to create them, etc.

Page 13: Spca2014 debugging remote event receivers van hunen

DEMO SITE MODIFIER

Page 14: Spca2014 debugging remote event receivers van hunen

PATTERNAPP

INSTALLATION PATTERN

Page 15: Spca2014 debugging remote event receivers van hunen

APP INSTALLATION PATTERN

APP HANDLES APPINSTALLED

EVENT

APP REGISTERS

ADDITIONAL EVEN

RECEIVERS

SAME WEBSERVICE

THAT HANDLES ALL

EVENTS

Page 16: Spca2014 debugging remote event receivers van hunen

DEMO APP INSTALLATION PATTERN

Page 17: Spca2014 debugging remote event receivers van hunen

CAVEAT

Custom events registered through the object model that do not reside in an app will not receive a context

• Create an App Only context

Page 18: Spca2014 debugging remote event receivers van hunen

DEBUGGING

Page 19: Spca2014 debugging remote event receivers van hunen

SharePoint Online

LIST Developer Machine

https://tenant.sharepoint.com https://localhost:44300

XAzureServiceBus

Page 20: Spca2014 debugging remote event receivers van hunen

Azure ServiceBus

LOCALHOST

EVENT RECEIVER URLS ARE BEING

REPLACED DURING

DEPLOYMENT

• Localhost is a different server to SharePoint Online

• Make sure to disable the usage of Azure ServiceBus to debug when going live.

Page 21: Spca2014 debugging remote event receivers van hunen

Azure ServiceBus

ACS AUTHENTICATION

NEEDED

ONLY DEFAULT ON SB

INSTANCES CREATED

BEFORE AUGUST 2014

Create new Azure SB instance:

New-AzureSPNamespace –Name <yoursbname>–Location “<location>” –CreateACSNamespace

Location = Northern Europe, Western Europe etc.

Page 22: Spca2014 debugging remote event receivers van hunen

https://github.com/officedev/pnp

Page 23: Spca2014 debugging remote event receivers van hunen

CMDLETS

Get-SPOEventReceiver

[-List [<ListPipeBind>]]

[-Identity [<GuidPipeBind>]]

[-Web [<WebPipeBind>]]

Page 24: Spca2014 debugging remote event receivers van hunen

CMDLETS

Add-SPOEventReceiver

-List [<ListPipeBind>]

-Name [<String>] -Url [<String>]

-EventReceiverType [<EventReceiverType>]

-Synchronization [<EventReceiverSynchronization>]

[-SequenceNumber [<Int32>]]

[-Force [<SwitchParameter>]]

[-Web [<WebPipeBind>]]

Page 25: Spca2014 debugging remote event receivers van hunen

CMDLETS

Remove-SPOEventReceiver

[-List [<ListPipeBind>]]

-Identity [<GuidPipeBind>]

[-Force [<SwitchParameter>]]

[-Web [<WebPipeBind>]]

Page 26: Spca2014 debugging remote event receivers van hunen