コード例 #1
0
        /// <summary>
        /// Get the localized label of User Profile Properties
        /// Option 1 => Get the specific property to find the label (much better performance)
        /// </summary>
        /// <param name="userProfilePropertyName"></param>
        /// <reference>
        ///       1. http://nikpatel.net/2013/12/26/code-snippet-programmatically-retrieve-localized-user-profile-properties-label/
        /// </reference>
        /// <returns></returns>
        public string getLocalizedUserProfilePropertiesLabel(string userProfilePropertyName, SPWeb currentWeb)
        {
            string localizedLabel = string.Empty;

            try
            {
                //Get the handle of User Profile Service Application for current site (web application)
                SPSite                   site    = SPContext.Current.Site;
                SPServiceContext         context = SPServiceContext.GetContext(site);
                UserProfileConfigManager upcm    = new UserProfileConfigManager(context);

                //Access the User Profile Property manager core properties
                ProfilePropertyManager ppm = upcm.ProfilePropertyManager;
                CorePropertyManager    cpm = ppm.GetCoreProperties();

                //Get the core property for user profile property and get the localized value
                CoreProperty cp = cpm.GetPropertyByName(userProfilePropertyName);
                if (cp != null)
                {
                    localizedLabel = cp.DisplayNameLocalized[System.Globalization.CultureInfo.CurrentUICulture.LCID];
                }
            }
            catch (Exception err)
            {
                LogErrorHelper objErr = new LogErrorHelper(LIST_SETTING_NAME, currentWeb);
                objErr.logSysErrorEmail(APP_NAME, err, "Error at getLocalizedUserProfilePropertiesLabel function");
                objErr = null;

                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(APP_NAME, TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, err.Message.ToString(), err.StackTrace);
                return(string.Empty);
            }
            return(localizedLabel);
        }
コード例 #2
0
        private static ProfileTypeProperty EnsureProfileTypeProperty(
            CoreProperty property,
            UserProfilePropertyInfo userProfilePropertyInfo,
            ProfileTypePropertyManager profileTypePropertyManager)
        {
            var profileTypeProperty = profileTypePropertyManager.GetPropertyByName(userProfilePropertyInfo.Name);

            if (profileTypeProperty == null)
            {
                profileTypeProperty = profileTypePropertyManager.Create(property);
                profileTypeProperty.IsVisibleOnViewer = userProfilePropertyInfo.IsVisibleOnViewer;
                profileTypeProperty.IsVisibleOnEditor = userProfilePropertyInfo.IsVisibleOnEditor;
                profileTypeProperty.IsReplicable      = userProfilePropertyInfo.IsReplicable;
                profileTypePropertyManager.Add(profileTypeProperty);
            }
            else
            {
                profileTypeProperty.IsVisibleOnViewer = userProfilePropertyInfo.IsVisibleOnViewer;
                profileTypeProperty.IsVisibleOnEditor = userProfilePropertyInfo.IsVisibleOnEditor;
                profileTypeProperty.IsReplicable      = userProfilePropertyInfo.IsReplicable;
            }

            profileTypeProperty.Commit();
            return(profileTypeProperty);
        }
コード例 #3
0
        public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var host       = modelHost.WithAssertAndCast <SiteModelHost>("modelHost", value => value.RequireNotNull());
            var typedModel = model.WithAssertAndCast <CorePropertyDefinition>("model", value => value.RequireNotNull());

            CoreProperty spObject = GetCurrentCoreProperty(host.HostSite, typedModel);

            var assert = ServiceFactory.AssertService
                         .NewAssert(typedModel, typedModel)
                         .ShouldNotBeNull(spObject);


            assert.ShouldBeEqual(m => m.Name, o => o.Name);
            assert.ShouldBeEqual(m => m.DisplayName, o => o.DisplayName);
            assert.ShouldBeEqual(m => m.Type, o => o.Type);

            assert.ShouldBeEqual(m => m.Length, o => o.Length);

            if (typedModel.IsAlias.HasValue)
            {
                assert.ShouldBeEqual(m => m.IsAlias, o => o.IsAlias);
            }
            else
            {
                assert.SkipProperty(m => m.IsAlias, "IsAlias is null or empty");
            }

            if (typedModel.IsMultivalued.HasValue)
            {
                assert.ShouldBeEqual(m => m.IsMultivalued, o => o.IsMultivalued);
            }
            else
            {
                assert.SkipProperty(m => m.IsMultivalued, "IsMultivalued is null or empty");
            }

            if (typedModel.IsSearchable.HasValue)
            {
                assert.ShouldBeEqual(m => m.IsSearchable, o => o.IsSearchable);
            }
            else
            {
                assert.SkipProperty(m => m.IsSearchable, "IsSearchable is null or empty");
            }

            if (!string.IsNullOrEmpty(typedModel.Description))
            {
                assert.ShouldBeEqual(m => m.Description, o => o.Description);
            }
            else
            {
                assert.SkipProperty(m => m.Description);
            }
        }
コード例 #4
0
    public void Initialize(CoreProperty coreProperty)
    {
        // Initializer Guard
        if (coreProperty == null)
        {
            Debug.LogWarning("You Inserted a null CoreProperty! Property not correctly initialized");
            return;
        }

        this.coreProperty = coreProperty;
    }
コード例 #5
0
        static void MaritalStatus()
        {
            //Code example adds a new property called Marital Status.
            using (SPSite site = new SPSite("http://servername"))
            {
                //SPServiceContext context = SPServiceContext.GetContext(site);
                //ClientContext context = new ClientContext(site);
                //ServerContext context = ServerContext.GetContext(site);
                UserProfileConfigManager upcm = new UserProfileConfigManager();

                try
                {
                    ProfilePropertyManager ppm = upcm.ProfilePropertyManager;

                    // create core property
                    CorePropertyManager cpm = ppm.GetCoreProperties();
                    CoreProperty        cp  = cpm.Create(false);
                    cp.Name        = "MaritalStatus";
                    cp.DisplayName = "Marital Status";
                    cp.Type        = PropertyDataType.StringSingleValue;
                    cp.Length      = 100;

                    cpm.Add(cp);

                    // create profile type property
                    ProfileTypePropertyManager ptpm = ppm.GetProfileTypeProperties(ProfileType.User);
                    ProfileTypeProperty        ptp  = ptpm.Create(cp);

                    ptpm.Add(ptp);

                    // create profile subtype property
                    ProfileSubtypeManager         psm  = ProfileSubtypeManager.Get();
                    ProfileSubtype                ps   = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));
                    ProfileSubtypePropertyManager pspm = ps.Properties;
                    ProfileSubtypeProperty        psp  = pspm.Create(ptp);

                    psp.PrivacyPolicy  = PrivacyPolicy.OptIn;
                    psp.DefaultPrivacy = Privacy.Organization;

                    pspm.Add(psp);
                }
                catch (DuplicateEntryException e)
                {
                    Console.WriteLine(e.Message);
                    Console.Read();
                }
                catch (System.Exception e2)
                {
                    Console.WriteLine(e2.Message);
                    Console.Read();
                }
            }
        }
コード例 #6
0
    public virtual void Initialize(CoreProperty coreProperty)
    {
        // Initializer Guard
        if (coreProperty == null)
        {
            Debug.LogWarning("You Inserted a null CoreProperty! Fade will not play");
            return;
        }

        this.coreProperty = coreProperty;
        floatProperty     = new FloatProperty(startValue, endValue, coreProperty);
    }
コード例 #7
0
    public void Initialize(CoreProperty coreProperty)
    {
        // Initializer Guard
        if (coreProperty == null)
        {
            Debug.LogWarning("You Inserted a null CoreProperty! Property not correctly initialized");
            return;
        }

        easeProperty      = new EaseProperty(StartVector, EndVector, easeIn, easeOut, coreProperty);
        this.coreProperty = coreProperty;
    }
コード例 #8
0
    public FloatProperty(float initial, float final, CoreProperty animationCore)
    {
        if (animationCore == null)
        {
            Debug.LogWarning("CoreProperty is null, nothing will be apllied");
            return;
        }

        bool isOpen = !animationCore.IsOpened();

        this.initial = !isOpen ? initial : final;
        this.final   = !isOpen ? final : initial;
    }
コード例 #9
0
        protected virtual CoreProperty GetCurrentCoreProperty(SPSite site, CorePropertyDefinition definition)
        {
            CoreProperty result = null;

            var serverContext  = SPServiceContext.GetContext(site);
            var profileManager = new UserProfileManager(serverContext);

            var profilePropertiesManager = new UserProfileConfigManager(serverContext).ProfilePropertyManager;
            var corePropertiesManager    = profilePropertiesManager.GetCoreProperties();

            // would return NULL, no try-catch is required
            result = corePropertiesManager.GetPropertyByName(definition.Name);

            return(result);
        }
コード例 #10
0
        private void MapProperties(CoreProperty currentProperty, CorePropertyDefinition definition)
        {
            if (definition.IsAlias.HasValue)
            {
                currentProperty.IsAlias = definition.IsAlias.Value;
            }

            if (definition.IsSearchable.HasValue)
            {
                currentProperty.IsSearchable = definition.IsSearchable.Value;
            }

            // this is cannot be updated
            //if (definition.IsMultivalued.HasValue)
            //    currentProperty.IsMultivalued = definition.IsMultivalued.Value;
        }
コード例 #11
0
        private void DeployDefinition(object modelHost, SiteModelHost siteModelHost, CorePropertyDefinition definition)
        {
            var site = siteModelHost.HostSite;

            // TODO, implementation
            // Add user profile property provision support #820
            // https://github.com/SubPointSolutions/spmeta2/issues/820

            CoreProperty currentProperty = GetCurrentCoreProperty(site, definition);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = currentProperty,
                ObjectType       = typeof(CoreProperty),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });

            if (currentProperty == null)
            {
                currentProperty = CreateNewCoreProperty(site, definition);
            }

            MapProperties(currentProperty, definition);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = currentProperty,
                ObjectType       = typeof(CoreProperty),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });
        }
コード例 #12
0
    public EaseProperty(Vector3 StartValues, Vector3 EndValues, AnimationCurve EaseIn, AnimationCurve EaseOut, CoreProperty animationCore)
    {
        if (animationCore == null)
        {
            Debug.LogWarning("CoreProperty is null, nothing will be apllied");
            return;
        }
        if (EaseIn == null || EaseOut == null)
        {
            Debug.LogWarning("EasinIn or EaseOut are null, please check your request.");
            return;
        }

        bool isAnimationOpen = animationCore.IsOpened();

        initialPoint = !isAnimationOpen ? StartValues : EndValues;
        finalPoint   = !isAnimationOpen ? EndValues : StartValues;
        ease         = !isAnimationOpen ? EaseIn : EaseOut;
    }
コード例 #13
0
        private static ProfileTypeProperty EnsureProfileTypeProperty(
            CoreProperty property,
            UserProfilePropertyInfo userProfilePropertyInfo,
            ProfileTypePropertyManager profileTypePropertyManager)
        {
            var profileTypeProperty = profileTypePropertyManager.GetPropertyByName(userProfilePropertyInfo.Name);
            if (profileTypeProperty == null)
            {
                profileTypeProperty = profileTypePropertyManager.Create(property);
                profileTypeProperty.IsVisibleOnViewer = userProfilePropertyInfo.IsVisibleOnViewer;
                profileTypeProperty.IsVisibleOnEditor = userProfilePropertyInfo.IsVisibleOnEditor;
                profileTypeProperty.IsReplicable = userProfilePropertyInfo.IsReplicable;
                profileTypePropertyManager.Add(profileTypeProperty);
            }
            else
            {
                profileTypeProperty.IsVisibleOnViewer = userProfilePropertyInfo.IsVisibleOnViewer;
                profileTypeProperty.IsVisibleOnEditor = userProfilePropertyInfo.IsVisibleOnEditor;
                profileTypeProperty.IsReplicable = userProfilePropertyInfo.IsReplicable;
            }

            profileTypeProperty.Commit();
            return profileTypeProperty;
        }