예제 #1
0
        private static PnPInfo LoadPnPPackage(PnPPackage package)
        {
            PnPInfo pnpInfo = new PnPInfo();

            pnpInfo.Manifest   = package.Manifest;
            pnpInfo.Properties = package.Properties;
            pnpInfo.FilesMap   = package.FilesMap;

            pnpInfo.Files = new List <PnPFileInfo>();

            foreach (KeyValuePair <String, PnPPackageFileItem> file in package.Files)
            {
                pnpInfo.Files.Add(
                    new PnPFileInfo
                {
                    InternalName = file.Key,
                    OriginalName = package.FilesMap != null ?
                                   (String.IsNullOrEmpty(file.Value.Folder) ?
                                    package.FilesMap.Map[file.Key] :
                                    package.FilesMap.Map[file.Key].Replace(file.Value.Folder + '/', "")) :
                                   file.Key,
                    Folder  = file.Value.Folder,
                    Content = file.Value.Content,
                });
            }
            return(pnpInfo);
        }
예제 #2
0
        /// <summary>
        /// Opens the package and returns it based on the stream
        /// </summary>
        /// <param name="stream">The stream</param>
        /// <param name="mode">File Mode of the package</param>
        /// <param name="access">File Access</param>
        /// <returns>Package</returns>
        public static PnPPackage Open(Stream stream, FileMode mode, FileAccess access)
        {
            PnPPackage package = new PnPPackage();

            package.Package = Package.Open(stream, mode, access);
            package.EnsureMandatoryPackageComponents();
            return(package);
        }
예제 #3
0
        public static PnPInfo UnpackTemplate(this MemoryStream stream)
        {
            PnPInfo siteTemplate;

            using (PnPPackage package = PnPPackage.Open(stream, FileMode.Open, FileAccess.ReadWrite))
            {
                siteTemplate = LoadPnPPackage(package);
            }
            return(siteTemplate);
        }
예제 #4
0
        public static MemoryStream PackTemplateAsStream(this PnPInfo pnpInfo)
        {
            MemoryStream stream = new MemoryStream();

            using (PnPPackage package = PnPPackage.Open(stream, FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                SavePnPPackage(pnpInfo, package);
            }
            stream.Position = 0;
            return(stream);
        }
예제 #5
0
        public static PnPInfo UnpackTemplate(this Byte[] packageBytes)
        {
            PnPInfo siteTemplate;

            using (MemoryStream stream = new MemoryStream(packageBytes))
            {
                using (PnPPackage package = PnPPackage.Open(stream, FileMode.Open, FileAccess.Read))
                {
                    siteTemplate = LoadPnPPackage(package);
                }
            }
            return(siteTemplate);
        }
예제 #6
0
 public static Byte[] PackTemplate(this PnPInfo pnpInfo)
 {
     Byte[] fileBytes;
     using (MemoryStream stream = new MemoryStream())
     {
         using (PnPPackage package = PnPPackage.Open(stream, FileMode.OpenOrCreate, FileAccess.ReadWrite))
         {
             SavePnPPackage(pnpInfo, package);
         }
         fileBytes = stream.ToArray();
     }
     return(fileBytes);
 }
예제 #7
0
 private static void SavePnPPackage(PnPInfo pnpInfo, PnPPackage package)
 {
     package.Manifest   = pnpInfo.Manifest;
     package.Properties = pnpInfo.Properties;
     package.ClearFiles();
     if (pnpInfo.Files != null)
     {
         foreach (PnPFileInfo file in pnpInfo.Files)
         {
             package.AddFile(file.Name, file.Folder, file.Content);
         }
     }
 }
예제 #8
0
 private static void SavePnPPackage(PnPInfo pnpInfo, PnPPackage package)
 {
     package.Manifest   = pnpInfo.Manifest;
     package.Properties = pnpInfo.Properties;
     package.FilesMap   = new PnPFilesMap(pnpInfo.Files.ToDictionary(f => f.InternalName, f => f.OriginalName));
     package.ClearFiles();
     if (pnpInfo.Files != null)
     {
         foreach (PnPFileInfo file in pnpInfo.Files)
         {
             package.AddFile(file.InternalName, file.Folder, file.Content);
         }
     }
 }
예제 #9
0
 private static void SavePnPPackage(PnPInfo pnpInfo, PnPPackage package)
 {
     package.Manifest   = pnpInfo.Manifest;
     package.Properties = pnpInfo.Properties;
     Debug.Assert(pnpInfo.Files.TrueForAll(f => !string.IsNullOrWhiteSpace(f.InternalName)), "All files need an InternalFileName");
     package.FilesMap = new PnPFilesMap(pnpInfo.Files.ToDictionary(f => f.InternalName, f => Path.Combine(f.Folder, f.OriginalName).Replace('\\', '/').TrimStart('/')));
     package.ClearFiles();
     if (pnpInfo.Files != null)
     {
         foreach (PnPFileInfo file in pnpInfo.Files)
         {
             package.AddFile(file.InternalName, file.Content);
         }
     }
 }
예제 #10
0
        private static PnPInfo LoadPnPPackage(PnPPackage package)
        {
            PnPInfo pnpInfo = new PnPInfo();

            pnpInfo.Manifest   = package.Manifest;
            pnpInfo.Properties = package.Properties;

            pnpInfo.Files = new List <PnPFileInfo>();
            foreach (KeyValuePair <String, PnPPackageFileItem> file in package.Files)
            {
                pnpInfo.Files.Add(
                    new PnPFileInfo
                {
                    Name    = file.Key,
                    Folder  = file.Value.Folder,
                    Content = file.Value.Content,
                });
            }
            return(pnpInfo);
        }