static void Main(string[] args) { // Initialize agent with default persistor DeviceProfilePersistorDefault persistor = new DeviceProfilePersistorDefault(); Agent agent = new Agent(); // Intialize Agent. try { agent.SetMetadata(Agent.MetaApplicationName, "CheckProfiles Sample"); agent.Initialize(persistor); } catch (SdkException sdkExp) { Console.WriteLine("Agent initialization error: " + sdkExp.Message); WaitForInput(); Environment.Exit(1); } // Check if there are profiles. // This code below will work for all persistor types. if (!agent.HasAnyProfiles) { Console.WriteLine("There are no device profiles on this device."); WaitForInput(); Environment.Exit(1); } foreach (DeviceProfile profile in agent.AllProfiles) { Console.WriteLine("Name: " + profile.Name + ", Id: " + profile.DeviceId); } // Check if there is an active profile. if (agent.HasActiveProfile) { Console.WriteLine("\nActive profile, Name: " + agent.ActiveProfile.Name + ", Id: " + agent.ActiveProfile.DeviceId); } else { Console.WriteLine("There is not an active device profile selected on this device."); } WaitForInput(); }
public void TestDefaultPersistor() { DeviceProfilePersistorPlaintext plainpersistor = new DeviceProfilePersistorPlaintext(); plainpersistor.FilePath = "C:\\Users\\jimmy.inIS\\Desktop\\plaintext.txt"; Console.WriteLine(plainpersistor.FilePath); DeviceProfilePersistorDefault persistor = new DeviceProfilePersistorDefault(); //load profiles List <DeviceProfile> profiles = null; String activeDeviceId = null; plainpersistor.LoadAllProfiles(ref profiles, ref activeDeviceId); Console.WriteLine(activeDeviceId); Agent agent = new Agent(); agent.Initialize(plainpersistor); CreateKeysRequest.Key requestKey = new CreateKeysRequest.Key("refid_test"); requestKey.Attributes.Add("classifications", new List <string>()); requestKey.Attributes["classifications"].Add("c1"); CreateKeysRequest request = new CreateKeysRequest(); request.Keys.Add(requestKey); CreateKeysResponse response = agent.CreateKeys(request); /* * persistor.SaveAllProfiles(profiles, activeDeviceId); * * List<DeviceProfile> profiles2 = null; * String activeDeviceId2 = null; * persistor.LoadAllProfiles(ref profiles2, ref activeDeviceId2); * * Console.WriteLine("----------------"); * Console.WriteLine(activeDeviceId); * * Assert.AreEqual(profiles.Count, profiles2.Count); * Assert.AreEqual(activeDeviceId, activeDeviceId2); */ }
static int convertSepDefaultToPassword(string passwordSepPath, string passwordSepPassword) { // Temporary variables to hold profiles during conversion. string sActiveDeviceId = null; List <IonicSecurity.SDK.DeviceProfile> lstProfiles = new List <IonicSecurity.SDK.DeviceProfile>(); // First create an default persistor that will read in a SEP that you have with your platform's default persistor, // for example, one that you created using the Ionic Manager enrollment tool. DeviceProfilePersistorDefault defaultPersistor = new DeviceProfilePersistorDefault(); try { defaultPersistor.LoadAllProfiles(ref lstProfiles, ref sActiveDeviceId); } catch (SdkException e) { Console.WriteLine("Error loading profiles from default SEP persistor: {0}", e.Message); return(-1); } Console.WriteLine("{0} profiles loaded by the default persistor.", lstProfiles.Count); // Now we create another persistor that outputs the profiles we loaded in a password protected SEP DeviceProfilePersistorPassword passwordPersistor = new DeviceProfilePersistorPassword(); passwordPersistor.FilePath = passwordSepPath; passwordPersistor.Password = passwordSepPassword; // Save the profiles using the password persistor. try { passwordPersistor.SaveAllProfiles(lstProfiles, sActiveDeviceId); } catch (SdkException e) { Console.WriteLine("Error saving profiles with the password-protected SEP: {0}", e.Message); return(-2); } Console.WriteLine("Profiles saved to password persistor, in encrypted file {0}", passwordSepPath); return(0); }