protected void Page_Load(object sender, EventArgs e)
        {
            WorkBox workBox = WorkBox.GetIfWorkBox(SPContext.Current);

            if (workBox != null)
            {
                WBTeam owningTeam = workBox.OwningTeam;

                if (owningTeam == null)
                {
                    LinkToOwner = "#";
                }
                else
                {
                    LinkToOwner = owningTeam.TeamSiteUrl;

                    // Only need to set the text to the owning team's name if the text hasn't been set already:
                    if (TextForLink == "")
                    {
                        TextForLink = owningTeam.Name;
                    }

                    WBUtils.logMessage("Found URL: " + LinkToOwner);
                }

                // This wont do anything because the web and site come from context, but still:
                workBox.Dispose();
            }
        }
        protected override void CreateChildControls()
        {
            Literal literal = new Literal();
            string  html    = "";

            WorkBox workBox = WorkBox.GetIfWorkBox(SPContext.Current);

            if (workBox == null)
            {
                return;
            }

            WBTermCollection <WBTeam> involvedTeams = workBox.InvolvedTeams;

            if (involvedTeams == null)
            {
                addErrorMessage("Couldn't find a involvedTeams for the field");
            }
            else
            {
                if (involvedTeams.Count > 0)
                {
                    if (TeamsRootSiteURL == null || TeamsRootSiteURL == "")
                    {
                        TeamsRootSiteURL = WBFarm.Local.TeamSitesSiteCollectionUrl;
                    }


                    try
                    {
                        using (SPSite teamsSite = new SPSite(TeamsRootSiteURL))
                        {
                            html += "<table cellpadding='5'>";
                            foreach (WBTeam team in involvedTeams)
                            {
                                html += "<tr><td><a href='" + team.TeamSiteUrl + "'>" + team.Name + "</a></td></tr>";
                            }
                            html += "</table>";
                        }
                    }
                    catch (Exception e)
                    {
                        html = "Exception was thrown " + e.StackTrace;
                    }
                }
                else
                {
                    html += "<i>(none)</i>";
                }
            }

            literal.Text = html;

            this.Controls.Add(literal);
        }
Beispiel #3
0
        protected override void CreateChildControls()
        {
            Label timeRemaining = new Label();

            this.Controls.Add(timeRemaining);


            timeRemaining.CssClass = "wbf-time-to-auto-close";

            try
            {
                WorkBox workBox = WorkBox.GetIfWorkBox(SPContext.Current);

                if (workBox != null)
                {
                    DateTime endTime = workBox.calculateAutoCloseDate();

                    if (endTime.Year == WBRecordsType.YEAR_REPRESENTING_A_PERMANENT_DATE)
                    {
                        timeRemaining.Text = "This work box will not auto close.";
                    }
                    else
                    {
                        if (endTime < DateTime.Now)
                        {
                            timeRemaining.Text = "No time remaining before auto close.";
                        }
                        else
                        {
                            TimeSpan timeSpan = endTime - DateTime.Now;

                            timeRemaining.Text = String.Format("{0} Days {1} Hours {2} Minutes",
                                                               timeSpan.Days, timeSpan.Hours, timeSpan.Minutes);
                        }
                    }


                    workBox.Dispose();
                }
                else
                {
                    timeRemaining.Text = "You can only use this web part on a work box.";
                }
            }
            catch (Exception e)
            {
                WBLogging.Generic.Unexpected("Error: " + e.Message);
                timeRemaining.Text = "An error occurred";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            WorkBox workBox = WorkBox.GetIfWorkBox(SPContext.Current);

            if (workBox != null)
            {
                LinkToHome = workBox.Web.Url;

                if (TextForLink == "")
                {
                    TextForLink = workBox.Web.Title;
                }

                // This wont do anything because the web and site come from context, but still:
                workBox.Dispose();
            }
        }
Beispiel #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            String redirectionURL = "";

            String settingsPage = Request.QueryString["SettingsPage"];
            String returnUrl    = Request.QueryString["ReturnUrl"];

            if (String.IsNullOrEmpty(settingsPage))
            {
                settingsPage = "WorkBoxCollectionSettingsPage.aspx";
            }

            // By default we will assume that we're either on the WBC or even that we are creating the WBC for the first time:
            redirectionURL = SPContext.Current.Web.Url + "/_layouts/WorkBoxFramework/" + settingsPage;

            // But if we are on a work box then we'll need to redirect to the wb collection's URL:
            WorkBox workBox = WorkBox.GetIfWorkBox(SPContext.Current);

            if (workBox != null)
            {
                redirectionURL = workBox.Collection.Url + "/_layouts/WorkBoxFramework/" + settingsPage;

                // This will dispose of the WBCollection object too.
                workBox.Dispose();
            }
            else
            {
                // Maybe we're on one of the container sites so the parent site will be the WBCollection:
                SPWeb parent = SPContext.Current.Web.ParentWeb;
                if (parent != null)
                {
                    if (WBCollection.IsWebAWBCollection(parent))
                    {
                        redirectionURL = parent.Url + "/_layouts/WorkBoxFramework/" + settingsPage;
                    }

                    parent.Dispose();
                }
            }

            redirectionURL = redirectionURL + "?ReturnUrl=" + returnUrl;

            SPUtility.Redirect(redirectionURL, SPRedirectFlags.Static, Context);
        }
        private string makeTemplatesMenu()
        {
            WBLogging.DEBUG.Monitorable("In makeTemplatesMenu(): Start");

            // OK so a first simple attempt to build up the correct info into this dynamic menu:

            WorkBox workBox = WorkBox.GetIfWorkBox(SPContext.Current);

            if (workBox == null)
            {
                WBLogging.DEBUG.Monitorable("In makeTemplatesMenu(): workBox was null!");
                return(makeNoTemplatesMenu("workBox was null"));
            }

            SPDocumentLibrary templatesLibrary = workBox.DocumentTemplates;

            if (templatesLibrary == null)
            {
                WBLogging.DEBUG.Monitorable("In makeTemplatesMenu(): templatesLibrary was null!");
                return(makeNoTemplatesMenu("templatesLibrary was null"));
            }

            StringBuilder dynamicMenuXml = new StringBuilder("<Menu Id='WorkBoxFramework.DocumentTemplates.Menu'>");

            dynamicMenuXml.Append("<MenuSection Id='WorkBoxFramework.DocumentTemplates.Menu.Section' DisplayMode='Menu16'>");
            dynamicMenuXml.Append("<Controls Id='WorkBoxFramework.DocumentTemplates.Menu.Section.Controls'>");

            SPFolder rootFolder = templatesLibrary.RootFolder;

            addFolderContents(dynamicMenuXml, rootFolder, true);

            dynamicMenuXml.Append("</Controls> </MenuSection> </Menu>");

            string finalXML = dynamicMenuXml.ToString();

            WBLogging.DEBUG.Monitorable("In makeTemplatesMenu(): Finished creating XML: " + finalXML);

            return(finalXML);
        }
Beispiel #7
0
        protected override void Render(HtmlTextWriter writer)
        {
            WorkBox workBox = WorkBox.GetIfWorkBox(SPContext.Current);

            if (workBox == null)
            {
                errorLiteral.Text = "<i>(You can only use this web part in a work box)</i>";
            }
            else
            {
                WBTaxonomy recordsTypes = WBTaxonomy.GetRecordsTypes(SPContext.Current.Site);
                WBTaxonomy seriesTags   = WBTaxonomy.GetSeriesTags(recordsTypes);

                WBTerm thisSeries = workBox.SeriesTag(seriesTags);

                WBQuery query = new WBQuery();

                query.AddEqualsFilter(WBColumn.RecordsType, workBox.RecordsType);

                if (FilterBySeriesTag)
                {
                    query.AddEqualsFilter(WBColumn.SeriesTag, workBox.SeriesTag(seriesTags));
                }

                if (FilterByReferenceID)
                {
                    query.AddEqualsFilter(WBColumn.ReferenceID, workBox.ReferenceID);
                }

                //            if (FilterByOwningTeam)
                //            query.AddEqualsFilter(WBColumn.OwningTeam, workBox.OwningTeam);


                if (sortColumn != null)
                {
                    WBLogging.Debug("Sorting in Render with sortColumn: " + sortColumn.DisplayName);
                }
                else
                {
                    WBLogging.Debug("Sorting Render - sortColumn was null");
                }

                if (sortColumn != null)
                {
                    query.OrderBy(sortColumn, ascending);
                }

                query.AddViewColumn(WBColumn.Title);
                query.AddViewColumn(WBColumn.WorkBoxURL);
                query.AddViewColumn(WBColumn.ReferenceDate);
                query.AddViewColumn(WBColumn.WorkBoxStatus);

                WBColumn testIfIsThisWorkBox = new WBColumn("IfIsThisWorkBox", WBColumn.DataTypes.VirtualConditional);
                testIfIsThisWorkBox.TestColumnInternalName = WBColumn.Title.InternalName;
                testIfIsThisWorkBox.TestColumnValue        = workBox.Title;
                testIfIsThisWorkBox.ValueIfEqual           = "===>";

                query.AddViewColumn(testIfIsThisWorkBox);

                DataTable dataTable = workBox.Collection.Query(query);

                gridView.DataSource = new DataView(dataTable);

                BoundField testIfIsThisWorkBoxField = WBUtils.BoundField(testIfIsThisWorkBox, HorizontalAlign.Center, sortColumn, ascending);
                testIfIsThisWorkBoxField.HeaderText = "     ";

                gridView.Columns.Add(testIfIsThisWorkBoxField);
                gridView.Columns.Add(WBUtils.FixedIconTemplateField(WorkBox.ICON_16_IMAGE_URL, WBColumn.WorkBoxURL));
                gridView.Columns.Add(WBUtils.HyperLinkField(WBColumn.Title, WBColumn.WorkBoxURL, sortColumn, ascending));
                gridView.Columns.Add(WBUtils.BoundField(WBColumn.ReferenceDate, sortColumn, ascending));
                gridView.Columns.Add(WBUtils.BoundField(WBColumn.WorkBoxStatus, HorizontalAlign.Center, sortColumn, ascending));

                gridView.DataBind();


                if (ShowCreateNewLink)
                {
                    string createNewText = workBox.RecordsType.CreateNewWorkBoxText;
                    string createNewURL  = workBox.Collection.GetUrlForNewDialog(workBox, WorkBox.RELATION_TYPE__DYNAMIC);

                    createNewLink.Text = "<a href=\"#\" onclick=\"javascript: WorkBoxFramework_commandAction('" + createNewURL + "', 600, 500); \">" + createNewText + "</a>";
                }

                workBox.Dispose();
            }

            base.Render(writer);
        }
        protected override void OnPreRender(EventArgs e)
        {
            try
            {
                if (this.Page == null)
                {
                    return;
                }
                if (SPContext.Current == null)
                {
                    return;
                }

                SPRibbon currentRibbon = SPRibbon.GetCurrent(this.Page);

                WorkBox workBox = null;

                // If we're looking at a modal dialog box then we want to
                // leave workBox == null so that no further action is taken:
                if (Request.QueryString["IsDlg"] == null || Request.QueryString["IsDlg"] != "1")
                {
                    workBox = WorkBox.GetIfWorkBox(SPContext.Current);
                }

                if (workBox != null)
                {
                    //OK so we are looking at a work box.
                    isWorkBox = true;
                    SPWeb workBoxWeb = workBox.Web;

                    if (!currentRibbon.IsTabAvailable("WorkBoxFramework.Ribbon.WorkBox"))
                    {
                        currentRibbon.MakeTabAvailable("WorkBoxFramework.Ribbon.WorkBox");
                    }

                    // Now let's register the commands for the tasks flyout button:
                    // Inspired by blogs:
                    // http://www.sharepointnutsandbolts.com/2010/02/ribbon-customizations-dropdown-controls.html
                    // http://patrickboom.wordpress.com/2010/05/25/adding-a-custom-company-menu-tab-with-dynamic-menu-on-the-ribbon/
                    // http://www.wictorwilen.se/Post/Creating-a-SharePoint-2010-Ribbon-extension-part-2.aspx

                    WBLogging.DEBUG.Monitorable("About to do various for Tasks flyout menu:");

                    ScriptLink.RegisterScriptAfterUI(this.Page, "SP.Core.js", false, false);
                    ScriptLink.RegisterScriptAfterUI(this.Page, "CUI.js", false, false);
                    ScriptLink.RegisterScriptAfterUI(this.Page, "core.js", true, false);
                    ScriptLink.RegisterScriptAfterUI(this.Page, "SP.Ribbon.js", false, false);
                    ScriptLink.RegisterScriptAfterUI(this.Page, "SP.Runtime.js", false, false);
                    ScriptLink.RegisterScriptAfterUI(this.Page, "SP.js", false, false);
                    //ScriptLink.RegisterScriptAfterUI(this.Page, "WorkBoxFramework/PageComponent.js", false, true);

                    var commands = new List <IRibbonCommand>();

                    // register the command at the ribbon. Include the callback to the server to generate the xml
                    commands.Add(new SPRibbonCommand("WorkBoxFramework.Command.PopulateDynamicTasks", "if (wbf_callCount==0) WorkBoxFramework_getDynamicTasksMenu('',''); wbf_callCount++; if (wbf_callCount > 1000) wbf_menuXml = WorkBoxFramework_errorMenuXml('Timeout'); if (wbf_menuXml != '') properties.PopulationXML = wbf_menuXml;"));
                    commands.Add(new SPRibbonCommand("WorkBoxFramework.Command.PopulateDynamicTemplates", "if (wbf_callCount==0) WorkBoxFramework_getDynamicTasksMenu('',''); wbf_callCount++; if (wbf_callCount > 1000) wbf_menu2Xml = WorkBoxFramework_errorMenuXml('Timeout'); if (wbf_menu2Xml != '') properties.PopulationXML = wbf_menu2Xml;"));

                    //                commands.Add(new SPRibbonCommand("PopulateDynamicTasksCommand", "properties.PopulationXML = errorMenuXml();"));
                    //commands.Add(new SPRibbonCommand("PopulateDynamicTasksCommand", "alert('Callaa to Popdyn'); if (menuXml == '') { CreateServerMenu('',''); } else { properties.PopulationXML = menuXml; }"));
                    //                commands.Add(new SPRibbonCommand("PopulateDynamicTasksCommand", "alert('Call to Popdyn: ' + menuXml); properties.PopulationXML = menuXml;"));

                    //Register various:
                    var manager = new SPRibbonScriptManager();

                    // Register ribbon scripts
                    manager.RegisterGetCommandsFunction(Page, "getGlobalCommands", commands);
                    manager.RegisterCommandEnabledFunction(Page, "commandEnabled", commands);
                    manager.RegisterHandleCommandFunction(Page, "handleCommand", commands);

                    WBLogging.DEBUG.Monitorable("Registered ribbon scripts");


                    //Register initialize function
                    var methodInfo = typeof(SPRibbonScriptManager).GetMethod("RegisterInitializeFunction", BindingFlags.Instance | BindingFlags.NonPublic);
                    methodInfo.Invoke(manager, new object[] { Page, "InitPageComponent", "/_layouts/WorkBoxFramework/PageComponent.js", false, "WorkBoxFramework.PageComponent.initialize()" });


                    // register the client callbacks so that the JavaScript can call the server.
                    ClientScriptManager cm = this.Page.ClientScript;

                    String cbReference    = cm.GetCallbackEventReference(this, "arg", "WorkBoxFramework_receiveTasksMenu", "", "WorkBoxFramework_processCallBackError", false);
                    String callbackScript = "function WorkBoxFramework_getDynamicTasksMenu(arg, context) {" + cbReference + "; }";
                    WBLogging.DEBUG.Monitorable("Creating the call back function WorkBoxFramework_getDynamicTasksMenu to call: \n" + callbackScript);
                    cm.RegisterClientScriptBlock(this.GetType(), "WorkBoxFramework_getDynamicTasksMenu", callbackScript, true);


                    // Now let's check or set the last visited Guid:
                    WBUser      user    = new WBUser(workBox);
                    UserProfile profile = user.Profile;

//                    SPSite _site = SPContext.Current.Site;
//                  SPServiceContext _serviceContext = SPServiceContext.GetContext(_site);
//                UserProfileManager _profileManager = new UserProfileManager(_serviceContext);
//                    UserProfile profile = _profileManager.GetUserProfile(true);

                    scriptForSettingGlobalVariables = makeScriptForSettingWorkBoxVariables(workBox, user, profile);

                    UserProfileValueCollection lastVisitedGuidUserProfileValueCollection = profile[WorkBox.USER_PROFILE_PROPERTY__WORK_BOX_LAST_VISITED_GUID];
                    bool needsUpdating = false;
                    if (lastVisitedGuidUserProfileValueCollection == null || lastVisitedGuidUserProfileValueCollection.Count == 0)
                    {
                        needsUpdating = true;
                    }
                    else
                    {
                        Guid lastGuid = new Guid(lastVisitedGuidUserProfileValueCollection.Value.ToString());

                        if (!lastGuid.Equals(workBoxWeb.ID))
                        {
                            needsUpdating = true;
                        }
                    }

                    if (needsUpdating)
                    {
                        workBoxWeb.AllowUnsafeUpdates = true;

                        string currentGuidString = workBoxWeb.ID.ToString();
                        lastVisitedGuidUserProfileValueCollection.Clear();
                        lastVisitedGuidUserProfileValueCollection.Add(currentGuidString);

                        // OK now we're going to make sure that this work box is the latest on the list of recently visited work boxes:
                        WBLogging.WorkBoxes.Verbose("Updating the list of recently visited work boxes - as we've just come to this work box");
                        UserProfileValueCollection workBoxesRecentlyVisited = profile[WorkBox.USER_PROFILE_PROPERTY__MY_RECENTLY_VISITED_WORK_BOXES];


                        //string mostRecentWorkBoxDetails = workBoxWeb.Title + "|" + workBoxWeb.Url + "|" + workBox.UniqueID + "|" + workBoxWeb.ID.ToString() + "|" + DateTime.Now.Ticks;
                        WBLink mostRecentWorkBoxDetails = new WBLink(workBox, true);
                        WBLogging.WorkBoxes.Verbose("The most recent work box details are: " + mostRecentWorkBoxDetails);

                        List <String> newList = new List <String>();
                        newList.Add(mostRecentWorkBoxDetails.ToString());

                        if (workBoxesRecentlyVisited.Value != null)
                        {
                            string[] recentWorkBoxes = workBoxesRecentlyVisited.Value.ToString().Split(';');
                            int      totalLength     = 0;
                            foreach (string recentWorkBox in recentWorkBoxes)
                            {
                                if (totalLength >= 3000)
                                {
                                    break;
                                }
                                if (!recentWorkBox.Contains(currentGuidString))
                                {
                                    newList.Add(recentWorkBox);
                                    totalLength += recentWorkBox.Length + 1;
                                }
                            }
                        }

                        profile[WorkBox.USER_PROFILE_PROPERTY__MY_RECENTLY_VISITED_WORK_BOXES].Value = WBUtils.JoinUpToLimit(";", newList, 3100);

                        profile.Commit();
                        workBoxWeb.AllowUnsafeUpdates = false;
                    }
                }
                else
                {
                    scriptForSettingGlobalVariables = makeScriptForSettingNonWorkBoxVariables(SPContext.Current.Web);
                    if (currentRibbon.IsTabAvailable("WorkBoxFramework.Ribbon.WorkBox"))
                    {
                        currentRibbon.TrimById("WorkBoxFramework.Ribbon.WorkBox");
                    }
                }

                //          currentRibbon.MakeContextualGroupInitiallyVisible("WorkBoxFramework.Ribbon.ContextualGroup", string.Empty);
            }
            catch (Exception exception)
            {
                // If this isn't working - let's just do nothing so that at least the SharePoint site is visible.
                scriptForSettingGlobalVariables = "<!-- Exception thrown in MaybeShowWorkBoxRibbonTools \n\n" + exception.Message + "\n\n" + exception.StackTrace + "\n\n-->";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                String currentUserLoginName = SPContext.Current.Web.CurrentUser.LoginName;

                WBTaxonomy teams           = WBTaxonomy.GetTeams(SPContext.Current.Site);
                WBTaxonomy functionalAreas = WBTaxonomy.GetFunctionalAreas(teams);
                WBTeam     team            = WBTeam.GetFromTeamSite(teams, SPContext.Current.Web);
                if (team == null)
                {
                    WorkBox workBox = WorkBox.GetIfWorkBox(SPContext.Current);
                    if (workBox != null)
                    {
                        team = workBox.OwningTeam;
                    }
                }

                // Check if this user has permission - checking basic team membership:
                if (team == null || !team.IsCurrentUserTeamMember())
                {
                    AccessDeniedPanel.Visible          = true;
                    UpdateRecordsMetadataPanel.Visible = false;
                    AccessDeniedReason.Text            = "You are not a member of this team";
                    return;
                }

                RecordID.Text = Request.QueryString["RecordID"];
                WBLogging.Debug("Record ID is found to be: " + RecordID.Text);

                using (WBRecordsManager manager = new WBRecordsManager(currentUserLoginName))
                {
                    WBRecord record = manager.Libraries.GetRecordByID(RecordID.Text);

                    record.CheckMetadata();

                    Filename.Text    = record.Name;
                    RecordTitle.Text = record.Title;

                    String location = "<unknown>";
                    if (record.FunctionalArea != null && record.FunctionalArea.Count > 0)
                    {
                        WBLogging.Debug("Found functional area = " + record.FunctionalArea);
                        WBTerm functionalArea = record.FunctionalArea[0];
                        location = functionalArea.FullPath;
                        WBLogging.Debug("location = " + location);

                        WBTermCollection <WBTerm> teamsFunctionalAreas = team.FunctionalArea(functionalAreas);

                        if (!teamsFunctionalAreas.Contains(functionalArea))
                        {
                            WBLogging.Debug("Team functional areas UIControlValue: " + teamsFunctionalAreas.UIControlValue);
                            WBLogging.Debug("Record's functional area UIControlValue: " + functionalArea);

                            AccessDeniedPanel.Visible          = true;
                            UpdateRecordsMetadataPanel.Visible = false;
                            AccessDeniedReason.Text            = "The team " + team.Name + " does not have permission to edit this functional area: " + functionalArea.Name;
                            return;
                        }
                    }
                    location += "/" + record.RecordsType.FullPath;

                    String folders = record.ProtectedMasterRecord.LibraryRelativePath.Replace(record.Name, "").Replace(location, "");

                    RecordsLocation.Text = "<b>" + location + "</b> " + folders;

                    String status = record.RecordSeriesStatus;
                    RecordSeriesStatus.Text = status;

                    String explainStatus = "";
                    if (status == "Latest")
                    {
                        if (record.ProtectiveZone == WBRecordsType.PROTECTIVE_ZONE__PUBLIC)
                        {
                            explainStatus = "(live on the public website)";
                        }
                        else if (record.ProtectiveZone == WBRecordsType.PROTECTIVE_ZONE__PUBLIC_EXTRANET)
                        {
                            explainStatus = "(live on a public extranet website)";
                        }
                        else
                        {
                            explainStatus = "(live on izzi intranet)";
                        }
                    }
                    else if (status == "Retired")
                    {
                        explainStatus = "(visible on izzi intranet searches)";
                    }
                    else if (status == "Archived")
                    {
                        explainStatus = "(archived in the protected, master records library)";
                    }
                    ExplainStatus.Text = explainStatus;

                    RecordSeriesStatusChange.DataSource = new String[] { "", "Retire", "Archive" };
                    RecordSeriesStatusChange.DataBind();
                    RecordSeriesStatusChange.SelectedValue = "";

                    ProtectiveZone.DataSource = new String[] { WBRecordsType.PROTECTIVE_ZONE__PROTECTED, WBRecordsType.PROTECTIVE_ZONE__PUBLIC };
                    ProtectiveZone.DataBind();
                    ProtectiveZone.SelectedValue = record.ProtectiveZone;

                    manager.SubjectTagsTaxonomy.InitialiseTaxonomyControl(SubjectTags, WBColumn.SubjectTags.DisplayName, true);
                    SubjectTags.Text = record.SubjectTagsUIControlValue;

                    manager.TeamsTaxonomy.InitialiseTaxonomyControl(OwningTeam, WBColumn.OwningTeam.DisplayName, false);
                    OwningTeam.Text = record.OwningTeam.UIControlValue;

                    manager.TeamsTaxonomy.InitialiseTaxonomyControl(InvolvedTeams, WBColumn.InvolvedTeams.DisplayName, true);
                    InvolvedTeams.Text = record.InvolvedTeamsWithoutOwningTeamAsUIControlValue;
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// An item was added.
        /// </summary>
        public override void ItemAdded(SPItemEventProperties properties)
        {
            WBLogging.Teams.Unexpected("In WBLinkedCalendarUpdatesEventReceiver(): Requesting a new team event");

            if (properties.List == null)
            {
                WBLogging.Teams.Unexpected("The properties.List value was null!");
                return;
            }
            else
            {
                WBLogging.Teams.Unexpected("Calendar item added to list: " + properties.List.DefaultViewUrl);
            }

            String workBoxCollectionURL = properties.List.WBxGetProperty(WorkBox.LIST_PROPERTY__LINKED_CALENDAR__WORK_BOX_COLLECTION);
            String defaultTemplateTitle = properties.List.WBxGetProperty(WorkBox.LIST_PROPERTY__LINKED_CALENDAR__DEFAULT_TEMPLATE_TITLE);

            if (String.IsNullOrEmpty(workBoxCollectionURL) || String.IsNullOrEmpty(defaultTemplateTitle))
            {
                WBLogging.Teams.Unexpected("The linked calendar configuration properties were blank: " + workBoxCollectionURL + " | " + defaultTemplateTitle);
                return;
            }

            using (WBCollection collection = new WBCollection(workBoxCollectionURL))
                using (SPSite calendarSite = new SPSite(properties.WebUrl))
                    using (SPWeb calendarWeb = calendarSite.OpenWeb())
                    {
                        WorkBox onWorkBox = WorkBox.GetIfWorkBox(calendarSite, calendarWeb);

                        WBTaxonomy teams           = WBTaxonomy.GetTeams(collection.Site);
                        WBTeam     eventOwningTeam = WBTeam.GetFromTeamSite(teams, calendarWeb);

                        if (eventOwningTeam == null && onWorkBox != null)
                        {
                            eventOwningTeam = onWorkBox.OwningTeam;
                        }

                        if (eventOwningTeam == null)
                        {
                            WBLogging.Teams.Unexpected("Didn't find an eventOwningTeam for this calender creation event!!!");
                        }
                        else
                        {
                            WBLogging.Teams.Unexpected("Found team: " + eventOwningTeam.Name + " | " + eventOwningTeam.TeamSiteUrl);
                        }


                        DateTime eventDate = DateTime.Now;
                        if (properties.ListItem["EventDate"] == null)
                        {
                            if (properties.AfterProperties["EventDate"] == null)
                            {
                                WBLogging.Teams.Unexpected("Both ListItem and AfterProperties have null for 'EventDate' !!");
                            }
                            else
                            {
                                eventDate = (DateTime)properties.AfterProperties["EventDate"];
                            }
                        }
                        else
                        {
                            eventDate = (DateTime)properties.ListItem["EventDate"];
                        }

                        DateTime endDate = DateTime.Now.AddHours(1);
                        if (properties.ListItem["EndDate"] == null)
                        {
                            if (properties.AfterProperties["EndDate"] == null)
                            {
                                WBLogging.Teams.Unexpected("Both ListItem and AfterProperties have null for 'EndDate' !!");
                            }
                            else
                            {
                                endDate = (DateTime)properties.AfterProperties["EndDate"];
                            }
                        }
                        else
                        {
                            endDate = (DateTime)properties.ListItem["EndDate"];
                        }

                        WBLogging.Teams.Unexpected(" Start End times are: " + eventDate + " and " + endDate);

                        String title = properties.ListItem["Title"].WBxToString();

                        WBLogging.Teams.Unexpected(" Title is: " + title);

                        String description = "Changed"; // properties.ListItem["Description"].WBxToString();

                        WBLogging.Teams.Unexpected(" description is: " + description);

                        String calendarURL = calendarSite.Url + properties.List.DefaultViewUrl;

                        WorkBox workBox = collection.RequestNewEventWorkBox(
                            calendarURL,
                            properties.List.ID,
                            properties.ListItemId,
                            title,
                            description,
                            eventDate,
                            endDate,
                            eventOwningTeam,
                            null,
                            defaultTemplateTitle);

                        workBox.Open("Opening work box triggered by new event in a calendar.");

                        workBox.Dispose();
                    }

            base.ItemAdded(properties);
        }