public HttpResponseMessage Import(string file)
        {
            var filePath = Path.Combine(IOHelper.MapPath(SystemDirectories.Data), file);

            if (string.IsNullOrEmpty(file) || !System.IO.File.Exists(filePath))
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            var dataInstaller = new PackageDataInstallation(Logger, Services.FileService, Services.MacroService, Services.LocalizationService,
                                                            Services.DataTypeService, Services.EntityService, Services.ContentTypeService, Services.ContentService, _propertyEditors, _scopeProvider);

            var xd = new XmlDocument {
                XmlResolver = null
            };

            xd.Load(filePath);

            var userId  = Security.GetUserId().ResultOr(0);
            var element = XElement.Parse(xd.InnerXml);

            dataInstaller.ImportDocumentType(element, userId);

            // Try to clean up the temporary file.
            try
            {
                System.IO.File.Delete(filePath);
            }
            catch (Exception ex)
            {
                Logger.Error <ContentTypeController, string>(ex, "Error cleaning up temporary udt file in App_Data: {File}", filePath);
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="packageDataInstallation"></param>
 /// <param name="packageFileInstallation"></param>
 /// <param name="parser"></param>
 /// <param name="packageActionRunner"></param>
 /// <param name="applicationRootFolder">
 /// The root folder of the application
 /// </param>
 public PackageInstallation(PackageDataInstallation packageDataInstallation, PackageFileInstallation packageFileInstallation, CompiledPackageXmlParser parser, IPackageActionRunner packageActionRunner,
                            DirectoryInfo applicationRootFolder)
 {
     _packageExtraction       = new PackageExtraction();
     _packageFileInstallation = packageFileInstallation ?? throw new ArgumentNullException(nameof(packageFileInstallation));
     _packageDataInstallation = packageDataInstallation ?? throw new ArgumentNullException(nameof(packageDataInstallation));
     _parser = parser ?? throw new ArgumentNullException(nameof(parser));
     _packageActionRunner   = packageActionRunner ?? throw new ArgumentNullException(nameof(packageActionRunner));
     _applicationRootFolder = applicationRootFolder ?? throw new ArgumentNullException(nameof(applicationRootFolder));
 }
Exemple #3
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;
 }
Exemple #4
0
 public DictionaryController(
     ILogger <DictionaryController> logger,
     ILocalizationService localizationService,
     IBackOfficeSecurityAccessor backofficeSecurityAccessor,
     IOptionsSnapshot <GlobalSettings> globalSettings,
     ILocalizedTextService localizedTextService,
     IUmbracoMapper umbracoMapper,
     IEntityXmlSerializer serializer,
     IHostingEnvironment hostingEnvironment,
     PackageDataInstallation packageDataInstallation)
 {
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
     _localizationService        = localizationService ?? throw new ArgumentNullException(nameof(localizationService));
     _backofficeSecurityAccessor = backofficeSecurityAccessor ?? throw new ArgumentNullException(nameof(backofficeSecurityAccessor));
     _globalSettings             = globalSettings.Value ?? throw new ArgumentNullException(nameof(globalSettings));
     _localizedTextService       = localizedTextService ?? throw new ArgumentNullException(nameof(localizedTextService));
     _umbracoMapper           = umbracoMapper ?? throw new ArgumentNullException(nameof(umbracoMapper));
     _serializer              = serializer ?? throw new ArgumentNullException(nameof(serializer));
     _hostingEnvironment      = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment));
     _packageDataInstallation = packageDataInstallation ?? throw new ArgumentNullException(nameof(packageDataInstallation));
 }
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PackageInstallation"/> class.
 /// </summary>
 public PackageInstallation(PackageDataInstallation packageDataInstallation, CompiledPackageXmlParser parser)
 {
     _packageDataInstallation = packageDataInstallation ?? throw new ArgumentNullException(nameof(packageDataInstallation));
     _parser = parser ?? throw new ArgumentNullException(nameof(parser));
 }