コード例 #1
0
        public void InitialData()
        {
            if (_prjList == null || _prjList.Count < 1)
            {
                return;
            }
            _dirModel = FileDirUtility.ReadAllDirAndFiles(_dllRootDir);

            for (int i = 0; i < _prjList.Count; i++)
            {
                TreeNode rootNode = this.treeView1.Nodes.Add(_prjList[i].Name);

                VSProject  vsProj  = _prjList[i].Object as VSProject;
                References dllRefs = vsProj.References;
                if (dllRefs == null)
                {
                    continue;
                }
                foreach (Reference dllRef in dllRefs)
                {
                    TreeNode subRootNode = rootNode.Nodes.Add(dllRef.Name);
                    if (dllRef.Name.StartsWith("System") || dllRef.Name.StartsWith("mscorlib"))
                    {
                        continue;
                    }
                    string dllPath = dllRef.Path;
                    if (string.IsNullOrEmpty(dllPath) || File.Exists(dllPath) == false)
                    {
                        continue;
                    }
                    int count = 0;
                    this.GetDllListTreeNode(dllPath, ref subRootNode, ref count);
                }
            }
        }
コード例 #2
0
        private void combSolutionPlatform_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (this.combSolutionPlatform.SelectedItem == null)
                {
                    return;
                }
                string dllRootDir = this.txtLibRootDir.Text.Trim();
                if (string.IsNullOrEmpty(dllRootDir) || Directory.Exists(dllRootDir) == false)
                {
                    return;
                }
                if (_dirModel == null || _dirModel.DirectoryPath != dllRootDir)
                {
                    _dirModel = FileDirUtility.ReadAllDirAndFiles(dllRootDir);
                }
                string solPlatform = this.combSolutionPlatform.SelectedItem.ToString();
                for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
                {
                    Project proj = this.dataGridView1.Rows[i].Tag as Project;
                    if (proj != null)
                    {
                        foreach (Configuration config in proj.ConfigurationManager)
                        {
                            if (config.ConfigurationName == solPlatform)
                            {
                                string rootDir = Path.GetDirectoryName(proj.FileName);

                                string objDllPath = Path.Combine(rootDir, "obj");
                                objDllPath = Path.Combine(objDllPath, solPlatform);
                                objDllPath = Path.Combine(objDllPath, proj.Properties.Item("OutputFileName").Value.ToString());
                                if (File.Exists(objDllPath))
                                {
                                    this.dataGridView1[2, i].Value       = objDllPath.Substring(rootDir.Length + 1);
                                    this.dataGridView1[2, i].Tag         = objDllPath;
                                    this.dataGridView1[2, i].ToolTipText = objDllPath;
                                }
                                else
                                {
                                    string outputPath = config.Properties.Item("OutputPath").Value.ToString();
                                    char[] charList   = outputPath.ToCharArray();
                                    int    num        = 0;
                                    for (int j = 0; j < charList.Length; j++)
                                    {
                                        if (charList[j] == '.')
                                        {
                                            bool isOK = true;
                                            for (int k = 0; k < j; k++)
                                            {
                                                if (charList[k] != '.')
                                                {
                                                    isOK = false;
                                                }
                                            }
                                            if (isOK)
                                            {
                                                num++;
                                            }
                                        }
                                    }
                                    for (int j = 0; j < num - 1; j++)
                                    {
                                        rootDir = rootDir.Substring(0, rootDir.LastIndexOf('\\'));
                                    }
                                    string fileName = proj.Properties.Item("OutputFileName").Value.ToString();
                                    if (outputPath.StartsWith("."))
                                    {
                                        outputPath = outputPath.Substring(outputPath.LastIndexOf('.') + 2);
                                    }
                                    outputPath = Path.Combine(rootDir, outputPath);
                                    outputPath = Path.Combine(outputPath, fileName);
                                    if (outputPath.EndsWith(".dll", StringComparison.CurrentCultureIgnoreCase) == false)
                                    {
                                        continue;
                                    }
                                    this.dataGridView1[2, i].Value       = outputPath.Substring(rootDir.Length + 1);
                                    this.dataGridView1[2, i].Value       = outputPath;
                                    this.dataGridView1[2, i].ToolTipText = outputPath;
                                }
                                break;
                            }
                        }
                        //查找最佳目标dll路径
                        List <string> similarDlls = new List <string>();
                        this.FindSimilarDlls(_dirModel, proj.Name, ref similarDlls);
                        if (similarDlls.Count > 0)
                        {
                            string cellValue = string.Empty;
                            string toolTip   = string.Empty;
                            for (int j = 0; j < similarDlls.Count; j++)
                            {
                                if (j == 0)
                                {
                                    cellValue = similarDlls[j].Substring(dllRootDir.Length + 1);
                                    toolTip   = similarDlls[j];
                                }
                                else
                                {
                                    cellValue += "#" + similarDlls[j].Substring(dllRootDir.Length + 1);
                                    toolTip   += "#" + similarDlls[j];
                                }
                            }
                            this.dataGridView1[3, i].Value       = cellValue;
                            this.dataGridView1[3, i].Tag         = similarDlls;
                            this.dataGridView1[3, i].ToolTipText = toolTip;
                        }
                        this.dataGridView1[4, i].Value = similarDlls.Count;
                    }
                }
            }
            catch (Exception ex)
            {
                MsgBox.ShowTip(ex.Message);
            }
        }
コード例 #3
0
        private void rMenuModifySelection_Click(object sender, EventArgs e)
        {
            if (this.dataGridView1.SelectedRows == null || this.dataGridView1.SelectedRows.Count < 1)
            {
                return;
            }
            References dllRefs = this.dataGridView1.Tag as References;

            if (dllRefs == null)
            {
                return;
            }
            string dllRootDir      = this.txtLibRootDir.Text.Trim();
            string dotNetBarDir    = this.txtDotNetBarDir.Text.Trim();
            string infragisticsDir = this.txtInfragisticsDir.Text.Trim();

            if (string.IsNullOrEmpty(dllRootDir) || Directory.Exists(dllRootDir) == false)
            {
                MsgBox.ShowTip("请先输入Lib根目录");
                return;
            }
            bool   proItemFirst = this.chkProItemFirst.Checked;
            string solPlatform  = this.combSolutionPlatform.SelectedItem.ToString();

            this.Cursor = Cursors.WaitCursor;

            //读取lib和第三方类库
            _dirModel = FileDirUtility.ReadAllDirAndFiles(dllRootDir);
            if (string.IsNullOrEmpty(dotNetBarDir) == false && Directory.Exists(dotNetBarDir))
            {
                _dotNetBarDirModel = FileDirUtility.ReadAllDirAndFiles(dotNetBarDir);
            }
            if (string.IsNullOrEmpty(infragisticsDir) == false && Directory.Exists(infragisticsDir))
            {
                _infragisticsDirModel = FileDirUtility.ReadAllDirAndFiles(infragisticsDir);
            }

            for (int i = 0; i < this.dataGridView1.SelectedRows.Count; i++)
            {
                DataGridViewRow selRow = this.dataGridView1.SelectedRows[i];
                Reference       dllRef = selRow.Tag as Reference;
                if (dllRef == null)
                {
                    continue;
                }
                //优先引用项目,再引用lib下的dll
                Project bestSimilarProj = null;
                if (proItemFirst)
                {
                    string dllName = dllRef.Name;
                    bestSimilarProj = this.FindProItem(dllName, solPlatform);
                    string bestSimilarDll = this.FindProItemOutPath(dllName, solPlatform);
                    if (bestSimilarProj != null)
                    {
                        string dllFilePath = this.GetOutPutDllPath(bestSimilarProj, solPlatform);
                        if (dllFilePath.Equals(dllRef.Path, StringComparison.CurrentCultureIgnoreCase))
                        {
                            continue;
                        }

                        selRow.Tag = null;
                        dllRef.Remove();

                        dllRef = dllRefs.AddProject(bestSimilarProj);

                        selRow.Tag            = dllRef;
                        selRow.Cells[0].Value = Path.GetFileNameWithoutExtension(bestSimilarDll);
                        selRow.Cells[1].Value = bestSimilarDll;
                    }
                }
                if (bestSimilarProj == null)
                {
                    List <string> similarDlls = new List <string>();
                    if (_dotNetBarDirModel != null && dllRef.Name.ToUpper().Contains("DevComponents".ToUpper()))
                    {
                        this.FindSimilarDlls(_dotNetBarDirModel, dllRef.Name, ref similarDlls);
                    }
                    else if (_infragisticsDirModel != null && dllRef.Name.ToUpper().Contains("Infragistics".ToUpper()))
                    {
                        this.FindSimilarDlls(_infragisticsDirModel, dllRef.Name, ref similarDlls);
                    }
                    if (similarDlls.Count == 0)
                    {
                        this.FindSimilarDlls(_dirModel, dllRef.Name, ref similarDlls);
                    }
                    if (similarDlls.Count < 1)
                    {
                        continue;
                    }
                    string bestSimilarDll = similarDlls[0];
                    if (similarDlls.Count > 1)
                    {
                        double maxSim      = double.MinValue;
                        int    maxSimIndex = 0;
                        for (int j = 0; j < similarDlls.Count; j++)
                        {
                            double sim = StrSimCalculator.CalculateSim(similarDlls[j], dllRef.Path);
                            if (maxSim < sim)
                            {
                                maxSim      = sim;
                                maxSimIndex = j;
                            }
                        }
                        bestSimilarDll = similarDlls[maxSimIndex];
                    }
                    if (bestSimilarDll.Equals(dllRef.Path, StringComparison.CurrentCultureIgnoreCase))
                    {
                        continue;
                    }

                    selRow.Tag = null;
                    dllRef.Remove();

                    try
                    {
                        dllRef = dllRefs.Add(bestSimilarDll);
                    }
                    catch
                    {
                    }
                    selRow.Tag            = dllRef;
                    selRow.Cells[0].Value = Path.GetFileNameWithoutExtension(bestSimilarDll);
                    selRow.Cells[1].Value = bestSimilarDll;
                }
            }
            this.Cursor = Cursors.Default;
        }
コード例 #4
0
        private void rMenuModifyAll_Click(object sender, EventArgs e)
        {
            if (this.combProjects.Tag == null)
            {
                return;
            }
            string dllRootDir      = this.txtLibRootDir.Text.Trim();
            string dotNetBarDir    = this.txtDotNetBarDir.Text.Trim();
            string infragisticsDir = this.txtInfragisticsDir.Text.Trim();

            if (string.IsNullOrEmpty(dllRootDir) || Directory.Exists(dllRootDir) == false)
            {
                MsgBox.ShowTip("请先输入Lib根目录");
                return;
            }
            bool   proItemFirst = this.chkProItemFirst.Checked;
            string solPlatform  = this.combSolutionPlatform.SelectedItem.ToString();

            this.Cursor = Cursors.WaitCursor;

            //读取lib和第三方类库
            _dirModel = FileDirUtility.ReadAllDirAndFiles(dllRootDir);
            if (string.IsNullOrEmpty(dotNetBarDir) == false && Directory.Exists(dotNetBarDir))
            {
                _dotNetBarDirModel = FileDirUtility.ReadAllDirAndFiles(dotNetBarDir);
            }
            if (string.IsNullOrEmpty(infragisticsDir) == false && Directory.Exists(infragisticsDir))
            {
                _infragisticsDirModel = FileDirUtility.ReadAllDirAndFiles(infragisticsDir);
            }

            List <Project> prjList = this.combProjects.Tag as List <Project>;

            for (int p = 0; p < prjList.Count; p++)
            {
                VSProject  vsProj  = prjList[p].Object as VSProject;
                References dllRefs = vsProj.References;
                if (dllRefs == null)
                {
                    continue;
                }
                foreach (Reference dllRef in dllRefs)
                {
                    if (this.IsNeedChangePath(dllRef.Path) == false)
                    {
                        continue;
                    }
                    //优先引用项目,再引用lib下的dll
                    Project bestSimilarProj = null;
                    if (proItemFirst)
                    {
                        string dllName = dllRef.Name;
                        bestSimilarProj = this.FindProItem(dllName, solPlatform);
                        if (bestSimilarProj != null)
                        {
                            string dllFilePath = this.GetOutPutDllPath(bestSimilarProj, solPlatform);
                            if (dllFilePath.Equals(dllRef.Path, StringComparison.CurrentCultureIgnoreCase))
                            {
                                continue;
                            }
                            dllRef.Remove();
                            dllRefs.AddProject(bestSimilarProj);
                        }
                    }
                    if (bestSimilarProj == null)
                    {
                        List <string> similarDlls = new List <string>();
                        if (_dotNetBarDirModel != null && dllRef.Name.ToUpper().Contains("DevComponents".ToUpper()))
                        {
                            this.FindSimilarDlls(_dotNetBarDirModel, dllRef.Name, ref similarDlls);
                        }
                        else if (_infragisticsDirModel != null && dllRef.Name.ToUpper().Contains("Infragistics".ToUpper()))
                        {
                            this.FindSimilarDlls(_infragisticsDirModel, dllRef.Name, ref similarDlls);
                        }
                        if (similarDlls.Count == 0)
                        {
                            this.FindSimilarDlls(_dirModel, dllRef.Name, ref similarDlls);
                        }
                        if (similarDlls.Count < 1)
                        {
                            continue;
                        }
                        string bestSimilarDll = similarDlls[0];
                        if (similarDlls.Count > 1)
                        {
                            double maxSim      = double.MinValue;
                            int    maxSimIndex = 0;
                            for (int j = 0; j < similarDlls.Count; j++)
                            {
                                double sim = StrSimCalculator.CalculateSim(similarDlls[j], dllRef.Path);
                                if (maxSim < sim)
                                {
                                    maxSim      = sim;
                                    maxSimIndex = j;
                                }
                            }
                            bestSimilarDll = similarDlls[maxSimIndex];
                        }
                        if (bestSimilarDll.Equals(dllRef.Path, StringComparison.CurrentCultureIgnoreCase))
                        {
                            continue;
                        }
                        dllRef.Remove();
                        try
                        {
                            dllRefs.Add(bestSimilarDll);
                        }
                        catch
                        {
                        }
                    }
                }
            }
            this.combProjects_SelectedIndexChanged(null, null);
            this.Cursor = Cursors.Default;
        }
コード例 #5
0
        private void rMenuCopySelRefDlls_Click(object sender, EventArgs e)
        {
            if (this.dataGridView1.SelectedRows == null || this.dataGridView1.SelectedRows.Count < 1)
            {
                return;
            }
            string dllRootDir = this.txtLibRootDir.Text.Trim();

            if (string.IsNullOrEmpty(dllRootDir) || Directory.Exists(dllRootDir) == false)
            {
                MsgBox.ShowTip("请先输入Lib根目录");
                return;
            }
            string destDir = this.txtDestDir.Text.Trim();

            if (string.IsNullOrEmpty(destDir) || Directory.Exists(destDir) == false)
            {
                MsgBox.ShowTip("请先输入目标路径");
                return;
            }
            CopyStrategyModel strategy = this.lblSetHideRefStrategy.Tag as CopyStrategyModel;

            if (strategy == null)
            {
                strategy = new CopyStrategyModel();
            }
            strategy.DeepCopy        = this.chkDeepCopy.Checked;
            strategy.CopyHideRefDlls = this.chkCopyHideRefDlls.Checked;

            _copiedFiles.Clear();
            _dirModel = FileDirUtility.ReadAllDirAndFiles(dllRootDir);

            this.Cursor = Cursors.WaitCursor;

            for (int i = 0; i < this.dataGridView1.SelectedRows.Count; i++)
            {
                DataGridViewRow selRow = this.dataGridView1.SelectedRows[i];
                Reference       dllRef = selRow.Tag as Reference;
                if (dllRef == null)
                {
                    continue;
                }
                string dllPath = dllRef.Path;
                if (string.IsNullOrEmpty(dllPath) || File.Exists(dllPath) == false)
                {
                    continue;
                }
                List <string> subRefDlls = DllRefReflectUtility.GetRefDlls(dllPath);
                if (subRefDlls == null || subRefDlls.Count < 1)
                {
                    continue;
                }
                foreach (string subRef in subRefDlls)
                {
                    if (subRef.StartsWith("System") || subRef.StartsWith("mscorlib"))
                    {
                        continue;
                    }
                    if (subRef == dllRef.Name)
                    {
                        continue;
                    }
                    List <string> similarDlls = new List <string>();
                    this.FindSimilarDlls(_dirModel, subRef, ref similarDlls);
                    if (similarDlls.Count < 1)
                    {
                        continue;
                    }
                    string destFilePath = Path.Combine(destDir, Path.GetFileName(similarDlls[0]));
                    if (_copiedFiles.Contains(destFilePath))
                    {
                        continue;
                    }
                    _copiedFiles.Add(destFilePath);
                    File.Copy(similarDlls[0], destFilePath, true);
                    if (strategy.DeepCopy)
                    {
                        int count = 0;
                        this.CopySubRefDlls(similarDlls[0], destDir, dllRootDir, ref count);
                    }
                    if (strategy.CopyHideRefDlls && strategy.UseStrStrategy)
                    {
                        this.CopyHideRefDlls(dllRootDir, similarDlls[0], destDir, strategy);
                    }
                }
            }
            if (strategy.CopyHideRefDlls && strategy.UseDirStrategy)
            {
                this.CopyHideRefFiles(dllRootDir, destDir, strategy);
            }

            this.Cursor = Cursors.Default;
        }