/// <summary> /// Deserialises XML into a valid object. /// </summary> /// <param name="source">An <see cref="XmlElement"/> containing the definition of the object.</param> /// <returns>The deserialised object.</returns> public virtual object Deserialize(XmlElement source) { ServerSecurity output = InitialiseActualType(source.Name); output.Deserialize(source); return(output); }
/// <summary> /// Generates the change menu item. /// </summary> /// <returns></returns> private ToolStripMenuItem GenerateChangeMenu() { ToolStripMenuItem menuItem = new ToolStripMenuItem("Change to"); menuItem.Image = CCNetConfig.Properties.Resources.securitychange_16x16; List <Type> serverSecurityModes = CoreUtil.GetAllServerSecurityModes(); foreach (Type securityMode in serverSecurityModes) { // Retrieve the display name of the security mode string displayName = securityMode.Name; DisplayNameAttribute attribute = CoreUtil.GetCustomAttribute <DisplayNameAttribute>(securityMode); if (attribute != null) { displayName = attribute.DisplayName; } // Add the actual menu item ToolStripMenuItem securityMenuItem = new ToolStripMenuItem(displayName); securityMenuItem.Image = CCNetConfig.Properties.Resources.applications_16x16; securityMenuItem.Tag = securityMode; menuItem.DropDownItems.Add(securityMenuItem); securityMenuItem.Click += delegate(object sender, EventArgs e) { // Generate the new instance and update the display ServerSecurity value = Activator.CreateInstance((sender as ToolStripMenuItem).Tag as Type) as ServerSecurity; configuration.Security = value; ChangeSecurity(value); UpdateDisplay(); }; } return(menuItem); }
/// <summary> /// Runs the wizard. /// </summary> public void Run() { var steps = new List <IStep>(); controller = new WizardController(steps); // Welcome text steps.Add(new TextDisplayStep("This wizard will guide you through the steps of configuring security for this configuration", "Welcome")); // Configuration mode step var modeStep = new SelectionStep("Security Mode", "Please choose the type of security you want:", "None", "Internal"); modeStep.NextHandler = () => { settings.Clear(); controller.DeleteAllAfterCurrent(); switch ((string)modeStep.Selected) { case "None": settings.Add("No security"); controller.AddAfterCurrent(GenerateNoneSteps()); configureProjects = () => { foreach (var project in configuration.Projects) { project.Security = new ProjectSecurity(); } }; security = new ServerSecurity(); break; case "Internal": settings.AddRange(new string[] { "Internal security", "No cache", "No XML logging", "No default server permission", "No default project permission" }); controller.AddAfterCurrent(GenerateInternalSteps()); security = new InternalServerSecurity(); break; } return(true); }; steps.Add(modeStep); steps.Add(new TextDisplayStep("Nothing")); var result = controller.StartWizard("Security Configuration Wizard"); }
/// <summary> /// Changes the associated server security settings. /// </summary> /// <param name="value"></param> public void ChangeSecurity(ServerSecurity value) { if (security != null) { security.PropertyChanged -= OnPropertyChanged; } hasSecurity = (value != null); security = value ?? new ServerSecurity(); DataItem = security; Nodes.Clear(); ReflectionHelper.GenerateChildNodes(this, security); security.PropertyChanged += OnPropertyChanged; }
/// <summary> /// Initialises an instance of the actual security type. /// </summary> /// <param name="name">The name of the type to find.</param> /// <returns>The security type, or an instance of <see cref="ServerSecurity"/> if the security type /// is unknown.</returns> private ServerSecurity InitialiseActualType(string name) { ServerSecurity value = new ServerSecurity(); // Retrieve all the types that inherit from ServerSecurity and attempt to find one that has // a matching reflector name. List <Type> serverSecurityModes = Util.GetAllServerSecurityModes(); foreach (Type securityMode in serverSecurityModes) { ReflectorNameAttribute attribute = Util.GetCustomAttribute <ReflectorNameAttribute>(securityMode); if ((attribute != null) && (attribute.Name == name)) { // Once the matching name has been found, instantiate an instance and exit value = Activator.CreateInstance(securityMode) as ServerSecurity; break; } } return(value); }