/* * * Copyright (c) 1999 - 2011 my-Channels Ltd * Copyright (c) 2012 - 2017 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors. * * Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG. * */ using System; using System.Collections.Generic; using com.pcbsys.nirvana.client; namespace com.pcbsys.nirvana.apps{ /** * Deletes a data group */ public class deleteDataGroup : nSampleApp { private static deleteDataGroup mySelf = null; private static Dictionary properties = new Dictionary(); /** * This method demonstrates the Nirvana API calls necessary to delete * a data group. * It is called after all command line arguments have been received and * validated * * @param realmDetails a string[] containing the possible RNAME values * @param dataGroup the data group names to delete */ private void doit(string[] realmDetails, string dataGroup, int deleteType) { mySelf.constructSession(realmDetails); //Deletes the specified data groups try { //Get all data groups so we can delete the wanted group IEnumerable dataGrps = mySession.getDataGroups(); if(deleteType ==1){ //Delete the data groups specified mySession.deleteDataGroup(dataGroup); Console.WriteLine("Successfully deleted group "+ dataGroup); } else if(deleteType ==2){ //Iterate through the array and find our data group nDataGroup group = null; foreach(nDataGroup grp in dataGrps){ if(grp.Name.Equals(dataGroup)){ group = grp; break; } } //Check we have the group if(group == null){ Console.WriteLine("Unable to find the data group you wish to delete, please check name."); } else{ //Delete the data group mySession.deleteDataGroup(group); Console.WriteLine("Successfully deleted group "+ dataGroup); } } } catch (nSecurityException e) { Console.WriteLine("Insufficient permissions for the requested operation."); Console.WriteLine("Please check the ACL settings on the server."); Console.WriteLine(e.StackTrace); Environment.Exit(1); } catch (nSessionNotConnectedException snce) { Console.WriteLine("The session object used is not physically connected to the Nirvana realm."); Console.WriteLine("Please ensure the realm is up and check your RNAME value."); Console.WriteLine(snce.StackTrace); Environment.Exit(1); } catch (nUnexpectedResponseException ure) { Console.WriteLine("The Nirvana REALM has returned an unexpected response."); Console.WriteLine("Please ensure the Nirvana REALM and client API used are compatible."); Console.WriteLine(ure.StackTrace); Environment.Exit(1); } catch (nRequestTimedOutException rtoe) { Console.WriteLine("The requested operation has timed out waiting for a response from the REALM."); Console.WriteLine("If this is a very busy REALM ask your administrator to increase the client timeout values."); Console.WriteLine(rtoe.StackTrace); Environment.Exit(1); } catch (nSessionPausedException e) { Console.WriteLine("Session has been paused, please resume the session"); Console.WriteLine(e.StackTrace); Environment.Exit(1); } catch (nIllegalArgumentException e) { Console.WriteLine("Illegal argument"); Console.WriteLine(e.StackTrace); Environment.Exit(1); }finally{ //Close the session we opened try { nSessionFactory.close(mySession); } catch (Exception ) { } //Close any other sessions within this JVM so that we can exit nSessionFactory.shutdown(); } } protected void processArgs(String[] args) { if(args.Length>0) { if (args[0].Equals("-?")) { Usage(); UsageEnv(); } } switch (args.Length) { case 3: { properties.Add("RNAME", args[0]); properties.Add("DataGroupName", args[1]); properties.Add("DeleteType", args[2]); break; } case 2: { properties.Add("RNAME", args[0]); properties.Add("DataGroupName", args[1]); properties.Add("DeleteType", "1"); break; } default: { Usage(); UsageEnv(); break; } } } public static void Main(String[] args) { //Create an instance for this class mySelf = new deleteDataGroup(); //Process command line arguments mySelf.processArgs(args); //Process Environment Variables nSampleApp.processEnvironmentVariables(); //Check the data group name specified string dataGroupName = properties["DataGroupName"]; string deleteTypeStr = properties["DeleteType"]; string RNAME = properties["RNAME"]; if (dataGroupName == null || dataGroupName.Length<1 || deleteTypeStr ==null || deleteTypeStr.Length<1){ Usage(); Environment.Exit(1); } int deleteType = int.Parse(deleteTypeStr); if(deleteType!=1 && deleteType!=2){ Usage(); Environment.Exit(1); } //Process the local REALM RNAME details String[] rproperties = new String[4]; rproperties = parseRealmProperties(RNAME); //delete the data group specified mySelf.doit(rproperties, dataGroupName, deleteType); } /** * Prints the usage message for this class */ private static void Usage() { Console.WriteLine("Usage ...\n"); Console.WriteLine("deleteDataGroups [delete type] \n"); Console.WriteLine(" \n"); Console.WriteLine(" - RNAME for the realm to connect to"); Console.WriteLine(" - Data group name parameter to delete"); Console.WriteLine(" \n"); Console.WriteLine("[Delete Type] - Data group delete by string(1) or object(2) default:1"); Console.WriteLine("\n\nNote: -? provides help on environment variables \n"); } } // End of deleteDataGroup Class }