Ejemplo n.º 1
0
        private void button_deleteInstance_Click(object sender, EventArgs e)
        {
            string strError = "";
            int    nRet     = 0;

            HideMessageTip();

            if (this.listView_instance.SelectedItems.Count == 0)
            {
                strError = "尚未选择要删除的事项";
                goto ERROR1;
            }

            DialogResult result = MessageBox.Show(this,
                                                  "确实要删除所选择的 " + this.listView_instance.SelectedItems.Count.ToString() + " 个实例?",
                                                  "InstanceDialog",
                                                  MessageBoxButtons.YesNo,
                                                  MessageBoxIcon.Question,
                                                  MessageBoxDefaultButton.Button2);

            if (result != DialogResult.Yes)
            {
                return;
            }

            // 删除应用程序目录
            foreach (ListViewItem item in this.listView_instance.SelectedItems)
            {
                string strSite         = ListViewUtil.GetItemText(item, COLUMN_SITE);
                string strVirtualDir   = ListViewUtil.GetItemText(item, COLUMN_VIRTUALDIR);
                string strPhysicalPath = ListViewUtil.GetItemText(item, COLUMN_PHYSICALPATH);

                // 注销 Web App。调用后,程序物理目录没有删除。apppool 没有删除。
                // 只能用于 IIS 7 以上版本
                nRet = OpacAppInfo.UnregisterWebApp(
                    strSite,
                    strVirtualDir,
                    out strError);
                if (nRet == -1)
                {
                    MessageBox.Show(this, strError);
                }

                // 删除应用程序物理目录
                //LineInfo info = (LineInfo)item.Tag;
                //if (info != null)
                {
                    if (string.IsNullOrEmpty(strPhysicalPath) == false)
                    {
                        // return:
                        //      -1  出错。包括出错后重试然后放弃
                        //      0   成功
                        nRet = InstallHelper.DeleteDataDir(strPhysicalPath,
                                                           out strError);
                        if (nRet == -1)
                        {
                            MessageBox.Show(this, strError);
                        }
                    }
                }
            }



            List <string> datadirs = new List <string>();

            foreach (ListViewItem item in this.listView_instance.SelectedItems)
            {
                string strDataDir = ListViewUtil.GetItemText(item, COLUMN_DATADIR);
                if (String.IsNullOrEmpty(strDataDir) == true)
                {
                    continue;
                }

                if (Directory.Exists(strDataDir) == false)
                {
                    continue;
                }

                datadirs.Add(strDataDir);
            }

            ListViewUtil.DeleteSelectedItems(this.listView_instance);

            this.Changed = true;

            // 如果数据目录已经存在,提示是否连带删除数据目录
            if (datadirs.Count > 0)
            {
                strError = "";
                result   = MessageBox.Show(this,
                                           "所选定的实例信息已经删除。\r\n\r\n要删除它们所对应的下列数据目录么?\r\n" + StringUtil.MakePathList(datadirs, "\r\n"),
                                           "InstanceDialog",
                                           MessageBoxButtons.YesNo,
                                           MessageBoxIcon.Question,
                                           MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Yes)
                {
                    foreach (string strDataDir in datadirs)
                    {
                        string strTempError = "";
                        // return:
                        //      -1  出错。包括出错后重试然后放弃
                        //      0   成功
                        nRet = InstallHelper.DeleteDataDir(strDataDir,
                                                           out strTempError);
                        if (nRet == -1)
                        {
                            strError += strTempError + "\r\n";
                        }
                    }
                    if (String.IsNullOrEmpty(strError) == false)
                    {
                        goto ERROR1;
                    }
                }
            }

            return;

ERROR1:
            MessageBox.Show(this, strError);
            return;
        }