Esempio n. 1
0
    public void AddPlugin_Click(Object sender, EventArgs e)
    {
        PluginDAO plugin = new PluginDAO()
        {
            Name = Request["pluginNameBox"],
            Description = Request["pluginDescriptionBox"],
            HelpText = Request["helpTextBox"],
            IsDisabled = false,
            VersionNum = Request["versionBox"],
            OwnerID = _currentUser.UserID
        };

        // Do some form validation
        if (plugin.Name == null || plugin.Name.Length > PluginDAO.NameMaxLength || plugin.Name.Length < 4)
        {
            ShowError(string.Format("Plugin name is invalid. Please enter a name between {0} and {1} characters.", 4, PluginDAO.NameMaxLength));
            pluginNameBox.Focus();
            return;
        }
        else if (plugin.Description == null || plugin.Description.Length >= PluginDAO.DescriptionMaxLength)
        {
            ShowError(string.Format("Plugin description is invalid. Please enter a description less than {0} characters long.", PluginDAO.DescriptionMaxLength));
            pluginDescriptionBox.Focus();
            return;
        }
        else if (plugin.HelpText == null || plugin.HelpText.Length >= PluginDAO.HelpTextMaxLength)
        {
            ShowError(string.Format("Plugin help text is invalid. Please enter a help text less than {0} characters long.", PluginDAO.HelpTextMaxLength));
            helpTextBox.Focus();
            return;
        }
        else if (plugin.VersionNum == null || plugin.VersionNum.Length >= PluginDAO.VersionNumberMaxLength)
        {
            ShowError(string.Format("Plugin version is invalid. Please enter a version that is less than {0} characters long.", PluginDAO.VersionNumberMaxLength));
            versionBox.Focus();
            return;
        }
        else
        {
            // All systems go
            IDBController controller = new SqlController();
            try
            {
                // Can we create our plugin?
                if (controller.CreatePlugin(plugin))
                {
                    // Create a blank file
                    string path = LUADefinitions.getLuaScriptLocation(Request["pluginNameBox"]);
                    try
                    {
                        using (File.Create(path)) { }
                    }
                    catch (Exception)
                    {
                        // Clean up
                        controller.DeletePlugin(plugin);
                        ShowError("Error creating plugin.  Please try again later.");
                        return;
                    }

                    // Shoot them to the editor
                    Response.Redirect(string.Format("EditPlugin.aspx?pluginname={0}", HttpUtility.UrlEncode(plugin.Name)));
                }
            }
            catch (EntryAlreadyExistsException)
            {
                // Error
                ShowError("That plugin name already exists.");
                return;
            }
            catch (SqlException ex)
            {
                // Error
                Logger.LogMessage("AddPlugin.aspx: " + ex.Message, LoggerLevel.SEVERE);
                return;
            }
        }
    }
        public void Setup()
        {
            _controller = new SqlController();

            _owner = new UserDAO()
            {
                UserName = "******",
                FirstName = "TEST",
                LastName = "USER",
                PhoneNumber = "1111111111",
                PhoneEmail = "*****@*****.**",
                Carrier = PhoneCarrier.Verizon,
                UserLevel = UserLevel.User,
                IsBanned = false,
                IsSuppressed = false
            };

            _moderator = new UserDAO()
            {
                UserName = "******",
                FirstName = "TEST",
                LastName = "USER",
                PhoneNumber = "1111111112",
                PhoneEmail = "*****@*****.**",
                Carrier = PhoneCarrier.Verizon,
                UserLevel = UserLevel.User,
                IsBanned = false,
                IsSuppressed = false
            };

            _user = new UserDAO()
            {
                UserName = "******",
                FirstName = "TEST",
                LastName = "USER",
                PhoneNumber = "1111111113",
                PhoneEmail = "*****@*****.**",
                Carrier = PhoneCarrier.Verizon,
                UserLevel = UserLevel.User,
                IsBanned = false,
                IsSuppressed = false
            };

            _controller.CreateUser(_owner, "password");
            _controller.CreateUser(_moderator, "password");
            _controller.CreateUser(_user, "password");

            _enabledPlugin = new PluginDAO()
            {
                Name = "EnPlgn",
                Description = "An enabled test plugin",
                IsDisabled = false,
                VersionNum = "1.0.0",
                OwnerID = _user.UserID,
                Access = PluginAccess.STANDARD,
                HelpText = "Help meh, I'm an enabled plugin!"
            };

            _disabledPlugin = new PluginDAO()
            {
                Name = "DsPlgn",
                Description = "A disabled test plugin",
                IsDisabled = true,
                VersionNum = "1.0.0",
                OwnerID = _user.UserID,
                Access = PluginAccess.STANDARD,
                HelpText = "Help meh, I'm a disabled plugin!"
            };

            _controller.CreatePlugin(_enabledPlugin);
            _controller.CreatePlugin(_disabledPlugin);

            _group = new GroupDAO(_owner)
            {
                Name = "Test Group",
                Description = "A test group, for testing",
                GroupTag = "TEST"
            };
        }