Getting Started

 

Here's the code for your WalkIn:

 private bool m_bCredentials;
enum strcode { CUNAM, CLPWD, CLKEY }
public string rcunam = string.Empty; // remote client username
public string rcpwd = string.Empty; // remote client password
public string rckey = string.Empty; // remote client key
private bool m_bNormalClose;
private string m_sUserDirPath;
private string URLString;

 public Form1()
{
InitializeComponent();

// put your server file path here
URLString = "http://www.yourcompany.com/somedirectory/clients.xml";

m_bPwdShow = true;
m_bCredentials = false;
m_bNormalClose = false;


}

private void Form1_Load(object sender, EventArgs e)
{
m_sUserDirPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
m_sUserDirPath += "/AppData/Local/YourCompany/YourAppName";
System.IO.Directory.CreateDirectory(m_sUserDirPath);
}

private void Form1_Closing(object sender, FormClosingEventArgs e)
{
if (!m_bNormalClose)
{
string[] str = new string[4];
str[0] = "cancel";
str[1] = rcunam;
str[2] = rcpwd;
str[3] = rckey;

File.WriteAllLines(m_sUserDirPath + "/drop.txt", str);
Application.Exit();
}
}

private void btnOK_Click(object sender, EventArgs e)
{

int j = 0;
bool bFound = false;
ArrayList alist = new ArrayList();

Cursor = Cursors.WaitCursor;

try
{

XmlTextReader reader = new XmlTextReader(URLString);

while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
Debug.Write("<" + reader.Name);

while (reader.MoveToNextAttribute()) // Read the attributes.
Debug.Write(" " + reader.Name + "='" + reader.Value + "'");
Debug.WriteLine(">");
break;
case XmlNodeType.Text: // Get the text in each element.
Debug.WriteLine(reader.Value);

if (reader.Value == tbUsername.Text) bFound = true;
if (bFound)
{
if (j >= 0 && j <= 3)
{
alist.Add(reader.Value);
}
j++;
}
break;
case XmlNodeType.EndElement: //Display the end of the element.
Debug.Write("</" + reader.Name);
Debug.WriteLine(">");
break;
}
}

}
catch (SystemException sex)
{
MessageBox.Show(sex.Message, "Error");
}

Cursor = Cursors.Arrow;

Debug.WriteLine("alist.Count =: " + alist.Count);

if (alist.Count == 0) // never found target username
{
btnCancel_Click(sender, e);
//Application.Exit(); // this doesn't stop the app here but continues to error below
Environment.Exit(0); // this works
}

rcunam = (string)alist[(int)(strcode.CUNAM)]; // remote client username
rcpwd = (string)alist[(int)(strcode.CLPWD)]; // remote client password
rckey = (string)alist[(int)(strcode.CLKEY)]; // remote client key

if (tbUsername.Text == rcunam)
{
Debug.WriteLine("KeyCode: " + rckey);

if (rcunam != tbUsername.Text || rcpwd != tbPassword.Text)
{
m_bCredentials = false;
MessageBox.Show("Problem with username or password. Please try again.");
}
if (rcunam == tbUsername.Text && rcpwd == tbPassword.Text)
{
m_bCredentials = true;
string screds = string.Empty;
if (m_bCredentials) screds = "true";
if (!m_bCredentials) screds = "false";

m_bNormalClose = true;

string[] str = new string[4];
str[0] = screds;
str[1] = rcunam;
str[2] = rcpwd;
str[3] = rckey;

File.WriteAllLines(m_sUserDirPath + "/drop.txt", str);
Application.Exit();
}

}
else
{
MessageBox.Show("We could not verify you credentials in our database. You must verify your credentials in order to run this application.", "Credentials Incorrect");
Application.Exit();
}

}

private void btnCancel_Click(object sender, EventArgs e)
{
string[] str = new string[4];
str[0] = "cancel";
str[1] = rcunam;
str[2] = rcpwd;
str[3] = rckey;

File.WriteAllLines(m_sUserDirPath + "/drop.txt", str);
Application.Exit();
}

 

 

Here's the code for your test app

private void Form1_Load(object sender, EventArgs e)
{
// get locally embedded unique application keycode
string KeyCode = Properties.Settings.Default.KeyCode;
Debug.WriteLine(String.Format("|{0}|", KeyCode));

// set the user envirionment directory path
m_sUserDirPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
m_sUserDirPath += "/AppData/Local/YourCompany/YourAppName";
System.IO.Directory.CreateDirectory(m_sUserDirPath); // create the path if it doesn't exist

try
{
Process firstProc = new Process();
firstProc.StartInfo.FileName = @"WalkIn.exe";

firstProc.EnableRaisingEvents = true;

firstProc.Start();

firstProc.WaitForExit();

}
catch (Exception ex)
{
MessageBox.Show("An error occurred!!!: " + ex.Message);
return;
}

string[] drops = File.ReadAllLines(m_sUserDirPath + "/drop.txt", Encoding.UTF8);

char[] chars = new char[3];
chars[0] = ' ';
chars[1] = '\r';
chars[2] = '\n';

for (int i = 0; i < drops.Length; i++)
{
drops[i] = drops[i].Trim(chars);

}
if (drops[0] == "cancel")
{

File.Delete(m_sUserDirPath + "/drop.txt");
MessageBox.Show("You must verify your credentials in order to run this application.", "Credentials Missing");
Environment.Exit(0);
}
if (drops[3] != KeyCode)
{
File.Delete(m_sUserDirPath + "/drop.txt");
MessageBox.Show("The key to run this application is not valid or has been disabled. Please contact your vender for further information.",
"Credentials Incorrect", MessageBoxButtons.OK, MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
//Application.Exit();
Environment.Exit(0);
}

File.Delete(m_sUserDirPath + "/drop.txt");
}