List<DMAssemblyName> DeployAsm() { bool isNonLocal = false; string asmWarning; List<DMAssemblyName> asl = null; try { //Debugger.Launch(); //deploy the assembly //get the perm set switch (PermissionSet) { case 0: perm = "SAFE"; break; case 1: perm = "EXTERNAL_ACCESS"; break; case 2: perm = "UNSAFE"; break; default: perm = "SAFE"; break; } string createCmd = "CREATE ASSEMBLY "; string logCmd = "--Creating the assembly"; if (alterAsm) { createCmd = "ALTER ASSEMBLY "; logCmd = "--Altering the assembly"; } //get the binary rep of the main assembly StringBuilder sb = new StringBuilder(); sb.Append(GetBinary(asmPath, true)); //ArrayList asl = new ArrayList(); asl = new List<DMAssemblyName>(); //if not alter, get the binary representation of the dependent assemblies if (!alterAsm) { //get the dependent assemblies asl = GetReferencedAssemblies(); StringBuilder nonBlessed = new StringBuilder(); nonBlessed.Append("***WARNING***\nFollowing assemblies - which are referenced by the main assembly - are not in the applicaton directory, and not in the 'blessed' list either:\n"); string depName = null; foreach (DMAssemblyName an in asl) { if (an.IsLocal) { depName = an.AssemblyFileName; sb.Append(GetBinary(depName, false)); } else { isNonLocal = true; nonBlessed.Append(" * " + an.ShortName + "\n"); } } if (isNonLocal) { nonBlessed.Append("The above assemblies have to be catalogued in the database before this deployment can succeed.\n***END WARNING***\n"); asmWarning = nonBlessed.ToString(); Utility.LogMyComment(this, asmWarning); } } string deployCmd = string.Format("{0} [{1}]\nFROM {2}\nWITH PERMISSION_SET = {3}", createCmd, asmName, sb.ToString(), perm); string createText = "About to create assembly '" + asmName + "':\n"; if (alterAsm) { //Debugger.Launch(); //we need to drop debug symbols //before being able to alter an assembly if (deployDebug) DropFiles(); createText = "About to alter assembly '" + asmName + "':\n"; if (unChecked) { deployCmd = string.Format("{0},\n{1}", deployCmd, "UNCHECKED DATA"); } } //add the main assembly to the list (will be used for debug symbols) DMAssemblyName dmasm = new DMAssemblyName(asmPath, asmName, true); asl.Add(dmasm); string logComment = createText + deployCmd + "\n"; Utility.LogMyComment(this, logComment); if (toScript) { Utility.WriteToFile(sw, logCmd, false, false); Utility.WriteToFile(sw, deployCmd, true, true); } if (toConnect) { //Debugger.Launch(); Utility.WriteToDb(deployCmd, conn, tx); } return asl; } catch (Exception e) { if(toConnect && alterAsm) { if(e.Message.Contains("ALTER ASSEMBLY has marked data as unchecked")) { Utility.LogMyComment(this, e.Message); } else { Utility.LogMyErrorFromException(this, e); throw e; } } else { Utility.LogMyErrorFromException(this, e); throw e; } return asl; } finally { } }
void LoopAsm(ref List<DMAssemblyName> asmList, string asmPath, string asmName, string asmFullPath, DMAssemblyName dmAsmName) { //Debugger.Launch(); Assembly a = null; if (asmFullPath != null && dmAsmName == null) { a = Assembly.ReflectionOnlyLoadFrom(asmFullPath); } else if (asmFullPath == null && dmAsmName == null) { asmFullPath = Path.Combine(asmPath, asmName + ".dll"); a = Assembly.ReflectionOnlyLoadFrom(asmFullPath); } else if (dmAsmName != null && dmAsmName.IsLocal) { a = Assembly.ReflectionOnlyLoadFrom(dmAsmName.AssemblyFileName); } else if (dmAsmName != null && !dmAsmName.IsLocal) { a = Assembly.ReflectionOnlyLoad(dmAsmName.AssemblyFullName); } if (a != null) { foreach (AssemblyName an in a.GetReferencedAssemblies()) { if (an.Name != "yukondeploy" && an.Name != "deployattributes") { DMAssemblyName refAsm = CheckIfAsmBlessed(an.Name, an.FullName); if (refAsm != null) { if (!refAsm.IsLocal) refAsm.AssemblyFullName = an.FullName; if (!asmList.Exists(delegate(DMAssemblyName asmx) { return asmx.ShortName == an.Name; } )) { asmList.Add(refAsm); if(!refAsm.IsMSAssembly) LoopAsm(ref asmList, asmPath, an.Name, refAsm.AssemblyFileName, refAsm); } } } } } }
//this loops through the list of blessed assemblies //to see if referenced assemblies are in the blessed list //if not add them to the list of referenced assemblies DMAssemblyName CheckIfAsmBlessed(string asmName, string asmFullName) { DMAssemblyName dasm = null; //string retString = null; bool isGac = false; string[] gacDlls = gacDlls2k5; //in Katmai we have more dlls allowed being loaded from the GAC if (servVersion == ServerVersion.S2K8) { gacDlls = gacDlls2k8; } foreach (string gacAsm in gacDlls) { if (gacAsm.ToUpper().IndexOf(asmName.ToUpper()) != -1) { isGac = true; break; } } if (!isGac) { dasm = new DMAssemblyName(); dasm.ShortName = asmName; dasm.AssemblyFullName = asmFullName; dasm.IsLocal = false; //check against the local dll's foreach (string locAsm in dlls) { if (locAsm.ToUpper().IndexOf(asmName.ToUpper()) != -1) { dasm.AssemblyFileName = locAsm; dasm.IsLocal = true; break; } } //check if this is a MS System assembly if (!dasm.IsLocal) { foreach (string pkt in msKeyTokens) { if(dasm.AssemblyFullName.Contains(pkt)) { dasm.IsMSAssembly = true; break; } } } } return dasm; }