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;
        }
        public PluginResponse Post(PluginRequest request)
        {
            PluginResponse response = new PluginResponse();
            Profile profile = (from p in Program.Runtime.Setup.Profiles
                               where p.Id == request.ProfileId
                               select p).FirstOrDefault();
            if (profile == null)
            {
                return response;
            }

            bool newPlugin = request.Id == 0;
            Type type = null;

            IAfterglowPlugin plugin = null;

            switch (request.PluginType)
            {
                case 1:
                    if (newPlugin)
                    {
                        type = Program.Runtime.Setup.AvailableLightSetupPlugins.Where(a => a.Name == request.Type).FirstOrDefault();
                    }
                    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();
                    }
                    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();
                    }
                    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();
                    }
                    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();
                    }
                    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();
                    }
                    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;
            }
            else if (plugin == null)
            {
                return response;
            }

            response.Id = plugin.Id;
            response.Name = plugin.Name;
            response.Title = string.Format("{0} - {1}", profile.Name, plugin.Name);
            response.Description = plugin.Description;
            response.Author = plugin.Author;
            response.Version = plugin.Version;
            response.Website = plugin.Website;
            response.PluginType = request.PluginType;
            response.ProfileId = profile.Id;

            response.Properties = GetPluginProperties(plugin);

            return response;
        }