Implementing better localhost support and Id verification

This commit is contained in:
Fabian Stamm 2018-05-29 15:39:47 +02:00
parent 2748d3c1fe
commit 1b8a85cd94
1634 changed files with 1543926 additions and 63457 deletions

1
.gitignore vendored
View File

@ -0,0 +1 @@
backups

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -9,6 +9,10 @@
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" /> <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly> </dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="DocumentFormat.OpenXml" publicKeyToken="8fb06cb64d019a17" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.8.1.0" newVersion="2.8.1.0" />
</dependentAssembly>
</assemblyBinding> </assemblyBinding>
</runtime> </runtime>
</configuration> </configuration>

View File

@ -76,7 +76,7 @@ namespace BuechermarktClient
rowBook["Title"] = "Unbekannt"; rowBook["Title"] = "Unbekannt";
} }
rowBook["LabelId"] = book.LabelId; rowBook["LabelId"] = book.LabelId;
rowBook["Price"] = book.State == Models.BookState.BackToStudent ? (object)DBNull.Value : book.Price; rowBook["Price"] = book.State == Models.BookState.BackToStudent || book.State == Models.BookState.InStock ? (object)DBNull.Value : book.Price;
total += !rowBook.IsNull("Price") ? rowBook.Field<decimal>("Price") : 0m; total += !rowBook.IsNull("Price") ? rowBook.Field<decimal>("Price") : 0m;
tableBooks.Rows.Add(rowBook); tableBooks.Rows.Add(rowBook);
books++; books++;

View File

@ -9,6 +9,7 @@ using System.Windows.Data;
using System; using System;
using System.Globalization; using System.Globalization;
using System.Threading; using System.Threading;
using System.Text.RegularExpressions;
namespace BuechermarktClient namespace BuechermarktClient
{ {
@ -51,9 +52,9 @@ namespace BuechermarktClient
} }
set set
{ {
if(value != Book.LabelId) if(value.ToUpper() != Book.LabelId)
{ {
Book.LabelId = value; Book.LabelId = value.ToUpper();
OnPropertyChanged("LabelId"); OnPropertyChanged("LabelId");
} }
} }
@ -247,7 +248,16 @@ namespace BuechermarktClient
StateComboBox.ItemsSource = StatesList; StateComboBox.ItemsSource = StatesList;
} }
private Regex lableid_regex = new Regex("^[A-Z0-9 ]*$");
private void Save_Click(object sender, RoutedEventArgs e) private void Save_Click(object sender, RoutedEventArgs e)
{
if (!lableid_regex.IsMatch(Book.LabelId))
{
MessageBox.Show("Die ID stimmt nicht mit den Richtlinien überein!!!");
return;
}
else
{ {
if (New) if (New)
{ {
@ -264,7 +274,8 @@ namespace BuechermarktClient
Book.State = BookState.InStock; Book.State = BookState.InStock;
OnPropertyChanged(string.Empty); OnPropertyChanged(string.Empty);
return; return;
} catch (MongoExecutionTimeoutException) }
catch (MongoExecutionTimeoutException)
{ {
Thread.Sleep(100); Thread.Sleep(100);
} }
@ -284,13 +295,15 @@ namespace BuechermarktClient
.Set(b => b.LabelId, Book.LabelId)); .Set(b => b.LabelId, Book.LabelId));
Close(); Close();
return; return;
} catch (MongoExecutionTimeoutException) }
catch (MongoExecutionTimeoutException)
{ {
Thread.Sleep(100); Thread.Sleep(100);
} }
} }
} }
} }
}
private void Delete_Click(object sender, RoutedEventArgs e) private void Delete_Click(object sender, RoutedEventArgs e)
{ {

View File

@ -34,6 +34,9 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="DocumentFormat.OpenXml, Version=2.8.1.0, Culture=neutral, PublicKeyToken=8fb06cb64d019a17, processorArchitecture=MSIL">
<HintPath>..\packages\DocumentFormat.OpenXml.2.8.1\lib\net40\DocumentFormat.OpenXml.dll</HintPath>
</Reference>
<Reference Include="MongoDB.Bson, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="MongoDB.Bson, Version=2.4.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MongoDB.Bson.2.4.4\lib\net45\MongoDB.Bson.dll</HintPath> <HintPath>..\packages\MongoDB.Bson.2.4.4\lib\net45\MongoDB.Bson.dll</HintPath>
</Reference> </Reference>
@ -56,6 +59,7 @@
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath> <HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
</Reference> </Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
@ -172,9 +176,26 @@
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput> <LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None> </None>
<Content Include="MSOfficeUtils.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Vorlage.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include="libeay32.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="mongodump.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ssleay32.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@ -49,7 +49,9 @@ namespace BuechermarktClient
string message = Encoding.ASCII.GetString(bytes); string message = Encoding.ASCII.GetString(bytes);
if(message == ServerIdentifier) if(message == ServerIdentifier)
{ {
MainWindow.MongoHost = ip.Address.ToString(); var cip = ip.Address.ToString();
if (IsLocalIpAddress(cip)) cip = "127.0.0.1";
MainWindow.MongoHost = cip;
Dispatcher.BeginInvoke(new Action(delegate () { Dispatcher.BeginInvoke(new Action(delegate () {
Close(); Close();
})); }));
@ -60,5 +62,29 @@ namespace BuechermarktClient
ListenForServer(); ListenForServer();
} }
} }
private static bool IsLocalIpAddress(string host)
{
try
{ // get host IP addresses
IPAddress[] hostIPs = Dns.GetHostAddresses(host);
// get local IP addresses
IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
// test if any host IP equals to any local IP or to localhost
foreach (IPAddress hostIP in hostIPs)
{
// is localhost
if (IPAddress.IsLoopback(hostIP)) return true;
// is local address
foreach (IPAddress localIP in localIPs)
{
if (hostIP.Equals(localIP)) return true;
}
}
}
catch { }
return false;
}
} }
} }

Binary file not shown.

View File

@ -30,9 +30,6 @@ namespace BuechermarktClient
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
} }
private Dictionary<char, char> _Dictionary;
private Dictionary<char, char> _ReverseDictionary;
private string _AddField; private string _AddField;
public string AddField public string AddField
{ {
@ -43,9 +40,10 @@ namespace BuechermarktClient
set set
{ {
if(value != _AddField) string val = value.ToUpper();
if(val != _AddField)
{ {
_AddField = value; _AddField = val;
OnPropertyChanged("AddField"); OnPropertyChanged("AddField");
} }
} }
@ -107,51 +105,6 @@ namespace BuechermarktClient
DataContext = this; DataContext = this;
_SellBooks = new ObservableCollection<SellBook>(); _SellBooks = new ObservableCollection<SellBook>();
_SellBooks.CollectionChanged += listChanged; _SellBooks.CollectionChanged += listChanged;
_Dictionary = new Dictionary<char, char>();
_Dictionary.Add('a', 'A');
_Dictionary.Add('b', 'B');
_Dictionary.Add('c', 'C');
_Dictionary.Add('d', 'D');
_Dictionary.Add('e', 'E');
_Dictionary.Add('f', 'F');
_Dictionary.Add('g', 'G');
_Dictionary.Add('h', 'H');
_Dictionary.Add('i', 'I');
_Dictionary.Add('j', 'J');
_Dictionary.Add('k', 'K');
_Dictionary.Add('l', 'L');
_Dictionary.Add('m', 'M');
_Dictionary.Add('n', 'N');
_Dictionary.Add('o', 'O');
_Dictionary.Add('p', 'P');
_Dictionary.Add('q', 'Q');
_Dictionary.Add('r', 'R');
_Dictionary.Add('s', 'S');
_Dictionary.Add('t', 'T');
_Dictionary.Add('u', 'U');
_Dictionary.Add('v', 'V');
_Dictionary.Add('w', 'W');
_Dictionary.Add('x', 'X');
_Dictionary.Add('y', 'Y');
_Dictionary.Add('z', 'Z');
_Dictionary.Add('1', '!');
_Dictionary.Add('2', '"');
_Dictionary.Add('3', '§');
_Dictionary.Add('4', '$');
_Dictionary.Add('5', '%');
_Dictionary.Add('6', '&');
_Dictionary.Add('7', '/');
_Dictionary.Add('8', '(');
_Dictionary.Add('9', ')');
_Dictionary.Add('0', '=');
_Dictionary.Add('ß', '?');
_Dictionary.Add('-', '_');
_ReverseDictionary = new Dictionary<char, char>();
foreach(var entry in _Dictionary)
{
_ReverseDictionary.Add(entry.Value, entry.Key);
}
} }
private void Add_Click(object sender, RoutedEventArgs e) private void Add_Click(object sender, RoutedEventArgs e)
@ -160,19 +113,16 @@ namespace BuechermarktClient
{ {
try try
{ {
var reverse = ReverseString(AddField);
var case1 = ReverseUnderscore(AddField);
var case2 = ReverseUnderscore(reverse);
foreach (var s in SellBooks) foreach (var s in SellBooks)
{ {
if(s.LabelId == AddField || s.LabelId == reverse || s.LabelId == case1 ||s.LabelId == case2) if(s.LabelId == AddField)
{ {
MessageBox.Show("Das Buch ist bereits in der Liste"); MessageBox.Show("Das Buch ist bereits in der Liste");
return; return;
} }
} }
var item = MainWindow.BookCollection.FindSync<Models.Book>(b => b.LabelId == AddField || b.LabelId == reverse || b.LabelId == case1 || b.LabelId == case2).FirstOrDefault(); var item = MainWindow.BookCollection.FindSync<Models.Book>(b => b.LabelId == AddField).FirstOrDefault();
if (item == null) if (item == null)
{ {
MessageBox.Show("Das Buch ist nicht vorhanden bitte überprüfen"); MessageBox.Show("Das Buch ist nicht vorhanden bitte überprüfen");
@ -245,35 +195,6 @@ namespace BuechermarktClient
} }
} }
} }
private string ReverseString(string s)
{
var res = String.Empty;
foreach(var i in s)
{
char v;
if(_Dictionary.TryGetValue(i, out v) || _ReverseDictionary.TryGetValue(i, out v))
{
res += v;
} else {
MessageBox.Show(string.Format("Das Label enthält ungültige Zeichen ( {0} ), {1}", i, s));
return null;
}
}
return res;
}
private string ReverseUnderscore(string s)
{
if(s.IndexOf("_") >= 0 || s.IndexOf("-") >= 0)
{
s = s.Replace("_", "?").Replace("-", "ß");
} else
{
s = s.Replace("?", "_").Replace("ß", "-");
}
return s;
}
} }
public class SellBook public class SellBook

Binary file not shown.

Binary file not shown.

View File

@ -9,6 +9,10 @@
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" /> <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly> </dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="DocumentFormat.OpenXml" publicKeyToken="8fb06cb64d019a17" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.8.1.0" newVersion="2.8.1.0" />
</dependentAssembly>
</assemblyBinding> </assemblyBinding>
</runtime> </runtime>
</configuration> </configuration>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More