// Example URL (GET) // ----------------------------------------------------- // ../api/devices/check?token=01234&sender_id=56789 (Check all devices for the user) // OR // ../api/devices/check?token=01234&sender_id=56789&unique_id=ABCDEFG (Check only the device with the specified 'unique_id') // ----------------------------------------------------- // Example Post Data // ----------------------------------------------------- // name = 'token' // value = 01234 (Session Token) // name = 'sender_id' // value = 56789 (Sender ID) // (Optional) // name = 'devices' // value = [ // { "unique_id": "ABCDEFG" }, // { "unique_id": "HIJKLMN" } // ] // ----------------------------------------------------- /// <summary> /// Check the status (Update Id) of a single Device /// </summary> /// <param name="userConfig">UserConfiguration object for the current user</param> /// <param name="deviceUniqueId">The Unique ID of the device to return</param> /// <returns></returns> public static CheckInfo Check(UserConfiguration userConfig, string deviceUniqueId) { if (!string.IsNullOrEmpty(deviceUniqueId)) { Uri apiHost = ApiConfiguration.AuthenticationApiHost; string url = new Uri(apiHost, "devices/check/index.php").ToString(); string format = "{0}?token={1}&sender_id={2}{3}"; string token = userConfig.SessionToken; string senderId = UserManagement.SenderId.Get(); string uniqueId = "unique_id=" + deviceUniqueId; url = string.Format(format, url, token, senderId, uniqueId); string response = HTTP.GET(url); if (response != null) { bool success = ApiError.ProcessResponse(response, "Check Device"); } } return(null); }
// Example URL (GET) // ----------------------------------------------------- // ../api/devices/list?token=01234&sender_id=56789 (List all devices for the user) // OR // ../api/devices/list?token=01234&sender_id=56789&unique_id=ABCDEFG (List only the device with the specified 'unique_id') // ----------------------------------------------------- // Example Post Data // ----------------------------------------------------- // name = 'token' // value = 01234 (Session Token) // name = 'sender_id' // value = 56789 (Sender ID) // (Optional) // name = 'devices' // value = [ // { "unique_id": "ABCDEFG" }, // { "unique_id": "HIJKLMN" } // ] // ----------------------------------------------------- /// <summary> /// List a single DeviceDescription /// </summary> /// <param name="userConfig">UserConfiguration object for the current user</param> /// <param name="deviceUniqueId">The Unique ID of the device to return</param> /// <returns></returns> public static DeviceDescription List(UserConfiguration userConfig, string deviceUniqueId, Uri apiHost) { if (!string.IsNullOrEmpty(deviceUniqueId)) { string url = new Uri(apiHost, "devices/list/index.php").ToString(); if (userConfig != null) { string format = "{0}?token={1}&sender_id={2}&unique_id={3}"; string token = userConfig.SessionToken; string senderId = UserManagement.SenderId.Get(); url = string.Format(format, url, token, senderId, deviceUniqueId); } string response = HTTP.GET(url); if (response != null) { bool success = ApiError.ProcessResponse(response, "List Devices"); if (success) { var deviceInfos = JSON.ToType <List <Data.DeviceInfo> >(response); if (deviceInfos != null && deviceInfos.Count > 0) { return(new DeviceDescription(deviceInfos[0])); } } } } return(null); }
/// <summary> /// Check the status (Update Id) for a list of devices /// </summary> /// <param name="userConfig">UserConfiguration object for the current user</param> /// <returns></returns> public static List <CheckInfo> Check(UserConfiguration userConfig) { Uri apiHost = ApiConfiguration.AuthenticationApiHost; string url = new Uri(apiHost, "devices/check/index.php").ToString(); string format = "{0}?token={1}&sender_id={2}"; string token = userConfig.SessionToken; string senderId = UserManagement.SenderId.Get(); url = string.Format(format, url, token, senderId); string response = HTTP.GET(url); if (response != null) { bool success = ApiError.ProcessResponse(response, "Check Devices"); if (success) { if (response == "No Devices Found") { return(null); } else { return(JSON.ToType <List <CheckInfo> >(response)); } } } return(null); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldMountUnmanagedExtensionsByPackage() public virtual void ShouldMountUnmanagedExtensionsByPackage() { // When using (ServerControls server = GetTestServerBuilder(TestDir.directory()).withExtension("/path/to/my/extension", "org.neo4j.harness.extensionpackage").newServer()) { // Then assertThat(HTTP.GET(server.HttpURI().ToString() + "path/to/my/extension/myExtension").status(), equalTo(234)); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldExtensionWork() public virtual void ShouldExtensionWork() { // Given the rule in the beginning of this class // When I run this test // Then assertThat(HTTP.GET(Neo4j.httpURI().resolve("test/myExtension").ToString()).status(), equalTo(234)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReturnEmptyMapForEmptyProperties() public virtual void ShouldReturnEmptyMapForEmptyProperties() { // Given string node = HTTP.POST(Server().baseUri().resolve("db/data/node").ToString()).location(); string rel = HTTP.POST(node + "/relationships", quotedJson("{'to':'" + node + "', " + "'type':'LOVES'}")).location(); // When HTTP.Response res = HTTP.GET(rel + "/properties"); // Then MatcherAssert.assertThat(res.RawContent(), equalTo("{ }")); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReportCommunityEdition() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldReportCommunityEdition() { // Given string releaseVersion = Server.Database.Graph.DependencyResolver.resolveDependency(typeof(KernelData)).version().ReleaseVersion; // When HTTP.Response res = HTTP.GET(FunctionalTestHelper.managementUri() + "/" + VersionAndEditionService.SERVER_PATH); // Then assertEquals(200, res.Status()); assertThat(res.Get("edition").asText(), equalTo("community")); assertThat(res.Get("version").asText(), equalTo(releaseVersion)); }
/// <summary> /// Get a list of DeviceConfigurations of all of the user's devices /// </summary> /// <param name="userConfig">UserConfiguration object for the current user</param> /// <returns></returns> public static List <DeviceConfiguration> Get(UserConfiguration userConfig) { Uri apiHost = ApiConfiguration.AuthenticationApiHost; string url = new Uri(apiHost, "devices/get/index.php").ToString(); string format = "{0}?token={1}&sender_id={2}"; string token = userConfig.SessionToken; string senderId = UserManagement.SenderId.Get(); url = string.Format(format, url, token, senderId); string response = HTTP.GET(url); if (response != null) { bool success = ApiError.ProcessResponse(response, "Get Devices"); if (success) { var deviceInfos = JSON.ToType <List <DeviceInfo> >(response); if (deviceInfos != null) { var deviceConfigs = new List <DeviceConfiguration>(); foreach (var deviceInfo in deviceInfos) { var table = deviceInfo.ToTable(); if (table != null) { var xml = DeviceConfiguration.TableToXml(table); if (xml != null) { var deviceConfig = DeviceConfiguration.Read(xml); if (deviceConfig != null && !string.IsNullOrEmpty(deviceConfig.UniqueId)) { deviceConfigs.Add(deviceConfig); } } } } return(deviceConfigs); } } } return(null); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldLaunchAServerInSpecifiedDirectory() public virtual void ShouldLaunchAServerInSpecifiedDirectory() { // Given File workDir = TestDir.directory("specific"); // When using (ServerControls server = GetTestServerBuilder(workDir).newServer()) { // Then assertThat(HTTP.GET(server.HttpURI().ToString()).status(), equalTo(200)); assertThat(workDir.list().length, equalTo(1)); } // And after it's been closed, it should've cleaned up after itself. assertThat(Arrays.ToString(workDir.list()), workDir.list().length, equalTo(0)); }
public static List <MessageInfo> Get(UserConfiguration userConfig, List <string> messageIds) { Uri apiHost = ApiConfiguration.AuthenticationApiHost; string url = new Uri(apiHost, "messages/get/index.php").ToString(); string format = "{0}?token={1}&sender_id={2}{3}"; string token = userConfig.SessionToken; string senderId = UserManagement.SenderId.Get(); string devices = ""; // List Message IDs to Get // If no Messages are listed then ALL Messages are retrieved if (messageIds != null) { string json = JSON.FromList <string>(messageIds); if (!string.IsNullOrEmpty(json)) { devices = "messages=" + json; } } url = string.Format(format, url, token, senderId, devices); var httpInfo = new HTTP.HTTPInfo(); httpInfo.Url = url; httpInfo.MaxAttempts = 1; string response = HTTP.GET(httpInfo); if (response != null) { bool success = ApiError.ProcessResponse(response, "Get Messages"); if (success) { var messageInfos = JSON.ToType <List <MessageInfo> >(response); if (messageInfos != null) { return(messageInfos); } } } return(null); }
public static bool CheckUsernameAvailability(string username) { bool result = false; if (!string.IsNullOrEmpty(username)) { string url = new Uri(ApiConfiguration.AuthenticationApiHost, "users/checkusername/index.php").ToString(); url += "?username="******"Username Check"); } } return(result); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void assertDBConfig(ServerControls server, String expected, String key) throws org.neo4j.server.rest.domain.JsonParseException private void AssertDBConfig(ServerControls server, string expected, string key) { JsonNode beans = HTTP.GET(server.HttpURI().ToString() + "db/manage/server/jmx/domain/org.neo4j/").get("beans"); JsonNode configurationBean = FindNamedBean(beans, "Configuration").get("attributes"); bool foundKey = false; foreach (JsonNode attribute in configurationBean) { if (attribute.get("name").asText().Equals(key)) { assertThat(attribute.get("value").asText(), equalTo(expected)); foundKey = true; break; } } if (!foundKey) { fail("No config key '" + key + "'."); } }
public static ApiConfiguration Get(IPAddress address) { if (address != null) { try { string response = HTTP.GET("http://" + address.ToString() + ":" + PORT + "/api/config"); if (response != null) { return(JSON.ToType <ApiConfiguration>(response)); } } catch (Exception ex) { Logger.Log("Error Connecting to " + address.ToString() + " :: " + ex.Message); } } return(null); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAllowCustomServerAndDbConfig() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldAllowCustomServerAndDbConfig() { // Given TrustAllSSLCerts(); // Get default trusted cypher suites SSLServerSocketFactory ssf = ( SSLServerSocketFactory )SSLServerSocketFactory.Default; string[] defaultCiphers = ssf.DefaultCipherSuites; // When HttpConnector httpConnector = new HttpConnector("0", HttpConnector.Encryption.NONE); HttpConnector httpsConnector = new HttpConnector("1", HttpConnector.Encryption.TLS); using (ServerControls server = GetTestServerBuilder(TestDir.directory()).withConfig(httpConnector.Type, "HTTP").withConfig(httpConnector.Enabled, "true").withConfig(httpConnector.Encryption, "NONE").withConfig(httpConnector.ListenAddress, "localhost:0").withConfig(httpsConnector.Type, "HTTP").withConfig(httpsConnector.Enabled, "true").withConfig(httpsConnector.Encryption, "TLS").withConfig(httpsConnector.ListenAddress, "localhost:0").withConfig(GraphDatabaseSettings.dense_node_threshold, "20").withConfig("https.ssl_policy", "test").withConfig("dbms.ssl.policy.test.base_directory", TestDir.directory("certificates").AbsolutePath).withConfig("dbms.ssl.policy.test.allow_key_generation", "true").withConfig("dbms.ssl.policy.test.ciphers", string.join(",", defaultCiphers)).withConfig("dbms.ssl.policy.test.tls_versions", "TLSv1.2, TLSv1.1, TLSv1").withConfig("dbms.ssl.policy.test.client_auth", ClientAuth.NONE.name()).withConfig("dbms.ssl.policy.test.trust_all", "true").newServer()) { // Then assertThat(HTTP.GET(server.HttpURI().ToString()).status(), equalTo(200)); assertThat(HTTP.GET(server.HttpsURI().get().ToString()).status(), equalTo(200)); AssertDBConfig(server, "20", GraphDatabaseSettings.dense_node_threshold.name()); } }
/// <summary> /// Get a list of DeviceDescriptions of all of the user's devices /// </summary> /// <param name="userConfig">UserConfiguration object for the current user</param> /// <returns></returns> public static List <DeviceDescription> List(UserConfiguration userConfig, Uri apiHost) { string url = new Uri(apiHost, "devices/list/index.php").ToString(); if (userConfig != null) { string format = "{0}?token={1}&sender_id={2}"; string token = userConfig.SessionToken; string senderId = UserManagement.SenderId.Get(); url = string.Format(format, url, token, senderId); } string response = HTTP.GET(url); if (response != null) { bool success = ApiError.ProcessResponse(response, "List Devices"); if (success) { var deviceInfos = JSON.ToType <List <Data.DeviceInfo> >(response); if (deviceInfos != null) { var devices = new List <DeviceDescription>(); foreach (var deviceInfo in deviceInfos) { devices.Add(new DeviceDescription(deviceInfo)); } return(devices); } } } return(null); }
/// <summary> /// User Login using Remember Token /// </summary> public static UserConfiguration TokenLogin(string token, string note = "") { UserConfiguration result = null; if (token != null && token.Length > 0) { string senderId = SenderId.Get(); string url = new Uri(ApiConfiguration.AuthenticationApiHost, "users/login/?token=" + token + "&sender_id=" + senderId + "¬e=" + note).ToString(); string response = HTTP.GET(url); if (response != null) { var success = ApiError.ProcessResponse(response, "User Token Login"); if (success) { result = UserConfiguration.Get(response); } } } return(result); }
/// <summary> /// Used to Logout a currently logged in user /// </summary> public static bool Logout(string token = null) { bool result = false; string url = new Uri(ApiConfiguration.AuthenticationApiHost, "users/logout/index.php").ToString(); string senderId = SenderId.Get(); url += "?sender_id=" + SenderId.Get(); if (token != null) { url += "&token=" + token; } string response = HTTP.GET(url); if (!string.IsNullOrEmpty(response)) { result = ApiError.ProcessResponse(response, "User Logout"); } return(result); }
public static Image DownloadImagev1(UserConfiguration userConfig, string fileId, bool useCache) { Image result = null; if (useCache) { if (cachedImages == null) { LoadCachedImages(); } var cachedImage = cachedImages.Find(o => o.Id == fileId); if (cachedImage != null) { result = cachedImage.Image; } } if (result == null && userConfig != null) { Uri apiHost = ApiConfiguration.AuthenticationApiHost; string url = new Uri(apiHost, "files/download/index.php").ToString(); string format = "{0}?token={1}&sender_id={2}&file_id={3}"; string token = userConfig.SessionToken; string senderId = UserManagement.SenderId.Get(); url = string.Format(format, url, token, senderId, fileId); var response = HTTP.GET(url, true); if (response != null && response.Body != null && response.Headers != null) { bool success = false; string dummy = System.Text.Encoding.ASCII.GetString(response.Body); // Takes forever to process an image if (response.Body.Length < 500) { success = ApiError.ProcessResponse(response, "Download File"); } else { success = true; } if (success) { try { using (var memStream = new MemoryStream()) { memStream.Write(response.Body, 0, response.Body.Length); result = Image.FromStream(memStream); Logger.Log("Download File Successful", LogLineType.Notification); } } catch (Exception ex) { Logger.Log("Response Not an Image : Exception : " + ex.Message); } } // Add Image to Cache if (useCache && result != null) { AddImageToCache(new CachedImage(fileId, result)); } } } return(result); }
public static bool Download(UserConfiguration userConfig, string fileId, string destinationPath) { bool result = false; if (userConfig != null && !string.IsNullOrEmpty(destinationPath)) { if (!File.Exists(destinationPath)) { Uri apiHost = ApiConfiguration.AuthenticationApiHost; string url = new Uri(apiHost, "files/download/index.php").ToString(); string format = "{0}?token={1}&sender_id={2}&file_id={3}"; string token = userConfig.SessionToken; string senderId = UserManagement.SenderId.Get(); url = string.Format(format, url, token, senderId, fileId); var response = HTTP.GET(url, true); if (response != null && response.Body != null && response.Headers != null) { string filename = Path.GetFileName(destinationPath); string dir = destinationPath; // Make sure destination directory exists if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } if (string.IsNullOrEmpty(filename)) { // Get filename from HTTP Header var header = response.Headers.ToList().Find(x => x.Key == "Content-Disposition"); if (header != null && header.Value != null) { try { if (header.Value.Contains("filename")) { string s = header.Value; int i = s.IndexOf("filename"); if (i >= 0) { i = s.IndexOf("=", i); } if (i >= 0) { i = s.IndexOf("\"", i); } if (i >= 0) { i++; int x = s.IndexOf("\"", i); if (x >= 0) { filename = s.Substring(i, x - i); } } } } catch (Exception ex) { Logger.Log("Error Reading Filename from Download Response Header"); } } } if (filename != null && dir != null) { string dest = Path.Combine(dir, filename); try { using (var fileStream = new FileStream(dest, FileMode.CreateNew, FileAccess.ReadWrite)) using (var memStream = new MemoryStream()) { memStream.Write(response.Body, 0, response.Body.Length); memStream.WriteTo(fileStream); } Logger.Log("Download File Successful", LogLineType.Notification); result = true; } catch (Exception ex) { Logger.Log("Download File Error : Exception : " + ex.Message); } } } } else { Logger.Log("Download File Failed : File Already Exists @ " + destinationPath, LogLineType.Error); } } return(result); }
public static List <DeviceInfo> Get(UserConfiguration userConfig, List <string> uniqueIds, DateTime from, DateTime to, int timeout, string command) { Uri apiHost = ApiConfiguration.DataApiHost; string url = new Uri(apiHost, "data/get/index.php").ToString(); string times = "&from=" + from.ToString("o") + "&to=" + to.ToString("o"); string devices = ""; // List Devices to Get data for // If no devices are listed then ALL devices are retrieved if (uniqueIds != null && uniqueIds.Count > 0) { var deviceItems = new List <DeviceListItem>(); foreach (var uniqueId in uniqueIds) { deviceItems.Add(new DeviceListItem(uniqueId)); } string json = JSON.FromList <DeviceListItem>(deviceItems); if (!string.IsNullOrEmpty(json)) { devices = "&devices=" + json; } } string cmd = ""; if (command != null) { cmd = "&command=" + command; } // Create GET request parameters if (userConfig != null) { string format = "{0}?token={1}&sender_id={2}{3}{4}{5}"; string token = userConfig.SessionToken; string senderId = UserManagement.SenderId.Get(); url = string.Format(format, url, token, senderId, devices, cmd, times); } else { string format = "{0}?{1}{2}{3}"; url = string.Format(format, url, devices, cmd, times); } // Setup HTTP Information for GET request var httpInfo = new HTTP.HTTPInfo(); httpInfo.Url = url; httpInfo.Timeout = timeout; httpInfo.MaxAttempts = 1; string response = HTTP.GET(httpInfo); if (response != null) { bool success = ApiError.ProcessResponse(response, "Get Device Data"); if (success) { var deviceInfos = JSON.ToType <List <DeviceInfo> >(response); if (deviceInfos != null) { return(deviceInfos); } } } return(null); }