Skip to content
Merged
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
15 changes: 7 additions & 8 deletions vsSolutionBuildEvent/API/EventLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,13 @@ protected void refreshComponents()

var data = AppSettings.CfgManager.Config.Data;

foreach(IComponent c in loader.Soba.Registered) {
if(data.Components == null || data.Components.Length < 1) {
//c.Enabled = true;
continue;
}

var found = data.Components.Where(p => p.ClassName == c.GetType().Name).FirstOrDefault();
if(found == null) {
foreach(IComponent c in loader.Soba.Registered)
{
var found = data.Components?.FirstOrDefault(p => p.ClassName == c.GetType().Name);
if(found == null)
{
// Each component provides its default state for IComponent.Enabled
// We'll just continue 'as is' if this component is not presented in config.
continue;
}

Expand Down
83 changes: 35 additions & 48 deletions vsSolutionBuildEvent/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using net.r_eg.MvsSln.Extensions;
using net.r_eg.vsSBE.Configuration;
using net.r_eg.vsSBE.Exceptions;
using SysVersion = System.Version;

namespace net.r_eg.vsSBE
{
Expand All @@ -41,7 +42,7 @@ public struct Entity
/// Config version.
/// Version of app managed by Package!
/// </summary>
public static readonly System.Version Version = new System.Version(0, 9);
public static readonly SysVersion Version = new SysVersion(0, 12, 4);

/// <summary>
/// To file system
Expand Down Expand Up @@ -144,84 +145,70 @@ public void unload()
protected virtual bool loadByLink(string link)
{
InRAM = false;
Log.Debug("Configuration: trying to load - '{0}'", link);
var newCfg = new SolutionEvents();

try
{
using(StreamReader stream = new StreamReader(link, Encoding.UTF8, true))
{
Data = deserialize(stream);
if(Data == null) {
throw new UnspecSBEException("file is empty");
}
compatibility(stream);
}
Log.Info("Loaded settings (v{0}): '{1}'", Data.Header.Compatibility, Settings.WPath);
Data = loadJsonConfig(link);
warnAboutJsonConfig(SysVersion.Parse(Data.Header.Compatibility));
}
catch(FileNotFoundException)
{
Data = new SolutionEvents();
Data = newCfg;
InRAM = true;
Log.Info("Initialized with new settings.");
}
catch(Newtonsoft.Json.JsonException ex)
{
Data = _xmlTryUpgrade(link, ex);
warnAboutXmlConfig();
Log.Error($"Incorrect configuration data: {ex.Message}");
Data = newCfg; //xml -> json 0.8-0.9
}
catch(Exception ex)
{
Log.Error("Configuration file is corrupt - '{0}'", ex.Message);
Data = new SolutionEvents(); //TODO: actions in UI, e.g.: restore, new..
Log.Error($"Configuration file `{link}` is corrupted: {ex.Message}");
Data = newCfg; //TODO: actions in UI, e.g.: restore, new..
InRAM = true;
}

// Now we work with latest version
// Now we'll work with latest version
Data.Header.Compatibility = Entity.Version.ToString();
Updated(this, new DataArgs<ISolutionEvents>() { Data = Data });

return !InRAM;
}

/// <summary>
/// Checks version and reorganizes structure if needed..
/// </summary>
/// <param name="stream"></param>
private void compatibility(StreamReader stream)
private SolutionEvents loadJsonConfig(string link)
{
System.Version cfg = System.Version.Parse(Data.Header.Compatibility);
using(StreamReader stream = new StreamReader(link, Encoding.UTF8, true))
{
var ret = deserialize(stream);
if(ret == null) {
throw new UnspecSBEException("file is empty");
}

if(cfg.Major > Entity.Version.Major || (cfg.Major == Entity.Version.Major && cfg.Minor > Entity.Version.Minor)) {
Log.Warn(
"Version {0} of configuration file is higher supported version {1}. Please update application. Several settings may be not correctly loaded.",
cfg.ToString(2), Entity.Version.ToString(2)
);
Log.Info($"Loaded settings (v{ ret.Header.Compatibility}): '{Settings.WPath}'");
return ret;
}
}

if(cfg.Major == 0 && cfg.Minor < 4)
private void warnAboutJsonConfig(SysVersion cfgVer)
{
if(cfgVer > Entity.Version)
{
Log._.show();
Log.Info("Upgrading configuration for <= v0.3.x");
//Upgrade.Migration03_04.migrate(stream);
Log.Warn("[Obsolete] Not supported. Use of any v0.4.x - v0.8.x for upgrading <= v0.3.x");
Log.Warn(
$"Configuration file v{cfgVer} is higher than supported v{Entity.Version}. Update app for best known behavior."
);
return;
}
}

/// <summary>
/// Upgrades from xml.
/// </summary>
/// <param name="file">Configuration file</param>
/// <param name="inner"></param>
/// <returns></returns>
private ISolutionEvents _xmlTryUpgrade(string file, Newtonsoft.Json.JsonException inner)
private void warnAboutXmlConfig()
{
try {
ISolutionEvents ret = Upgrade.v08.Migration08_09.migrate(file);
Log.Info("Successfully upgraded settings. *Save manually! :: -> {0}", Entity.NAME);
return ret;
}
catch(Exception ex) {
Log.Error("Incorrect configuration data: '{0}' -> '{1}'. Initialize new.", inner.Message, ex.Message);
}
return new SolutionEvents();
const string _MSG = "Please use any version from `{0}` for auto-upgrading configuration `{1}`.";

Log.Warn(_MSG, "0.4.x - 0.8.x", "<= v0.3");
Log.Warn(_MSG, "0.9.x - 1.14.0", "<= v0.8");
}
}
}
21 changes: 4 additions & 17 deletions vsSolutionBuildEvent/Configuration/Header.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,12 @@ namespace net.r_eg.vsSBE.Configuration
{
public class Header
{
public string[] _ = new string[]
public string[] _ => new string[]
{
" This requires vsSolutionBuildEvent engine.",
" Free plugin for Visual Studio or MSBuild Tools:",
" * https://github.com/3F/vsSolutionBuildEvent"
" This file for vsSolutionBuildEvent ",
" https://github.com/3F/vsSolutionBuildEvent "
};

/// <summary>
/// Compatibility of configurations.
/// </summary>
public string Compatibility
{
get { return compatibility; }
set { compatibility = value; }
}
/// <summary>
/// The version below used by default if current attr is not found.
/// </summary>
private string compatibility = "0.1";

public string Compatibility { get; set; } = "0.1";
}
}
33 changes: 4 additions & 29 deletions vsSolutionBuildEvent/Configuration/User/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,11 @@ namespace net.r_eg.vsSBE.Configuration.User
{
public class Global: IGlobal
{
/// <summary>
/// Debug mode for application.
/// </summary>
public bool DebugMode
{
get;
set;
}
/// <inheritdoc cref="IGlobal.DebugMode"/>
public bool DebugMode { get; set; }

/// <summary>
/// Suppress the 'Command__' property for main configuration if true.
///
/// This property is temporary and used for compatibility with format v0.9 of conf. file.
/// However, this can be inconvenient and while we can't upgrade format, we should also provide a some option to turn off one field at least.
/// </summary>
public bool SuppressDualCommand
{
get;
set;
}

/// <summary>
/// List of levels for disabling from logger.
/// </summary>
/// <inheritdoc cref="IGlobal.LogIgnoreLevels"/>
//[JsonProperty(TypeNameHandling = TypeNameHandling.None, ItemTypeNameHandling = TypeNameHandling.All)]
public Dictionary<string, bool> LogIgnoreLevels
{
get { return logIgnoreLevels; }
set { logIgnoreLevels = value; }
}
private Dictionary<string, bool> logIgnoreLevels = new Dictionary<string, bool>();
public Dictionary<string, bool> LogIgnoreLevels { get; set; } = new Dictionary<string, bool>();
}
}
8 changes: 0 additions & 8 deletions vsSolutionBuildEvent/Configuration/User/IGlobal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ public interface IGlobal
/// </summary>
bool DebugMode { get; set; }

/// <summary>
/// Suppress the 'Command__' property for main configuration if true.
///
/// This property is temporary and used for compatibility with format v0.9 of conf. file.
/// However, this can be inconvenient and while we can't upgrade format, we should also provide a some option to turn off one field at least.
/// </summary>
bool SuppressDualCommand { get; set; }

/// <summary>
/// List of levels for disabling from logger.
/// </summary>
Expand Down
11 changes: 2 additions & 9 deletions vsSolutionBuildEvent/Events/CommandEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@ namespace net.r_eg.vsSBE.Events
/// </summary>
public class CommandEvent: SBEEvent, ISolutionEvent, ICommandEvent
{
/// <summary>
/// Conditions of work Commands
/// </summary>
/// <inheritdoc cref="ICommandEvent.Filters"/>
[JsonProperty(TypeNameHandling = TypeNameHandling.All)]
public IFilter[] Filters
{
get { return filters; }
set { filters = value; }
}
private IFilter[] filters;
public IFilter[] Filters { get; set; }
}
}
56 changes: 32 additions & 24 deletions vsSolutionBuildEvent/Events/EventProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,46 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using net.r_eg.MvsSln.Extensions;

namespace net.r_eg.vsSBE.Events
{
public class EventProcess: IEventProcess
{
/// <summary>
/// Waiting completion
/// </summary>
public bool Waiting
{
get { return waiting; }
set { waiting = value; }
}
private bool waiting = true;
/// <inheritdoc cref="IEventProcess.Waiting"/>
public bool Waiting { get; set; } = true;

/// <inheritdoc cref="IEventProcess.Hidden"/>
public bool Hidden { get; set; } = true;

/// <inheritdoc cref="IEventProcess.TimeLimit"/>
public int TimeLimit { get; set; } = 30;

/// <summary>
/// Hiding of processing or not
/// </summary>
public bool Hidden
public static bool operator ==(EventProcess a, EventProcess b) => a.Equals(b);

public static bool operator !=(EventProcess a, EventProcess b) => !(a == b);

public override bool Equals(object obj)
{
get { return hidden; }
set { hidden = value; }
if(obj is null || !(obj is EventProcess)) {
return false;
}

var b = (EventProcess)obj;

return Waiting == b.Waiting
&& Hidden == b.Hidden
&& TimeLimit == b.TimeLimit;
}
private bool hidden = true;

/// <summary>
/// How long to wait the execution, in seconds. 0 value - infinitely
/// </summary>
public int TimeLimit
public override int GetHashCode()
{
get { return timeLimit; }
set { timeLimit = value; }
return 0.CalculateHashCode
(
Waiting,
Hidden,
TimeLimit
);
}
private int timeLimit = 30;
}
}
}
17 changes: 6 additions & 11 deletions vsSolutionBuildEvent/Events/Mapping/Json/ModeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public abstract class ModeCommand: ICommand
/// And, how about all as a ICommandArray ? this used with ModeOperation for example.
/// </summary>
[Browsable(false)]
[JsonIgnore] // "Command" removed after 1.14.0. Minimal 0.12.4
public string Command
{
get {
return command;
}
set {
get => command;
set
{
if(value != null) {
_command = value.Replace("\r\n", "\n").Split('\n');
}
Expand All @@ -59,14 +59,9 @@ public string Command
[JsonProperty(PropertyName = "Command__")]
protected string[] _Command
{
get
get => _command;
set
{
if(Settings.CfgUser != null && Settings.CfgUser.Global.SuppressDualCommand) {
return null;
}
return _command;
}
set {
if(value != null) {
command = String.Join("\n", value);
}
Expand Down
Loading