Skip to content

Commit

Permalink
Merge pull request #1 from XanatosX/refactor/refactor-the-whole-code
Browse files Browse the repository at this point in the history
Refactor/refactor the whole code
  • Loading branch information
XanatosX authored Apr 13, 2018
2 parents 1c58d2b + 0903166 commit 36a66ac
Show file tree
Hide file tree
Showing 16 changed files with 339 additions and 343 deletions.
73 changes: 12 additions & 61 deletions ModularToolManger/DefaultTools/CommandLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,78 +15,27 @@ public class Commandline : IFunction
{
public bool Active { get; set; }

public string Author
{
get
{
return "Simon Aberle";
}
}
public string Author => "Simon Aberle";

private PluginContext _context;
public PluginContext context
{
get
{
return _context;
}
}
public PluginContext context => _context;

public string Description
{
get
{
return "Create a function performed by the commandline in Windows";
}
}
public string Description => "Create a function performed by the commandline in Windows";

public string DisplayName
{
get
{
return "Windows commandline";
}
}
public string DisplayName => "Windows commandline";

private Dictionary<string, string> _fileEndings;
public Dictionary<string,string> FileEndings
{
get
{
return _fileEndings;
}
}
public Dictionary<string, string> FileEndings => _fileEndings;

private bool _initialized;
public bool initialized
{
get
{
return _initialized;
}
}
public bool initialized => _initialized;

public string UniqueName
{
get
{
return "WindowsCommandLine";
}
}
public string UniqueName => "WindowsCommandLine";

public Version Version
{
get
{
return new Version(1, 0, 0, 0);
}
}
public Version Version => new Version(1, 0, 0, 0);

private Module _comModule;
public Module ComModule
{
get => _comModule;
}
public Module ComModule => _comModule;

PluginSettings _settings;
PluginSettings ISettingPlugin.Settings => _settings;
Expand Down Expand Up @@ -121,8 +70,10 @@ public bool Load()
public bool PerformeAction(PluginContext context)
{
if (context.GetType() != typeof(FunctionContext))
{
return false;

}

FunctionContext CurrentContext = (FunctionContext)context;
Process process = new Process();

Expand Down
73 changes: 10 additions & 63 deletions ModularToolManger/DefaultTools/LinkOpener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,78 +15,27 @@ public class Shortcut : IFunction
{
public bool Active { get; set; }

public string Author
{
get
{
return "Simon Aberle";
}
}
public string Author => "Simon Aberle";

private PluginContext _context;
public PluginContext context
{
get
{
return _context;
}
}
public PluginContext context => _context;

public string Description
{
get
{
return "Open a windows shortcut";
}
}
public string Description => "Open a windows shortcut";

public string DisplayName
{
get
{
return "Windows shortcut";
}
}
public string DisplayName => "Windows shortcut";

private Dictionary<string, string> _fileEndings;
public Dictionary<string,string> FileEndings
{
get
{
return _fileEndings;
}
}
public Dictionary<string, string> FileEndings => _fileEndings;

private bool _initialized;
public bool initialized
{
get
{
return _initialized;
}
}
public bool initialized => _initialized;

public string UniqueName
{
get
{
return "Shortcut";
}
}
public string UniqueName => "Shortcut";

public Version Version
{
get
{
return new Version(1, 0, 0, 0);
}
}
public Version Version => new Version(1, 0, 0, 0);

private Module _comModule;
public Module ComModule
{
get => _comModule;
}
public Module ComModule => _comModule;


PluginSettings _settings;
Expand Down Expand Up @@ -123,7 +72,7 @@ public bool PerformeAction(PluginContext context)
return false;

FunctionContext CurrentContext = (FunctionContext)context;
Process process = new Process(); ;
Process process = new Process();
process.StartInfo.FileName = CurrentContext.FilePath;
process.StartInfo.WorkingDirectory = (new FileInfo(CurrentContext.FilePath)).DirectoryName;
try
Expand All @@ -134,8 +83,6 @@ public bool PerformeAction(PluginContext context)
{
_comModule.SendMessage("log", ex.Message);
}



return true;
}
Expand Down
15 changes: 12 additions & 3 deletions ModularToolManger/JSONSettings/JSON/SettingJSON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,27 @@ public SettingJSON()
public bool AddNew(string Name)
{
if (Contained(Name))
{
return false;
}
nodes.Add(new SettingsNode(Name));
return true;
}

public bool AddValue(string Name, string Key, object Value)
{
SettingsNode node = getNode(Name);
SettingsNode node = GetNode(Name);
if (node == null)
{
return false;
}
node.AddOrChangeKeyValue(Key, Value);
return true;
}

public string GetValue(string Name, string Key, out SettingsType type)
{
SettingsNode node = getNode(Name);
SettingsNode node = GetNode(Name);
if (node == null)
{
type = SettingsType.Error;
Expand All @@ -44,12 +48,14 @@ public string GetValue(string Name, string Key, out SettingsType type)

return Value;
}
private SettingsNode getNode(string Name)
private SettingsNode GetNode(string Name)
{
foreach (SettingsNode node in nodes)
{
if (node.Name == Name)
{
return node;
}
}
return null;
}
Expand All @@ -59,7 +65,10 @@ private bool Contained(string name)
foreach (SettingsNode node in nodes)
{
if (node.Name == name)
{
return true;
}

}
return false;
}
Expand Down
35 changes: 15 additions & 20 deletions ModularToolManger/JSONSettings/JSON/SettingsNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,24 @@ namespace JSONSettings
{
public class SettingsNode
{
public string Name;
public List<KeyValue> Settings;
readonly string _name;
public string Name => _name;

readonly List<KeyValue> _settings;
public List<KeyValue> Settings => _settings;

public SettingsNode()
{
init();
_settings = new List<KeyValue>();
}

public SettingsNode(string name)
{
init();
Name = name;
}

private void init()
{
Settings = new List<KeyValue>();
_settings = new List<KeyValue>();
_name = name;
}

private bool AddKeyValue(string key, object Value, SettingsType valueType = SettingsType.String)
private void AddKeyValue(string key, object Value, SettingsType valueType = SettingsType.String)
{
if (KeyContained(key))
{
Expand All @@ -42,19 +40,18 @@ private bool AddKeyValue(string key, object Value, SettingsType valueType = Sett
}
else
{
Settings.Add(new KeyValue()
Settings.Add(new KeyValue
{
Key = key,
Value = Value.ToString(),
ValueType = valueType,
});
}

return true;
}

public bool AddOrChangeKeyValue(string key, object Value)
{
SettingsType type = SettingsType.String;
SettingsType type;
TypeCode code = Type.GetTypeCode(Value.GetType());
switch (code)
{
Expand All @@ -69,6 +66,7 @@ public bool AddOrChangeKeyValue(string key, object Value)
type = SettingsType.Float;
break;
default:
type = SettingsType.String;
break;
}
if (type != SettingsType.Error)
Expand Down Expand Up @@ -105,14 +103,11 @@ private bool KeyContained(string key)
foreach (KeyValue pair in Settings)
{
if (pair.Key == key)
{
return true;
}
}
return false;
}

internal void GetValue(string Name)
{

}
}
}
Loading

0 comments on commit 36a66ac

Please sign in to comment.