예제 #1
0
        /// <summary/>
        public static void Transform(System.Xaml.XamlReader reader, System.Xaml.XamlWriter writer, System.Xaml.Permissions.XamlAccessLevel accessLevel, bool requestReflectionPermission)
        {
            if (requestReflectionPermission)
            {
                System.Security.PermissionSet permissions = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
                permissions.AddPermission(new System.Xaml.Permissions.XamlLoadPermission(accessLevel));
                permissions.AddPermission(new System.Security.Permissions.ReflectionPermission(System.Security.Permissions.ReflectionPermissionFlag.RestrictedMemberAccess));
                permissions.Assert();
            }
            else
            {
                new System.Xaml.Permissions.XamlLoadPermission(accessLevel).Assert();
            }

            System.Xaml.XamlServices.Transform(reader, writer);
        }
        [System.Security.SecuritySafeCritical]  // auto-generated
        private static EraInfo[] GetErasFromRegistry()
        {
            // Look in the registry key and see if we can find any ranges
            int iFoundEras = 0;
            EraInfo[] registryEraRanges = null;
#if !MONO            
            try
            {
                // Need to access registry
                PermissionSet permSet = new PermissionSet(PermissionState.None);
                permSet.AddPermission(new RegistryPermission(RegistryPermissionAccess.Read, c_japaneseErasHivePermissionList));
                permSet.Assert();
                RegistryKey key = RegistryKey.GetBaseKey(RegistryKey.HKEY_LOCAL_MACHINE).OpenSubKey(c_japaneseErasHive, false);

                // Abort if we didn't find anything
                if (key == null) return null;

                // Look up the values in our reg key
                String[] valueNames = key.GetValueNames();
                if (valueNames != null && valueNames.Length > 0)
                {
                    registryEraRanges = new EraInfo[valueNames.Length];

                    // Loop through the registry and read in all the values
                    for (int i = 0; i < valueNames.Length; i++)
                    {
                        // See if the era is a valid date
                        EraInfo era = GetEraFromValue(valueNames[i], key.GetValue(valueNames[i]).ToString());

                        // continue if not valid
                        if (era == null) continue;

                        // Remember we found one.
                        registryEraRanges[iFoundEras] = era;
                        iFoundEras++;                        
                    }
                }
            }
            catch (System.Security.SecurityException)
            {
                // If we weren't allowed to read, then just ignore the error
                return null;
            }
            catch (System.IO.IOException)
            {
                // If key is being deleted just ignore the error
                return null;
            }
            catch (System.UnauthorizedAccessException)
            {
                // Registry access rights permissions, just ignore the error
                return null;
            }

            //
            // If we didn't have valid eras, then fail
            // should have at least 4 eras
            //
            if (iFoundEras < 4) return null;

            //
            // Now we have eras, clean them up.
            //
            // Clean up array length
            Array.Resize(ref registryEraRanges, iFoundEras);

            // Sort them
            Array.Sort(registryEraRanges, CompareEraRanges);

            // Clean up era information
            for (int i = 0; i < registryEraRanges.Length; i++)
            {
                // eras count backwards from length to 1 (and are 1 based indexes into string arrays)
                registryEraRanges[i].era = registryEraRanges.Length - i;

                // update max era year
                if (i == 0)
                {
                    // First range is 'til the end of the calendar
                    registryEraRanges[0].maxEraYear = GregorianCalendar.MaxYear - registryEraRanges[0].yearOffset;
                }
                else
                {
                    // Rest are until the next era (remember most recent era is first in array)
                    registryEraRanges[i].maxEraYear = registryEraRanges[i-1].yearOffset + 1 - registryEraRanges[i].yearOffset;
                }
            }
#endif
            // Return our ranges
            return registryEraRanges;
        }
예제 #3
0
        private void DisplayProfile()
        {
            try
            {
                System.Security.PermissionSet ps = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted);
                ps.Assert();

                Microsoft.SharePoint.SPServiceContext serviceContext = Microsoft.SharePoint.SPServiceContext.Current;
                UserProfileManager upm = new Microsoft.Office.Server.UserProfiles.UserProfileManager(serviceContext);
                ProfileSubtypePropertyManager pspm = upm.DefaultProfileSubtypeProperties;

                UserProfile profile = upm.GetUserProfile(true); //_accountName);

                this.Controls.Add(new Literal() { Text = "<table border='0' > <tr><td>Displayname</td><td>Value</td></tr>" });

                string[] props = { "UserName", "FirstName", "LastName", "WorkEmail", "Department" };

                foreach (string prop in props)
                {

                    string text = string.Format("<tr><td>{0}</td><td>{1}</td></tr>",
                           profile[prop].ProfileSubtypeProperty.DisplayName,
                           profile[prop].Value);

                    this.Controls.Add(new Literal() { Text = text });

                }
                string txtEdit = "<tr><td colspan='2'>";
                btnEdit = new Button() { Text = "Edit" };

                this.Controls.Add(new Literal() { Text = txtEdit });
                this.Controls.Add(btnEdit);
                this.Controls.Add(new Literal() { Text = "</td></tr>" });
                btnEdit.Click += new EventHandler(btnEdit_Click);

                /*
                foreach (ProfileSubtypeProperty prop in pspm.PropertiesWithSection)
                {

                    if (prop.IsSection)
                        this.Controls.Add(new Literal() { Text = string.Format("<tr><td colspan='3'><b>Section: {0}</b></td></tr>", prop.DisplayName) });
                    else
                    {
                        string text = string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>",
                            prop.DisplayName,
                            prop.Name,
                            profile[prop.Name].Value);

                        this.Controls.Add(new Literal() { Text = text });
                    }
                }*/
                this.Controls.Add(new Literal() { Text = "</table>" });
            }
            catch (Exception ex)
            {
                this.Controls.Add(new Literal() { Text = ex.ToString() });
            }
            finally
            {
                System.Security.CodeAccessPermission.RevertAssert();
            }
        }
        [System.Security.SecuritySafeCritical]  // auto-generated
        private static EraInfo[] GetErasFromRegistry()
        {
            // Look in the registry key and see if we can find any ranges
            int iFoundEras = 0;

            EraInfo[] registryEraRanges = null;

            try
            {
                // Need to access registry
                PermissionSet permSet = new PermissionSet(PermissionState.None);
                permSet.AddPermission(new RegistryPermission(RegistryPermissionAccess.Read, c_japaneseErasHivePermissionList));
                permSet.Assert();
                RegistryKey key = Registry.LocalMachine.OpenSubKey(c_japaneseErasHive, writable: false);

                // Abort if we didn't find anything
                if (key == null)
                {
                    return(null);
                }

                // Look up the values in our reg key
                String[] valueNames = key.GetValueNames();
                if (valueNames != null && valueNames.Length > 0)
                {
                    registryEraRanges = new EraInfo[valueNames.Length];

                    // Loop through the registry and read in all the values
                    for (int i = 0; i < valueNames.Length; i++)
                    {
                        // See if the era is a valid date
                        EraInfo era = GetEraFromValue(valueNames[i], key.GetValue(valueNames[i]).ToString());

                        // continue if not valid
                        if (era == null)
                        {
                            continue;
                        }

                        // Remember we found one.
                        registryEraRanges[iFoundEras] = era;
                        iFoundEras++;
                    }
                }
            }
            catch (System.Security.SecurityException)
            {
                // If we weren't allowed to read, then just ignore the error
                return(null);
            }
            catch (System.IO.IOException)
            {
                // If key is being deleted just ignore the error
                return(null);
            }
            catch (System.UnauthorizedAccessException)
            {
                // Registry access rights permissions, just ignore the error
                return(null);
            }

            //
            // If we didn't have valid eras, then fail
            // should have at least 4 eras
            //
            if (iFoundEras < 4)
            {
                return(null);
            }

            //
            // Now we have eras, clean them up.
            //
            // Clean up array length
            Array.Resize(ref registryEraRanges, iFoundEras);

            // Sort them
            Array.Sort(registryEraRanges, CompareEraRanges);

            // Clean up era information
            for (int i = 0; i < registryEraRanges.Length; i++)
            {
                // eras count backwards from length to 1 (and are 1 based indexes into string arrays)
                registryEraRanges[i].era = registryEraRanges.Length - i;

                // update max era year
                if (i == 0)
                {
                    // First range is 'til the end of the calendar
                    registryEraRanges[0].maxEraYear = GregorianCalendar.MaxYear - registryEraRanges[0].yearOffset;
                }
                else
                {
                    // Rest are until the next era (remember most recent era is first in array)
                    registryEraRanges[i].maxEraYear = registryEraRanges[i - 1].yearOffset + 1 - registryEraRanges[i].yearOffset;
                }
            }

            // Return our ranges
            return(registryEraRanges);
        }
예제 #5
0
        string GetFullNameFromProfile()
        {
            string FullName = string.Empty;
            try
            {
                System.Security.PermissionSet ps = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted);
                ps.Assert();

                Microsoft.SharePoint.SPServiceContext serviceContext = Microsoft.SharePoint.SPServiceContext.Current;
                UserProfileManager upm = new Microsoft.Office.Server.UserProfiles.UserProfileManager(serviceContext);
                ProfileSubtypePropertyManager pspm = upm.DefaultProfileSubtypeProperties;

                UserProfile profile = upm.GetUserProfile(true);
                FullName = profile["FirstName"].Value + " " + profile["LastName"].Value;
            }
            catch (Exception) { }
            return FullName;
        }