/// <summary> /// History: /// /// 12/9/2006 - Mike : Had to add a check for the attribute count when checking directories because /// of the new altova hack. /// </summary> /// <param name="strVirtualPathToProcess"></param> /// <param name="bMatch"></param> /// <returns></returns> public static string resolveNameAndFolder(string strVirtualPathToProcess, ref bool bMatch) { //TODO: refactor this, it smellz! try { string strDirectoryPath = Path.GetDirectoryName(strVirtualPathToProcess); string strFileName = Path.GetFileName(strVirtualPathToProcess); SiteMapping smCurrent = SiteMapping.GetSiteMapping(); if (null == strDirectoryPath) { return(strVirtualPathToProcess); } XmlNode xnXmlDataToUse = smCurrent.Mapping.DocumentElement.GetElementsByTagName("rootFolder")[0]; // I wanted to place this here but this becomes null after a while if (null != xnXmlDataToUse) { // map directory foreach (string strDirToProcess in strDirectoryPath.Split('\\')) { if (bMatch && strDirToProcess == "") { break; // for the case where strDirToProcess = } bMatch = false; foreach (XmlNode xnDirectories in xnXmlDataToUse.ChildNodes) { if ((xnDirectories.Attributes.Count > 0) && (xnDirectories.Attributes.GetNamedItem("name").Value.ToUpper() == strDirToProcess.ToUpper())) { xnXmlDataToUse = xnDirectories; bMatch = true; break; } } } if (bMatch || strDirectoryPath == "\\") // case when we find a match on a sub dir and case when we are on the root { // map File foreach (XmlNode xnFiles in xnXmlDataToUse.ChildNodes) { bMatch = false; if (xnFiles.Attributes.GetNamedItem("name").Value.ToUpper() == strFileName.ToUpper()) { bMatch = true; string strMappedFileName = xnFiles.Attributes.GetNamedItem("mappedTo").Value; return(strMappedFileName); } } } } } catch (Exception ex) { Console.WriteLine("Error in resolveNameAndFolder: " + ex.Message); } bMatch = false; return(strVirtualPathToProcess); }
public static bool isPathAFolder(string strVirtualPathToProcess, ref XmlNode xnSelectedDirectory) { SiteMapping smCurrent = SiteMapping.GetSiteMapping(); char[] charSeperators = new char[] { '/' }; XmlNode xnXmlDataToUse = smCurrent.Mapping.DocumentElement.GetElementsByTagName("site")[0]; // I wanted to place this here but this becomes null after a while bool bMatch = false; if (null != xnXmlDataToUse) { // Handle the root folder case... if (strVirtualPathToProcess == "/") { xnSelectedDirectory = smCurrent.Mapping.DocumentElement.GetElementsByTagName("rootFolder")[0]; bMatch = true; } else { // map directory foreach (string strDirToProcess in strVirtualPathToProcess.Split(charSeperators, StringSplitOptions.RemoveEmptyEntries)) { if (bMatch && strDirToProcess == "") { break; // for the case where strDirToProcess = } bMatch = false; foreach (XmlNode xnDirectories in xnXmlDataToUse.ChildNodes) { if ((xnDirectories.Name == "folder") || (xnDirectories.Name == "rootFolder")) { // Do a case-insensitive compare XmlNode xnName = xnDirectories.Attributes.GetNamedItem("name"); if ((xnName != null) && (xnName.Value.ToUpper() == strDirToProcess.ToUpper())) { xnXmlDataToUse = xnDirectories; xnSelectedDirectory = xnDirectories; bMatch = true; break; } } } } } } if (!bMatch) { xnSelectedDirectory = null; } return(bMatch); }
public static string CreateFileW(string strOriginalFileName) { SiteMapping smCurrent = SiteMapping.GetSiteMapping(); string strFullPathToRootDir = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, Path.Combine(ConfigurationManager.AppSettings["StaticPagePath"], "SiteA"))); string strProcessedFileName = strOriginalFileName; // defaults to the original one if (strOriginalFileName.ToUpper().IndexOf(SGIdentifier) > -1) { string[] strSplitedRequest = strOriginalFileName.ToUpper().Split(new string[] { SGIdentifier }, StringSplitOptions.RemoveEmptyEntries); if (strSplitedRequest.Length == 1) // we are in the root of the [SG] files so let's point it to strFullPathToRootDir { return(strFullPathToRootDir); } if (strSplitedRequest.Length == 2) { string strVirtualPathToProcess = strSplitedRequest[1]; strVirtualPathToProcess = strVirtualPathToProcess.Replace('-', '\\'); string strDirectoryPath = Path.GetDirectoryName(strVirtualPathToProcess); string strFileName = Path.GetFileName(strVirtualPathToProcess); Console.Write("dir: " + strDirectoryPath); Console.WriteLine("file: " + strFileName); if (null == strDirectoryPath) { return(strFullPathToRootDir); } XmlNode xnXmlDataToUse = smCurrent.Mapping.DocumentElement.GetElementsByTagName("site")[0]; bool bMatch = false; if (null != xnXmlDataToUse) { // map directory foreach (string strDirToProcess in strDirectoryPath.Split('\\')) { if (bMatch && strDirToProcess == "") { break; // for the case where strDirToProcess = } bMatch = false; foreach (XmlNode xnDirectories in xnXmlDataToUse.ChildNodes) { if (xnDirectories.Attributes.GetNamedItem("name").Value.ToUpper() == strDirToProcess.ToUpper()) // .ToUpper() will make it case insensitive { xnXmlDataToUse = xnDirectories; bMatch = true; break; } } } if (bMatch) { // map File foreach (XmlNode xnFiles in xnXmlDataToUse.ChildNodes) { bMatch = false; if (xnFiles.Attributes.GetNamedItem("name").Value.ToUpper() == strFileName.ToUpper()) { bMatch = true; string strMappedFileName = xnFiles.Attributes.GetNamedItem("mappedTo").Value; if (strMappedFileName.IndexOf("~\\") > -1) // "~\\" means use the website base directory { return(Path.GetFullPath(Path.Combine(strSplitedRequest[0], strMappedFileName))); // strSplitedRequest[0] contains the what was to the left of GlobalVariables.strSiteGenerator_SGIdentifierString } else { return(Path.GetFullPath(Path.Combine(strFullPathToRootDir, strMappedFileName))); // strFullPathToRootDir contains the full path to this Site's Root Dir (i.e. not the original wwwroot folder) } } } } } } else if (SiteGenerator_Transformers.tbDebugMessages != null) { GUI.updateTextBox("CreateFileW Transformer error: more that 1 instance of *", SiteGenerator_Transformers.tbDebugMessages); } } return(strProcessedFileName); }