Пример #1
0
        /// <summary>
        /// Process ONet.xml file
        /// </summary>
        public void ProcessOnet(string fileName, SiteDefinitionInformation sdi)
        {
            try
            {
                //// A FileStream is needed to read the XML document.
                using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    FileInfo fi = new FileInfo(fileStream.Name);
                    bool inSiteFeatures = false;
                    bool inWebFeatures = false;

                    using (StreamReader reader2 = new StreamReader(fileStream))
                    {
                        while (!reader2.EndOfStream)
                        {
                            string s = reader2.ReadLine().Trim();
                            if (String.Compare(s, "<sitefeatures>", true) == 0)
                            {
                                inSiteFeatures = true;
                                continue;
                            }

                            if (String.Compare(s, "</sitefeatures>", true) == 0)
                            {
                                inSiteFeatures = false;
                                continue;
                            }

                            if (String.Compare(s, "<webfeatures>", true) == 0)
                            {
                                inWebFeatures = true;
                                continue;
                            }

                            if (String.Compare(s, "</webfeatures>", true) == 0)
                            {
                                inWebFeatures = false;
                                continue;
                            }

                            if (inSiteFeatures || inWebFeatures)
                            {
                                int pos = s.IndexOf("Feature ID=\"");
                                if (pos > 0)
                                {
                                    string featId = s.Substring(pos + 12);
                                    pos = featId.IndexOf("\"");
                                    featId = featId.Substring(0, pos);
                                    if (inSiteFeatures)
                                    {
                                        sdi.SiteFeatures.Add(featId);
                                    }
                                    else
                                        sdi.WebFeatures.Add(featId);
                                }
                            }
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                if (_verbose)
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.BackgroundColor = ConsoleColor.Red;
                    Console.WriteLine("Error when processing onet.xml. Error:{0}", ex.Message);
                    Console.ResetColor();
                }
                //ExceptionCSV_SolutionAnalyzer.WriteException(fileName, "ProcessOnet", ex.Message, ex.ToString(), ex.GetType().ToString(), "N/A");

            }
        }
Пример #2
0
        /// <summary>
        /// Process WSP
        /// </summary>
        public void ProcessWsp(string fileName, SolutionInformation solutionInfo)
        {
            string folderWeExtractedTo = "";
            try
            {
                Hashtable ht = new Hashtable();
                FileInfo fi = new FileInfo(fileName);
                solutionInfo.FileSize = (int)fi.Length;
                solutionInfo.FileDate = fi.CreationTime.ToString();

                if (_verbose) { Console.WriteLine("Processing wsp :{0}", fileName); }

                folderWeExtractedTo = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString().Replace("-", ""));

                UnCab(fileName, folderWeExtractedTo);

                if (File.Exists(Path.Combine(folderWeExtractedTo, "manifest.xml")))
                {
                    //// A FileStream is needed to read the XML document.
                    using (FileStream fs = new FileStream(Path.Combine(folderWeExtractedTo, "manifest.xml"), FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        FileInfo fiManifest = new FileInfo(fs.Name);

                        using (XmlReader reader = new XmlTextReader(fs))
                        {
                            // Declare an object variable of the type to be deserialized.
                            // Create an instance of the XmlSerializer specifying type and namespace.
                            XmlSerializer serializer = new XmlSerializer(typeof(Solution));

                            try
                            {
                                Solution sol = new Solution();
                                // Use the Deserialize method to restore the object's state.
                                sol = (Solution)serializer.Deserialize(reader);

                                if (sol.SiteDefinitionManifests != null)
                                {
                                    foreach (SiteDefinitionManifestFileReference siteDef in sol.SiteDefinitionManifests)
                                    {
                                        //siteDefinitions.Add(siteDef.Location);
                                        SiteDefinitionInformation sd = new SiteDefinitionInformation();

                                        sd.Name = siteDef.Location;
                                        sd.NrOfLocales = siteDef.WebTempFile.GetLength(0);
                                        ProcessOnet(Path.Combine(folderWeExtractedTo, siteDef.WebTempFile[0].Location), sd);
                                        solutionInfo.SiteDefinitions.Add(sd);
                                    }
                                }

                                if (sol.FeatureManifests != null)
                                {
                                    foreach (FeatureManifestReference feat in sol.FeatureManifests)
                                    {
                                        _numberOfFeatures = _numberOfFeatures + 1;
                                        ProcessFeatureManifest(Path.Combine(folderWeExtractedTo, feat.Location), solutionInfo, sol);
                                    }
                                }

                                if (sol.Assemblies != null)
                                {
                                    foreach (AssemblyFileReference assembly in sol.Assemblies)
                                    {
                                        ProcessAssembly(assembly, solutionInfo, folderWeExtractedTo);
                                    }
                                }

                                // Look for InfoPath solutions
                                if (solutionInfo.AssemblyCount > 0)
                                {
                                    var InfoPathDependency = solutionInfo.Assemblies.Where(s => s.ReferencedAssemblies.Contains("Microsoft.Office.InfoPath") &&
                                                                                                s.ReferencedAssemblies.Contains("Microsoft.VisualStudio.Tools.Applications.Contract") &&
                                                                                                s.ReferencedAssemblies.Contains("System.AddIn.Contract")).FirstOrDefault();
                                    if (InfoPathDependency != null)
                                    {
                                        solutionInfo.InfoPathSolution = true;
                                    }
                                    else
                                    {
                                        solutionInfo.InfoPathSolution = false;
                                    }
                                }

                                if (sol.TemplateFiles != null)
                                {
                                    SiteDefinitionInformation sdi = new SiteDefinitionInformation();
                                    string lastWebTemp = String.Empty;
                                    foreach (TemplateFileReference files in sol.TemplateFiles)
                                    {
                                        string key = files.Location.Substring(0, files.Location.IndexOf("\\"));
                                        if (ht.ContainsKey(key))
                                        {
                                            int count = (int)ht[key] + 1;
                                            ht[key] = count;
                                        }
                                        else
                                        {
                                            ht.Add(key, 1);
                                        }

                                        if (files.Location.ToLowerInvariant().EndsWith(".aspx"))
                                        {
                                            solutionInfo.AspxPages.Add(files.Location);
                                        }
                                        else if (files.Location.ToLowerInvariant().EndsWith(".ascx"))
                                        {
                                            solutionInfo.UserControls.Add(files.Location);
                                        }
                                        else if (files.Location.ToLowerInvariant().EndsWith(".asmx"))
                                        {
                                            solutionInfo.WebServices.Add(files.Location);
                                        }
                                        else if (files.Location.ToLowerInvariant().EndsWith(".css"))
                                        {
                                            solutionInfo.CSSFiles.Add(files.Location);
                                        }
                                        else if (files.Location.ToLowerInvariant().EndsWith(".js"))
                                        {
                                            solutionInfo.JSFiles.Add(files.Location);
                                        }
                                        else if (files.Location.ToLowerInvariant().EndsWith(".xsl"))
                                        {
                                            solutionInfo.XSLFiles.Add(files.Location);
                                        }
                                        else if (files.Location.ToLowerInvariant().EndsWith("onet.xml"))
                                        {
                                            ProcessOnet(files.Location, sdi);
                                            solutionInfo.SiteDefinitions.Add(sdi);
                                        }
                                        else if (files.Location.ToLowerInvariant().EndsWith(".xml"))
                                        {
                                            ProcessFieldType(files.Location, solutionInfo);
                                            solutionInfo.Files.Add(files.Location);
                                        }
                                        else if (files.Location.ToLowerInvariant().EndsWith(".actions"))
                                        {
                                            ProcessWorkFlowActions(files.Location, solutionInfo);
                                            solutionInfo.Files.Add(files.Location);
                                        }
                                        else if (files.Location.ToLowerInvariant().EndsWith(".actions4"))
                                        {
                                            ProcessWorkFlowActions(files.Location, solutionInfo);
                                            solutionInfo.Files.Add(files.Location);
                                        }
                                        else
                                        {
                                            if (files.Location.Contains("WEBTEMP"))
                                            {
                                                int lastPos = files.Location.LastIndexOf("\\");
                                                string webtempname = files.Location.Substring(lastPos + 1);
                                                if (webtempname == lastWebTemp)
                                                {
                                                    sdi.NrOfLocales = sdi.NrOfLocales + 1;
                                                }
                                                else
                                                {
                                                    sdi.NrOfLocales = 1;
                                                    sdi.Name = webtempname.Substring(7);
                                                    lastWebTemp = webtempname;
                                                }
                                            }
                                            solutionInfo.Files.Add(files.Location);
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                if (ex.Message.StartsWith("There is an error in XML document"))
                                {
                                    if ((fileName.ToLower().EndsWith(".cab")) || (fileName.ToLower().EndsWith(".stp")))
                                    {
                                        if (ProcessCabFile(fiManifest.FullName, solutionInfo))
                                        {
                                        }
                                        else
                                        {
                                            solutionInfo.Error = "The specified file appears to be a Web Part package";
                                        }
                                    }
                                    else
                                    {
                                        solutionInfo.Error = ex.Message;
                                    }
                                }
                                else
                                {
                                    solutionInfo.Error = ex.Message;
                                }

                                //ExceptionCSV_SolutionAnalyzer.WriteException(Path.GetFileName(solutionInfo.Name), "ProcessWSPFile", ex.Message, ex.ToString(), ex.GetType().ToString(), solutionInfo.Error);
                            }
                        }
                    }
                }
            }
            finally
            {
                try
                {
                    Directory.Delete(folderWeExtractedTo, true);
                }
                catch { }
            }
        }