/************************************************************************** Copyright (c) [2005] Novell, Inc. All Rights Reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, if not, contact Novell, Inc. To contact Novell about this file by physical or electronic mail, you may find current contact information at www.novell.com. **************************************************************************/ using System; using Novell.CASA; namespace cSharpTest { /// /// Summary description for Class1. /// class Class1 { private static string APPID = "cSharpAppID"; //private static string SHARED_ID = "cSharp_SharedID"; private static string USERNAME = "Admin.nov€ll"; private static string PASSWORD = "PasswordFor€Admin"; /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { Console.WriteLine("**************************************************"); Console.WriteLine("********** miCASA Sample written in C# ***********"); Console.WriteLine("**************************************************"); ShowMenu(); } static private void ShowMenu() { while (true) { Console.WriteLine(); Console.WriteLine("********** Menu ***********"); Console.WriteLine("* 1. Add secret *"); Console.WriteLine("* 2. Display secret *"); Console.WriteLine("* 3. Remove secret *"); Console.WriteLine("* 4. Run automated test *"); Console.WriteLine("* 5. Quit *"); Console.WriteLine("***************************"); Console.WriteLine("Select option and Press enter"); String line = Console.ReadLine(); if (line.Length > 0) { char[] c = line.Substring(0, 1).ToCharArray(); if (c.Length > 0) { if (c[0].Equals('5')) break; if (c[0].Equals('1')) AddSecret(); else if (c[0].Equals('2')) DisplaySecret(); else if (c[0].Equals('3')) RemoveSecret(); else if (c[0].Equals('4')) RunTest(); } } } } static private void AddSecret() { while (true) { Console.Write("Enter SecretID: "); String sID = Console.ReadLine(); Console.Write("Enter Username: "); String sUsername = Console.ReadLine(); Console.Write("Enter Password: "); String sPassword = Console.ReadLine(); if (sID != null && sUsername != null && sPassword != null) { try { //miCASA.SetBasicCredential(sID, null, sUsername, sPassword); miCASA.SetCredential(0, sID, null, miCASA.USERNAME_TYPE_CN_F, sUsername, sPassword); } catch (miCasaException e) { Console.WriteLine(e.getMessage()); } return; } else { Console.WriteLine("Invalid input, try again"); } } } static private void RemoveSecret() { Console.Write("Enter SecretID to remove: "); String sID = Console.ReadLine(); if (sID != null) { try { miCASA.RemoveBasicCredential(sID, null); } catch (miCasaException e) { Console.WriteLine(e.getMessage()); } } } static private void DisplaySecret() { Console.Write("Enter SecretID to display: "); String sID = Console.ReadLine(); if (sID != null) { try { BasicCredential bc; //bc = miCASA.GetBasicCredential(sID, null); bc = miCASA.GetCredential(0, sID, null, miCASA.USERNAME_TYPE_CN_F); if (bc != null) { Console.WriteLine("Data for "+sID); Console.WriteLine("------------------------"); Console.WriteLine("Username:" + bc.GetUsername()); Console.WriteLine("Password:" + bc.GetPassword()); Console.WriteLine("------------------------"); Console.WriteLine("Press the Enter key to continue"); Console.ReadLine(); } else Console.WriteLine(sID + " not found"); } catch (miCasaException e) { Console.WriteLine(e.getMessage()); } } } static private void RunTest() { int count = 1; Console.Write("Enter times to run: "); String sCount = Console.ReadLine(); try { int icount = int.Parse(sCount); count = icount; } catch (Exception) { } for (int i=0; i