Пример #1
0
        /// <summary>
        /// Document_s the before publish.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="umbraco.cms.businesslogic.PublishEventArgs"/> instance containing the event data.</param>
        private void Document_BeforePublish(Document sender, PublishEventArgs e)
        {
            var propertyTypes = sender.ContentType.PropertyTypes;

            foreach (var propertyType in propertyTypes)
            {
                try
                {
                    var property = sender.getProperty(propertyType);

                    if (property.Value == null)
                    {
                        continue;
                    }

                    var xDocument = XDocument.Parse(property.Value.ToString());

                    // Check if this is TextImage data
                    if (xDocument.Element("TextImage") == null)
                    {
                        continue;
                    }

                    // Extract text from xml and generate an fresh image
                    var text = xDocument.Descendants().Elements("Text").First().Value;

                    if (text == string.Empty)
                    {
                        continue;
                    }

                    var imageUrl  = xDocument.Descendants().Elements("Url").First().Value;
                    var imageFile = IOHelper.MapPath(imageUrl);
                    var imageName = Path.GetFileNameWithoutExtension(imageFile);

                    var parameters = GetParameters(text, property.PropertyType.DataTypeDefinition);

                    // Delete old and Save updated image
                    File.Delete(imageFile);
                    MediaHelper.SaveTextImage(parameters, imageName);
                }
                catch
                {
                    continue;
                }
            }
        }
Пример #2
0
        /// <summary>
        ///   Saves the image using the specified parameters
        /// </summary>
        /// <param name = "parameters">The parameters.</param>
        public void SaveImage(TextImageParameters parameters)
        {
            //Save image and set the url
            var imageName = string.Format("{0}-{1}-{2}", MediaHelper.CurrentNode.Id, Guid.NewGuid(), _textBox.Text);
            var imageUrl  = MediaHelper.SaveTextImage(parameters, imageName);

            // Delete previous image
            if (ImageUrl != imageUrl && ImageUrl != string.Empty)
            {
                DeleteImage();
            }

            ImageUrl = imageUrl;

            if (Text == string.Empty)
            {
                DeleteImage();
            }
        }
Пример #3
0
        /// <summary>
        ///   Saves this instance.
        /// </summary>
        public void Save()
        {
            BackgroundMediaChooser.Save();

            _dataType.DBType = DBTypes.Nvarchar;

            UpdatePreValue(0, FontNameDropDownList.SelectedItem.Text);
            UpdatePreValue(1, CustomFontPathTextBox.Text);
            UpdatePreValue(2, FontSizeTextBox.Text);
            var commaSepratedList = string.Join(",",
                                                (from ListItem listItem in FontStyleCheckBoxList.Items
                                                 where listItem.Selected
                                                 select listItem.Value).ToArray());

            UpdatePreValue(3, commaSepratedList);
            UpdatePreValue(4, ForegroundColorPicker.Value);
            UpdatePreValue(5, BackgroundColorPicker.Value);
            UpdatePreValue(6, ShadowColorPicker.Value);
            UpdatePreValue(7, HorizontalAlignmentDropDownList.SelectedItem.Text);
            UpdatePreValue(8, VerticalAlignmentDropDownList.SelectedItem.Text);
            UpdatePreValue(9, ImageHeightTextBox.Text);
            UpdatePreValue(10, ImageWidthTextBox.Text);
            UpdatePreValue(11, BackgroundMediaChooser.Value);
            UpdatePreValue(12, ImageFormatDropDownList.SelectedItem.Text);

            var sampleText      = FontName + " " + FontSize + " " + OutputFormat;
            var imageParameters = new TextImageParameters(sampleText,
                                                          OutputFormat,
                                                          CustomFontPath,
                                                          FontName,
                                                          FontSize,
                                                          FontStyles,
                                                          ForegroundColor,
                                                          BackgroundColor,
                                                          ShadowColor,
                                                          HorizontalAlignment, VerticalAlignment, ImageHeight,
                                                          ImageWidth, BackgroundMedia);

            var imageUrl = MediaHelper.SaveTextImage(imageParameters, "Preview" + Page.Request["id"]);

            UpdatePreValue(13, imageUrl);
        }