static Compiler() { msbuildDirectory = PathSW.GetDirectoryName(AssemblySW.Wrap(typeof(object).Assembly).Location); }
/// <summary> /// From an Assembly get the error/warning description. /// </summary> /// <param name="node"></param> /// <returns>Assembly resource found result</returns> private bool GetErrorWarningInfoFromAssemblyResources(XmlNode node) { if (node == null) { return(false); } XmlNode childnode = node.SelectSingleNode("./" + Constants.AssemblyResourceAssembly); if (childnode == null) { return(false); } AssemblySW assm = null; if (listofassembliesloaded == null) { listofassembliesloaded = new Hashtable(); } if (String.IsNullOrEmpty(childnode.InnerText)) { return(false); } string assemblyname = childnode.InnerText; if (assemblyname.Contains("Presentation")) { if (String.IsNullOrEmpty(presentationassemblyfullname)) { presentationassemblyfullname = MSBuildEngineCommonHelper.PresentationFrameworkFullName; } int startindex = presentationassemblyfullname.IndexOf(","); presentationassemblyfullname = presentationassemblyfullname.Substring(startindex); assemblyname = assemblyname + presentationassemblyfullname; } else { if (assemblyname.EndsWith(".dll") == false) { assemblyname += ".dll"; } if (String.IsNullOrEmpty(urtpath)) { urtpath = PathSW.GetDirectoryName(typeof(object).Assembly.Location) + PathSW.DirectorySeparatorChar; } assemblyname = urtpath + assemblyname; } childnode = node.SelectSingleNode("./" + Constants.AssemblyResoruceResourceName); if (childnode == null) { return(false); } if (String.IsNullOrEmpty(childnode.InnerText)) { return(false); } string resourcename = childnode.InnerText; if (listofresourcesloaded == null) { listofresourcesloaded = new Hashtable(); } childnode = node.SelectSingleNode("./" + Constants.AssemblyResourceErrorIdentifier); if (childnode == null) { return(false); } if (String.IsNullOrEmpty(childnode.InnerText)) { return(false); } string erroridentifier = childnode.InnerText; ResourceSetSW rs = null; string cultureinfo = null; if (listofresourcesloaded.Contains(resourcename) == false) { if (listofassembliesloaded.Contains(assemblyname)) { assm = (AssemblySW)listofassembliesloaded[assemblyname]; } else { if (FileSW.Exists(assemblyname)) { if (listofassembliesloaded.Contains(assemblyname) == false) { assm = AssemblySW.ReflectionOnlyLoadFrom(assemblyname); } else { assm = (AssemblySW)listofassembliesloaded[assemblyname]; } } else { //assm = Assembly.GetAssembly(typeof(Microsoft.Build.BuildEngine.BuildItem)); AssemblySW[] assmlist = AppDomainSW.CurrentDomain.GetAssemblies(); for (int i = 0; i < assmlist.Length; i++) { object obj = assmlist.GetValue(i); assm = (AssemblySW)obj; if (PathSW.GetFileNameWithoutExtension(assm.ManifestModule.Name).ToLowerInvariant() == assemblyname.ToLowerInvariant()) { break; } assm = null; obj = null; } assmlist = null; } } if (assm == null) { assm = AssemblySW.ReflectionOnlyLoad(assemblyname); if (assm == null) { throw new ApplicationException(assemblyname + " could not be loaded."); } } AssemblySW assm2 = null; try { assm2 = assm.GetSatelliteAssembly(System.Globalization.CultureInfo.CurrentUICulture); cultureinfo = System.Globalization.CultureInfo.CurrentUICulture.Name; assm = null; assm = assm2; assm2 = null; } catch (FileNotFoundException) { MSBuildEngineCommonHelper.LogDiagnostic = "Current UI culture = " + CultureInfo.CurrentUICulture.Name + " with full culture name"; MSBuildEngineCommonHelper.LogDiagnostic = "Assembly " + assm.FullName + " doesn't have a culture dependent resource assembly."; } try { assm2 = assm.GetSatelliteAssembly(System.Globalization.CultureInfo.CurrentUICulture.Parent); cultureinfo = System.Globalization.CultureInfo.CurrentUICulture.Parent.Name; assm = null; assm = assm2; assm2 = null; } catch (FileNotFoundException) { MSBuildEngineCommonHelper.LogDiagnostic = "Current UI culture = " + CultureInfo.CurrentUICulture.Parent.Name + " with full culture name"; MSBuildEngineCommonHelper.LogDiagnostic = "Assembly " + assm.FullName + " doesn't have a culture dependent resource assembly."; } string resourcenamewithculture = null; if (String.IsNullOrEmpty(cultureinfo) == false) { if (resourcename.Contains(".")) { string[] resourcesplit = resourcename.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); if (resourcesplit.Length >= 2) { if (resourcesplit[resourcesplit.Length - 1].ToLowerInvariant() == "resources") { int resindex = resourcename.IndexOf(".resources"); if (resindex > 0) { resourcenamewithculture = resourcename.Substring(0, resindex) + "." + cultureinfo + "." + resourcesplit[resourcesplit.Length - 1]; } } } resourcesplit = null; } } if (listofassembliesloaded.Contains(assemblyname) == false) { listofassembliesloaded.Add(assemblyname, assm); } string[] resourcenames = assm.GetManifestResourceNames(); bool resourcefound = false; for (int j = 0; j < resourcenames.Length; j++) { if (resourcename == resourcenames[j]) { resourcefound = true; break; } if (resourcenamewithculture == resourcenames[j]) { resourcefound = true; break; } } resourcenames = null; if (resourcefound) { StreamSW resourcestream = null; if (String.IsNullOrEmpty(cultureinfo)) { resourcestream = assm.GetManifestResourceStream(resourcename); rs = new ResourceSetSW(resourcestream.InnerObject); if (listofresourcesloaded.Contains(resourcename) == false) { listofresourcesloaded.Add(resourcename, rs); } resourcestream.Close(); } else { resourcestream = assm.GetManifestResourceStream(resourcenamewithculture); rs = new ResourceSetSW(resourcestream.InnerObject); if (listofresourcesloaded.Contains(resourcename) == false) { listofresourcesloaded.Add(resourcename, rs); } resourcestream.Close(); } resourcestream = null; } } else { rs = (ResourceSetSW)listofresourcesloaded[resourcename]; } if (rs != null) { string errordescription = rs.GetString(erroridentifier); if (String.IsNullOrEmpty(errordescription)) { return(false); } if (errordescription.StartsWith(id)) { try { Convert.ToInt16(id); } catch (FormatException) { errordescription = errordescription.Substring(id.Length); } //errordescription = errordescription.Substring(id.Length); startingmessage = errortype.ToString().ToLowerInvariant() + " " + id; errordescription = errordescription.Trim(); } if (errordescription.StartsWith(":")) { errordescription = errordescription.Substring(1).Trim(); } ConvertResourceDescriptionToArray(errordescription); errordescription = null; } else { MSBuildEngineCommonHelper.Log = "The following erroridentifier could not be found as resourceset was null."; MSBuildEngineCommonHelper.Log = "ErrorIdentifier = " + erroridentifier; MSBuildEngineCommonHelper.Log = "Resourcname = " + resourcename; MSBuildEngineCommonHelper.Log = "Culture = " + cultureinfo; MSBuildEngineCommonHelper.Log = "AssemblyName = " + assemblyname; } return(true); }
/// <summary> /// Encapsulated method - taking 3 input params /// Does the file generation. /// First based on inputs decides the final file name for the file to be generated. /// </summary> /// <param name="scenarioid"></param> /// <param name="variationstring"></param> private void GenerateFile(string scenarioid, string variationstring) { // If no scenarioid is defined set to all. if (scenarioid == null) { scenarioid = "_all"; } // If newfiledata is null make a bunch of checks to come up with final name and fileextension. FileData tempfiledata = definedfiledata; if (String.IsNullOrEmpty(tempfiledata.FileName)) { // Use default filename (defined in Attribute or element in TemplateData). Refer GetTemplateData method. tempfiledata.FileName = defaultfiledata.FileName; } if (String.IsNullOrEmpty(tempfiledata.FileExtension)) { // Use default fileextension (defined in Attribute or element in TemplateData). Refer GetTemplateData method. tempfiledata.FileExtension = defaultfiledata.FileExtension; } // Generate XmlDocument with defaultdata document innerxml. if (base.canvasdoc == null) { UtilsLogger.LogError = "Variation document is null"; return; } if (base.canvasdoc.GetElementsByTagName(Constants.TemplateDataElement) == null) { UtilsLogger.LogError = "Variation document did not contain TemplateData element"; return; } if (base.canvasdoc.GetElementsByTagName(Constants.TemplateDataElement).Count > 1) { UtilsLogger.LogError = "Variation document contained more than one TemplateData element"; return; } // Generated file name. if (_retainfilename == false) { if (variationstring != null) { generatedFile = tempfiledata.FileName + "_Sc" + scenarioid + "_Var" + variationstring + tempfiledata.FileExtension; } else { generatedFile = tempfiledata.FileName + "_Sc" + scenarioid + "_Var" + "all" + tempfiledata.FileExtension; } } else { generatedFile = tempfiledata.FileName + tempfiledata.FileExtension; } if (String.IsNullOrEmpty(_fileoutputdirectory) == false) { if (DirectorySW.Exists(_fileoutputdirectory)) { generatedFile = _fileoutputdirectory + PathSW.DirectorySeparatorChar + generatedFile; } } if (generatedFile.Contains(PathSW.DirectorySeparatorChar.ToString())) { string directoryname = PathSW.GetDirectoryName(generatedFile); if (string.IsNullOrEmpty(directoryname) == false) { if (DirectorySW.Exists(directoryname) == false) { if (DirectorySW.Exists(directoryname) == false) { DirectorySW.CreateDirectory(directoryname); } } } } if (_isxmldocument) { XmlDocumentSW tempdoc = new XmlDocumentSW(); tempdoc.LoadXml(base.canvasdoc.DocumentElement.InnerXml); GenerateFile(ref tempdoc); tempdoc = null; } else { GenerateFile(base.canvasdoc.DocumentElement.InnerText); } }