Esempio n. 1
0
        protected override ValidatorResult Evaluate()
        {
            string value = this.ControlValidationValue;

            if (string.IsNullOrEmpty(value))
            {
                return(ValidatorResult.Valid);
            }

            Item item = Database.GetItem(this.ItemUri);

            Assert.IsNotNull(item, "item");
            FileDropAreaField fda        = new FileDropAreaField(item.Fields[this.FieldID], value);
            ItemList          mediaItems = fda.GetMediaItems();

            if (mediaItems == null || mediaItems.Count < 1 || mediaItems[0] == null)
            {
                return(ValidatorResult.Valid);
            }

            if (mediaItems.Count > 1 || mediaItems[0]["extension"] != "docx")
            {
                string field = string.IsNullOrEmpty(
                    fda.InnerField.Title) ? fda.InnerField.Name : fda.InnerField.Title;
                this.Text = Translate.Text(
                    "{0} may contain only one Word document (.docx file).",
                    field);
                return(this.GetMaxValidatorResult());
            }

            return(ValidatorResult.Valid);
        }
Esempio n. 2
0
        /// <summary>
        /// Nested logic for argument processing and possible UI alerts.
        /// </summary>
        private void Apply(object[] parameters)
        {
            Assert.ArgumentCondition(
                parameters != null && parameters.Length == 1 && parameters[0] is ClientPipelineArgs,
                "parameters",
                "//TODO");
            ClientPipelineArgs args = parameters[0] as ClientPipelineArgs;

            // the FDA field of the item edited by the user
            Field field = this.Item.Fields[this.FieldID];

            Assert.IsNotNull(field, "field");

            FileDropAreaField fda = new FileDropAreaField(
                field,
                base.GetViewStateProperty("XmlValue", string.Empty) as string);
            ItemList mediaItems = fda.GetMediaItems();

            if (mediaItems.Count < 1)
            {
                SheerResponse.Alert(
                    Translate.Text("Add a media item."));
                args.AbortPipeline();
                return;
            }

            Item item = null;

            if (mediaItems.Count == 1)
            {
                item = mediaItems[0];
            }
            else if (mediaItems.Count > 1)
            {
                ItemList selectedItems = null;

                try
                {
                    // this may throw an exception; see 406891
                    selectedItems = this.GetSelectedItems();
                }
                catch (Exception ex)
                {
                    SheerResponse.Alert(
                        Translate.Text("Select an item from the list."));
                    args.AbortPipeline();
                    return;
                }

                if (selectedItems.Count != 1)
                {
                    SheerResponse.Alert(
                        Translate.Text("Select a single item from the list."));
                    args.AbortPipeline();
                    return;
                }

                item = selectedItems[0];
            }

            MediaItem mediaItem = new MediaItem(item);

            if (mediaItem.Extension != "docx")
            {
                SheerResponse.Alert(Translate.Text(
                                        "Seelect a Word document from the list."));
                args.AbortPipeline();
                return;
            }

            WordUtil.HandleWordDocument(this.Item, mediaItem);
        }