Skip to content

Commit

Permalink
Merge pull request #2 from arichika/develop
Browse files Browse the repository at this point in the history
bugs fixed & lite implementation IQuerable<T>
  • Loading branch information
arichika committed Aug 22, 2014
2 parents ed69a75 + ebc6ac5 commit 1f55ae9
Show file tree
Hide file tree
Showing 12 changed files with 236 additions and 12 deletions.
6 changes: 6 additions & 0 deletions Src/.nuget/NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
Binary file added Src/.nuget/NuGet.exe
Binary file not shown.
144 changes: 144 additions & 0 deletions Src/.nuget/NuGet.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>

<!-- Enable the restore command to run before builds -->
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>

<!-- Property that enables building a package from a project -->
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>

<!-- Determines if package restore consent is required to restore packages -->
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>

<!-- Download NuGet.exe if it does not already exist -->
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
</PropertyGroup>

<ItemGroup Condition=" '$(PackageSources)' == '' ">
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
<!-- The official NuGet package source (https://www.nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
<!--
<PackageSource Include="https://www.nuget.org/api/v2/" />
<PackageSource Include="https://my-nuget-source/nuget/" />
-->
</ItemGroup>

<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
<!-- Windows specific commands -->
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
</PropertyGroup>

<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
</PropertyGroup>

<PropertyGroup>
<PackagesProjectConfig Condition=" '$(OS)' == 'Windows_NT'">$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName.Replace(' ', '_')).config</PackagesProjectConfig>
<PackagesProjectConfig Condition=" '$(OS)' != 'Windows_NT'">$(MSBuildProjectDirectory)\packages.$(MSBuildProjectName).config</PackagesProjectConfig>
</PropertyGroup>

<PropertyGroup>
<PackagesConfig Condition="Exists('$(MSBuildProjectDirectory)\packages.config')">$(MSBuildProjectDirectory)\packages.config</PackagesConfig>
<PackagesConfig Condition="Exists('$(PackagesProjectConfig)')">$(PackagesProjectConfig)</PackagesConfig>
</PropertyGroup>

<PropertyGroup>
<!-- NuGet command -->
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\NuGet.exe</NuGetExePath>
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>

<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 "$(NuGetExePath)"</NuGetCommand>

<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>

<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
<NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch>

<PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT'">"$(SolutionDir) "</PaddedSolutionDir>
<PaddedSolutionDir Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)"</PaddedSolutionDir>

<!-- Commands -->
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)</RestoreCommand>
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand>

<!-- We need to ensure packages are restored prior to assembly resolve -->
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
RestorePackages;
$(BuildDependsOn);
</BuildDependsOn>

<!-- Make the build depend on restore packages -->
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
$(BuildDependsOn);
BuildPackage;
</BuildDependsOn>
</PropertyGroup>

<Target Name="CheckPrerequisites">
<!-- Raise an error if we're unable to locate nuget.exe -->
<Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
<!--
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
This effectively acts as a lock that makes sure that the download operation will only happen once and all
parallel builds will have to wait for it to complete.
-->
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadNuGetExe=$(DownloadNuGetExe)" />
</Target>

<Target Name="_DownloadNuGet">
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
</Target>

<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(RestoreCommand)"
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />

<Exec Command="$(RestoreCommand)"
LogStandardErrorAsError="true"
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
</Target>

<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(BuildCommand)"
Condition=" '$(OS)' != 'Windows_NT' " />

<Exec Command="$(BuildCommand)"
LogStandardErrorAsError="true"
Condition=" '$(OS)' == 'Windows_NT' " />
</Target>

<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<OutputFilename ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Net" />
<Using Namespace="Microsoft.Build.Framework" />
<Using Namespace="Microsoft.Build.Utilities" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
OutputFilename = Path.GetFullPath(OutputFilename);
Log.LogMessage("Downloading latest version of NuGet.exe...");
WebClient webClient = new WebClient();
webClient.DownloadFile("https://www.nuget.org/nuget.exe", OutputFilename);
return true;
}
catch (Exception ex) {
Log.LogErrorFromException(ex);
return false;
}
]]>
</Code>
</Task>
</UsingTask>
</Project>
1 change: 1 addition & 0 deletions Src/AspNet.Identity.Oracle/OracleDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ private void ensureConnectionClosed()
private OracleCommand createCommand(string commandText, IEnumerable parameters)
{
var command = connection.CreateCommand();
command.BindByName = true;
command.CommandText = commandText;
addParameters(command, parameters);

Expand Down
11 changes: 9 additions & 2 deletions Src/AspNet.Identity.Oracle/RoleStore.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.AspNet.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

Expand All @@ -14,15 +15,21 @@ public class RoleStore<TRole> : IQueryableRoleStore<TRole>
private RoleTable roleTable;
public OracleDatabase Database { get; private set; }

/// <summary>
/// Get all Roles defined.
/// This code is a loose implementation.
/// An occurrence of a performance problem is when you get a large amount of data.
/// </summary>
public IQueryable<TRole> Roles
{
get
{
throw new NotImplementedException();
// If you have some performance issues, then you can implement the IQueryable.
var x = roleTable.GetRoles() as List<TRole>;
return x != null ? x.AsQueryable() : null;
}
}


/// <summary>
/// Default constructor that initializes a new Oracle Database
/// instance using the Default Connection string
Expand Down
24 changes: 23 additions & 1 deletion Src/AspNet.Identity.Oracle/RoleTable.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Oracle.DataAccess.Client;

namespace AspNet.Identity.Oracle
Expand Down Expand Up @@ -123,16 +124,37 @@ public IdentityRole GetRoleByName(string roleName)
return role;
}

/// <summary>
/// Update Role's attributes
/// </summary>
/// <param name="role"></param>
/// <returns></returns>
public int Update(IdentityRole role)
{
const string commandText = @"UPDATE ANID2ROLES SET NAME = :NAME WHERE ID = :ID";
var parameters = new List<OracleParameter>
{
new OracleParameter {ParameterName = "ID", Value = role.Id, OracleDbType = OracleDbType.Varchar2 },
new OracleParameter {ParameterName = "NAME", Value = role.Name, OracleDbType = OracleDbType.Varchar2 },
new OracleParameter {ParameterName = "ID", Value = role.Id, OracleDbType = OracleDbType.Varchar2 },
};

return _database.Execute(commandText, parameters);
}

/// <summary>
/// Get the all Roles
/// </summary>
/// <returns>IdentityRole</returns>
public IEnumerable<IdentityRole> GetRoles()
{
const string commandText = @"SELECT ID, NAME FROM ANID2ROLES";
var results = _database.Query(commandText, null);

return results.Select(result => new IdentityRole
{
Id = string.IsNullOrEmpty(result["ID"]) ? null : result["ID"],
Name = string.IsNullOrEmpty(result["NAME"]) ? null : result["NAME"],
}).ToList();
}
}
}
10 changes: 8 additions & 2 deletions Src/AspNet.Identity.Oracle/UserStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,21 @@ public class UserStore<TUser> : IUserLoginStore<TUser>,
private UserLoginsTable userLoginsTable;
public OracleDatabase Database { get; private set; }

/// <summary>
/// Get all Users defined.
/// This code is a loose implementation.
/// An occurrence of a performance problem is when you get a large amount of data.
/// </summary>
public IQueryable<TUser> Users
{
get
{
throw new NotImplementedException();
// If you have some performance issues, then you can implement the IQueryable.
var x = userTable.GetUsers() as List<TUser>;
return x != null ? x.AsQueryable() : null;
}
}


/// <summary>
/// Default constructor that initializes a new Oracle Database
/// instance using the Default Connection string
Expand Down
40 changes: 39 additions & 1 deletion Src/AspNet.Identity.Oracle/UserTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,16 @@ public List<TUser> GetUserByName(string userName)
return users;
}

/// <summary>
/// Get Users by email
/// </summary>
/// <param name="email"></param>
/// <returns></returns>
public List<TUser> GetUserByEmail(string email)
{
return null;
var users = new List<TUser>();
// throw new NotImplementedException();
return users;
}

/// <summary>
Expand Down Expand Up @@ -272,5 +279,36 @@ public int Update(TUser user)

return _database.Execute(commandText, parameters);
}

/// <summary>
/// Returns all list of TUser instances
/// </summary>
/// <returns></returns>
public IEnumerable<TUser> GetUsers()
{
var users = new List<TUser>();
const string commandText = @"SELECT * FROM ANID2USERS";

var rows = _database.Query(commandText, null);
foreach (var row in rows)
{
var user = (TUser)Activator.CreateInstance(typeof(TUser));
user.Id = row["ID"];
user.UserName = row["USERNAME"];
user.PasswordHash = string.IsNullOrEmpty(row["PASSWORDHASH"]) ? null : row["PASSWORDHASH"];
user.SecurityStamp = string.IsNullOrEmpty(row["SECURITYSTAMP"]) ? null : row["SECURITYSTAMP"];
user.Email = string.IsNullOrEmpty(row["EMAIL"]) ? null : row["EMAIL"];
user.EmailConfirmed = (row["EMAILCONFIRMED"] == "1");
user.PhoneNumber = string.IsNullOrEmpty(row["PHONENUMBER"]) ? null : row["PHONENUMBER"];
user.PhoneNumberConfirmed = (row["PHONENUMBERCONFIRMED"] == "1");
user.LockoutEnabled = (row["LOCKOUTENABLED"] == "1");
user.LockoutEndDateUtc = string.IsNullOrEmpty(row["LOCKOUTENDDATEUTC"]) ? DateTime.Now : DateTime.Parse(row["LOCKOUTENDDATEUTC"]);
user.AccessFailedCount = string.IsNullOrEmpty(row["ACCESSFAILEDCOUNT"]) ? 0 : int.Parse(row["ACCESSFAILEDCOUNT"]);
user.TwoFactorEnabled = (row["TWOFACTORENABLED"] == "1");
users.Add(user);
}

return users;
}
}
}
6 changes: 3 additions & 3 deletions Src/SampleWebSite/Controllers/UserAdminController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private set
// GET: /Users/
public async Task<ActionResult> Index()
{
return View(await UserManager.Users.ToListAsync());
return View(UserManager.Users);
}

//
Expand All @@ -78,7 +78,7 @@ public async Task<ActionResult> Details(string id)
public async Task<ActionResult> Create()
{
//Get the list of Roles
ViewBag.RoleId = new SelectList(await RoleManager.Roles.ToListAsync(), "Name", "Name");
ViewBag.RoleId = new SelectList(RoleManager.Roles, "Name", "Name");
return View();
}

Expand All @@ -101,7 +101,7 @@ public async Task<ActionResult> Create(RegisterViewModel userViewModel, params s
if (!result.Succeeded)
{
ModelState.AddModelError("", result.Errors.First());
ViewBag.RoleId = new SelectList(await RoleManager.Roles.ToListAsync(), "Name", "Name");
ViewBag.RoleId = new SelectList(RoleManager.Roles, "Name", "Name");
return View();
}
}
Expand Down
2 changes: 1 addition & 1 deletion Src/SampleWebSite/Views/RolesAdmin/Delete.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model Microsoft.AspNet.Identity.EntityFramework.IdentityRole
@model AspNet.Identity.Oracle.IdentityRole

@{
ViewBag.Title = "Delete";
Expand Down
2 changes: 1 addition & 1 deletion Src/SampleWebSite/Views/RolesAdmin/Details.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model Microsoft.AspNet.Identity.EntityFramework.IdentityRole
@model AspNet.Identity.Oracle.IdentityRole

@{
ViewBag.Title = "Details";
Expand Down
2 changes: 1 addition & 1 deletion Src/SampleWebSite/Views/RolesAdmin/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model IEnumerable<Microsoft.AspNet.Identity.EntityFramework.IdentityRole>
@model IEnumerable<AspNet.Identity.Oracle.IdentityRole>

@{
ViewBag.Title = "Index";
Expand Down

0 comments on commit 1f55ae9

Please sign in to comment.