1
Fork 0

Added development testing projects to Repo

This commit is contained in:
Jake Howard 2014-06-25 21:52:11 +01:00
parent e1f115d9df
commit d14a218584
3 changed files with 162 additions and 0 deletions

View File

@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace USB_Detection_and_XML_Reading
{
class Program
{
static void Main(string[] args)
{
string[] foundDrives= cycleDrivesForFile();
Console.WriteLine("Cycle Ended!");
foreach (char drive in foundDrives)
{
Console.WriteLine("File found on drive " + drive + ":\\");
}
Console.ReadKey();
}
static bool fileExists(string driveLetter)
{
string path = driveLetter + "config.sbf";
return File.Exists(path);
}
static string[] cycleDrivesForFile()
{
/*
char[] letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
char[] systemDrives = "C".ToCharArray(); //Scan will not look in these drives
int count = 0;
foreach (char driveLetter in letters)
{
if (systemDrives.Contains(driveLetter))
{
continue;
}
if (fileExists(driveLetter))
{
foundDrives.Add(driveLetter);
}
}
return foundDrives.ToArray();
*/
List<string> foundDrives = new List<string>();
DriveInfo[] driveArray = DriveInfo.GetDrives();
for (int i = 0; i < driveArray.Count(); i++)
{
if (fileExists(driveArray[i].Name))
{
foundDrives.Add(driveArray[i].Name);
}
Console.WriteLine("Drive " + i + ": " + driveArray[i].Name);
}
return foundDrives.ToArray();
}
}
}

View File

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.IO;
namespace Read_USB_XML
{
class Program
{
static void Main(string[] args)
{
DriveInfo[] drives = DriveInfo.GetDrives();
for (int i = 0; i < drives.Count(); i++)
{
string driveName;
string driveLetter;
try //if the volume label is invalid (CD Drive in laptop), then the program crashes
{
driveName = drives[i].VolumeLabel;
driveLetter = drives[i].Name;
} catch {
continue;
}
if (driveName == "")
{
driveName = "Unnamed Volume";
}
Console.WriteLine("Drive " + i + ": " + driveLetter + ". Drive Label: " + driveName);
}
Console.ReadKey();
}
}
}

View File

@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
namespace Background_Worker_Testing
{
class worker
{
public void do_Work()
{
while (_ThreadActive)
{
Console.WriteLine("Thread Processing with ID " + id);
System.Threading.Thread.Sleep(id * 755);
}
}
public void request_Stop()
{
_ThreadActive = false;
}
private volatile bool _ThreadActive = true;
public volatile int id;
}
class Program
{
public static int count1 = 0;
public static int count2 = 0;
static void Main(string[] args)
{
Console.WriteLine("Program Started.");
worker worker1 = new worker();
worker worker2 = new worker();
worker1.id = 1;
worker2.id = 2;
Console.WriteLine("Workers defined.");
Thread thread1 = new Thread(worker1.do_Work);
Thread thread2 = new Thread(worker2.do_Work);
Console.WriteLine("Threads Defined");
thread1.Start();
while (!thread1.IsAlive);
Console.WriteLine("Thread 1 has begun!");
thread2.Start();
while (!thread2.IsAlive);
Console.WriteLine("Thread 2 has begun!");
System.Threading.Thread.Sleep(5000);
Console.WriteLine("Stopping Threads...");
worker1.request_Stop();
while (thread1.IsAlive);
worker2.request_Stop();
while (thread2.IsAlive);
Console.WriteLine("Threads Stopped.");
Console.ReadKey();
}
}
}