Example #1
0
        //#region Unzip
        //public string Unzip(ref string moduleName, Stream moduleStream, string user)
        //{
        //    string error = "";
        //    using (ModuleStreamEntry moduleEntry = new ModuleStreamEntry(moduleName, moduleStream))
        //    {
        //        if (!moduleEntry.IsValid())
        //        {
        //            error = "The module is invalid.".Localize();
        //            return error;
        //        }

        //        var moduleInfo = moduleEntry.ModuleInfo;
        //        if (moduleInfo == null)
        //        {
        //            error = "The module.config file is invalid.".Localize();
        //            return error;
        //        }

        //        moduleName = moduleEntry.ModuleName;

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

        //        if (Directory.Exists(modulePath.PhysicalPath))
        //        {
        //            error = "The module name already exists.".Localize();
        //            return error;
        //        }

        //        //save the module version
        //        var installationFile = this._installationFileManager.SaveInstallationFile(moduleEntry);
        //        this._installationFileManager.LogInstallation(moduleName, new InstallationContext(moduleInfo.ModuleName, moduleInfo.Version, DateTime.UtcNow) { User = user, InstallationFileName = installationFile });


        //        moduleEntry.Extract(modulePhysicalPath);
        //    }
        //    return error;
        //}
        //#endregion

        //#region CheckConflictedAssemblyReferences
        //public IEnumerable<ConflictedAssemblyReference> CheckConflictedAssemblyReferences(string moduleName)
        //{
        //    var assemblyFiles = GetAssemblyFiles(moduleName);
        //    return _assemblyReferences.Check(assemblyFiles);
        //}
        //#endregion

        //#region GetAssemblyFiles
        //private IEnumerable<string> GetAssemblyFiles(string moduleName)
        //{
        //    ModulePath modulePath = new ModulePath(moduleName);
        //    ModuleItemPath moduleBinPath = new ModuleItemPath(moduleName, "Bin");
        //    if (Directory.Exists(moduleBinPath.PhysicalPath))
        //    {
        //        return Directory.EnumerateFiles(moduleBinPath.PhysicalPath);
        //    }
        //    else
        //    {
        //        return new string[0];
        //    }
        //}
        //#endregion

        public UploadModuleResult Upload(string moduleName, Stream moduleStream, string user)
        {
            UploadModuleResult result  = new UploadModuleResult();
            IPath tempInstallationPath = null;

            using (ModuleStreamEntry moduleEntry = new ModuleStreamEntry(moduleName, moduleStream))
            {
                if (!moduleEntry.IsValid())
                {
                    result.IsValid = false;
                }

                var moduleInfo = moduleEntry.ModuleInfo;
                if (moduleInfo == null)
                {
                    result.IsValid = false;
                }

                if (result.IsValid)
                {
                    moduleName = moduleEntry.ModuleName;
                    var existsModule = ModuleInfo.Get(moduleName);
                    if (existsModule != null)
                    {
                        result.ModuleExists = true;
                    }

                    tempInstallationPath = _installationFileManager.GetTempInstallationPath(moduleName);

                    moduleEntry.Extract(tempInstallationPath.PhysicalPath);

                    result.ModuleName           = moduleName;
                    result.TempInstallationPath = tempInstallationPath;
                    result.TargetModuleInfo     = moduleInfo;

                    var binFolder = Path.Combine(tempInstallationPath.PhysicalPath, "Bin");
                    if (Directory.Exists(binFolder))
                    {
                        var assemblyFiles = Directory.EnumerateFiles(binFolder);
                        result.ConflictedAssemblies = _assemblyReferences.Check(assemblyFiles);
                    }
                }
            }



            return(result);
        }
Example #2
0
        //#region Unzip
        //public string Unzip(ref string moduleName, Stream moduleStream, string user)
        //{
        //    string error = "";
        //    using (ModuleStreamEntry moduleEntry = new ModuleStreamEntry(moduleName, moduleStream))
        //    {
        //        if (!moduleEntry.IsValid())
        //        {
        //            error = "The module is invalid.".Localize();
        //            return error;
        //        }
        //        var moduleInfo = moduleEntry.ModuleInfo;
        //        if (moduleInfo == null)
        //        {
        //            error = "The module.config file is invalid.".Localize();
        //            return error;
        //        }
        //        moduleName = moduleEntry.ModuleName;
        //        ModulePath modulePath = new ModulePath(moduleEntry.ModuleName);
        //        var modulePhysicalPath = modulePath.PhysicalPath;
        //        if (Directory.Exists(modulePath.PhysicalPath))
        //        {
        //            error = "The module name already exists.".Localize();
        //            return error;
        //        }
        //        //save the module version
        //        var installationFile = this._installationFileManager.SaveInstallationFile(moduleEntry);
        //        this._installationFileManager.LogInstallation(moduleName, new InstallationContext(moduleInfo.ModuleName, moduleInfo.Version, DateTime.UtcNow) { User = user, InstallationFileName = installationFile });
        //        moduleEntry.Extract(modulePhysicalPath);
        //    }
        //    return error;
        //}
        //#endregion
        //#region CheckConflictedAssemblyReferences
        //public IEnumerable<ConflictedAssemblyReference> CheckConflictedAssemblyReferences(string moduleName)
        //{
        //    var assemblyFiles = GetAssemblyFiles(moduleName);
        //    return _assemblyReferences.Check(assemblyFiles);
        //}
        //#endregion
        //#region GetAssemblyFiles
        //private IEnumerable<string> GetAssemblyFiles(string moduleName)
        //{
        //    ModulePath modulePath = new ModulePath(moduleName);
        //    ModuleItemPath moduleBinPath = new ModuleItemPath(moduleName, "Bin");
        //    if (Directory.Exists(moduleBinPath.PhysicalPath))
        //    {
        //        return Directory.EnumerateFiles(moduleBinPath.PhysicalPath);
        //    }
        //    else
        //    {
        //        return new string[0];
        //    }
        //}
        //#endregion
        public UploadModuleResult Upload(string moduleName, Stream moduleStream, string user)
        {
            UploadModuleResult result = new UploadModuleResult();
            IPath tempInstallationPath = null;
            using (ModuleStreamEntry moduleEntry = new ModuleStreamEntry(moduleName, moduleStream))
            {
                if (!moduleEntry.IsValid())
                {
                    result.IsValid = false;
                }

                var moduleInfo = moduleEntry.ModuleInfo;
                if (moduleInfo == null)
                {
                    result.IsValid = false;
                }

                if (result.IsValid)
                {
                    moduleName = moduleEntry.ModuleName;
                    var existsModule = ModuleInfo.Get(moduleName);
                    if (existsModule != null)
                    {
                        result.ModuleExists = true;
                    }

                    tempInstallationPath = _installationFileManager.GetTempInstallationPath(moduleName);

                    moduleEntry.Extract(tempInstallationPath.PhysicalPath);

                    result.ModuleName = moduleName;
                    result.TempInstallationPath = tempInstallationPath;
                    result.TargetModuleInfo = moduleInfo;

                    var binFolder = Path.Combine(tempInstallationPath.PhysicalPath, "Bin");
                    if (Directory.Exists(binFolder))
                    {
                        var assemblyFiles = Directory.EnumerateFiles(binFolder);
                        result.ConflictedAssemblies = _assemblyReferences.Check(assemblyFiles);
                    }
                }
            }

            return result;
        }