125 lines
4.5 KiB
C#
125 lines
4.5 KiB
C#
using PWAPPv2.Source.DataObjects;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace PWAPPv2.Source.API
|
|
{
|
|
public class PWApiConnection
|
|
{
|
|
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;
|
|
|
|
public PWApiConnection(Source.Config.Configuration practiceConfig, Source.Config.Configuration universalConfig)
|
|
{
|
|
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");
|
|
|
|
}
|
|
|
|
public string PostToApi(string uri, string data)
|
|
{
|
|
return BaseConnection.SendPostRequestAsync(uri, data);
|
|
}
|
|
|
|
public string GetFromApi(string uri)
|
|
{
|
|
return BaseConnection.SendPostRequestAsync(uri);
|
|
}
|
|
|
|
public bool CheckForUpdate()
|
|
{
|
|
string currentVersion = UpdateConnection.SendPostWithCredsInHeader("", "");
|
|
currentVersion = currentVersion.Replace("\"", "");
|
|
if(currentVersion != AppVersion)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void Update(string[] args)
|
|
{
|
|
try
|
|
{
|
|
if (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)
|
|
{
|
|
//System.Windows.MessageBox.Show("HAHA NO UPDATE FOR YOU!");
|
|
Process p = new Process();
|
|
p.StartInfo.FileName = "C:\\PWAPP\\Updater\\PWAppUpdaterForm.exe";
|
|
p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
|
|
p.StartInfo.UseShellExecute = false;
|
|
p.StartInfo.RedirectStandardOutput = true;
|
|
p.StartInfo.RedirectStandardError = true;
|
|
try
|
|
{
|
|
p.StartInfo.Arguments = args[0];
|
|
}
|
|
catch { }
|
|
if (System.Environment.OSVersion.Version.Major >= 6)
|
|
{
|
|
p.StartInfo.Verb = "runas";
|
|
}
|
|
p.Start();
|
|
Environment.Exit(0);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw new UpdateException();
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
}
|
|
|
|
public class UpdateException : Exception { }
|
|
}
|