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 Main(string[] args) { // Get the user's home path and password persistor from the environment. String homePath = Environment.GetEnvironmentVariable("USERPROFILE"); String persistorPassword = Environment.GetEnvironmentVariable("IONIC_PERSISTOR_PASSWORD"); if (persistorPassword == null || persistorPassword.Length == 0) { Console.WriteLine("Please provide the persistor password as env variable: IONIC_PERSISTOR_PASSWORD"); WaitForInput(); Environment.Exit(1); } // Create an agent object to talk to Ionic. Agent agent = new Agent(); // Create a password persistor for agent initialization. try { DeviceProfilePersistorPassword persistor = new DeviceProfilePersistorPassword(); persistor.FilePath = homePath + "\\.ionicsecurity\\profiles.pw"; persistor.Password = persistorPassword; agent.SetMetadata(Agent.MetaApplicationName, "CreateMultipleKeys Sample"); agent.Initialize(persistor); } catch (SdkException sdkExp) { Console.WriteLine("Agent initialization error: " + sdkExp.Message); WaitForInput(); Environment.Exit(1); } String keyRef = "sample"; int keyCount = 5; // Create multiple keys request. CreateKeysRequest.Key keysToCreate = new CreateKeysRequest.Key(keyRef, keyCount); CreateKeysRequest createKeysRequest = new CreateKeysRequest(); createKeysRequest.Keys.Add(keysToCreate); // Invoke the agent to create the keys. CreateKeysResponse createKeysResponse = null; try { createKeysResponse = agent.CreateKeys(createKeysRequest); } catch (SdkException sdkExp) { Console.WriteLine("Create multiple keys error: " + sdkExp.Message); WaitForInput(); Environment.Exit(1); } // Pull the keys out of the response. List <CreateKeysResponse.Key> keys = createKeysResponse.Keys; foreach (CreateKeysResponse.Key key in keys) { Console.WriteLine("Key ID : " + key.Id); Console.WriteLine("Key Bytes : " + BitConverter.ToString(key.KeyBytes).Replace("-", String.Empty)); Console.WriteLine("Fixed Attributes : " + JsonDump(key.Attributes)); Console.WriteLine("Mutable Attributes : " + JsonDump(key.MutableAttributes)); } WaitForInput(); return(0); }