Add project files.

This commit is contained in:
Administrator 2025-05-05 11:45:57 -05:00
parent a352a33ede
commit d552ebe0a6
14 changed files with 673 additions and 0 deletions

3
App.config Normal file
View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>

BIN
Assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

20
CramLink_v2.csproj Normal file
View File

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<BaseOutputPath>C:\TestRepo\CramLink</BaseOutputPath>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<None Remove="Assets\logo.png" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Assets\logo.png" />
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\" />
</ItemGroup>
</Project>

25
CramLink_v2.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.35013.160
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CramLink_v2", "CramLink_v2.csproj", "{3C79CF75-0152-4443-A49F-EA94FF67D2B7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3C79CF75-0152-4443-A49F-EA94FF67D2B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3C79CF75-0152-4443-A49F-EA94FF67D2B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3C79CF75-0152-4443-A49F-EA94FF67D2B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3C79CF75-0152-4443-A49F-EA94FF67D2B7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {87E85B4D-7A8D-49DB-88F0-AB28E404CE70}
EndGlobalSection
EndGlobal

126
MainForm.Designer.cs generated Normal file
View File

@ -0,0 +1,126 @@
using System.Windows.Forms;
namespace CramLinkClientGUI
{
public partial class MainForm
{
private System.ComponentModel.IContainer components = null;
private ComboBox siteComboBox;
private Button connectButton;
private Label statusLabel;
private TextBox logBox;
private Label label1;
private Label label2;
private Label piStatus;
private Label plcStatus;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
components.Dispose();
base.Dispose(disposing);
}
private void InitializeComponent()
{
siteComboBox = new ComboBox();
connectButton = new Button();
statusLabel = new Label();
logBox = new TextBox();
label1 = new Label();
label2 = new Label();
piStatus = new Label();
plcStatus = new Label();
SuspendLayout();
//
// siteComboBox
//
siteComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
siteComboBox.FormattingEnabled = true;
siteComboBox.Location = new Point(12, 12);
siteComboBox.Name = "siteComboBox";
siteComboBox.Size = new Size(300, 23);
siteComboBox.TabIndex = 0;
//
// connectButton
//
connectButton.Location = new Point(330, 12);
connectButton.Name = "connectButton";
connectButton.Size = new Size(100, 23);
connectButton.TabIndex = 1;
connectButton.Text = "Connect";
connectButton.Click += connectButton_Click;
//
// statusLabel
//
statusLabel.AutoSize = true;
statusLabel.Location = new Point(450, 17);
statusLabel.Name = "statusLabel";
statusLabel.Size = new Size(79, 15);
statusLabel.TabIndex = 2;
statusLabel.Text = "Disconnected";
//
// logBox
//
logBox.Location = new Point(12, 50);
logBox.Multiline = true;
logBox.Name = "logBox";
logBox.ReadOnly = true;
logBox.ScrollBars = ScrollBars.Vertical;
logBox.Size = new Size(600, 300);
logBox.TabIndex = 3;
//
// label1
//
label1.Location = new Point(12, 360);
label1.Name = "label1";
label1.Size = new Size(59, 23);
label1.TabIndex = 4;
label1.Text = "Pi Status:";
//
// label2
//
label2.Location = new Point(101, 360);
label2.Name = "label2";
label2.Size = new Size(70, 23);
label2.TabIndex = 6;
label2.Text = "PLC Status:";
//
// piStatus
//
piStatus.Font = new Font("Segoe UI Emoji", 12F, FontStyle.Regular, GraphicsUnit.Point);
piStatus.Location = new Point(65, 358);
piStatus.Name = "piStatus";
piStatus.Size = new Size(30, 23);
piStatus.TabIndex = 5;
piStatus.Text = "🔴";
//
// plcStatus
//
plcStatus.Font = new Font("Segoe UI Emoji", 12F, FontStyle.Regular, GraphicsUnit.Point);
plcStatus.Location = new Point(168, 358);
plcStatus.Name = "plcStatus";
plcStatus.Size = new Size(31, 23);
plcStatus.TabIndex = 7;
plcStatus.Text = "🔴";
//
// MainForm
//
ClientSize = new Size(630, 390);
Controls.Add(siteComboBox);
Controls.Add(connectButton);
Controls.Add(statusLabel);
Controls.Add(logBox);
Controls.Add(label1);
Controls.Add(piStatus);
Controls.Add(label2);
Controls.Add(plcStatus);
Name = "MainForm";
Text = "CramLink VPN Client";
ResumeLayout(false);
PerformLayout();
}
}
}

111
MainForm.cs Normal file
View File

@ -0,0 +1,111 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Net.NetworkInformation;
using System.Windows.Forms;
namespace CramLinkClientGUI
{
public partial class MainForm : Form
{
private Process vpnProcess;
private System.Windows.Forms.Timer pingTimer = new System.Windows.Forms.Timer();
public MainForm()
{
InitializeComponent();
statusLabel.Text = "Disconnected";
siteComboBox.Items.AddRange(new[]
{
"CramLink 1 - HQ",
"CramLink 2 - N/A"
});
siteComboBox.SelectedIndex = 0;
pingTimer.Interval = 5000;
pingTimer.Tick += PingTargets;
}
private void connectButton_Click(object sender, EventArgs e)
{
if (vpnProcess != null && !vpnProcess.HasExited)
{
vpnProcess.Kill();
vpnProcess.Dispose();
vpnProcess = null;
statusLabel.Text = "Disconnected";
connectButton.Text = "Connect";
logBox.AppendText("VPN disconnected.\r\n");
pingTimer.Stop();
return;
}
string configPath = "C:\\CramLinkVPN\\client.ovpn";
string openvpnPath = "C:\\CramLinkVPN\\openvpn.exe";
if (!File.Exists(configPath) || !File.Exists(openvpnPath))
{
MessageBox.Show("OpenVPN executable or config not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
vpnProcess = new Process();
vpnProcess.StartInfo.FileName = openvpnPath;
vpnProcess.StartInfo.Arguments = "--config \"" + configPath + "\"";
vpnProcess.StartInfo.RedirectStandardOutput = true;
vpnProcess.StartInfo.RedirectStandardError = true;
vpnProcess.StartInfo.UseShellExecute = false;
vpnProcess.StartInfo.CreateNoWindow = true;
vpnProcess.OutputDataReceived += (s, args) => HandleVPNOutput(args.Data);
vpnProcess.ErrorDataReceived += (s, args) => HandleVPNOutput(args.Data);
vpnProcess.Start();
vpnProcess.BeginOutputReadLine();
vpnProcess.BeginErrorReadLine();
connectButton.Text = "Disconnect";
statusLabel.Text = "Connecting...";
logBox.AppendText("Connecting to VPN...\r\n");
}
private void HandleVPNOutput(string data)
{
if (data == null) return;
Invoke(new Action(() =>
{
logBox.AppendText(data + "\r\n");
if (data.Contains("Initialization Sequence Completed"))
{
statusLabel.Text = "Connected";
pingTimer.Start();
}
}));
}
private void PingTargets(object sender, EventArgs e)
{
bool piOnline = PingHost("192.168.0.53");
bool plcOnline = PingHost("192.168.0.98");
piStatus.ForeColor = piOnline ? System.Drawing.Color.Green : System.Drawing.Color.Red;
plcStatus.ForeColor = plcOnline ? System.Drawing.Color.Green : System.Drawing.Color.Red;
}
private bool PingHost(string host)
{
try
{
using Ping ping = new Ping();
PingReply reply = ping.Send(host, 1000);
return reply.Status == IPStatus.Success;
}
catch { return false; }
}
private void plcStatus_Click(object sender, EventArgs e)
{
}
}
}

120
MainForm.resx Normal file
View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

15
Program.cs Normal file
View File

@ -0,0 +1,15 @@
using System;
using System.Windows.Forms;
namespace CramLinkClientGUI
{
internal static class Program
{
[STAThread]
static void Main()
{
ApplicationConfiguration.Initialize();
Application.Run(new SplashContext());
}
}
}

BIN
Properties/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 MiB

27
SplashContext.cs Normal file
View File

@ -0,0 +1,27 @@
using System;
using System.Windows.Forms;
using System.Threading.Tasks;
namespace CramLinkClientGUI
{
public class SplashContext : ApplicationContext
{
private SplashForm splash;
private MainForm main;
public SplashContext()
{
splash = new SplashForm();
splash.Shown += async (s, e) =>
{
await Task.Delay(2500);
splash.Hide();
main = new MainForm();
main.FormClosed += (s2, e2) => ExitThread();
main.Show();
};
splash.Show();
}
}
}

49
SplashForm.Designer.cs generated Normal file
View File

@ -0,0 +1,49 @@
namespace CramLinkClientGUI
{
partial class SplashForm
{
private System.ComponentModel.IContainer components = null;
private System.Windows.Forms.PictureBox logoBox;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.logoBox = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.logoBox)).BeginInit();
this.SuspendLayout();
//
// logoBox
//
this.logoBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.logoBox.Location = new System.Drawing.Point(0, 0);
this.logoBox.Name = "logoBox";
this.logoBox.Size = new System.Drawing.Size(768, 512);
this.logoBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.logoBox.TabIndex = 0;
this.logoBox.TabStop = false;
//
// SplashForm
//
this.Opacity = 0;
this.TopMost = true;
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(768, 512);
this.Controls.Add(this.logoBox);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "SplashForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "SplashForm";
((System.ComponentModel.ISupportInitialize)(this.logoBox)).EndInit();
this.ResumeLayout(false);
}
}
}

42
SplashForm.cs Normal file
View File

@ -0,0 +1,42 @@
using System;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using Timer = System.Windows.Forms.Timer;
namespace CramLinkClientGUI
{
public partial class SplashForm : Form
{
private Timer fadeTimer;
public SplashForm()
{
InitializeComponent();
StartFadeIn();
LoadLogo();
}
private void StartFadeIn()
{
this.Opacity = 0;
fadeTimer = new Timer();
fadeTimer.Interval = 30; // ms
fadeTimer.Tick += (s, e) =>
{
if (this.Opacity < 1)
this.Opacity += 0.05;
else
fadeTimer.Stop();
};
fadeTimer.Start();
}
private void LoadLogo()
{
var assembly = Assembly.GetExecutingAssembly();
using Stream stream = assembly.GetManifestResourceStream("CramLink_v2.Assets.logo.png");
if (stream != null)
logoBox.Image = Image.FromStream(stream);
}
}
}

120
SplashForm.resx Normal file
View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

15
app.manifest Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
</application>
</compatibility>
</assembly>