using System;
using System.Net;
using System.Reflection ;
using Novell.Security.ClientPasswordManager;


namespace Tester
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Class1
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{															
			// call NetCredential code
			NetCredential nc = new NetCredential("Ifolder", "Network", true, "jnorman", "novell");
			NetCredential nc2 = new NetCredential("Ifolder", null, false, "ifolderusername", "novell");

			NetworkCredential nwc = nc2.GetCredential(new System.Uri("http://IFolder"), "Basic");
				
			if (nwc != null)
			{
				Console.WriteLine("Username: "+ nwc.UserName);
				Console.WriteLine("Password: "+ nwc.Password);
			}

			/*
				// call SetCredential
				Type type = assembly.GetType("Novell.CASA.miCASA");
				MemberInfo[] members = type.GetMembers();

				object Instance = Activator.CreateInstance (type);				

				object[] cargs = new object[4];
				//cargs[0] = 0;				
				cargs[0] = "AppSecretIDTest";
				cargs[1] = null; //"SharedSecretIDTEST";
				//cargs[3] = 0;
				cargs[2] = "Username";
				cargs[3] = "password";
				
				object result; // = type.InvokeMember ("SetCredential" ,BindingFlags.InvokeMethod ,null,Instance,cargs);
				// call SetBasicCredential
				try
				{					
					type.InvokeMember("SetBasicCredential", BindingFlags.InvokeMethod, null, Instance, cargs);
				}
				catch (Exception e)
				{
					Console.WriteLine(e.ToString());
				}


				// now get the basicCred back
				try
				{
					object[] getArgs = new object[2];
					getArgs[0] = "AppSecretIDTest";
					getArgs[1] = null;


					result = type.InvokeMember("GetCredentialUsername", BindingFlags.InvokeMethod, null, Instance, getArgs);
					Console.WriteLine("Username: "+result.ToString());

					result = type.InvokeMember("GetCredentialPassword", BindingFlags.InvokeMethod, null, Instance, getArgs);
					Console.WriteLine("Password: "+result.ToString());
					// invoke the GetUsername and GetPassword methods
					//Type basicCred = assembly.GetType("Novell.CASA.miCASA.BasicCredential");
					//object username = basicCred.InvokeMember("GetUsername", BindingFlags.InvokeMethod, null, result, null);
					//object password = basicCred.InvokeMember("GetPassword", BindingFlags.InvokeMethod, null, result, null);
				}
				catch (Exception e)
				{
					Console.WriteLine(e.ToString());
				}
				*/				
			
		}
	}
}