Beispiel #1
0
        public static bool Unzip(string moduleName, Stream moduleStream, ref StringBuilder log)
        {
            ModulePath modulePath = new ModulePath(moduleName);
            if (Directory.Exists(modulePath.PhysicalPath))
            {
                log.Append("The module name already exists.".Localize());
                return false;
            }
            using (ZipFile zipFile = ZipFile.Read(moduleStream))
            {
                if (!Verify(zipFile))
                {
                    log.Append("The module is invalid.".Localize());
                    return false;
                }
                var webconfigEntry = zipFile["web.config"];
                if (webconfigEntry != null)
                {
                    zipFile.RemoveEntry(webconfigEntry);
                }

                zipFile.ExtractAll(modulePath.PhysicalPath, ExtractExistingFileAction.OverwriteSilently);
            }
            return true;
        }
Beispiel #2
0
        public static ModuleInfo Unzip(string moduleName, Stream moduleStream, ref StringBuilder log)
        {
            //ModulePath modulePath = new ModulePath(moduleName);
            //if (Directory.Exists(modulePath.PhysicalPath))
            //{
            //    log.Append("The module name already exists.".Localize());
            //    return false;
            //}
            ModuleInfo moduleInfo = null;
            using (ZipFile zipFile = ZipFile.Read(moduleStream))
            {
                string dirName;
                var moduleConfigEntry = ParseZipFile(zipFile, out dirName);
                if (moduleConfigEntry == null)
                {
                    log.Append("The module is invalid.".Localize());
                    return null;
                }

                using (MemoryStream ms = new MemoryStream())
                {
                    moduleConfigEntry.Extract(ms);
                    ms.Position = 0;
                    moduleInfo = ModuleInfo.Get(ms);
                }
                if (moduleInfo == null)
                {
                    return null;
                }
                if (string.IsNullOrEmpty(moduleInfo.ModuleName))
                {
                    moduleInfo.ModuleName = moduleName;
                }

                ModulePath modulePath = new ModulePath(moduleInfo.ModuleName);
                var modulePhysicalPath = modulePath.PhysicalPath;

                if (Directory.Exists(modulePath.PhysicalPath))
                {
                    log.Append("The module name already exists.".Localize());
                    return null;
                }
                var webconfigEntry = zipFile["web.config"];
                if (webconfigEntry != null)
                {
                    zipFile.RemoveEntry(webconfigEntry);
                }
                zipFile.ExtractAll(modulePhysicalPath, ExtractExistingFileAction.OverwriteSilently);

                if (!string.IsNullOrEmpty(dirName))
                {
                    var subDir = Path.Combine(modulePhysicalPath, dirName);
                    Kooboo.IO.IOUtility.CopyDirectory(subDir, modulePhysicalPath);
                    Kooboo.IO.IOUtility.DeleteDirectory(subDir, true);
                }

            }
            return moduleInfo;
        }
Beispiel #3
0
        public ModuleEntryPath(string moduleName, string entryName)
        {
            ModulePath modulePath = new ModulePath(moduleName);

            EntryName = entryName;
            PhysicalPath = Path.Combine(modulePath.PhysicalPath, EntryName);
            VirtualPath = UrlUtility.Combine(modulePath.VirtualPath, EntryName);
        }
Beispiel #4
0
 public static ModuleInfo Get(string moduleName)
 {
     ModulePath modulePath = new ModulePath(moduleName);
     if (!Directory.Exists(modulePath.PhysicalPath))
     {
         throw new Exception(string.Format("The module does not exist.Module name:{0}".Localize(), moduleName));
     }
     ModuleEntryPath moduleInfoPath = GetModuleInfoPath(moduleName);
     var moduleInfo = DataContractSerializationHelper.Deserialize<ModuleInfo>(moduleInfoPath.PhysicalPath);
     moduleInfo.ModuleName = moduleName;
     return moduleInfo;
 }
Beispiel #5
0
 private static void CopyAssembies(ModuleInfo moduleInfo, ref StringBuilder log)
 {
     ModulePath modulePath = new ModulePath(moduleInfo.ModuleName);
     ModuleItemPath moduleBinPath = new ModuleItemPath(moduleInfo.ModuleName, "Bin");
     var binPath = Settings.BinDirectory;
     if (Directory.Exists(moduleBinPath.PhysicalPath))
     {
         foreach (var file in Directory.EnumerateFiles(moduleBinPath.PhysicalPath))
         {
             string fileName = Path.GetFileName(file);
             if (!Assemblies.Defaults.Any(it => it.EqualsOrNullEmpty(fileName, StringComparison.CurrentCultureIgnoreCase)))
             {
                 File.Copy(file, Path.Combine(binPath, fileName), true);
             }
         }
     }
 }
Beispiel #6
0
 private static void RemoveAssemblies(string moduleName)
 {
     ModulePath modulePath = new ModulePath(moduleName);
     ModuleItemPath moduleBinPath = new ModuleItemPath(moduleName, "Bin");
     var binPath = Settings.BinDirectory;
     if (Directory.Exists(moduleBinPath.PhysicalPath))
     {
         foreach (var file in Directory.EnumerateFiles(moduleBinPath.PhysicalPath))
         {
             string fileName = Path.GetFileName(file);
             if (!Assemblies.Defaults.Any(it => it.EqualsOrNullEmpty(fileName, StringComparison.CurrentCultureIgnoreCase)))
             {
                 var binFile = Path.Combine(binPath, fileName);
                 if (File.Exists(binFile))
                 {
                     File.Delete(binFile);
                 }
             }
         }
     }
 }
Beispiel #7
0
 private static string GetSitesModuleRelationDataFile(string moduleName)
 {
     var modulePath = new ModulePath(moduleName);
     var relation = modulePath.GetModuleSharedFilePath("Sites.txt");
     return relation.PhysicalPath;
 }
Beispiel #8
0
 private static void DeleteModule(string moduleName)
 {
     ModulePath modulePath = new ModulePath(moduleName);
     IO.IOUtility.DeleteDirectory(modulePath.PhysicalPath, true);
 }
Beispiel #9
0
        private static void DeleteModule(string moduleName)
        {
            ModulePath modulePath = new ModulePath(moduleName);

            IO.IOUtility.DeleteDirectory(modulePath.PhysicalPath, true);
        }
Beispiel #10
0
 public static ModuleInfo Get(string moduleName)
 {
     ModulePath modulePath = new ModulePath(moduleName);
     if (!Directory.Exists(modulePath.PhysicalPath))
     {
         return null;
     }
     string moduleInfoPath = GetModuleInfoPath(moduleName);
     var moduleInfo = DataContractSerializationHelper.Deserialize<ModuleInfo>(moduleInfoPath);
     moduleInfo.ModuleName = moduleName;
     return moduleInfo;
 }