Пример #1
0
        public ImportResult ImportApp()
        {
            Log.Add("import app start");
            var result = new ImportResult();

            var request = HttpContext.Current.Request;

            var zoneId = int.Parse(request["ZoneId"]);

            if (request.Files.Count <= 0)
            {
                return(result);
            }

            var helper = new ImportExportEnvironment(Log);

            try
            {
                var zipImport          = new ZipImport(helper, zoneId, null, PortalSettings.UserInfo.IsSuperUser, Log);
                var temporaryDirectory = HttpContext.Current.Server.MapPath(Path.Combine(Eav.ImportExport.Settings.TemporaryDirectory, Guid.NewGuid().ToString().Substring(0, 8)));

                // Increase script timeout to prevent timeouts
                HttpContext.Current.Server.ScriptTimeout = 300;
                result.Succeeded = zipImport.ImportZip(request.Files[0].InputStream, temporaryDirectory);// HttpContext.Current.Server);
                result.Messages  = helper.Messages;
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                result.Succeeded = false;
                result.Messages  = helper.Messages;
            }
            return(result);
        }
Пример #2
0
        public ImportResult ImportContent()
        {
            var result = new ImportResult();

            var request = HttpContext.Current.Request;

            var allowSystemChanges = UserInfo.IsSuperUser;

            var appId  = int.Parse(request["AppId"]);
            var zoneId = int.Parse(request["ZoneId"]);

            if (request.Files.Count > 0)
            {
                var file = request.Files[0];
                if (file.FileName.EndsWith(".zip"))
                {   // ZIP
                    var zipImport = new ZipImport(zoneId, appId, PortalSettings.UserInfo.IsSuperUser);
                    result.Succeeded = zipImport.ImportZip(file.InputStream, HttpContext.Current.Server, PortalSettings, result.Messages);
                }
                else
                {   // XML
                    using (var fileStreamReader = new StreamReader(file.InputStream))
                    {
                        var xmlImport   = new XmlImport(PortalSettings.DefaultLanguage, UserIdentity.CurrentUserIdentityToken, allowSystemChanges);
                        var xmlDocument = XDocument.Parse(fileStreamReader.ReadToEnd());
                        result.Succeeded = xmlImport.ImportXml(zoneId, appId, xmlDocument);
                        result.Messages  = xmlImport.ImportLog;
                    }
                }
            }
            return(result);
        }
Пример #3
0
        public ImportResult ImportContent()
        {
            Log.Add("import content start");
            var result = new ImportResult();

            var request = HttpContext.Current.Request;

            var allowSystemChanges = UserInfo.IsSuperUser;

            var appId  = int.Parse(request["AppId"]);
            var zoneId = int.Parse(request["ZoneId"]);

            if (request.Files.Count <= 0)
            {
                return(result);
            }

            var file = request.Files[0];

            if (file.FileName.EndsWith(".zip"))
            {   // ZIP
                try
                {
                    var env       = new ImportExportEnvironment(Log);
                    var zipImport = new ZipImport(env, zoneId, appId, PortalSettings.UserInfo.IsSuperUser, Log);
                    // Increase script timeout to prevent timeouts
                    HttpContext.Current.Server.ScriptTimeout = 300;
                    var temporaryDirectory = HttpContext.Current.Server.MapPath(Path.Combine(Eav.ImportExport.Settings.TemporaryDirectory, Guid.NewGuid().ToString()));
                    result.Succeeded = zipImport.ImportZip(file.InputStream, temporaryDirectory);// HttpContext.Current.Server); // , /*PortalSettings,*/ env.Messages);
                    result.Messages  = env.Messages;
                }
                catch (Exception ex)
                {
                    Exceptions.LogException(ex);
                }
            }
            else
            {   // XML
                using (var fileStreamReader = new StreamReader(file.InputStream))
                {
                    var xmlImport   = new XmlImportWithFiles(Log, PortalSettings.DefaultLanguage, /*UserIdentity.CurrentUserIdentityToken,*/ allowSystemChanges);
                    var xmlDocument = XDocument.Parse(fileStreamReader.ReadToEnd());
                    result.Succeeded = xmlImport.ImportXml(zoneId, appId, xmlDocument);
                    result.Messages  = xmlImport.Messages;
                }
            }
            return(result);
        }