Esempio n. 1
0
        public void Commit()
        {
            Byte[] buffer = pnpInfo.PackTemplate();

            MemoryStream stream = new MemoryStream();

            // TODO: Handle large files with chunking
            stream.Write(buffer, 0, buffer.Length);
            stream.Position = 0;

            persistenceConnector.SaveFileStream(this.packageFileName, stream);
        }
Esempio n. 2
0
        private byte[] CreatePnPPackageFile(string ctId)
        {
            PnPInfo info = new PnPInfo
            {
                Manifest = new PnPManifest()
                {
                    Type = PackageType.Full
                },
                Properties = new PnPProperties()
                {
                    Generator = PnP.Framework.Utilities.PnPCoreUtilities.PnPCoreVersionTag,
                    Author    = string.Empty,
                },
                Files = new List <PnPFileInfo>()
            };
            DirectoryInfo dirInfo          = new DirectoryInfo(Path.GetFullPath(Folder));
            string        templateFileName = Path.GetFileNameWithoutExtension(Out) + ".xml";
            var           xml          = CreateXmlAsStringFrom(ctId);
            PnPFileInfo   templateInfo = new PnPFileInfo
            {
                InternalName = templateFileName.AsInternalFilename(),
                OriginalName = templateFileName,
                Folder       = "",
                Content      = System.Text.Encoding.UTF8.GetBytes(xml)
            };

            info.Files.Add(templateInfo);

            foreach (var currentFile in dirInfo.GetFiles("*.*", SearchOption.AllDirectories))
            {
                var         folder   = GetFolderName(currentFile, dirInfo);
                PnPFileInfo fileInfo = new PnPFileInfo
                {
                    InternalName = currentFile.Name.AsInternalFilename(),
                    OriginalName = currentFile.Name,
                    Folder       = folder,
                    Content      = System.IO.File.ReadAllBytes(currentFile.FullName)
                };
                WriteVerbose("Adding file:" + currentFile.Name + " - " + folder);
                info.Files.Add(fileInfo);
            }
            byte[] pack = info.PackTemplate().ToArray();
            return(pack);
        }
        private byte[] CreatePnPPackageFile()
        {
            PnPInfo info = new PnPInfo
            {
                Manifest = new PnPManifest()
                {
                    Type = PackageType.Full
                },
                Properties = new PnPProperties()
                {
                    Generator = OfficeDevPnP.Core.Utilities.PnPCoreUtilities.PnPCoreVersionTag,
                    Author    = string.Empty,
                },
                Files = new List <PnPFileInfo>()
            };
            DirectoryInfo dirInfo             = new DirectoryInfo(Path.GetFullPath(Folder));
            string        templateFileName    = Path.GetFileNameWithoutExtension(Out) + ".xml";
            bool          templateFileMissing = dirInfo.GetFiles(templateFileName, SearchOption.TopDirectoryOnly).Length == 0;

            if (templateFileMissing)
            {
                throw new InvalidOperationException("You need an xml template file (" + templateFileName + ") with the same name as the .pnp outfile in order to pack a folder to a .pnp package file.");
            }

            info.Properties.TemplateFileName = templateFileName;

            foreach (var currentFile in dirInfo.GetFiles("*.*", SearchOption.AllDirectories))
            {
                var         folder   = GetFolderName(currentFile, dirInfo);
                PnPFileInfo fileInfo = new PnPFileInfo
                {
                    InternalName = currentFile.Name.AsInternalFilename(),
                    OriginalName = currentFile.Name,
                    Folder       = folder,
                    Content      = File.ReadAllBytes(currentFile.FullName)
                };
                WriteVerbose("Adding file:" + currentFile.Name + " - " + folder);
                info.Files.Add(fileInfo);
            }
            byte[] pack = info.PackTemplate().ToArray();
            return(pack);
        }