CopyAllFiles() public method

Copy all files from SourceFolder to DestinationFolder (directly on the file system)
public CopyAllFiles ( string destinationFolder, bool overwriteFiles, List messages ) : void
destinationFolder string
overwriteFiles bool
messages List
return void
コード例 #1
0
ファイル: ZipExport.cs プロジェクト: hassangas2003/2sxc
        public MemoryStream ExportApp(bool includeContentGroups = false, bool resetAppGuid = false)
        {
            // generate the XML
            var xmlExport = GenerateExportXml(includeContentGroups, resetAppGuid);

            #region Copy needed files to temporary directory

            var messages = new List <ExportImportMessage>();
            var randomShortFolderName = Guid.NewGuid().ToString().Substring(0, 4);

            var temporaryDirectoryPath = HttpContext.Current.Server.MapPath(Path.Combine(Settings.TemporaryDirectory, randomShortFolderName));

            if (!Directory.Exists(temporaryDirectoryPath))
            {
                Directory.CreateDirectory(temporaryDirectoryPath);
            }

            AddInstructionsToPackageFolder(temporaryDirectoryPath);

            var tempDirectory = new DirectoryInfo(temporaryDirectoryPath);
            var appDirectory  = tempDirectory.CreateSubdirectory("Apps/" + _app.Folder + "/");

            var sexyDirectory = appDirectory.CreateSubdirectory(_zipFolderForAppStuff);

            var portalFilesDirectory = appDirectory.CreateSubdirectory(_zipFolderForPortalFiles);

            // Copy app folder
            if (Directory.Exists(_app.PhysicalPath))
            {
                FileManager.CopyAllFiles(sexyDirectory.FullName, false, messages);
            }

            // Copy PortalFiles
            foreach (var file in xmlExport.ReferencedFiles)
            {
                var portalFilePath = Path.Combine(portalFilesDirectory.FullName, Path.GetDirectoryName(file.RelativePath.Replace('/', '\\')));

                if (!Directory.Exists(portalFilePath))
                {
                    Directory.CreateDirectory(portalFilePath);
                }

                if (File.Exists(file.PhysicalPath))
                {
                    var fullPath = Path.Combine(portalFilesDirectory.FullName, file.RelativePath.Replace('/', '\\'));
                    try
                    {
                        File.Copy(file.PhysicalPath, fullPath);
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Error on " + fullPath + " (" + fullPath.Length + ")", e);
                    }
                }
            }
            #endregion


            // Save export xml
            string xml = xmlExport.GenerateNiceXml();
            File.AppendAllText(Path.Combine(appDirectory.FullName, _AppXmlFileName), xml);


            // Zip directory and return as stream
            var stream    = new MemoryStream();
            var zipStream = new ZipOutputStream(stream);
            zipStream.SetLevel(6);
            ZipFolder(tempDirectory.FullName + "\\", tempDirectory.FullName + "\\", zipStream);
            zipStream.Finish();

            tempDirectory.Delete(true);

            return(stream);
        }
コード例 #2
0
ファイル: ZipExport.cs プロジェクト: yonglehou/2sxc
        public MemoryStream ExportApp(bool includeContentGroups = false, bool resetAppGuid = false)
        {
            // Get Export XML
            var attributeSets = App.TemplateManager.GetAvailableContentTypes(true);

            attributeSets = attributeSets.Where(a => !a.ConfigurationIsOmnipresent);

            var attributeSetIds = attributeSets.Select(p => p.AttributeSetId.ToString()).ToArray();
            var entities        = DataSource.GetInitialDataSource(_zoneId, _appId).Out["Default"].List.Where(e => e.Value.AssignmentObjectTypeId != ContentTypeHelpers.AssignmentObjectTypeIDSexyContentTemplate &&
                                                                                                             e.Value.AssignmentObjectTypeId != Constants.AssignmentObjectTypeIdFieldProperties).ToList();

            if (!includeContentGroups)
            {
                entities = entities.Where(p => p.Value.Type.StaticName != _sexycontentContentgroupName).ToList();
            }

            var entityIds = entities
                            .Select(e => e.Value.EntityId.ToString()).ToArray();

            var messages  = new List <ExportImportMessage>();
            var xmlExport = new XmlExporter(_zoneId, _appId, true, attributeSetIds, entityIds);


            #region reset App Guid if necessary
            if (resetAppGuid)
            {
                var root    = xmlExport.ExportXDocument;//.Root;
                var appGuid = root.XPathSelectElement("/SexyContent/Header/App").Attribute("Guid");
                appGuid.Value = _blankGuid;
            }
            #endregion

            string xml = xmlExport.GenerateNiceXml();

            #region Copy needed files to temporary directory

            var randomShortFolderName  = Guid.NewGuid().ToString().Substring(0, 4);
            var temporaryDirectoryPath = HttpContext.Current.Server.MapPath(Path.Combine(Settings.TemporaryDirectory, randomShortFolderName));

            if (!Directory.Exists(temporaryDirectoryPath))
            {
                Directory.CreateDirectory(temporaryDirectoryPath);
            }

            AddInstructionsToPackageFolder(temporaryDirectoryPath);

            var tempDirectory = new DirectoryInfo(temporaryDirectoryPath);
            var appDirectory  = tempDirectory.CreateSubdirectory("Apps/" + App.Folder + "/");

            var sexyDirectory = appDirectory.CreateSubdirectory(_zipFolderForAppStuff);

            var portalFilesDirectory = appDirectory.CreateSubdirectory(_zipFolderForPortalFiles);

            // Copy app folder
            if (Directory.Exists(App.PhysicalPath))
            {
                FileManager.CopyAllFiles(sexyDirectory.FullName, false, messages);
            }

            // Copy PortalFiles
            foreach (var file in xmlExport.ReferencedFiles)
            {
                var portalFilePath = Path.Combine(portalFilesDirectory.FullName, Path.GetDirectoryName(file.RelativePath.Replace('/', '\\')));

                if (!Directory.Exists(portalFilePath))
                {
                    Directory.CreateDirectory(portalFilePath);
                }

                if (File.Exists(file.PhysicalPath))
                {
                    var fullPath = Path.Combine(portalFilesDirectory.FullName, file.RelativePath.Replace('/', '\\'));
                    try
                    {
                        File.Copy(file.PhysicalPath, fullPath);
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Error on " + fullPath + " (" + fullPath.Length + ")", e);
                    }
                }
            }

            // Save export xml
            File.AppendAllText(Path.Combine(appDirectory.FullName, _AppXmlFileName), xml);

            #endregion

            // Zip directory and return as stream
            var stream    = new MemoryStream();
            var zipStream = new ZipOutputStream(stream);
            zipStream.SetLevel(6);
            ZipFolder(tempDirectory.FullName + "\\", tempDirectory.FullName + "\\", zipStream);
            zipStream.Finish();

            tempDirectory.Delete(true);

            return(stream);
        }