Skip to content

Commit

Permalink
code-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
thewhobox committed Sep 10, 2024
1 parent 62bd8f5 commit 2d6c398
Show file tree
Hide file tree
Showing 20 changed files with 25 additions and 59 deletions.
13 changes: 4 additions & 9 deletions Kaenx.Creator/Classes/CheckHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@


namespace Kaenx.Creator.Classes {

public class CheckHelper
{
public static void CheckThis(MainModel General, ObservableCollection<PublishAction> actions, bool showOnlyErrors = false)
Expand Down Expand Up @@ -185,7 +184,6 @@ public static void CheckVersion(

if(penum.UseIcon && penum.IconObject == null)
actions.Add(new PublishAction() { Text = "\t" + string.Format(Properties.Messages.check_ver_parat_enum_icon, penum.Name, ptype.Name, ptype.UId), State = PublishState.Fail, Item = ptype });

}
break;

Expand Down Expand Up @@ -491,7 +489,6 @@ private static void CheckVersion(AppVersion ver, IVersionBase vbase, ObservableC
else {
if(!(para.SaveObject as Memory).IsAutoPara && para.Offset == -1) actions.Add(new PublishAction() { Text = "\t" + string.Format(Properties.Messages.check_ver_para_save_offset, para.Name, para.UId), State = PublishState.Fail, Item = para, Module = mod });
if(!(para.SaveObject as Memory).IsAutoPara && para.OffsetBit == -1) actions.Add(new PublishAction() { Text = "\t" + string.Format(Properties.Messages.check_ver_para_save_offsetbit, para.Name, para.UId), State = PublishState.Fail, Item = para, Module = mod });

}
if(para.OffsetBit > 7) actions.Add(new PublishAction() { Text = "\t" + string.Format(Properties.Messages.check_ver_para_save_obsolet, para.Name, para.UId), State = PublishState.Fail, Item = para, Module = mod });
break;
Expand Down Expand Up @@ -526,10 +523,8 @@ private static void CheckVersion(AppVersion ver, IVersionBase vbase, ObservableC
if(para.OverwriteSuffix)
CheckSuffix(para, showOnlyErrors, defaultLang, mod, actions);
}

}



var x = vbase.ComObjects.GroupBy((c) => c.Number);
if(x.Any((c) => c.Count() > 1))
{
Expand Down Expand Up @@ -754,11 +749,11 @@ private static void CheckValue(object item, object mod, ObservableCollection<Pub
{
//TODO implement check
if(type.Increment == "PackedSecondsAndMilliseconds") {

//TODO
} else if(type.Increment == "PackedDaysHoursMinutesAndSeconds") {

//TODO
} else if(type.Increment == "PackedMinutesSecondsAndMilliseconds") {

//TODO
} else {
long paraval;
if(!long.TryParse(value, out paraval))
Expand Down
27 changes: 12 additions & 15 deletions Kaenx.Creator/Classes/ImportHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void StartXml(MainModel general, ObservableCollection<DataPointType>dpts)
var res = System.Windows.MessageBox.Show($"Hersteller der Produktdatenbank stimmt nicht mit dem Hersteller des Projekts über ein.\r\nWollen Sie ihre HerstellerId von {_general.ManufacturerId:X4} auf {manuId:X4} ändern?", "Question", System.Windows.MessageBoxButton.YesNoCancel, System.Windows.MessageBoxImage.Warning);
switch(res) {
case System.Windows.MessageBoxResult.Yes:
_general.ManufacturerId = manuId;;
_general.ManufacturerId = manuId;
break;
case System.Windows.MessageBoxResult.Cancel:
return;
Expand All @@ -104,7 +104,6 @@ public void StartXml(MainModel general, ObservableCollection<DataPointType>dpts)

xtemp = xmanu.Element(Get("Catalog"));
ImportCatalog(xtemp);

}

public void StartZip(MainModel general, ObservableCollection<DataPointType> dpts)
Expand All @@ -124,7 +123,7 @@ public void StartZip(MainModel general, ObservableCollection<DataPointType> dpts
var res = System.Windows.MessageBox.Show($"Hersteller der Produktdatenbank stimmt nicht mit dem Hersteller des Projekts über ein.\r\nWollen Sie ihre HerstellerId von {_general.ManufacturerId:X4} auf {manuId:X4} ändern?", "Question", System.Windows.MessageBoxButton.YesNoCancel, System.Windows.MessageBoxImage.Warning);
switch(res) {
case System.Windows.MessageBoxResult.Yes:
_general.ManufacturerId = manuId;;
_general.ManufacturerId = manuId;
break;
case System.Windows.MessageBoxResult.Cancel:
Archive.Dispose();
Expand Down Expand Up @@ -339,7 +338,7 @@ private void ImportIcons(string path)
Icon icon = new Icon()
{
UId = Kaenx.Creator.Classes.Helper.GetNextFreeUId(_general.Icons),
Name = entry.Name.Substring(0, entry.Name.LastIndexOf("."))
Name = entry.Name.Substring(0, entry.Name.LastIndexOf('.'))
};

using(Stream s = entry.Open())
Expand Down Expand Up @@ -582,7 +581,6 @@ private void DynamicRenameRefIds(bool renameParas, bool renameComs, XElement xst
foreach(XElement xele in xstatic.Parent.Parent.Parent.Element(Get("Languages")).Descendants(Get("TranslationElement")))
if(newIds.ContainsKey(xele.Attribute("RefId").Value))
xele.Attribute("RefId").Value = "P-x_R-" + newIds[xele.Attribute("RefId").Value];

}

counter = 1;
Expand Down Expand Up @@ -864,7 +862,6 @@ public void ImportParameterTypes(XElement xparatypes, AppVersion vers, bool remo
ptype.SizeInBit = int.Parse(xsub.Attribute("SizeInBit").Value);
foreach (XElement xenum in xsub.Elements())
{

ParameterTypeEnum penum = new ParameterTypeEnum()
{
Name = xenum.Attribute("Text")?.Value ?? "",
Expand Down Expand Up @@ -1021,7 +1018,7 @@ private void ParseParameter(XElement xpara, IVersionBase vbase, Union union = nu
IsUnionDefault = xpara.Attribute("DefaultUnionParameter")?.Value == "true"
};
string id = GetLastSplit(xpara.Attribute("Id").Value, 2);
if (id.StartsWith("-"))
if (id.StartsWith('-'))
id = id.Substring(1);
para.Id = int.Parse(id);

Expand Down Expand Up @@ -1123,7 +1120,7 @@ public void ImportParameterRefs(XElement xrefs, IVersionBase vbase)
_ => throw new Exception("Unbekannter Access Typ für ParameterRef: " + xref.Attribute("Access")?.Value)
};
string id = GetLastSplit(xref.Attribute("RefId").Value, 2);
if (id.StartsWith("-"))
if (id.StartsWith('-'))
id = id.Substring(1);
long paraId = long.Parse(id);
if(Paras.ContainsKey(paraId))
Expand Down Expand Up @@ -1164,7 +1161,7 @@ public void ImportComObjects(XElement xcoms, IVersionBase vbase, ref Dictionary<
int firstId = -1;
foreach(XElement xref in xcoms.Elements())
{
string[] id = xref.Attribute("Id").Value.Split("-");
string[] id = xref.Attribute("Id").Value.Split('-');
int currId = int.Parse(id[id.Length - 2]);
if(firstId == -1)
{
Expand Down Expand Up @@ -1198,7 +1195,7 @@ public void ImportComObjects(XElement xcoms, IVersionBase vbase, ref Dictionary<
idmapper.Add(xcom.Attribute("Id").Value, com.Id);
} else {
string id = xcom.Attribute("Id").Value;
id = id.Substring(id.LastIndexOf("-") + 1);
id = id.Substring(id.LastIndexOf('-') + 1);
com.Id = long.Parse(id);
}

Expand Down Expand Up @@ -1232,7 +1229,7 @@ public void ImportComObjects(XElement xcoms, IVersionBase vbase, ref Dictionary<
com.HasDpt = true;
if (type.StartsWith("DPST-"))
{
string[] xtype = type.Split("-");
string[] xtype = type.Split('-');
com.Type = DPTs.Single(d => d.Number == xtype[1]);
com.HasDpts = com.Type.SubTypes.Any(s => s.Number == xtype[2]);
if(com.HasDpts)
Expand All @@ -1244,7 +1241,7 @@ public void ImportComObjects(XElement xcoms, IVersionBase vbase, ref Dictionary<
}
else if (type.StartsWith("DPT-"))
{
string[] xtype = type.Split("-");
string[] xtype = type.Split('-');
com.HasDpts = false;
com.Type = DPTs.Single(d => d.Number == xtype[1]);
}
Expand Down Expand Up @@ -1300,7 +1297,7 @@ public void ImportComObjectRefs(XElement xrefs, IVersionBase vbase, Dictionary<s
cref.ComObjectObject = Coms[refId];
} else {
string id = xref.Attribute("RefId").Value;
id = id.Substring(id.LastIndexOf("-") + 1);
id = id.Substring(id.LastIndexOf('-') + 1);
long comId = long.Parse(id);
cref.ComObjectObject = Coms[comId];
}
Expand Down Expand Up @@ -1571,8 +1568,8 @@ private void ImportHardware(XElement xhards) {

string def = xprod.Attribute("DefaultLanguage").Value;

if(!def.Contains("-")){
def = _langTexts.Keys.First(l => l.StartsWith(def + "-"));
if(!def.Contains('-')){
def = _langTexts.Keys.First(l => l.StartsWith(def + '-'));
}

if(!_general.Languages.Any(l => l.CultureCode == def))
Expand Down
5 changes: 0 additions & 5 deletions Kaenx.Creator/Controls/BaggageView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ private void ClickExport(object sender, System.Windows.RoutedEventArgs e)
}
}

private void Failed(object sender, System.Windows.ExceptionRoutedEventArgs e)
{

}

public event PropertyChangedEventHandler PropertyChanged;
private void Changed(string name)
{
Expand Down
1 change: 0 additions & 1 deletion Kaenx.Creator/Controls/CheckView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ private void ClickDoClean(object sender, RoutedEventArgs e)
System.Diagnostics.Debug.WriteLine("Summe: " + sum);
ClearHelper.RemoveUnusedElements(Version);
} while(sum > 0);

} else if(msgRes == MessageBoxResult.No) {
res = ClearHelper.ShowUnusedElements(Version);
countParameterTypes = res.ParameterTypes;
Expand Down
2 changes: 1 addition & 1 deletion Kaenx.Creator/Controls/DynamicView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private void ClickEditButtonFunction(object sender, RoutedEventArgs e)
if(line.Trim().StartsWith("function"))
{
string temp = line.Trim();
string declaration = "\"declare " + temp.Substring(0, temp.IndexOf(")")+1) + ";\",";
string declaration = "\"declare " + temp.Substring(0, temp.IndexOf(')')+1) + ";\",";
definitions.AppendLine(declaration);
}
}
Expand Down
3 changes: 1 addition & 2 deletions Kaenx.Creator/Controls/IconView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private void ClickImport(object sender, System.Windows.RoutedEventArgs e)
Icon icon = new Icon()
{
UId = Kaenx.Creator.Classes.Helper.GetNextFreeUId(General.Icons),
Name = entry.Name.Substring(0, entry.Name.LastIndexOf("."))
Name = entry.Name.Substring(0, entry.Name.LastIndexOf('.'))
};

using(Stream s = entry.Open())
Expand Down Expand Up @@ -235,7 +235,6 @@ private void ClickExport(object sender, System.Windows.RoutedEventArgs e)
}
}
}

}
}

Expand Down
1 change: 0 additions & 1 deletion Kaenx.Creator/Controls/ListDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace Kaenx.Creator.Controls
{
public partial class ListDialog : Window
{

public ListDialog(string question, string title, List<string> items)
{
InitializeComponent();
Expand Down
3 changes: 0 additions & 3 deletions Kaenx.Creator/Controls/ModuleView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ private void ResetId(object sender, RoutedEventArgs e)
//((sender as Button).DataContext as Models.Message).Id = -1;
}


private void ClickAddModule(object sender, RoutedEventArgs e)
{
Models.Module mod = new Models.Module() { UId = Kaenx.Creator.Classes.Helper.GetNextFreeUId(CurrentModule.Modules)};
Expand Down Expand Up @@ -195,7 +194,6 @@ private void ClickDoClean(object sender, RoutedEventArgs e)
System.Diagnostics.Debug.WriteLine("Summe: " + sum);
ClearHelper.RemoveUnusedElements(model);
} while(sum > 0);

} else if(msgRes == MessageBoxResult.No) {
res = ClearHelper.ShowUnusedElements(model);
countParameterTypes = res.ParameterTypes;
Expand All @@ -219,7 +217,6 @@ private void ClickDoClean(object sender, RoutedEventArgs e)
MessageBox.Show(msg);
}


public event PropertyChangedEventHandler PropertyChanged;
private void Changed(string name)
{
Expand Down
1 change: 0 additions & 1 deletion Kaenx.Creator/Controls/OpenKnxView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,6 @@ private XElement ChangeFile(XElement xroot, OpenKnxModule mod)
Regex regex2 = new Regex("%[C]+%");
xblock.Attribute("Text").Value = regex2.Replace(xblock.Attribute("Text").Value, "{{argChan}}");
}

}
counter = 1;
foreach(XElement xblock in xroot.Descendants(XName.Get("ParameterSeparator", xroot.Name.NamespaceName)))
Expand Down
1 change: 0 additions & 1 deletion Kaenx.Creator/Controls/ParameterRefView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ protected virtual void OnModuleChanged(DependencyPropertyChangedEventArgs e)
{
_filter.ChangeView((e.NewValue as IVersionBase).ParameterRefs);
}

}

private void ClickAdd(object sender, RoutedEventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion Kaenx.Creator/Controls/ParameterView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private static void OnModuleChangedCallback(DependencyObject sender, DependencyP
}

protected virtual void OnVersionChanged() {

//nothing to do
}

protected virtual void OnModuleChanged(DependencyPropertyChangedEventArgs e) {
Expand Down
1 change: 0 additions & 1 deletion Kaenx.Creator/Controls/UnionView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ private void CurrentCellChanged(object sender, EventArgs e)
{
DataGridCellInfo cell = (sender as DataGrid).CurrentCell;
Models.MemorySection sec = cell.Item as Models.MemorySection;

}

public event PropertyChangedEventHandler PropertyChanged;
Expand Down
1 change: 0 additions & 1 deletion Kaenx.Creator/Converter/BinaryToBool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace Kaenx.Creator.Converter
{
public class BinaryToBool : IValueConverter
{

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value.ToString() == "1";
Expand Down
1 change: 0 additions & 1 deletion Kaenx.Creator/Converter/BoolNegation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace Kaenx.Creator.Converter
{
public class BoolNegation : IValueConverter
{

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (value as bool?) != true;
Expand Down
1 change: 0 additions & 1 deletion Kaenx.Creator/Converter/IntToHex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace Kaenx.Creator.Converter
{
public class IntToHex : IValueConverter
{

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string length = parameter != null ? parameter.ToString() : "2";
Expand Down
10 changes: 5 additions & 5 deletions Kaenx.Creator/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ private void ClickNew(object sender, RoutedEventArgs e)
General = new Models.MainModel() { ImportVersion = Kaenx.Creator.Classes.Helper.CurrentVersion, Guid = Guid.NewGuid().ToString() };
var currentLang = System.Threading.Thread.CurrentThread.CurrentUICulture.IetfLanguageTag;
if(!ImportHelper._langTexts.ContainsKey(currentLang))
if(currentLang.Contains("-"))
currentLang = currentLang.Split("-")[0];
if(currentLang.Contains('-'))
currentLang = currentLang.Split('-')[0];

if(!currentLang.Contains("-"))
if(!currentLang.Contains('-'))
{
currentLang = ImportHelper._langTexts.Keys.FirstOrDefault(l => l.Split("-")[0] == currentLang);
currentLang = ImportHelper._langTexts.Keys.FirstOrDefault(l => l.Split('-')[0] == currentLang);
if(string.IsNullOrEmpty(currentLang)) currentLang = "en-US";
}
General.Languages.Add(new Models.Language(System.Threading.Thread.CurrentThread.CurrentUICulture.DisplayName, currentLang));
Expand Down Expand Up @@ -897,7 +897,7 @@ private async void Button_Click(object sender, RoutedEventArgs e)
#if DEBUG
fileFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Output");
#else
fileFolder = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
fileFolder = Path.GetDirectoryName(Environment.ProcessPath);
#endif
break;

Expand Down
1 change: 0 additions & 1 deletion Kaenx.Creator/Models/CompletionData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using ICSharpCode.AvalonEdit.Editing;

namespace Kaenx.Creator.Models {

public class CompletionData : ICompletionData
{
public CompletionData(string text, bool prop = true)
Expand Down
2 changes: 1 addition & 1 deletion Kaenx.Creator/Viewer/DeviceComObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class DeviceComObject : INotifyPropertyChanged
{
public DeviceComObject()
{

//nothing to do
}

public DeviceComObject(AppComObject comObj)
Expand Down
3 changes: 0 additions & 3 deletions Kaenx.Creator/Viewer/ImporterCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,9 @@ private void ImportParameterTypes()
if(!Baggages.Contains(ptype.BaggageObject))
Baggages.Add(ptype.BaggageObject);
break;

}

_context.AppParameterTypes.Add(mtype);


/*
-Text,
Expand Down Expand Up @@ -931,7 +929,6 @@ private void CopyDynamicItem(Models.Dynamic.IDynItems item, IVersionBase vbase)

default:
throw new Exception("Not implemented copy " + item.GetType().ToString());

}

if(item.Items == null) return;
Expand Down
5 changes: 0 additions & 5 deletions Kaenx.Creator/ViewerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,6 @@ private void Para_PropertyChanged(object sender, PropertyChangedEventArgs e = nu
System.Diagnostics.Debug.WriteLine("Sichtbarkeit geändert! " + para.Id + " -> " + para.IsVisible);
}

if(para.Id == 5618)
{

}

CalculateVisibilityParas(para);
CalculateVisibilityComs(para);
}
Expand Down

0 comments on commit 2d6c398

Please sign in to comment.