Skip to content

Commit

Permalink
- V 0.93.05; License and terms of use; Usage statistics via MySQL dat…
Browse files Browse the repository at this point in the history
…abase as server

  - License and data collection notice now in DialogInitial (Github issue #27)
    - Localization strings updated, clearly must accept terms of service
  - Server connection (via MySQL) implemented for sending usage statistics (Github issue #28)
    - Tested and debugged ... set to run in BackgroundWorker
  • Loading branch information
tanjera committed Apr 17, 2019
1 parent 2a8d382 commit fb6bea3
Show file tree
Hide file tree
Showing 13 changed files with 233 additions and 88 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# Access codes/passwords
[Ss]erver_Access.cs

# Third party or paid content (against TOS/EULA to include on Github!!)
[Tt]hird Party/

Expand Down
75 changes: 45 additions & 30 deletions II_Core/Classes/Localization_Dictionary.cs

Large diffs are not rendered by default.

80 changes: 80 additions & 0 deletions II_Core/Classes/Server.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Net.NetworkInformation;
using System.Text;

using MySql.Data.MySqlClient;

namespace II.Server {

public partial class Connection {

private MySqlConnection connection;

public Connection() {
connection = new MySqlConnection (
String.Format ("SERVER={0};DATABASE={1};UID={2};PASSWORD={3};",
accessServer, accessDatabase, accessUid, accessPassword));
}

private bool Open () {
try {
connection.Open();
return true;
}
catch (MySqlException e) {
// When handling errors, you can your application's response based on the error number.
// The two most common error numbers when connecting are as follows:
// 0: Cannot connect to server.
// 1045: Invalid user name and/or password.
return false;
}
}

private bool Close () {
try {
connection.Close ();
return true;
} catch (MySqlException e) {
return false;
}
}

public void UsageStatistics_Send () {
try {
string macAddress = "",
ipAddress = "";

NetworkInterface nInterface = NetworkInterface.GetAllNetworkInterfaces ().Where (
(o) => (o.NetworkInterfaceType == NetworkInterfaceType.Ethernet || o.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)
&& o.OperationalStatus == OperationalStatus.Up)
.First ();
if (nInterface != null) {
macAddress = nInterface.GetPhysicalAddress ().ToString ();
ipAddress = nInterface.GetIPProperties ().UnicastAddresses.Where (
(a) => a.Address.AddressFamily == AddressFamily.InterNetwork)
.Select (a => a.Address.ToString ()).First ();
}

MySqlCommand c = connection.CreateCommand ();
c.CommandText = "INSERT INTO usage_statistics(timestamp, ii_version, client_os, client_ip, client_mac, client_user) " +
"VALUES(?timestamp, ?ii_version, ?client_os, ?client_ip, ?client_mac, ?client_user)";
c.Parameters.Add ("?timestamp", MySqlDbType.VarChar).Value = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
c.Parameters.Add ("?ii_version", MySqlDbType.VarChar).Value = Utility.Version;
c.Parameters.Add ("?client_os", MySqlDbType.VarChar).Value = Environment.OSVersion.VersionString;
c.Parameters.Add ("?client_ip", MySqlDbType.VarChar).Value = ipAddress;
c.Parameters.Add ("?client_mac", MySqlDbType.VarChar).Value = macAddress;
c.Parameters.Add ("?client_user", MySqlDbType.VarChar).Value = Environment.UserName;

connection.Open ();
c.ExecuteNonQuery ();
connection.Close ();
} catch (MySqlException e) {
connection.Close ();
}
}
}
}
Binary file added II_Core/Classes/Server_Access.rar
Binary file not shown.
2 changes: 2 additions & 0 deletions II_Core/II_Core.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<Compile Include="$(MSBuildThisFileDirectory)Classes\Localization_Dictionary.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Classes\Patient.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Classes\Rhythms.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Classes\Server.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Classes\Server_Access.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Classes\Strip.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Classes\Timer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Classes\Utility.cs" />
Expand Down
Binary file modified II_Core/Localization Strings.xlsx
Binary file not shown.
9 changes: 8 additions & 1 deletion II_Windows/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Linq;
Expand All @@ -17,6 +18,7 @@ public partial class App : Application {

public static string [] Start_Args;

public static II.Server.Connection Server_Connection = new II.Server.Connection ();
public static II.Localization.Languages Language = new II.Localization.Languages();

public static Patient Patient;
Expand All @@ -29,7 +31,7 @@ public partial class App : Application {
public static DeviceIABP Device_IABP;

public static DialogAbout Dialog_About;
public static DialogLanguage Dialog_Language;
public static DialogInitial Dialog_Language;

public static DispatcherTimer Timer_Main = new DispatcherTimer();

Expand All @@ -38,6 +40,11 @@ public partial class App : Application {

Timer_Main.Interval = new TimeSpan (100000); // q 10 milliseconds
Timer_Main.Start ();

// Send usage statistics to server in background
BackgroundWorker bgw = new BackgroundWorker ();
bgw.DoWork += delegate { Server_Connection.UsageStatistics_Send (); };
bgw.RunWorkerAsync ();
}
}
}
9 changes: 6 additions & 3 deletions II_Windows/II_Windows.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Windows\DialogLanguage.xaml">
<Page Include="Windows\DialogInitial.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
Expand Down Expand Up @@ -205,8 +205,8 @@
<Compile Include="Windows\DialogAbout.xaml.cs">
<DependentUpon>DialogAbout.xaml</DependentUpon>
</Compile>
<Compile Include="Windows\DialogLanguage.xaml.cs">
<DependentUpon>DialogLanguage.xaml</DependentUpon>
<Compile Include="Windows\DialogInitial.xaml.cs">
<DependentUpon>DialogInitial.xaml</DependentUpon>
</Compile>
<Compile Include="Windows\PatientEditor.xaml.cs">
<DependentUpon>PatientEditor.xaml</DependentUpon>
Expand Down Expand Up @@ -280,6 +280,9 @@
<PackageReference Include="Extended.Wpf.Toolkit">
<Version>3.2.0</Version>
</PackageReference>
<PackageReference Include="MySql.Data">
<Version>8.0.15</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Resource Include="Icon_Infirmary.ico" />
Expand Down
73 changes: 73 additions & 0 deletions II_Windows/Windows/DialogInitial.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<Window x:Class="II_Windows.DialogInitial"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:II_Windows"
mc:Ignorable="d"
Title="Select Language and Agree to Terms"
Name="dlgLanguage"
Icon="{StaticResource Icon_Infirmary}"
WindowStartupLocation="CenterScreen"
MinHeight="150" MinWidth="275" SizeToContent="WidthAndHeight">

<Window.Resources>
<Style x:Key="grpBorder" TargetType="{x:Type Border}">
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="BorderThickness" Value="0, 0, 0, 1" />
</Style>
</Window.Resources>


<Grid HorizontalAlignment="Center" Margin="15, 10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<Label Name="lblChooseLanguage"
Grid.Column="0" Grid.Row="0"
Padding="5,2" Margin="5"
VerticalAlignment="Center" HorizontalAlignment="Center"/>

<ComboBox Name="cmbLanguages"
Grid.Column="0" Grid.Row="1"
Padding="5,2,5,5" Margin="5"
HorizontalAlignment="Stretch"/>

<Border Style="{StaticResource grpBorder}"
Grid.Column="0" Grid.Row="2" />

<Label Name="lblAgreeTerms"
Grid.Column="0" Grid.Row="3"
Padding="5,5,5,2" VerticalAlignment="Center" HorizontalAlignment="Center">

<TextBlock Name="txtAgreeTerms" TextWrapping="Wrap" />
</Label>

<Label Name="lblTermsUri"
Grid.Column="0" Grid.Row="4"
Padding="5,2" VerticalAlignment="Center" HorizontalAlignment="Center">
<Hyperlink
NavigateUri="http://www.infirmary-integrated.com/license-and-data-collection/"
RequestNavigate="Hyperlink_RequestNavigate">
http://www.infirmary-integrated.com/license-and-data-collection/
</Hyperlink>
</Label>

<Button Name="btnContinue"
Grid.Column="0" Grid.Row="5"
Padding="5,2" Margin="5" Background="White"
HorizontalAlignment="Stretch"
Click="OnClick_Continue" />

</Grid>
</Window>
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ namespace II_Windows {
/// <summary>
/// Interaction logic for DialogLanguage.xaml
/// </summary>
public partial class DialogLanguage : Window {
public DialogLanguage () {
public partial class DialogInitial : Window {
public DialogInitial () {
InitializeComponent ();

// Populate UI strings per language selection
dlgLanguage.Title = App.Language.Dictionary["LANG:LanguageSelection"];
lblChooseLanguage.Content = App.Language.Dictionary["LANG:ChooseLanguage"];
dlgLanguage.Title = App.Language.Dictionary["INITIAL:LanguageAndTerms"];
lblChooseLanguage.Content = App.Language.Dictionary["INITIAL:ChooseLanguage"];
txtAgreeTerms.Text = App.Language.Dictionary ["INITIAL:AgreeToTerms"];
btnContinue.Content = App.Language.Dictionary["BUTTON:Continue"];

cmbLanguages.ItemsSource = Languages.Descriptions;
Expand All @@ -38,5 +39,9 @@ public partial class DialogLanguage : Window {
Properties.Settings.Default.Save ();
this.Close ();
}

private void Hyperlink_RequestNavigate (object sender, System.Windows.Navigation.RequestNavigateEventArgs e) {
System.Diagnostics.Process.Start (e.Uri.ToString());
}
}
}
42 changes: 0 additions & 42 deletions II_Windows/Windows/DialogLanguage.xaml

This file was deleted.

13 changes: 6 additions & 7 deletions II_Windows/Windows/PatientEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public partial class PatientEditor : Window {
DataContext = this;
App.Patient_Editor = this;

InitLanguage ();
InitInitialRun ();
InitInterface ();
InitPatient ();

Expand All @@ -45,13 +45,12 @@ public partial class PatientEditor : Window {
//WindowState = WindowState.Minimized;
}

private void InitLanguage () {
private void InitInitialRun () {
string setLang = Properties.Settings.Default.Language;

if (setLang == null || setLang == ""
|| !Enum.TryParse<Languages.Values>(setLang, out App.Language.Value)) {
App.Language = new Languages ();
DialogLanguage ();
DialogInitial ();
}
}

Expand Down Expand Up @@ -189,8 +188,8 @@ public partial class PatientEditor : Window {

App.Patient.PatientEvent += App.Device_IABP.OnPatientEvent;
}
private void DialogLanguage(bool reloadUI = false) {
App.Dialog_Language = new DialogLanguage ();
private void DialogInitial(bool reloadUI = false) {
App.Dialog_Language = new DialogInitial ();
App.Dialog_Language.Activate ();
App.Dialog_Language.ShowDialog ();

Expand Down Expand Up @@ -422,7 +421,7 @@ public partial class PatientEditor : Window {
private void MenuLoadFile_Click (object s, RoutedEventArgs e) => LoadFile ();
private void MenuSaveFile_Click (object s, RoutedEventArgs e) => SaveFile ();
private void MenuExit_Click (object s, RoutedEventArgs e) => RequestExit ();
private void MenuSetLanguage_Click (object s, RoutedEventArgs e) => DialogLanguage (true);
private void MenuSetLanguage_Click (object s, RoutedEventArgs e) => DialogInitial (true);
private void MenuAbout_Click (object s, RoutedEventArgs e) => DialogAbout ();
private void ButtonDeviceMonitor_Click (object s, RoutedEventArgs e) => InitDeviceMonitor ();
private void ButtonDeviceECG_Click (object s, RoutedEventArgs e) => InitDeviceECG ();
Expand Down
2 changes: 1 addition & 1 deletion To Do.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


* Next steps:
* Defibrillator
* Defibrillator
- Pacing functionality
- Will need capture threshold on Patient Editor
- Pause button
Expand Down

0 comments on commit fb6bea3

Please sign in to comment.