Skip to content

Commit

Permalink
The final draft-version of the new configurator via MvsSln - #38
Browse files Browse the repository at this point in the history
Also changed `IDDNS.setNamespace(...)` I think I'll leave old configurator for original nuget clients... need to think.

+updated MvsSln v1.0.1.43422
 https://github.com/3F/MvsSln
  • Loading branch information
3F committed Jul 21, 2017
1 parent 66b21ec commit 536bfbc
Show file tree
Hide file tree
Showing 27 changed files with 1,029 additions and 192 deletions.
13 changes: 9 additions & 4 deletions .vssbe
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@
"Mode": {
"$type": "net.r_eg.vsSBE.Events.ModeScript, vsSolutionBuildEvent",
"Type": "Script",
"Command": "#[IO copy.file(\n \"$(SolutionDir)tools/*.*\", \n \"$(odir)/tools/\", \n true, \n {\"*.nuspec\"})]\n\n#[IO copy.file(\"tools/DllExport.nuspec\", \"$(odir)/DllExport.nuspec\", true)]\n\n#[IO copy.file({\n \"$(pDllExport)/$(OutDir:$(pDllExport))/*.*\",\n \"$(pMSBuild)/$(OutDir:$(pMSBuild))/*.*\",\n \"$(pNSBin)/$(OutDir:$(pNSBin))/*.*\",\n \"$(pWizard)/$(OutDir:$(pWizard))/*.*\",\n \"$(pConf)/$(OutDir:$(pConf))/*.*\"\n }, \n \"$(odir)/tools/\", true)]\n\n \n#[IO copy.file(\"$(pMeta)/$(OutDir:$(pMeta))/*.dll\", \n \"$(odir)/lib/net20/\", true)]\n\n#[IO copy.file({ \"Readme.md\", \"3rd-party.txt\", \"changelog.txt\" }, \"$(odir)/\", true)]\n#[IO copy.file(\"LICENSE\", \"$(odir)/License.txt\", true)]\n\n#[IO writeLine(\"$(odir)/build_info.txt\"):\n S_NUM: #[$(pVer)]\n \n S_REV: #[$(revBuild)]\n \n S_NUM_REV: #[$(pVer)].#[$(revBuild)]\n \n bSha1: #[$(bSha1)]\n \n bName: #[$(bName)]\n \n bRevc: #[$(bRevc)]\n \n Metadata .NET: #[$(TargetFrameworkVersion:$(pMeta))]\n \n Wizard .NET: #[$(TargetFrameworkVersion:$(pWizard))]\n \n Configurator .NET: #[$(TargetFrameworkVersion:$(pConf))]\n \n Configuration: #[$(Configuration)]\n \n Platform: #[$(Platform)]\n \n cfgname: #[$(cfgname)]\n \n revDeltaBase: #[$(revDeltaBase)]\n \n revDeltaMin: #[$(revDeltaMin)]\n \n revDeltaMax: #[$(revDeltaMax)]\n \n \n :: generated by a vsSolutionBuildEvent v#[$(vsSolutionBuildEvent)]]",
"Command": "#[IO copy.file(\n \"$(SolutionDir)tools/*.*\", \n \"$(odir)/tools/\", \n true, \n {\"*.nuspec\"})]\n\n#[IO copy.file(\"tools/DllExport.nuspec\", \"$(odir)/DllExport.nuspec\", true)]\n\n#[IO copy.file({\n \"$(pDllExport)/$(OutDir:$(pDllExport))/*.*\",\n \"$(pMSBuild)/$(OutDir:$(pMSBuild))/*.*\",\n \"$(pNSBin)/$(OutDir:$(pNSBin))/*.*\",\n \"$(pWizard)/$(OutDir:$(pWizard))/*.*\",\n \"$(pConf)/$(OutDir:$(pConf))/*.*\"\n }, \n \"$(odir)/tools/\", true)]\n\n \n#[IO copy.file(\"$(pMeta)/$(OutDir:$(pMeta))/*.dll\", \n \"$(odir)/lib/net20/\", true)]\n\n#[IO copy.file({ \"Readme.md\", \"3rd-party.txt\", \"changelog.txt\" }, \"$(odir)/\", true)]\n#[IO copy.file(\"LICENSE\", \"$(odir)/License.txt\", true)]\n\n#[var buildInfo = $([System.String]::Concat(\" \"))\n S_NUM: #[$(pVer)]\n \n S_REV: #[$(revBuild)]\n \n S_NUM_REV: #[$(pVer)].#[$(revBuild)]\n \n bSha1: #[$(bSha1)]\n \n bName: #[$(bName)]\n \n bRevc: #[$(bRevc)]\n \n Metadata .NET: #[$(TargetFrameworkVersion:$(pMeta))]\n \n Wizard .NET: #[$(TargetFrameworkVersion:$(pWizard))]\n \n Configurator .NET: #[$(TargetFrameworkVersion:$(pConf))]\n \n Configuration: #[$(Configuration)]\n \n Platform: #[$(Platform)]\n \n cfgname: #[$(cfgname)]\n \n revDeltaBase: #[$(revDeltaBase)]\n \n revDeltaMin: #[$(revDeltaMin)]\n \n revDeltaMax: #[$(revDeltaMax)]\n \n \n :: generated by a vsSolutionBuildEvent v#[$(vsSolutionBuildEvent)]\n]\n\n#[IO writeLine(\"$(odir)/build_info.txt\"):#[var buildInfo]]",
"Command__": [
"#[IO copy.file(",
" \"$(SolutionDir)tools/*.*\", ",
Expand All @@ -357,7 +357,7 @@
"#[IO copy.file({ \"Readme.md\", \"3rd-party.txt\", \"changelog.txt\" }, \"$(odir)/\", true)]",
"#[IO copy.file(\"LICENSE\", \"$(odir)/License.txt\", true)]",
"",
"#[IO writeLine(\"$(odir)/build_info.txt\"):",
"#[var buildInfo = $([System.String]::Concat(\" \"))",
" S_NUM: #[$(pVer)]",
" ",
" S_REV: #[$(revBuild)]",
Expand Down Expand Up @@ -389,7 +389,10 @@
" revDeltaMax: #[$(revDeltaMax)]",
" ",
" ",
" :: generated by a vsSolutionBuildEvent v#[$(vsSolutionBuildEvent)]]"
" :: generated by a vsSolutionBuildEvent v#[$(vsSolutionBuildEvent)]",
"]",
"",
"#[IO writeLine(\"$(odir)/build_info.txt\"):#[var buildInfo]]"
]
}
},
Expand Down Expand Up @@ -459,8 +462,10 @@
"Mode": {
"$type": "net.r_eg.vsSBE.Events.ModeScript, vsSolutionBuildEvent",
"Type": "Script",
"Command": "#[NuGet gnt.raw(\"/t:pack /p:ngin=\\\"$(odir)\\\" /p:ngout=\\\"$(dbin)\\\"\")]",
"Command": "#[IO replace(\"$(odir)/DllExport.nuspec\", \"{build_info}\", \"$(buildInfo)\")]\r\n\r\n#[NuGet gnt.raw(\"/t:pack /p:ngin=\\\"$(odir)\\\" /p:ngout=\\\"$(dbin)\\\"\")]",
"Command__": [
"#[IO replace(\"$(odir)/DllExport.nuspec\", \"{build_info}\", \"$(buildInfo)\")]",
"",
"#[NuGet gnt.raw(\"/t:pack /p:ngin=\\\"$(odir)\\\" /p:ngout=\\\"$(dbin)\\\"\")]"
]
}
Expand Down
5 changes: 3 additions & 2 deletions NSBin/DDNS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ public static bool IsValidNS(string name)
/// <param name="lib">Full path to prepared library.</param>
/// <param name="name">New namespace.</param>
/// <param name="useCecil">Use Cecil instead of direct modification.</param>
public void setNamespace(string lib, string name, bool useCecil)
/// <param name="preparing">Preparing library is obsolete variant for previous distribution with nuget.</param>
public void setNamespace(string lib, string name, bool useCecil, bool preparing = true)
{
using(var def = new Rmod(lib, encoding)) {
def.setNamespace(name, useCecil);
def.setNamespace(name, useCecil, preparing);
}
}

Expand Down
3 changes: 2 additions & 1 deletion NSBin/IDDNS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public interface IDDNS
/// <param name="lib">Full path to prepared library.</param>
/// <param name="name">New namespace.</param>
/// <param name="useCecil">To use Cecil instead of direct modification.</param>
void setNamespace(string lib, string name, bool useCecil);
/// <param name="preparing">Preparing library is obsolete variant for previous distribution with nuget.</param>
void setNamespace(string lib, string name, bool useCecil, bool preparing = true);
}
}
6 changes: 4 additions & 2 deletions NSBin/Rmod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static bool IsValidNS(string name)
&& !Regex.IsMatch(name, @"(?:\.(\s*\.)+|\.\s*$)"); // left. ... .right.
}

public void setNamespace(string name, bool viaCecil = true)
public void setNamespace(string name, bool viaCecil, bool preparing)
{
Log.send(this, $"set new namespace(Cecil: {viaCecil}): ({name}) - ({dll})");

Expand All @@ -89,7 +89,9 @@ public void setNamespace(string name, bool viaCecil = true)
// throw new ArgumentException("The namespace cannot be null or empty.");
//}

prepareLib(dll);
if(preparing) {
prepareLib(dll);
}
var ns = nsRule(name);

if(viaCecil) {
Expand Down
47 changes: 41 additions & 6 deletions Wizard/DllExportCfgTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ public string SlnDir
set;
}

/// <summary>
/// Optional predefined .sln file to process via the restore operations etc.
/// </summary>
public string SlnFile
{
get;
set;
}

/// <summary>
/// Root path of the DllExport package.
/// </summary>
Expand All @@ -53,6 +62,26 @@ public string PkgPath
set;
}

/// <summary>
/// Relative path from PkgPath to DllExport meta library.
/// </summary>
[Required]
public string MetaLib
{
get;
set;
}

/// <summary>
/// Path to .target file of the DllExport.
/// </summary>
[Required]
public string DxpTarget
{
get;
set;
}

/// <summary>
/// Raw type of operation via ActionType.
/// </summary>
Expand Down Expand Up @@ -111,12 +140,15 @@ internal bool TryExecute(IExecutor exec, Action act)
}
catch(Exception ex)
{
LSender.Send(this, $"ERROR-GUI: {ex.Message}");
LSender.Send(this, $"SlnDir: {SlnDir}");
LSender.Send(this, $"PkgPath: {PkgPath}");
LSender.Send(this, $"Action: {Type}");
LSender.Send(this, $"ERROR-Wizard: {ex.Message}", Message.Level.Fatal);
LSender.Send(this, $"SlnDir: '{SlnDir}'", Message.Level.Warn);
LSender.Send(this, $"SlnFile: '{SlnFile}'", Message.Level.Warn);
LSender.Send(this, $"PkgPath: '{PkgPath}'", Message.Level.Warn);
LSender.Send(this, $"MetaLib: '{MetaLib}'", Message.Level.Warn);
LSender.Send(this, $"DxpTarget: '{DxpTarget}'", Message.Level.Warn);
LSender.Send(this, $"Action: '{Type}'", Message.Level.Warn);
#if DEBUG
LSender.Send(this, $"Stack trace: {ex.StackTrace}");
LSender.Send(this, $"Stack trace: {ex.StackTrace}", Message.Level.Error);
#endif
}
finally {
Expand All @@ -129,7 +161,10 @@ internal bool TryExecute(IExecutor exec, Action act)

protected virtual void ConWrite(string message, Message.Level level)
{
if(level == Message.Level.Error || level == Message.Level.Fatal) {
if(level == Message.Level.Fatal) {
Console.ForegroundColor = ConsoleColor.Blue;
}
else if(level == Message.Level.Error) {
Console.ForegroundColor = ConsoleColor.Red;
}
else if(level == Message.Level.Warn) {
Expand Down
42 changes: 30 additions & 12 deletions Wizard/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using System.Linq;
using System.Text;
using net.r_eg.DllExport.NSBin;
using net.r_eg.DllExport.Wizard.Extensions;
using net.r_eg.MvsSln;
using net.r_eg.MvsSln.Core;
using net.r_eg.MvsSln.Log;
Expand Down Expand Up @@ -74,7 +75,7 @@ public IEnumerable<string> SlnFiles
/// <returns></returns>
public IEnumerable<IProject> ProjectsBy(string sln)
{
return GetEnv(sln)?.Projects.Select(p => new Project(p, GetDefaultUserConfig()));
return GetEnv(sln)?.Projects?.Select(p => new Project(p, GetUserConfig(p)));
}

/// <summary>
Expand All @@ -84,7 +85,7 @@ public IEnumerable<IProject> ProjectsBy(string sln)
/// <returns></returns>
public IEnumerable<IProject> UniqueProjectsBy(string sln)
{
return GetEnv(sln)?.UniqueByGuidProjects.Select(p => new Project(p, GetDefaultUserConfig()));
return GetEnv(sln)?.UniqueByGuidProjects?.Select(p => new Project(p, GetUserConfig(p)));
}

/// <summary>
Expand All @@ -100,13 +101,30 @@ public ISender Log
/// </summary>
public void Configure()
{
if(Config.Type == ActionType.Configure) {
var frm = new UI.ConfiguratorForm(this);
frm.ShowDialog();
if(Config.Type == ActionType.Configure)
{
using(var frm = new UI.ConfiguratorForm(this)) {
frm.ShowDialog();
}
return;
}

if(Config.Type == ActionType.Restore) {
//TODO:
if(Config.Type == ActionType.Restore)
{
var sln = String.IsNullOrWhiteSpace(Config.SlnFile) ? SlnFiles.FirstOrDefault() : Config.SlnFile;
if(sln == null)
{
throw new ArgumentException(
String.Format(
"We can't find any .sln file to continue processing. Use '{0}' property or check '{1}'",
nameof(IWizardConfig.SlnFile),
nameof(IWizardConfig.SlnDir)
)
);
}
Log.send(this, $"To restore '{sln}'", Message.Level.Info);

UniqueProjectsBy(sln)?.ForEach(p => p.Configure(ActionType.Restore));
}
}

Expand All @@ -116,9 +134,9 @@ public Executor(IWizardConfig cfg)
Config = cfg ?? throw new ArgumentNullException(nameof(cfg));
}

protected virtual IUserConfig GetDefaultUserConfig()
protected virtual IUserConfig GetUserConfig(IXProject project)
{
return new UserConfig(Config) {
return new UserConfig(Config, project) {
NSBuffer = DDNS.NSBuffer,
DDNS = DDNS,
Log = Log,
Expand All @@ -132,12 +150,12 @@ protected IEnvironment GetEnv(string file)
}

if(!solutions.ContainsKey(file)) {
solutions[file] = new Sln(file, SlnItems.EnvWithProjects);
solutions[file] = new Sln(file, SlnItems.EnvWithMinimalProjects);
}
return solutions[file].Result.Env;
}

private void Free()
protected void Free()
{
if(solutions == null) {
return;
Expand All @@ -159,7 +177,7 @@ public void Dispose()
Dispose(true);
}

private void Dispose(bool disposing)
protected virtual void Dispose(bool disposing)
{
if(disposed) {
return;
Expand Down
49 changes: 49 additions & 0 deletions Wizard/Extensions/CollectionExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 Denis Kuzmin < entry.reg@gmail.com > :: github.com/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.
*/

using System;
using System.Collections.Generic;

namespace net.r_eg.DllExport.Wizard.Extensions
{
public 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 void ForEach<T>(this IEnumerable<T> items, Action<T> act)
{
if(items == null) {
return;
}

foreach(var item in items) {
act(item);
}
}
}
}
74 changes: 74 additions & 0 deletions Wizard/Extensions/StringExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 Denis Kuzmin < entry.reg@gmail.com > :: github.com/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.
*/

using System;

namespace net.r_eg.DllExport.Wizard.Extensions
{
public static class StringExtension
{
/// <summary>
/// To get boolean value from string.
/// </summary>
/// <param name="value">Any compatible value.</param>
/// <returns></returns>
public static bool ToBoolean(this string value)
{
if(String.IsNullOrWhiteSpace(value)) {
return false;
}

switch(value.Trim())
{
case "1":
case "True":
case "TRUE":
case "true": {
return true;
}
case "0":
case "False":
case "FALSE":
case "false": {
return false;
}
}
throw new ArgumentException($"Incorrect boolean value - '{value}'");
}

/// <summary>
/// To get integer value from string.
/// </summary>
/// <param name="value">Any compatible value.</param>
/// <returns></returns>
public static int ToInteger(this string value)
{
if(String.IsNullOrWhiteSpace(value)) {
return 0;
}

return Int32.Parse(value);
}
}
}
Loading

0 comments on commit 536bfbc

Please sign in to comment.