Skip to content

Commit

Permalink
Fixed bug when default config path is taken instead of from app settings
Browse files Browse the repository at this point in the history
  • Loading branch information
FoC- committed Jun 23, 2012
1 parent 6b1f785 commit 17d5a0b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
6 changes: 3 additions & 3 deletions MongoMembership/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MongoMembership")]
[assembly: AssemblyCopyright("FoC © 2012")]
[assembly: AssemblyCopyright("FoC © 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,6 +32,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.0.7")]
[assembly: AssemblyFileVersion("0.0.0.7")]
[assembly: AssemblyVersion("0.0.0.8")]
[assembly: AssemblyFileVersion("0.0.0.8")]
[assembly: InternalsVisibleTo("MongoMembership.Tests")]
26 changes: 25 additions & 1 deletion MongoMembership/Providers/MongoProfileProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ namespace MongoMembership.Providers
{
public class MongoProfileProvider : ProfileProvider
{
internal string MongoConnectionString { get; private set; }
private IMongoGateway mongoGateway;
public override string ApplicationName { get; set; }

public override void Initialize(string name, NameValueCollection config)
{
this.mongoGateway = new MongoGateway(ConfigurationManager.AppSettings.Get("MONGOLAB_URI") ?? "mongodb://localhost/Accounting");
this.ApplicationName = Util.GetValue(config["applicationName"], HostingEnvironment.ApplicationVirtualPath);

this.MongoConnectionString = ConnectionString(Util.GetValue(config["connectionStringKeys"], string.Empty));
this.mongoGateway = new MongoGateway(MongoConnectionString);

base.Initialize(name, config);
}

Expand Down Expand Up @@ -210,6 +213,26 @@ public override void SetPropertyValues(SettingsContext context, SettingsProperty
this.mongoGateway.UpdateUser(user);
}

#region Private Methods
private static string ConnectionString(string connectionsettingskeys)
{
var keys = connectionsettingskeys.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var key in keys)
{
var name = key.Trim(new[] { ' ' });

if (name.IsNullOrEmpty())
continue;

var connectionString = ConfigurationManager.AppSettings.Get(name);
if (connectionString == null)
continue;

return connectionString;
}
return "mongodb://localhost/MongoMembership";
}

private static ProfileInfo ToProfileInfo(User user)
{
return new ProfileInfo(user.Username, user.IsAnonymous, user.LastActivityDate, user.LastUpdatedDate, 0);
Expand All @@ -226,5 +249,6 @@ private static ProfileInfoCollection ToProfileInfoCollection(IEnumerable<User> u

return profileCollection;
}
#endregion
}
}
31 changes: 28 additions & 3 deletions MongoMembership/Providers/MongoRoleProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Specialized;
using System;
using System.Collections.Specialized;
using System.Configuration;
using System.Configuration.Provider;
using System.Linq;
Expand All @@ -11,15 +12,18 @@ namespace MongoMembership.Providers
{
public class MongoRoleProvider : RoleProvider
{
internal string MongoConnectionString { get; private set; }
private IMongoGateway mongoGateway;

public override string ApplicationName { get; set; }

public override void Initialize(string name, NameValueCollection config)
{
this.mongoGateway = new MongoGateway(ConfigurationManager.AppSettings.Get("MONGOLAB_URI") ?? "mongodb://localhost/Accounting");

this.ApplicationName = Util.GetValue(config["applicationName"], HostingEnvironment.ApplicationVirtualPath);

this.MongoConnectionString = ConnectionString(Util.GetValue(config["connectionStringKeys"], string.Empty));
this.mongoGateway = new MongoGateway(MongoConnectionString);

base.Initialize(name, config);
}

Expand Down Expand Up @@ -120,5 +124,26 @@ public override bool RoleExists(string roleName)
{
return this.mongoGateway.IsRoleExists(this.ApplicationName, roleName);
}

#region Private Methods
private static string ConnectionString(string connectionsettingskeys)
{
var keys = connectionsettingskeys.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var key in keys)
{
var name = key.Trim(new[] { ' ' });

if (name.IsNullOrEmpty())
continue;

var connectionString = ConfigurationManager.AppSettings.Get(name);
if (connectionString == null)
continue;

return connectionString;
}
return "mongodb://localhost/MongoMembership";
}
#endregion
}
}
4 changes: 2 additions & 2 deletions Nuget/MongoMembership.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<package >
<metadata>
<id>MongoMembership</id>
<version>0.0.7</version>
<version>0.0.8</version>
<authors>Kush</authors>
<owners>Kush</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Store user profiles and roles in MongoDB storage. And allow easy access to use thems from MemberShipProvider, ProfileProvider, RoleProvider in ASP.NET</description>
<description>Store user profiles and roles in MongoDB storage. And allow easy access to use thems from MemberShipProvider, ProfileProvider, RoleProvider in ASP.NET Project on github: https://github.com/FoC-/MongoMembership</description>
<copyright>FoC © 2012</copyright>
<tags>mongo membership providers role profile mvc asp.net</tags>
<dependencies>
Expand Down

0 comments on commit 17d5a0b

Please sign in to comment.