private void HandleAppInstalled(SPRemoteEventProperties properties) { using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, false)) { if (clientContext != null) { List myList = clientContext.Web.Lists.GetByTitle(ListName); clientContext.Load(myList, p => p.EventReceivers); clientContext.ExecuteQuery(); bool rerExists = false; foreach (var rer in myList.EventReceivers) { if (rer.ReceiverName == ReceiverName) { rerExists = true; System.Diagnostics.Trace.WriteLine("Found existing ItemAdded receiver at " + rer.ReceiverUrl); } } if (!rerExists) { EventReceiverDefinitionCreationInformation receiver = new EventReceiverDefinitionCreationInformation(); receiver.EventType = EventReceiverType.ItemAdded; //Get WCF URL where this message was handled OperationContext op = OperationContext.Current; Message msg = op.RequestContext.RequestMessage; receiver.ReceiverUrl = msg.Headers.To.ToString(); receiver.ReceiverName = ReceiverName; receiver.Synchronization = EventReceiverSynchronization.Synchronous; myList.EventReceivers.Add(receiver); clientContext.ExecuteQuery(); System.Diagnostics.Trace.WriteLine("Added ItemAdded receiver at " + msg.Headers.To.ToString()); } } } }
private void HandleAppUninstalling(SPRemoteEventProperties properties) { using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, false)) { if (clientContext != null) { List myList = clientContext.Web.Lists.GetByTitle(ListName); clientContext.Load(myList, p => p.EventReceivers); clientContext.ExecuteQuery(); var rer = myList.EventReceivers.Where(e => e.ReceiverName == ReceiverName).FirstOrDefault(); try { System.Diagnostics.Trace.WriteLine("Removing ItemAdded receiver at " + rer.ReceiverUrl); //This will fail when deploying via F5, but works //when deployed to production rer.DeleteObject(); clientContext.ExecuteQuery(); } catch (Exception oops) { System.Diagnostics.Trace.WriteLine(oops.Message); } } } }
/// <summary> /// Handles app events that occur after the app is installed or upgraded, or when app is being uninstalled. /// </summary> /// <param name="properties">Holds information about the app event.</param> /// <returns>Holds information returned from the app event.</returns> public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties) { SPRemoteEventResult result = new SPRemoteEventResult(); helper.Logger.LogInfo("ProcessEvent - {0}", () => { using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, useAppWeb: false)) { if (clientContext != null) { if (properties.EventType == SPRemoteEventType.AppInstalled) { // Create the default demo document library and view. helper.SPAppHelper.Instance.CreateDocumentLibrary(clientContext, Controllers.HomeController.DEFAULT_LIBNAME); helper.SPAppHelper.Instance.CreateListView(clientContext, Controllers.HomeController.DEFAULT_LIBNAME, Controllers.HomeController.DEFAULT_VIEWNAME); helper.SPAppHelper.Instance.CreateSitePage(clientContext, Controllers.HomeController.DEFAULT_PAGENAME, Controllers.HomeController.DEFAULT_LIBNAME); } else if (properties.EventType == SPRemoteEventType.AppUninstalling) { helper.SPAppHelper.Instance.RemoveDocumentLibrary(clientContext, Controllers.HomeController.DEFAULT_LIBNAME); helper.SPAppHelper.Instance.RemoveSitePage(clientContext, Controllers.HomeController.DEFAULT_PAGENAME); } } } }, properties.EventType.ToString()); return(result); }
public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties) { TraceHelper.RemoteLog("app event triggered: " + properties.EventType.ToString()); SPRemoteEventResult result = new SPRemoteEventResult(); using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, false)) { if (clientContext != null) { clientContext.Load(clientContext.Web); clientContext.Load(clientContext.Web.SiteUsers); clientContext.ExecuteQuery(); RegisterEventReceivers(clientContext); PlaybasisHelper.Instance.Auth(); foreach (var user in clientContext.Web.SiteUsers) { if (string.IsNullOrWhiteSpace(user.Email)) { continue; } PlaybasisHelper.Instance.Register(user, true); } } } return(result); }
/// <summary> /// Handles app events that occur after the app is installed or upgraded, or when app is being uninstalled. /// </summary> /// <param name="properties">Holds information about the app event.</param> /// <returns>Holds information returned from the app event.</returns> public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties) { SPRemoteEventResult result = new SPRemoteEventResult(); if (properties.EventType == SPRemoteEventType.ItemAdded || properties.EventType == SPRemoteEventType.ItemUpdated) { using (ClientContext ctx = TokenHelper.CreateRemoteEventReceiverClientContext(properties)) { Helpers.CreateFullNameHelper.CombineName(properties.ItemEventProperties.ListItemId, ctx); } } using (ClientContext ctx = TokenHelper.CreateAppEventClientContext(properties, useAppWeb: false)) { if (ctx != null) { if (properties.EventType == SPRemoteEventType.AppInstalled) { Helpers.AppEventHelper.Install(ctx); } if (properties.EventType == SPRemoteEventType.AppUninstalling) { Helpers.AppEventHelper.UnInstall(ctx); } } } return(result); }
public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties) { SPRemoteEventResult result = new SPRemoteEventResult(); using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, false)) { if (clientContext != null) { clientContext.Load(clientContext.Web); clientContext.ExecuteQuery(); var requestProperty = (System.ServiceModel.Channels.HttpRequestMessageProperty)System.ServiceModel.OperationContext.Current.IncomingMessageProperties[System.ServiceModel.Channels.HttpRequestMessageProperty.Name]; string opContext = System.ServiceModel.OperationContext.Current.Channel.LocalAddress.Uri.AbsoluteUri.Substring(0, System.ServiceModel.OperationContext.Current.Channel.LocalAddress.Uri.AbsoluteUri.LastIndexOf("/")); string remoteUrl = string.Format("{0}/CreateSite.svc", opContext); //string remoteUrl = string.Format("{0}/CreateSite2.svc", System.ServiceModel.OperationContext.Current.Channel.LocalAddress.Uri.DnsSafeHost + "/services"); var appWebUrl = "https://" + requestProperty.Headers[System.Net.HttpRequestHeader.Host]; List createSiteRequests = clientContext.Web.Lists.GetByTitle("SiteCreationRequests"); if (properties.EventType == SPRemoteEventType.AppInstalled) { EventReceiverDefinitionCreationInformation newEventReceiver = new EventReceiverDefinitionCreationInformation() { EventType = EventReceiverType.ItemUpdated, ReceiverName = "CreateSite", ReceiverUrl = remoteUrl, SequenceNumber = 1000 //Should be higher number if lower priority, particularly for async events }; createSiteRequests.EventReceivers.Add(newEventReceiver); clientContext.ExecuteQuery(); } } } return(result); }
/// <summary> /// Handles app events that occur after the app is installed or upgraded, or when app is being uninstalled. /// </summary> /// <param name="properties">Holds information about the app event.</param> /// <returns>Holds information returned from the app event.</returns> public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties) { SPRemoteEventResult result = new SPRemoteEventResult(); using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, useAppWeb: false)) { if (clientContext != null) { clientContext.Load(clientContext.Web); clientContext.ExecuteQuery(); switch (properties.EventType) { case SPRemoteEventType.AppInstalled: RemoveQuickLaunchNode(clientContext); AddSiteInformationJsLink(clientContext); result.Status = SPRemoteEventServiceStatus.Continue; break; case SPRemoteEventType.AppUninstalling: RemoveQuickLaunchNode(clientContext); Web web = clientContext.Web; clientContext.Load(web, w => w.UserCustomActions, w => w.Url, w => w.AppInstanceId); clientContext.ExecuteQuery(); DeleteExistingActions(clientContext, web); break; } } } return(result); }
private Guid CreateList(String listTitle, SPRemoteEventProperties properties) { Guid listID = Guid.Empty; using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, useAppWeb: false)) { if (clientContext != null) { // SharePoint might be retrying the event after a time-out. It // may have created the list on the last try of this handler, so // check to see if there's already a list with that name. List targetList = GetListByTitle(listTitle, clientContext); // If there isn't one, create it. if (targetList == null) { ListCreationInformation listInfo = new ListCreationInformation(); listInfo.Title = listTitle; listInfo.TemplateType = (int)ListTemplateType.GenericList; listInfo.Url = listTitle; targetList = clientContext.Web.Lists.Add(listInfo); clientContext.Load(targetList, l => l.Id); clientContext.ExecuteQuery(); listID = targetList.Id; } } } return(listID); }
public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties) { using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, useAppWeb: false)) { PrepareHostWeb(clientContext); } return(new SPRemoteEventResult()); }
/// <summary> /// Handles app events that occur after the app is installed or upgraded, or when app is being uninstalled. /// </summary> /// <param name="properties">Holds information about the app event.</param> /// <returns>Holds information returned from the app event.</returns> public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties) { var result = new SPRemoteEventResult(); Logger.Logger.LogInfo("ProcessEvent called for AppEventReceiver", () => { using (var clientContext = TokenHelper.CreateAppEventClientContext(properties, false)) { switch (properties.EventType) { case SPRemoteEventType.AppInstalled: // Remove any old RER first. AppHelper.UnregisterRemoteEvents(clientContext); // Install a RER for the App Catalog. AppHelper.RegisterRemoteEvents(clientContext); // Iterate existing apps and process them. AppHelper.ProcessAppList(clientContext); break; case SPRemoteEventType.AppUninstalling: // Remove RER from the App Catalog. AppHelper.UnregisterRemoteEvents(clientContext); break; } } }); return(result); }
public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties) { SPRemoteEventResult result = new SPRemoteEventResult(); using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, false)) { if (clientContext != null) { clientContext.Load(clientContext.Web); clientContext.ExecuteQuery(); //List contactList = clientContext.Web.Lists.GetByTitle("GeoContacts"); //EventReceiverDefinitionCreationInformation eventReceiver = new EventReceiverDefinitionCreationInformation(); //eventReceiver.EventType = EventReceiverType.ItemAdding; //eventReceiver.ReceiverAssembly = Assembly.GetExecutingAssembly().FullName; //eventReceiver.ReceiverClass = "GetGeolocationEventReciever"; //eventReceiver.ReceiverName = "GetGeolocationEventReciever"; //eventReceiver.ReceiverUrl = "https://eichlereducation-fd47fd3b494c93.sharepoint.com/sites/geo/GetGeolocationEvent/"; //eventReceiver.SequenceNumber = 1000; //contactList.EventReceivers.Add(eventReceiver); } } return(result); }
void AppUninstalling(SPRemoteEventProperties properties) { LogHelper.Log("The application was uninstalled from " + properties.AppEventProperties.HostWebFullUrl); try { using (ClientContext ctx = TokenHelper.CreateAppEventClientContext(properties, false)) { List <EventReceiverDefinition> events = new List <EventReceiverDefinition>(); var lists = ctx.LoadQuery(ctx.Web.Lists.Where(l => l.BaseType == BaseType.DocumentLibrary).Include( ll => ll.Title, ll => ll.EventReceivers)); ctx.ExecuteQuery(); foreach (var list in lists) { foreach (var ev in list.EventReceivers) { if (ev.ReceiverName.Equals(Constants.ItemAddedEventReceiverName) || ev.ReceiverName.Equals(Constants.FieldDeletedEventReceiverName)) { events.Add(ev); } } } foreach (var eve in events) { eve.DeleteObject(); } ctx.ExecuteQuery(); } } catch (Exception ex) { LogHelper.Log(ex.Message + ex.StackTrace, LogSeverity.Error); throw; } }
public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties) { SPRemoteEventResult result = new SPRemoteEventResult(); if (properties.EventType == SPRemoteEventType.AppInstalled) { using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, false)) { if (clientContext != null) { //Get reference to the host web list by itsname var documentsList = clientContext.Web.Lists.GetByTitle("firstlist"); clientContext.Load(documentsList); clientContext.ExecuteQuery(); string remoteUrl = "http://azurewebappname.azurewebsites.net/Services/RemoteEventReceiver1.svc"; //Create the remote event receiver definition EventReceiverDefinitionCreationInformation newEventReceiver = new EventReceiverDefinitionCreationInformation() { EventType = EventReceiverType.ItemAdded, ReceiverAssembly = Assembly.GetExecutingAssembly().FullName, ReceiverName = "RemoteEventReceiver1", ReceiverClass = "RemoteEventReceiver1", ReceiverUrl = remoteUrl, SequenceNumber = 15000 }; //Add the remote event receiver to the host web list documentsList.EventReceivers.Add(newEventReceiver); clientContext.ExecuteQuery(); } } } else if (properties.EventType == SPRemoteEventType.AppUninstalling) { using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, false)) { var list = clientContext.Web.Lists.GetByTitle("firstlist"); clientContext.Load(list); clientContext.ExecuteQuery(); EventReceiverDefinitionCollection erdc = list.EventReceivers; clientContext.Load(erdc); clientContext.ExecuteQuery(); List <EventReceiverDefinition> toDelete = new List <EventReceiverDefinition>(); foreach (EventReceiverDefinition erd in erdc) { if (erd.ReceiverName == "RemoteEventReceiver1") { toDelete.Add(erd); } } //Delete the remote event receiver from the list, when the app gets uninstalled foreach (EventReceiverDefinition item in toDelete) { item.DeleteObject(); clientContext.ExecuteQuery(); } } } return(result); }
private void HandleAppUnInstall(SPRemoteEventProperties properties) { using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, false)) { this.CleanUp(clientContext); } }
private void HandleAppInstall(SPRemoteEventProperties properties) { using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, false)) { this.CreateSiteRequestList(clientContext); } }
/// <summary> /// Handles when an app is installed. Activates a feature in the /// host web. The feature is not required. /// Next, if the Jobs list is /// not present, creates it. Finally it attaches a remote event /// receiver to the list. /// </summary> /// <param name="properties"></param> private void HandleAppInstalled(SPRemoteEventProperties properties) { using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, false)) { if (clientContext != null) { new RemoteEventReceiverManager().AssociateRemoteEventsToHostWeb(clientContext); } } }
private void AppUninstall(SPRemoteEventProperties properties) { using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, false)) { if (clientContext != null) { SequenceProcessor processor = new SequenceProcessor(); processor.Process(clientContext, false, "ProvisioningSequence.xml"); } } }
/// <summary> /// Removes the remote event receiver from the list and /// adds a new item to the list. /// </summary> /// <param name="properties"></param> private void HandleAppUninstalling(SPRemoteEventProperties properties) { using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, false)) { if (clientContext != null) { new RemoteEventReceiverManager().RemoveEventReceiversFromHostWeb(clientContext); } } }
public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties) { SPRemoteEventResult result = new SPRemoteEventResult(); using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, useAppWeb: false)) { if (clientContext != null) { clientContext.Load(clientContext.Web); string listTitle = "Customers"; // delete list if it exists ExceptionHandlingScope scope = new ExceptionHandlingScope(clientContext); using (scope.StartScope()) { using (scope.StartTry()) { clientContext.Web.Lists.GetByTitle(listTitle).DeleteObject(); } using (scope.StartCatch()) { } } // create and initialize ListCreationInformation object ListCreationInformation listInformation = new ListCreationInformation(); listInformation.Title = listTitle; listInformation.Url = "Lists/Customers"; listInformation.QuickLaunchOption = QuickLaunchOptions.On; listInformation.TemplateType = (int)ListTemplateType.Contacts; // Add ListCreationInformation to lists collection and return list object List list = clientContext.Web.Lists.Add(listInformation); // modify additional list properties and update list.OnQuickLaunch = true; list.EnableAttachments = false; list.Update(); // send command to server to create list clientContext.ExecuteQuery(); // create a sample item in the list var customer1 = list.AddItem(new ListItemCreationInformation()); customer1["FirstName"] = "Mike"; customer1["Title"] = "Fitzmaurice"; customer1["Company"] = "Wingtip Toys"; customer1["WorkPhone"] = "(111)111-1111"; customer1["HomePhone"] = "(222)222-2222"; customer1["Email"] = "*****@*****.**"; customer1.Update(); // send command to server to create item clientContext.ExecuteQuery(); } } return(result); }
static void UnInstall(SPRemoteEventProperties properties) { //CreateAppEventClientContext used for install and uninstall events using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, useAppWeb: false)) { if (clientContext != null) { // Helpers.CalculatorHelper.RemoveCalculator(clientContext); Helpers.CalculatorHelper.RemoveRemoteEventReciver(clientContext); } } }
private void HandleAppInstalled(SPRemoteEventProperties properties) { using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, false)) { if (clientContext != null) { List pdfList = clientContext.Web.Lists.GetByTitle(ListName); clientContext.Load(pdfList, p => p.EventReceivers); clientContext.ExecuteQuery(); foreach (var receiver in pdfList.EventReceivers.Where(receiver => receiver.ReceiverName == ReceiverNameAdded)) { Trace.WriteLine("Found existing ItemAdded receiver at " + receiver.ReceiverUrl); DeleteReceiver(clientContext, receiver); break; } foreach (var receiver in pdfList.EventReceivers.Where(receiver => receiver.ReceiverName == ReceiverNameUpdated)) { Trace.WriteLine("Found existing ItemAdded receiver at " + receiver.ReceiverUrl); DeleteReceiver(clientContext, receiver); break; } Message msg = OperationContext.Current.RequestContext.RequestMessage; EventReceiverDefinitionCreationInformation receiverAdded = new EventReceiverDefinitionCreationInformation { EventType = EventReceiverType.ItemAdded, ReceiverUrl = msg.Headers.To.ToString(), ReceiverName = ReceiverNameAdded, Synchronization = EventReceiverSynchronization.Synchronous }; pdfList.EventReceivers.Add(receiverAdded); clientContext.ExecuteQuery(); Trace.WriteLine("Added ItemAdded receiver at " + msg.Headers.To); EventReceiverDefinitionCreationInformation receiverUpdating = new EventReceiverDefinitionCreationInformation { EventType = EventReceiverType.ItemUpdating, ReceiverUrl = msg.Headers.To.ToString(), ReceiverName = ReceiverNameUpdated, Synchronization = EventReceiverSynchronization.Synchronous }; pdfList.EventReceivers.Add(receiverUpdating); clientContext.ExecuteQuery(); Trace.WriteLine("Added ItemUpdating receiver at " + msg.Headers.To); } } }
/// <summary> /// Handles app events that occur after the app is installed or upgraded, or when app is being uninstalled. /// </summary> /// <param name="properties">Holds information about the app event.</param> /// <returns>Holds information returned from the app event.</returns> public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties) { SPRemoteEventResult result = new SPRemoteEventResult(); using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, useAppWeb: false)) { if (clientContext != null) { clientContext.Load(clientContext.Web); clientContext.ExecuteQuery(); } } return(result); }
private void HandleAppInstalled(SPRemoteEventProperties properties) { using (ClientContext ctx = TokenHelper.CreateAppEventClientContext(properties, false)) { if (ctx != null) { //Add a list to the host web List eventReceiverList = LabHelper.AddList(ctx, ctx.Web, Microsoft.SharePoint.Client.ListTemplateType.GenericList, ListName); //Remove existing event handlers ctx.Load(eventReceiverList, x => x.EventReceivers); ctx.ExecuteQuery(); foreach (var rer in eventReceiverList.EventReceivers) { if (rer.ReceiverName == ReceiverName) { System.Diagnostics.Trace.WriteLine("Found existing ItemAdded receiver at " + rer.ReceiverUrl); try { //This will fail when deploying via F5, but works when deployed to production rer.DeleteObject(); ctx.ExecuteQuery(); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex.Message); } } } //Get WCF URL where this message was handled OperationContext op = OperationContext.Current; Message msg = op.RequestContext.RequestMessage; //Create a new event receiver EventReceiverDefinitionCreationInformation receiver = new EventReceiverDefinitionCreationInformation(); receiver.EventType = EventReceiverType.ItemAdded; receiver.ReceiverUrl = msg.Headers.To.ToString(); receiver.ReceiverName = ReceiverName; receiver.Synchronization = EventReceiverSynchronization.Synchronous; //Add the new event receiver to a list in the host web eventReceiverList.EventReceivers.Add(receiver); ctx.ExecuteQuery(); } } }
private void HandleAppUninstalling(SPRemoteEventProperties properties) { using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, false)) { if (clientContext != null) { Web oWebsite = clientContext.Web; List oList = oWebsite.Lists.GetByTitle(ListHtmlToPdf); oList.DeleteObject(); clientContext.ExecuteQuery(); } } }
/// <summary> /// Handles app events that occur after the app is installed or upgraded, or when app is being uninstalled. /// </summary> /// <param name="properties">Holds information about the app event.</param> /// <returns>Holds information returned from the app event.</returns> public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties) { SPRemoteEventResult result = new SPRemoteEventResult(); using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, useAppWeb: false)) { if (clientContext != null) { clientContext.Load(clientContext.Web, wde => wde.Title); clientContext.ExecuteQuery(); LogProvider.LogWarning("Upgrading application {0} for web {1}", properties.ToString(), clientContext.Web.Title); } } return(result); }
/// <summary> /// Handles app events that occur after the app is installed or upgraded, or when app is being uninstalled. /// </summary> /// <param name="properties">Holds information about the app event.</param> /// <returns>Holds information returned from the app event.</returns> public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties) { SPRemoteEventResult result = new SPRemoteEventResult(); //remote event recievers if (properties.EventType == SPRemoteEventType.ItemAdded || properties.EventType == SPRemoteEventType.ItemUpdated) { using (ClientContext ctx = TokenHelper.CreateRemoteEventReceiverClientContext(properties)) { Helpers.CalculatorHelper.DoCalculation(properties.ItemEventProperties.ListItemId, ctx); } } if (properties.EventType == SPRemoteEventType.ItemAdding) { using (ClientContext ctx = TokenHelper.CreateRemoteEventReceiverClientContext(properties)) { bool IsValid = Helpers.CalculatorHelper.ValidateCalculation(properties.ItemEventProperties.ListItemId, ctx); if (!IsValid) { result.ErrorMessage = "You cannot devide by zero"; result.Status = SPRemoteEventServiceStatus.CancelWithError; } } } //app Evnets using (ClientContext ctx = TokenHelper.CreateAppEventClientContext(properties, useAppWeb: false)) { if (ctx != null) { if (properties.EventType == SPRemoteEventType.AppInstalled) { Helpers.AppEventHelper.Install(ctx); } if (properties.EventType == SPRemoteEventType.AppUninstalling) { Helpers.AppEventHelper.UnInstall(ctx); } } } return(result); }
public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties) { var result = new SPRemoteEventResult(); Logger.Logger.LogInfo("ProcessEvent called for AppEventReceiver", () => { // Deal with application installed event. switch (properties.EventType) { case SPRemoteEventType.AppInstalled: case SPRemoteEventType.AppUninstalling: using (var clientContext = TokenHelper.CreateAppEventClientContext(properties, false)) AppHelper.UnregisterRemoteEvents(clientContext); break; } }); return(result); }
private void RecycleList(String title, SPRemoteEventProperties properties) { using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, useAppWeb: false)) { if (clientContext != null) { // Check to see that a user hasn't already recycled the list in the SharePoint UI. List targetList = GetListByTitle(title, clientContext); // If its still there, recycle it. if (targetList != null) { targetList.Recycle(); clientContext.ExecuteQuery(); } } } }
private void DeleteList(Guid listID, SPRemoteEventProperties properties) { using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, useAppWeb: false)) { if (clientContext != null) { // Check to see if the "try" block code got far enough to create the list before it errored. List targetList = GetListByID(listID, clientContext); // If it did, delete the list. if (targetList != null) { targetList.DeleteObject(); clientContext.ExecuteQuery(); } } } }
private void HandleAppUninstalling(SPRemoteEventProperties properties) { using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, false)) { if (clientContext != null) { List projectList = clientContext.Web.Lists.GetByTitle(ListName); clientContext.Load(projectList, p => p.EventReceivers); clientContext.ExecuteQuery(); var receiver = projectList.EventReceivers.FirstOrDefault(e => e.ReceiverName == ReceiverNameAdded); if (receiver == null) { return; } DeleteReceiver(clientContext, receiver); } } }