Example #1
0
        private void FinishButtonClick(object sender, EventArgs eventArgs)
        {
            var name           = this.nameTextBox.Text.Trim();
            var templateSource = this.templateSourceTextBox.Text.Trim();

            if (name.Length == 0)
            {
                MessageBox.Show("Name is required.", "Allors Add Template Wizard - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.nameTextBox.Focus();
                return;
            }

            if (templateSource.Length == 0)
            {
                MessageBox.Show("Template Source is required.", "Allors Add Template Wizard - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.templateSourceTextBox.Focus();
                return;
            }

            Uri templateSourceUri;

            try
            {
                templateSourceUri = new Uri(templateSource);
            }
            catch (Exception e)
            {
                MessageBox.Show("Template Source is an illegal URL.\n\n" + e.Message, "Allors Add Template Wizard - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.templateSourceTextBox.Focus();
                return;
            }

            if (!StringTemplate.IsValid(templateSourceUri))
            {
                MessageBox.Show("Template Source is not valid.", "Allors Add Template Wizard - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.templateSourceTextBox.Focus();
                return;
            }

            try
            {
                this.template        = this.repository.AddTemplate();
                this.template.Name   = name;
                this.template.Source = templateSourceUri;
            }
            catch (Exception e)
            {
                MessageBox.Show("Could not create Template.\n\n" + e.Message, "Allors Add Template Wizard - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.template.Delete();
                return;
            }

            this.Close();
        }
        protected void OnButtonOkClicked(object sender, EventArgs eventArgs)
        {
            var error = false;
            this.ResetErrorMessages();

            var name = this.nameEntry.Text.Trim();
            if (string.IsNullOrEmpty(name))
            {
                error = true;
                this.nameErrorMessage.Text = "Name is mandatory";
            }

            var location = this.locationEntry.Text.Trim();
            if (string.IsNullOrEmpty(location))
            {
                error = true;
                this.locationErrorMessage.Text = "Location is mandatory";
            }

            try
            {
                var uri = new Uri(location);
                if (!StringTemplate.IsValid(uri))
                {
                    error = true;
                    this.locationErrorMessage.Text = "Template Source is not valid.";
                }
            }
            catch (Exception e)
            {
                error = true;
                this.locationErrorMessage.Text = "Template Source is an illegal URL.\n\n" + e.Message;
            }

            if (!error)
            {
                try
                {
                    this.template = this.repository.AddTemplate();
                    this.template.Name = name;
                    this.template.Source = new Uri(location);
                    this.Respond(ResponseType.Ok);
                }
                catch (Exception e)
                {
                    this.locationErrorMessage.Text = "Could not create Template.\n\n" + e.Message;
                }
            }

            this.Resize(this.DefaultWidth, this.DefaultHeight);
        }