示例#1
0
        public static VariableValueDto fromFormPart(string type, FormPart binaryDataFormPart)
        {
            VariableValueDto dto = new VariableValueDto();

            dto.type  = type;
            dto.value = binaryDataFormPart.BinaryContent;

            if (ValueType.FILE.Name.Equals(fromRestApiTypeName(type)))
            {
                string contentType = binaryDataFormPart.ContentType;
                if (string.ReferenceEquals(contentType, null))
                {
                    contentType = MediaType.APPLICATION_OCTET_STREAM;
                }

                dto.valueInfo = new Dictionary <>();
                dto.valueInfo[FileValueType.VALUE_INFO_FILE_NAME] = binaryDataFormPart.FileName;
                MimeType mimeType = null;
                try
                {
                    mimeType = new MimeType(contentType);
                }
                catch (MimeTypeParseException)
                {
                    throw new RestException(Status.BAD_REQUEST, "Invalid mime type given");
                }

                dto.valueInfo[FileValueType.VALUE_INFO_FILE_MIME_TYPE] = mimeType.BaseType;

                string encoding = mimeType.getParameter("encoding");
                if (!string.ReferenceEquals(encoding, null))
                {
                    dto.valueInfo[FileValueType.VALUE_INFO_FILE_ENCODING] = encoding;
                }

                string transientString = mimeType.getParameter("transient");
                bool   isTransient     = bool.Parse(transientString);
                if (isTransient)
                {
                    dto.valueInfo[AbstractValueTypeImpl.VALUE_INFO_TRANSIENT] = isTransient;
                }
            }

            return(dto);
        }
示例#2
0
 public virtual void addPart(FormPart formPart)
 {
     formParts[formPart.FieldName] = formPart;
 }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MultiFileAttachmentBaseControl"/> class.
        /// </summary>
        /// <param name="attachmentType">Defines the type of file attachment this control supports</param>
        /// <param name="maxFiles">The maximum files that will be supported by this control</param>
        /// <param name="validationGroup">The validation group used by this control</param>
        /// <param name="attachmentReference">The attachment reference used by this control (particularly in feedback error messages)</param>
        public MultiFileAttachmentBaseControl(
            string dotnetProjectName,
            MultiFileAttachmentType attachmentType,
            int maxFiles,
            string validationGroup,
            string attachmentReference)
            : base(HtmlTextWriterTag.Fieldset)
        {
            // Set the .NET project name specific for file retrieval from the database.
            this.dotnetProjectName = dotnetProjectName;

            // Set the file attachment type that will be supported by this control
            this.attachmentType = attachmentType;

            // Set the maximum files that will be supported by this control
            this.maxFiles = maxFiles;

            // Set the validation group used by this control
            this.validationGroup = validationGroup;

            // Set the attachment reference used by this control
            this.attachmentReference = attachmentReference;

            // Create the validation summary control
            this.vUploadSummary = new EsccValidationSummary();
            this.vUploadSummary.ValidationGroup = this.validationGroup;

            // Create the 'form part' for the file browser
            this.fileBrowserBox  = new HtmlInputFile();
            this.fileBrowserPart = new HtmlGenericControl("div");
            this.fileBrowserPart.Attributes.Add("class", "formPart");
            this.placePostFileBrowserParts = new PlaceHolder();

            // Create the 'form part' for the 'Add' button control. Enclose the button in a div tag that has the class 'formControl' so
            // that the button will appear a normal button size.
            HtmlGenericControl divAddButton = new HtmlGenericControl("div");

            this.addFile                 = new EsccButton();
            this.addFile.Text            = "Add";
            this.addFile.Click          += new EventHandler(addFile_Click);
            this.addFile.ValidationGroup = this.ValidationGroup;
            divAddButton.Controls.Add(this.addFile);
            this.addButtonPart = new FormPart(string.Empty, divAddButton);

            // Create the 'form part' for the fieldset control
            this.fieldsetPart = new HtmlGenericControl("fieldset");
            this.fieldsetPart.Attributes.Add("class", "formPart");

            // Initialise the file data arrays from page request to page request.
            this.fileIdArray       = new HtmlInputHidden[maxFiles];
            this.fileNameArray     = new HtmlInputHidden[maxFiles];
            this.spanFilenameArray = new HtmlGenericControl[maxFiles];
            this.divFileArray      = new HtmlGenericControl[maxFiles];
            for (int index = 0; index < maxFiles; index++)
            {
                this.fileIdArray[index]       = new HtmlInputHidden();
                this.fileNameArray[index]     = new HtmlInputHidden();
                this.spanFilenameArray[index] = new HtmlGenericControl("span");
                this.divFileArray[index]      = new HtmlGenericControl("div");
            }
        }
        /// <summary>
        /// Build the email address entry form
        /// </summary>
        protected override void CreateChildControls()
        {
            if (this.Service == null || this.Service.Id <= 0 || String.IsNullOrEmpty(this.Service.Name))
            {
                // Add header template
                if (NotFoundHeaderTemplate != null)
                {
                    XhtmlContainer header = new XhtmlContainer();
                    NotFoundHeaderTemplate.InstantiateIn(header);
                    this.Controls.Add(header);
                }

                // Add no service template
                if (NotFoundTemplate == null)
                {
                    NotFoundTemplate = new DefaultTemplate(this.Service, Resources.EmailSubscribeNoService);
                }

                XhtmlContainer template = new XhtmlContainer();
                NotFoundTemplate.InstantiateIn(template);
                this.Controls.Add(template);

                // Add footer template
                if (NotFoundFooterTemplate != null)
                {
                    XhtmlContainer footer = new XhtmlContainer();
                    NotFoundFooterTemplate.InstantiateIn(footer);
                    this.Controls.Add(footer);
                }
            }
            else
            {
                bool IsNewSubscription = true;

                // Get activation code from querystring
                string subscriptionCode = this.Context.Request.QueryString[this.CodeParameter];
                // Did we find a valid subscription code?
                if (!string.IsNullOrEmpty(subscriptionCode))
                {
                    // This is a change of an existing subscription.
                    IsNewSubscription = false;
                }

                // Add header template
                if (SubscribeHeaderTemplate != null)
                {
                    XhtmlContainer header = new XhtmlContainer();
                    SubscribeHeaderTemplate.InstantiateIn(header);
                    this.Controls.Add(header);
                }

                // Add intro template
                if (IntroTemplate == null)
                {
                    if (IsNewSubscription)
                    {
                        IntroTemplate = new DefaultTemplate(this.Service, Resources.EmailSubscribeIntro);
                    }
                    else
                    {
                        IntroTemplate = new DefaultTemplate(this.Service, Resources.SubscriptionOptionsUpdateIntro);
                    }
                }

                XhtmlContainer intro = new XhtmlContainer();
                IntroTemplate.InstantiateIn(intro);
                this.Controls.Add(intro);

                // If the intro contains a Literal with the id "serviceName", replace it with the current service name
                Literal serviceName = intro.FindControl("IntroServiceName") as Literal;
                if (serviceName != null)
                {
                    serviceName.Text = Service.Name;
                }

                // validation messages - added in at this point to work around a .NET bug
                this.Controls.Add(new EsccValidationSummary());

                // Add form header template
                if (FormHeaderTemplate != null)
                {
                    XhtmlContainer header = new XhtmlContainer();
                    FormHeaderTemplate.InstantiateIn(header);
                    this.Controls.Add(header);
                }

                if (IsNewSubscription)
                {
                    // Display controls suitable for a new subscription.

                    // email box
                    this.email           = new TextBox();
                    this.email.MaxLength = 255;    // e-GIF
                    this.email.ID        = "sub1"; // don't call the box "email", spammers look for that
                    this.email.CssClass  = "email";

                    FormPart emailPart = new FormPart(Resources.EmailEntryPrompt, this.email);
                    emailPart.Required = true;
                    this.Controls.Add(emailPart);

                    // Confirm email box
                    this.confirmEmail           = new TextBox();
                    this.confirmEmail.MaxLength = 255; // e-GIF
                    this.confirmEmail.ID        = "sub2";
                    this.confirmEmail.CssClass  = "email";

                    FormPart confirmPart = new FormPart(Resources.EmailConfirmEntryPrompt, this.confirmEmail);
                    confirmPart.Required = true;
                    this.Controls.Add(confirmPart);

                    // validate email
                    EsccRequiredFieldValidator vrEmail = new EsccRequiredFieldValidator(this.email.ID, Resources.EmailRequiredError);
                    this.Controls.Add(vrEmail);

                    EmailValidator vrxEmail = new EmailValidator(this.email.ID, Resources.EmailInvalidError);
                    this.Controls.Add(vrxEmail);

                    // validate confirmation of email - no need for an EmailValidator because it must match the one above
                    EsccRequiredFieldValidator vrConfirm = new EsccRequiredFieldValidator(this.confirmEmail.ID, Resources.EmailConfirmRequiredError);
                    this.Controls.Add(vrConfirm);

                    EsccCustomValidator vMatchConfirm = new EsccCustomValidator(this.confirmEmail.ID, Resources.EmailConfirmMismatchError);
                    vMatchConfirm.ServerValidate += new ServerValidateEventHandler(vMatchConfirm_ServerValidate);
                    this.Controls.Add(vMatchConfirm);

                    // validate that email is not already subscribed to this service
                    EsccCustomValidator vSubscriptionExists = new EsccCustomValidator(this.confirmEmail.ID, Resources.EmailAlreadySubscribed);
                    vSubscriptionExists.ServerValidate += new ServerValidateEventHandler(vSubscriptionExists_ServerValidate);
                    this.Controls.Add(vSubscriptionExists);
                }
                else
                {
                    // Display controls suitable for a subscription update.

                    // Add the subscription email address as information feedback.
                    this.emailReadOnly      = new Label();
                    this.emailReadOnly.ID   = "sub3"; // don't call the box "email", spammers look for that
                    this.emailReadOnly.Text = this.GetEmailAddressForExistingSubscription(new Guid(subscriptionCode));

                    FormPart emailPart = new FormPart(Properties.Resources.EmailEntryPrompt, this.emailReadOnly);
                    this.Controls.Add(emailPart);
                }

                // Add extra options template
                if (FormExtraOptionsTemplate != null)
                {
                    XhtmlContainer extraOptions = new XhtmlContainer();
                    FormExtraOptionsTemplate.InstantiateIn(extraOptions);
                    this.Controls.Add(extraOptions);
                }

                // Add form footer template
                if (FormFooterTemplate != null)
                {
                    XhtmlContainer footer = new XhtmlContainer();
                    FormFooterTemplate.InstantiateIn(footer);
                    this.Controls.Add(footer);
                }

                // Submit button
                EsccButton submitButton = new EsccButton();
                submitButton.Text     = Resources.SubscribeButtonText;
                submitButton.CssClass = "button";
                submitButton.Click   += new EventHandler(submitButton_Click);

                // Update button
                EsccButton updateButton = new EsccButton();
                updateButton.Text     = Resources.SubscriptionOptionsUpdateButtonText;
                updateButton.CssClass = "button buttonBigger";
                updateButton.Click   += new EventHandler(updateButton_Click);

                FormButtons buttons = new FormButtons();
                if (IsNewSubscription)
                {
                    buttons.Controls.Add(submitButton);
                }
                else
                {
                    buttons.Controls.Add(updateButton);
                }
                this.Controls.Add(buttons);

                // Add footer template
                if (SubscribeFooterTemplate != null)
                {
                    XhtmlContainer footer = new XhtmlContainer();
                    SubscribeFooterTemplate.InstantiateIn(footer);
                    this.Controls.Add(footer);
                }
            }
        }
        /// <summary>
        /// Build the email address entry form
        /// </summary>
        protected override void CreateChildControls()
        {
            if (this.Service == null || this.Service.Id <= 0 || String.IsNullOrEmpty(this.Service.Name))
            {
                // Add header template
                if (NotFoundHeaderTemplate != null)
                {
                    XhtmlContainer header = new XhtmlContainer();
                    NotFoundHeaderTemplate.InstantiateIn(header);
                    this.Controls.Add(header);
                }

                // Add no service template
                if (NotFoundTemplate == null) NotFoundTemplate = new DefaultTemplate(this.Service, Resources.EmailSubscribeNoService);

                XhtmlContainer template = new XhtmlContainer();
                NotFoundTemplate.InstantiateIn(template);
                this.Controls.Add(template);

                // Add footer template
                if (NotFoundFooterTemplate != null)
                {
                    XhtmlContainer footer = new XhtmlContainer();
                    NotFoundFooterTemplate.InstantiateIn(footer);
                    this.Controls.Add(footer);
                }
            }
            else
            {
                bool IsNewSubscription = true;

                // Get activation code from querystring
                string subscriptionCode = this.Context.Request.QueryString[this.CodeParameter];
                // Did we find a valid subscription code?
                if (!string.IsNullOrEmpty(subscriptionCode))
                {
                    // This is a change of an existing subscription.
                    IsNewSubscription = false;
                }

                // Add header template
                if (SubscribeHeaderTemplate != null)
                {
                    XhtmlContainer header = new XhtmlContainer();
                    SubscribeHeaderTemplate.InstantiateIn(header);
                    this.Controls.Add(header);
                }

                // Add intro template
                if (IntroTemplate == null)
                {
                    if (IsNewSubscription)
                    {
                        IntroTemplate = new DefaultTemplate(this.Service, Resources.EmailSubscribeIntro);
                    }
                    else
                    {
                        IntroTemplate = new DefaultTemplate(this.Service, Resources.SubscriptionOptionsUpdateIntro);
                    }
                }

                XhtmlContainer intro = new XhtmlContainer();
                IntroTemplate.InstantiateIn(intro);
                this.Controls.Add(intro);

                // If the intro contains a Literal with the id "serviceName", replace it with the current service name
                Literal serviceName = intro.FindControl("IntroServiceName") as Literal;
                if (serviceName != null) serviceName.Text = Service.Name;

                // validation messages - added in at this point to work around a .NET bug
                this.Controls.Add(new EsccValidationSummary());

                // Add form header template
                if (FormHeaderTemplate != null)
                {
                    XhtmlContainer header = new XhtmlContainer();
                    FormHeaderTemplate.InstantiateIn(header);
                    this.Controls.Add(header);
                }

                if (IsNewSubscription)
                {
                    // Display controls suitable for a new subscription.

                    // email box
                    this.email = new TextBox();
                    this.email.MaxLength = 255; // e-GIF
                    this.email.ID = "sub1"; // don't call the box "email", spammers look for that
                    this.email.CssClass = "email";

                    FormPart emailPart = new FormPart(Resources.EmailEntryPrompt, this.email);
                    emailPart.Required = true;
                    this.Controls.Add(emailPart);

                    // Confirm email box
                    this.confirmEmail = new TextBox();
                    this.confirmEmail.MaxLength = 255; // e-GIF
                    this.confirmEmail.ID = "sub2";
                    this.confirmEmail.CssClass = "email";

                    FormPart confirmPart = new FormPart(Resources.EmailConfirmEntryPrompt, this.confirmEmail);
                    confirmPart.Required = true;
                    this.Controls.Add(confirmPart);

                    // validate email
                    EsccRequiredFieldValidator vrEmail = new EsccRequiredFieldValidator(this.email.ID, Resources.EmailRequiredError);
                    this.Controls.Add(vrEmail);

                    EmailValidator vrxEmail = new EmailValidator(this.email.ID, Resources.EmailInvalidError);
                    this.Controls.Add(vrxEmail);

                    // validate confirmation of email - no need for an EmailValidator because it must match the one above
                    EsccRequiredFieldValidator vrConfirm = new EsccRequiredFieldValidator(this.confirmEmail.ID, Resources.EmailConfirmRequiredError);
                    this.Controls.Add(vrConfirm);

                    EsccCustomValidator vMatchConfirm = new EsccCustomValidator(this.confirmEmail.ID, Resources.EmailConfirmMismatchError);
                    vMatchConfirm.ServerValidate += new ServerValidateEventHandler(vMatchConfirm_ServerValidate);
                    this.Controls.Add(vMatchConfirm);

                    // validate that email is not already subscribed to this service
                    EsccCustomValidator vSubscriptionExists = new EsccCustomValidator(this.confirmEmail.ID, Resources.EmailAlreadySubscribed);
                    vSubscriptionExists.ServerValidate += new ServerValidateEventHandler(vSubscriptionExists_ServerValidate);
                    this.Controls.Add(vSubscriptionExists);
                }
                else
                {
                    // Display controls suitable for a subscription update.

                    // Add the subscription email address as information feedback.
                    this.emailReadOnly = new Label();
                    this.emailReadOnly.ID = "sub3"; // don't call the box "email", spammers look for that
                    this.emailReadOnly.Text = this.GetEmailAddressForExistingSubscription(new Guid(subscriptionCode));

                    FormPart emailPart = new FormPart(Properties.Resources.EmailEntryPrompt, this.emailReadOnly);
                    this.Controls.Add(emailPart);
                }

                // Add extra options template
                if (FormExtraOptionsTemplate != null)
                {
                    XhtmlContainer extraOptions = new XhtmlContainer();
                    FormExtraOptionsTemplate.InstantiateIn(extraOptions);
                    this.Controls.Add(extraOptions);
                }

                // Add form footer template
                if (FormFooterTemplate != null)
                {
                    XhtmlContainer footer = new XhtmlContainer();
                    FormFooterTemplate.InstantiateIn(footer);
                    this.Controls.Add(footer);
                }

                // Submit button
                EsccButton submitButton = new EsccButton();
                submitButton.Text = Resources.SubscribeButtonText;
                submitButton.CssClass = "button";
                submitButton.Click += new EventHandler(submitButton_Click);

                // Update button
                EsccButton updateButton = new EsccButton();
                updateButton.Text = Resources.SubscriptionOptionsUpdateButtonText;
                updateButton.CssClass = "button buttonBigger";
                updateButton.Click += new EventHandler(updateButton_Click);

                FormButtons buttons = new FormButtons();
                if (IsNewSubscription) buttons.Controls.Add(submitButton); else buttons.Controls.Add(updateButton);
                this.Controls.Add(buttons);

                // Add footer template
                if (SubscribeFooterTemplate != null)
                {
                    XhtmlContainer footer = new XhtmlContainer();
                    SubscribeFooterTemplate.InstantiateIn(footer);
                    this.Controls.Add(footer);
                }
            }
        }