Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Service.Common.dll
Binary file not shown.
Binary file added Service.Common.pdb
Binary file not shown.
30 changes: 30 additions & 0 deletions ServiceResult/IdentityExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Microsoft.AspNetCore.Identity;
using System.Collections.Generic;

namespace server.ServiceResult
{
public static class IdentityExtension
{
public static ServiceResultBase ToServiceResult(this IdentityResult identity)
{
var result = new ServiceResult();
AddErrors(result, identity.Errors);
return result;
}

public static ServiceResult<TReturn> ToServiceResult<TReturn>(this IdentityResult identity, TReturn tReturn)
{
var result = new ServiceResult<TReturn>(tReturn);
AddErrors(result, identity.Errors);
return result;
}

private static void AddErrors(ServiceResultBase result, IEnumerable<IdentityError> errors)
{
foreach (var error in errors)
{
result.AddNotification(NotificationType.Error, error.Description);
}
}
}
}
10 changes: 10 additions & 0 deletions ServiceResult/NotificationType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Service.Common
{
public enum NotificationType : byte
{
Error,
Success,
Info,
Warning
}
}
25 changes: 25 additions & 0 deletions ServiceResult/ServiceResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;

namespace Service.Common
{
public class ServiceResult : ServiceResultBase
{

}

public class ServiceResult<T> : ServiceResultBase
{
public ServiceResult()
{

}

public ServiceResult(T response) : base()
{
Response = response;
}

public T Response { get; set; }
}
}
42 changes: 42 additions & 0 deletions ServiceResult/ServiceResultBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Collections.Generic;
using System.Linq;

namespace Service.Common
{
public abstract class ServiceResultBase
{
protected ServiceResultBase()
{
Notifications = new List<KeyValuePair<NotificationType, string>>();
Errors = new Dictionary<string, ICollection<string>>();
}

public string errorMessages { get; set; }
public Dictionary<string, ICollection<string>> Errors { get; set; }

public List<KeyValuePair<NotificationType, string>> Notifications { get; set; }

public bool IsSuccess
{
get { return !Errors.Any() && Notifications.All(n => n.Key != NotificationType.Error); }
}

public void AddError(string key, string message)
{
if (Errors.ContainsKey(key))
{
Errors[key].Add(message);
return;
}

Errors.Add(key, new List<string>() { message });
errorMessages = message;
}

public void AddNotification(NotificationType type, string message)
{
Notifications.Add(new KeyValuePair<NotificationType, string>(type, message));
errorMessages = message;
}
}
}
Binary file added Sql.sql
Binary file not shown.
Binary file added Test/.vs/Test/v15/.suo
Binary file not shown.
Empty file.
Binary file added Test/.vs/Test/v15/Server/sqlite3/storage.ide
Binary file not shown.
Binary file not shown.
Binary file added Test/.vs/Test/v15/Server/sqlite3/storage.ide-wal
Binary file not shown.
984 changes: 984 additions & 0 deletions Test/.vs/config/applicationhost.config

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions Test/Shorter.Core/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace Shortener.Core.Extensions
{
using System;

public static class StringExtensions
{
public static string ValidateUrl(this string url)
{
var builder = new UriBuilder(url);
if (!builder.Host.Contains("."))
{
throw new Exception("Invalid URL.");
}

url = builder.Uri.ToString();
if (url.EndsWith("/"))
{
url = url.Substring(0, url.Length - 1);
}

return url;
}

public static string UrlToBase64(this string url)
{
var bytes = System.Text.Encoding.UTF8.GetBytes(url);
var base64 = System.Convert.ToBase64String(bytes);
return base64.Replace('/', '_');
}
}
}
36 changes: 36 additions & 0 deletions Test/Shorter.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Shortener.Core")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Shortener.Core")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("ac9c4397-46f4-471c-b0c9-123f2a689769")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// 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("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
126 changes: 126 additions & 0 deletions Test/Shorter.Core/ShortCodeGenerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
namespace Shortener.Core
{
using System;
using System.Security.Cryptography;

// http://www.obviex.com/samples/password.aspx
public static class ShortCodeGenerator
{
private const string LowerCase = "abcdefgijkmnopqrstwxyz";
private const string UpperCase = "ABCDEFGHJKLMNPQRSTWXYZ";
private const string Numbers = "0123456789";

public static string Generate()
{
var rand = new Random(Guid.NewGuid().GetHashCode());
return RandomCharacters(rand.Next(6, 6));
}

private static string RandomCharacters(int length)
{
// Create a local array containing supported short-url characters grouped by types.
var charGroups = new[] { LowerCase.ToCharArray(), UpperCase.ToCharArray(), Numbers.ToCharArray() };

// Use this array to track the number of unused characters in each character group.
var charsLeftInGroup = new int[charGroups.Length];

// Initially, all characters in each group are not used.
for (int i = 0; i < charsLeftInGroup.Length; i++)
{
charsLeftInGroup[i] = charGroups[i].Length;
}

// Use this array to track (iterate through) unused character groups.
int[] leftGroupsOrder = new int[charGroups.Length];

// Initially, all character groups are not used.
for (int i = 0; i < leftGroupsOrder.Length; i++)
{
leftGroupsOrder[i] = i;
}

// Use a 4-byte array to fill it with random bytes and convert it then
// to an integer value.
byte[] randomBytes = new byte[4];

// Generate 4 random bytes.
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
rng.GetBytes(randomBytes);

// Convert 4 bytes into a 32-bit integer value.
int seed = (randomBytes[0] & 0x7f) << 24 | randomBytes[1] << 16 | randomBytes[2] << 8 | randomBytes[3];

// Now, this is real randomization.
Random random = new Random(seed);

// This array will hold short-url characters.
var shortUrl = new char[random.Next(length, length)];

// Index of the last non-processed group.
int lastLeftGroupsOrderIdx = leftGroupsOrder.Length - 1;

// Generate short-url characters one at a time.
for (int i = 0; i < shortUrl.Length; i++)
{
// If only one character group remained unprocessed, process it;
// otherwise, pick a random character group from the unprocessed
// group list. To allow a special character to appear in the
// first position, increment the second parameter of the Next
// function call by one, i.e. lastLeftGroupsOrderIdx + 1.
int nextLeftGroupsOrderIdx = lastLeftGroupsOrderIdx == 0 ? 0 : random.Next(0, lastLeftGroupsOrderIdx);

// Get the actual index of the character group, from which we will
// pick the next character.
int nextGroupIdx = leftGroupsOrder[nextLeftGroupsOrderIdx];

// Get the index of the last unprocessed characters in this group.
int lastCharIdx = charsLeftInGroup[nextGroupIdx] - 1;

// If only one unprocessed character is left, pick it; otherwise,
// get a random character from the unused character list.
int nextCharIdx = lastCharIdx == 0 ? 0 : random.Next(0, lastCharIdx + 1);

// Add this character to the short-url.
shortUrl[i] = charGroups[nextGroupIdx][nextCharIdx];

// If we processed the last character in this group, start over.
if (lastCharIdx == 0)
{
charsLeftInGroup[nextGroupIdx] = charGroups[nextGroupIdx].Length;
}
else
{
// Swap processed character with the last unprocessed character
// so that we don't pick it until we process all characters in
// this group.
if (lastCharIdx != nextCharIdx)
{
char temp = charGroups[nextGroupIdx][lastCharIdx];
charGroups[nextGroupIdx][lastCharIdx] = charGroups[nextGroupIdx][nextCharIdx];
charGroups[nextGroupIdx][nextCharIdx] = temp;
}
}

// If we processed the last group, start all over.
if (lastLeftGroupsOrderIdx == 0)
{
lastLeftGroupsOrderIdx = leftGroupsOrder.Length - 1;
}
else
{
// Swap processed group with the last unprocessed group
// so that we don't pick it until we process all groups.
if (lastLeftGroupsOrderIdx != nextLeftGroupsOrderIdx)
{
int temp = leftGroupsOrder[lastLeftGroupsOrderIdx];
leftGroupsOrder[lastLeftGroupsOrderIdx] = leftGroupsOrder[nextLeftGroupsOrderIdx];
leftGroupsOrder[nextLeftGroupsOrderIdx] = temp;
}
}
}

// Convert password characters into a string and return the result.
return new string(shortUrl);
}
}
}
49 changes: 49 additions & 0 deletions Test/Shorter.Core/Shortener.Core.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{CC30D7FA-ECE8-4F09-976A-222D03B71041}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>shortener.Core</RootNamespace>
<AssemblyName>shortener.Core</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="Extensions\StringExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ShortCodeGenerator.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Binary file not shown.
Binary file added Test/Shorter.Core/bin/Debug/shortener.Core.pdb
Binary file not shown.
Binary file not shown.
Binary file added Test/Shorter.Core/bin/Release/shortener.Core.pdb
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
27ab5bb23956511d6ba433310c6cbf4defdc1042
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
C:\Users\Dlaila\Documents\Visual Studio 2013\Projects\url shortener\Core\Shorter.Core\bin\Debug\Shorter.Core.dll
C:\Users\Dlaila\Documents\Visual Studio 2013\Projects\url shortener\Core\Shorter.Core\bin\Debug\Shorter.Core.pdb
C:\Users\Dlaila\Documents\Visual Studio 2013\Projects\url shortener\Core\Shorter.Core\obj\Debug\Shorter.Core.dll
C:\Users\Dlaila\Documents\Visual Studio 2013\Projects\url shortener\Core\Shorter.Core\obj\Debug\Shorter.Core.pdb
C:\Users\Dlaila\Documents\Visual Studio 2013\Projects\url shortener\Core\Shorter.Core\obj\Debug\Shortener.Core.csprojResolveAssemblyReference.cache
C:\Users\Dlaila\Source\Repos\urlshortener\Core\Shorter.Core\obj\Debug\Shortener.Core.csprojResolveAssemblyReference.cache
C:\Users\Dlaila\Source\Repos\urlshortener\Core\Shorter.Core\bin\Debug\shortener.Core.dll
C:\Users\Dlaila\Source\Repos\urlshortener\Core\Shorter.Core\bin\Debug\shortener.Core.pdb
C:\Users\Dlaila\Source\Repos\urlshortener\Core\Shorter.Core\obj\Debug\shortener.Core.dll
C:\Users\Dlaila\Source\Repos\urlshortener\Core\Shorter.Core\obj\Debug\shortener.Core.pdb
C:\PROYECTOS\PROYECTOS_ACTUALES\Prueba_dll\Test\Test\Shorter.Core\bin\Debug\shortener.Core.dll
C:\PROYECTOS\PROYECTOS_ACTUALES\Prueba_dll\Test\Test\Shorter.Core\bin\Debug\shortener.Core.pdb
C:\PROYECTOS\PROYECTOS_ACTUALES\Prueba_dll\Test\Test\Shorter.Core\obj\Debug\Shortener.Core.csproj.CoreCompileInputs.cache
C:\PROYECTOS\PROYECTOS_ACTUALES\Prueba_dll\Test\Test\Shorter.Core\obj\Debug\shortener.Core.dll
C:\PROYECTOS\PROYECTOS_ACTUALES\Prueba_dll\Test\Test\Shorter.Core\obj\Debug\shortener.Core.pdb
C:\PROYECTOS\PROYECTOS_ACTUALES\Prueba_dll\Test_ShortUrl\Test\Shorter.Core\bin\Debug\shortener.Core.dll
C:\PROYECTOS\PROYECTOS_ACTUALES\Prueba_dll\Test_ShortUrl\Test\Shorter.Core\bin\Debug\shortener.Core.pdb
C:\PROYECTOS\PROYECTOS_ACTUALES\Prueba_dll\Test_ShortUrl\Test\Shorter.Core\obj\Debug\Shortener.Core.csprojAssemblyReference.cache
C:\PROYECTOS\PROYECTOS_ACTUALES\Prueba_dll\Test_ShortUrl\Test\Shorter.Core\obj\Debug\Shortener.Core.csproj.CoreCompileInputs.cache
C:\PROYECTOS\PROYECTOS_ACTUALES\Prueba_dll\Test_ShortUrl\Test\Shorter.Core\obj\Debug\shortener.Core.dll
C:\PROYECTOS\PROYECTOS_ACTUALES\Prueba_dll\Test_ShortUrl\Test\Shorter.Core\obj\Debug\shortener.Core.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
C:\Users\Dlaila\Documents\Visual Studio 2013\Projects\url shortener\Core\Shorter.Core\bin\Debug\Shorter.Core.dll
C:\Users\Dlaila\Documents\Visual Studio 2013\Projects\url shortener\Core\Shorter.Core\bin\Debug\Shorter.Core.pdb
C:\Users\Dlaila\Documents\Visual Studio 2013\Projects\url shortener\Core\Shorter.Core\obj\Debug\Shorter.Core.csprojResolveAssemblyReference.cache
C:\Users\Dlaila\Documents\Visual Studio 2013\Projects\url shortener\Core\Shorter.Core\obj\Debug\Shorter.Core.dll
C:\Users\Dlaila\Documents\Visual Studio 2013\Projects\url shortener\Core\Shorter.Core\obj\Debug\Shorter.Core.pdb
Binary file not shown.
Binary file added Test/Shorter.Core/obj/Debug/shortener.Core.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
27ab5bb23956511d6ba433310c6cbf4defdc1042
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
C:\PROYECTOS\PROYECTOS_ACTUALES\Prueba_dll\Test_ShortUrl\Test\Shorter.Core\bin\Release\shortener.Core.dll
C:\PROYECTOS\PROYECTOS_ACTUALES\Prueba_dll\Test_ShortUrl\Test\Shorter.Core\bin\Release\shortener.Core.pdb
C:\PROYECTOS\PROYECTOS_ACTUALES\Prueba_dll\Test_ShortUrl\Test\Shorter.Core\obj\Release\Shortener.Core.csprojAssemblyReference.cache
C:\PROYECTOS\PROYECTOS_ACTUALES\Prueba_dll\Test_ShortUrl\Test\Shorter.Core\obj\Release\Shortener.Core.csproj.CoreCompileInputs.cache
C:\PROYECTOS\PROYECTOS_ACTUALES\Prueba_dll\Test_ShortUrl\Test\Shorter.Core\obj\Release\shortener.Core.dll
C:\PROYECTOS\PROYECTOS_ACTUALES\Prueba_dll\Test_ShortUrl\Test\Shorter.Core\obj\Release\shortener.Core.pdb
Binary file not shown.
Binary file not shown.
Binary file added Test/Shorter.Core/obj/Release/shortener.Core.pdb
Binary file not shown.
Loading