コード例 #1
0
        private void rMenuBrowseSelPrjDllRef_Click(object sender, EventArgs e)
        {
            if (this.combProjects.Tag == null || this.combProjects.SelectedItem == null)
            {
                return;
            }
            string dllRootDir = this.txtLibRootDir.Text.Trim();

            if (string.IsNullOrEmpty(dllRootDir) || Directory.Exists(dllRootDir) == false)
            {
                MsgBox.ShowTip("请先输入Lib根目录");
                return;
            }
            List <Project> prjList = this.combProjects.Tag as List <Project>;

            Project        selProj = prjList[this.combProjects.SelectedIndex];
            List <Project> temp    = new List <Project>();

            temp.Add(selProj);

            frmDllRefBrowse frm = new frmDllRefBrowse(temp, dllRootDir);

            this.Cursor = Cursors.WaitCursor;
            frm.InitialData();
            this.Cursor = Cursors.Default;
            frm.ShowDialog();
        }
コード例 #2
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < this.treeView1.Nodes.Count; i++)
     {
         for (int j = 0; j < this.treeView1.Nodes[i].Nodes.Count; j++)
         {
             TreeNode node = this.treeView1.Nodes[i].Nodes[j];
             if (node.Checked == false)
             {
                 continue;
             }
             string tip = string.Format("确定删除:{0}?", node.Text);
             if (MsgBox.ShowOkCancel(tip) == System.Windows.Forms.DialogResult.OK)
             {
                 try
                 {
                     File.Delete(node.Tag.ToString());
                     node.Remove();
                     if (node.Parent.Nodes.Count < 2)
                     {
                         node.Parent.Remove();
                     }
                 }
                 catch (Exception ex)
                 {
                     MsgBox.ShowTip(ex.Message);
                 }
             }
         }
     }
 }
コード例 #3
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (this.treeView1.SelectedNode == null || this.treeView1.SelectedNode.Tag == null)
            {
                MsgBox.ShowTip("请选择要引用的dll");
                return;
            }
            string dllFileName = string.Empty;

            if (string.IsNullOrEmpty(_selDllPath) == false)
            {
                dllFileName = Path.GetFileName(_selDllPath);
            }
            TreeNode selNode = this.treeView1.SelectedNode;

            if (string.IsNullOrEmpty(dllFileName) == false)
            {
                if (dllFileName != selNode.Text)
                {
                    DialogResult rlt = MsgBox.ShowOkCancel("所选dll名称与要修改引用的dll名称不一致,仍要修改吗?");
                    if (rlt == DialogResult.Cancel)
                    {
                        return;
                    }
                }
            }
            _selDllPath       = selNode.Tag as string;
            this.DialogResult = DialogResult.OK;
        }
コード例 #4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            Solution sol = _app.Solution as Solution;

            if (sol == null || string.IsNullOrEmpty(sol.FileName))
            {
                MsgBox.ShowTip("请先打开已有解决方案或者新建一个解决方案");
                return;
            }
            if (this.combOutPath.Text == null)
            {
                MsgBox.ShowTip("请先输入输出路径");
                return;
            }
            if (this.combSolutionPlatform.SelectedItem == null)
            {
                MsgBox.ShowTip("请先选择解决平台");
                return;
            }
            DialogResult rlt = MsgBox.ShowOkCancel("您确定要批量修改输出路径吗?");

            if (rlt == DialogResult.Cancel)
            {
                return;
            }
            string outPath     = this.combOutPath.Text.Trim();
            string solPlatform = this.combSolutionPlatform.SelectedItem.ToString();
            int    num         = 0;

            for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
            {
                object obj   = this.dataGridView1[0, i].Value;
                bool   isSel = (bool)obj;
                if (isSel == false)
                {
                    continue;
                }
                Project proj = this.dataGridView1.Rows[i].Tag as Project;
                if (proj != null)
                {
                    foreach (Configuration config in proj.ConfigurationManager)
                    {
                        if (config.ConfigurationName == solPlatform)
                        {
                            config.Properties.Item("OutputPath").Value = outPath;
                            this.dataGridView1[2, i].Value             = outPath;
                            num++;
                            break;
                        }
                    }
                }
            }
            MsgBox.ShowTip(string.Format("修改输出路径完成,总共修改{0}个项目", num));
        }
コード例 #5
0
        private void btnRemoveEmptyDllRef_Click(object sender, EventArgs e)
        {
            Solution sol = _app.Solution as Solution;

            if (sol == null || string.IsNullOrEmpty(sol.FileName))
            {
                MsgBox.ShowTip("请先打开已有解决方案或者新建一个解决方案");
                return;
            }
            DialogResult rlt = MsgBox.ShowOkCancel("您确定要移除dll引用路径为空的引用吗?");

            if (rlt == DialogResult.Cancel)
            {
                return;
            }
            int num = 0;

            for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
            {
                object obj   = this.dataGridView1[0, i].Value;
                bool   isSel = (bool)obj;
                if (isSel == false)
                {
                    continue;
                }
                Project proj = this.dataGridView1.Rows[i].Tag as Project;
                if (proj != null)
                {
                    try
                    {
                        VSProject vsProj = proj.Object as VSProject;
                        if (vsProj == null)
                        {
                            continue;
                        }
                        References dllRefs = vsProj.References;
                        foreach (Reference dllRef in dllRefs)
                        {
                            if (string.IsNullOrEmpty(dllRef.Path))
                            {
                                dllRef.Remove();
                                num++;
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
            MsgBox.ShowTip(string.Format("移除空引用完成,总共移除{0}个空引用", num));
        }
コード例 #6
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            Solution sol = _app.Solution as Solution;

            if (sol == null || string.IsNullOrEmpty(sol.FileName))
            {
                MsgBox.ShowTip("请先打开已有解决方案或者新建一个解决方案");
                return;
            }

            if (this.combPlatform.SelectedItem == null)
            {
                MsgBox.ShowTip("请先选择目标平台");
                return;
            }
            if (this.combSolutionPlatform.SelectedItem == null)
            {
                MsgBox.ShowTip("请先选择解决平台");
                return;
            }
            string platform    = this.combPlatform.SelectedItem.ToString();
            string solPlatform = this.combSolutionPlatform.SelectedItem.ToString();
            int    num         = 0;

            for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
            {
                object obj   = this.dataGridView1[0, i].Value;
                bool   isSel = (bool)obj;
                if (isSel == false)
                {
                    continue;
                }
                Project proj = this.dataGridView1.Rows[i].Tag as Project;
                if (proj != null)
                {
                    foreach (Configuration config in proj.ConfigurationManager)
                    {
                        if (config.ConfigurationName == solPlatform)
                        {
                            config.Properties.Item("PlatformTarget").Value = platform;
                            this.dataGridView1[2, i].Value = platform;
                            num++;
                            break;
                        }
                    }
                }
            }
            MsgBox.ShowTip(string.Format("修改目标平台完成,总共修改{0}个项目", num));
        }
コード例 #7
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     if (this.treeView1.SelectedNode == null || this.treeView1.SelectedNode.Tag == null)
     {
         MsgBox.ShowTip("请选择要引用的dll");
         return;
     }
     _selDllPaths = new List <string>();
     for (int i = 0; i < this.listView1.SelectedItems.Count; i++)
     {
         string dllPath = this.listView1.SelectedItems[i].Tag as string;
         _selDllPaths.Add(dllPath);
     }
     this.DialogResult = System.Windows.Forms.DialogResult.OK;
 }
コード例 #8
0
        private void rMenuAddRefs_Click(object sender, EventArgs e)
        {
            string dllRootDir = this.txtLibRootDir.Text.Trim();

            if (string.IsNullOrEmpty(dllRootDir) || Directory.Exists(dllRootDir) == false)
            {
                MsgBox.ShowTip("请先输入Lib根目录");
                return;
            }
            References dllRefs = this.dataGridView1.Tag as References;

            if (dllRefs == null)
            {
                return;
            }
            List <string> existDlls = new List <string>();

            foreach (Reference dllRef in dllRefs)
            {
                existDlls.Add(dllRef.Name);
            }
            frmMutiSelDllRef frm = new frmMutiSelDllRef(dllRootDir);

            if (frm.ShowDialog() == DialogResult.OK)
            {
                this.Cursor = Cursors.WaitCursor;
                List <string> selDlls = frm.SelDllPaths;
                for (int i = 0; i < selDlls.Count; i++)
                {
                    string dllName = Path.GetFileNameWithoutExtension(selDlls[i]);
                    if (existDlls.Contains(dllName) == false)
                    {
                        try
                        {
                            dllRefs.Add(selDlls[i]);
                        }
                        catch
                        {
                        }
                    }
                }
                this.combProjects_SelectedIndexChanged(null, null);
                this.Cursor = Cursors.Default;
            }
        }
コード例 #9
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (this.combSolutionPlatform.SelectedItem == null)
            {
                MsgBox.ShowTip("请选择解决方案配置");
                return;
            }
            string dllRootDir = this.txtLibRootDir.Text.Trim();

            if (string.IsNullOrEmpty(dllRootDir) || Directory.Exists(dllRootDir) == false)
            {
                MsgBox.ShowTip("请选择Lib根目录");
                return;
            }
            List <string> msgList = new List <string>();

            for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
            {
                bool isSel = (bool)this.dataGridView1[0, i].Value;
                if (isSel == false)
                {
                    continue;
                }
                string        srcPath   = this.dataGridView1[2, i].Tag as string;
                List <string> destPaths = this.dataGridView1[3, i].Tag as List <string>;
                if (string.IsNullOrEmpty(srcPath) == false && File.Exists(srcPath) && destPaths != null && destPaths.Count > 0)
                {
                    for (int j = 0; j < destPaths.Count; j++)
                    {
                        string msg = string.Format("从 {0}  拷贝到  {1}  ", this.dataGridView1[2, i].Value.ToString(), destPaths[j].Substring(dllRootDir.Length));
                        try
                        {
                            File.Copy(srcPath, destPaths[j], true);
                            msg += "成功";
                        }
                        catch (Exception ex)
                        {
                            msg += "失败!,具体信息:" + ex.Message;
                        }
                        msgList.Add(msg);
                    }
                }
            }
            SaveText2Notepad.SaveContext(msgList, true);
        }
コード例 #10
0
        private void dataGridView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (this.dataGridView1.SelectedRows == null || this.dataGridView1.SelectedRows.Count > 1 || this.dataGridView1.SelectedRows.Count == 0)
            {
                return;
            }
            DataGridViewRow selRow = this.dataGridView1.SelectedRows[0];

            References dllRefs = this.dataGridView1.Tag as References;
            Reference  dllRef  = selRow.Tag as Reference;

            if (dllRefs == null || dllRef == null)
            {
                return;
            }

            string dllRootDir = this.txtLibRootDir.Text.Trim();

            if (string.IsNullOrEmpty(dllRootDir) || Directory.Exists(dllRootDir) == false)
            {
                MsgBox.ShowTip("请先输入Lib根目录");
                return;
            }
            frmSelDllRef frm = new frmSelDllRef(dllRootDir);

            frm.SelDllPath = selRow.Cells[1].Value.ToString();
            if (frm.ShowDialog() == DialogResult.OK)
            {
                selRow.Tag = null;
                dllRef.Remove();

                try
                {
                    dllRef = dllRefs.Add(frm.SelDllPath);
                }
                catch
                {
                }
                selRow.Tag            = dllRef;
                selRow.Cells[0].Value = Path.GetFileNameWithoutExtension(frm.SelDllPath);
                selRow.Cells[1].Value = frm.SelDllPath;
            }
        }
コード例 #11
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            Solution sol = _app.Solution as Solution;

            if (sol == null || string.IsNullOrEmpty(sol.FileName))
            {
                MsgBox.ShowTip("请先打开已有解决方案或者新建一个解决方案");
                return;
            }
            if (this.combFramework.SelectedItem == null)
            {
                MsgBox.ShowTip("请先选择解决平台");
                return;
            }
            DialogResult rlt = MsgBox.ShowOkCancel("您确定要批量修改.NET Framework版本吗?");

            if (rlt == DialogResult.Cancel)
            {
                return;
            }
            string framework = this.combFramework.SelectedItem.ToString();
            int    num       = 0;

            for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
            {
                object obj   = this.dataGridView1[0, i].Value;
                bool   isSel = (bool)obj;
                if (isSel == false)
                {
                    continue;
                }
                Project proj = this.dataGridView1.Rows[i].Tag as Project;
                if (proj != null)
                {
                    proj.Properties.Item("TargetFramework").Value = this.GetFrameworkId(framework);
                    this.dataGridView1[2, i].Value = framework;
                    num++;
                }
            }
            MsgBox.ShowTip(string.Format("修改输出路径完成,总共修改{0}个项目", num));
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }
コード例 #12
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            Solution sol = _app.Solution as Solution;

            if (sol == null || string.IsNullOrEmpty(sol.FileName))
            {
                MsgBox.ShowTip("请先打开已有解决方案或者新建一个解决方案");
                return;
            }
            DialogResult rlt = MsgBox.ShowOkCancel("您确定要批量修改生成前事件和生成后事件吗?");

            if (rlt == DialogResult.Cancel)
            {
                return;
            }
            string preBuildEvent  = this.txtPreBuildEvent.Text.Trim();
            string postBuildEvent = this.txtPostBuildEvent.Text.Trim();
            int    num            = 0;

            for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
            {
                object obj   = this.dataGridView1[0, i].Value;
                bool   isSel = (bool)obj;
                if (isSel == false)
                {
                    continue;
                }
                Project proj = this.dataGridView1.Rows[i].Tag as Project;
                if (proj != null)
                {
                    proj.Properties.Item("PreBuildEvent").Value  = preBuildEvent;
                    proj.Properties.Item("PostBuildEvent").Value = postBuildEvent;
                    this.dataGridView1[2, i].Value = preBuildEvent;
                    this.dataGridView1[3, i].Value = postBuildEvent;
                    num++;
                }
            }
            MsgBox.ShowTip(string.Format("修改输出路径完成,总共修改{0}个项目", num));
        }
コード例 #13
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            string[] context = this.txtStringArray.Lines;
            if (context == null || context.Length < 1)
            {
                MsgBox.ShowTip("请先输入字符串数组,每个字符串占一行");
                return;
            }
            if (this.combSQLType.SelectedItem == null)
            {
                MsgBox.ShowTip("请选择SQL类型");
                return;
            }
            List <string> tempList = new List <string>();

            for (int i = 0; i < context.Length; i++)
            {
                if (string.IsNullOrEmpty(context[i].Trim()) == false)
                {
                    tempList.Add(context[i].Trim());
                }
            }
            if (tempList.Count < 1)
            {
                return;
            }
            context = tempList.ToArray();

            string rlt     = string.Empty;
            string sqlType = this.combSQLType.SelectedItem.ToString().Trim('用', '分', '割');

            switch (sqlType)
            {
            case ",":
                for (int i = 0; i < context.Length; i++)
                {
                    if (i == 0)
                    {
                        rlt += context[i].Trim().Trim();
                    }
                    else
                    {
                        rlt += "," + context[i].Trim();
                    }
                }
                break;

            case "',":
                for (int i = 0; i < context.Length; i++)
                {
                    if (i == 0)
                    {
                        rlt += "'" + context[i].Trim() + "'";
                    }
                    else
                    {
                        rlt += ",'" + context[i].Trim() + "'";
                    }
                }
                break;

            case "\",":
                for (int i = 0; i < context.Length; i++)
                {
                    if (i == 0)
                    {
                        rlt += "\"" + context[i].Trim() + "\"";
                    }
                    else
                    {
                        rlt += ",\"" + context[i].Trim() + "\"";
                    }
                }
                break;

            case "delete from":
                for (int i = 0; i < context.Length; i++)
                {
                    if (string.IsNullOrEmpty(context[i].Trim()) == false)
                    {
                        rlt += "delete from " + context[i].Trim();
                        if (i != context.Length - 1)
                        {
                            rlt += "\ngo\n";
                        }
                        else
                        {
                            rlt += "\ngo";
                        }
                    }
                }
                break;

            default:
                break;
            }
            this.txtRlt.Text = rlt;
        }
コード例 #14
0
        /// <summary>实现 IDTCommandTarget 接口的 Exec 方法。此方法在调用该命令时调用。</summary>
        /// <param term='commandName'>要执行的命令的名称。</param>
        /// <param term='executeOption'>描述该命令应如何运行。</param>
        /// <param term='varIn'>从调用方传递到命令处理程序的参数。</param>
        /// <param term='varOut'>从命令处理程序传递到调用方的参数。</param>
        /// <param term='handled'>通知调用方此命令是否已被处理。</param>
        /// <seealso class='Exec' />
        public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
        {
            handled = false;
            if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
            {
                if (commandName == "Leation.VSAddin.Connect.PlatformSetting")
                {
                    frmPlatformSetting frm = new frmPlatformSetting(_app);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.OutPathSetting")
                {
                    frmOutPathSetting frm = new frmOutPathSetting(_app);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.BuildEventSetting")
                {
                    frmBuildEventSetting frm = new frmBuildEventSetting(_app);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.NetFrameweorkSetting")
                {
                    frmNetFrameworkSetting frm = new frmNetFrameworkSetting(_app);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.CollapseAll")
                {
                    SolutionExployerUtility utility = new SolutionExployerUtility(_app);
                    utility.CollapseAll();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.ExpandAll")
                {
                    SolutionExployerUtility utility = new SolutionExployerUtility(_app);
                    utility.ExpandAll();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.MultiLoadProjects")
                {
                    frmMultiLoadProjects frm = new frmMultiLoadProjects(_app);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.MultiCreateProjects")
                {
                    frmMultiCreateProjects frm = new frmMultiCreateProjects(_app);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.DllRefConfig")
                {
                    frmDllRefSetting frm = new  frmDllRefSetting(_app);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.DllRefFileCopy")
                {
                    frmDllRefFileCopy frm = new frmDllRefFileCopy(_app);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.Dll2Lib")
                {
                    frmDll2Lib frm = new frmDll2Lib(_app);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.SQLCreator")
                {
                    Form frm = new Form();
                    frm.FormBorderStyle = FormBorderStyle.Sizable;
                    frm.ShowIcon        = false;
                    frm.Width           = 800;
                    frm.Height          = 520;
                    frm.StartPosition   = FormStartPosition.CenterScreen;
                    frm.Text            = "SQL语句生成器";
                    SQLCreatorUI ctr = new SQLCreatorUI();
                    ctr.Dock = DockStyle.Fill;
                    frm.Controls.Add(ctr);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.GuidCreator")
                {
                    Form frm = new Form();
                    frm.FormBorderStyle = FormBorderStyle.Sizable;
                    frm.ShowIcon        = false;
                    frm.Width           = 800;
                    frm.Height          = 520;
                    frm.StartPosition   = FormStartPosition.CenterScreen;
                    frm.Text            = "Guid生成器";
                    GuidCreatorUI ctr = new GuidCreatorUI();
                    ctr.Dock = DockStyle.Fill;
                    frm.Controls.Add(ctr);
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.CheckRepeatDll")
                {
                    frmCheckRepeatDll frm = new frmCheckRepeatDll(_app);
                    frm.WindowState = FormWindowState.Maximized;
                    frm.ShowDialog();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.Selection2Upper")
                {
                    frmSelection2Upper frm = new frmSelection2Upper();

                    frm.BtnSelection2Upper.Click += delegate(object sender, EventArgs e)
                    {
                        try
                        {
                            TextSelection txtSelection = _app.ActiveDocument.Selection as TextSelection;
                            if (txtSelection != null)
                            {
                                txtSelection.Text = txtSelection.Text.ToUpper();
                            }
                        }
                        catch (Exception ex)
                        {
                            MsgBox.ShowTip(ex.Message);
                        }
                    };
                    frm.BtnSelection2Lower.Click += delegate(object sender, EventArgs e)
                    {
                        try
                        {
                            TextSelection txtSelection = _app.ActiveDocument.Selection as TextSelection;
                            if (txtSelection != null)
                            {
                                txtSelection.Text = txtSelection.Text.ToLower();
                            }
                        }
                        catch (Exception ex)
                        {
                            MsgBox.ShowTip(ex.Message);
                        }
                    };
                    frm.Show();

                    handled = true;
                    return;
                }
                if (commandName == "Leation.VSAddin.Connect.AboutMe")
                {
                    MsgBox.ShowTip("李仙伟\r\nQQ:744757242\r\nCopyright(c)2013 Leation");

                    handled = true;
                    return;
                }
            }
        }
コード例 #15
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);
            }
        }
コード例 #16
0
 private void txtRootDir_TextChanged(object sender, EventArgs e)
 {
     try
     {
         this.Cursor = Cursors.WaitCursor;
         string rootDir = this.txtRootDir.Text.Trim();
         if (string.IsNullOrEmpty(rootDir) || Directory.Exists(rootDir) == false)
         {
             return;
         }
         this.treeView1.Nodes.Clear();
         string[] csprojList = Directory.GetFiles(rootDir, "*.csproj", SearchOption.AllDirectories);
         if (csprojList == null || csprojList.Length < 1)
         {
             return;
         }
         Dictionary <string, List <string> > projDic = new Dictionary <string, List <string> >();
         List <string> keyList = new List <string>();
         for (int i = 0; i < csprojList.Length; i++)
         {
             string fileName = Path.GetFileNameWithoutExtension(csprojList[i]);
             string key      = fileName;
             if (fileName.IndexOf('.') > 0)
             {
                 key = fileName.Substring(0, fileName.LastIndexOf('.'));
             }
             if (projDic.ContainsKey(key) == false)
             {
                 List <string> temp = new List <string>();
                 temp.Add(csprojList[i]);
                 projDic.Add(key, temp);
                 keyList.Add(key);
             }
             else
             {
                 projDic[key].Add(csprojList[i]);
             }
         }
         keyList.Sort();
         for (int i = 0; i < keyList.Count; i++)
         {
             List <string> fileList = projDic[keyList[i]];
             TreeNode      root     = this.treeView1.Nodes.Add(keyList[i]);
             root.Tag = keyList[i];
             for (int j = 0; j < fileList.Count; j++)
             {
                 string   fileName = Path.GetFileName(fileList[j]);
                 TreeNode node     = root.Nodes.Add(fileName);
                 node.Tag = fileList[j];
             }
         }
     }
     catch (Exception ex)
     {
         MsgBox.ShowTip(ex.Message);
     }
     finally
     {
         this.Cursor = Cursors.Default;
     }
 }
コード例 #17
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                Solution3 sol3 = _app.Solution as Solution3;
                if (sol3 == null || string.IsNullOrEmpty(sol3.FileName))
                {
                    MsgBox.ShowTip("请先打开已有解决方案或者新建一个解决方案");
                    return;
                }
                List <Project> existProjs = ProjectUtility.GetAllProjects(_app);
                for (int i = 0; i < this.treeView1.Nodes.Count; i++)
                {
                    TreeNode rootNode = this.treeView1.Nodes[i];
                    if (rootNode.Checked && rootNode.Nodes.Count > 0)
                    {
                        string foldName      = rootNode.Tag as string;
                        bool   isExistFolder = false;
                        for (int j = 1; j < sol3.Projects.Count; j++)
                        {
                            Project proj = sol3.Projects.Item(j);
                            if (proj.Kind != ProjectKinds.vsProjectKindSolutionFolder)
                            {
                                continue;
                            }
                            if (sol3.Projects.Item(j).Name.Equals(foldName, StringComparison.CurrentCultureIgnoreCase))
                            {
                                isExistFolder = true;
                                break;
                            }
                        }
                        if (isExistFolder == false)
                        {
                            Project solFolder = sol3.AddSolutionFolder(rootNode.Tag as string);
                        }
                        for (int j = 0; j < rootNode.Nodes.Count; j++)
                        {
                            if (rootNode.Nodes[j].Checked)
                            {
                                string projPath = rootNode.Nodes[j].Tag as string;
                                bool   isExist  = false;
                                for (int k = 0; k < existProjs.Count; k++)
                                {
                                    if (existProjs[k].FileName.Equals(projPath, StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        isExist = true;
                                        break;
                                    }
                                }
                                if (isExist == false)
                                {
                                    Project proj = sol3.AddFromFile(projPath, false);
                                }
                                else
                                {
                                    MsgBox.ShowTip(Path.GetFileNameWithoutExtension(projPath) + "已经加载");
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0; j < rootNode.Nodes.Count; j++)
                        {
                            if (rootNode.Nodes[j].Checked)
                            {
                                string projPath = rootNode.Nodes[j].Tag as string;
                                bool   isExist  = false;
                                for (int k = 0; k < existProjs.Count; k++)
                                {
                                    if (existProjs[k].FileName.Equals(projPath, StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        isExist = true;
                                        break;
                                    }
                                }
                                if (isExist == false)
                                {
                                    Project proj = sol3.AddFromFile(projPath, false);
                                }
                                else
                                {
                                    MsgBox.ShowTip(Path.GetFileNameWithoutExtension(projPath) + "已经加载");
                                }
                            }
                        }
                    }
                }
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            catch (Exception ex)
            {
                MsgBox.ShowTip(ex.Message);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
コード例 #18
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                Solution3 sol3 = _app.Solution as Solution3;
                if (sol3 == null || string.IsNullOrEmpty(sol3.FileName))
                {
                    MsgBox.ShowTip("请先打开已有解决方案或者新建一个解决方案");
                    return;
                }
                string saveDir = this.txtSaveDir.Text.Trim();
                if (string.IsNullOrEmpty(saveDir) || Directory.Exists(saveDir) == false)
                {
                    MsgBox.ShowTip("请选择项目保存位置");
                    return;
                }
                string rootDir = this.txtRootDir.Text.Trim();
                rootDir = rootDir.TrimEnd('.');
                if (string.IsNullOrEmpty(rootDir))
                {
                    MsgBox.ShowTip("根名字空间不能为空");
                    return;
                }
                bool isExistFolder = false;
                for (int j = 1; j < sol3.Projects.Count; j++)
                {
                    Project proj = sol3.Projects.Item(j);
                    if (proj.Kind != ProjectKinds.vsProjectKindSolutionFolder)
                    {
                        continue;
                    }
                    if (sol3.Projects.Item(j).Name.Equals(rootDir, StringComparison.CurrentCultureIgnoreCase))
                    {
                        isExistFolder = true;
                        break;
                    }
                }
                if (isExistFolder == false)
                {
                    Project solFolder = sol3.AddSolutionFolder(rootDir);
                }
                List <Project> existProjs = ProjectUtility.GetAllProjects(_app);
                for (int i = 0; i < this.richTextBox1.Lines.Length; i++)
                {
                    string subDir = this.richTextBox1.Lines[i].Trim();
                    subDir = subDir.TrimStart('.').TrimEnd('.');
                    if (string.IsNullOrEmpty(subDir))
                    {
                        continue;
                    }
                    subDir = rootDir + "." + subDir;

                    string projPath = Path.Combine(saveDir, subDir + "\\" + subDir + ".csproj");
                    bool   isExist  = false;
                    for (int k = 0; k < existProjs.Count; k++)
                    {
                        if (existProjs[k].FileName.Equals(projPath, StringComparison.CurrentCultureIgnoreCase))
                        {
                            isExist = true;
                            break;
                        }
                    }
                    if (isExist == false)
                    {
                        if (File.Exists(projPath))
                        {
                            DialogResult rlt = MsgBox.ShowOkCancel("项目保存位置下已经存在:" + subDir + ",是否需要加载?");
                            if (rlt == DialogResult.OK)
                            {
                                sol3.AddFromFile(projPath, false);
                            }
                            continue;
                        }
                        string  templatePath = sol3.GetProjectTemplate("ClassLibrary.zip", "CSharp");
                        Project proj         = sol3.AddFromTemplate(templatePath, Path.Combine(saveDir, subDir), subDir, true);
                    }
                    else
                    {
                        MsgBox.ShowTip(subDir + "已经存在");
                    }
                }
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            catch (Exception ex)
            {
                MsgBox.ShowTip(ex.Message);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
コード例 #19
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;
        }
コード例 #20
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;
        }
コード例 #21
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;
        }