コード例 #1
0
        private static void SetUploadFile(
            this IContentBase content,
            MediaFileManager mediaFileManager,
            MediaUrlGeneratorCollection mediaUrlGenerators,
            IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
            string propertyTypeAlias,
            string filename,
            Stream filestream,
            string culture = null,
            string segment = null)
        {
            var property = GetProperty(content, contentTypeBaseServiceProvider, propertyTypeAlias);

            // Fixes https://github.com/umbraco/Umbraco-CMS/issues/3937 - Assigning a new file to an
            // existing IMedia with extension SetValue causes exception 'Illegal characters in path'
            string oldpath = null;

            if (content.TryGetMediaPath(property.Alias, mediaUrlGenerators, out string mediaFilePath, culture, segment))
            {
                oldpath = mediaFileManager.FileSystem.GetRelativePath(mediaFilePath);
            }

            var filepath = mediaFileManager.StoreFile(content, property.PropertyType, filename, filestream, oldpath);

            // NOTE: Here we are just setting the value to a string which means that any file based editor
            // will need to handle the raw string value and save it to it's correct (i.e. JSON)
            // format. I'm unsure how this works today with image cropper but it does (maybe events?)
            property.SetValue(mediaFileManager.FileSystem.GetUrl(filepath), culture, segment);
        }
コード例 #2
0
 public RichTextEditorPastedImages(IUmbracoContextAccessor umbracoContextAccessor, ILogger logger, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider)
 {
     _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
     _logger       = logger ?? throw new ArgumentNullException(nameof(logger));
     _mediaService = mediaService ?? throw new ArgumentNullException(nameof(mediaService));
     _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider ?? throw new ArgumentNullException(nameof(contentTypeBaseServiceProvider));
 }
コード例 #3
0
 /// <summary>
 /// The constructor will setup the property editor based on the attribute if one is found
 /// </summary>
 public RichTextPropertyEditor(ILogger logger, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor) : base(logger)
 {
     _mediaService = mediaService;
     _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider;
     _umbracoContextAccessor         = umbracoContextAccessor;
     _logger = logger;
 }
コード例 #4
0
        /// <summary>
        /// Sets the posted file value of a property.
        /// </summary>
        public static void SetValue(
            this IContentBase content,
            MediaFileManager mediaFileManager,
            MediaUrlGeneratorCollection mediaUrlGenerators,
            IShortStringHelper shortStringHelper,
            IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
            string propertyTypeAlias,
            string filename,
            Stream filestream,
            string culture = null,
            string segment = null)
        {
            if (filename == null || filestream == null)
            {
                return;
            }

            filename = shortStringHelper.CleanStringForSafeFileName(filename);
            if (string.IsNullOrWhiteSpace(filename))
            {
                return;
            }
            filename = filename.ToLower();

            SetUploadFile(content, mediaFileManager, mediaUrlGenerators, contentTypeBaseServiceProvider, propertyTypeAlias, filename, filestream, culture, segment);
        }
コード例 #5
0
 public BlogMlImporter(
     ArticulateTempFileSystem fileSystem,
     DisqusXmlExporter disqusXmlExporter,
     IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
     IContentService contentService,
     IContentTypeService contentTypeService,
     IUserService userService,
     ILogger logger,
     IDataTypeService dataTypeService,
     ISqlContext sqlContext,
     IScopeProvider scopeProvider,
     ILocalizationService localizationService)
 {
     _fileSystem        = fileSystem;
     _disqusXmlExporter = disqusXmlExporter;
     _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider;
     _contentService      = contentService;
     _contentTypeService  = contentTypeService;
     _userService         = userService;
     _logger              = logger;
     _dataTypeService     = dataTypeService;
     _sqlContext          = sqlContext;
     _scopeProvider       = scopeProvider;
     _localizationService = localizationService;
 }
コード例 #6
0
        private BroadcastResult OnCreateSuccess(
            VideoConvertedCommand command,
            IMedia media,
            IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
            IMediaService mediaService
            )
        {
            var name = $"{Path.GetFileNameWithoutExtension(media.Name)}.mp4";

            using (var fileStream = new FileStream(command.ConvertedFilePath, FileMode.Open, FileAccess.Read))
                using (var memoryStream = new MemoryStream())
                {
                    fileStream.CopyTo(memoryStream);

                    media.SetValue(contentTypeBaseServiceProvider, UmbracoAliases.Media.UmbracoFilePropertyAlias, name, memoryStream);
                }

            File.Delete(command.ConvertedFilePath);
            SaveVideoAdditionProperties(media);
            media.Name = name;
            mediaService.Save(media);
            _videoConverterLogService.Log(true, "Converted successfully", command.MediaId);

            return(BroadcastResult.Success);
        }
コード例 #7
0
        /// <summary>
        /// Creates a partial service context with only some services (for tests).
        /// </summary>
        /// <remarks>
        /// <para>Using a true constructor for this confuses DI containers.</para>
        /// </remarks>
        public static ServiceContext CreatePartial(
            IContentService contentService         = null,
            IMediaService mediaService             = null,
            IContentTypeService contentTypeService = null,
            IMediaTypeService mediaTypeService     = null,
            IDataTypeService dataTypeService       = null,
            IFileService fileService = null,
            ILocalizationService localizationService = null,
            IPackagingService packagingService       = null,
            IEntityService entityService             = null,
            IRelationService relationService         = null,
            IMemberGroupService memberGroupService   = null,
            IMemberTypeService memberTypeService     = null,
            IMemberService memberService             = null,
            IUserService userService = null,
            ITagService tagService   = null,
            INotificationService notificationService   = null,
            ILocalizedTextService localizedTextService = null,
            IAuditService auditService                                     = null,
            IDomainService domainService                                   = null,
            IMacroService macroService                                     = null,
            IPublicAccessService publicAccessService                       = null,
            IExternalLoginService externalLoginService                     = null,
            IServerRegistrationService serverRegistrationService           = null,
            IRedirectUrlService redirectUrlService                         = null,
            IConsentService consentService                                 = null,
            IContentTypeBaseServiceProvider contentTypeBaseServiceProvider = null)
        {
            Lazy <T> Lazy <T>(T service) => service == null ? null : new Lazy <T>(() => service);

            return(new ServiceContext(
                       Lazy(publicAccessService),
                       Lazy(domainService),
                       Lazy(auditService),
                       Lazy(localizedTextService),
                       Lazy(tagService),
                       Lazy(contentService),
                       Lazy(userService),
                       Lazy(memberService),
                       Lazy(mediaService),
                       Lazy(contentTypeService),
                       Lazy(mediaTypeService),
                       Lazy(dataTypeService),
                       Lazy(fileService),
                       Lazy(localizationService),
                       Lazy(packagingService),
                       Lazy(serverRegistrationService),
                       Lazy(entityService),
                       Lazy(relationService),
                       Lazy(macroService),
                       Lazy(memberTypeService),
                       Lazy(memberGroupService),
                       Lazy(notificationService),
                       Lazy(externalLoginService),
                       Lazy(redirectUrlService),
                       Lazy(consentService),
                       Lazy(contentTypeBaseServiceProvider)
                       ));
        }
コード例 #8
0
 public CommonMapper(IUserService userService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
                     ContentAppFactoryCollection contentAppDefinitions, ILocalizedTextService localizedTextService)
 {
     _userService = userService;
     _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider;
     _contentAppDefinitions          = contentAppDefinitions;
     _localizedTextService           = localizedTextService;
 }
コード例 #9
0
 public RichTextPropertyValueEditor(DataEditorAttribute attribute, IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IUmbracoContextAccessor umbracoContextAccessor, ILogger logger)
     : base(attribute)
 {
     _mediaService = mediaService;
     _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider;
     _umbracoContextAccessor         = umbracoContextAccessor;
     _logger = logger;
 }
コード例 #10
0
 public ImagePreprocessingComponent(IMediaFileSystem mediaFileSystem, IContentSection contentSection,
                                    IMediaService mediaService, IMediaTypeService mediaTypeService, IContentTypeBaseServiceProvider contentTypeBaseService)
 {
     _mediaFileSystem        = mediaFileSystem;
     _contentSection         = contentSection;
     _mediaService           = mediaService;
     _mediaTypeService       = mediaTypeService;
     _contentTypeBaseService = contentTypeBaseService;
 }
コード例 #11
0
 public MigrateToPackageData(
     IPackagingService packagingService,
     IMediaService mediaService,
     MediaFileManager mediaFileManager,
     MediaUrlGeneratorCollection mediaUrlGenerators,
     IShortStringHelper shortStringHelper,
     IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
     IMigrationContext context)
     : base(packagingService, mediaService, mediaFileManager, mediaUrlGenerators, shortStringHelper, contentTypeBaseServiceProvider, context)
 {
 }
コード例 #12
0
 public BlogMlImporter(ArticulateTempFileSystem fileSystem, DisqusXmlExporter disqusXmlExporter, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IContentService contentService, IContentTypeService contentTypeService, IUserService userService, ILogger logger, IDataTypeService dataTypeService)
 {
     _fileSystem        = fileSystem;
     _disqusXmlExporter = disqusXmlExporter;
     _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider;
     _contentService     = contentService;
     _contentTypeService = contentTypeService;
     _userService        = userService;
     _logger             = logger;
     _dataTypeService    = dataTypeService;
 }
コード例 #13
0
        /// <summary>
        /// Stores a file.
        /// </summary>
        /// <param name="content"><see cref="IContentBase"/>A content item.</param>
        /// <param name="propertyTypeAlias">The property alias.</param>
        /// <param name="filename">The name of the file.</param>
        /// <param name="filestream">A stream containing the file data.</param>
        /// <param name="filepath">The original file path, if any.</param>
        /// <returns>The path to the file, relative to the media filesystem.</returns>
        /// <remarks>
        /// <para>Does NOT set the property value, so one should probably store the file and then do
        /// something alike: property.Value = MediaHelper.FileSystem.GetUrl(filepath).</para>
        /// <para>The original file path is used, in the old media file path scheme, to try and reuse
        /// the "folder number" that was assigned to the previous file referenced by the property,
        /// if any.</para>
        /// </remarks>
        public static string StoreFile(this IContentBase content, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, string propertyTypeAlias, string filename, Stream filestream, string filepath)
        {
            var contentType  = contentTypeBaseServiceProvider.GetContentTypeOf(content);
            var propertyType = contentType
                               .CompositionPropertyTypes.FirstOrDefault(x => x.Alias.InvariantEquals(propertyTypeAlias));

            if (propertyType == null)
            {
                throw new ArgumentException("Invalid property type alias " + propertyTypeAlias + ".");
            }
            return(MediaFileSystem.StoreFile(content, propertyType, filename, filestream, filepath));
        }
        private IMedia CreateMediaItem(int parentId, string fileName, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider)
        {
            IMedia newFile  = _mediaService.CreateMedia(fileName, parentId, "Image");
            string filePath = HttpContext.Current.Server.MapPath("~/img/" + fileName);

            using (FileStream stream = System.IO.File.Open(filePath, FileMode.Open))
            {
                newFile.SetValue(contentTypeBaseServiceProvider, "umbracoFile", fileName, stream);
            }
            _mediaService.Save(newFile);
            return(newFile);
        }
コード例 #15
0
ファイル: uSync.cs プロジェクト: KevinJump/uSync
 public SetupuSync(
     IPackagingService packagingService,
     IMediaService mediaService,
     MediaFileManager mediaFileManager,
     MediaUrlGeneratorCollection mediaUrlGenerators,
     IShortStringHelper shortStringHelper,
     IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
     IMigrationContext context,
     IOptions <PackageMigrationSettings> packageMigrationsSettings)
     : base(packagingService, mediaService, mediaFileManager, mediaUrlGenerators, shortStringHelper, contentTypeBaseServiceProvider, context, packageMigrationsSettings)
 {
 }
コード例 #16
0
 public ImportPackageBuilderExpression(
     IPackagingService packagingService,
     IMediaService mediaService,
     MediaFileManager mediaFileManager,
     MediaUrlGeneratorCollection mediaUrlGenerators,
     IShortStringHelper shortStringHelper,
     IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
     IMigrationContext context) : base(context)
 {
     _packagingService               = packagingService;
     _mediaService                   = mediaService;
     _mediaFileManager               = mediaFileManager;
     _mediaUrlGenerators             = mediaUrlGenerators;
     _shortStringHelper              = shortStringHelper;
     _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider;
 }
コード例 #17
0
    public MediaMapDefinition(ICultureDictionary cultureDictionary, CommonMapper commonMapper,
                              CommonTreeNodeMapper commonTreeNodeMapper, IMediaService mediaService, IMediaTypeService mediaTypeService,
                              ILocalizedTextService localizedTextService, MediaUrlGeneratorCollection mediaUrlGenerators,
                              IOptions <ContentSettings> contentSettings, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider)
    {
        _commonMapper         = commonMapper;
        _commonTreeNodeMapper = commonTreeNodeMapper;
        _mediaService         = mediaService;
        _mediaTypeService     = mediaTypeService;
        _mediaUrlGenerators   = mediaUrlGenerators;
        _contentSettings      = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings));

        _tabsAndPropertiesMapper =
            new TabsAndPropertiesMapper <IMedia>(cultureDictionary, localizedTextService,
                                                 contentTypeBaseServiceProvider);
    }
コード例 #18
0
 public MediaController(
     ICultureDictionary cultureDictionary,
     ILoggerFactory loggerFactory,
     IShortStringHelper shortStringHelper,
     IEventMessagesFactory eventMessages,
     ILocalizedTextService localizedTextService,
     IOptions <ContentSettings> contentSettings,
     IMediaTypeService mediaTypeService,
     IMediaService mediaService,
     IEntityService entityService,
     IBackOfficeSecurityAccessor backofficeSecurityAccessor,
     IUmbracoMapper umbracoMapper,
     IDataTypeService dataTypeService,
     ISqlContext sqlContext,
     IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
     IRelationService relationService,
     PropertyEditorCollection propertyEditors,
     MediaFileManager mediaFileManager,
     MediaUrlGeneratorCollection mediaUrlGenerators,
     IHostingEnvironment hostingEnvironment,
     IImageUrlGenerator imageUrlGenerator,
     IJsonSerializer serializer,
     IAuthorizationService authorizationService,
     AppCaches appCaches)
     : base(cultureDictionary, loggerFactory, shortStringHelper, eventMessages, localizedTextService, serializer)
 {
     _shortStringHelper          = shortStringHelper;
     _contentSettings            = contentSettings.Value;
     _mediaTypeService           = mediaTypeService;
     _mediaService               = mediaService;
     _entityService              = entityService;
     _backofficeSecurityAccessor = backofficeSecurityAccessor;
     _umbracoMapper              = umbracoMapper;
     _dataTypeService            = dataTypeService;
     _localizedTextService       = localizedTextService;
     _sqlContext = sqlContext;
     _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider;
     _relationService      = relationService;
     _propertyEditors      = propertyEditors;
     _mediaFileManager     = mediaFileManager;
     _mediaUrlGenerators   = mediaUrlGenerators;
     _hostingEnvironment   = hostingEnvironment;
     _logger               = loggerFactory.CreateLogger <MediaController>();
     _imageUrlGenerator    = imageUrlGenerator;
     _authorizationService = authorizationService;
     _appCaches            = appCaches;
 }
コード例 #19
0
        /// <summary>
        /// Sets the posted file value of a property.
        /// </summary>
        public static void SetValue(this IContentBase content, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, string propertyTypeAlias, string filename, Stream filestream, string culture = null, string segment = null)
        {
            if (filename == null || filestream == null)
            {
                return;
            }

            // get a safe & clean filename
            filename = IOHelper.SafeFileName(filename);
            if (string.IsNullOrWhiteSpace(filename))
            {
                return;
            }
            filename = filename.ToLower();

            SetUploadFile(content, contentTypeBaseServiceProvider, propertyTypeAlias, filename, filestream, culture, segment);
        }
コード例 #20
0
        public ContentMapDefinition(
            CommonMapper commonMapper,
            CommonTreeNodeMapper commonTreeNodeMapper,
            ICultureDictionary cultureDictionary,
            ILocalizedTextService localizedTextService,
            IContentService contentService,
            IContentTypeService contentTypeService,
            IFileService fileService,
            IUmbracoContextAccessor umbracoContextAccessor,
            IPublishedRouter publishedRouter,
            ILocalizationService localizationService,
            ILoggerFactory loggerFactory,
            IUserService userService,
            IVariationContextAccessor variationContextAccessor,
            IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
            UriUtility uriUtility,
            IPublishedUrlProvider publishedUrlProvider,
            IEntityService entityService,
            IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
            AppCaches appCaches)
        {
            _commonMapper               = commonMapper;
            _commonTreeNodeMapper       = commonTreeNodeMapper;
            _cultureDictionary          = cultureDictionary;
            _localizedTextService       = localizedTextService;
            _contentService             = contentService;
            _contentTypeService         = contentTypeService;
            _fileService                = fileService;
            _umbracoContextAccessor     = umbracoContextAccessor;
            _publishedRouter            = publishedRouter;
            _localizationService        = localizationService;
            _loggerFactory              = loggerFactory;
            _userService                = userService;
            _entityService              = entityService;
            _backOfficeSecurityAccessor = backOfficeSecurityAccessor;
            _variationContextAccessor   = variationContextAccessor;
            _uriUtility           = uriUtility;
            _publishedUrlProvider = publishedUrlProvider;
            _appCaches            = appCaches;

            _tabsAndPropertiesMapper = new TabsAndPropertiesMapper <IContent>(cultureDictionary, localizedTextService, contentTypeBaseServiceProvider);
            _stateMapper             = new ContentSavedStateMapper <ContentPropertyDisplay>();
            _basicStateMapper        = new ContentBasicSavedStateMapper <ContentPropertyBasic>();
            _contentVariantMapper    = new ContentVariantMapper(_localizationService, localizedTextService);
        }
コード例 #21
0
 public ImportPackageBuilder(
     IPackagingService packagingService,
     IMediaService mediaService,
     MediaFileManager mediaFileManager,
     MediaUrlGeneratorCollection mediaUrlGenerators,
     IShortStringHelper shortStringHelper,
     IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
     IMigrationContext context)
     : base(new ImportPackageBuilderExpression(
                packagingService,
                mediaService,
                mediaFileManager,
                mediaUrlGenerators,
                shortStringHelper,
                contentTypeBaseServiceProvider,
                context))
 {
 }
コード例 #22
0
 public MemberTabsAndPropertiesMapper(ICultureDictionary cultureDictionary,
                                      IBackOfficeSecurityAccessor backofficeSecurityAccessor,
                                      ILocalizedTextService localizedTextService,
                                      IMemberTypeService memberTypeService,
                                      IMemberService memberService,
                                      IMemberGroupService memberGroupService,
                                      IOptions <MemberPasswordConfigurationSettings> memberPasswordConfiguration,
                                      IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
                                      PropertyEditorCollection propertyEditorCollection)
     : base(cultureDictionary, localizedTextService, contentTypeBaseServiceProvider)
 {
     _backofficeSecurityAccessor = backofficeSecurityAccessor ?? throw new ArgumentNullException(nameof(backofficeSecurityAccessor));
     _localizedTextService       = localizedTextService ?? throw new ArgumentNullException(nameof(localizedTextService));
     _memberTypeService          = memberTypeService ?? throw new ArgumentNullException(nameof(memberTypeService));
     _memberService               = memberService ?? throw new ArgumentNullException(nameof(memberService));
     _memberGroupService          = memberGroupService ?? throw new ArgumentNullException(nameof(memberGroupService));
     _memberPasswordConfiguration = memberPasswordConfiguration.Value;
     _propertyEditorCollection    = propertyEditorCollection;
 }
コード例 #23
0
 public PackageMigrationBase(
     IPackagingService packagingService,
     IMediaService mediaService,
     MediaFileManager mediaFileManager,
     MediaUrlGeneratorCollection mediaUrlGenerators,
     IShortStringHelper shortStringHelper,
     IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
     IMigrationContext context,
     IOptions <PackageMigrationSettings> packageMigrationsSettings)
     : base(context)
 {
     _packagingService               = packagingService;
     _mediaService                   = mediaService;
     _mediaFileManager               = mediaFileManager;
     _mediaUrlGenerators             = mediaUrlGenerators;
     _shortStringHelper              = shortStringHelper;
     _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider;
     _packageMigrationsSettings      = packageMigrationsSettings;
 }
コード例 #24
0
 public PackageMigrationBase(
     IPackagingService packagingService,
     IMediaService mediaService,
     MediaFileManager mediaFileManager,
     MediaUrlGeneratorCollection mediaUrlGenerators,
     IShortStringHelper shortStringHelper,
     IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
     IMigrationContext context)
     : this(
         packagingService,
         mediaService,
         mediaFileManager,
         mediaUrlGenerators,
         shortStringHelper,
         contentTypeBaseServiceProvider,
         context,
         StaticServiceProvider.Instance.GetRequiredService <IOptions <PackageMigrationSettings> >())
 {
 }
コード例 #25
0
 public ContentTypeController(
     ICultureDictionary cultureDictionary,
     IContentTypeService contentTypeService,
     IMediaTypeService mediaTypeService,
     IMemberTypeService memberTypeService,
     IUmbracoMapper umbracoMapper,
     ILocalizedTextService localizedTextService,
     IEntityXmlSerializer serializer,
     PropertyEditorCollection propertyEditors,
     IBackOfficeSecurityAccessor backofficeSecurityAccessor,
     IDataTypeService dataTypeService,
     IShortStringHelper shortStringHelper,
     IFileService fileService,
     ILogger <ContentTypeController> logger,
     IContentService contentService,
     IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
     IHostingEnvironment hostingEnvironment,
     EditorValidatorCollection editorValidatorCollection,
     PackageDataInstallation packageDataInstallation)
     : base(
         cultureDictionary,
         editorValidatorCollection,
         contentTypeService,
         mediaTypeService,
         memberTypeService,
         umbracoMapper,
         localizedTextService)
 {
     _serializer                 = serializer;
     _propertyEditors            = propertyEditors;
     _contentTypeService         = contentTypeService;
     _umbracoMapper              = umbracoMapper;
     _backofficeSecurityAccessor = backofficeSecurityAccessor;
     _dataTypeService            = dataTypeService;
     _shortStringHelper          = shortStringHelper;
     _localizedTextService       = localizedTextService;
     _fileService                = fileService;
     _logger         = logger;
     _contentService = contentService;
     _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider;
     _hostingEnvironment             = hostingEnvironment;
     _packageDataInstallation        = packageDataInstallation;
 }
コード例 #26
0
        private static void SetUploadFile(this IContentBase content, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, string propertyTypeAlias, string filename, Stream filestream, string culture = null, string segment = null)
        {
            var property = GetProperty(content, contentTypeBaseServiceProvider, propertyTypeAlias);

            // Fixes https://github.com/umbraco/Umbraco-CMS/issues/3937 - Assigning a new file to an
            // existing IMedia with extension SetValue causes exception 'Illegal characters in path'
            string oldpath = null;
            var    value   = property.GetValue(culture, segment);

            if (PropertyEditors.TryGet(propertyTypeAlias, out var editor) &&
                editor is IDataEditorWithMediaPath dataEditor)
            {
                var svalue = dataEditor.GetMediaPath(value);
                oldpath = MediaFileSystem.GetRelativePath(svalue);
            }

            var filepath = MediaFileSystem.StoreFile(content, property.PropertyType, filename, filestream, oldpath);

            property.SetValue(MediaFileSystem.GetUrl(filepath), culture, segment);
        }
コード例 #27
0
 public RichTextEditorPastedImages(
     IUmbracoContextAccessor umbracoContextAccessor,
     ILogger <RichTextEditorPastedImages> logger,
     IHostingEnvironment hostingEnvironment,
     IMediaService mediaService,
     IContentTypeBaseServiceProvider contentTypeBaseServiceProvider,
     MediaFileManager mediaFileManager,
     MediaUrlGeneratorCollection mediaUrlGenerators,
     IShortStringHelper shortStringHelper,
     IPublishedUrlProvider publishedUrlProvider)
 {
     _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
     _logger                         = logger ?? throw new ArgumentNullException(nameof(logger));
     _hostingEnvironment             = hostingEnvironment;
     _mediaService                   = mediaService ?? throw new ArgumentNullException(nameof(mediaService));
     _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider ?? throw new ArgumentNullException(nameof(contentTypeBaseServiceProvider));
     _mediaFileManager               = mediaFileManager;
     _mediaUrlGenerators             = mediaUrlGenerators;
     _shortStringHelper              = shortStringHelper;
     _publishedUrlProvider           = publishedUrlProvider;
 }
コード例 #28
0
        // gets or creates a property for a content item.
        private static IProperty GetProperty(IContentBase content, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, string propertyTypeAlias)
        {
            var property = content.Properties.FirstOrDefault(x => x.Alias.InvariantEquals(propertyTypeAlias));

            if (property != null)
            {
                return(property);
            }

            var contentType  = contentTypeBaseServiceProvider.GetContentTypeOf(content);
            var propertyType = contentType.CompositionPropertyTypes
                               .FirstOrDefault(x => x.Alias.InvariantEquals(propertyTypeAlias));

            if (propertyType == null)
            {
                throw new Exception("No property type exists with alias " + propertyTypeAlias + ".");
            }

            property = new Property(propertyType);
            content.Properties.Add(property);
            return(property);
        }
コード例 #29
0
        public static IPublishedContent AddImageByUrl(IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, UmbracoHelper umbraco, string url)
        {
            var ctx = HttpContext.Current;

            string urlFilename = Path.GetFileName(new System.Uri(url).LocalPath);
            string tempfile    = string.Format("/App_Data/TEMP/FileUploads/{0}{1}", System.Guid.NewGuid(), System.IO.Path.GetExtension(urlFilename));

            tempfile = ctx.Server.MapPath(tempfile);

            // - TODO
            // - This effectively bypasses and upload limits configured on the server.
            // - You can easily file-bomb the host by providing a huge (scripted) response from a fast destination (sub timeout)
            // - To add fuel to the fire, WebClient has a built in default timeout of 100 seconds (yikes!)
            // - Also ... loading the image 'through' ImageSharp (or ImageProcesor) after download would
            // - ensure that is really is a valid image (and not an attack/trojan image for the frontend client)?
            using (WebClient webclient = new WebClient())
            {
                webclient.DownloadFile(url, tempfile);
            }

            return(AddImageByFile(mediaService, contentTypeBaseServiceProvider, umbraco, urlFilename, tempfile));
        }
コード例 #30
0
        //private System.Drawing.Image DownloadImageFromUrl(string imageUrl)
        //{
        //    System.Drawing.Image image = null;
        //    try
        //    {
        //        var webRequest = (HttpWebRequest)WebRequest.Create(imageUrl);
        //        webRequest.AllowWriteStreamBuffering = true;
        //        webRequest.Timeout = 30000;

        //        var webResponse = webRequest.GetResponse();
        //        var stream = webResponse.GetResponseStream();
        //        image = System.Drawing.Image.FromStream(stream);

        //        webResponse.Close();
        //    }
        //    catch (Exception ex)
        //    {
        //        // log the exception
        //    }
        //    return image;
        //}


        public static IPublishedContent AddImageByFile(IMediaService mediaService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, UmbracoHelper umbraco, string filename, string tempfile)
        {
            _mediaService = mediaService;
            string name = System.IO.Path.GetFileNameWithoutExtension(filename);

            // - place them inside of a folder!
            IMedia folder = CreateFolder(_foldername);

            // - create media item in this folder, save file data and persist
            var media  = _mediaService.CreateMedia(name, folder, "image");
            var buffer = System.IO.File.ReadAllBytes(tempfile);

            media.SetValue(contentTypeBaseServiceProvider, "umbracoFile", filename, new MemoryStream(buffer));
            _mediaService.Save(media);

            // - remove temp file!
            if (System.IO.File.Exists(tempfile))
            {
                System.IO.File.Delete(tempfile);
            }

            return(umbraco.Media(media.Id));
        }