Exemplo n.º 1
0
        /// <summary>
        /// Read additional file information.
        /// </summary>
        /// <param name="xmldatafile"></param>
        /// <returns></returns>
        public override bool Read(string xmldatafile)
        {
            defaultfiledata.FileName      = PathSW.GetFileNameWithoutExtension(xmldatafile);
            defaultfiledata.FileExtension = PathSW.GetExtension(xmldatafile);

            return(base.Read(xmldatafile));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Return the Generated Assembly from the list.
        /// </summary>
        /// <param name="text"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        internal string GetGeneratedAssembly(string text, XmlNode node)
        {
            int    index    = -1;
            string filetype = "withoutextension";

            if (text.Contains("[") || text.Contains("]"))
            {
                index = text.IndexOf("[");
                if (index < 0)
                {
                    index    = text.IndexOf("]");
                    filetype = text.Substring(0, index);
                }
                else
                {
                    if (text.Contains("]"))
                    {
                        filetype = text.Substring(index + 1, text.IndexOf("]") - index - 1);
                    }
                }
            }

            index = text.IndexOf(':');
            if (index < 0)
            {
                return(null);
            }

            text  = text.Substring(index + 1, text.Length - index - 1);
            index = Convert.ToInt16(text);

            if (_generatedassembliestable.Contains(index))
            {
                GeneratedAssemblyInfo asseminfo = (GeneratedAssemblyInfo)_generatedassembliestable[index];
                text = asseminfo.GeneratedAssembly;
            }

            if (filetype.ToLowerInvariant() == "withoutextension")
            {
                text = PathSW.GetFileNameWithoutExtension(text);
            }

            return(text);
        }
Exemplo n.º 3
0
        /// <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);
        }