private static String GetCursorText(ConfigXmlCursor cursor) { String strText = String.Empty; if (cursor.MoveToFirstChild()) { while (cursor.Type == ConfigXmlElement.Whitespace || cursor.Type == ConfigXmlElement.Text) { strText += cursor.Text; // grab the text if (!cursor.MoveNext()) { break; } } cursor.MoveToParent(); } return(strText.Trim()); }
private static String GetCabFileNameFromCursor(ConfigXmlCursor cursor) { String strReturn = String.Empty; if (cursor.MoveToFirstChild()) { do { if (cursor.Type == ConfigXmlElement.Element && cursor.Name.ToLower(CultureInfo.InvariantCulture).Equals("codebase")) { strReturn = cursor.AttributeText("href"); break; } }while (cursor.MoveNext()); cursor.MoveToParent(); } return(strReturn); }
////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// // Private stuff ////////////////////////////////////////////////////////////////////// // Create a manifest from a manifest file static internal MyWebManifest CreateFromFile( String strFile, String strUrl, bool installed, bool donotfail) { String [] strProperties = null; ConfigXmlDocument xmlDoc = null; ConfigXmlCursor cursor = null; int iter = 0; int iRet = 0; StringBuilder strBuf = new StringBuilder(1024); bool fFound = false; ArrayList customUrls = new ArrayList(); ArrayList customUrlDs = new ArrayList(); String strRandom = System.Web.SessionState.SessionId.Create(); //////////////////////////////////////////////////////////// // Step 1: Parse the file and get the other properties try { xmlDoc = new ConfigXmlDocument(); xmlDoc.Load(strFile); cursor = xmlDoc.GetCursor(); cursor.MoveToFirstChild(); } catch (Exception e) { if (!donotfail) { throw e; } cursor = null; } if (cursor != null) { do { if (cursor.Type == ConfigXmlElement.Element && cursor.Name.ToLower(CultureInfo.InvariantCulture).Equals("softpkg")) { fFound = true; break; } }while (cursor.MoveNext()); } if (!fFound && !donotfail) { return(null); } //////////////////////////////////////////////////////////// // Step 2: Get the non-manifest file properties strProperties = new String[NUM_PROPERTIES]; for (iter = 0; iter < NUM_PROPERTIES; iter++) { strProperties[iter] = String.Empty; } strProperties[_ApplicationUrl] = strUrl.Replace('\\', '/'); strProperties[_ManifestFile] = strFile; if (!installed) { iRet = NativeMethods.MyWebGetInstallLocationForUrl(MyWeb.GetDefaultInstallLocation(), strUrl, strRandom, strBuf, 1024); if (iRet < 0) { iRet = -iRet + 100; strBuf = new StringBuilder(iRet); iRet = NativeMethods.MyWebGetInstallLocationForUrl(MyWeb.GetDefaultInstallLocation(), strUrl, strRandom, strBuf, iRet); } if (iRet <= 0) { throw new HttpException(HttpRuntime.FormatResourceString(SR.Unable_to_get_app_location)); } strProperties[_InstalledLocation] = strBuf.ToString(); } else { strProperties[_InstalledLocation] = strFile.Substring(0, strFile.LastIndexOf('\\')); } if (cursor == null && donotfail) { return(new MyWebManifest(strProperties, installed, new String[0], new String[0])); } strProperties[_Name] = cursor.AttributeText("name"); strProperties[_Version] = cursor.AttributeText("version"); cursor.MoveToFirstChild(); do { if (cursor.Type == ConfigXmlElement.Element) { String strName = cursor.Name.ToLower(CultureInfo.InvariantCulture); if (strName.Equals("implementation")) { strProperties[_CabFile] = GetCabFileNameFromCursor(cursor); } else if (strName.Equals("license")) { strProperties[_License] = cursor.AttributeText("href"); } else if (strName.Equals("customurl")) { String strC = cursor.AttributeText("href"); String strD = cursor.AttributeText("description"); customUrls.Add(strC); customUrlDs.Add(strD); } else { for (iter = 0; iter < _OtherProperties.Length; iter++) { if (strName.Equals(_OtherProperties[iter])) { strProperties[OTHER_PROP_START + iter] = GetCursorText(cursor); break; } } } } }while (cursor.MoveNext()); return(new MyWebManifest(strProperties, installed, customUrls.ToArray(), customUrlDs.ToArray())); }