Skip to content

Commit

Permalink
Merge pull request #145 from TelerikAcademy/CodeRefactorings
Browse files Browse the repository at this point in the history
Code refactorings
  • Loading branch information
NikolayIT committed Aug 16, 2015
2 parents c4f9a17 + 44522bb commit 5011727
Show file tree
Hide file tree
Showing 23 changed files with 14 additions and 27 deletions.
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
Expand Up @@ -10,7 +10,7 @@
durationin:2000;
delayin:300;
offsetxout:-50;
durationout:1000;" style="top: 370px; left: 200px; font-weight: 300; height: 40px; padding: 0px 10px; font-size: 30px; line-height: 37px; color: rgb(169, 69, 69); white-space: nowrap; width: auto; border-width: 0px; margin-left: 0px; margin-top: 0px; transform-origin: 50% 50% 0px; transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, -0.002, 0, 0, 0, 1); opacity: 0.7; visibility: visible; filter: none; background: rgba(255, 255, 255, 0.85098);">
durationout:1000;" style="top: 370px; left: 200px; font-weight: 300; height: 40px; padding: 0 10px; font-size: 30px; line-height: 37px; color: rgb(169, 69, 69); white-space: nowrap; width: auto; border-width: 0; margin-left: 0; margin-top: 0; transform-origin: 50% 50% 0; transform: matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, -0.002, 0, 0, 0, 1); opacity: 0.7; visibility: visible; filter: none; background: rgba(255, 255, 255, 0.85098);">
<a href="/projects/{{project.id}}/{{project.titleUrl}}" style="color: white;">{{project.title}}</a>
</p>
</div>
Expand Down
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
2 changes: 0 additions & 2 deletions Source/Data/Showcase.Data.Models/File.cs
Expand Up @@ -2,8 +2,6 @@
{
using System.ComponentModel.DataAnnotations.Schema;

using Showcase.Data.Common;

[Table("Files")]
public class File : FileInfo
{
Expand Down
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
1 change: 0 additions & 1 deletion Source/Data/Showcase.Data/Properties/AssemblyInfo.cs
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
Expand Up @@ -2,7 +2,6 @@
{
using System.Web.Http;

using AutoMapper;
using AutoMapper.QueryableExtensions;

using Showcase.Server.Api.Controllers.Base;
Expand Down
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
Expand Up @@ -35,7 +35,7 @@ public void CreateMappings(IConfiguration configuration)
{
string visitorUsername = null;
string username = null;
bool isAdmin = false;
bool isAdmin = false; // TODO: Value is always false?
configuration.CreateMap<User, UserResponseModel>()
.ForMember(u => u.ProjectsCount, opt => opt.MapFrom(u => u.Projects.Count))
.ForMember(u => u.CommentsCount, opt => opt.MapFrom(u => u.Comments.Count))
Expand Down
@@ -1,7 +1,6 @@
namespace Showcase.Server.Infrastructure.Auth
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using Microsoft.Owin.Security;
Expand Down Expand Up @@ -115,12 +114,12 @@ private bool IsValidContext(OAuthGrantResourceOwnerCredentialsContext context)
}
else if (string.IsNullOrEmpty(context.UserName) || string.IsNullOrWhiteSpace(context.UserName))
{
context.SetError("invalid_grant", string.Format("Information is not valid"));
context.SetError("invalid_grant", "Information is not valid");
isValid = false;
}
else if (string.IsNullOrEmpty(context.Password) || string.IsNullOrWhiteSpace(context.Password))
{
context.SetError("invalid_grant", string.Format("Information is not valid"));
context.SetError("invalid_grant", "Information is not valid");
isValid = false;
}

Expand All @@ -134,7 +133,7 @@ private async Task<User> LoginUser(OAuthGrantResourceOwnerCredentialsContext con
// Check if remote login credentials are correct
if (user == null)
{
context.SetError("invalid_grant", string.Format("Information is not valid"));
context.SetError("invalid_grant", "Information is not valid");
return null;
}

Expand Down
Expand Up @@ -44,6 +44,7 @@ private async Task SaveFile(byte[] content, string path)
await Task.Run(async () =>
{
var filePath = HostingEnvironment.MapPath(path);
//// TODO: filePath can be null
var fileInfo = new FileInfo(filePath);
fileInfo.Directory.Create();
using (var fileWriter = new FileStream(filePath, FileMode.CreateNew))
Expand Down
Expand Up @@ -49,6 +49,7 @@ public override Task WriteToStreamAsync(Type type, object value, Stream writeStr
var task = Task.Factory.StartNew(() =>
{
var viewPath = HostingEnvironment.MapPath(CrawlersIndexView);
//// TODO: viewPath can be null
var template = File.ReadAllText(viewPath);
if (!Engine.Razor.IsTemplateCached(type.Name, type))
Expand Down
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
Expand Up @@ -17,6 +17,7 @@ public override void OnActionExecuting(HttpActionContext actionContext)
{
var routeData = actionContext.RequestContext.RouteData.Values;

//// TODO: routeData.FirstOrDefault() result can be null
var folder = int.Parse(routeData.FirstOrDefault(a => a.Key == "folder").Value as string);
var file = routeData.FirstOrDefault(a => a.Key == "file").Value as string;

Expand Down
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
Expand Up @@ -35,7 +35,7 @@ public async Task<IEnumerable<File>> AddNew(IEnumerable<RawFile> rawFiles)
{
var addedFiles = await rawFiles.ForEachAsync(async rawFile =>
{
var file = await base.SaveFileInfo<File>(rawFile);
var file = await this.SaveFileInfo<File>(rawFile);
file.Content = rawFile.Content;
return file;
});
Expand Down
2 changes: 1 addition & 1 deletion Source/Services/Showcase.Services.Data/ImagesService.cs
Expand Up @@ -24,7 +24,7 @@ public async Task<IEnumerable<ProcessedImage>> ProcessImages(IEnumerable<RawFile
{
var processedImages = await rawImages.ForEachAsync(async rawImage =>
{
var image = await base.SaveFileInfo<Image>(rawImage);
var image = await this.SaveFileInfo<Image>(rawImage);
var thumbnailContent = await this.imageProcessor.Resize(rawImage.Content, ProcessedImage.ThumbnailImageWidth);
var highContent = await this.imageProcessor.Resize(rawImage.Content, ProcessedImage.HighResolutionWidth);
Expand Down
Expand Up @@ -14,16 +14,16 @@ public class ProcessedImage : Image
public const int HighResolutionWidth = 1360;
public const string HighResolutionImage = "high";

private static IMappingService mappingService;
private static readonly IMappingService MappingService;

static ProcessedImage()
{
mappingService = ObjectFactory.Get<IMappingService>();
MappingService = ObjectFactory.Get<IMappingService>();
}

public static Func<ProcessedImage, Image> ToImage
{
get { return pi => mappingService.Map<Image>(pi); }
get { return pi => MappingService.Map<Image>(pi); }
}

public byte[] ThumbnailContent { get; set; }
Expand All @@ -32,7 +32,7 @@ static ProcessedImage()

public static ProcessedImage FromImage(Image image, byte[] thumbnailContent, byte[] highResolutionContent)
{
var result = mappingService.Map<ProcessedImage>(image);
var result = MappingService.Map<ProcessedImage>(image);
result.ThumbnailContent = thumbnailContent;
result.HighResolutionContent = highResolutionContent;
return result;
Expand Down
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down

0 comments on commit 5011727

Please sign in to comment.