private IEnumerable<List<object>> getSample(Results data, int columns)
 {
     if (columns == 1)
     {
         for (int i = 0; i < data.Box1.Count; i++)
         {
             yield return new List<object> { data.Box1[i] };
         }
     }
     else if (columns == 2)
     {
         for (int i = 0; i < data.Box1.Count; i++)
         {
             yield return new List<object> { data.Box1[i], data.Box2[i] };
         }
     }
     else if (columns == 3)
     {
         for (int i = 0; i < data.Box1.Count; i++)
         {
             yield return new List<object> { data.Box1[i], data.Box2[i], data.Box3[i] };
         }
     }
     else if (columns == 4)
     {
         for (int i = 0; i < data.Box1.Count; i++)
         {
             yield return new List<object> { data.Box1[i], data.Box2[i], data.Box3[i], data.Box4[i] };
         }
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
        public void GenerateSpreadsheet(OperationTemplates template, string outputLocation, Results data)
        {
            var templatePath = GetTemplate(template);
            using (ExcelHelper helper = new ExcelHelper(templatePath, outputLocation))
            {
                helper.Direction = ExcelHelper.DirectionType.TOP_TO_DOWN;
                helper.CurrentSheetName = "Sheet1";
                helper.CurrentPosition = new CellRef("A1");
                helper.InsertRange("header");

                CellRangeTemplate sample1;
                IEnumerable<List<object>> sample = null;
                switch (template)
                {
                    case OperationTemplates.FIND_DLL_BY_PROJECT_TEMPLATE:
                        sample1 = helper.CreateCellRangeTemplate("sample1", new List<string> { "dll", "branch", "version" });
                        sample = getSample(data, 3);
                        break;
                    case OperationTemplates.FIND_DLL_BY_NAME_TEMPLATE:
                        sample1 = helper.CreateCellRangeTemplate("sample1", new List<string> { "project", "projectBranch", "dllBranch", "version"});
                        sample = getSample(data, 4);
                        break;
                    case OperationTemplates.FIND_DLL_BY_SOLUTION_TEMPLATE:
                        sample1 = helper.CreateCellRangeTemplate("sample1", new List<string> { "project", "dllName", "dllBranch", "version" });
                        sample = getSample(data, 4);
                        break;
                    case OperationTemplates.FIND_SERVICE_REFERENCES_BY_NAME_TEMPLATE:
                        sample1 = helper.CreateCellRangeTemplate("sample1", new List<string> { "solution", "branch", "url" });
                        sample = getSample(data, 3);
                        break;
                    case OperationTemplates.FIND_SERVICE_REFERENCES_BY_SOLUTION_TEMPLATE:
                        sample1 = helper.CreateCellRangeTemplate("sample1", new List<string> { "serviceName", "url" });
                        sample = getSample(data, 2);
                        break;
                    default:
                        return;
                }

                helper.InsertRange(sample1, sample);
                helper.DeleteSheet("Sheet3");
            }
        }
Exemplo n.º 3
0
        public Results SearchByProject(string project)
        {
            var results = new Results();
            results.Box1 = new List<string>();
            results.Box2 = new List<string>();
            results.Box3 = new List<string>();

            XmlDocument doc = new XmlDocument();
            doc.Load(project);

            XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
            mgr.AddNamespace("msbld", "http://schemas.microsoft.com/developer/msbuild/2003");

            foreach (XmlNode node in doc.SelectNodes("//msbld:Reference", mgr))
            {
                if (node.HasChildNodes)
                {
                    foreach (XmlNode child in node.ChildNodes)
                    {
                        //We only care about references with hint paths
                        if (child.Name == "HintPath")
                        {
                            var include = child.ParentNode.Attributes["Include"].Value;
                            if (include.Contains(','))
                            {
                                var name = include.Split(',').ToList().First();
                                results.Box1.Add(name);
                            }
                            else
                            {
                                results.Box1.Add(include);
                            }
                            results.Box2.Add(ParseBranchFromPath(child.InnerText));
                            results.Box3.Add(GetVersion(child, project));
                        }
                    }
                }
            }
            return results;
        }
Exemplo n.º 4
0
        public Results SearchByDll(string dll)
        {
            var results = new Results();
            results.Box1 = new List<string>();
            results.Box2 = new List<string>();
            results.Box3 = new List<string>();
            results.Box4 = new List<string>();
            var projects = Directory.GetFiles(@"C:\Projects", "*.csproj", SearchOption.AllDirectories).ToList();
            projects.Sort();
            foreach (var project in projects)
            {
                //If project contains reference to specified dll then add the name, branch, and version
                XmlDocument doc = new XmlDocument();
                doc.Load(project);

                XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
                mgr.AddNamespace("msbld", "http://schemas.microsoft.com/developer/msbuild/2003");
                foreach (XmlNode node in doc.SelectNodes("//msbld:Reference", mgr))
                {
                    if (node.HasChildNodes)
                    {
                        foreach (XmlNode child in node.ChildNodes)
                        {
                            //We only care about references with hint paths
                            if (child.Name == "HintPath")
                            {
                                if (child.InnerText.Split('\\').ToList().Last().Contains(dll))
                                {
                                    results.Box1.Add(project.Split('\\').ToList().Last().TrimEnd(".csproj".ToCharArray()));
                                    results.Box2.Add(ParseBranchFromPath(project));
                                    results.Box3.Add(ParseBranchFromPath(child.InnerText));
                                    results.Box4.Add(GetVersion(child, project));
                                }
                            }
                        }
                    }
                }
            }
            return results;
        }
Exemplo n.º 5
0
        public Results SearchServicesBySolution(string solutionPath)
        {
            var results = new Results();
            results.Box1 = new List<string>();//Service Name
            results.Box2 = new List<string>();//url

            var temp = solutionPath.Split('\\').ToList();
            temp.Remove(temp.Last());
            string folder = string.Empty;
            temp.ForEach(a => folder += (a + '\\'));

            var configs = (Directory.GetFiles(folder, "*.config", SearchOption.AllDirectories).Where(c => c.ToLower().Contains("\\app.config") || c.ToLower().Contains("\\web.config")).ToList());
            configs.Sort();
            foreach (var config in configs)
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(config);
                XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
                foreach (XmlNode node in doc.SelectNodes("//endpoint", mgr))
                {
                    var address = node.Attributes["address"];
                    if (address != null)
                    {
                        var chunks = address.Value.Split('/');
                        if (!results.Box2.Contains(address.Value))
                        {
                            results.Box1.Add(chunks.Last());
                            results.Box2.Add(address.Value);
                        }
                    }
                }
            }

            return results;
        }
Exemplo n.º 6
0
        public Results SearchServicesByService(string serviceName)
        {
            var results = new Results();
            results.Box1 = new List<string>();//solution name
            results.Box2 = new List<string>();//branch
            results.Box3 = new List<string>();//url
            //Get all solution files
            //foreach solution, go up a folder level and do a search for any app.configs or web.configs
            //foreach config in the config collection, parse it to see if it has a reference that matches the service name
            //if it does, add the details to the results

            var solutions = Directory.GetFiles(@"C:\Projects", "*.sln", SearchOption.AllDirectories).ToList();
            solutions.Sort();
            foreach (var solution in solutions)
            {
                var temp = solution.Split('\\').ToList();
                temp.Remove(temp.Last());
                string folder = string.Empty;
                temp.ForEach(a => folder += (a + '\\'));

                var configs = Directory.GetFiles(folder, "*.config", SearchOption.AllDirectories).ToList();
                configs.Sort();
                foreach (var config in configs)
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(config);
                    XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
                    foreach (XmlNode node in doc.SelectNodes("//endpoint", mgr))
                    {
                        var address = node.Attributes["address"];
                        if (address != null)
                        {
                            if (address.Value.ToLower().Contains(serviceName.ToLower()))
                            {
                                results.Box1.Add(ParseSolutionFromPath(solution));
                                results.Box2.Add(ParseBranchFromPath(solution));
                                results.Box3.Add(address.Value);
                            }
                        }
                    }
                }
            }

            return results;
        }
Exemplo n.º 7
0
        public Results SearchBySolution(string solutionPath)
        {
            var results = new Results();
            results.Box1 = new List<string>(); //Dll Name
            results.Box2 = new List<string>(); //Dll Branch
            results.Box3 = new List<string>(); //Dll Version
            results.Box4 = new List<string>(); //Project name

            string directory = string.Empty;
            var pieces = solutionPath.Split('\\').ToList();
            pieces.Remove(pieces.Last());
            foreach (var piece in pieces)
            {
                directory += (piece + "\\");
            }

            var projects = Directory.GetFiles(directory, "*.csproj", SearchOption.AllDirectories).ToList();
            foreach (var project in projects)
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(project);

                XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
                mgr.AddNamespace("msbld", "http://schemas.microsoft.com/developer/msbuild/2003");

                foreach (XmlNode node in doc.SelectNodes("//msbld:Reference", mgr))
                {
                    if (node.HasChildNodes)
                    {
                        foreach (XmlNode child in node.ChildNodes)
                        {
                            //We only care about references with hint paths
                            if (child.Name == "HintPath")
                            {
                                var include = child.ParentNode.Attributes["Include"].Value;
                                if (include.Contains(','))
                                {
                                    var name = include.Split(',').ToList().First();
                                    results.Box2.Add(name);
                                }
                                else
                                {
                                    results.Box2.Add(include);
                                }
                                results.Box3.Add(ParseBranchFromPath(child.InnerText));
                                results.Box4.Add(GetVersion(child, project));
                                var projName = project.Split('\\').ToList().Last();
                                results.Box1.Add(projName);
                            }
                        }
                    }
                }
            }
            return results;
        }