コード例 #1
0
        public void LoadData(string initSelection)
        {
            ListViewItem          viSel = null;
            IList <VirtualWebDir> vs    = IisUtility.GetVirtualDirectories(IisUtility.LocalWebPath);

            foreach (VirtualWebDir v in vs)
            {
                ListViewItem vi = new ListViewItem(new string[] { v.WebName, v.PhysicalDirectory });
                vi.Tag = v;
                listView1.Items.Add(vi);
                if (viSel == null)
                {
                    if (!string.IsNullOrEmpty(initSelection))
                    {
                        if (string.Compare(initSelection, v.WebName, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            viSel = vi;
                        }
                    }
                }
            }
            if (viSel != null)
            {
                viSel.Selected = true;
            }
        }
コード例 #2
0
        public static void CreateLocalWebSite(string virtualDir, string physicalDir)
        {
            EnumIIS iis = IisUtility.GetIisVersion();

            IisUtility.CreateVDir(LocalWebPath, virtualDir, physicalDir);
            if (iis == EnumIIS.IIS6 || iis == EnumIIS.IIS7)
            {
#if DOTNET40
                string appName = "Limnor Studio 5";
#else
                string appName = "Limnor Studio";                // string.Format(CultureInfo.InvariantCulture, "app{0}", Guid.NewGuid().GetHashCode().ToString("x", CultureInfo.InvariantCulture));
#endif
                IisUtility.CreateAppPool("localhost", appName);
                IisUtility.AssignVDirToAppPool(string.Format(CultureInfo.InvariantCulture, "{0}/{1}", LocalWebPath, virtualDir), appName);
            }
        }
コード例 #3
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            bool bOK = false;

            buttonOK.Enabled     = false;
            buttonCancel.Enabled = false;
            this.Cursor          = Cursors.WaitCursor;
            string svDir = textBoxVdir.Text.Trim();

            if (svDir.Length == 0)
            {
                MessageBox.Show(this, "Web site name is empty", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                if (svDir.Contains(' ') || svDir.Contains('\t'))
                {
                    MessageBox.Show(this, "Do not use spaces and tabs in the web site name", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    Regex rg = new Regex(@"^([\w])*$");
                    if (rg.IsMatch(svDir))
                    {
                        string spDir = textBoxPdir.Text.Trim();
                        if (spDir.Length == 0)
                        {
                            MessageBox.Show(this, "Web site folder is empty", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        else
                        {
                            if (VirtualWebDir.IsNetworkDrive(spDir))
                            {
                                MessageBox.Show(this, "Cannot use a network folder for web site", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                            else
                            {
                                bOK = Directory.Exists(spDir);
                                if (!bOK)
                                {
                                    try
                                    {
                                        Directory.CreateDirectory(spDir);
                                        bOK = true;
                                    }
                                    catch (Exception er)
                                    {
                                        bOK = false;
                                        MessageBox.Show(this, er.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    }
                                }
                            }
                            if (bOK && Directory.Exists(spDir))
                            {
                                bool exists = false;
                                try
                                {
                                    IList <VirtualWebDir> vs = IisUtility.GetVirtualDirectories(IisUtility.LocalWebPath);
                                    foreach (VirtualWebDir v in vs)
                                    {
                                        if (string.Compare(v.WebName, svDir, StringComparison.OrdinalIgnoreCase) == 0)
                                        {
                                            exists = true;
                                            if (string.Compare(v.PhysicalDirectory, spDir, StringComparison.OrdinalIgnoreCase) == 0)
                                            {
                                                MessageBox.Show(this, "The web site is already created", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                                Ret = v;
                                            }
                                            else
                                            {
                                                MessageBox.Show(this, string.Format(CultureInfo.InvariantCulture, "Web site name is used by folder {0}", v.PhysicalDirectory), Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                                bOK = false;
                                            }
                                            break;
                                        }
                                        if (string.Compare(v.PhysicalDirectory, spDir, StringComparison.OrdinalIgnoreCase) == 0)
                                        {
                                            MessageBox.Show(this, string.Format(CultureInfo.InvariantCulture, "Web site folder is used by web site {0}.", v.WebName), Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                            Ret    = v;
                                            exists = true;
                                            bOK    = false;
                                            break;
                                        }
                                    }
                                    if (!exists)
                                    {
                                        try
                                        {
                                            IisUtility.CreateLocalWebSite(svDir, spDir);
                                            Ret = new VirtualWebDir(svDir, spDir);
                                        }
                                        catch (Exception err)
                                        {
                                            bOK = false;
                                            MessageBox.Show(this, err.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                        }
                                    }
                                }
                                catch (Exception err)
                                {
                                    bOK = false;
                                    MessageBox.Show(this, err.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                }
                                if (bOK)
                                {
                                    //set access permissions
                                    VirtualWebDir.AddDirectorySecurity(spDir);
                                }
                            }
                            else
                            {
                                MessageBox.Show(this, "Web site folder does not exist", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(this, "Please use only alphanumeric characters in Web site name", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
            if (bOK)
            {
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                buttonOK.Enabled     = true;
                buttonCancel.Enabled = true;
                this.Cursor          = Cursors.Default;
            }
        }