Exemple #1
0
        private void loadTemplates()
        {
            string sdir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Projects");

            if (!Directory.Exists(sdir))
            {
                MessageBox.Show("Project templates folder not exist at " + sdir, "New Project", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                string[] folders = Directory.GetDirectories(sdir);
                if (folders != null && folders.Length > 0)
                {
                    _templates = new List <ProjectTemplate>();
                    for (int i = 0; i < folders.Length; i++)
                    {
                        string[] temps = Directory.GetFiles(folders[i], "*.vstemplate");
                        if (temps != null && temps.Length > 0)
                        {
                            for (int k = 0; k < temps.Length; k++)
                            {
                                try
                                {
                                    ProjectTemplate pt = new ProjectTemplate(temps[k]);
                                    pt.LoadName();
                                    _templates.Add(pt);
                                }
                                catch (Exception err)
                                {
                                    MessageBox.Show("Error loading " + temps[k] + ". " + err.Message, "New Project", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                }
                            }
                        }
                    }
                    if (_templates.Count == 0)
                    {
                        MessageBox.Show("No project templates found at " + sdir, "New Project", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        foreach (ProjectTemplate p in _templates)
                        {
                            int  idx;
                            Icon ic = p.TemplateIcon;
                            if (ic == null)
                            {
                                idx = IMG_DEF_Image;
                            }
                            else
                            {
                                idx = imageList1.Images.Add(ic.ToBitmap(), Color.White);
                                imageList2.Images.Add(ic.ToBitmap(), Color.White);
                            }
                            ListViewItem li = new ListViewItem(p.Name, idx);
                            li.Tag = p;
                            listView1.Items.Add(li);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Project templates not installed at " + sdir, "New Project", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            listView1.Refresh();
        }
Exemple #2
0
 private void buttonOK_Click(object sender, EventArgs e)
 {
     if (listView1.SelectedItems.Count > 0)
     {
         ListViewItem item = listView1.SelectedItems[0];
         if (item != null)
         {
             ProjectTemplate p = item.Tag as ProjectTemplate;
             if (p != null)
             {
                 Result = new SolutionSelection();
                 Result.ProjectTemplate = p.EntityTemplateFile;
                 Result.ProjectName     = textBoxName.Text.Trim();
                 if (Result.ProjectName.Length == 0)
                 {
                     MessageBox.Show(this, "Missing project name", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                     return;
                 }
                 Result.Location = textBoxLocation.Text.Trim();
                 if (Result.Location.Length == 0)
                 {
                     MessageBox.Show(this, "Missing project location", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                     return;
                 }
                 Result.SolutionName         = textBoxSolution.Text.Trim();
                 Result.CreateSolutionFolder = checkBox1.Checked;
                 if (checkBox1.Checked)
                 {
                     if (Result.SolutionName.Length == 0)
                     {
                         MessageBox.Show(this, "Missing solution name", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                         return;
                     }
                 }
                 if (Result.SolutionName.Length == 0)
                 {
                     Result.SolutionName = Result.ProjectName;
                 }
                 if (checkBox1.Checked)
                 {
                     string s = Path.Combine(Result.Location, Result.SolutionName);
                     if (Directory.Exists(s))
                     {
                         MessageBox.Show(this, string.Format(CultureInfo.InvariantCulture, "Solution folder exists: {0}", s), Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                         return;
                     }
                     s = Path.Combine(s, Result.ProjectName);
                     if (Directory.Exists(s))
                     {
                         MessageBox.Show(this, string.Format(CultureInfo.InvariantCulture, "Project folder exists: {0}", s), Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                         return;
                     }
                 }
                 else
                 {
                     string s = Path.Combine(Result.Location, Result.ProjectName);
                     if (Directory.Exists(s))
                     {
                         MessageBox.Show(this, string.Format(CultureInfo.InvariantCulture, "Project folder exists: {0}", s), Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                         return;
                     }
                 }
                 string wizardName = p.GetWizardName();
                 if (!string.IsNullOrEmpty(wizardName))
                 {
                     if (string.CompareOrdinal(wizardName, "Longflow.VSProject.WebWizard") == 0)
                     {
                         WebWizard cw      = new WebWizard();
                         string    destKey = "$destinationdirectory$";
                         if (Result.ReplaceNames.ContainsKey(destKey))
                         {
                             Result.ReplaceNames[destKey] = Path.Combine(Result.Location, Result.ProjectName);
                         }
                         else
                         {
                             Result.ReplaceNames.Add(destKey, Path.Combine(Result.Location, Result.ProjectName));
                         }
                         if (!cw.RunWizard(Result.ReplaceNames))
                         {
                             return;
                         }
                     }
                 }
                 AppConfig.SetSolutionStringValue(CFG_Loc, Result.Location);
                 this.DialogResult = DialogResult.OK;
             }
         }
     }
 }