static List <DeviceProfile> GetDeviceProfilesFromPlaintextPersistor() { // Set the persistor's path. String persistorPath = "../../../../../../sample-data/persistors/sample-persistor.pt"; // Create a blank agent. Agent ptAgent = new Agent(); // Create a plaintext persistor and initialize the agent. try { DeviceProfilePersistorPlaintext persistor = new DeviceProfilePersistorPlaintext(); persistor.FilePath = persistorPath; ptAgent.SetMetadata(Agent.MetaApplicationName, "ProfileConversion Sample (plaintext persistor)"); ptAgent.Initialize(persistor); } catch (SdkException sdkExp) { Console.WriteLine("Plaintext agent initialization error: " + sdkExp.Message); WaitForInput(); Environment.Exit(1); } // Return the device profiles. List <DeviceProfile> profiles = ptAgent.AllProfiles; return(profiles); }
public static Agent getTestAgent(AgentConfig config = null) { Agent agent = new Agent(); DeviceProfilePersistorPlaintext persistor = new DeviceProfilePersistorPlaintext(); persistor.FilePath = AgentTestUtils.buildInputPath("plaintext.sep"); if (config != null) { agent.Initialize(config, persistor); } else { agent.Initialize(persistor); } return(agent); }
static void Main(string[] args) { // Set the persistor's path. String persistorPath = "../../../../../../sample-data/persistors/sample-persistor.pt"; // Create an agent object to talk to Ionic. Agent agent = new Agent(); // Create a plaintext persistor and initialize the agent. try { DeviceProfilePersistorPlaintext persistor = new DeviceProfilePersistorPlaintext(); persistor.FilePath = persistorPath; agent.SetMetadata(Agent.MetaApplicationName, "InitializeAgentWithPlaintextPersistor Sample"); agent.Initialize(persistor); } catch (SdkException sdkExp) { Console.WriteLine("Agent initialization error: " + sdkExp.Message); WaitForInput(); Environment.Exit(1); } // Get the profiles and check if the are any. List <DeviceProfile> profiles = agent.AllProfiles; if (profiles.Count == 0) { Console.WriteLine("No profiles for plaintext persistor."); WaitForInput(); return; } // Display profile information. foreach (DeviceProfile profile in profiles) { Console.WriteLine("-----"); Console.WriteLine("ID : " + profile.DeviceId); Console.WriteLine("Name : " + profile.Name); Console.WriteLine("Keyspace : " + profile.KeySpace); Console.WriteLine("API URL : " + profile.Server); } 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 void Main(string[] args) { // Set the persistor's path. String persistorPath = "../../../../../../sample-data/persistors/sample-persistor.pt"; // Set the active profile to the hard-coded profile device ID. String profileId = "ABcd.1.48sdf0-cs80-5802-sd80-d8s0df80sdfj"; // Create an agent object to talk to Ionic. Agent agent = new Agent(); // Create a plaintext persistor and initialize the agent. DeviceProfilePersistorPlaintext persistor = new DeviceProfilePersistorPlaintext(); try { persistor.FilePath = persistorPath; agent.SetMetadata(Agent.MetaApplicationName, "SetActiveProfile Sample"); agent.Initialize(persistor); } catch (SdkException sdkExp) { Console.WriteLine("Agent initialization error: " + sdkExp.Message); WaitForInput(); Environment.Exit(1); } // Get the profiles and check if the are any. List <DeviceProfile> profiles = null; try { profiles = agent.AllProfiles; } catch (SdkException sdkExp) { Console.WriteLine("Agent get all profiles error: " + sdkExp.Message); WaitForInput(); Environment.Exit(1); } // Verify there is at one profile. if (profiles.Count == 0) { Console.WriteLine("No profiles for plaintext persistor."); WaitForInput(); return; } // Display current profile information. Console.WriteLine("Available Profiles:"); foreach (DeviceProfile profile in profiles) { Console.WriteLine(profile.DeviceId); } // If the number of profiles is equal to one, then there is nothing to set. if (profiles.Count == 1) { Console.WriteLine("Only one profile, nothing to change."); WaitForInput(); return; } // Set the active profile with a profile device ID. Console.WriteLine("\nSetting {0} as the active profile.", profileId); try { agent.SetActiveProfileById(profileId); } catch (SdkException sdkExp) { Console.WriteLine("Failed to set active profile to: " + profileId); Console.WriteLine("SetActiveProfileById error: " + sdkExp.Message); WaitForInput(); Environment.Exit(1); } // Get the current active profile DeviceProfile activeProfile = agent.ActiveProfile; // Display active profile information. Console.WriteLine("\nActive Profile:"); Console.WriteLine("ID : " + activeProfile.DeviceId); Console.WriteLine("Name : " + activeProfile.Name); Console.WriteLine("Keyspace : " + activeProfile.KeySpace); Console.WriteLine("API URL : " + activeProfile.Server); WaitForInput(); }