From cd69bd7c7dca673a1b15ac96fb06f265a7e4fdc7 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Mon, 4 Mar 2013 21:05:59 -0500 Subject: [PATCH] fixed configuration saving issues --- MediaBrowser.Api/Api.cs | 12 ---- MediaBrowser.Api/Javascript/ApiClient.js | 56 +++++++++++++++++-- MediaBrowser.Api/PluginService.cs | 9 +-- .../ScheduledTasks/ScheduledTaskService.cs | 10 +--- MediaBrowser.Api/SystemService.cs | 15 +++-- .../UserLibrary/UserLibraryService.cs | 16 +----- MediaBrowser.Api/UserService.cs | 24 ++------ .../Serialization/XmlSerializer.cs | 30 ---------- .../Serialization/IXmlSerializer.cs | 16 ------ .../Html/scripts/SupporterKeyPage.js | 4 +- 10 files changed, 69 insertions(+), 123 deletions(-) delete mode 100644 MediaBrowser.Api/Api.cs diff --git a/MediaBrowser.Api/Api.cs b/MediaBrowser.Api/Api.cs deleted file mode 100644 index fda9d1bd8..000000000 --- a/MediaBrowser.Api/Api.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MediaBrowser.Api -{ - class Api - { - } -} diff --git a/MediaBrowser.Api/Javascript/ApiClient.js b/MediaBrowser.Api/Javascript/ApiClient.js index 84e54597b..a57722e50 100644 --- a/MediaBrowser.Api/Javascript/ApiClient.js +++ b/MediaBrowser.Api/Javascript/ApiClient.js @@ -1126,7 +1126,29 @@ var ApiClient = { var url = ApiClient.getUrl("System/Configuration"); - return $.post(url, JSON.stringify(configuration)); + return $.ajax({ + type: "POST", + url: url, + data: JSON.stringify(configuration), + dataType: "json", + contentType: "application/json" + }); + }, + + /** + * Updates plugin security info + */ + updatePluginSecurityInfo: function (info) { + + var url = ApiClient.getUrl("Plugins/SecurityInfo"); + + return $.ajax({ + type: "POST", + url: url, + data: JSON.stringify(info), + dataType: "json", + contentType: "application/json" + }); }, /** @@ -1141,7 +1163,13 @@ var ApiClient = { var url = ApiClient.getUrl("Users"); - return $.post(url, JSON.stringify(user)); + return $.ajax({ + type: "POST", + url: url, + data: JSON.stringify(user), + dataType: "json", + contentType: "application/json" + }); }, /** @@ -1156,7 +1184,13 @@ var ApiClient = { var url = ApiClient.getUrl("Users/" + user.Id); - return $.post(url, JSON.stringify(user)); + return $.ajax({ + type: "POST", + url: url, + data: JSON.stringify(user), + dataType: "json", + contentType: "application/json" + }); }, /** @@ -1176,7 +1210,13 @@ var ApiClient = { var url = ApiClient.getUrl("ScheduledTasks/" + id + "/Triggers"); - return $.post(url, JSON.stringify(triggers)); + return $.ajax({ + type: "POST", + url: url, + data: JSON.stringify(triggers), + dataType: "json", + contentType: "application/json" + }); }, /** @@ -1196,7 +1236,13 @@ var ApiClient = { var url = ApiClient.getUrl("Plugins/" + id + "/Configuration"); - return $.post(url, JSON.stringify(configuration)); + return $.ajax({ + type: "POST", + url: url, + data: JSON.stringify(configuration), + dataType: "json", + contentType: "application/json" + }); }, /** diff --git a/MediaBrowser.Api/PluginService.cs b/MediaBrowser.Api/PluginService.cs index 932a3e545..044f867ab 100644 --- a/MediaBrowser.Api/PluginService.cs +++ b/MediaBrowser.Api/PluginService.cs @@ -106,13 +106,8 @@ namespace MediaBrowser.Api /// Class UpdatePluginSecurityInfo /// [Route("/Plugins/SecurityInfo", "POST")] - public class UpdatePluginSecurityInfo : IReturnVoid, IRequiresRequestStream + public class UpdatePluginSecurityInfo : PluginSecurityInfo, IReturnVoid { - /// - /// The raw Http Request Input Stream - /// - /// The request stream. - public Stream RequestStream { get; set; } } /// @@ -227,7 +222,7 @@ namespace MediaBrowser.Api /// The request. public void Post(UpdatePluginSecurityInfo request) { - var info = _jsonSerializer.DeserializeFromStream(request.RequestStream); + var info = request; _securityManager.SupporterKey = info.SupporterKey; _securityManager.LegacyKey = info.LegacyKey; diff --git a/MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs b/MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs index 45d1ae14c..0c18725fa 100644 --- a/MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs +++ b/MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs @@ -64,19 +64,13 @@ namespace MediaBrowser.Api.ScheduledTasks /// Class UpdateScheduledTaskTriggers /// [Route("/ScheduledTasks/{Id}/Triggers", "POST")] - public class UpdateScheduledTaskTriggers : IRequiresRequestStream + public class UpdateScheduledTaskTriggers : List, IReturnVoid { /// /// Gets or sets the task id. /// /// The task id. public Guid Id { get; set; } - - /// - /// The raw Http Request Input Stream - /// - /// The request stream. - public Stream RequestStream { get; set; } } /// @@ -202,7 +196,7 @@ namespace MediaBrowser.Api.ScheduledTasks throw new ResourceNotFoundException("Task not found"); } - var triggerInfos = _jsonSerializer.DeserializeFromStream(request.RequestStream); + var triggerInfos = request; task.Triggers = triggerInfos.Select(ScheduledTaskHelpers.GetTrigger); } diff --git a/MediaBrowser.Api/SystemService.cs b/MediaBrowser.Api/SystemService.cs index 0d5d47e4b..96ed70b8f 100644 --- a/MediaBrowser.Api/SystemService.cs +++ b/MediaBrowser.Api/SystemService.cs @@ -49,13 +49,8 @@ namespace MediaBrowser.Api /// Class UpdateConfiguration /// [Route("/System/Configuration", "POST")] - public class UpdateConfiguration : IRequiresRequestStream + public class UpdateConfiguration : ServerConfiguration, IReturnVoid { - /// - /// The raw Http Request Input Stream - /// - /// The request stream. - public Stream RequestStream { get; set; } } /// @@ -160,9 +155,13 @@ namespace MediaBrowser.Api /// The request. public void Post(UpdateConfiguration request) { - var serverConfig = _jsonSerializer.DeserializeFromStream(request.RequestStream); + // Silly, but we need to serialize and deserialize or the XmlSerializer will write the xml with an element name of UpdateConfiguration - _configurationManager.ReplaceConfiguration(serverConfig); + var json = _jsonSerializer.SerializeToString(request); + + var config = _jsonSerializer.DeserializeFromString(json); + + _configurationManager.ReplaceConfiguration(config); } } } diff --git a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs index ad4d9f73e..c40e59998 100644 --- a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs +++ b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs @@ -62,25 +62,13 @@ namespace MediaBrowser.Api.UserLibrary /// [Route("/Users/{UserId}/Items/{Id}/DisplayPreferences", "POST")] [ServiceStack.ServiceHost.Api(("Updates a user's display preferences for an item"))] - public class UpdateDisplayPreferences : IReturnVoid, IRequiresRequestStream + public class UpdateDisplayPreferences : DisplayPreferences, IReturnVoid { - /// - /// Gets or sets the user id. - /// - /// The user id. - public Guid UserId { get; set; } - /// /// Gets or sets the id. /// /// The id. public string Id { get; set; } - - /// - /// The raw Http Request Input Stream - /// - /// The request stream. - public Stream RequestStream { get; set; } } /// @@ -434,7 +422,7 @@ namespace MediaBrowser.Api.UserLibrary var item = (Folder)DtoBuilder.GetItemByClientId(itemId, _userManager, _libraryManager, user.Id); - var displayPreferences = _jsonSerializer.DeserializeFromStream(request.RequestStream); + var displayPreferences = request; var task = _libraryManager.SaveDisplayPreferencesForFolder(user, item, displayPreferences); diff --git a/MediaBrowser.Api/UserService.cs b/MediaBrowser.Api/UserService.cs index d43eded29..a2618c43c 100644 --- a/MediaBrowser.Api/UserService.cs +++ b/MediaBrowser.Api/UserService.cs @@ -102,32 +102,16 @@ namespace MediaBrowser.Api /// Class UpdateUser /// [Route("/Users/{Id}", "POST")] - public class UpdateUser : IRequiresRequestStream, IReturnVoid + public class UpdateUser : UserDto, IReturnVoid { - /// - /// The raw Http Request Input Stream - /// - /// The request stream. - public Stream RequestStream { get; set; } - - /// - /// Gets or sets the id. - /// - /// The id. - public Guid Id { get; set; } } /// /// Class CreateUser /// [Route("/Users", "POST")] - public class CreateUser : IRequiresRequestStream, IReturn + public class CreateUser : UserDto, IReturn { - /// - /// The raw Http Request Input Stream - /// - /// The request stream. - public Stream RequestStream { get; set; } } /// @@ -292,7 +276,7 @@ namespace MediaBrowser.Api var pathInfo = PathInfo.Parse(Request.PathInfo); var id = new Guid(pathInfo.GetArgumentValue(1)); - var dtoUser = _jsonSerializer.DeserializeFromStream(request.RequestStream); + var dtoUser = request; var user = _userManager.GetUserById(id); @@ -310,7 +294,7 @@ namespace MediaBrowser.Api /// System.Object. public object Post(CreateUser request) { - var dtoUser = _jsonSerializer.DeserializeFromStream(request.RequestStream); + var dtoUser = request; var newUser = _userManager.CreateUser(dtoUser.Name).Result; diff --git a/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs b/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs index d01199f6f..06c60dacd 100644 --- a/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs +++ b/MediaBrowser.Common.Implementations/Serialization/XmlSerializer.cs @@ -22,22 +22,6 @@ namespace MediaBrowser.Common.Implementations.Serialization netSerializer.Serialize(writer, obj); } - /// - /// Deserializes from stream. - /// - /// - /// The stream. - /// ``0. - public T DeserializeFromStream(Stream stream) - { - using (var reader = new XmlTextReader(stream)) - { - var netSerializer = new System.Xml.Serialization.XmlSerializer(typeof(T)); - - return (T)netSerializer.Deserialize(reader); - } - } - /// /// Deserializes from stream. /// @@ -67,20 +51,6 @@ namespace MediaBrowser.Common.Implementations.Serialization } } - /// - /// Deserializes from file. - /// - /// - /// The file. - /// ``0. - public T DeserializeFromFile(string file) - { - using (var stream = File.OpenRead(file)) - { - return DeserializeFromStream(stream); - } - } - /// /// Serializes to file. /// diff --git a/MediaBrowser.Model/Serialization/IXmlSerializer.cs b/MediaBrowser.Model/Serialization/IXmlSerializer.cs index 1d0e0302b..177377350 100644 --- a/MediaBrowser.Model/Serialization/IXmlSerializer.cs +++ b/MediaBrowser.Model/Serialization/IXmlSerializer.cs @@ -5,14 +5,6 @@ namespace MediaBrowser.Model.Serialization { public interface IXmlSerializer { - /// - /// Deserializes from stream. - /// - /// - /// The stream. - /// ``0. - T DeserializeFromStream(Stream stream); - /// /// Deserializes from stream. /// @@ -28,14 +20,6 @@ namespace MediaBrowser.Model.Serialization /// The stream. void SerializeToStream(object obj, Stream stream); - /// - /// Deserializes from file. - /// - /// - /// The file. - /// ``0. - T DeserializeFromFile(string file); - /// /// Serializes to file. /// diff --git a/MediaBrowser.WebDashboard/Html/scripts/SupporterKeyPage.js b/MediaBrowser.WebDashboard/Html/scripts/SupporterKeyPage.js index 50da44331..cebc47764 100644 --- a/MediaBrowser.WebDashboard/Html/scripts/SupporterKeyPage.js +++ b/MediaBrowser.WebDashboard/Html/scripts/SupporterKeyPage.js @@ -37,9 +37,7 @@ LegacyKey: legacyKey }; - var url = ApiClient.getUrl("Plugins/SecurityInfo"); - console.log(url); - $.post(url, JSON.stringify(info)).done(function () { + ApiClient.updateSecurityInfo(info).done(function () { Dashboard.resetPluginSecurityInfo(); Dashboard.hideLoadingMsg(); SupporterPage.load();