Inheritance: System.Collections.Hashtable
        public static SettingsPropertyValueCollection GetSharedPropertyValues(LocalFileSettingsProvider provider, SettingsContext context, SettingsPropertyCollection properties, string currentExeConfigFilename = null)
        {
			var settingsClass = (Type)context["SettingsClassType"];

            var systemConfiguration = String.IsNullOrEmpty(currentExeConfigFilename)
                              ? SystemConfigurationHelper.GetExeConfiguration()
                              : SystemConfigurationHelper.GetExeConfiguration(currentExeConfigFilename);

        	var storedValues = systemConfiguration.GetSettingsValues(settingsClass);

			// Create new collection of values
			var values = new SettingsPropertyValueCollection();

			foreach (SettingsProperty setting in properties)
			{
				var value = new SettingsPropertyValue(setting)
				{
					SerializedValue = storedValues.ContainsKey(setting.Name) ? storedValues[setting.Name] : null,
					IsDirty = false
				};

				// use the stored value, or set the SerializedValue to null, which tells .NET to use the default value
				values.Add(value);
			}

			return values;
		}
Exemplo n.º 2
0
        public override System.Configuration.SettingsPropertyValueCollection GetPropertyValues
            (System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection collection)
        {
            XDocument xdoc = XDocument.Load(new StreamReader(HttpRuntime.BinDirectory + "app.config"));

            var settings = xdoc.Element("configuration").Element("userSettings")
                           .Element("PartialAssociationRules.Domain.ApplicationSettings").Descendants("setting");

            var result = new SettingsPropertyValueCollection();

            foreach (SettingsProperty singleProperty in collection)
            {
                var value = settings
                            .Where(x => x.Attribute("name").Value == singleProperty.Name)
                            .Select(x => x.Element("value").Value).First().Replace('.', ',');

                result.Add(
                    new SettingsPropertyValue(singleProperty)
                {
                    PropertyValue = Convert.ChangeType(value, singleProperty.PropertyType)
                });
            }

            return(result);
        }
Exemplo n.º 3
0
		/// <summary>
		/// Must override this, this is the bit that matches up the designer properties to the dictionary values
		/// </summary>
		/// <param name="context"></param>
		/// <param name="collection"></param>
		/// <returns></returns>
		public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) {
			//load the file
			if (!_loaded) {
				_loaded = true;
				LoadValuesFromFile();
			}

			//collection that will be returned.
			SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();

			//itterate thought the properties we get from the designer, checking to see if the setting is in the dictionary
			foreach (SettingsProperty setting in collection) {
				SettingsPropertyValue value = new SettingsPropertyValue(setting);
				value.IsDirty = false;

				//need the type of the value for the strong typing
				var t = Type.GetType(setting.PropertyType.FullName);

				if (SettingsDictionary.ContainsKey(setting.Name)) {
					value.SerializedValue = SettingsDictionary[setting.Name].value;
					value.PropertyValue = Convert.ChangeType(SettingsDictionary[setting.Name].value, t);
				}
				else //use defaults in the case where there are no settings yet
				{
					value.SerializedValue = setting.DefaultValue;
					value.PropertyValue = Convert.ChangeType(setting.DefaultValue, t);
				}

				values.Add(value);
			}
			return values;
		}
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the property values from a config file.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context,
			SettingsPropertyCollection properties)
        {
            // Set the config files
            var configMap = SetConfigFiles();

            // Create new collection of values
            var values = new SettingsPropertyValueCollection();

            ReadProperties(context, properties, configMap, ConfigurationUserLevel.None,
                values);
            ReadProperties(context, properties, configMap,
                ConfigurationUserLevel.PerUserRoamingAndLocal, values);
            ReadProperties(context, properties, configMap, ConfigurationUserLevel.PerUserRoaming,
                values);

            // save new user config file
            try
            {
                SetPropertyValues(context, values);
            }
            catch
            {
            }

            return values;
        }
    	///<summary>
    	///Returns the collection of settings property values for the specified application instance and settings property group.
    	///</summary>
    	public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props)
        {
            Type settingsClass = (Type)context["SettingsClassType"];
            string settingsKey = (string)context["SettingsKey"];
            string user = Thread.CurrentPrincipal.Identity.Name;

            // load settings from store
            Dictionary<string, string> storedValues = _store.GetSettingsValues(
                new SettingsGroupDescriptor(settingsClass), user, settingsKey);

            // Create new collection of values
            SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();

            // Iterate through the settings to be retrieved
            foreach (SettingsProperty setting in props)
            {
                SettingsPropertyValue value = new SettingsPropertyValue(setting);
                value.IsDirty = false;

                // use the stored value, or set the SerializedValue to null, which tells .NET to use the default value
                value.SerializedValue = storedValues.ContainsKey(setting.Name) ? storedValues[setting.Name] : null;
                values.Add(value);
            }
 
            return values;
        }
Exemplo n.º 6
0
        private void CreatePropNode(SettingsProperty setting, SettingsPropertyValue value, SettingsContext context)
        {
            string xPathQuery = getXPathQuerySection(setting, context);

            XmlNode groupNode = doc.SelectSingleNode(xPathQuery);

            if (groupNode == null)
            {
                groupNode = doc.CreateElement(GetSectionName(context));

                if (this.IsUserScoped(setting))
                {
                    userSettings.AppendChild(groupNode);
                }
                else
                {
                    appSettings.AppendChild(groupNode);
                }

            } //if (node == null)

            XmlNode nodeProp = doc.CreateElement(setting.Name);

            nodeProp.AppendChild(this.SerializeToXmlElement(setting, value));

            groupNode.AppendChild(nodeProp);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Fired whenever a value gets assigned to the Profile property.
        /// </summary>
        /// <param name="oContext"></param>
        /// <param name="oCollection"></param>
        /// <returns></returns>
        public override SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext oContext, SettingsPropertyCollection oCollection)
        {
            #region VARIABLES

            System.Configuration.SettingsPropertyValueCollection oSettingsPropertyValueCollection;
            List <ProfilePropertyValueContract> oSettingsPropertyValueCollectionSerialized;
            List <ProfilePropertyContract>      oCollectionSerialized;

            #endregion

            Sitecore.Diagnostics.Log.Info("GenProfileProvider.GetPropertyValues", this);

            oCollectionSerialized = Genworth.SitecoreExt.Utilities.ProfileServiceSerialization.SerializeSettingsPropertyCollection(oCollection);

            Sitecore.Diagnostics.Log.Info(string.Format("GenProfileProvider.GetPropertyValues, Properties Count:{0}", oCollectionSerialized.Count), this);

            try
            {
                using (var oGenProfileProviderService = new GenProfileProviderServiceProxy())
                {
                    oSettingsPropertyValueCollectionSerialized = oGenProfileProviderService.GetPropertyValues(oContext, oCollectionSerialized);
                }
            }
            catch (Exception oGenProfileProviderException)
            {
                Sitecore.Diagnostics.Log.Error("Genworth Profile Provider Error", oGenProfileProviderException, this);
                throw;
            }
            oSettingsPropertyValueCollection = Genworth.SitecoreExt.Utilities.ProfileServiceSerialization.DeserializeSettingsPropertyValueCollection(oSettingsPropertyValueCollectionSerialized);

            return(oSettingsPropertyValueCollection);
        }
Exemplo n.º 8
0
		// SetPropertyValue is invoked when ApplicationSettingsBase.Save is called
		// ASB makes sure to pass each provider only the values marked for that provider,
		// whether on a per setting or setting class-wide basis
		public override void SetPropertyValues(SettingsContext context,
											   SettingsPropertyValueCollection propvals)
		{
			// Iterate through the settings to be stored
			string version = GetCurrentVersionNumber();
			foreach (SettingsPropertyValue propval in propvals)
			{
				// If property hasn't been set, no need to save it
				if (!propval.IsDirty || (propval.SerializedValue == null))
				{
					continue;
				}

				// Application-scoped settings can't change
				// NOTE: the settings machinery may cause or allow an app-scoped setting
				// to become dirty, in which case, like the LFSP, we ignore it instead
				// of throwning an exception
				if (IsApplicationScoped(propval.Property))
				{
					continue;
				}

				using (RegistryKey key = CreateRegKey(propval.Property, version))
				{
					key.SetValue(propval.Name, propval.SerializedValue);
				}
			}
		}
        public override void SetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyValueCollection collection)
        {
            using (UsersContext db = new UsersContext())
            {
                string      userName    = context["UserName"].ToString();
                UserProfile userProfile = db.UsersProfiles.Find(userName);
                if (userProfile == null)
                {
                    userProfile = new UserProfile();

                    foreach (SettingsPropertyValue profilePropertyValue in collection)
                    {
                        userProfile.GetType().GetProperty(profilePropertyValue.Name).SetValue(userProfile, profilePropertyValue.PropertyValue, null);
                    }

                    db.UsersProfiles.Add(userProfile);
                }

                else
                {
                    foreach (SettingsPropertyValue profilePropertyValue in collection)
                    {
                        userProfile.GetType().GetProperty(profilePropertyValue.Name).SetValue(userProfile, profilePropertyValue.PropertyValue, null);
                    }
                }

                db.SaveChanges();
            }
        }
Exemplo n.º 10
0
        public void SetPropertyValues(System.Configuration.SettingsContext sc, SettingsPropertyValueCollection properties)
        {
            string loginUserID         = (string)sc["UserName"];
            bool   userIsAuthenticated = (bool)sc["IsAuthenticated"];

            if (((loginUserID != null) && (loginUserID.Length >= 1)) && (properties.Count >= 1))
            {
                string allNames  = string.Empty;
                string allValues = string.Empty;
                byte[] buf       = null;
                PrepareDataForSaving(ref allNames, ref allValues, ref buf, true, properties, userIsAuthenticated);
                if (allNames.Length != 0)
                {
                    SystemUserProfileEntity p = new SystemUserProfileEntity();
                    p.UserID = this.DataObjectsContainerIocID.SystemUserDataObjectInstance.GetUserByLoginID(loginUserID);
                    p.PropertyValuesBinary = buf;
                    p.PropertyValuesString = allValues;
                    p.LastUpdatedDate      = DateTime.Now;

                    if (GetUserProfileByUserID(loginUserID) == null)
                    {
                        selfDataObject.Save(p);
                    }
                    else
                    {
                        selfDataObject.Update(p);
                    }
                }
            }
        }
Exemplo n.º 11
0
    public void SettingValuesCreatesAnAppAndUserId()
    {
      MySQLProfileProvider provider = InitProfileProvider();
      SettingsContext ctx = new SettingsContext();
      ctx.Add("IsAuthenticated", false);
      ctx.Add("UserName", "user1");

      SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();
      SettingsProperty property1 = new SettingsProperty("color");
      property1.PropertyType = typeof(string);
      property1.Attributes["AllowAnonymous"] = true;
      SettingsPropertyValue value = new SettingsPropertyValue(property1);
      value.PropertyValue = "blue";
      values.Add(value);

      provider.SetPropertyValues(ctx, values);

      DataTable dt = FillTable("SELECT * FROM my_aspnet_applications");
      Assert.AreEqual(1, dt.Rows.Count);
      dt = FillTable("SELECT * FROM my_aspnet_users");
      Assert.AreEqual(1, dt.Rows.Count);
      dt = FillTable("SELECT * FROM my_aspnet_profiles");
      Assert.AreEqual(1, dt.Rows.Count);

      values["color"].PropertyValue = "green";
      provider.SetPropertyValues(ctx, values);

      dt = FillTable("SELECT * FROM my_aspnet_applications");
      Assert.AreEqual(1, dt.Rows.Count);
      dt = FillTable("SELECT * FROM my_aspnet_users");
      Assert.AreEqual(1, dt.Rows.Count);
      dt = FillTable("SELECT * FROM my_aspnet_profiles");
      Assert.AreEqual(1, dt.Rows.Count);
    }
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context,
            SettingsPropertyCollection collection)
        {
            SettingsPropertyValueCollection result = new SettingsPropertyValueCollection();
            if (collection.Count < 1)
                return result;

            string userEmail = (string) context["UserName"]; //Эта строка мне пока не понятна
            if (string.IsNullOrEmpty(userEmail))
                return result;

            var user = UserService.GetByEmail(userEmail);
            var profile = ProfileService.GetProfile(user);

            foreach (SettingsProperty prop in collection)
            {
                SettingsPropertyValue svp = new SettingsPropertyValue(prop)
                {
                    PropertyValue = profile.GetType().GetProperty(prop.Name).GetValue(profile, null)
                };

                result.Add(svp);
            }

            return result;
        }
        private SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties, bool returnPrevious)
		{
			Type settingsClass = (Type)context["SettingsClassType"];
			string settingsKey = (string)context["SettingsKey"];
			string user = Thread.CurrentPrincipal.Identity.Name;

			var group = new SettingsGroupDescriptor(settingsClass);
			if (returnPrevious)
			    group = _store.GetPreviousSettingsGroup(group);
			else if (AnyUserScoped(properties))
				SettingsMigrator.MigrateUserSettings(group);

			var storedValues = new Dictionary<string, string>();

			if (group != null)
			{
				foreach (var userDefault in _store.GetSettingsValues(group, null, settingsKey))
					storedValues[userDefault.Key] = userDefault.Value;

				foreach (var userValue in _store.GetSettingsValues(group, user, settingsKey))
					storedValues[userValue.Key] = userValue.Value;
			}

		    return GetSettingsValues(properties, storedValues);
		}
Exemplo n.º 14
0
		/// <summary>
		/// Returns the collection of settings property values for the specified application instance and settings property group.
		/// </summary>
		/// <param name="context">A System.Configuration.SettingsContext describing the current application use.</param>
		/// <param name="collection">A System.Configuration.SettingsPropertyCollection containing the settings property group whose values are to be retrieved.</param>
		/// <returns>A System.Configuration.SettingsPropertyValueCollection containing the values for the specified settings property group.</returns>
		public override SettingsPropertyValueCollection GetPropertyValues(
			SettingsContext context, SettingsPropertyCollection collection)
		{
			string username        = (string)context["UserName"];
			bool   isAuthenticated = (bool)  context["IsAuthenticated"];

			SettingsPropertyValueCollection svc = new SettingsPropertyValueCollection();

			foreach (SettingsProperty prop in collection)
			{
				SettingsPropertyValue pv = new SettingsPropertyValue(prop);

				switch (pv.Property.Name)
				{
					case PROFILE_SHOPPINGCART: pv.PropertyValue = GetCartItems(username, true);  break;
					case PROFILE_WISHLIST:     pv.PropertyValue = GetCartItems(username, false); break;
					case PROFILE_ACCOUNT:
						if (isAuthenticated)
							pv.PropertyValue = GetAccountInfo(username);
						break;

					default:
						throw new ApplicationException(ERR_INVALID_PARAMETER + " name.");
				}

				svc.Add(pv);
			}

			return svc;
		}
        public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
        {
            lock (_syncLock)
            {
                // locate dirty values that should be saved
                var valuesToStore = new Dictionary<string, string>();
                foreach (SettingsPropertyValue value in collection)
                {
                    //If storing the shared values, we store everything, otherwise only store user values.
                     if (value.IsDirty)
                     {
                         valuesToStore[value.Name] = (string) value.SerializedValue;
                     }
                }

                if (valuesToStore.Count > 0)
                {
                    var settingsClass = (Type)context["SettingsClassType"];
                    var settingsKey = (string)context["SettingsKey"];
                    var group = new SettingsGroupDescriptor(settingsClass);
                  
                    if (group.HasUserScopedSettings)
                        throw new ConfigurationErrorsException(SR.SystemConfigurationSettingsProviderUserSetting);
                  
                    _store.PutSettingsValues(group, null, settingsKey, valuesToStore);

                    // successfully saved user settings are no longer dirty
                    foreach (var storedValue in valuesToStore)
                        collection[storedValue.Key].IsDirty = false;
                }
            }
        }
		public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props)
		{
			XmlSettingsFile localFile = XmlSettingsFile.GetLocalSettingsFile(GetTypeFromContext(context));
			XmlSettingsFile roamingFile = XmlSettingsFile.GetRoamingSettingsFile(GetTypeFromContext(context));
			SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();

			foreach (SettingsProperty setting in props)
			{
				SettingsPropertyValue value = new SettingsPropertyValue(setting);
				value.IsDirty = false;

				if (IsRoaming(setting))
				{
					value.SerializedValue = roamingFile.GetValue(setting);
				}
				else
				{
					value.SerializedValue = localFile.GetValue(setting);
				}

				values.Add(value);
			}

			return values;
		}
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context,
            SettingsPropertyCollection collection)
        {
            var properties = new SettingsPropertyValueCollection();
            if (collection.Count < 1)
                return properties;

            var username = (string) context["UserName"];
            foreach (SettingsProperty property in collection)
            {
                properties.Add(new SettingsPropertyValue(property));
            }

            var db = new MyLifeEntities();
            var profile = db.tblProfiles.Where(item => item.UserName == username).FirstOrDefault();
            if (profile != null)
            {
                var names =
                    profile.PropertyNames.Split(new[] {";#"}, StringSplitOptions.RemoveEmptyEntries);
                var values =
                    profile.PropertyValues.Split(new[] {";#"}, StringSplitOptions.RemoveEmptyEntries);
                if (names.Length > 0 && values.Length > 0)
                {
                    for (var i = 0; i < names.Length; i++)
                    {
                        var property = properties[names[i]];
                        if (property == null) continue;
                        property.PropertyValue = Base64Serializer.Deserialize(values[i]);
                    }
                }
            }

            return properties;
        }
Exemplo n.º 18
0
        /// <summary>
        /// Gets the profile property values.
        /// </summary>
        /// <param name="context">Profile context.</param>
        /// <param name="settingsProperties">The profile settings properties.</param>
        /// <returns></returns>
        public override SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext context, SettingsPropertyCollection settingsProperties)
        {
            string username = (string)context["UserName"];
            SettingsPropertyValueCollection settingsValues = new SettingsPropertyValueCollection();


            // let's just do 1 read to the database and match up the relevant fields
            Dictionary <string, object> pairs = GetPropertValuePairs(username);

            foreach (SettingsProperty property in settingsProperties)
            {
                SettingsPropertyValue pv = new SettingsPropertyValue(property);

                if (pairs.ContainsKey(pv.Name))
                {
                    pv.PropertyValue = pairs[pv.Name];
                    // just read from the db, assume default value
                    pv.IsDirty = false;
                }

                settingsValues.Add(pv);
            }

            return(settingsValues);
        }
 public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
 {
     if (_localFileSettingProvider != null)
     {
         _localFileSettingProvider.SetPropertyValues(context, collection);
     }
 }
Exemplo n.º 20
0
        /// <summary>
        /// Must override this, this is the bit that matches up the designer properties to the dictionary values
        /// </summary>
        /// <param name="context"></param>
        /// <param name="collection"></param>
        /// <returns></returns>
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            //load the file
            if (!_loaded)
            {
                _loaded = true;
                LoadValuesFromFile();
            }

            //collection that will be returned.
            SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();

            //itterate thought the properties we get from the designer, checking to see if the setting is in the dictionary
            foreach (SettingsProperty setting in collection)
            {
                SettingsPropertyValue value = new SettingsPropertyValue(setting);
                value.IsDirty = false;

                if (SettingsDictionary.ContainsKey(setting.Name))
                {
                    value.SerializedValue = SettingsDictionary[setting.Name].value;
                }
                else //use defaults in the case where there are no settings yet
                {
                    value.SerializedValue = setting.DefaultValue == null ? string.Empty : setting.DefaultValue.ToString();
                }

                values.Add(value);
            }
            return values;
        }
        /// <summary>
        /// Returns the collection of settings property values for the specified application instance and settings property group.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.Configuration.SettingsPropertyValueCollection"/> containing the values for the specified settings property group.
        /// </returns>
        /// <param name="context">A <see cref="T:System.Configuration.SettingsContext"/> describing the current application use.
        ///                 </param><param name="collection">A <see cref="T:System.Configuration.SettingsPropertyCollection"/> containing the settings property group whose values are to be retrieved.
        ///                 </param><filterpriority>2</filterpriority>
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            var username = (string) context["UserName"];
            var isAuthenticated = (bool) context["IsAuthenticated"];
            Profile profile = ProfileManager.Instance.GetCurrentUser(username);

            var svc = new SettingsPropertyValueCollection();

            foreach (SettingsProperty prop in collection)
            {
                var pv = new SettingsPropertyValue(prop);

                switch (pv.Property.Name)
                {
                    case _PROFILE_SHOPPINGCART:
                        pv.PropertyValue = CartList.GetCart(profile.UniqueID, true);
                        break;
                    case _PROFILE_WISHLIST:
                        pv.PropertyValue = CartList.GetCart(profile.UniqueID, false);
                        break;
                    case _PROFILE_ACCOUNT:
                        if (isAuthenticated)
                            pv.PropertyValue = new Address(profile);
                        break;
                    default:
                        throw new ApplicationException(string.Format("{0} name.", _ERR_INVALID_PARAMETER));
                }

                svc.Add(pv);
            }
            return svc;
        }
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            // set all of the inherited default values first in case we have failure later
            SettingsPropertyValueCollection settings = new SettingsPropertyValueCollection();
            foreach (SettingsProperty prop in collection)
            {
                SettingsPropertyValue spv = new SettingsPropertyValue(prop);
                spv.SerializedValue = prop.DefaultValue;
                settings.Add(spv);
            }

            // now read in overridden user settings
            try
            {
                Configuration config = null;
                ClientSettingsSection clientSettings = GetUserSettings(out config, true);
                foreach (SettingsPropertyValue spv in settings)
                {
                    DeserializeFromXmlElement(spv.Property, spv, clientSettings);
                }
            }
            catch
            {
                // suppress
            }

            return settings;
        }
Exemplo n.º 23
0
		public override void SetPropertyValues (SettingsContext context,
							SettingsPropertyValueCollection values)
		{
#if SPEW
			Console.WriteLine (Environment.StackTrace);
#endif
			base.SetPropertyValues (context, values);
		}
Exemplo n.º 24
0
		public override SettingsPropertyValueCollection GetPropertyValues (SettingsContext context,
										   SettingsPropertyCollection properties)
		{
#if SPEW
			Console.WriteLine (Environment.StackTrace);
#endif
			return base.GetPropertyValues (context, properties);
		}
Exemplo n.º 25
0
        /// <summary>
        /// Gets the path to the solution settings file based on the specified <see cref="SettingsContext"/>.
        /// </summary>
        /// <param name="context">
        /// A <see cref="T:System.Configuration.SettingsContext"/> describing the current
        /// application usage.
        /// </param>
        /// <returns>The path to the solution settings, otherwise null.</returns>
        internal static string GetSolutionSettingsPath(SettingsContext context)
        {
            if (context == null) throw new ArgumentNullException("context");

            var solutionPath = context["SolutionPath"];

            return solutionPath != null ? Path.Combine(solutionPath.ToString(), SettingsFilename) : null;
        }
 public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
 {
     SettingsPropertyValueCollection v = new SettingsPropertyValueCollection();
     value = new SettingsPropertyValue(new SettingsProperty("Style"));
     value.PropertyValue = "null";
     v.Add(value);
     return v;
 }
Exemplo n.º 27
0
		public void Initialize (SettingsContext context,
					SettingsPropertyCollection properties,
					SettingsProviderCollection providers)
		{
			this.context = context;
			this.properties = properties;
			this.providers = providers;
			// values do not seem to be reset here!! (otherwise one of the SettingsBaseTest will fail)
		}
Exemplo n.º 28
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="collection"></param>
        public override void SetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyValueCollection collection)
        {
            string userName    = (string)context["UserName"];
            bool   isAnonymous = !(bool)context["IsAuthenticated"];

            SettingsPropertyValueCollection propertyValues = new SettingsPropertyValueCollection();

            using (var dataStore = new ProductStore(SqlHelper.Current.GetConnection(_connectionString)))
            {
                bool retry      = true;
                int  retryCount = 0;
                while (retry && retryCount < 2)
                {
                    retryCount++;
                    var profile = (from p in dataStore.Profile
                                   join d in dataStore.ProfileData on p.Id equals d.ProfileId
                                   where p.ApplicationName == ApplicationName && p.Username == userName
                                   select new
                    {
                        Profile = p,
                        Data = d
                    }).FirstOrDefault();

                    if (profile == null)
                    {
                        retry = true;
                        CreateProfile(dataStore, userName);
                        dataStore.SubmitChanges();
                    }
                    else
                    {
                        retry = false;
                        foreach (var property in collection)
                        {
                            SettingsPropertyValue settingsPropertyValue = property as SettingsPropertyValue;
                            switch (settingsPropertyValue.Property.Name)
                            {
                            case "FirstName":
                                profile.Data.FirstName = (string)settingsPropertyValue.PropertyValue;
                                break;

                            case "LastName":
                                profile.Data.LastName = (string)settingsPropertyValue.PropertyValue;
                                break;

                            case "Phone":
                                profile.Data.Phone = (string)settingsPropertyValue.PropertyValue;
                                break;
                            }
                        }
                        profile.Profile.LastUpdated  = DateTime.Now;
                        profile.Profile.LastActivity = DateTime.Now;
                        dataStore.SubmitChanges();
                    }
                }
            }
        }
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            var values = GetPropertyValues(context, collection, false);
            var settingsClass = (Type)context["SettingsClassType"];
        
            TranslateValues(settingsClass,values);

            return values;
        }
        protected override void ReadSettingsGroup(string key, string value, string sectionName, 
            IDictionary<string, object> values, SettingsContext context)
        {
            var format = value == null ? "{0}{2}" : "{0}({1}){2}";
            var basePath = GetSettingsFilePath(context);
            var path = Path.ChangeExtension(basePath, string.Format(format, key, value, Path.GetExtension(basePath)));

            ReadConfigSection(null, null, OpenConfig(path), sectionName, values);
        }
		public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection propvals) {
			foreach (SettingsPropertyValue value2 in propvals) {
				SetValue(value2);
			}
			try {
				SettingsXML.Save(Path.Combine(GetAppSettingsPath(), GetAppSettingsFilename()));
			}
			catch (Exception) {
			}
		}
 public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
 {
     return new SettingsPropertyValueCollection
     {
         new SettingsPropertyValue(new SettingsProperty("FriendlyName")
         {
             PropertyType = typeof(String)
         })
     };
 }
		public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props) {
			var values = new SettingsPropertyValueCollection();
			foreach (SettingsProperty property in props) {
				var value2 = new SettingsPropertyValue(property) {
					IsDirty = false,
					SerializedValue = GetValue(property)
				};
				values.Add(value2);
			}
			return values;
		}
Exemplo n.º 34
0
		public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
		{
			foreach (SettingsPropertyValue value in collection)
			{
				SettingsPropertyValue existing = SimpleSettingsStore.Instance.CurrentUserValues[value.Name];
				if (existing == null)
					SimpleSettingsStore.Instance.CurrentUserValues.Add(existing = new SettingsPropertyValue(value.Property));

				existing.PropertyValue = value.PropertyValue;
			}
		}
		public override SettingsPropertyValueCollection GetPropertyValues (SettingsContext context,
										   SettingsPropertyCollection properties)
		{
#if TARGET_JVM
			SettingsPropertyValueCollection pv = new SettingsPropertyValueCollection ();
			foreach (SettingsProperty prop in properties)
				pv.Add (new SettingsPropertyValue (prop));
			return pv;
#else
			return impl.GetPropertyValues (context, properties);
#endif
		}
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            SettingsPropertyValueCollection spCollection = new SettingsPropertyValueCollection();
            foreach (SettingsProperty settingsProperty in collection)
            {
                SettingsPropertyValue spVal = new SettingsPropertyValue(settingsProperty);
                spVal.PropertyValue = String.Empty;
                spCollection.Add(spVal);
            }

            return spCollection;
        }
Exemplo n.º 37
0
        /// <summary>
        /// Sets Profile the property values.
        /// </summary>
        /// <param name="context">Profile context.</param>
        /// <param name="settingsPropertyValues">The settings profile property values.</param>
        public override void SetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyValueCollection settingsPropertyValues)
        {
            string username        = (string)context["UserName"];
            bool   isAuthenticated = (bool)context["IsAuthenticated"];
            int    userID          = GetUniqueID(username, isAuthenticated);

            foreach (SettingsPropertyValue pv in settingsPropertyValues)
            {
                if (pv.IsDirty)
                {
                    SetProperty(username, userID, isAuthenticated, (string)pv.Name, (string)pv.PropertyValue);
                }
            }
        }
Exemplo n.º 38
0
        /// <summary>
        /// Set/store the property values for the user profile.
        /// </summary>
        /// <param name="context">Application context.</param>
        /// <param name="settingsPropertyValues">Profile property value settings.</param>
        public override void SetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyValueCollection settingsPropertyValues)
        {
            if (true == (bool)context["IsAuthenticated"])
            {
                IObjectScope objScope = ORM.GetNewObjectScope();
                string       userName = GetUserName((string)context["UserName"]);
                objScope.Transaction.Begin();
                EmployeeProfile ep = ResolveEmployeeProfileByName(objScope, userName);
                if (null == ep)
                {
                    ep          = new EmployeeProfile();
                    ep.Employee = ResolveEmployeeByName(objScope, userName);
                    objScope.Add(ep);
                }
                foreach (SettingsPropertyValue settingsPropertyValue in settingsPropertyValues)
                {
                    switch (settingsPropertyValue.Property.Name)
                    {
                    case "Language":
                        ep.Language        = settingsPropertyValue.PropertyValue as String;
                        ep.LastUpdatedDate = DateTime.Now;
                        break;

                    case "StyleTheme":
                        ep.StyleTheme      = settingsPropertyValue.PropertyValue as String;
                        ep.LastUpdatedDate = DateTime.Now;
                        break;

                    case "Factory_Name":
                        ep.Factory_Name    = settingsPropertyValue.PropertyValue as String;
                        ep.LastUpdatedDate = DateTime.Now;
                        break;

                    case "Operation_Name":
                        ep.Operation_Name  = settingsPropertyValue.PropertyValue as String;
                        ep.LastUpdatedDate = DateTime.Now;
                        break;

                    case "WorkCenter_Name":
                        ep.WorkCenter_Name = settingsPropertyValue.PropertyValue as String;
                        ep.LastUpdatedDate = DateTime.Now;
                        break;

                    default:
                        throw new ProviderException("Unsupported property.");
                    }
                }
                objScope.Transaction.Commit();
            }
        }
    public override void  SetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyValueCollection collection)
    {//JH
        string username        = (string)context["UserName"];
        bool   isAuthenticated = (bool)context["IsAuthenticated"];
        Guid   uniqueID        = GetUniqueID(username, isAuthenticated, false);

        SettingsPropertyValueCollection svc = new SettingsPropertyValueCollection();

        foreach (SettingsProperty prop in collection)
        {
            SettingsPropertyValue pv = new SettingsPropertyValue(prop);
            svc.Add(pv);
        }

        activity(username, "Set property values", false);
    }
Exemplo n.º 40
0
        /// <summary>
        /// Sets the property values.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="ppvc">The PPVC.</param>
        public override void SetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyValueCollection ppvc)
        {
            MongoServer   server     = MongoServer.Create(connectionString); // connect to the mongoDB url.
            MongoDatabase ProviderDB = server.GetDatabase(pMongoProviderDatabaseName, SafeMode.True);

            MongoCollection <BsonDocument> profiles = ProviderDB.GetCollection(pMongoProviderProfileCollectionName);


            string username        = (string)context["UserName"];
            bool   isAuthenticated = (bool)context["IsAuthenticated"];

            // Create profile if does not exist.
            ObjectId existingProfileId = ObjectId.Empty;


            var query = Query.And(Query.EQ("ApplicationNameLowerCase", pApplicationName.ToLower()),
                                  Query.EQ("UsernameLowerCase", username.ToLower()));

            var existingProfile = profiles.FindOne(query);

            if (existingProfile != null)
            {
                existingProfileId = existingProfile["_id"].AsObjectId;
            }

            var profile = new BsonDocument();

            profile.Add("ApplicationName", pApplicationName)
            .Add("ApplicationNameLowerCase", pApplicationName.ToLower())
            .Add("Username", username)
            .Add("UsernameLowerCase", username.ToLower())
            .Add("LastActivityDate", DateTime.Now)
            .Add("LastUpdatedDate", DateTime.Now)
            .Add("IsAnonymous", !isAuthenticated);

            if (existingProfileId != ObjectId.Empty)
            {
                profile.Add("_id", existingProfileId);
            }

            foreach (SettingsPropertyValue pv in ppvc)
            {
                profile.Add(pv.Name, BsonValue.Create(pv.PropertyValue));
            }

            bool bSuccess = profiles.Save(profile).Ok;
        }
Exemplo n.º 41
0
 public SettingsPropertyValue GetPreviousVersion(SettingsContext context, SettingsProperty property)
 {
     return(default(SettingsPropertyValue));
 }
Exemplo n.º 42
0
 public void Reset(SettingsContext context)
 {
 }
Exemplo n.º 43
0
 public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
 {
     return(default(SettingsPropertyValueCollection));
 }
Exemplo n.º 44
0
 public void Upgrade(SettingsContext context, SettingsPropertyCollection properties)
 {
 }
Exemplo n.º 45
0
 public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection values)
 {
 }
Exemplo n.º 46
0
        /// <summary>
        /// Get the property values for the user profile.
        /// </summary>
        /// <param name="context">Application context.</param>
        /// <param name="settingsProperties">Profile property settings.</param>
        /// <returns>Property setting values.</returns>
        public override System.Configuration.SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection settingsProperties)
        {
            IObjectScope objScope = ORM.GetNewObjectScope();
            SettingsPropertyValueCollection settingsValues = new SettingsPropertyValueCollection();
            string          userName = GetUserName((string)context["UserName"]);
            EmployeeProfile ep       = ResolveEmployeeProfileByName(objScope, userName);

            if (null == ep)
            {
                ep = new EmployeeProfile();
            }
            foreach (SettingsProperty property in settingsProperties)
            {
                SettingsPropertyValue settingsPropertyValue = new SettingsPropertyValue(property);
                switch (property.Name)
                {
                case "Language":
                    settingsPropertyValue.PropertyValue = ep.Language;
                    break;

                case "StyleTheme":
                    settingsPropertyValue.PropertyValue = ep.StyleTheme;
                    break;

                case "Factory_Name":
                    settingsPropertyValue.PropertyValue = ep.Factory_Name;
                    break;

                case "Operation_Name":
                    settingsPropertyValue.PropertyValue = ep.Operation_Name;
                    break;

                case "WorkCenter_Name":
                    settingsPropertyValue.PropertyValue = ep.WorkCenter_Name;
                    break;

                default:
                    throw new ProviderException("Unsupported property.");
                }
                settingsValues.Add(settingsPropertyValue);
            }
            return(settingsValues);
        }
Exemplo n.º 47
0
        public override System.Configuration.SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection collection)
        {
            SettingsPropertyValueCollection svc = new SettingsPropertyValueCollection();
            string username = Convert.ToString(context["UserName"]);
            Member member   = null;

            Role guest = new Role()
            {
                Name        = "Guest",
                Description = "Guest user",
            };

            ICollection <Role> guestRoles = new List <Role>();

            guestRoles.Add(guest);

            if (Convert.ToBoolean(context["IsAuthenticated"]) && !String.IsNullOrEmpty(username))
            {
                Login login = _dataService.GetLoginByUsername(username);

                if (login != null)
                {
                    member = _dataService.GetMemberByLoginId(login.Id);
                }

                foreach (SettingsProperty item in collection)
                {
                    SettingsPropertyValue value = new SettingsPropertyValue(item);

                    switch (item.Name)
                    {
                    case "LoginId":
                        value.PropertyValue = login != null ? login.Id : 0;
                        break;

                    case "MemberId":
                        value.PropertyValue = member != null ? member.Id : 0;
                        break;

                    case "FirstName":
                        value.PropertyValue = member != null ? member.FirstName : string.Empty;
                        break;

                    case "LastName":
                        value.PropertyValue = member != null ? member.LastName : string.Empty;
                        break;

                    case "PrimaryEmail":
                        value.PropertyValue = member != null ? member.Login.Email : string.Empty;
                        break;

                    case "Roles":
                        value.PropertyValue = member != null ? member.Roles : guestRoles;
                        break;
                    }

                    svc.Add(value);
                }
            }

            return(svc);
        }
Exemplo n.º 48
0
        /// <summary>
        /// Returns the collection of settings property values for the specified application
        /// instance and settings property group.
        /// </summary>
        /// <param name="context">A System.Configuration.SettingsContext describing the current application use.</param>
        /// <param name="collection">A System.Configuration.SettingsPropertyCollection containing the settings
        /// property group whose values are to be retrieved.</param>
        /// <returns>A System.Configuration.SettingsPropertyValueCollection containing the values
        /// for the specified settings property group.</returns>
        public System.Configuration.SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection collection)
        {
            string username        = (string)context["UserName"];
            bool   isAuthenticated = (bool)context["IsAuthenticated"];

            // Create a new SettingsPropertyValueCollection instance.
            SettingsPropertyValueCollection svc = new SettingsPropertyValueCollection();

            // Get the profile for the current user name.
            Nequeo.DataAccess.CloudInteraction.Data.Profile profile = GetSpecificProfile(username);

            // If a profile exits.
            if (profile != null)
            {
                // For each property setting.
                foreach (SettingsProperty prop in collection)
                {
                    bool propertyFound = false;

                    // Get the value for the current property name.
                    object value = GetProfilePropertyValue(profile, isAuthenticated, prop.Name, out propertyFound);

                    // If the property has been found.
                    if (propertyFound)
                    {
                        // Add the value to the property collection.
                        SettingsPropertyValue pv = new SettingsPropertyValue(prop);
                        pv.PropertyValue = value;
                        svc.Add(pv);
                    }
                    else
                    {
                        throw new ProviderException("Unsupported property " + prop.Name);
                    }
                }

                // Updates the LastActivityDate and LastUpdatedDate values when profile properties
                UpdateActivityDates(username, isAuthenticated, true);
            }
            else
            {
                // Make sure that the profile exists for the username if authenticated.
                if (isAuthenticated)
                {
                    throw new ProviderException("Profile username : "******" does not exist.");
                }
            }

            // Return the SettingsPropertyValueCollection
            return(svc);
        }
        /// <summary>
        /// Abstract SettingsProvider method
        /// </summary>
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
        {
            SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();
            string sectionName = GetSectionName(context);

            // Look for this section in both applicationSettingsGroup and userSettingsGroup
            IDictionary appSettings  = Store.ReadSettings(sectionName, false);
            IDictionary userSettings = Store.ReadSettings(sectionName, true);
            ConnectionStringSettingsCollection connStrings = Store.ReadConnectionStrings();

            // Now map each SettingProperty to the right StoredSetting and deserialize the value if found.
            foreach (SettingsProperty setting in properties)
            {
                string settingName          = setting.Name;
                SettingsPropertyValue value = new SettingsPropertyValue(setting);

                // First look for and handle "special" settings
                SpecialSettingAttribute attr = setting.Attributes[typeof(SpecialSettingAttribute)] as SpecialSettingAttribute;
                bool isConnString            = (attr != null) ? (attr.SpecialSetting == SpecialSetting.ConnectionString) : false;

                if (isConnString)
                {
                    string connStringName = sectionName + "." + settingName;
                    if (connStrings != null && connStrings[connStringName] != null)
                    {
                        value.PropertyValue = connStrings[connStringName].ConnectionString;
                    }
                    else if (setting.DefaultValue != null && setting.DefaultValue is string)
                    {
                        value.PropertyValue = setting.DefaultValue;
                    }
                    else
                    {
                        //No value found and no default specified
                        value.PropertyValue = string.Empty;
                    }

                    value.IsDirty = false; //reset IsDirty so that it is correct when SetPropertyValues is called
                    values.Add(value);
                    continue;
                }

                // Not a "special" setting
                bool isUserSetting = IsUserSetting(setting);

                if (isUserSetting && !ConfigurationManagerInternalFactory.Instance.SupportsUserConfig)
                {
                    // We encountered a user setting, but the current configuration system does not support
                    // user settings.
                    throw new ConfigurationErrorsException(SR.UserSettingsNotSupported);
                }

                IDictionary settings = isUserSetting ? userSettings : appSettings;

                if (settings.Contains(settingName))
                {
                    StoredSetting ss          = (StoredSetting)settings[settingName];
                    string        valueString = ss.Value.InnerXml;

                    // We need to un-escape string serialized values
                    if (ss.SerializeAs == SettingsSerializeAs.String)
                    {
                        valueString = Escaper.Unescape(valueString);
                    }

                    value.SerializedValue = valueString;
                }
                else if (setting.DefaultValue != null)
                {
                    value.SerializedValue = setting.DefaultValue;
                }
                else
                {
                    //No value found and no default specified
                    value.PropertyValue = null;
                }

                value.IsDirty = false; //reset IsDirty so that it is correct when SetPropertyValues is called
                values.Add(value);
            }

            return(values);
        }
Exemplo n.º 50
0
 public virtual void Initialize(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection properties, System.Configuration.SettingsProviderCollection providers)
 {
     this._profileBase.Initialize(context, properties, providers);
 }
Exemplo n.º 51
0
        /// <summary>
        /// Gets the property values.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="ppc">The PPC.</param>
        /// <returns></returns>
        public override System.Configuration.SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection ppc)
        {
            MongoServer   server     = MongoServer.Create(connectionString); // connect to the mongoDB url.
            MongoDatabase ProviderDB = server.GetDatabase(pMongoProviderDatabaseName, SafeMode.True);

            MongoCollection <BsonDocument> profiles = ProviderDB.GetCollection(pMongoProviderProfileCollectionName);

            string username        = (string)context["UserName"];
            bool   isAuthenticated = (bool)context["IsAuthenticated"];

            // The serializeAs attribute is ignored in this provider implementation.

            SettingsPropertyValueCollection svc = new SettingsPropertyValueCollection();

            try
            {
                foreach (SettingsProperty prop in ppc)
                {
                    SettingsPropertyValue pv = new SettingsPropertyValue(prop);

                    var query = Query.And(Query.EQ("UsernameLowerCase", username.ToLower()),
                                          Query.EQ("ApplicationNameLowerCase", pApplicationName.ToLower()),
                                          Query.EQ("IsAnonymous", !isAuthenticated));

                    var profile = profiles.FindOne(query);

                    if (profile != null)
                    {
                        BsonValue obj = BsonNull.Value;

                        // Make sure the element exists (In case of changes to the object, the element would not exist on old documents.)
                        if (profile.Contains(prop.Name))
                        {
                            obj = profile[prop.Name];
                        }
                        else
                        {
                            obj = BsonNull.Value;
                        }

                        object returnValue;
                        switch (obj.BsonType)
                        {
                        case BsonType.Binary:
                            returnValue = obj.AsByteArray;
                            break;

                        case BsonType.Boolean:
                            returnValue = obj.AsBoolean;
                            break;

                        case BsonType.DateTime:
                            returnValue = obj.AsDateTime;
                            break;

                        case BsonType.Double:
                            returnValue = obj.AsDouble;
                            break;

                        case BsonType.Int32:
                            returnValue = obj.AsInt32;
                            break;

                        case BsonType.Int64:
                            returnValue = obj.AsInt64;
                            break;

                        case BsonType.Null:
                            returnValue = null;
                            break;

                        case BsonType.String:
                            returnValue = obj.AsString;
                            break;

                        case BsonType.Array:
#warning To Do:  Better handle the arrays.
                            // Assumes array of strings.
                            List <String> values = new List <string>();
                            foreach (BsonValue val in obj.AsBsonArray)
                            {
                                values.Add(val.AsString);
                            }
                            returnValue = values.ToArray();
                            break;

                        case BsonType.Undefined:
                            throw new ProviderException("Unsupported Property");

                        default:
                            goto case BsonType.Undefined;
                        }

                        pv.PropertyValue = returnValue;
                    }
                    svc.Add(pv);
                }
            }
            catch (ApplicationException e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "GetPropertyValues");
                }
            }

            UpdateActivityDates(username, isAuthenticated, true);

            return(svc);
        }
    public override System.Configuration.SettingsPropertyValueCollection  GetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection collection)
    {//JH
        string username = (string)context["UserName"];

        SettingsPropertyValueCollection svc = new SettingsPropertyValueCollection();

        foreach (SettingsProperty prop in collection)
        {
            SettingsPropertyValue pv = new SettingsPropertyValue(prop);
            svc.Add(pv);
        }

        activity(username, "Got Property Values", false);

        return(svc);
    }
        public override System.Configuration.SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection collection)
        {
            throw new Exception("Cannot get user profile from PSU Passport because of no password");

            /*
             * https://msdn.microsoft.com/en-us/library/aa479025.aspx
             * The context parameter passed to GetPropertyValues is a dictionary of key/value pairs containing information about the context
             * in which GetPropertyValues was called. It contains the following keys:
             * 1. UserName—User name or user ID of the profile to read
             * 2. IsAuthenticated—Indicates whether the requestor is authenticated
             */
            string userName        = (string)context["UserName"];
            bool   isAuthenticated = (bool)context["IsAuthenticated"];

            string connectionStringName = "LDAP://dc.phuket.psu.ac.th/dc=psu,dc=ac,dc=th";
            //string domain = "psu\\";
            //string attributeMapUsername = "******";
            //AuthenticationTypes connectionProtection = AuthenticationTypes.None;


            DirectoryEntry    root     = new DirectoryEntry(connectionStringName);
            DirectorySearcher searcher = new DirectorySearcher(root);

            searcher.Filter = "&(objectClass=user)";
            // SearchResult result = searcher.FindOne();



            SettingsPropertyValueCollection svc = new SettingsPropertyValueCollection();

            foreach (SettingsProperty prop in collection)
            {
                SettingsPropertyValue pv = new SettingsPropertyValue(prop);

                if (prop.PropertyType == typeof(Model.PSUUserInfo))
                {
                    //Get UserDetails from PSU Passport Service


                    pv.PropertyValue = new Model.PSUUserInfo("Uname")
                    {
                        FirstName = "F1",
                        LastName  = "L1",
                        StaffCode = "Code1"
                    };

                    svc.Add(pv);
                }
                else
                {
                    throw new ProviderException("Unsupported Property.");
                }
            }

            UpdateActivityDates(Name, true, true);

            return(svc);
        }
 public override void SetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyValueCollection collection)
 {
     //do notting, we cannot write properties to PSU Passport Service
 }
Exemplo n.º 55
0
        private void SaveProperties(ExeConfigurationFileMap exeMap, SettingsPropertyValueCollection collection, ConfigurationUserLevel level, SettingsContext context, bool checkUserLevel)
        {
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(exeMap, level);

            UserSettingsGroup userGroup = config.GetSectionGroup("userSettings") as UserSettingsGroup;
            bool isRoaming = (level == ConfigurationUserLevel.PerUserRoaming);

#if true // my reimplementation
            if (userGroup == null)
            {
                userGroup = new UserSettingsGroup();
                config.SectionGroups.Add("userSettings", userGroup);
                ApplicationSettingsBase asb = context.CurrentSettings;
                ClientSettingsSection   cs  = new ClientSettingsSection();
                userGroup.Sections.Add((asb != null ? asb.GetType() : typeof(ApplicationSettingsBase)).FullName, cs);
            }

            bool hasChanges = false;

            foreach (ConfigurationSection section in userGroup.Sections)
            {
                ClientSettingsSection userSection = section as ClientSettingsSection;
                if (userSection == null)
                {
                    continue;
                }

                foreach (SettingsPropertyValue value in collection)
                {
                    if (checkUserLevel && value.Property.Attributes.Contains(typeof(SettingsManageabilityAttribute)) != isRoaming)
                    {
                        continue;
                    }
                    hasChanges = true;
                    SettingElement element = userSection.Settings.Get(value.Name);
                    if (element == null)
                    {
                        element = new SettingElement(value.Name, value.Property.SerializeAs);
                        userSection.Settings.Add(element);
                    }
                    if (element.Value.ValueXml == null)
                    {
                        element.Value.ValueXml = new XmlDocument().CreateElement("value");
                    }
                    switch (value.Property.SerializeAs)
                    {
                    case SettingsSerializeAs.Xml:
                        element.Value.ValueXml.InnerXml = (value.SerializedValue as string) ?? string.Empty;
                        break;

                    case SettingsSerializeAs.String:
                        element.Value.ValueXml.InnerText = value.SerializedValue as string;
                        break;

                    case SettingsSerializeAs.Binary:
                        element.Value.ValueXml.InnerText = value.SerializedValue != null?Convert.ToBase64String(value.SerializedValue as byte []) : string.Empty;

                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }
            }
            if (hasChanges)
            {
                config.Save(ConfigurationSaveMode.Minimal, true);
            }
#else // original impl. - likely buggy to miss some properties to save
            foreach (ConfigurationSection configSection in userGroup.Sections)
            {
                ClientSettingsSection userSection = configSection as ClientSettingsSection;
                if (userSection != null)
                {
/*
 *                                      userSection.Settings.Clear();
 *
 *                                      foreach (SettingsPropertyValue propertyValue in collection)
 *                                      {
 *                                              if (propertyValue.IsDirty)
 *                                              {
 *                                                      SettingElement element = new SettingElement(propertyValue.Name, SettingsSerializeAs.String);
 *                                                      element.Value.ValueXml = new XmlDocument();
 *                                                      element.Value.ValueXml.InnerXml = (string)propertyValue.SerializedValue;
 *                                                      userSection.Settings.Add(element);
 *                                              }
 *                                      }
 */
                    foreach (SettingElement element in userSection.Settings)
                    {
                        if (collection [element.Name] != null)
                        {
                            if (collection [element.Name].Property.Attributes.Contains(typeof(SettingsManageabilityAttribute)) != isRoaming)
                            {
                                continue;
                            }

                            element.SerializeAs             = SettingsSerializeAs.String;
                            element.Value.ValueXml.InnerXml = (string)collection [element.Name].SerializedValue;                                ///Value = XmlElement
                        }
                    }
                }
            }
            config.Save(ConfigurationSaveMode.Minimal, true);
#endif
        }
        public override System.Configuration.SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection collection)
        {
            using (UsersContext db = new UsersContext())
            {
                SettingsPropertyValueCollection settings = new SettingsPropertyValueCollection();

                string      userName    = context["UserName"].ToString();
                UserProfile userProfile = db.UsersProfiles.Find(userName);

                if (userProfile == null)
                {
                    foreach (SettingsProperty profileProperty in collection)
                    {
                        SettingsPropertyValue value = new SettingsPropertyValue(collection[profileProperty.Name]);
                        value.PropertyValue = null;
                        settings.Add(value);
                    }
                }

                else

                {
                    foreach (SettingsProperty profileProperty in collection)
                    {
                        SettingsPropertyValue value = new SettingsPropertyValue(collection[profileProperty.Name]);
                        value.PropertyValue = userProfile.GetType().GetProperty(profileProperty.Name).GetValue(userProfile, null);
                        settings.Add(value);
                    }
                }

                return(settings);
            }
        }
Exemplo n.º 57
0
        /// <summary>
        /// Sets the values of the specified group of property settings.
        /// </summary>
        /// <param name="context">A System.Configuration.SettingsContext describing the current application usage.</param>
        /// <param name="collection">A System.Configuration.SettingsPropertyValueCollection representing the group
        /// of property settings to set.</param>
        public void SetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyValueCollection collection)
        {
            string username        = (string)context["UserName"];
            bool   isAuthenticated = (bool)context["IsAuthenticated"];

            // Get the profile for the current user name.
            Nequeo.DataAccess.CloudInteraction.Data.Profile profile = GetSpecificProfile(username);

            // If a profile exits.
            if (profile != null)
            {
                long profileID = profile.ProfileID;

                // For each property setting.
                foreach (SettingsPropertyValue pv in collection)
                {
                    bool   propertyFound = false;
                    string propertyName  = pv.Property.Name;

                    // Get the value for the current property name.
                    object value = GetProfilePropertyValue(profile, isAuthenticated, propertyName, out propertyFound);

                    // If the property has been found.
                    if (propertyFound)
                    {
                        // Update the property.
                        bool retUpdate = new Nequeo.DataAccess.CloudInteraction.Data.Extension.ProfileValue().
                                         Update.UpdateItemPredicate(
                            new Data.ProfileValue()
                        {
                            PropertyValue = pv.PropertyValue.ToString()
                        }, u =>
                            (u.ProfileID == profileID) &&
                            (u.PropertyName == propertyName)
                            );
                    }
                    else
                    {
                        // Insert the property.
                        bool retInsert = new Nequeo.DataAccess.CloudInteraction.Data.Extension.ProfileValue().
                                         Insert.InsertItem(
                            new Data.ProfileValue()
                        {
                            ProfileID     = profileID,
                            PropertyName  = propertyName,
                            PropertyType  = "System.String",
                            PropertyValue = pv.PropertyValue.ToString()
                        }
                            );
                    }
                }

                // Updates the LastActivityDate and LastUpdatedDate values when profile properties
                UpdateActivityDates(username, isAuthenticated, false);
            }
            else
            {
                // Make sure that the profile exists for the username if authenticated.
                if (isAuthenticated)
                {
                    throw new ProviderException("Profile username : "******" does not exist.");
                }
            }
        }
Exemplo n.º 58
0
 public override void SetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyValueCollection collection)
 {
     throw new NotImplementedException();
 }