private void processChangeRequest(WorkBox workBox) { WBLogging.Generic.Verbose("WorkBoxMetaDataItemChangeEventReceiver.processChangeRequest()"); String currentStatus = workBox.Status; String requestedChange = workBox.StatusChangeRequest; WBLogging.Generic.Verbose("WorkBoxMetaDataItemChangeEventReceiver.processChangeRequest(): Current status = " + currentStatus + " and requested change = " + requestedChange); // this.EventFiringEnabled = false; if (requestedChange.Equals(WorkBox.REQUEST_WORK_BOX_STATUS_CHANGE__CREATE)) { workBox.Create(); } else if (requestedChange.Equals(WorkBox.REQUEST_WORK_BOX_STATUS_CHANGE__OPEN)) { workBox.Open(); } else if (requestedChange.Equals(WorkBox.REQUEST_WORK_BOX_STATUS_CHANGE__CLOSE)) { workBox.Close(); } else if (requestedChange.Equals(WorkBox.REQUEST_WORK_BOX_STATUS_CHANGE__ARCHIVE)) { workBox.Archive(); } else if (requestedChange.Equals(WorkBox.REQUEST_WORK_BOX_STATUS_CHANGE__DELETE)) { workBox.Delete(); } else if (requestedChange.Equals(WorkBox.REQUEST_WORK_BOX_STATUS_CHANGE__REAPPLY_PERMISSIONS)) { workBox.ReapplyPermissions(); workBox.ClearStatusChangeRequest(); } else { WBLogging.Generic.Verbose("WorkBoxMetaDataItemChangeEventReceiver.processChangeRequest(): No request for change so doing nothing"); } // this.EventFiringEnabled = true; }
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; }