public async Task <IActionResult> UpdatePluginAsync(UpdatePluginRequest request) { if (await _srv.GetPluginByIdAsync(request.Id) == null) { return(BadRequest(new GenericResponse { Success = false, Message = "Plugin with that Id does not exist." })); } var userId = HttpContext.User.FindFirstValue(ClaimTypes.Sid); if (!await _srv.UserIdOwnsPluginIdAsync(userId, request.Id)) { return(Unauthorized(new GenericResponse { Success = false, Message = "Unauthorized to update plugin." })); } var pluginEntity = await _srv.UpdatePluginAsync(request); return(Ok(new GenericResponse <PluginEntity> { Success = true, Message = "Updated plugin.", Data = pluginEntity })); }
public async Task <PluginEntity> UpdatePluginAsync(UpdatePluginRequest request) { var pluginEntity = await _database.Plugins .FirstOrDefaultAsync(x => x.Id == request.Id); pluginEntity.Name = request.Name; pluginEntity.Description = request.Description; pluginEntity.MarkdownDescription = request.MarkdownDescription; pluginEntity.ImageUrl = request.ImageUrl; pluginEntity.UpdatedAt = DateTimeOffset.UtcNow; _database.Plugins.Update(pluginEntity); await _database.SaveChangesAsync(); return(pluginEntity); }
public PluginResponse Post(UpdatePluginRequest request) { PluginResponse response = new PluginResponse(); Profile profile = (from p in Program.Runtime.Setup.Profiles where p.Id == request.ProfileId select p).FirstOrDefault(); bool newPlugin = request.Id == 0; int newId = 0; IAfterglowPlugin plugin = null; Type type = null; switch (request.PluginType) { case 1: if (newPlugin) { type = Program.Runtime.Setup.AvailableLightSetupPlugins.Where(a => a.Name == request.Type).FirstOrDefault(); newId = Program.Runtime.Setup.GetNewId <ILightSetupPlugin>(); } else { plugin = profile.LightSetupPlugins.Where(l => l.Id == request.Id).FirstOrDefault(); } break; case 2: if (newPlugin) { type = Program.Runtime.Setup.AvailableCapturePlugins.Where(a => a.Name == request.Type).FirstOrDefault(); newId = Program.Runtime.Setup.GetNewId <ICapturePlugin>(); } else { plugin = profile.CapturePlugins.Where(l => l.Id == request.Id).FirstOrDefault(); } break; case 3: if (newPlugin) { type = Program.Runtime.Setup.AvailableColourExtractionPlugins.Where(a => a.Name == request.Type).FirstOrDefault(); newId = Program.Runtime.Setup.GetNewId <IColourExtractionPlugin>(); } else { plugin = profile.ColourExtractionPlugins.Where(l => l.Id == request.Id).FirstOrDefault(); } break; case 4: if (newPlugin) { type = Program.Runtime.Setup.AvailablePostProcessPlugins.Where(a => a.Name == request.Type).FirstOrDefault(); newId = Program.Runtime.Setup.GetNewId <IPostProcessPlugin>(); } else { plugin = profile.PostProcessPlugins.Where(l => l.Id == request.Id).FirstOrDefault(); } break; case 5: if (newPlugin) { type = Program.Runtime.Setup.AvailablePreOutputPlugins.Where(a => a.Name == request.Type).FirstOrDefault(); newId = Program.Runtime.Setup.GetNewId <IPreOutputPlugin>(); } else { plugin = profile.PreOutputPlugins.Where(l => l.Id == request.Id).FirstOrDefault(); } break; case 6: if (newPlugin) { type = Program.Runtime.Setup.AvailableOutputPlugins.Where(a => a.Name == request.Type).FirstOrDefault(); newId = Program.Runtime.Setup.GetNewId <IOutputPlugin>(); } else { plugin = profile.OutputPlugins.Where(l => l.Id == request.Id).FirstOrDefault(); } break; default: plugin = null; break; } if (newPlugin && type != null) { plugin = Activator.CreateInstance(type) as IAfterglowPlugin; } if (SetPluginProperties(plugin, request.Properties)) { if (newPlugin) { plugin.Id = newId; switch (request.PluginType) { case 1: profile.LightSetupPlugins[0] = plugin as ILightSetupPlugin; break; case 2: profile.CapturePlugins[0] = plugin as ICapturePlugin; break; case 3: profile.ColourExtractionPlugins[0] = plugin as IColourExtractionPlugin; break; case 4: profile.PostProcessPlugins.Add(plugin as IPostProcessPlugin); break; case 5: profile.PreOutputPlugins.Add(plugin as IPreOutputPlugin); break; case 6: profile.OutputPlugins.Add(plugin as IOutputPlugin); break; default: plugin = null; break; } } Program.Runtime.Save(); // Load the saved version PluginRequest newRequest = new PluginRequest(); newRequest.Id = plugin.Id; newRequest.PluginType = request.PluginType; newRequest.ProfileId = profile.Id; return(Post(newRequest)); } return(null); }