Пример #1
0
        /// <summary>
        /// An item was updated.
        /// </summary>
        public override void ItemUpdated(SPItemEventProperties properties)
        {
            String workBoxURL = properties.ListItem.WBxGetAsString(WBColumn.WorkBoxURL);

            if (!String.IsNullOrEmpty(workBoxURL))
            {
                using (WorkBox workBox = new WorkBox(workBoxURL))
                {
                    workBox.ReferenceDate = (DateTime)properties.ListItem["EventDate"];

                    if (workBox.Item.WBxColumnExists("EventDate"))
                    {
                        workBox.Item["EventDate"] = properties.ListItem["EventDate"];
                    }

                    if (workBox.Item.WBxColumnExists("EndDate"))
                    {
                        workBox.Item["EndDate"] = properties.ListItem["EndDate"];
                    }

                    workBox.GenerateTitle();
                    workBox.Item.Update();
                    workBox.UpdateCachedDetails();

                    workBox.UpdateWorkBoxWebSiteTitle();

                    // Finally we're going to update the title of the calendar event as it may have changed
                    // in light of the update to the title of the associated work box.
                    using (EventsFiringDisabledScope noevents = new EventsFiringDisabledScope())
                    {
                        properties.ListItem["Title"] = workBox.Title;
                        properties.ListItem.Update();
                    }
                }
            }

            base.ItemUpdated(properties);
        }
Пример #2
0
        public void PrecreateWorkBoxes()
        {
            int totalToHavePrecreated = Item.WBxGetColumnAsInt(WBColumn.PrecreateWorkBoxes, -1);

            // Is this template configured to precreate?
            if (totalToHavePrecreated <= 0)
            {
                return;
            }

            // Next let's just check that both of the lists for the precreation process are configured:
            String precreatedWorkBoxesListName = Item.WBxGetAsString(WBColumn.PrecreatedWorkBoxesList);

            if (String.IsNullOrEmpty(precreatedWorkBoxesListName))
            {
                return;
            }

            String requestPrecreatedWorkBoxListName = Item.WBxGetAsString(WBColumn.RequestPrecreatedWorkBoxList);

            if (String.IsNullOrEmpty(requestPrecreatedWorkBoxListName))
            {
                return;
            }

            bool previousWebAllowUnsafeUpdates = Collection.Web.AllowUnsafeUpdates;

            Collection.Web.AllowUnsafeUpdates = true;

            try
            {
                SPList precreatedWorkBoxesList      = Collection.Web.Lists[precreatedWorkBoxesListName];
                SPList requestPrecreatedWorkBoxList = Collection.Web.Lists[requestPrecreatedWorkBoxListName];

                // We only need to bring the two list's IDs into sync if there are no remaining precreated work boxes waiting to be used
                // if there are still waiting precreated work boxes, then we should be able to assume that the lists are still in sync
                if (precreatedWorkBoxesList.ItemCount == 0)
                {
                    MakeSureListsAreInSync(precreatedWorkBoxesList, requestPrecreatedWorkBoxList);
                }

                int safety       = 0;
                int safetyCutOut = 1000;

                int countPrecreated = precreatedWorkBoxesList.ItemCount;

                WBLogging.Debug("Current count of precreated: " + countPrecreated);
                WBLogging.Debug("Total target of precreated: " + totalToHavePrecreated);


                using (EventsFiringDisabledScope noevents = new EventsFiringDisabledScope())
                {
                    while (countPrecreated < totalToHavePrecreated && safety < safetyCutOut)
                    {
                        safety++;

                        SPListItem newItem    = Collection.List.AddItem();
                        WorkBox    newWorkBox = new WorkBox(Collection, newItem);
                        newWorkBox.Template = this;

                        // This update ensures that at the item is assigned an ID:
                        newItem.Update();

                        newWorkBox.Create("Precreated work box");

                        Collection.Web.AllowUnsafeUpdates = true;

                        SPListItem precreatedWorkBoxesListItem = precreatedWorkBoxesList.AddItem();
                        precreatedWorkBoxesListItem.WBxSet(WBColumn.WorkBoxListID, newItem.ID);
                        precreatedWorkBoxesListItem.WBxSet(WBColumn.Title, "Precreated work box: " + newWorkBox.Url);
                        precreatedWorkBoxesListItem.Update();

                        // We need to do this as precreatedWorkBoxesList.ItemCount does not get updated in the loop:
                        countPrecreated++;
                    }
                }

                if (safety >= safetyCutOut)
                {
                    throw new NotImplementedException("The precreation of work boxes loop appears to be out of control for: " + TemplateTitle);
                }
            }
            catch (Exception exception)
            {
                WBUtils.SendErrorReport(this.Collection.Web, "Work Box Precreation Error", "Something went wrong when trying to precreate a work box for: " + this.TemplateTitle + " Exception: " + exception.Message + " \n\n " + exception.StackTrace);
            }

            Collection.Web.AllowUnsafeUpdates = previousWebAllowUnsafeUpdates;
        }