Skip to content

Commit

Permalink
introduced string interpolation where it could simplify the code
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisWillDoIt committed Oct 3, 2016
1 parent caecc31 commit a7902cd
Show file tree
Hide file tree
Showing 105 changed files with 391 additions and 421 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ internal bool DeletePage(string blogId, string pageId, string userName, string p
}
catch (Exception ex)
{
throw new MetaWeblogException("15", string.Format("DeletePage failed. Error: {0}", ex.Message));
throw new MetaWeblogException("15", $"DeletePage failed. Error: {ex.Message}");
}

return true;
Expand Down Expand Up @@ -220,7 +220,7 @@ internal bool DeletePost(string appKey, string postId, string userName, string p
}
catch (Exception ex)
{
throw new MetaWeblogException("12", string.Format("DeletePost failed. Error: {0}", ex.Message));
throw new MetaWeblogException("12", $"DeletePost failed. Error: {ex.Message}");
}

return true;
Expand Down Expand Up @@ -712,7 +712,7 @@ internal MWAMediaInfo NewMediaObject(

var mediaInfo = new MWAMediaInfo();

var rootPath = string.Format("{0}files/", Blog.CurrentInstance.StorageLocation);
var rootPath = $"{Blog.CurrentInstance.StorageLocation}files/";
var serverPath = request.Server.MapPath(rootPath);
var saveFolder = serverPath;
string mediaObjectName = mediaObject.name.Replace(" ", "_");
Expand Down Expand Up @@ -749,7 +749,7 @@ internal MWAMediaInfo NewMediaObject(
// Find unique fileName
for (var count = 1; count < 30000; count++)
{
var tempFileName = fileName.Insert(fileName.LastIndexOf('.'), string.Format("_{0}", count));
var tempFileName = fileName.Insert(fileName.LastIndexOf('.'), $"_{count}");
if (File.Exists(saveFolder + tempFileName))
{
continue;
Expand Down
4 changes: 2 additions & 2 deletions BlogEngine/BlogEngine.Core/API/MetaWeblog/XMLRPCRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ private void LoadXmlRequest(string xml)
}
catch (Exception ex)
{
throw new MetaWeblogException("01", string.Format("Invalid XMLRPC Request. ({0})", ex.Message));
throw new MetaWeblogException("01", $"Invalid XMLRPC Request. ({ex.Message})");
}

// Method name is always first
Expand Down Expand Up @@ -449,7 +449,7 @@ private void LoadXmlRequest(string xml)
this.PageID = this.inputParams[3].InnerText;
break;
default:
throw new MetaWeblogException("02", string.Format("Unknown Method. ({0})", this.MethodName));
throw new MetaWeblogException("02", $"Unknown Method. ({MethodName})");
}
}

Expand Down
4 changes: 2 additions & 2 deletions BlogEngine/BlogEngine.Core/AuthorProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public string FullName
{
get
{
return string.Format("{0} {1} {2}", this.FirstName, this.MiddleName, this.LastName).Replace(" ", " ");
return $"{FirstName} {MiddleName} {LastName}".Replace(" ", " ");
}
}

Expand Down Expand Up @@ -439,7 +439,7 @@ public string RelativeLink
{
get
{
return string.Format("{0}author/{1}{2}", Utils.RelativeWebRoot, this.Id, BlogConfig.FileExtension);
return $"{Utils.RelativeWebRoot}author/{Id}{BlogConfig.FileExtension}";
}
}

Expand Down
10 changes: 5 additions & 5 deletions BlogEngine/BlogEngine.Core/Blog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ public string StorageLocation
return BlogConfig.StorageLocation;
}

return string.Format("{0}{1}/{2}/", BlogConfig.StorageLocation, BlogConfig.BlogInstancesFolderName, this.StorageContainerName);
return $"{BlogConfig.StorageLocation}{BlogConfig.BlogInstancesFolderName}/{StorageContainerName}/";
}
}

Expand Down Expand Up @@ -676,7 +676,7 @@ public Uri AbsoluteWebRoot
{
get
{
string contextItemKey = string.Format("{0}-absolutewebroot", this.Id);
string contextItemKey = $"{Id}-absolutewebroot";

var context = HttpContext.Current;
if (context == null)
Expand Down Expand Up @@ -955,7 +955,7 @@ internal bool CopyExistingBlogFolderToNewBlogFolder(Blog existingBlog)
existingBlogStoragePath = HostingEnvironment.MapPath(existingBlog.StorageLocation);
if (!Directory.Exists(existingBlogStoragePath))
{
throw new Exception(string.Format("Storage folder for existing blog instance to copy from does not exist. Directory not found is: {0}", existingBlogStoragePath));
throw new Exception($"Storage folder for existing blog instance to copy from does not exist. Directory not found is: {existingBlogStoragePath}");
}
}
catch (Exception ex)
Expand All @@ -965,7 +965,7 @@ internal bool CopyExistingBlogFolderToNewBlogFolder(Blog existingBlog)
}

// Ensure "BlogInstancesFolderName" exists.
string blogInstancesFolder = HostingEnvironment.MapPath(string.Format("{0}{1}", BlogConfig.StorageLocation, BlogConfig.BlogInstancesFolderName));
string blogInstancesFolder = HostingEnvironment.MapPath($"{BlogConfig.StorageLocation}{BlogConfig.BlogInstancesFolderName}");
if (!Utils.CreateDirectoryIfNotExists(blogInstancesFolder))
return false;

Expand All @@ -976,7 +976,7 @@ internal bool CopyExistingBlogFolderToNewBlogFolder(Blog existingBlog)
{
if (Directory.Exists(newBlogStoragePath))
{
throw new Exception(string.Format("Blog destination folder already exists. {0}", newBlogStoragePath));
throw new Exception($"Blog destination folder already exists. {newBlogStoragePath}");
}
}
catch (Exception ex)
Expand Down
4 changes: 2 additions & 2 deletions BlogEngine/BlogEngine.Core/BlogSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public bool IsRazorTheme
/// </summary>
public static bool IsThemeRazor(string themeName)
{
string path = HostingEnvironment.MapPath(string.Format("~/Custom/Themes/{0}/site.cshtml", themeName));
string path = HostingEnvironment.MapPath($"~/Custom/Themes/{themeName}/site.cshtml");
return File.Exists(path);
}

Expand Down Expand Up @@ -1312,7 +1312,7 @@ private void Load(Blog blog)
}
catch (Exception e)
{
Utils.Log(string.Format("Error loading blog settings: {0}", e.Message));
Utils.Log($"Error loading blog settings: {e.Message}");
}
}

Expand Down
2 changes: 1 addition & 1 deletion BlogEngine/BlogEngine.Core/Category.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public string CompleteTitle()

var cat = GetCategory((Guid)parent, Blog.CurrentInstance.IsSiteAggregation);

return cat == null ? title : string.Format("{0} - {1}", cat.CompleteTitle(), title);
return cat == null ? title : $"{cat.CompleteTitle()} - {title}";
}


Expand Down
6 changes: 3 additions & 3 deletions BlogEngine/BlogEngine.Core/Comment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public Uri AbsoluteLink
{
get
{
return new Uri(string.Format("{0}#id_{1}", Parent.AbsoluteLink, Id));
return new Uri($"{Parent.AbsoluteLink}#id_{Id}");
}
}

Expand Down Expand Up @@ -240,7 +240,7 @@ public string RelativeLink
{
get
{
return string.Format("{0}#id_{1}", Parent.RelativeLink, Id);
return $"{Parent.RelativeLink}#id_{Id}";
}
}

Expand Down Expand Up @@ -268,7 +268,7 @@ public string Teaser
get
{
var ret = Utils.StripHtml(Content).Trim();
return ret.Length > 120 ? string.Format("{0} ...", ret.Substring(0, 116)) : ret;
return ret.Length > 120 ? $"{ret.Substring(0, 116)} ..." : ret;
}
}

Expand Down
4 changes: 2 additions & 2 deletions BlogEngine/BlogEngine.Core/Data/CategoryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public CategoryItem Add(CategoryItem item)
}
catch (Exception ex)
{
Utils.Log(string.Format("CategoryRepository.Add: {0}", ex.Message));
Utils.Log($"CategoryRepository.Add: {ex.Message}");
return null;
}
}
Expand Down Expand Up @@ -172,7 +172,7 @@ public bool Remove(Guid id)
}
catch (Exception ex)
{
Utils.Log(string.Format("CategoryRepository.Remove: {0}", ex.Message));
Utils.Log($"CategoryRepository.Remove: {ex.Message}");
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions BlogEngine/BlogEngine.Core/Data/CustomFilterRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ public JsonResponse ResetCounters(string filterName)
}
ExtensionManager.SaveSettings("MetaExtension", CustomFilters);
}
return new JsonResponse() { Success = true, Message = string.Format("Counters for {0} reset", filterName) };
return new JsonResponse() { Success = true, Message = $"Counters for {filterName} reset"};
}
catch (Exception ex)
{
Utils.Log(string.Format("CustomFilterRepository.ResetCounters: {0}", ex.Message));
Utils.Log($"CustomFilterRepository.ResetCounters: {ex.Message}");
return new JsonResponse() { Message = "Error resetting counters" };
}
}
Expand Down
2 changes: 1 addition & 1 deletion BlogEngine/BlogEngine.Core/Data/LookupsRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void LoadCultures()
}
else
{
var path = HostingEnvironment.MapPath(string.Format("{0}App_GlobalResources/", Utils.ApplicationRelativeWebRoot));
var path = HostingEnvironment.MapPath($"{Utils.ApplicationRelativeWebRoot}App_GlobalResources/");
foreach (var file in Directory.GetFiles(path, "labels.*.resx"))
{
var index = file.LastIndexOf(Path.DirectorySeparatorChar) + 1;
Expand Down
2 changes: 1 addition & 1 deletion BlogEngine/BlogEngine.Core/Data/PackageRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public bool Update(Package item)
}
else
{
Utils.Log(string.Format("Failed to find extension {0} while trying to update package repository", item.Id));
Utils.Log($"Failed to find extension {item.Id} while trying to update package repository");
}
}
break;
Expand Down
2 changes: 1 addition & 1 deletion BlogEngine/BlogEngine.Core/Data/PageRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ static string GetUniqueSlug(string slug)
if (IsUniqueSlug(s))
break;

s = string.Format("{0}{1}", slug, i);
s = $"{slug}{i}";
}
return s;
}
Expand Down
2 changes: 1 addition & 1 deletion BlogEngine/BlogEngine.Core/Data/PostRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static string GetUniqueSlug(string slug)
if (IsUniqueSlug(s))
break;

s = string.Format("{0}{1}", slug, i);
s = $"{slug}{i}";
}
return s;
}
Expand Down
12 changes: 6 additions & 6 deletions BlogEngine/BlogEngine.Core/Data/Services/Avatar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace BlogEngine.Core.Data.Services
/// </summary>
public class Avatar
{
private static string _noAvatar = string.Format("{0}Content/images/blog/noavatar.jpg", Utils.AbsoluteWebRoot);
private static string _pingImg = string.Format("{0}Content/images/blog/pingback.png", Utils.AbsoluteWebRoot);
private static string _noAvatar = $"{Utils.AbsoluteWebRoot}Content/images/blog/noavatar.jpg";
private static string _pingImg = $"{Utils.AbsoluteWebRoot}Content/images/blog/pingback.png";

/// <summary>
/// Get avatar image source
Expand Down Expand Up @@ -43,13 +43,13 @@ public static string GetSrc(string email, string website = "")
return src;

// default noavatar if nothing worked
return string.Format("{0}Content/images/blog/noavatar.jpg", Utils.AbsoluteWebRoot);
return $"{Utils.AbsoluteWebRoot}Content/images/blog/noavatar.jpg";
}

static string ThemeNoAvatar(string email)
{
var themeAvatar = string.Format(
"{0}Custom/Themes/{1}/noavatar.jpg", Utils.ApplicationRelativeWebRoot, BlogSettings.Instance.Theme);
var themeAvatar =
$"{Utils.ApplicationRelativeWebRoot}Custom/Themes/{BlogSettings.Instance.Theme}/noavatar.jpg";

if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(themeAvatar)))
return themeAvatar;
Expand All @@ -65,7 +65,7 @@ static string Gravatar(string email)
if (hash != null)
hash = hash.ToLowerInvariant();

var gravatar = string.Format("http://www.gravatar.com/avatar/{0}.jpg?d=", hash);
var gravatar = $"http://www.gravatar.com/avatar/{hash}.jpg?d=";

switch (BlogSettings.Instance.Avatar)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static List<CustomField> LoadFields()
static List<CustomField> FromThemeTemplates()
{
var dirPath = HttpContext.Current.Server.MapPath(
string.Format("{0}Custom/Themes", Utils.ApplicationRelativeWebRoot));
$"{Utils.ApplicationRelativeWebRoot}Custom/Themes");

var items = new List<CustomField>();

Expand Down
4 changes: 2 additions & 2 deletions BlogEngine/BlogEngine.Core/Data/Services/TagCloud.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public List<string> Links()
{
var link = string.Format(
Link,
string.Format("{0}?tag={1}", Utils.AbsoluteWebRoot, HttpUtility.UrlEncode(key)),
WeightedList[key], string.Format("Tag: {0}", key), key);
$"{Utils.AbsoluteWebRoot}?tag={HttpUtility.UrlEncode(key)}",
WeightedList[key], $"Tag: {key}", key);
links.Add(link);
}
return links;
Expand Down
4 changes: 2 additions & 2 deletions BlogEngine/BlogEngine.Core/Data/TagRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public bool Save(string updateFrom, string updateTo)
}
catch (Exception ex)
{
Utils.Log(string.Format("TagRepository.Update: {0}", ex.Message));
Utils.Log($"TagRepository.Update: {ex.Message}");
return false;
}
}
Expand Down Expand Up @@ -117,7 +117,7 @@ public bool Delete(string id)
}
catch (Exception ex)
{
Utils.Log(string.Format("Tags.Delete: {0}", ex.Message));
Utils.Log($"Tags.Delete: {ex.Message}");
return false;
}
}
Expand Down
6 changes: 3 additions & 3 deletions BlogEngine/BlogEngine.Core/Helpers/BlogGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public static bool CopyTemplateBlogFolder(string blogName, string userName, stri

if (!Directory.Exists(templateFolderPath))
{
throw new Exception(string.Format("Template folder for new blog does not exist. Directory not found is: {0}", templateFolderPath));
throw new Exception($"Template folder for new blog does not exist. Directory not found is: {templateFolderPath}");
}
}
catch (Exception ex)
Expand All @@ -165,7 +165,7 @@ public static bool CopyTemplateBlogFolder(string blogName, string userName, stri
{
if (Directory.Exists(newBlogFolderPath))
{
throw new Exception(string.Format("Blog destination folder already exists. {0}", newBlogFolderPath));
throw new Exception($"Blog destination folder already exists. {newBlogFolderPath}");
}
}
catch (Exception ex)
Expand All @@ -174,7 +174,7 @@ public static bool CopyTemplateBlogFolder(string blogName, string userName, stri
throw; // re-throw error so error message bubbles up.
}
if (!Utils.CreateDirectoryIfNotExists(newBlogFolderPath))
throw new Exception(string.Format("Can not create blog directory: {0}", newBlogFolderPath));
throw new Exception($"Can not create blog directory: {newBlogFolderPath}");

// Copy the entire directory contents.
DirectoryInfo source = new DirectoryInfo(templateFolderPath);
Expand Down
2 changes: 1 addition & 1 deletion BlogEngine/BlogEngine.Core/Helpers/Pager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static string Render(string callback = "false")

var linkFormat = "<a href=\"#\" id=\"{0}\" onclick=\"return " + callback + ";\" class=\"{0}\">{1}</a>";

var pageLink = string.Format("<span>Showing {0} - {1} of {2}</span>", From, To, Total);
var pageLink = $"<span>Showing {From} - {To} of {Total}</span>";

if (CurrentPage > 1)
{
Expand Down
Loading

0 comments on commit a7902cd

Please sign in to comment.