Skip to content

Instantly share code, notes, and snippets.

View ChrisMoney's full-sized avatar

Chris Weathers ChrisMoney

  • Onevested
  • St. Louis, MO
View GitHub Profile
@ChrisMoney
ChrisMoney / MainWindow.cs
Created September 28, 2016 20:20
MainWindow - Replaced Window property with Page property so app can be a navigation app. NavigationWindow uses this page as it's source.
using System.Windows.Navigation;
namespace RegistrationKiosk
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Page
{
public MainWindow()
@ChrisMoney
ChrisMoney / NavigationWindow.xaml
Last active September 28, 2016 20:21
WPF - Uses MainWindow.xaml as source. Allows for page navigation. All pages are hosted in a window. App.xaml uses as StartupUri. Used for event listening.
namespace RegistrationKiosk
{
/// <summary>
/// Interaction logic for NavWindow.xaml
/// </summary>
public partial class NavWindow : System.Windows.Navigation.NavigationWindow, INotifyPropertyChanged
{
public NavWindow()
{
InitializeComponent();
@ChrisMoney
ChrisMoney / cardswipe.cs
Created September 28, 2016 20:01
WPF Navigation App - Desktop app with page navigation that functions like web app
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Navigation;
using System.Windows.Threading;
using SocketSender;
using IntercardLogging;
@ChrisMoney
ChrisMoney / xml-to-object.cs
Last active September 21, 2016 17:36
XML Serializer - Deserializer. No XSD involved.
protected override void WriteRequest(object data, Stream stream)
{
var serializer = SerializerHelper.Get(data.GetType());
var ns = new XmlSerializerNamespaces(new[] { new XmlQualifiedName("", "") }); //strip all default namespaces.
var settings = new XmlWriterSettings { Encoding = new UTF8Encoding(false), OmitXmlDeclaration = false };
using (var xw = XmlTextWriter.Create(stream, settings))
{
if (settings.OmitXmlDeclaration)
{
//'encoding' in the xml declaration used to be forced to all-caps. As far as I can tell, there's no reason for it.
@ChrisMoney
ChrisMoney / ReadCardTrack.cs
Created August 29, 2016 18:07
Read track data from card - Return account number and site code
// acct number + site code: %6074=4369371343068064237?;6074=0000000000303942?
public static string FormatAcctNumber(string cardNumber, out string siteCode)
{
// split data by
string[] array = cardNumber.Split(';');
string data = array[1];
string[] dataArray = data.Split('=');
siteCode = dataArray[0];
string acctNumber = dataArray[1];
// remove question mark
@ChrisMoney
ChrisMoney / page.xaml
Last active August 25, 2016 21:46
WPF - XAML Page with virtual keyboard
<Page x:Class="RegistrationKiosk.FirstName"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:TermControls="clr-namespace:TermControls;assembly=TermControls"
xmlns:adorners="http://gu.se/Adorners"
mc:Ignorable="d"
d:DesignHeight="{Binding SystemParameters.PrimaryScreenHeight }" d:DesignWidth="{Binding SystemParameters.PrimaryScreenWidth }"
Title="FirstName">
@ChrisMoney
ChrisMoney / K100-send-command.cs
Last active August 11, 2016 21:40
C# : Send low level hexadecimal, binary command to K100 debit card dispenser listening on a serial port.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using IntercardLogging;
using System.IO;
using System.Net;
using System.IO.Ports;
using System.Reflection;
using System.Text;
@ChrisMoney
ChrisMoney / void-type-interface.cs
Last active August 11, 2016 21:43
Void Interface method that wraps a return method
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// methods encapsulated by the interface method of various return types can be placed inside of the void interface methods
// could use a public global class property to out a return value
namespace Dispenser
@ChrisMoney
ChrisMoney / K720-send-command.cs
Last active September 23, 2023 19:29
C# Send low level hexadecimal, binary command to K720 debit card dispenser listening on a serial port.
#define USE_DEBUG
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.IO.Ports;
using Microsoft.Win32.SafeHandles;
using System.Reflection;
@ChrisMoney
ChrisMoney / unit-test-serial-port.cs
Created July 11, 2016 14:51
Unit Test Serial Port: Find which Serial port is open to test a piece of hardware.
using System;
using System.IO.Ports;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using CardDispenser;
namespace CardDispenserTests
{
[TestClass]
public class CardDispenerTests
{