示例#1
0
 public TemplateLocalInfo(TemplateSource source, string templateSourceRoot)
     : this(
         source,
         templateSourceRoot,
         Path.Combine(templateSourceRoot, @"project-templates\"),
         Path.Combine(templateSourceRoot, @"project-templates-v0\"),
         Path.Combine(templateSourceRoot, @"item-Templates\")) {
 }
示例#2
0
        public TemplateLocalInfo(TemplateSource source, string templateSourceRoot, string templateReferenceSourceRoot, string projectTemplateSourceRoot, string itemTemplateSourceRoot) {
            if (source == null) { throw new ArgumentNullException("source"); }
            if (string.IsNullOrEmpty(templateSourceRoot)) { throw new ArgumentNullException("templateSourceRoot"); }

            this.Source = source;
            this.TemplateSourceRoot = templateSourceRoot;
            this.TemplateReferenceSourceRoot = templateReferenceSourceRoot;
            this.ProjectTemplateSourceRoot = projectTemplateSourceRoot;
            this.ItemTemplateSourceRoot = itemTemplateSourceRoot;
        }
        protected void FetchSourceLocally(TemplateSource source, string destFolder) {
            if (source == null) { throw new ArgumentNullException("source"); }
            if (string.IsNullOrEmpty(destFolder)) { throw new ArgumentNullException("destFolder"); }

            if (string.Compare("file", source.Location.Scheme, StringComparison.InvariantCultureIgnoreCase)==0) {
                // do a recursive copy of the folder to the dest
                new DirectoryHelper().DirectoryCopy(source.Location.LocalPath, destFolder, true, true);
            }
            else if(
                string.Compare("git", source.Location.Scheme, StringComparison.InvariantCultureIgnoreCase)==0 ||
                string.Compare("http", source.Location.Scheme, StringComparison.InvariantCultureIgnoreCase)==0 ||
                string.Compare("https", source.Location.Scheme, StringComparison.InvariantCultureIgnoreCase) == 0) {
                    FetchGitSourceLocally(source, destFolder);
            }
            else {
                throw new ApplicationException(
                    string.Format(
                        "Unsupported scheme [{0}] in template source Uri [{1}]",
                        source.Location.Scheme,
                        source.Location.AbsoluteUri));
            }
        }
示例#4
0
        private async void OkBtn_Click(object sender, EventArgs e)
        {
            DisableControls();
            LoadingImage.Enabled = true;
            LoadingLabel.Enabled = true;
            LoadingImage.Visible = true;
            LoadingLabel.Visible = true;

            List<TemplateSource> sources = new List<TemplateSource>();

            foreach (ListViewItem row in remoteSourceListView.Items)
            {
                TemplateSource source = new TemplateSource();
                if (row.Checked == true)
                {
                    source.Enabled = true;
                }

                else
                {
                    source.Enabled = false;
                }

                source.Name = row.SubItems[1].Text;

                Uri uri = new Uri(row.SubItems[2].Text);
                Uri url = uri;
                if (uri.IsFile)
                {
                    url = new Uri(uri.AbsoluteUri);
                }

                source.Location = url;

                if (row.SubItems[3].Text != "")
                {
                    source.Branch = row.SubItems[3].Text;
                }

                sources.Add(source);
            }

            templateSettings.Sources = sources;

            // Save the configuration schedule
            var checkbox = scheduleGroupBox.Controls.OfType<RadioButton>().FirstOrDefault(r => r.Checked);
            templateSettings.UpdateInterval = (UpdateFrequency)checkbox.Tag;

            // Here is where the .json file needs to be saved before calling ProcessTemplates
            templateBuilder.WriteJsonTemplateSettings(templateSettings);

            // Rebuild all templates before notifying the user
            await startRebuildingTemplates();

            // If a new source was added notify the user to restart Visual Studio
            if (templateSourcesChanged || newSourceAdded)
            {
                var dte = Package.GetGlobalService(typeof(DTE)) as DTE;
                dte.StatusBar.Text = @"Your template(s) have been installed. Please restart Visual Studio.";
            }

            templateSourcesChanged = false;
            newSourceAdded = false;
            this.Close();
        }
        protected void FetchGitSourceLocally(TemplateSource source, string destFolder) {
            if (source == null) { throw new ArgumentNullException("source"); }
            if (string.IsNullOrEmpty(destFolder)) { throw new ArgumentNullException("destFolder"); }

            // TODO: these methods should be renamed since fetch means something in git

            try {
                var destDirInfo = new DirectoryInfo(destFolder);
                if (destDirInfo.Exists) {
                    ResetDirectoryAttributes(destDirInfo);
                    // TODO: if the folder exists and there is a .git folder then we should do a fetch/merge or pull
                    destDirInfo.Delete(true);
                }

                // clone it
                var repoPath = Repository.Clone(source.Location.AbsoluteUri, destFolder);
                var repo = new Repository(repoPath);
                Branch branch = repo.Checkout(source.Branch);
                branch.Checkout();
            }
            catch (Exception ex) {
                UpdateStatusBar("There was an error check the activity log");
                // TODO: we should log this error
                string msg = ex.ToString();
                System.Windows.Forms.MessageBox.Show(msg);
            }
        }