Skip to content

Commit

Permalink
Adds Pre-Processing feature. Related issue #40 (#146)
Browse files Browse the repository at this point in the history
* Adds Pre-Processing feature. Related issue #40

* Completes option for integration with Conari and others in Pre-Processing

Part of #146

* Based on `CopyLocalLockFileAssemblies`
* A bit refactored Project class. Pre-Proc feature has been splitted into separate PreProcGear implementation (IProjectGear)

* Updated form layout and its disposing method
  • Loading branch information
3F authored Apr 28, 2020
1 parent 2131353 commit 2579d14
Show file tree
Hide file tree
Showing 20 changed files with 1,166 additions and 196 deletions.
1 change: 1 addition & 0 deletions Wizard/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using net.r_eg.DllExport.Wizard.Extensions;
using net.r_eg.MvsSln;
using net.r_eg.MvsSln.Core;
using net.r_eg.MvsSln.Extensions;
using net.r_eg.MvsSln.Log;

namespace net.r_eg.DllExport.Wizard
Expand Down
29 changes: 6 additions & 23 deletions Wizard/Extensions/CollectionExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,21 @@

using System;
using System.Collections.Generic;
using net.r_eg.MvsSln.Extensions;

namespace net.r_eg.DllExport.Wizard.Extensions
{
public static class CollectionExtension
internal static class CollectionExtension
{
/// <summary>
/// Foreach in Linq manner.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="items"></param>
/// <param name="act">The action that should be executed for each item.</param>
public static IEnumerable<T> ForEach<T>(this IEnumerable<T> items, Action<T> act)
public static IEnumerable<T> Each<T>(this IEnumerable<T> items, Action<T> act)
{
return items?.ForEach((x, i) => act(x));
}

/// <summary>
/// Foreach in Linq manner.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="items"></param>
/// <param name="act">The action that should be executed for each item.</param>
public static IEnumerable<T> ForEach<T>(this IEnumerable<T> items, Action<T, long> act)
{
if(items == null) {
return null;
}

long n = 0;
foreach(var item in items) {
act(item, n++);
}
items?.ForEach((x, i) => act(x));
return items;
}

Expand All @@ -69,15 +52,15 @@ public static IEnumerable<T> ForEach<T>(this IEnumerable<T> items, Action<T, lon
/// <returns></returns>
public static IEnumerable<string> Combine(this IEnumerable<string> items, string elem, bool before = false)
{
if(before && !String.IsNullOrEmpty(elem)) {
if(before && !string.IsNullOrEmpty(elem)) {
yield return elem;
}

foreach(var item in items) {
yield return item;
}

if(!before && !String.IsNullOrEmpty(elem)) {
if(!before && !string.IsNullOrEmpty(elem)) {
yield return elem;
}
}
Expand Down
67 changes: 12 additions & 55 deletions Wizard/Extensions/StringExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace net.r_eg.DllExport.Wizard.Extensions
{
Expand All @@ -38,7 +36,7 @@ public static class StringExtension
/// <returns></returns>
public static bool ToBoolean(this string value)
{
if(String.IsNullOrWhiteSpace(value)) {
if(string.IsNullOrWhiteSpace(value)) {
return false;
}

Expand Down Expand Up @@ -67,7 +65,7 @@ public static bool ToBoolean(this string value)
/// <returns></returns>
public static int ToInteger(this string value)
{
if(String.IsNullOrWhiteSpace(value)) {
if(string.IsNullOrWhiteSpace(value)) {
return 0;
}

Expand All @@ -81,7 +79,7 @@ public static int ToInteger(this string value)
/// <returns></returns>
public static long ToLongInteger(this string value)
{
if(String.IsNullOrWhiteSpace(value)) {
if(string.IsNullOrWhiteSpace(value)) {
return 0;
}

Expand All @@ -94,44 +92,17 @@ public static long ToLongInteger(this string value)
/// <param name="url"></param>
public static void OpenUrl(this string url)
{
if(!String.IsNullOrWhiteSpace(url)) {
if(!string.IsNullOrWhiteSpace(url)) {
System.Diagnostics.Process.Start(url);
}
}

/// <summary>
/// Calculate SHA-1 hash from file.
/// </summary>
/// <param name="file">Path to file.</param>
/// <returns>SHA-1 Hash code.</returns>
public static string SHA1HashFromFile(this string file)
{
using(var fs = File.OpenRead(file))
{
using(SHA1 sha1 = SHA1.Create()) {
return BytesToHexView(sha1.ComputeHash(fs));
}
}
}

/// <summary>
/// To add postfix to filename.
/// </summary>
/// <param name="fname">Filename or path to file with extension or without.</param>
/// <param name="postfix"></param>
/// <returns></returns>
public static string AddFileNamePostfix(this string fname, string postfix)
internal static bool CmpPublicKeyTokenWith(this string pkToken, string pkTokenAsm)
{
if(String.IsNullOrWhiteSpace(fname) || String.IsNullOrWhiteSpace(postfix)) {
return fname;
}

int idx = fname.LastIndexOf('.');
if(idx == -1) {
return fname + postfix;
if(pkTokenAsm == null || string.IsNullOrWhiteSpace(pkToken)) {
return false;
}

return fname.Insert(idx, postfix);
return pkToken.Equals(pkTokenAsm, StringComparison.InvariantCultureIgnoreCase);
}

/// <summary>
Expand All @@ -141,7 +112,7 @@ public static string AddFileNamePostfix(this string fname, string postfix)
/// <returns></returns>
public static string OpenDoubleQuotes(this string value)
{
if(String.IsNullOrWhiteSpace(value)) {
if(string.IsNullOrWhiteSpace(value)) {
return value;
}

Expand Down Expand Up @@ -183,31 +154,17 @@ public static string FilePathFormat(this string path, string root = null)
/// <param name="path"></param>
/// <param name="root"></param>
/// <returns></returns>
public static string CombineRootPath(string path, string root)
private static string CombineRootPath(string path, string root)
{
if(String.IsNullOrWhiteSpace(path) || Path.IsPathRooted(path)) {
if(string.IsNullOrWhiteSpace(path) || Path.IsPathRooted(path)) {
return path;
}

if(String.IsNullOrWhiteSpace(root)) {
if(string.IsNullOrWhiteSpace(root)) {
return path;
}

return Path.Combine(root, path);
}

/// <summary>
/// To format bytes data to hex view.
/// </summary>
/// <param name="data">Bytes data.</param>
/// <returns>Hex view of bytes.</returns>
private static string BytesToHexView(byte[] data)
{
var ret = new StringBuilder();
foreach(byte b in data) {
ret.Append(b.ToString("X2"));
}
return ret.ToString();
}
}
}
11 changes: 11 additions & 0 deletions Wizard/Extensions/XProjectExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,16 @@ public static Guid GetPId(this IXProject xp)
)
.Guid();
}

public static void AddPackageIfNotExists(this IXProject xp, string id, string version)
{
if(xp == null) {
throw new ArgumentNullException(nameof(xp));
}

if(xp.GetFirstPackageReference(id ?? throw new ArgumentNullException(nameof(id))).parentItem == null) {
xp.AddPackageReference(id, version);
}
}
}
}
33 changes: 33 additions & 0 deletions Wizard/Gears/IProjectGear.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2020 Denis Kuzmin < x-3F@outlook.com > GitHub/3F
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace net.r_eg.DllExport.Wizard.Gears
{
internal interface IProjectGear
{
void Install();

void Uninstall(bool hardReset);
}
}
Loading

0 comments on commit 2579d14

Please sign in to comment.