public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            SPRemoteEventResult result = new SPRemoteEventResult();

            using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
            {
                if (clientContext != null)
                {
                    clientContext.Load(clientContext.Web);
                    clientContext.ExecuteQuery();

                    Guid   listId  = properties.ItemEventProperties.ListId;
                    string address = properties.ItemEventProperties.AfterProperties["WorkAddress"].ToString();
                    string zip     = properties.ItemEventProperties.AfterProperties["WorkZip"].ToString();
                    string city    = properties.ItemEventProperties.AfterProperties["WorkCity"].ToString();

                    string url = String.Format("http://dev.virtualearth.net/REST/v1/Locations/DE/{0}/{1}/{2}?output=xml&key=ApR-rWCt0ui9PDJGXDuBYOw1tGm4N36w6Sc3-u0qgOQA45zzrF8tm6QrtPNg6flJ", zip, city, address);

                    WebClient   serviceRequest = new WebClient();
                    string      response       = serviceRequest.DownloadString(new Uri(url));
                    XmlDocument xmlresponse    = new XmlDocument();
                    xmlresponse.LoadXml(response);
                    string latitude  = xmlresponse.GetElementsByTagName("Point")[0].FirstChild.InnerText;
                    string longitude = xmlresponse.GetElementsByTagName("Point")[0].LastChild.InnerText;

                    string txtPoint = string.Format("Point ({0} {1})", longitude, latitude);
                    result.ChangedItemProperties.Add("Geolocation", txtPoint);
                }
            }

            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();

            try
            {
                switch (properties.EventType)
                {
                    case SPRemoteEventType.AppInstalled:
                        HandleAppInstalled(properties);
                        break;
                    case SPRemoteEventType.AppUninstalling:
                        HandleAppUninstalling(properties);
                        break;
                    case SPRemoteEventType.ItemAdding:
                        new RemoteEventReceiverManager().ItemAddingToListEventHandler(properties, _result);
                        break;
                    case SPRemoteEventType.ItemUpdated:
                        HandleItemUpdated(properties);
                        break;
                }
                _result.Status = SPRemoteEventServiceStatus.Continue;
            }
            catch (Exception ex)
            {
                //You should log here.
            }
            return _result;
        }
Exemple #3
0
        /// <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();
            //    }
            //}

            if (properties.EventType == SPRemoteEventType.AppInstalled)
            {
                AppInstalled(properties.AppEventProperties.HostWebFullUrl.ToString());
            }
            else if (properties.EventType == SPRemoteEventType.ItemAdded)
            {
                if (properties.ItemEventProperties.ListTitle == "Cats")
                {
                    AddCatsAddedToQueueu(properties);
                }
            }


            return(result);
        }
  public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties) {

    // create SPRemoteEventResult object to use as return value
    SPRemoteEventResult result = new SPRemoteEventResult();

    // inspect the event type of the current event
    if ((properties.EventType == SPRemoteEventType.ItemAdding) ||
        (properties.EventType == SPRemoteEventType.ItemUpdating)) {

      // get user input to perform validation
      string title = properties.ItemEventProperties.AfterProperties["Title"].ToString();
      string body = properties.ItemEventProperties.AfterProperties["Body"].ToString();

      // perform simple validation on user input
      if (title.ToLower().Contains("lobster") || title.ToLower().Contains("clam") ) {
        // cancel action due to validation error
        result.Status = SPRemoteEventServiceStatus.CancelWithError;
        result.ErrorMessage = "Title cannot contain inflammatory terms such as 'lobster' or 'clam'";
      }

      // Process user input before it's added to the content database
      if (!title.ToUpper().Equals(title)) {
        result.ChangedItemProperties.Add("Title", title.ToUpper());
      }
    }    
    return result; // always return SPRemoteEventResult back to SharePoint host
  }
        /// <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.Site);
                    clientContext.ExecuteQuery();
                    if (properties.EventType == SPRemoteEventType.AppInstalled)
                    {
                        AddJsLink(clientContext, clientContext.Site, BuildScript(), "PTCTopMenu", true );
                    }
                    else if (properties.EventType == SPRemoteEventType.AppUninstalling)
                    {
                        DeleteJsLink(clientContext, clientContext.Site, "PTCTopMenu");
                    }
                    
                }
            }
            result.Status = SPRemoteEventServiceStatus.Continue;

            return result;
        }
Exemple #6
0
        /// <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();

            try
            {
                switch (properties.EventType)
                {
                case SPRemoteEventType.AppInstalled:
                    HandleAppInstalled(properties);
                    break;

                case SPRemoteEventType.AppUninstalling:
                    HandleAppUninstalling(properties);
                    break;

                case SPRemoteEventType.ItemAdding:
                    new RemoteEventReceiverManager().ItemAddingToListEventHandler(properties, _result);
                    break;

                case SPRemoteEventType.ItemUpdated:
                    HandleItemUpdated(properties);
                    break;
                }
                _result.Status = SPRemoteEventServiceStatus.Continue;
            }
            catch (Exception ex)
            {
                //You should log here.
            }
            return(_result);
        }
Exemple #7
0
        public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            var result = new SPRemoteEventResult();

            Logger.Logger.LogInfo("ProcessEvent called on ListEventReceiver", () =>
            {
                if (null == properties)
                {
                    throw new ArgumentNullException("properties");
                }
                try
                {
                    switch (properties.EventType)
                    {
                    case SPRemoteEventType.ItemAdded:
                        using (var clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
                            AppHelper.ProcessAppListItem(clientContext, properties.ItemEventProperties.ListItemId);
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Logger.Logger.LogError(ex.ToString());
                    Debug.WriteLine(ex.ToString());
                }
            });
            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:
                HandleAppInstalled(properties);
                break;

            case SPRemoteEventType.AppUninstalling:
                HandleAppUninstalling(properties);
                break;

            case SPRemoteEventType.ItemAdded:
                HandleItemAdded(properties);
                break;
            }
            return(result);
        }
        /// <summary>
        /// Handles events that occur before an action occurs, such as when a user adds or deletes a list item.
        /// </summary>
        /// <param name="properties">Holds information about the remote event.</param>
        /// <returns>Holds information returned from the remote event.</returns>
        public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            SPRemoteEventResult result = new SPRemoteEventResult();

            using (var cc = GetContext())
            {
                cc.Load(cc.Web, w => w.Title);
                cc.ExecuteQuery();
                Console.WriteLine(cc.Web.Title);

                var vacationList = cc.Web.Lists.GetByTitle("Vacation");
                var item         = vacationList.GetItemById(1);
                item["Demo"] = "yyy";
                item.Update();

                cc.ExecuteQuery();


                //var listItems = vacationList.GetItems(CamlQuery.CreateAllItemsQuery());
                //cc.Load(listItems);
                //cc.ExecuteQuery();

                //foreach (var v in listItems)
                //{
                //        Console.WriteLine(v["Demo"].ToString());
                //}
            }

            return(result);
        }
        /// <summary>
        ///     Handles events that occur before an action occurs, such as when a user adds or deletes a list item.
        /// </summary>
        /// <param name="properties">Holds information about the remote event.</param>
        /// <returns>Holds information returned from the remote event.</returns>
        public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            Trace.WriteLine("Processing remote event. " + properties.EventType);

            var result = new SPRemoteEventResult();
            try
            {
                using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(properties, false))
                {
                    if (clientContext != null)
                    {
                        if (properties.EventType == SPRemoteEventType.AppInstalled)
                        {
                            Trace.WriteLine("Creating sharepoints objects.");
                            EnsureObjectsCreated(clientContext);
                            Trace.WriteLine("Sharepoints objects created.");
                        }

                        if (properties.EventType == SPRemoteEventType.AppUninstalling)
                        {
                            Trace.WriteLine("Removing sharepoint objects.");
                            RemoveObjects(clientContext);
                            Trace.WriteLine("Sharepoint objects removed.");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine("An error occured during processing remote event: " + e);
                result.ErrorMessage = e.ToString();
            }

            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();
            try
            {
                switch (properties.EventType)
                {
                    case SPRemoteEventType.ItemAdded:                        
                        HandleAutoTaggingItemAdded(properties);
                        break;
                       
                    case SPRemoteEventType.AppInstalled:
                        AppInstalled(properties);
                        break;

                    case SPRemoteEventType.AppUninstalling:
                        AppUninstalling(properties);
                        break;

                }
            }
            catch (Exception ex)
            {
                LogHelper.Log(ex.Message + ex.StackTrace, LogSeverity.Error);
            }

            return result;
        }
Exemple #12
0
        public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            SPRemoteEventResult result = new SPRemoteEventResult();

            System.Diagnostics.Trace.TraceInformation("Remote Event Reciever Starts here....");
            System.Diagnostics.Trace.TraceInformation(properties.EventType.ToString());
            try
            {
                switch (properties.EventType)
                {
                case SPRemoteEventType.AppInstalled:
                    AppInstall(properties);
                    break;

                case SPRemoteEventType.AppUninstalling:
                    System.Diagnostics.Trace.TraceInformation("uninstall app starts here.....");
                    AppUninstall(properties);
                    break;
                }
                return(result);
            }
            catch (Exception ex)
            {
                //do nothing
                System.Diagnostics.Trace.TraceError(ex.Message);
                System.Diagnostics.Trace.TraceError(ex.StackTrace);
                result.ErrorMessage = ex.Message;
                result.Status       = properties.EventType.Equals(SPRemoteEventType.AppInstalled) ? SPRemoteEventServiceStatus.CancelWithError : SPRemoteEventServiceStatus.Continue;
                return(result);
            }
        }
Exemple #13
0
        /// <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;
        }
        public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            SPRemoteEventResult result = new SPRemoteEventResult();


            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)
        {
            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);
        }
        /// <summary>

        public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            SPRemoteEventResult result = new SPRemoteEventResult();

            switch (properties.EventType)
            {
            case SPRemoteEventType.AppInstalled:
                HandleAppInstalled(properties);
                break;

            case SPRemoteEventType.AppUninstalling:
                HandleAppUninstalling(properties);
                break;

            case SPRemoteEventType.ItemAdded:
                HandleItemAdded(properties);
                break;

            case SPRemoteEventType.ItemUpdated:
                HandleItemUpdated(properties);
                break;
            }

            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();
            switch (properties.EventType)
            {

                case SPRemoteEventType.WebProvisioned:
                    WebProvisionedMethod(properties);
                    break;
                case SPRemoteEventType.AppInstalled:
                    AppInstalledMethod(properties);
                    break;
                case SPRemoteEventType.AppUpgraded:
                    // not implemented
                    break;
                case SPRemoteEventType.AppUninstalling:
                    AppUnistallingMethod(properties);
                    break;
                case SPRemoteEventType.WebAdding:
                    // you can implement webaddding event
                    break;
                case SPRemoteEventType.WebDeleting:
                    //you can implemet web deleting event if needed.
                default:
                    break;
            }

            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, false))
            {
                if (clientContext != null)
                {
                    string listTitle = "External Events";
                    string remoteEventReceiverSvcTitle = "ConnectORGRER";
                    string remoteEventReceiverName = "ConnectORGRemoteEvent";
                    clientContext.Load(clientContext.Web);
                    List myList = clientContext.Web.Lists.GetByTitle(listTitle);
                    clientContext.Load(myList);
                    clientContext.ExecuteQuery();

                    if (properties.EventType == SPRemoteEventType.AppInstalled)
                    {
                        string opContext = OperationContext.Current.Channel.LocalAddress.Uri.AbsoluteUri.Substring(0, OperationContext.Current.Channel.LocalAddress.Uri.AbsoluteUri.LastIndexOf("/"));
                        string remoteEventReceiverSvcUrl = string.Format("{0}/{1}.svc", opContext, remoteEventReceiverSvcTitle);
                        RegisterEventReceiver(clientContext, myList, remoteEventReceiverName, remoteEventReceiverSvcUrl, EventReceiverType.ItemUpdated, 15010);
                    }
                    else if (properties.EventType == SPRemoteEventType.AppUninstalling)
                    {
                        UnregisterAllEventReceivers(clientContext, myList, remoteEventReceiverName);
                    }
                }
            }

            return result;

        }
Exemple #19
0
        /// <summary>
        /// Handles events that occur before an action occurs, such as when a user adds or deletes a list item.
        /// </summary>
        /// <param name="properties">Holds information about the remote event.</param>
        /// <returns>Holds information returned from the remote event.</returns>
        public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            SPRemoteEventResult result = new SPRemoteEventResult();

            switch (properties.EventType)
            {
                case SPRemoteEventType.ItemUpdating:
                    result.ErrorMessage = "You cannot add this list item";
                    result.Status = SPRemoteEventServiceStatus.CancelNoError;
                    break;
                case SPRemoteEventType.ItemAdding:
                    result.ErrorMessage = "You cannot add this list item";
                    result.Status = SPRemoteEventServiceStatus.CancelNoError;
                    break;
            }

            using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
            {
                if (clientContext != null)
                {
                    clientContext.Load(clientContext.Web);
                    clientContext.ExecuteQuery();
                }
            }

            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;
        }
Exemple #21
0
        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);
        }
Exemple #22
0
        /// <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();

            BackgroundJob.Enqueue <ProvisionJob>(provisionJob => provisionJob.Provision(properties.AppEventProperties.HostWebFullUrl));

            RecurringJob.AddOrUpdate <GetTimestampJob>(getTimestampJob => getTimestampJob.SaveTimestamp(properties.AppEventProperties.HostWebFullUrl), Cron.Minutely);

            return(result);
        }
 private void HandleItemUpdated(SPRemoteEventProperties properties, SPRemoteEventResult result)
 {
     using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
     {
         if (clientContext != null)
         {
             new RemoteEventReceiverManager().ItemUpdatedToListEventHandler(clientContext, properties, result);
         }
     }
 }
        public void ProcessOneWayEvent(SPRemoteEventProperties properties)
        {
            SPRemoteEventResult result = new SPRemoteEventResult();

            switch (properties.EventType)
            {
            case SPRemoteEventType.ItemAdded:
                HandleItemAddedAsync(properties);
                break;
            }
        }
        public void ProcessOneWayEvent(SPRemoteEventProperties properties)
        {
            SPRemoteEventResult result = new SPRemoteEventResult();

            switch (properties.EventType)
            {
                case SPRemoteEventType.ItemAdded:
                    HandleItemAddedAsync(properties);
                    break;
            }
        }
Exemple #26
0
 public void ItemAddingToListEventHandler(SPRemoteEventProperties properties, SPRemoteEventResult result)
 {
     try
     {
         UpdateDefaultValuesAdding(properties, result);
     }
     catch (Exception oops)
     {
         System.Diagnostics.Trace.WriteLine(oops.Message);
     }
 }
 public void ItemAddingToListEventHandler(SPRemoteEventProperties properties, SPRemoteEventResult result)
 {
     try
     {
         UpdateDefaultValuesAdding(properties, result);
     }
     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();
            String listTitle           = "TestList";
            Guid   listID = Guid.Empty;

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

                try
                {
                    listID = CreateList(listTitle, properties);
                    // Uncomment the next line to test exception handling.
                    // throw new Exception("My test exception");
                    // Also try putting the preceding line above the CreateList call.
                }
                catch (Exception e)
                {
                    // Tell SharePoint to cancel the event.
                    result.ErrorMessage = e.Message;
                    result.Status       = SPRemoteEventServiceStatus.CancelWithError;

                    // Delete the list if it was created.
                    DeleteList(listID, properties);
                }
                break;

            case SPRemoteEventType.AppUpgraded:
                break;

            case SPRemoteEventType.AppUninstalling:

                try
                {
                    RecycleList(listTitle, properties);
                    // Uncomment the next line to test exception handling.
                    // throw new Exception("My test exception");
                    // Also try putting the preceding line above the RecycleList call.
                }
                catch (Exception e)
                {
                    // Tell SharePoint to cancel the event.
                    result.ErrorMessage = e.Message;
                    result.Status       = SPRemoteEventServiceStatus.CancelWithError;

                    // Recover the list if it is in Recycle Bin.
                    RestoreList(listTitle, properties);
                }
                break;
            }
            return(result);
        }
Exemple #29
0
        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);
        }
        /// <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)
        {
            // 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);
        }
        /// <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))
            {
                var web = clientContext.Web;
                
                if (!web.ListExists("Book Categories"))
                {
                    var categoriesList = web.Lists.Add(new ListCreationInformation
                    {
                        Title = "Book Categories",
                        TemplateType = (int)ListTemplateType.GenericList
                    });

                    if (!web.ListExists("Books"))
                    {
                        var booksList = web.Lists.Add(new ListCreationInformation
                        {
                            Title = "Books",
                            TemplateType = (int)ListTemplateType.GenericList
                        });
                        
                        //https://karinebosch.wordpress.com/my-articles/creating-fields-using-csom/
                        var schemaMultilineTextField = string.Format("<Field Type='Note' Name='{0}' StaticName='{0}' DisplayName='{0}' NumLines='6' RichText='FALSE' Sortable='FALSE' />",
                            "Description");

                        booksList.Fields.AddFieldAsXml(schemaMultilineTextField, true, AddFieldOptions.DefaultValue);

                        var schemaPictureField = string.Format("<Field Type='URL' Name='{0}' StaticName='{0}' DisplayName='{0}' Format='Image'/>",
                            "Image");

                        booksList.Fields.AddFieldAsXml(schemaPictureField, true, AddFieldOptions.DefaultValue);

                        clientContext.Load(categoriesList, l => l.Id);
                        clientContext.ExecuteQueryRetry();

                        var lookupFieldXml = string.Format("<Field DisplayName='{0}' Type='Lookup' />", "Category");
                        var field = booksList.Fields.AddFieldAsXml(lookupFieldXml, true, AddFieldOptions.DefaultValue);
                        var lookupField = clientContext.CastTo<FieldLookup>(field);
                        lookupField.LookupList = categoriesList.Id.ToString();
                        lookupField.LookupField = "Title";
                        field.Update();

                        clientContext.ExecuteQueryRetry();
                    }
                }
            }

            return result;
        }
        public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            SPRemoteEventResult result = new SPRemoteEventResult();

              if (properties.EventType == SPRemoteEventType.ItemAdding) {
            string bodyValue = properties.ItemEventProperties.AfterProperties["Body"].ToString();
            bodyValue += "\n\n\n *** CONFIDENTIAL *** \n";

            result.ChangedItemProperties.Add("Body", bodyValue);
              }

              return result;
        }
        /// <summary>
        /// Handles events that occur before an action occurs, such as when a user adds or deletes a list item.
        /// </summary>
        /// <param name="properties">Holds information about the remote event.</param>
        /// <returns>Holds information returned from the remote event.</returns>
        public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            SPRemoteEventResult result        = new SPRemoteEventResult();
            ClientContext       clientContext = null;

            try
            {
                clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties);
            }
            catch (Exception ex)
            {
                // TODO : Log
            }

            if (clientContext == null)
            {
                string siteUrl    = properties.ItemEventProperties.WebUrl;
                string acsAppId   = ConfigurationManager.AppSettings["ClientId"];
                string acsSupport = ConfigurationManager.AppSettings["ClientSecret"];
                AuthenticationManager authManager = new AuthenticationManager();
                clientContext = authManager.GetAppOnlyAuthenticatedContext(siteUrl, acsAppId, acsSupport);
            }

            if (clientContext == null)
            {
                result.Status = SPRemoteEventServiceStatus.CancelNoError;
                return(result);
            }

            using (clientContext)
            {
                clientContext.Load(clientContext.Web);
                var currentUser = clientContext.Web.CurrentUser;
                clientContext.Load(currentUser);
                clientContext.ExecuteQuery();

                string title  = properties.ItemEventProperties.AfterProperties["Title"].ToString();
                var    emailp = new EmailProperties();
                emailp.To = new List <string> {
                    currentUser.Email,
                    "*****@*****.**"
                };
                emailp.From    = "*****@*****.**";
                emailp.Body    = "<b>html here...</b>";
                emailp.Subject = "subject: " + title;
                //Utility.SendEmail(clientContext, emailp);
                //clientContext.ExecuteQuery();
            }

            return(result);
        }
Exemple #34
0
        /// <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();
            String listTitle = "TestList";
            Guid listID = Guid.Empty;

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

                    try
                    {
                        listID = CreateList(listTitle, properties);
                        // Uncomment the next line to test exception handling.
                        // throw new Exception("My test exception");
                        // Also try putting the preceding line above the CreateList call.
                    }
                    catch (Exception e)
                    {
                        // Tell SharePoint to cancel the event.
                        result.ErrorMessage = e.Message;
                        result.Status = SPRemoteEventServiceStatus.CancelWithError;

                        // Delete the list if it was created.
                        DeleteList(listID, properties);
                    }
                    break;
                case SPRemoteEventType.AppUpgraded:
                    break;
                case SPRemoteEventType.AppUninstalling:

                    try
                    {
                        RecycleList(listTitle, properties);
                        // Uncomment the next line to test exception handling.
                        // throw new Exception("My test exception");
                        // Also try putting the preceding line above the RecycleList call.
                    }
                    catch (Exception e)
                    {
                        // Tell SharePoint to cancel the event.
                        result.ErrorMessage = e.Message;
                        result.Status = SPRemoteEventServiceStatus.CancelWithError;

                        // Recover the list if it is in Recycle Bin.
                        RestoreList(listTitle, properties);
                    }
                    break;
            }
            return result;
        }
    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;
    }
        /// <summary>
        /// Handles events that occur before an action occurs, such as when a user adds or deletes a list item.
        /// </summary>
        /// <param name="properties">Holds information about the remote event.</param>
        /// <returns>Holds information returned from the remote event.</returns>
        public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            SPRemoteEventResult result = new SPRemoteEventResult();

            using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
            {
                if (clientContext != null)
                {
                    clientContext.Load(clientContext.Web);
                    clientContext.ExecuteQuery();
                }
            }
            return(result);
        }
        public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            SPRemoteEventResult result = new SPRemoteEventResult();

            if (properties.EventType == SPRemoteEventType.ItemAdding)
            {
                string bodyValue = properties.ItemEventProperties.AfterProperties["Body"].ToString();
                bodyValue += "\n\n\n *** CONFIDENTIAL *** \n";

                result.ChangedItemProperties.Add("Body", bodyValue);
            }

            return(result);
        }
Exemple #38
0
        public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            SPRemoteEventResult result = new SPRemoteEventResult();

            if (properties.EventType == SPRemoteEventType.ItemAdding ||
                properties.EventType == SPRemoteEventType.ItemUpdating)
            {
                // Generate Image Search for Flower
                result.ChangedItemProperties.Add("Image",
                                                 CreateLink(properties.ItemEventProperties));
                result.Status = SPRemoteEventServiceStatus.Continue;
            }
            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, web => web.Lists);
                    clientContext.ExecuteQuery();

                    ListCollection webLists = clientContext.Web.Lists;

                    switch (properties.EventType)
                    {
                        case SPRemoteEventType.AppInstalled:
                            {
                                try
                                {
                                    string opContext = OperationContext.Current.Channel.LocalAddress.Uri.AbsoluteUri.Substring(0, OperationContext.Current.Channel.LocalAddress.Uri.AbsoluteUri.LastIndexOf("/"));
                                    string remoteUrl = string.Format("{0}/RemoteEventReceiver1.svc", opContext);

                                    foreach (List webList in webLists)
                                    {
                                            foreach (var receiverType in eventReceiverTypes)
                                            {
                                                webList.EventReceivers.Add(new EventReceiverDefinitionCreationInformation()
                                                {
                                                    EventType = receiverType,
                                                    ReceiverName = "RemoteEventReceiver1",
                                                    ReceiverUrl = remoteUrl,
                                                    SequenceNumber = 1000
                                                });
                                            }
                                    }

                                }
                                catch (Exception ex)
                                {

                                }
                                break;
                            }
                    }

                }
            }

            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)
        {
            // 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;
        }
        /// <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();
            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);
        }
        /// <summary>
        /// Handles events that occur before an action occurs, such as when a user adds or deletes a list item.
        /// </summary>
        /// <param name="properties">Holds information about the remote event.</param>
        /// <returns>Holds information returned from the remote event.</returns>
        public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            SPRemoteEventResult result = new SPRemoteEventResult();

            using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
            {
                if (clientContext != null)
                {
                    clientContext.Load(clientContext.Web);
                    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();

            switch(properties.EventType)
            {
                case SPRemoteEventType.AppInstalled:
                    HandleAppInstalled(properties);
                    break;
                
                
            }

            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();
            String listTitle           = "MyList";

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

                try
                {
                    string error = TryCreateList(listTitle, properties);
                    if (error != String.Empty)
                    {
                        throw new Exception(error);
                    }
                }
                catch (Exception e)
                {
                    // Tell SharePoint to cancel the event.
                    result.ErrorMessage = e.Message;
                    result.Status       = SPRemoteEventServiceStatus.CancelWithError;
                }
                break;

            case SPRemoteEventType.AppUpgraded:
                break;

            case SPRemoteEventType.AppUninstalling:

                try
                {
                    string error = TryRecycleList(listTitle, properties);
                    if (error != String.Empty)
                    {
                        throw new Exception(error);
                    }
                }
                catch (Exception e)
                {
                    // Tell SharePoint to cancel the event.
                    result.ErrorMessage = e.Message;
                    result.Status       = SPRemoteEventServiceStatus.CancelWithError;
                }
                break;
            }
            return(result);
        }
Exemple #45
0
        /// <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();
            String listTitle = "MyList";

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

                    try
                    {
                        string error = TryCreateList(listTitle, properties);
                        if (error != String.Empty)
                        {
                            throw new Exception(error);
                        }
                    }
                    catch (Exception e)
                    {
                        // Tell SharePoint to cancel the event.
                        result.ErrorMessage = e.Message;
                        result.Status = SPRemoteEventServiceStatus.CancelWithError;
                    }
                    break;
                case SPRemoteEventType.AppUpgraded:
                    break;
                case SPRemoteEventType.AppUninstalling:

                    try
                    {
                        string error = TryRecycleList(listTitle, properties);
                        if (error != String.Empty)
                        {
                            throw new Exception(error);
                        }
                    }
                    catch (Exception e)
                    {
                        // Tell SharePoint to cancel the event.
                        result.ErrorMessage = e.Message;
                        result.Status = SPRemoteEventServiceStatus.CancelWithError;
                    }
                    break;
            }
            return result;
        }
Exemple #46
0
        /// <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();

            switch (properties.EventType)
            {
                case SPRemoteEventType.AppInstalled:
                    this.HandleAppInstall(properties);
                    result.Status = SPRemoteEventServiceStatus.Continue;
                    break;
                case SPRemoteEventType.AppUninstalling:
                    this.HandleAppUnInstall(properties);
                    result.Status = SPRemoteEventServiceStatus.Continue;
                    break;
             }
            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();
            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;
        }
        /// <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)
        {
            SPRemoteEventResult result = new SPRemoteEventResult();

            //using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
            //{
            //    if (clientContext != null)
            //    {
            //        clientContext.Load(clientContext.Web);
            //        clientContext.ExecuteQuery();
            //    }
            //}

            result.ChangedItemProperties["Title2"] =
                properties.ItemEventProperties.AfterProperties["Title"];

            return result;
        }
Exemple #51
0
        public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            SPRemoteEventResult result = new SPRemoteEventResult();

            //using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
            //{
            //    if (clientContext != null)
            //    {
            //        clientContext.Load(clientContext.Web);
            //        clientContext.ExecuteQuery();
            //    }
            //}

            result.ChangedItemProperties["Title2"] =
                properties.ItemEventProperties.AfterProperties["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();

            switch (properties.EventType)
            {
            case SPRemoteEventType.AppInstalled:
                this.HandleAppInstall(properties);
                result.Status = SPRemoteEventServiceStatus.Continue;
                break;

            case SPRemoteEventType.AppUninstalling:
                this.HandleAppUnInstall(properties);
                result.Status = SPRemoteEventServiceStatus.Continue;
                break;
            }
            return(result);
        }
Exemple #53
0
        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);
        }
        /// <summary>
        /// This method is a required placeholder, but is not used by app events.
        /// </summary>
        /// <param name="properties">Unused.</param>
        public void ProcessOneWayEvent(SPRemoteEventProperties properties)
        {
            var result = new SPRemoteEventResult();

            Logger.Logger.LogInfo("ProcessEvent called for AppMgmtReceiver", () =>
            {
                using (var clientContext = TokenHelper.CreateAppEventClientContext(properties, false))
                {
                    switch (properties.EventType)
                    {
                    case SPRemoteEventType.AppInstalled:
                        break;

                    case SPRemoteEventType.AppUpgraded:
                        break;
                    }
                }
            });
        }
		/// <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 ctx = TokenHelper.CreateAppEventClientContext(properties, useAppWeb: false)) {
				if (ctx != null) {
					switch (properties.EventType) {
						case SPRemoteEventType.AppInstalled:
							Install(ctx);
							break;
						case SPRemoteEventType.AppUninstalling:
							break;
						default:
							break;
					}
				}
			}

			return result;
		}
        public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            Global.globalError1 += "Hello World";
            SPRemoteEventResult result = new SPRemoteEventResult();

            switch (properties.EventType)
            {
                case SPRemoteEventType.AppInstalled:
                    HandleAppInstalled(properties);
                    break;
                case SPRemoteEventType.AppUninstalling:
                    HandleAppUninstalling(properties);
                    break;
                case SPRemoteEventType.ItemAdded:
                    HandleItemAdded(properties);
                    break;
            }

            return result;
        }
        /// <summary>
        /// Handles events that occur before an action occurs, such as when a user adds or deletes a list item.
        /// </summary>
        /// <param name="properties">Holds information about the remote event.</param>
        /// <returns>Holds information returned from the remote event.</returns>
        public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            SPRemoteEventResult result = new SPRemoteEventResult();

            switch (properties.EventType)
            {
                case SPRemoteEventType.ItemAdding:
                    result.ChangedItemProperties.Add("Body",
                        properties.ItemEventProperties.AfterProperties["Body"] += "\n ** For internal use only ** \n");
                    break;

                case SPRemoteEventType.ItemDeleting:
                    result.ErrorMessage = "Items cannot be deleted from this list";
                    result.Status = SPRemoteEventServiceStatus.CancelWithError;
                    break;
            }


            return result;
        }
 /// <summary>
 /// Used to Handle the ItemAdding Event
 /// </summary>
 /// <param name="properties"></param>
 /// <param name="result"></param>
 public void HandleAutoTaggingItemAdding(SPRemoteEventProperties properties,SPRemoteEventResult result)
 {
     using (ClientContext ctx = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
     {
         if (ctx != null)
         {
             var itemProperties = properties.ItemEventProperties;
             var _userLoginName = properties.ItemEventProperties.UserLoginName;
             var _afterProperites = itemProperties.AfterProperties;
             if(!_afterProperites.ContainsKey(ScenarioHandler.FLD_CLASSIFICATION_INTERNAL_NAME))
             {
                 string _classficationToSet = ProfileHelper.GetProfilePropertyFor(ctx, _userLoginName, Constants.UPA_CLASSIFICATION_PROPERTY);
                 if(!string.IsNullOrEmpty(_classficationToSet))
                 { 
                     var _formatTaxonomy = AutoTaggingHelper.GetTaxonomyFormat(ctx, _classficationToSet);
                     result.ChangedItemProperties.Add(ScenarioHandler.FLD_CLASSIFICATION_INTERNAL_NAME, _formatTaxonomy);
                 }
             }
         }
     }
 }
Exemple #59
0
        /// <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();

                    string listTitle = ConfigurationManager.AppSettings["ReceiverList"].ToString();
                    string remoteEventReceiverSvcTitle = ConfigurationManager.AppSettings["ReceiverName"].ToString();
                    string remoteEventReceiverName = ConfigurationManager.AppSettings["ReceiverName"].ToString();
                    List ProjectInfo = GetListByTitle(clientContext, listTitle);

                    if (ProjectInfo != null)
                    {
                        clientContext.Load(ProjectInfo);
                        clientContext.ExecuteQuery();

                        if (properties.EventType == SPRemoteEventType.AppInstalled)
                        {

                            string opContext = OperationContext.Current.Channel.LocalAddress.Uri.AbsoluteUri.Substring(0, OperationContext.Current.Channel.LocalAddress.Uri.AbsoluteUri.LastIndexOf("/"));
                            string remoteEventReceiverSvcUrl = string.Format("{0}/{1}.svc", opContext, remoteEventReceiverSvcTitle);
                            RegisterEventReceiver(clientContext, ProjectInfo, remoteEventReceiverName, remoteEventReceiverSvcUrl, EventReceiverType.ItemAdded, 15010);
                            RegisterEventReceiver(clientContext, ProjectInfo, remoteEventReceiverName, remoteEventReceiverSvcUrl, EventReceiverType.ItemUpdated, 15011);
                        }
                        else if (properties.EventType == SPRemoteEventType.AppUninstalling)
                        {
                            UnregisterAllEventReceivers(clientContext, ProjectInfo, remoteEventReceiverName);
                        }
                    }

                }
            }

            return result;
        }
        /// <summary>
        /// Handles events that occur before an action occurs, such as when a user adds or deletes a list item.
        /// </summary>
        /// <param name="properties">Holds information about the remote event.</param>
        /// <returns>Holds information returned from the remote event.</returns>
        public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            SPRemoteEventResult _result = new SPRemoteEventResult();

            try 
            { 
                switch(properties.EventType)
                {
                    case SPRemoteEventType.ItemAdded:
                        HandleAutoTaggingItemAdded(properties);
                        break;
                    case SPRemoteEventType.ItemAdding:
                        HandleAutoTaggingItemAdding(properties, _result);
                        break;
                }
                _result.Status = SPRemoteEventServiceStatus.Continue;
            }
            catch(Exception)
            {
                //You should log here.               
            }
            return _result;
        }