protected override void CreateChildControls()
        {
            base.CreateChildControls();
            TempStoreSPSyncSettingsList(false);
            Mode = Request.QueryString["mode"] == "add" ? PageMode.Add : PageMode.Edit;
            if (Mode == PageMode.Add)
            {
                spSyncSettings = new SPProfileSyncProvider(String.Empty, String.Empty, String.Empty, String.Empty, null);
                Header.Title   = AddPageTitleText;
                CtAuth.Controls.Add(AuthenticationHelper.GetPropertyControls(authBuilder));

                TbUserIdFieldName.Text        = "ID";
                TbUserEmailFieldName.Text     = "EMail";
                TbFarmUserEmailFieldName.Text = "WorkEmail";
            }
            else
            {
                Header.Title = EditPageTitleText;
                int id;
                if (int.TryParse(Request.QueryString["id"], out id))
                {
                    spSyncSettings = spSyncSettingsList.Get(id);
                    spConfig       = SPConfigurationService.Get(spSyncSettings.SPSiteURL, spSyncSettings.Authentication);
                    CtAuth.Controls.Add(AuthenticationHelper.SetPropertyControls(spSyncSettings.Authentication, authBuilder));
                    DisplaySyncSettings(spSyncSettings);
                }
            }

            TbFarmUserIdFieldName.Text = spSyncSettings.SPFarmUserIdFieldName;
        }
示例#2
0
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            TempStoreSPSyncSettingsList(false);

            int id;

            if (int.TryParse(Request.QueryString["id"], out id))
            {
                spSyncSettings = spSyncSettingsList.Get(id);
                spConfig       = SPConfigurationService.Get(spSyncSettings.SPSiteURL, spSyncSettings.Authentication);
                if (spSyncSettings.SyncConfig != null)
                {
                    spConfig.FarmProfileMappedFields = spSyncSettings.SyncConfig.FarmProfileMappedFields;
                    spConfig.SiteProfileMappedFields = spSyncSettings.SyncConfig.SiteProfileMappedFields;
                    spConfig.SyncEnabled             = spSyncSettings.SyncConfig.SyncEnabled;
                    spConfig.FarmSyncEnabled         = spSyncSettings.SyncConfig.FarmSyncEnabled;
                }
            }
            else
            {
                ShowErrorMessage("Incorrect request. Please try again or contact your administrator.");
            }
        }
示例#3
0
        private bool IsValid(SPConfiguration config)
        {
            if (config.FarmSyncEnabled && config.FarmProfileMappedFields.Count > 0)
            {
                return(true);
            }

            if (!config.FarmSyncEnabled && config.SiteProfileMappedFields.Count > 0)
            {
                return(true);
            }
            return(false);
        }
        internal static void Set(SPConfiguration config)
        {
            using (var spcontext = new SPContext(config.Url, config.Auth))
            {
                SP.Web web = spcontext.Site.RootWeb;
                web.AllProperties[SPWebPropertyKey.SyncEnabled]     = config.SyncEnabled;
                web.AllProperties[SPWebPropertyKey.FarmSyncEnabled] = config.FarmSyncEnabled;
                web.AllProperties[SPWebPropertyKey.SiteSettings]    = new JavaScriptSerializer().Serialize(config.SiteProfileMappedFields);
                web.AllProperties[SPWebPropertyKey.FarmSettings]    = new JavaScriptSerializer().Serialize(config.FarmProfileMappedFields);
                web.Update();

                spcontext.ExecuteQuery();
            }
        }
        internal static SPConfiguration Get(string url, Authentication auth)
        {
            var config = new SPConfiguration(url, auth);

            using (var spcontext = new SPContext(url, auth))
            {
                try
                {
                    SP.Web web = spcontext.Site.RootWeb;
                    var    siteProfileFieldsQuery = spcontext.LoadQuery(web.SiteUserInfoList.Fields).Where(f => !f.Hidden);

                    spcontext.ExecuteQuery();
                    config.SiteProfileFields = siteProfileFieldsQuery.Select(f => new ProfileField(f.StaticName, f.Title, !f.ReadOnlyField)).OrderBy(f => f.Title).ToList();

                    spcontext.Load(web.AllProperties,
                                   prop => prop[SPWebPropertyKey.SyncEnabled],
                                   prop => prop[SPWebPropertyKey.SiteSettings],
                                   prop => prop[SPWebPropertyKey.FarmSettings],
                                   prop => prop[SPWebPropertyKey.FarmSyncEnabled]);

                    spcontext.ExecuteQuery();
                    ParseWebProperties(web, config);
                }
                catch (Exception)
                {
                    SPLog.Info("Profile Sync properites do not exist in SharePoint. These are optional fields, no action is required.");
                }
            }

            config.FarmProfileFields = new List <ProfileField>();
            using (var userProfileService = new ProfileService(url, auth))
            {
                try
                {
                    var properties = userProfileService.GetUserProfileSchema();
                    foreach (var property in properties.OrderBy(p => p.DisplayName))
                    {
                        config.FarmProfileFields.Add(new ProfileField(property.Name, property.DisplayName, property.IsUserEditable));
                    }
                }
                catch (Exception ex)
                {
                    SPLog.RoleOperationUnavailable(ex, ex.Message);
                }
            }
            return(config);
        }
        public ISPConfiguration Create(
            Configuration configuration)
        {
            ISPConfiguration SPConfiguration = null;

            try
            {
                SPConfiguration = new SPConfiguration(
                    configuration);
            }
            catch (Exception exception)
            {
                this.Log.Error(
                    exception.Message,
                    exception);
            }

            return(SPConfiguration);
        }
        private static void ParseWebProperties(SP.Web web, SPConfiguration config)
        {
            bool syncEnabled;

            if (web.TryParse(SPWebPropertyKey.SyncEnabled, out syncEnabled))
            {
                config.SyncEnabled = syncEnabled;
            }

            bool farmSyncEnabled;

            if (web.TryParse(SPWebPropertyKey.FarmSyncEnabled, out farmSyncEnabled))
            {
                config.FarmSyncEnabled = farmSyncEnabled;
            }

            config.SiteProfileMappedFields = new List <UserFieldMapping>();
            web.TryParse(SPWebPropertyKey.SiteSettings, config.SiteProfileMappedFields);

            config.FarmProfileMappedFields = new List <UserFieldMapping>();
            web.TryParse(SPWebPropertyKey.FarmSettings, config.FarmProfileMappedFields);
        }