protected virtual void CreateBinFile(PaFile File) { string binFolder = Path.Combine(InstallerInfo.SitePath, "bin"); string binFullFileName = Path.Combine(binFolder, File.Name); CreateFile(binFullFileName, File.Buffer); InstallerInfo.Log.AddInfo(FILE_Created + binFullFileName); }
protected virtual void CreateModuleFile(PaFile File, PaFolder Folder) { // account for skinobject names which include [ ] string FolderName = Folder.FolderName.Trim('[').Trim(']'); string rootFolder = ""; // check for the [app_code] token ( dynamic modules ) if (File.Path.ToLower().StartsWith("[app_code]")) { rootFolder = Path.Combine(InstallerInfo.SitePath, Path.Combine("App_Code", FolderName)); // remove the [app_code] token if (File.Path.ToLower() == "[app_code]") { File.Path = ""; } else // there is extra path info to retain { File.Path = File.Path.Substring(10); } Config.AddCodeSubDirectory(FolderName); } else { rootFolder = Path.Combine(InstallerInfo.SitePath, Path.Combine("DesktopModules", FolderName)); } // create the root folder if (!Directory.Exists(rootFolder)) { Directory.CreateDirectory(rootFolder); } //if this is a Resource file, then we need to expand the resourcefile if (Folder.ResourceFile != null && File.Name.ToLower().Equals(Folder.ResourceFile.ToLower())) { CreateResourceFile(File, rootFolder); } else { // create the actual file folder which includes any relative filepath info string fileFolder = Path.Combine(rootFolder, File.Path); if (!Directory.Exists(fileFolder)) { Directory.CreateDirectory(fileFolder); } // save file string FullFileName = Path.Combine(fileFolder, File.Name); if (File.Type == PaFileType.Dnn) { FullFileName += ".config"; // add a forbidden extension so that it is not browsable } CreateFile(FullFileName, File.Buffer); InstallerInfo.Log.AddInfo(FILE_Created + FullFileName); } }
protected virtual bool BatchSql(PaFile sqlFile) { bool WasSuccessful = true; InstallerInfo.Log.StartJob(string.Format(SQL_BeginFile, sqlFile.Name)); string strScript = ""; switch (sqlFile.Encoding) { case PaTextEncoding.UTF16LittleEndian: strScript = GetAsciiString(sqlFile.Buffer, Encoding.Unicode); //System.Text.Encoding.Unicode.GetString(sqlFile.Buffer) break; case PaTextEncoding.UTF16BigEndian: strScript = GetAsciiString(sqlFile.Buffer, Encoding.BigEndianUnicode); //System.Text.Encoding.BigEndianUnicode.GetString(sqlFile.Buffer) break; case PaTextEncoding.UTF8: strScript = GetAsciiString(sqlFile.Buffer, Encoding.UTF8); //System.Text.Encoding.UTF8.GetString(sqlFile.Buffer) break; case PaTextEncoding.UTF7: strScript = GetAsciiString(sqlFile.Buffer, Encoding.UTF7); //System.Text.Encoding.UTF7.GetString(sqlFile.Buffer) break; case PaTextEncoding.Unknown: throw (new Exception(string.Format(SQL_UnknownFile, sqlFile.Name))); } //This check needs to be included because the unicode Byte Order mark results in an extra character at the start of the file //The extra character - '?' - causes an error with the database. if (strScript.StartsWith("?")) { strScript = strScript.Substring(1); } // execute SQL installation script //TODO: Transactions are removed temporarily. string strSQLExceptions = PortalSettings.ExecuteScript(strScript, false); if (!String.IsNullOrEmpty(strSQLExceptions)) { InstallerInfo.Log.AddFailure(string.Format(SQL_Exceptions, "\r\n", strSQLExceptions)); WasSuccessful = false; } InstallerInfo.Log.EndJob(string.Format(SQL_EndFile, sqlFile.Name)); return(WasSuccessful); }
private void ReadZipStream() { InstallerInfo.Log.StartJob(FILES_Reading); ZipInputStream unzip = new ZipInputStream(ZipStream); ZipEntry entry = unzip.GetNextEntry(); while (entry != null) { if (!entry.IsDirectory) { InstallerInfo.Log.AddInfo(FILE_Loading + entry.Name); // add file to the file list PaFile file = new PaFile(unzip, entry); InstallerInfo.FileTable[file.Name.ToLower()] = file; if (file.Type == PaFileType.Dnn) { if (InstallerInfo.DnnFile == null) { InstallerInfo.DnnFile = file; } else { InstallerInfo.Log.AddFailure(EXCEPTION_MultipleDnn + InstallerInfo.DnnFile.Name + " and " + file.Name); } } InstallerInfo.Log.AddInfo(string.Format(FILE_ReadSuccess, file.FullName)); } entry = unzip.GetNextEntry(); } if (InstallerInfo.DnnFile == null) { InstallerInfo.Log.AddFailure(EXCEPTION_MissingDnn); } if (InstallerInfo.Log.Valid) { InstallerInfo.Log.EndJob(FILES_ReadingEnd); } else { throw (new Exception(EXCEPTION_FileLoad)); } }
protected virtual void CreateResourceFile(PaFile ResourceFile, string RootFolder) { InstallerInfo.Log.StartJob(FILES_Expanding); try { ZipInputStream objZipInputStream = new ZipInputStream(new MemoryStream(ResourceFile.Buffer)); FileSystemUtils.UnzipResources(objZipInputStream, RootFolder); } catch (Exception) { } InstallerInfo.Log.EndJob(FILES_CreatedResources); }
protected virtual void CreatePrivateBinFile(PaFile File) { string binFolder = Path.Combine(InstallerInfo.SitePath, "bin\\Modules"); // create the private folder if (!(Directory.Exists(binFolder))) { Directory.CreateDirectory(binFolder); } string binFullFileName = Path.Combine(binFolder, File.Name); CreateFile(binFullFileName, File.Buffer); InstallerInfo.Log.AddInfo((FILE_Created + binFullFileName)); }
protected virtual void CreateDataProviderFile(PaFile file, PaFolder Folder) { string rootFolder = Path.Combine(InstallerInfo.SitePath, Path.Combine("DesktopModules", Folder.FolderName)); string ProviderTypeFolder = Path.Combine("Providers\\DataProviders", file.Extension); string ProviderFolder = Path.Combine(rootFolder, ProviderTypeFolder); if (!Directory.Exists(ProviderFolder)) { Directory.CreateDirectory(ProviderFolder); } // save file string FullFileName = Path.Combine(ProviderFolder, file.Name); CreateFile(FullFileName, file.Buffer); InstallerInfo.Log.AddInfo(FILE_Created + FullFileName); }
public override PaFolderCollection ReadDnn() { //This is a very long subroutine and should probably be broken down //into a couple of smaller routines. That would make it easier to //maintain. InstallerInfo.Log.StartJob(DNN_Reading); //Determine if XML conforms to designated schema ArrayList DnnErrors = ValidateDnn(); if (DnnErrors.Count == 0) { InstallerInfo.Log.AddInfo(string.Format(DNN_Valid, "2.0")); PaFolderCollection Folders = new PaFolderCollection(); XmlDocument doc = new XmlDocument(); MemoryStream buffer = new MemoryStream(InstallerInfo.DnnFile.Buffer, false); doc.Load(buffer); InstallerInfo.Log.AddInfo(XML_Loaded); //Create an XmlNamespaceManager for resolving namespaces. //Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(doc.NameTable) //nsmgr.AddNamespace("dnn", "urn:ModuleDefinitionSchema") XmlNode dnnRoot = doc.DocumentElement; XmlElement FolderElement = (XmlElement)dnnRoot.SelectSingleNode("folder"); //We will process each folder individually. So we don't need to keep //as much in memory. //As we loop through each folder, we will save the data PaFolder Folder = new PaFolder(); //The folder/name node is a required node. If empty, this will throw //an exception. try { Folder.Name = FolderElement.SelectSingleNode("name").InnerText.Trim(); } catch (Exception) { throw (new Exception(EXCEPTION_FolderName)); } try { Folder.ProviderType = FolderElement.SelectSingleNode("type").InnerText.Trim(); } catch (Exception) { throw (new Exception(EXCEPTION_FolderProvider)); } // loading files InstallerInfo.Log.AddInfo(FILES_Loading); XmlElement file; foreach (XmlElement tempLoopVar_file in FolderElement.SelectNodes("files/file")) { file = tempLoopVar_file; //The file/name node is a required node. If empty, this will throw //an exception. string name; try { name = file.SelectSingleNode("name").InnerText.Trim(); } catch (Exception) { throw (new Exception(EXCEPTION_FileName)); } PaFile paf = (PaFile)InstallerInfo.FileTable[name.ToLower()]; if (paf == null) { InstallerInfo.Log.AddFailure(FILE_NotFound + name); } else { //A file path may or may not exist XmlElement pathElement = (XmlElement)file.SelectSingleNode("path"); if (!(pathElement == null)) { string filepath = pathElement.InnerText.Trim(); InstallerInfo.Log.AddInfo(string.Format(FILE_Found, filepath, name)); paf.Path = filepath; } else { // This is needed to override any file path which may exist in the zip file paf.Path = ""; } Folder.Files.Add(paf); } } Folders.Add(Folder); if (!InstallerInfo.Log.Valid) { throw (new Exception(EXCEPTION_LoadFailed)); } InstallerInfo.Log.EndJob(DNN_Success); return(Folders); } else { string err; foreach (string tempLoopVar_err in DnnErrors) { err = tempLoopVar_err; InstallerInfo.Log.AddFailure(err); } throw (new Exception(EXCEPTION_Format)); } }
protected virtual PaFolder GetFolderFromNode(ref int TempModuleDefinitionID, XmlElement FolderElement) { PaFolder Folder = GetFolderAttributesFromNode(FolderElement); XmlElement resourcefileElement = (XmlElement)FolderElement.SelectSingleNode("resourcefile"); if (resourcefileElement != null) { if (resourcefileElement.InnerText.Trim() != "") { Folder.ResourceFile = resourcefileElement.InnerText.Trim(); PaFile paRF = (PaFile)InstallerInfo.FileTable[Folder.ResourceFile.ToLower()]; if (paRF == null) { InstallerInfo.Log.AddFailure(EXCEPTION_MissingResource + Folder.ResourceFile); } else { //need to add this file to the list of files to be installed Folder.Files.Add(paRF); } } } // loading files InstallerInfo.Log.AddInfo(FILES_Loading); XmlElement file; foreach (XmlElement tempLoopVar_file in FolderElement.SelectNodes("files/file")) { file = tempLoopVar_file; //The file/name node is a required node. If empty, this will throw //an exception. string name; try { name = file.SelectSingleNode("name").InnerText.Trim(); } catch (Exception) { throw (new Exception(EXCEPTION_FolderName)); } PaFile paf = (PaFile)InstallerInfo.FileTable[name.ToLower()]; if (paf == null) { InstallerInfo.Log.AddFailure(FILE_NotFound + name); } else { //A file path may or may not exist XmlElement pathElement = (XmlElement)file.SelectSingleNode("path"); if (!(pathElement == null)) { string filepath = pathElement.InnerText.Trim(); InstallerInfo.Log.AddInfo(string.Format(FILE_Found, filepath, name)); paf.Path = filepath; } Folder.Files.Add(paf); } } // add dnn file to collection ( if it does not exist already ) if (Folder.Files.Contains(InstallerInfo.DnnFile) == false) { Folder.Files.Add(InstallerInfo.DnnFile); } InstallerInfo.Log.AddInfo(MODULES_Loading); XmlElement DNNModule; foreach (XmlElement tempLoopVar_DNNModule in FolderElement.SelectNodes("modules/module")) { DNNModule = tempLoopVar_DNNModule; Folder.Modules.Add(GetModuleFromNode(TempModuleDefinitionID, Folder, DNNModule)); TempModuleDefinitionID++; } return(Folder); }
protected virtual void ExecuteSql(PaFolder Folder) { InstallerInfo.Log.StartJob(SQL_Begin); // get list of script files ArrayList arrScriptFiles = new ArrayList(); PaFile InstallScript = null; // executing all the sql files foreach (PaFile file in Folder.Files) { // DataProvider files may be either: the SQL to execute, uninstall, or XML stored procs. // We only want to execute the first type of DataProvider files. if (file.Type == PaFileType.Sql || (file.Type == PaFileType.DataProvider && file.Name.ToLower().IndexOf("uninstall") == -1 && file.Name.ToLower().IndexOf(".xml") == -1)) { ProviderConfiguration objProviderConfiguration = ProviderConfiguration.GetProviderConfiguration("data"); if (objProviderConfiguration.DefaultProvider.ToLower() == Path.GetExtension(file.Name.ToLower()).Substring(1)) { if (file.Name.ToLower().StartsWith("install.")) { InstallScript = file; } else { arrScriptFiles.Add(file); } } } } // get current module version string strModuleVersion = "000000"; DesktopModuleInfo objDesktopModule = GetDesktopModule(Folder); if (objDesktopModule != null) { strModuleVersion = objDesktopModule.Version.Replace(".", ""); } if (InstallScript != null && objDesktopModule == null) { // new install InstallerInfo.Log.AddInfo(SQL_Executing + InstallScript.Name); BatchSql(InstallScript); string strInstallVersion = Path.GetFileNameWithoutExtension(InstallScript.Name).Replace(".", ""); strInstallVersion = strInstallVersion.ToLower().Replace("install", ""); // if install script includes version number will be used a base version for upgrades // otherwise it is assigned an initial version of 000000 if (!String.IsNullOrEmpty(strInstallVersion)) { strModuleVersion = strInstallVersion; } UpgradeVersions.Add(Regex.Replace(strModuleVersion, "^(?<a>\\d{2})(?<b>\\d{2})(?<c>\\d{2})$", "${a}.${b}.${c}")); } // iterate through scripts PaDataProviderComparer Comparer = new PaDataProviderComparer(); arrScriptFiles.Sort(Comparer); foreach (PaFile scriptFile in arrScriptFiles) { string strScriptVersion = Path.GetFileNameWithoutExtension(scriptFile.Name).Replace(".", ""); if (String.Compare(strScriptVersion, strModuleVersion, false) > 0) { UpgradeVersions.Add(Path.GetFileNameWithoutExtension(scriptFile.Name)); InstallerInfo.Log.AddInfo(SQL_Executing + scriptFile.Name); BatchSql(scriptFile); } } InstallerInfo.Log.EndJob(SQL_End); }
private void ReadZipStream() { InstallerInfo.Log.StartJob( FILES_Reading ); ZipInputStream unzip = new ZipInputStream( ZipStream ); ZipEntry entry = unzip.GetNextEntry(); while( entry != null ) { if( !entry.IsDirectory ) { InstallerInfo.Log.AddInfo( FILE_Loading + entry.Name ); // add file to the file list PaFile file = new PaFile( unzip, entry ); InstallerInfo.FileTable[file.Name.ToLower()] = file; if( file.Type == PaFileType.Dnn ) { if( InstallerInfo.DnnFile == null ) { InstallerInfo.DnnFile = file; } else { InstallerInfo.Log.AddFailure( EXCEPTION_MultipleDnn + InstallerInfo.DnnFile.Name + " and " + file.Name ); } } InstallerInfo.Log.AddInfo( string.Format( FILE_ReadSuccess, file.FullName ) ); } entry = unzip.GetNextEntry(); } if( InstallerInfo.DnnFile == null ) { InstallerInfo.Log.AddFailure( EXCEPTION_MissingDnn ); } if( InstallerInfo.Log.Valid ) { InstallerInfo.Log.EndJob( FILES_ReadingEnd ); } else { throw ( new Exception( EXCEPTION_FileLoad ) ); } }
public override PaFolderCollection ReadDnn() { //This is a very long subroutine and should probably be broken down //into a couple of smaller routines. That would make it easier to //maintain. InstallerInfo.Log.StartJob(DNN_Reading); //Determine if XML conforms to designated schema ArrayList DnnErrors = ValidateDnn(); if (DnnErrors.Count == 0) { InstallerInfo.Log.AddInfo(DNN_ValidSkinObject); PaFolderCollection Folders = new PaFolderCollection(); XmlDocument doc = new XmlDocument(); MemoryStream buffer = new MemoryStream(InstallerInfo.DnnFile.Buffer, false); doc.Load(buffer); InstallerInfo.Log.AddInfo(XML_Loaded); XmlNode dnnRoot = doc.DocumentElement; int TempModuleDefinitionID = 0; XmlElement FolderElement; foreach (XmlElement tempLoopVar_FolderElement in dnnRoot.SelectNodes("folders/folder")) { FolderElement = tempLoopVar_FolderElement; //We will process each folder individually. So we don't need to keep //as much in memory. //As we loop through each folder, we will save the data PaFolder Folder = new PaFolder(); //The folder/name node is a required node. If empty, this will throw //an exception. try { Folder.Name = FolderElement.SelectSingleNode("name").InnerText.Trim(); } catch (Exception) { throw (new Exception(EXCEPTION_FolderName)); } // in V2 the FriendlyName/FolderName/ModuleName attributes were not supported in the *.dnn file, // so set them to the Folder Name Folder.FriendlyName = Folder.Name; Folder.FolderName = Folder.Name; Folder.ModuleName = Folder.Name; XmlElement resourcefileElement = (XmlElement)FolderElement.SelectSingleNode("resourcefile"); if (resourcefileElement != null) { if (resourcefileElement.InnerText.Trim() != "") { Folder.ResourceFile = resourcefileElement.InnerText.Trim(); PaFile paRF = (PaFile)InstallerInfo.FileTable[Folder.ResourceFile.ToLower()]; if (paRF == null) { InstallerInfo.Log.AddFailure(EXCEPTION_MissingResource + Folder.ResourceFile); } else { paRF.Path = Folder.ResourceFile; } } } // loading files InstallerInfo.Log.AddInfo(FILES_Loading); XmlElement file; foreach (XmlElement tempLoopVar_file in FolderElement.SelectNodes("files/file")) { file = tempLoopVar_file; //The file/name node is a required node. If empty, this will throw //an exception. string name; try { name = file.SelectSingleNode("name").InnerText.Trim(); } catch (Exception) { throw (new Exception(EXCEPTION_FileName)); } PaFile paf = (PaFile)InstallerInfo.FileTable[name.ToLower()]; if (paf == null) { InstallerInfo.Log.AddFailure(FILE_NotFound + name); } else { //A file path may or may not exist XmlElement pathElement = (XmlElement)file.SelectSingleNode("path"); if (!(pathElement == null)) { string filepath = pathElement.InnerText.Trim(); InstallerInfo.Log.AddInfo(string.Format(FILE_Found, filepath, name)); paf.Path = filepath; } Folder.Files.Add(paf); } } // add dnn file to collection ( if it does not exist already ) if (Folder.Files.Contains(InstallerInfo.DnnFile) == false) { Folder.Files.Add(InstallerInfo.DnnFile); } InstallerInfo.Log.AddInfo(MODULES_Loading); XmlElement DNNModule; foreach (XmlElement tempLoopVar_DNNModule in FolderElement.SelectNodes("modules/module")) { DNNModule = tempLoopVar_DNNModule; ModuleDefinitionInfo ModuleDef = new ModuleDefinitionInfo(); ModuleDef.TempModuleID = TempModuleDefinitionID; //We need to ensure that admin order is null for "User" modules TempModuleDefinitionID++; Folder.Modules.Add(ModuleDef); InstallerInfo.Log.AddInfo(string.Format(MODULES_ControlInfo, ModuleDef.FriendlyName)); XmlElement ModuleControl; foreach (XmlElement tempLoopVar_ModuleControl in DNNModule.SelectNodes("controls/control")) { ModuleControl = tempLoopVar_ModuleControl; ModuleControlInfo ModuleControlDef = new ModuleControlInfo(); XmlElement keyElement = (XmlElement)ModuleControl.SelectSingleNode("key"); if (keyElement != null) { ModuleControlDef.ControlKey = keyElement.InnerText.Trim(); } XmlElement titleElement = (XmlElement)ModuleControl.SelectSingleNode("title"); if (titleElement != null) { ModuleControlDef.ControlTitle = titleElement.InnerText.Trim(); } try { ModuleControlDef.ControlSrc = Path.Combine("DesktopModules", Path.Combine(Folder.Name, ModuleControl.SelectSingleNode("src").InnerText.Trim()).Replace('\\', '/')).Replace(@"\", "/"); } catch (Exception) { throw (new Exception(EXCEPTION_Src)); } XmlElement iconFileElement = (XmlElement)ModuleControl.SelectSingleNode("iconfile"); if (iconFileElement != null) { ModuleControlDef.IconFile = iconFileElement.InnerText.Trim(); } try { ModuleControlDef.ControlType = (SecurityAccessLevel)TypeDescriptor.GetConverter(typeof(SecurityAccessLevel)).ConvertFromString(ModuleControl.SelectSingleNode("type").InnerText.Trim()); //ModuleControlDef.ControlType = CType(ModuleControl.SelectSingleNode("type").InnerText.Trim, SecurityAccessLevel) } catch (Exception) { throw (new Exception(EXCEPTION_Type)); } XmlElement orderElement = (XmlElement)ModuleControl.SelectSingleNode("vieworder"); if (orderElement != null) { ModuleControlDef.ViewOrder = Convert.ToInt32(orderElement.InnerText.Trim()); } else { ModuleControlDef.ViewOrder = Null.NullInteger; } //This is a temporary relationship since the ModuleDef has not been saved to the db //it does not have a valid ModuleDefID. Once it is saved then we can update the //ModuleControlDef with the correct value. ModuleControlDef.ModuleDefID = ModuleDef.TempModuleID; Folder.Controls.Add(ModuleControlDef); } } Folders.Add(Folder); } if (!InstallerInfo.Log.Valid) { throw (new Exception(EXCEPTION_LoadFailed)); } InstallerInfo.Log.EndJob(DNN_Success); return(Folders); } else { string err; foreach (string tempLoopVar_err in DnnErrors) { err = tempLoopVar_err; InstallerInfo.Log.AddFailure(err); } throw (new Exception(EXCEPTION_Format)); } }