Esempio n. 1
0
        private static string GetSingleValuedProperty(UserProfile spUser, string userProperty)
        {
            string returnString = string.Empty;

            try
            {
                UserProfileValueCollection propCollection = spUser[userProperty];

                if (propCollection[0] != null)
                {
                    returnString = propCollection[0].ToString();
                }
                else
                {
                    LogMessage(string.Format("User '{0}' does not have a value in property '{1}'", spUser.DisplayName, userProperty), LogLevel.Warning);
                }
            }
            catch
            {
                LogMessage(string.Format("User '{0}' does not have a value in property '{1}'", spUser.DisplayName, userProperty), LogLevel.Warning);
            }


            return(returnString);
        }
Esempio n. 2
0
        public String GetClipboardAction(UserProfile userProfile)
        {
            UserProfileValueCollection clipboardPropertyValue = userProfile[WorkBox.USER_PROFILE_PROPERTY__MY_WORK_BOX_CLIPBOARD];

            String clipboardString = "";

            if (clipboardPropertyValue != null)
            {
                clipboardString = clipboardPropertyValue.Value.WBxToString().Trim();
            }

            if (String.IsNullOrEmpty(clipboardString))
            {
                return("");
            }

            String actionString = "";

            string[] actionItemsSplit = clipboardString.Split('#');
            if (actionItemsSplit.Length == 1)
            {
                actionString = CLIPBOARD_ACTION__COPY;
            }
            else if (actionItemsSplit.Length == 2)
            {
                actionString = actionItemsSplit[0];
            }
            else
            {
                throw new NotImplementedException("The clipboard string is badly formed: " + clipboardString);
            }

            return(actionString);
        }
Esempio n. 3
0
        private static string GetMultiValuedProperty(UserProfile spUser, string userProperty)
        {
            StringBuilder sb        = new StringBuilder("");
            string        seperator = ConfigurationManager.AppSettings["PROPERTYSEPERATOR"];

            string returnString = string.Empty;

            try
            {
                UserProfileValueCollection propCollection = spUser[userProperty];

                if (propCollection.Count > 1)
                {
                    for (int i = 0; i < propCollection.Count; i++)
                    {
                        if (i == propCollection.Count - 1)
                        {
                            seperator = "";
                        }
                        sb.AppendFormat("{0}{1}", propCollection[i], seperator);
                    }
                }
                else if (propCollection.Count == 1)
                {
                    sb.AppendFormat("{0}", propCollection[0]);
                }
            }
            catch
            {
                LogMessage(string.Format("User '{0}' does not have a value in property '{1}'", spUser.DisplayName, userProperty), LogLevel.Warning);
            }

            return(sb.ToString());
        }
Esempio n. 4
0
        private String SetClipboard(UserProfile userProfile, String clipboardAction, Dictionary <String, List <int> > clipboardItems)
        {
            if (String.IsNullOrEmpty(clipboardAction))
            {
                clipboardAction = CLIPBOARD_ACTION__COPY;
            }

            UserProfileValueCollection clipboardPropertyValue = userProfile[WorkBox.USER_PROFILE_PROPERTY__MY_WORK_BOX_CLIPBOARD];

            String clipboardString = "";

            List <String> stringsForEachWorkBox = new List <String>();

            foreach (String workBoxURL in clipboardItems.Keys)
            {
                List <int> ids = clipboardItems[workBoxURL];

                List <String> idStrings = new List <String>();
                foreach (int id in ids)
                {
                    idStrings.Add(id.ToString());
                }

                String stringForAWorkBox = workBoxURL + "|" + String.Join("|", idStrings.ToArray());
                stringsForEachWorkBox.Add(stringForAWorkBox);
            }

            clipboardString = clipboardAction + "#" + String.Join(";", stringsForEachWorkBox.ToArray());

            clipboardPropertyValue.Value = clipboardString;
            userProfile.Commit();

            // returning an error string:
            return("");
        }
Esempio n. 5
0
        public String ClearClipboard(UserProfile userProfile)
        {
            UserProfileValueCollection clipboardPropertyValue = userProfile[WorkBox.USER_PROFILE_PROPERTY__MY_WORK_BOX_CLIPBOARD];

            clipboardPropertyValue.Value = "";
            userProfile.Commit();

            // returning an error string:
            return("");
        }
Esempio n. 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SPServiceContext   _serviceContext = SPServiceContext.GetContext(WorkBox.Site);
                UserProfileManager _profileManager = new UserProfileManager(_serviceContext);
                UserProfile        profile         = _profileManager.GetUserProfile(true);

                UserProfileValueCollection myFavouriteWorkBoxesPropertyValue = profile[WorkBox.USER_PROFILE_PROPERTY__MY_FAVOURITE_WORK_BOXES];

                string myFavouriteWorkBoxesString = "";

                if (myFavouriteWorkBoxesPropertyValue.Value != null)
                {
                    myFavouriteWorkBoxesString = myFavouriteWorkBoxesPropertyValue.Value.ToString();
                }

                if (myFavouriteWorkBoxesString.Contains(WorkBox.Web.ID.ToString()))
                {
                    // The user's favourites already contains this work box - so do nothing.
                    Message.Text = "The work box is already one of your favourites.";
                }
                else
                {
                    List <String> favourites = new List <String>();

                    if (!String.IsNullOrEmpty(myFavouriteWorkBoxesString.WBxTrim()))
                    {
                        favourites.AddRange(myFavouriteWorkBoxesString.Split(';'));
                    }

                    WBLink newFavourite = new WBLink(WorkBox, false);
                    favourites.Add(newFavourite.ToString());
                    //favourites.Add(WorkBox.Web.Title + "|" + WorkBox.Web.Url + "|" + WorkBox.UniqueID + "|" + WorkBox.Web.ID.ToString());

                    myFavouriteWorkBoxesString = WBUtils.JoinUpToLimit(";", favourites, 3100);

                    myFavouriteWorkBoxesPropertyValue.Value = myFavouriteWorkBoxesString;
                    WorkBox.Web.AllowUnsafeUpdates          = true;
                    profile.Commit();
                    WorkBox.Web.AllowUnsafeUpdates = false;

                    if (myFavouriteWorkBoxesString.Contains(WorkBox.Web.ID.ToString()))
                    {
                        Message.Text = "The work box has been added to your favourites.";
                    }
                    else
                    {
                        Message.Text = "The work box could not be added to your favourites as your list of favourites is too long.";
                    }
                }

                okButton.Focus();
            }
        }
Esempio n. 7
0
        public static List <String> GetWorkBoxURLsVisitedSinceTickTime(UserProfile profile, long ticksAtLastUpdate)
        {
            WBLogging.TimerTasks.Verbose("In GetWorkBoxURLsModidifiedSinceTickTime(): Looking at work boxes recently visited by: " + profile.DisplayName);

            List <String> listOfWorkBoxURLs = new List <string>();

            UserProfileValueCollection workBoxesRecentlyVisited = profile[WorkBox.USER_PROFILE_PROPERTY__MY_RECENTLY_VISITED_WORK_BOXES];
            String recentlyVisitedDetails = workBoxesRecentlyVisited.Value.WBxToString();

            if (!String.IsNullOrEmpty(recentlyVisitedDetails))
            {
                string[] recentWorkBoxes = recentlyVisitedDetails.Split(';');

                if (recentWorkBoxes.Length > 0)
                {
                    WBLogging.TimerTasks.Verbose("In GetWorkBoxURLsModidifiedSinceTickTime(): Found recently visited work boxes: " + recentWorkBoxes.Length);

                    List <String> updatedRecentWorkBoxes = new List <String>();

                    foreach (string recentWorkBoxLinkDetails in recentWorkBoxes)
                    {
                        WBLink workBoxLink = new WBLink(recentWorkBoxLinkDetails);
                        if (!workBoxLink.IsOK)
                        {
                            continue;
                        }

                        try
                        {
                            long ticksWhenVisited = 0;
                            if (workBoxLink.UsingTicksWhenVisited)
                            {
                                string ticksWhenVisitedString = workBoxLink.TicksWhenVisitedString;
                                ticksWhenVisited = Convert.ToInt64(workBoxLink.TicksWhenVisitedString);

                                if (ticksWhenVisited > ticksAtLastUpdate)
                                {
                                    listOfWorkBoxURLs.Add(workBoxLink.URL);
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            WBLogging.Teams.Unexpected("In GetWorkBoxURLsModidifiedSinceTickTime(): Something went wrong when looking for recently changed work boxes", exception);
                        }
                    }
                }
            }

            return(listOfWorkBoxURLs);
        }
Esempio n. 8
0
        /// <summary>
        ///     Function to retreive multiple values for a user profile field
        /// </summary>
        /// <param name="proValCol"></param>
        /// <returns></returns>
        private string getUserProfileMultiValue(UserProfileValueCollection proValCol)
        {
            StringBuilder sb         = new StringBuilder("");
            string        multiValue = string.Empty;

            //retrieve all values inisde property values collection
            foreach (Object obj in proValCol)
            {
                sb.AppendFormat("{0}<br/>", obj.ToString());
            }
            multiValue = sb.ToString();

            return(multiValue);
        }
Esempio n. 9
0
        public String GetUrlToMyUnprotectedWorkBox(SPSite site)
        {
            UserProfile profile = GetUserProfile(site);

            UserProfileValueCollection myUnprotectedWorkBoxURL = profile[WorkBox.USER_PROFILE_PROPERTY__MY_UNPROTECTED_WORK_BOX_URL];

            String url = "";

            if (myUnprotectedWorkBoxURL != null)
            {
                url = myUnprotectedWorkBoxURL.Value.WBxToString().Trim();
            }

            return(url);
        }
Esempio n. 10
0
        private string TryGetProperty(UserProfile profile, string propertyName)
        {
            string result = String.Empty;

            UserProfileValueCollection property = null;

            try
            {
                property = profile[propertyName];
                result   = property.Value?.ToString();
            }
            catch
            {
            }

            return(result);
        }
Esempio n. 11
0
        private bool getUserProfileDetailsById_BUG(long byUserID, SPWeb currentWeb, SPSite site)
        {
            try
            {
                //SPSite site = SPContext.Current.Site;
                SPServiceContext   ospServerContext      = SPServiceContext.GetContext(site);
                UserProfileManager ospUserProfileManager = new UserProfileManager(ospServerContext);

                UserProfile ospUserProfile = ospUserProfileManager.GetUserProfile(byUserID);
                Microsoft.Office.Server.UserProfiles.PropertyCollection propColl = ospUserProfile.ProfileManager.PropertiesWithSection;

                if (ospUserProfile != null && propColl != null)
                {
                    upFieldName  = new List <string>();
                    upFieldValue = new List <string>();

                    //Search through all user profile property fields
                    foreach (Property prop in propColl)
                    {
                        //Console.WriteLine("property Name : " + prop.Name);
                        //Console.WriteLine("proerpty Value : " + ospUserProfile[prop.Name].Value);
                        UserProfileValueCollection proValCol = ospUserProfile[prop.Name];
                        mapUserProfilePropertyValue(proValCol, prop, prop.Name, ospUserProfile[prop.Name].Value.ToString());
                    }

                    //Send email with any user profile fields not map to a custom list
                    reportUnManagedUserProfileProperties(currentWeb);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception err)
            {
                LogErrorHelper objErr = new LogErrorHelper(LIST_SETTING_NAME, currentWeb);
                objErr.logSysErrorEmail(APP_NAME, err, "Error at getUserProfileDetailsById function");
                objErr = null;

                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(APP_NAME, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, err.Message.ToString(), err.StackTrace);

                return(false);
            }
        }
Esempio n. 12
0
        internal static string PickSome(string [] allValues, Random rnd, UserProfileValueCollection userVals, int count)
        {
            string        temp = string.Empty;
            List <string> vals = new List <string> ();

            for (int c = 0; c < count; c++)
            {
                while (string.IsNullOrEmpty(temp) || vals.Contains(temp))
                {
                    temp = allValues [rnd.Next(0, allValues.Length)];
                }
                if (userVals != null)
                {
                    userVals.Add(temp);
                }
                vals.Add(temp);
            }
            return(string.Join(", ", vals.ToArray()));
        }
        protected void removeFromFavouritesButton_OnClick(object sender, EventArgs e)
        {
            SPSite             site           = SPContext.Current.Site;
            SPServiceContext   serviceContext = SPServiceContext.GetContext(site);
            UserProfileManager profileManager = new UserProfileManager(serviceContext);
            UserProfile        profile        = profileManager.GetUserProfile(true);

            UserProfileValueCollection myFavouriteWorkBoxesPropertyValue = profile[WorkBox.USER_PROFILE_PROPERTY__MY_FAVOURITE_WORK_BOXES];

            string myFavouriteWorkBoxesString = "";


            if (myFavouriteWorkBoxesPropertyValue.Value != null)
            {
                myFavouriteWorkBoxesString = myFavouriteWorkBoxesPropertyValue.Value.ToString();
            }

            string guidStringToRemove = WorkBoxGuid.Value;

            List <String> updatedFavouritesList = new List <String>();

            string[] favouriteWorkBoxes = myFavouriteWorkBoxesString.Split(';');
            foreach (string favouriteWorkBox in favouriteWorkBoxes)
            {
                if (!favouriteWorkBox.Contains(guidStringToRemove))
                {
                    updatedFavouritesList.Add(favouriteWorkBox);
                }
            }

            myFavouriteWorkBoxesPropertyValue.Value = String.Join(";", updatedFavouritesList.ToArray());

            site.AllowUnsafeUpdates = true;
            profile.Commit();
            site.AllowUnsafeUpdates = false;

            CloseDialogAndRefresh();
        }
Esempio n. 14
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string html  = "";
                int    count = 0;


                /*
                 *  First add the recent work boxes:
                 */

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

                UserProfileValueCollection workBoxesRecentlyVisited = profile[WorkBox.USER_PROFILE_PROPERTY__MY_RECENTLY_VISITED_WORK_BOXES];

                if (workBoxesRecentlyVisited.Value != null)
                {
                    string[] recentWorkBoxes = workBoxesRecentlyVisited.Value.ToString().Split(';');

                    if (recentWorkBoxes.Length > 0)
                    {
                        html += "<table cellpadding='5'>";
                        count = 0;
                        foreach (string recentWorkBox in recentWorkBoxes)
                        {
                            string[] details = recentWorkBox.Split('|');

                            string workBoxTitle = details[0];
                            string workBoxURL   = details[1];

                            html += string.Format("<tr><td><img src='/_layouts/images/WorkBoxFramework/work-box-16.png'/></td><td><a href='#' onclick='javascript: WorkBoxFramework_WorkBoxPicker_pickWorkBox(\"{0}\", \"{1}\");'>{1}</a></td></tr>\n", workBoxURL, workBoxTitle);

                            count++;
                            if (count >= 10)
                            {
                                break;
                            }
                        }
                        html += "</table>";
                    }
                    else
                    {
                        html += "<i>(No recently visited work boxes)</i>";
                    }
                }
                else
                {
                    html += "<i>(No recently visited work boxes)</i>";
                }


                RecentWorkBoxes.Text = html;


                html = "";


                /*
                 *  Now add the favourite work boxes:
                 */

                UserProfileValueCollection myFavouriteWorkBoxesPropertyValue = profile[WorkBox.USER_PROFILE_PROPERTY__MY_FAVOURITE_WORK_BOXES];

                if (myFavouriteWorkBoxesPropertyValue.Value != null)
                {
                    string[] myFavouriteWorkBoxes = myFavouriteWorkBoxesPropertyValue.Value.ToString().Split(';');

                    if (myFavouriteWorkBoxes.Length > 0)
                    {
                        html += "<table cellpadding='5'>";
                        count = 0;
                        foreach (string recentWorkBox in myFavouriteWorkBoxes)
                        {
                            string[] details = recentWorkBox.Split('|');

                            string workBoxTitle = details[0];
                            string workBoxURL   = details[1];

                            html += string.Format("<tr><td><img src='/_layouts/images/WorkBoxFramework/work-box-16.png'/></td><td><a href='#' onclick='javascript: WorkBoxFramework_WorkBoxPicker_pickWorkBox(\"{0}\", \"{1}\");'>{1}</a></td></tr>\n", workBoxURL, workBoxTitle);

                            count++;
                            if (count >= 10)
                            {
                                break;
                            }
                        }
                        html += "</table>";
                    }
                    else
                    {
                        html += "<i>(No favourite work boxes)</i>";
                    }
                }
                else
                {
                    html += "<i>(No favourite work boxes)</i>";
                }


                FavouriteWorkBoxes.Text = html;
            }
        }
Esempio n. 15
0
        protected override void CreateChildControls()
        {
            Literal literal = new Literal();
            string  html    = "";


            try
            {
                html += "<style type=\"text/css\">\n tr.wbf-extra-favourites-items {display:none;}\n</style>\n\n" + getScriptCode();

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

                UserProfileValueCollection myFavouriteWorkBoxesPropertyValue = profile[WorkBox.USER_PROFILE_PROPERTY__MY_FAVOURITE_WORK_BOXES];

                // If the NumberToShow value isn't set or is set zero or negative then fix the web part to show 5 items:
                if (NumberToShow <= 0)
                {
                    NumberToShow = 5;
                }

                if (myFavouriteWorkBoxesPropertyValue.Value != null)
                {
                    string[] myFavouriteWorkBoxes = myFavouriteWorkBoxesPropertyValue.Value.ToString().Split(';');

                    // We actually want to display the most recently added favourite first even though it'll be last in the list so:
                    Array.Reverse(myFavouriteWorkBoxes);

                    if (myFavouriteWorkBoxes.Length > 0)
                    {
                        html += "<table cellpadding='5' width='100%'>";
                        int    count         = 0;
                        bool   hasExtraItems = false;
                        String cssClass      = "";

                        foreach (string workBoxLinkDetails in myFavouriteWorkBoxes)
                        {
                            WBLink workBoxLink = new WBLink(workBoxLinkDetails);
                            if (!workBoxLink.IsOK)
                            {
                                continue;
                            }

                            count++;

                            if (count > NumberToShow)
                            {
                                cssClass      = " class='wbf-extra-favourites-items'";
                                hasExtraItems = true;
                            }

                            /*
                             * string[] details = recentWorkBoxDetails.Split('|');
                             *
                             * string guidString = details[2];
                             * if (details.Length == 4)
                             *  guidString = details[3];
                             *
                             * html += "<tr" + cssClass + "><td><img src='/_layouts/images/WorkBoxFramework/work-box-16.png'/></td><td><a href='";
                             * html += details[1];
                             * html += "'>" + details[0] + "</a></td>";
                             *
                             * String command = "RemoveWorkBoxFromFavourites.aspx?workBoxTitle=" + HttpUtility.UrlEncode(details[0]) + "&workBoxGuid=" + guidString;
                             *
                             * html += "<td><a href='#' onclick='javascript: WorkBoxFramework_relativeCommandAction(\"" + command + "\", 0, 0);'>remove</a></td>";
                             * html += "</tr>";
                             */

                            html += "<tr" + cssClass + "><td><img src='/_layouts/images/WorkBoxFramework/work-box-16.png'/></td><td><a href='";
                            html += workBoxLink.URL;
                            html += "'>" + workBoxLink.Title + "</a></td>";

                            String command = "RemoveWorkBoxFromFavourites.aspx?workBoxTitle=" + HttpUtility.UrlEncode(workBoxLink.Title) + "&workBoxGuid=" + workBoxLink.SPWebGUID;

                            html += "<td><a href='#' onclick='javascript: WorkBoxFramework_relativeCommandAction(\"" + command + "\", 0, 0);'>remove</a></td>";
                            html += "</tr>";
                        }

                        if (hasExtraItems)
                        {
                            html += "<tr class=\"wbf-show-more-favourites-link\"><td colspan='3' align='right'><a href='#' onclick='javascript: $(\".wbf-extra-favourites-items\").show(); $(\".wbf-show-more-favourites-link\").hide(); '>More favourite work boxes ...</a></td></tr>";
                            html += "<tr class=\"wbf-extra-favourites-items\"><td colspan='3' align='right'><a href='#' onclick='javascript: $(\".wbf-extra-favourites-items\").hide(); $(\".wbf-show-more-favourites-link\").show(); '>Fewer favourite work boxes</a></td></tr>";
                        }

                        html += "</table>";
                    }
                    else
                    {
                        html += "<i>(No favourite work boxes)</i>";
                    }
                }
                else
                {
                    html += "<i>(No favourite work boxes)</i>";
                }
            }
            catch (Exception e)
            {
                html += "<i>(An error occurred)</i> \n\n <!-- \n Exception was: " + e.WBxFlatten() + " \n\n -->";
            }

            literal.Text = html;

            this.Controls.Add(literal);
        }
Esempio n. 16
0
        public override List <GDPRSubject> GetAllSubjects(int skip, int count, DateTime?changeDate)
        {
            List <GDPRSubject> subjects = new List <GDPRSubject>();

            SPFarm farm = SPFarm.Local;

            bool done = false;

            SPWebService service = farm.Services.GetValue <SPWebService>("");

            foreach (SPWebApplication webApp in service.WebApplications)
            {
                foreach (SPSite site in webApp.Sites)
                {
                    if (done)
                    {
                        return(subjects);
                    }

                    //get user profiles...
                    SPServiceContext serviceContext = SPServiceContext.GetContext(site);

                    try
                    {
                        UserProfileManager userProfileMgr = new UserProfileManager(serviceContext);

                        foreach (UserProfile profile in userProfileMgr)
                        {
                            GDPRSubject s = new GDPRSubject();
                            s.Attributes           = new System.Collections.Hashtable();
                            s.ApplicationSubjectId = profile.ID.ToString();

                            foreach (var prop in profile.Properties)
                            {
                                UserProfileValueCollection val = profile[prop.Name];

                                if (val == null || val.Value == null)
                                {
                                    continue;
                                }

                                s.Attributes.Add(prop.Name, val.Value);

                                switch (prop.Name)
                                {
                                case "FirstName":
                                    s.FirstName = val.Value.ToString();
                                    break;

                                case "LastName":
                                    s.LastName = val.Value.ToString();
                                    break;

                                case "AboutMe":
                                    break;

                                case "WorkPhone":
                                case "MobilePhone":
                                case "HomePhone":
                                    BasePhone p = BasePhone.Parse(val.Value.ToString());

                                    if (p != null)
                                    {
                                        GDPRSubjectPhone sp = new GDPRSubjectPhone();
                                        sp.Raw = p.ToString();
                                        s.Phones.Add(sp);
                                    }
                                    break;

                                case "WorkEmail":
                                    s.EmailAddresses.Add(new GDPRSubjectEmail {
                                        EmailAddress = val.Value.ToString()
                                    });
                                    break;

                                case "OfficeLocation":
                                    string      address = val.Value.ToString();
                                    BaseAddress a       = core.GeocodeAddress(null, address);
                                    s.Addresses.Add(new GDPRSubjectAddress()
                                    {
                                        Raw = a.ToString()
                                    });
                                    break;

                                case "Birthday":
                                    s.BirthDate = DateTime.Parse(val.Value.ToString());
                                    break;
                                }
                            }

                            subjects.Add(s);
                        }

                        done = true;
                    }
                    catch (System.Exception e)
                    {
                        Console.WriteLine(e.GetType().ToString() + ": " + e.Message);
                        Console.Read();
                    }
                }
            }

            return(subjects);
        }
Esempio n. 17
0
        public override RecordPropertyValueCollection GetPropertyValues(Record rec, RecordProperty prop)
        {
            roxority.Shared.Func <int>    getCount = null;
            roxority.Shared.Func <object> getValue = null;
            bool          isHtml    = false;
            UserProfile   mainItem  = rec.MainItem as UserProfile;
            List <object> list      = null;
            SPUser        user      = null;
            Property      property2 = prop.Property as Property;

            if (property2 != null)
            {
                isHtml = property2.Type == "HTML";
            }
            if (prop.Name == "roxVcardExport")
            {
                return(new RecordPropertyValueCollection(this, rec, prop, new object[] { UserDataSource.GetVcardExport(rec) }, null, null, null));
            }
            if (prop.Name == "roxSiteGroups")
            {
                string         str;
                RecordProperty property;
                RecordPropertyValueCollection values;
                list = new List <object>();
                if ((((property = rec.DataSource.Properties.GetPropertyByName("AccountName")) != null) && ((values = this.GetPropertyValues(rec, property)) != null)) && !string.IsNullOrEmpty(str = values.Value + string.Empty))
                {
                    try
                    {
                        user = SPContext.Current.Web.AllUsers[str];
                    }
                    catch
                    {
                    }
                    if (user != null)
                    {
                        foreach (SPGroup group in ProductPage.TryEach <SPGroup>(user.Groups))
                        {
                            try
                            {
                                list.Add(group.Name);
                            }
                            catch
                            {
                            }
                        }
                    }
                }
                return(new RecordPropertyValueCollection(this, rec, prop, list.ToArray(), null, null, null));
            }
            if (prop.Name == "roxUserPersonalUrl")
            {
                return(new RecordPropertyValueCollection(this, rec, prop, new object[] { base.GetPersonalUrl(rec) }, null, null, null));
            }
            if (prop.Name == "roxUserPublicUrl")
            {
                return(new RecordPropertyValueCollection(this, rec, prop, new object[] { base.GetPublicUrl(rec) }, null, null, null));
            }
            UserProfileValueCollection vals = mainItem[prop.Name];

            if (getCount == null)
            {
                getCount = () => vals.Count;
            }
            if (getValue == null)
            {
                getValue = delegate {
                    if (isHtml)
                    {
                        return("<roxhtml/>" + vals.Value);
                    }
                    return(vals.Value);
                };
            }
            return(new RecordPropertyValueCollection(this, rec, prop, null, isHtml ? Array.ConvertAll <object, string>(new ArrayList(vals).ToArray(), o => "<roxhtml/>" + o).GetEnumerator() : vals.GetEnumerator(), getCount, getValue));
        }
Esempio n. 18
0
        protected override void CreateChildControls()
        {
            Literal literal = new Literal();
            string  html    = "<style type=\"text/css\">\n tr.wbf-extra-recent-items {display:none;}\n</style>\n\n";

            try
            {
                // Now let's check or set the last visited Guid:
                SPSite             _site           = SPContext.Current.Site;
                SPServiceContext   _serviceContext = SPServiceContext.GetContext(_site);
                UserProfileManager _profileManager = new UserProfileManager(_serviceContext);
                UserProfile        profile         = _profileManager.GetUserProfile(true);

                UserProfileValueCollection workBoxesRecentlyVisited = profile[WorkBox.USER_PROFILE_PROPERTY__MY_RECENTLY_VISITED_WORK_BOXES];

                // If the NumberToShow value isn't set or is set zero or negative then fix the web part to show 5 items:
                if (NumberToShow <= 0)
                {
                    NumberToShow = 5;
                }

                if (workBoxesRecentlyVisited.Value != null)
                {
                    string[] recentWorkBoxes = workBoxesRecentlyVisited.Value.ToString().Split(';');

                    if (recentWorkBoxes.Length > 0)
                    {
                        html += "<table cellpadding='5' width='100%'>";
                        int    count         = 0;
                        bool   hasExtraItems = false;
                        String cssClass      = "";

                        foreach (string workBoxLinkDetails in recentWorkBoxes)
                        {
                            WBLink workBoxLink = new WBLink(workBoxLinkDetails);
                            if (!workBoxLink.IsOK)
                            {
                                continue;
                            }

                            //string[] details = workBoxLinkDetails.Split('|');

                            //String workBoxTitle = details[0];
                            //String workBoxUrl = details[1];
                            //String workBoxUniqueID = details[2];

                            // We're going to skip any work box whose title matches the unique prefix being filtered:
                            if (!String.IsNullOrEmpty(UniquePrefixToFilter))
                            {
                                if (workBoxLink.UniqueID.StartsWith(UniquePrefixToFilter))
                                {
                                    continue;
                                }
                            }

                            count++;
                            if (count > NumberToShow)
                            {
                                cssClass      = " class='wbf-extra-recent-items'";
                                hasExtraItems = true;
                            }

                            html += "<tr" + cssClass + "><td><img src='/_layouts/images/WorkBoxFramework/work-box-16.png'/></td><td><a href='";
                            html += workBoxLink.URL;
                            html += "'>" + workBoxLink.Title + "</a></td></tr>";
                        }

                        if (hasExtraItems)
                        {
                            html += "<tr class=\"wbf-show-more-recent-link\"><td colspan='2' align='right'><a href='#' onclick='javascript: $(\".wbf-extra-recent-items\").show(); $(\".wbf-show-more-recent-link\").hide(); '>More recent work boxes ...</a></td></tr>";
                            html += "<tr class=\"wbf-extra-recent-items\"><td colspan='2' align='right'><a href='#' onclick='javascript: $(\".wbf-extra-recent-items\").hide(); $(\".wbf-show-more-recent-link\").show(); '>Fewer recent work boxes</a></td></tr>";
                        }

                        html += "</table>";
                    }
                    else
                    {
                        html += "<i>(No recently visited work boxes)</i>";
                    }
                }
                else
                {
                    html += "<i>(No recently visited work boxes)</i>";
                }
            }
            catch (Exception e)
            {
                html += "<i>(An error occurred)</i> \n\n <!-- \n Exception was: " + e.WBxFlatten() + " \n\n -->";
            }

            literal.Text = html;

            this.Controls.Add(literal);
        }
Esempio n. 19
0
        public static void CheckTitlesOfFavouriteWorkBoxes(SPSite cacheSite, SPList cacheList, UserProfile profile)
        {
            WBLogging.TimerTasks.Verbose("Checking titles of favourite work boxes of: " + profile.DisplayName);

            UserProfileValueCollection favouriteWorkBoxesPropertyValue = profile[WorkBox.USER_PROFILE_PROPERTY__MY_FAVOURITE_WORK_BOXES];
            String favouriteWBDetails = favouriteWorkBoxesPropertyValue.Value.WBxToString();

            if (!String.IsNullOrEmpty(favouriteWBDetails))
            {
                string[] favouriteWorkBoxes = favouriteWBDetails.Split(';');

                if (favouriteWorkBoxes.Length > 0)
                {
                    WBLogging.TimerTasks.Verbose("Found favourite work boxes: " + favouriteWorkBoxes.Length);

                    bool hasChangesToSave = false;

                    List <String> updatedFavouriteWorkBoxes = new List <String>();

                    foreach (string favouriteWorkBoxLinkDetails in favouriteWorkBoxes)
                    {
                        WBLink workBoxLink = new WBLink(favouriteWorkBoxLinkDetails);
                        if (!workBoxLink.IsOK)
                        {
                            continue;
                        }

                        /*
                         * string[] details = favouriteWorkBoxLinkDetails.Split('|');
                         * string workBoxTitle = details[0];
                         * string workBoxUrl = details[1];
                         * string workBoxUniqueID = details[2];
                         * string workBoxGUID = details[3];
                         */

                        try
                        {
                            WBQuery query = new WBQuery();
                            query.AddEqualsFilter(WBColumn.WorkBoxGUID, workBoxLink.SPWebGUID);
                            query.AddViewColumn(WBColumn.Title);

                            SPListItemCollection items = cacheList.WBxGetItems(cacheSite, query);

                            if (items.Count > 0)
                            {
                                String cachedWBTitle = items[0].WBxGetAsString(WBColumn.Title);
                                if (cachedWBTitle != workBoxLink.Title)
                                {
                                    WBLogging.TimerTasks.Verbose("Updating work box title in favourite list: " + workBoxLink.Title + " -> " + cachedWBTitle);
                                    workBoxLink.Title = cachedWBTitle;
                                    hasChangesToSave  = true;
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            WBLogging.Teams.Monitorable("Something went wrong when searching for a favourite work box" + exception.Message);
                        }


                        updatedFavouriteWorkBoxes.Add(workBoxLink.ToString());
                    }


                    if (hasChangesToSave)
                    {
                        profile[WorkBox.USER_PROFILE_PROPERTY__MY_FAVOURITE_WORK_BOXES].Value = WBUtils.JoinUpToLimit(";", updatedFavouriteWorkBoxes, 3100);
                        profile.Commit();
                    }
                }
            }
        }
Esempio n. 20
0
        public static void CheckLastModifiedDatesAndTitlesOfRecentWorkBoxes(SPSite cacheSite, SPList cacheList, UserProfile profile, long ticksAtLastUpdate)
        {
            WBLogging.TimerTasks.Verbose("Looking at work boxes recently visited by: " + profile.DisplayName);

            UserProfileValueCollection workBoxesRecentlyVisited = profile[WorkBox.USER_PROFILE_PROPERTY__MY_RECENTLY_VISITED_WORK_BOXES];
            String recentlyVisitedDetails = workBoxesRecentlyVisited.Value.WBxToString();

            if (!String.IsNullOrEmpty(recentlyVisitedDetails))
            {
                string[] recentWorkBoxes = recentlyVisitedDetails.Split(';');

                if (recentWorkBoxes.Length > 0)
                {
                    WBLogging.TimerTasks.Verbose("Found recently visited work boxes: " + recentWorkBoxes.Length);

                    bool hasChangesToSave = false;

                    List <String> updatedRecentWorkBoxes = new List <String>();

                    foreach (string recentWorkBoxLinkDetails in recentWorkBoxes)
                    {
                        WBLink workBoxLink = new WBLink(recentWorkBoxLinkDetails);
                        if (!workBoxLink.IsOK)
                        {
                            continue;
                        }

                        /*
                         * string[] details = recentWorkBoxLinkDetails.Split('|');
                         * string workBoxTitle = details[0];
                         * string workBoxUrl = details[1];
                         * string workBoxUniqueID = details[2];
                         * string workBoxGUID = details[3];
                         */

                        try
                        {
                            long ticksWhenVisited = 0;
                            //if (details.Length >= 5)
                            if (workBoxLink.UsingTicksWhenVisited)
                            {
                                string ticksWhenVisitedString = workBoxLink.TicksWhenVisitedString;
                                ticksWhenVisited = Convert.ToInt64(workBoxLink.TicksWhenVisitedString);

                                // Would we have already done this recently visited work box during the last update:
                                if (ticksWhenVisited > ticksAtLastUpdate)
                                {
                                    // OK so we're going to update the details for this work box:
                                    using (WorkBox workBox = new WorkBox(workBoxLink.URL))
                                    {
                                        workBox.RecentlyVisited(cacheList, ticksWhenVisited);
                                    }
                                }
                            }

                            WBQuery query = new WBQuery();
                            query.AddEqualsFilter(WBColumn.WorkBoxGUID, workBoxLink.SPWebGUID);
                            query.AddViewColumn(WBColumn.Title);

                            SPListItemCollection items = cacheList.WBxGetItems(cacheSite, query);

                            if (items.Count > 0)
                            {
                                String cachedWBTitle = items[0].WBxGetAsString(WBColumn.Title);
                                if (cachedWBTitle != workBoxLink.Title)
                                {
                                    WBLogging.TimerTasks.Verbose("Updating work box title in recently visited list: " + workBoxLink.Title + " -> " + cachedWBTitle);
                                    workBoxLink.Title = cachedWBTitle;
                                    hasChangesToSave  = true;
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            WBLogging.Teams.Monitorable("Something went wrong when searching for a favourite work box" + exception.Message);
                        }

                        updatedRecentWorkBoxes.Add(workBoxLink.ToString());
                    }


                    if (hasChangesToSave)
                    {
                        profile[WorkBox.USER_PROFILE_PROPERTY__MY_RECENTLY_VISITED_WORK_BOXES].Value = WBUtils.JoinUpToLimit(";", updatedRecentWorkBoxes, 3100);
                        profile.Commit();
                    }
                }
            }
        }
Esempio n. 21
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string html      = "";
            string userValue = "";
            UserProfileValueCollection valueCollection = null;
            object valueObject = null;

            _site                     = SPContext.Current.Site;
            _serviceContext           = SPServiceContext.GetContext(_site);
            _userProfileConfigManager = new UserProfileConfigManager(_serviceContext);
            _profilePropertyManager   = _userProfileConfigManager.ProfilePropertyManager;

            _profileManager = new UserProfileManager(_serviceContext);
            _profileSubtypePropertyManager = _profileManager.DefaultProfileSubtypeProperties;

            // if you need another profile subtype
            //_profileSubtypePropertyManager = _profilePropertyManager.GetProfileSubtypeProperties("ProfileSubtypeName");

            _corePropertyManager        = _profilePropertyManager.GetCoreProperties();
            _profileTypePropertyManager = _profilePropertyManager.GetProfileTypeProperties(ProfileType.User);

            UserProfile profile = _profileManager.GetUserProfile(true);

            html += "<h1>First listing out all of the property types themselves</h1>";

            html += "<h2>ProfileSubtypeProperty list</h2>";

            html += "<table cellspacing='2' border='1'>";

            html += "<tr><th>Section/Property</th><th>Name</th><th>Display Name</th><th>Type Property Name</th><th>Core Property Name</th><th>Display Order</th><th>Current User's Value</th></tr>";

            foreach (ProfileSubtypeProperty profileSubtypeProperty in _profileSubtypePropertyManager.PropertiesWithSection)
            {
                userValue = "";
                if (!profileSubtypeProperty.IsSection)
                {
                    userValue       = "<i>(none)</i>";
                    valueCollection = profile[profileSubtypeProperty.Name];
                    if (valueCollection != null)
                    {
                        valueObject = valueCollection.Value;
                        if (valueObject != null)
                        {
                            userValue = valueObject.ToString();
                        }
                    }
                }


                html += string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6}</td></tr>",
                                      profileSubtypeProperty.IsSection ? "Section" : "Property",
                                      profileSubtypeProperty.Name,
                                      profileSubtypeProperty.DisplayName,
                                      profileSubtypeProperty.TypeProperty.Name,
                                      profileSubtypeProperty.CoreProperty.Name,
                                      profileSubtypeProperty.DisplayOrder,
                                      userValue);
            }

            html += "</table>";

            html += "<h2>ProfileTypeProperty list</h2>";

            html += "<table cellspacing='2' border='1'>";

            html += "<tr><th>Section/Property</th><th>Name</th><th>Core Property Name</th></tr>";

            foreach (ProfileTypeProperty profileTypeProperty in _profileTypePropertyManager.PropertiesWithSection)
            {
                html += string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>",
                                      profileTypeProperty.IsSection ? "Section" : "Property",
                                      profileTypeProperty.Name,
                                      profileTypeProperty.CoreProperty.Name);
            }

            html += "</table>";

            html += "<h2>CoreProperty list</h2>";
            html += "<table cellspacing='2' border='1'>";

            html += "<tr><th>Section/Property</th><th>(Core Property) Name</th><th>Display Name</th><th>Type</th></tr>";

            foreach (CoreProperty coreProperty in _corePropertyManager.PropertiesWithSection)
            {
                html += string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>",
                                      coreProperty.IsSection ? "Section" : "Property",
                                      coreProperty.Name,
                                      coreProperty.DisplayName,
                                      coreProperty.Type); //,
                //coreProperty.UseCount
                //"BUG!" );
            }

            html += "</table>";

            UserProfileValueCollection values = profile[PropertyConstants.PictureUrl];

            if (values.Count > 0)
            {
                // Author Image: {37A5CA4C-7621-44d7-BF3B-583F742CE52F}

                SPFieldUrlValue urlValue = new SPFieldUrlValue(values.Value.ToString());

                html += "<p><b>PictureUrl = " + urlValue.Url + "</b></p>";
            }

            html += "<p><b>User account = " + profile[PropertyConstants.AccountName].Value.ToString() + "</b></p>";


            Content.Text = html;
        }
Esempio n. 22
0
        /// <summary>
        ///     Map internal property field value to class members
        /// </summary>
        /// <reference>
        ///     1. http://www.isurinder.com/Blog/Post/2011/02/01/Retrieve-and-Manage-User-Profile-Properties-in-SharePoint-2010
        /// </reference>
        /// <param name="fieldName"></param>
        private void mapUserProfilePropertyValue(UserProfileValueCollection proValCol, Property prop, string internalPropertyFieldName, string fieldValue)
        {
            //Check if this property has a multiple values to retrieve all values as an objects from it
            if (prop.IsMultivalued)
            {
                //TODO: handle multi-value routine
                switch (internalPropertyFieldName)
                {
                case "AccountName":
                    _accountName = getUserProfileMultiValue(proValCol);
                    break;

                default:
                    break;
                }
            }
            else
            {
                switch (internalPropertyFieldName)
                {
                case "AccountName":
                    _accountName = fieldValue;
                    break;

                case "FirstName":
                    _firstName = fieldValue;
                    break;

                case "LastName":
                    _lastName = fieldValue;
                    break;

                case "EmployeeID":
                    _employeeID = fieldValue;
                    break;

                case "DepartmentNumber":    //TODO:- Investigate internal fieldname
                    _deptNum = fieldValue;
                    break;

                case "Department":
                    _division = fieldValue;
                    break;

                case "IPPhone":
                    _ipPhone = fieldValue;
                    break;

                case "WorkPhone":
                    _workPhone = fieldValue;
                    break;

                case "WorkEmail":
                    _email = fieldValue;
                    break;

                case "Manager":
                    _manager = fieldValue;
                    break;

                case "CompanyName":     //TODO:- Find internal field name
                    _companyName = fieldValue;
                    break;

                case "Office":
                    _officeAddress = fieldValue;
                    break;

                case "StartDate":
                    _startDate = ConvertToDateTime(fieldValue);
                    break;

                default:
                    upFieldName.Add(internalPropertyFieldName);
                    upFieldValue.Add(fieldValue);
                    break;
                }
            }
        }
Esempio n. 23
0
        /// <summary>
        /// This method returns the action of the clipboard while filling the 'clipboardItems' dictionary and
        /// therefore returns the two key values from the clipboard in one go. The passed in clipboardItems dictionary
        /// must be empty.
        /// </summary>
        /// <param name="userProfile"></param>
        /// <param name="clipboardItems">An empty dictionary object that will be filled with any clipboard items.</param>
        /// <returns>The clipboard action of either 'COPY' or 'CUT'</returns>
        public String GetClipboard(UserProfile userProfile, Dictionary <String, List <int> > clipboardItems)
        {
            if (clipboardItems.Count != 0)
            {
                throw new NotImplementedException("You should only use this method with an empty clipboardItems dictionary object");
            }

            UserProfileValueCollection clipboardPropertyValue = userProfile[WorkBox.USER_PROFILE_PROPERTY__MY_WORK_BOX_CLIPBOARD];

            String clipboardString = "";

            if (clipboardPropertyValue != null)
            {
                clipboardString = clipboardPropertyValue.Value.WBxToString().Trim();
            }

            if (String.IsNullOrEmpty(clipboardString))
            {
                return("");
            }

            String clipboardItemsString = "";
            String actionString         = CLIPBOARD_ACTION__COPY;

            string[] actionItemsSplit = clipboardString.Split('#');
            if (actionItemsSplit.Length == 1)
            {
                clipboardItemsString = actionItemsSplit[0];
            }
            else if (actionItemsSplit.Length == 2)
            {
                actionString         = actionItemsSplit[0];
                clipboardItemsString = actionItemsSplit[1];
            }
            else
            {
                throw new NotImplementedException("The clipboard string is badly formed: " + clipboardString);
            }

            string[] valuesForEachWorkBox = clipboardItemsString.Split(';');

            foreach (string valueForAWorkBox in valuesForEachWorkBox)
            {
                if (String.IsNullOrEmpty(valueForAWorkBox) || !valueForAWorkBox.Contains('|'))
                {
                    throw new NotImplementedException("The clipboard string is badly formed: " + clipboardString);
                }

                List <String> listOfIDStrings = new List <String>(valueForAWorkBox.Split('|'));

                String workBoxURL = listOfIDStrings[0];
                listOfIDStrings.RemoveAt(0);

                List <int> listOfIDs = new List <int>();
                foreach (String idString in listOfIDStrings)
                {
                    listOfIDs.Add(Int32.Parse(idString));
                }

                clipboardItems.Add(workBoxURL, listOfIDs);
            }

            return(actionString);
        }
        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-->";
            }
        }