diff --git a/PWAPPv2.sln b/PWAPPv2.sln index 5b08ebc..27b0408 100644 --- a/PWAPPv2.sln +++ b/PWAPPv2.sln @@ -1,11 +1,13 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.33529.622 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34009.444 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PWAPPv2", "PWAPPv2\PWAPPv2.csproj", "{45E26AF8-41D7-4308-A2C8-D55A0350DB47}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "UnitTests\UnitTests.csproj", "{164B9220-F337-4E88-B619-0C52C502B9C4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PWAppUpdater", "PWAppUpdater\PWAppUpdater.csproj", "{B84B314C-C17A-42A3-BCAE-038F48343F5A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PWAppUpdaterForm", "PWAppUpdater2\PWAppUpdaterForm.csproj", "{093798DD-2EDD-4519-AAC6-9DFF0DE3C15A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -17,10 +19,14 @@ Global {45E26AF8-41D7-4308-A2C8-D55A0350DB47}.Debug|Any CPU.Build.0 = Debug|Any CPU {45E26AF8-41D7-4308-A2C8-D55A0350DB47}.Release|Any CPU.ActiveCfg = Release|Any CPU {45E26AF8-41D7-4308-A2C8-D55A0350DB47}.Release|Any CPU.Build.0 = Release|Any CPU - {164B9220-F337-4E88-B619-0C52C502B9C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {164B9220-F337-4E88-B619-0C52C502B9C4}.Debug|Any CPU.Build.0 = Debug|Any CPU - {164B9220-F337-4E88-B619-0C52C502B9C4}.Release|Any CPU.ActiveCfg = Release|Any CPU - {164B9220-F337-4E88-B619-0C52C502B9C4}.Release|Any CPU.Build.0 = Release|Any CPU + {B84B314C-C17A-42A3-BCAE-038F48343F5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B84B314C-C17A-42A3-BCAE-038F48343F5A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B84B314C-C17A-42A3-BCAE-038F48343F5A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B84B314C-C17A-42A3-BCAE-038F48343F5A}.Release|Any CPU.Build.0 = Release|Any CPU + {093798DD-2EDD-4519-AAC6-9DFF0DE3C15A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {093798DD-2EDD-4519-AAC6-9DFF0DE3C15A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {093798DD-2EDD-4519-AAC6-9DFF0DE3C15A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {093798DD-2EDD-4519-AAC6-9DFF0DE3C15A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/PWAPPv2/MainWindow.xaml.cs b/PWAPPv2/MainWindow.xaml.cs index efbe229..05b2727 100644 --- a/PWAPPv2/MainWindow.xaml.cs +++ b/PWAPPv2/MainWindow.xaml.cs @@ -1,10 +1,10 @@ -using Microsoft.Win32; -using System; +using System; using System.Collections.Generic; +using System.Diagnostics; +using System.IO; using System.Windows; using System.Windows.Controls; using System.Windows.Forms; -using System.Windows.Media; /** * TODO: @@ -40,7 +40,10 @@ namespace PWAPPv2 List images; - string ConfigPath = "C:\\PWAPP\\Config\\Config.xml"; + + //string ConfigPath = "C:\\PWAPP\\Config\\Config.xml"; + + string ConfigPath; public MainWindow() { @@ -53,7 +56,10 @@ namespace PWAPPv2 try { - practiceConfig = new Source.Config.Configuration(".\\Config\\PracticeConfig.xml"); + ConfigPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + ConfigPath = Path.Combine(ConfigPath, "PWAPP\\Config\\"); + + practiceConfig = new Source.Config.Configuration(ConfigPath + "PracticeConfig.xml"); universalConfig = new Source.Config.Configuration(".\\Config\\UniversalConfig.xml"); } catch @@ -66,15 +72,28 @@ namespace PWAPPv2 try { - if(pwapiConnection.CheckForUpdate() == true) + if (pwapiConnection.CheckForUpdate() == true) { string message = "An update is available! Would you like to install it?"; string title = "Update available!"; MessageBoxButtons buttons = MessageBoxButtons.YesNo; DialogResult result = System.Windows.Forms.MessageBox.Show(message, title, buttons); - if(result == System.Windows.Forms.DialogResult.Yes) + if (result == System.Windows.Forms.DialogResult.Yes) { - System.Windows.MessageBox.Show("HAHA NO UPDATE FOR YOU!"); + //System.Windows.MessageBox.Show("HAHA NO UPDATE FOR YOU!"); + Process p = new Process(); + p.StartInfo.FileName = "E:\\PatientWebAPI\\PWAPPv2\\PWAPPv2\\PWAppUpdater2\\bin\\Release\\net6.0-windows\\PWAppUpdaterForm.exe"; + p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized; + p.StartInfo.UseShellExecute = false; + p.StartInfo.RedirectStandardOutput = true; + p.StartInfo.RedirectStandardError = true; + p.StartInfo.Arguments = args[0]; + if(System.Environment.OSVersion.Version.Major >= 6) + { + p.StartInfo.Verb = "runas"; + } + p.Start(); + Environment.Exit(0); } } } @@ -104,11 +123,11 @@ namespace PWAPPv2 this.DataContext = new Source.PatientGUIAdapter(patient); } - catch(NullReferenceException) + catch (NullReferenceException) { } - catch(Exception e) + catch (Exception e) { System.Windows.MessageBox.Show(e.Message); } @@ -123,20 +142,21 @@ namespace PWAPPv2 private void PopulateReferTypesBox() { - string ReferTypeString = apiConnection.SendPostRequestAsync("api/PWReferralTypes"); + //string ReferTypeString = apiConnection.SendPostRequestAsync("api/PWReferralTypes"); + string ReferTypeString = pwapiConnection.GetReferalTypes(); TypeBox = new Source.DataObjects.ReferralTypeBox(boxReferType, ReferTypeString); } private void PopulateReferToBox() { - string ReferToString = apiConnection.SendPostRequestAsync("api/PWReferTo"); + string ReferToString = pwapiConnection.GetReferTo(); //apiConnection.SendPostRequestAsync("api/PWReferTo"); ToBox = new Source.DataObjects.ReferToBox(boxReferTo, ReferToString); } private void PopulateReferFromBox() { - string ReferFromString = apiConnection.SendPostRequestAsync("api/PWReferFrom"); + string ReferFromString = pwapiConnection.GetReferFrom(); //apiConnection.SendPostRequestAsync("api/PWReferFrom"); FromBox = new Source.DataObjects.ReferFromBox(boxReferFrom, ReferFromString); } @@ -205,7 +225,7 @@ namespace PWAPPv2 try { string referralString = referral.ToJsonString(); - string result = apiConnection.SendPostRequestAsync("api/PWMakeReferral", referralString); + string result = pwapiConnection.SendReferral(referralString); //apiConnection.SendPostRequestAsync("api/PWMakeReferral", referralString); if (images.Count > 0) { foreach (Source.DataObjects.PWImage im in images) @@ -214,12 +234,10 @@ namespace PWAPPv2 string json = att.ToJsonString(); apiConnection.SendPostRequestAsync("api/PWAttachment", json); } - System.Windows.MessageBox.Show("Referral added successfully!"); - } - else - { - System.Windows.MessageBox.Show(result); } + + System.Windows.MessageBox.Show("Referral added successfully!"); + this.Close(); } catch (Source.DataObjects.Referral.InvalidReferalDataException) @@ -236,7 +254,7 @@ namespace PWAPPv2 openFileDialog.Filter = "Image files (*.jpg,*.jpeg)|*.jpg;*.jpeg"; openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); - if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) + if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { foreach (string filename in openFileDialog.FileNames) { diff --git a/PWAPPv2/Source/API/APIConnection.cs b/PWAPPv2/Source/API/APIConnection.cs index ba72ecc..4768258 100644 --- a/PWAPPv2/Source/API/APIConnection.cs +++ b/PWAPPv2/Source/API/APIConnection.cs @@ -100,6 +100,7 @@ namespace PWAPPv2.Source.API Client.DefaultRequestHeaders.Add("ApiID", Credentials.APIid); StringContent content = new StringContent(PostData, Encoding.UTF8, "application/json"); + string conts = content.ToString(); var response = Client.PostAsync(apiUri, content).Result; diff --git a/PWAPPv2/Source/API/PWApiConnection.cs b/PWAPPv2/Source/API/PWApiConnection.cs index c188642..18bd815 100644 --- a/PWAPPv2/Source/API/PWApiConnection.cs +++ b/PWAPPv2/Source/API/PWApiConnection.cs @@ -12,6 +12,12 @@ namespace PWAPPv2.Source.API private APIConnection BaseConnection; private APIConnection UpdateConnection; + private APIConnection AttachementConnection; + private APIConnection ReferralConnection; + private APIConnection ReferToConnection; + private APIConnection ReferFromConnection; + private APIConnection ReferTypesConnection; + private APICredentials Credentials; private string AppVersion; @@ -20,6 +26,11 @@ namespace PWAPPv2.Source.API Credentials = new APICredentials(practiceConfig); BaseConnection = new APIConnection(universalConfig.Get("PWBaseURI"), Credentials); UpdateConnection = new APIConnection(universalConfig.Get("PWUpdateURI"), Credentials); + AttachementConnection = new APIConnection(universalConfig.Get("PWAttachmentURI"), Credentials); + ReferralConnection = new APIConnection(universalConfig.Get("PWReferralURI"), Credentials); + ReferToConnection = new APIConnection(universalConfig.Get("PWReferToURI"), Credentials); + ReferFromConnection = new APIConnection(universalConfig.Get("PWReferFromURI"), Credentials); + ReferTypesConnection = new APIConnection(universalConfig.Get("PWReferTypesURI"), Credentials); AppVersion = universalConfig.Get("PWAppVersion"); @@ -46,5 +57,25 @@ namespace PWAPPv2.Source.API return false; } + public string GetReferalTypes() + { + return ReferTypesConnection.SendPostWithCredsInHeader("", ""); + } + + public string GetReferTo() + { + return ReferToConnection.SendPostWithCredsInHeader("", ""); + } + + public string GetReferFrom() + { + return ReferFromConnection.SendPostWithCredsInHeader("", ""); + } + + public string SendReferral(string JsonData) + { + return ReferralConnection.SendPostWithCredsInHeader("", JsonData); + } + } } diff --git a/PWAppUpdater/App.xaml b/PWAppUpdater/App.xaml new file mode 100644 index 0000000..c91f125 --- /dev/null +++ b/PWAppUpdater/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/PWAppUpdater/App.xaml.cs b/PWAppUpdater/App.xaml.cs new file mode 100644 index 0000000..0ba6512 --- /dev/null +++ b/PWAppUpdater/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace PWAppUpdater +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/PWAppUpdater/AssemblyInfo.cs b/PWAppUpdater/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/PWAppUpdater/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/PWAppUpdater/FTP/FTPManager.cs b/PWAppUpdater/FTP/FTPManager.cs new file mode 100644 index 0000000..e478cbd --- /dev/null +++ b/PWAppUpdater/FTP/FTPManager.cs @@ -0,0 +1,45 @@ +using System; +using System.IO; +using System.Net; + + +namespace PWAppUpdater.FTP +{ + class FTPManager + { + private string BaseUri; + private NetworkCredential credential; + + public FTPManager(string baseUri, string username, string password) + { + BaseUri = baseUri; + credential = new NetworkCredential(username, password); + } + + public void DownloadFile(string FTPPath, string localPath) + { + try + { + FtpWebRequest request = (FtpWebRequest)WebRequest.Create(BaseUri + FTPPath); + request.Method = WebRequestMethods.Ftp.DownloadFile; + request.Credentials = credential; + request.KeepAlive = false; + request.UseBinary = true; + request.UsePassive = true; + + FtpWebResponse response = (FtpWebResponse)request.GetResponse(); + Stream responseStream = response.GetResponseStream(); + + using (Stream s = File.Create(localPath)) + { + responseStream.CopyTo(s); + } + response.Close(); + } + catch (Exception e) + { + Console.WriteLine(e.Message.ToString()); + } + } + } +} diff --git a/PWAppUpdater/MainWindow.xaml b/PWAppUpdater/MainWindow.xaml new file mode 100644 index 0000000..bb52683 --- /dev/null +++ b/PWAppUpdater/MainWindow.xaml @@ -0,0 +1,16 @@ + + + +