public static string LikePromotion(string text) { if (Json.TryDeserialize(text, out PromotionLikeRequest request) && request.IsValid() && IsValidIdAndHash(request.GetId(), request.Hash)) { var result = new UpgradeResponse { Success = false }; if (Database.TryGetPromotion(request.Id, out Promotion promotion)) { promotion.Likes++; if (Database.TryCreatePromotion(request.Id, promotion, true)) { result.Success = true; } } if (Json.TrySerialize(result, out string json)) { return(json); } else { return(FailedRequest); } } return(null); }
public string UpgradeAccount(string text) { if (Json.TryDeserialize(text, out UpgradeRequest request) && request.IsValid() && IsValidIdAndHash(request.GetId(), request.Hash)) { var result = new UpgradeResponse { Success = Database.TrySetEnterprise(request.GetId(), true) }; if (Json.TrySerialize(result, out string json)) { return(json); } else { return(FailedRequest); } } return(null); }
public static string CreatePromotion(string text) { if (Json.TryDeserialize(text, out PromotionPostRequest request) && request.IsValid() && IsValidIdAndHash(request.GetId(), request.Hash) && IsEnterprise(request.GetId())) { var response = new UpgradeResponse(); var promotion = new Promotion { Owner = request.GetId().ToString(), Id = Guid.NewGuid().ToString(), Title = request.Title, IconURI = request.IconURI, CoverURI = request.CoverURI, Cost = request.Cost, Description = request.Description, Days = request.Days, Likes = 0, StartTime = DateTime.UtcNow }; if (Database.TryCreatePromotion(promotion.Id, promotion)) { response.Success = true; } if (Json.TrySerialize(response, out string json)) { return(json); } else { return(FailedRequest); } } return(null); }
private static void EdgeGeneralTests(WebClient webClient) { // Test the Authenticate method. AuthenticateResponse authenticateResponse = webClient.Authenticate(ConfigurationManager.AppSettings["Username"], ConfigurationManager.AppSettings["Password"]); EdgeOS.API.Types.Configuration.Configuration exampleConfiguration = new EdgeOS.API.Types.Configuration.Configuration() { Firewall = new Firewall() { Group = new FirewallGroup() { AddressGroup = new Dictionary <string, AddressGroupEntry>() { { "APITestAddresses", new AddressGroupEntry() { Address = new[] { "4.3.2.1" } } } } } } }; // Add an IP to a FirewallAddressGroup (creating it if it doesn't already exist). ConfigurationSettingsBatchResponse configurationSettingsBatchResponse = webClient.ConfigurationSettingsBatch(new ConfigurationSettingsBatchRequest { // Add an IP address group. Set = exampleConfiguration, // Cut down on the amount of bytes being returned by selecting a hopefully empty node. Get = new EdgeOS.API.Types.Configuration.Configuration() { CustomAttribute = new[] { "" } } }); // Delete APITestAddresses. exampleConfiguration.Firewall.Group.AddressGroup["APITestAddresses"] = null; // Remove the FirewallAddressGroup. ConfigurationSettingsDeleteResponse configurationSettingsDeleteResponse = webClient.ConfigurationSettingsDelete(exampleConfiguration); // Get predefined config list. ConfigurationSettingsGetResponse configurationSettingsGetPredefinedListResponse = webClient.ConfigurationSettingsGetPredefinedList(); // Get sections of partial config. ConfigurationSettingsGetResponse configurationSettingsGetSectionsResponse = webClient.ConfigurationSettingsGetSections("{\"firewall\":null, \"protocols\":null}"); // Get tree config. ConfigurationSettingsGetTreeResponse configurationSettingsGetTreeResponse = webClient.ConfigurationSettingsGetTree(new[] { "system", "ntp" }); configurationSettingsGetTreeResponse = webClient.ConfigurationSettingsGetTree(new[] { "system" }); configurationSettingsGetTreeResponse = webClient.ConfigurationSettingsGetTree(new[] { "firewall", "group", "address-group" }); // Set a FirewallAddressGroup. ConfigurationSettingsSetResponse configurationSettingsSetResponse = webClient.ConfigurationSettingsSet(exampleConfiguration); // Data methods. DataDefaultConfigurationStatusResponse dataDefaultConfigurationStatusResponse = webClient.DataDefaultConfigurationStatus(); DataDHCPLeasesResponse dataDHCPLeasesResponse = webClient.DataDHCPLeases(); DataDHCPStatisticsResponse dataDHCPStatisticsResponse = webClient.DataDHCPStatistics(); DataFirewallStatisticsResponse dataFirewallStatisticsResponse = webClient.DataFirewallStatistics(); DataNATStatisticsResponse dataNATStatisticsResponse = webClient.DataNATStatistics(); DataRoutesResponse dataRoutesResponse = webClient.DataRoutes(); DataSystemInformationResponse dataSystemInformationResponse = webClient.DataSystemInformation(); // Heartbeat. webClient.Heartbeat(); // Firmware update. UpgradeResponse upgradeFirmware = webClient.UpgradeFirmware("EdgeOS.API.dll"); upgradeFirmware = webClient.UpgradeFirmware(new Uri("http://localhost/firmware.bin")); //TODO: Wizard Feature. //TODO: Wizard Setup. }