ChainStoreWeb.Services.AppEventReceiver.ProcessEvent C# (CSharp) Method

ProcessEvent() public method

Handles app events that occur after the app is installed or upgraded, or when app is being uninstalled.
public ProcessEvent ( SPRemoteEventProperties properties ) : SPRemoteEventResult
properties SPRemoteEventProperties Holds information about the app event.
return SPRemoteEventResult
        public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            // The following line is used only once to get the event receiver debugging URL.
            // string debugEndpoint = System.ServiceModel.OperationContext.Current.Channel.LocalAddress.Uri.ToString();

            SPRemoteEventResult result = new SPRemoteEventResult();
            string tenantName = properties.AppEventProperties.HostWebFullUrl.ToString();
            if (!tenantName.EndsWith("/"))
            {
                tenantName += "/";
            }

            switch (properties.EventType)
            {
                case SPRemoteEventType.AppInstalled:

                    try
                    {
                        CreateTenant(tenantName);
                    }
                    catch (Exception e)
                    {
                        // Tell SharePoint to cancel and roll back the event.
                        result.ErrorMessage = e.Message;
                        result.Status = SPRemoteEventServiceStatus.CancelWithError;
                    }

                    break;
                case SPRemoteEventType.AppUpgraded:
                    // This sample does not implement an add-in upgrade handler.
                    break;
                case SPRemoteEventType.AppUninstalling:

                    try
                    {
                        DeleteTenant(tenantName);
                    }
                    catch (Exception e)
                    {
                        // Tell SharePoint to cancel and roll back the event.
                        result.ErrorMessage = e.Message;
                        result.Status = SPRemoteEventServiceStatus.CancelWithError;
                    }

                    break;
            }

            return result;
        }