示例#1
0
        public void ResourceCodeGenHasCorrectBaseName(string sourcePath, string baseName)
        {
            // Resx code generation does not respect <LogicalName> metadata on <EmbeddedResource />.
            // This can result in an incorrect base name being used in generated code.
            //
            // https://github.com/dotnet/project-system/issues/1058
            //
            // To prevent this from happening unwittingly (eg. https://github.com/dotnet/project-system/issues/6180)
            // this test ensures the expected name is used. This will catch cases when code gen
            // produces invalid code before merging/insertion.

            string pattern = sourcePath.Substring(sourcePath.Length - 2, 2) switch
            {
                "cs" => $"global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager(\"{baseName}\"",
                "vb" => $"Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager(\"{baseName}\"",
                string format => throw new Exception("Unexpected source file format: " + format)
            };

            string path = Path.Combine(RepoUtil.FindRepoRootPath(), sourcePath);

            foreach (string line in File.ReadLines(path))
            {
                if (line.Contains(pattern))
                {
                    return;
                }
            }

            throw new XunitException($"Expected base name \"{baseName}\" not found in generated file: {sourcePath}");
        }
    }
示例#2
0
        public async Task <ReadMeResponse> GetReadMe([FromQuery] string Owner, [FromQuery] string Repo, [FromQuery] ReadMeFormat Format = ReadMeFormat.Markdown)
        {
            var readme = await RepoUtil.GetReadMeAsync(Owner, Repo);

            if (readme != null)
            {
                switch (Format)
                {
                case ReadMeFormat.Markdown:
                {
                    return(new ReadMeResponse()
                        {
                            Content = readme.GetContent(), Format = Format, Owner = Owner, Repo = Repo
                        });
                }

                case ReadMeFormat.Html:
                {
                    return(new ReadMeResponse()
                        {
                            Content = await readme.GetHtmlAsync(), Format = Format, Owner = Owner, Repo = Repo
                        });
                }

                default:
                {
                    return(null);
                }
                }
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Exports the given changeset as a patch to a file.
        /// </summary>
        /// <param name="action"></param>
        public void ExportPatch(object action)
        {
            var commit = action as Commit;

            if (commit == null)
            {
                return;
            }

            var dialog = new SaveFileDialog
            {
                FileName   = commit.Description.Right(72),
                DefaultExt = ".patch",
                Filter     = "Patch files|*.patch"
            };

            if (dialog.ShowDialog() == false)
            {
                return;
            }

            var filename = dialog.FileName;

            Task.Run(() =>
            {
                using (var repo = new LibGit2Sharp.Repository(RepositoryFullPath))
                {
                    File.WriteAllText(filename, RepoUtil.GetTreeChangesForCommit(repo, commit).Patch);
                }
            });
        }
示例#4
0
        /// <summary>
        /// Adds the commits of a branch in oldest-to-newest order. and returns the list of commits.
        /// </summary>
        public List <ShallowCommit> AddBranch(Branch branch)
        {
            var commits = RepoUtil.GetPrimaryParents(branch.Tip).Select(ShallowCommit.FromCommit).Reverse().ToList();

            this.branches.Add(commits);
            return(commits);
        }
        protected static IEnumerable <string> GetRules(string suffix, bool recursive = false)
        {
            // Not all rules are embedded as manifests so we have to read the xaml files from the file system.
            string rulesPath = Path.Combine(RepoUtil.FindRepoRootPath(), "src", "Microsoft.VisualStudio.ProjectSystem.Managed", "ProjectSystem", "Rules");

            if (!string.IsNullOrEmpty(suffix))
            {
                rulesPath = Path.Combine(rulesPath, suffix);
            }

            Assert.True(Directory.Exists(rulesPath), "Couldn't find XAML rules folder: " + rulesPath);

            var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;

            foreach (var filePath in Directory.EnumerateFiles(rulesPath, "*.xaml", searchOption))
            {
                XElement rule = LoadXamlRule(filePath);

                // Ignore XAML documents for non-Rule types (such as ProjectSchemaDefinitions)
                if (rule.Name.LocalName != "Rule")
                {
                    continue;
                }

                yield return(filePath);
            }
        }
示例#6
0
        public static IEnumerable <object[]> GetRules(string suffix, bool file, bool browseObject)
        {
            // Not all rules are embedded as manifests so we have to read the xaml files from the file system.
            string rulesPath = Path.Combine(RepoUtil.FindRepoRootPath(), "src", "Microsoft.VisualStudio.ProjectSystem.Managed", "ProjectSystem", "Rules");

            Assert.True(Directory.Exists(rulesPath), "Couldn't find XAML rules folder: " + rulesPath);

            if (!string.IsNullOrEmpty(suffix))
            {
                rulesPath = Path.Combine(rulesPath, suffix);
            }
            foreach (var fileName in Directory.EnumerateFiles(rulesPath, "*.xaml"))
            {
                if (fileName.EndsWith(".BrowseObject.xaml", StringComparisons.Paths) && !browseObject)
                {
                    continue;
                }
                // Special case for Folder because it is File and BrowseObject context (for now) but naming convention is like File
                if ((!fileName.EndsWith(".BrowseObject.xaml", StringComparisons.Paths) && !file) ||
                    (fileName.EndsWith("Folder.xaml", StringComparisons.Paths) && browseObject))
                {
                    continue;
                }

                // we return the rule name separately mainly to get a readable display in Test Explorer so failures can be diagnosed more easily
                yield return(new object[] { Path.GetFileNameWithoutExtension(fileName), fileName });
            }
        }
示例#7
0
        private static IEnumerable <string> GetPackageContents(string vsixName)
        {
            var rootPath = RepoUtil.FindRepoRootPath();

#if DEBUG
            var config = "Debug";
#elif RELEASE
            var config = "Release";
#else
#error Unexpected configuration
#endif

            // D:\repos\project-system\artifacts\Debug\VSSetup\ProjectSystem.vsix

            var vsixPath = Path.Combine(
                rootPath,
                "artifacts",
                config,
                "VSSetup",
                "Insertion",
                vsixName);

            using var archive = ZipFile.OpenRead(vsixPath);

            return(archive.Entries.Select(entry => entry.FullName).OrderBy(fn => fn));
        }
示例#8
0
        /// <summary>
        /// Copies the given changeset as a patch to clipboard.
        /// </summary>
        /// <param name="action"></param>
        public void CopyPatch(object action)
        {
            Commit commit = action as Commit;

            using (var repo = new LibGit2Sharp.Repository(RepositoryFullPath))
            {
                Clipboard.SetText(RepoUtil.GetTreeChangesForCommit(repo, commit).Patch);
            }
        }
示例#9
0
        /// <summary>
        /// Exports the given changeset as a patch to a file.
        /// </summary>
        /// <param name="action"></param>
        public void ExportPatch(object action)
        {
            Commit commit = action as Commit;

            using (var repo = new LibGit2Sharp.Repository(RepositoryFullPath))
            {
                SaveFileDialog dialog = new SaveFileDialog();
                dialog.FileName   = commit.Description.Right(72);
                dialog.DefaultExt = ".patch";
                dialog.Filter     = "Patch files|*.patch";

                if (dialog.ShowDialog() == true)
                {
                    // Save the patch to a file.
                    File.WriteAllText(dialog.FileName, RepoUtil.GetTreeChangesForCommit(repo, commit).Patch);
                }
            }
        }
示例#10
0
        /// <summary>
        /// Records a list of commits.
        /// </summary>
        private void RecordCommits(Repository repo, IEnumerable <ShallowCommit> commits)
        {
            foreach (var commit in commits)
            {
                if (this.Commits.Contains(commit))
                {
                    continue;
                }

                this.Commits.Add(commit);
                if (commit.Parents.Count() > 1)
                {
                    this.Merges.Add(commit);
                    foreach (var parent in commit.Parents.Skip(1))
                    {
                        this.RecordCommits(repo, RepoUtil.GetPrimaryParents(repo, parent.Sha).Select(ShallowCommit.FromCommit));
                    }
                }
            }
        }
示例#11
0
        /// <summary>
        /// Post-processes the commit. This means that we set up the parent object relationship.
        /// </summary>
        /// <param name="Commits"></param>
        public void PostProcess(ObservableCollection <Commit> commits, ObservableCollection <Branch> branches)
        {
            // Set Parents.
            if (ParentCount > 0)
            {
                foreach (string hash in ParentHashes)
                {
                    Commit parentCommit = commits.Where(c => c.Hash == hash).FirstOrDefault();

                    if (parentCommit != null)
                    {
                        Parents.Add(parentCommit);
                        parentCommit.Children.Add(this);
                    }
                }
            }

            // Set BranchesAround.
            BranchesAround = RepoUtil.GetBranchesAroundCommit(this, branches);
        }
示例#12
0
        public async Task <String> GetHtmlAsync()
        {
            var content = new StringContent(JsonConvert.SerializeObject(new MarkdownRequest()
            {
                text    = GetContent(),
                mode    = "gfm",
                context = $"{Owner}/{Repo}"
            }), Encoding.UTF8, "application/json");

            var data = await Web.PostAsync("https://api.github.com/markdown" + RepoUtil.GetAuthQuery(), content);

            if (data.IsSuccessStatusCode)
            {
                var html = await data.Content.ReadAsStringAsync();

                return(await ProcessHtmlForView(html));
            }
            else
            {
                return(String.Empty);
            }
        }
示例#13
0
        public void Register()
        {
            using (var payCnn = new MySqlConnection(ConnectionStrings.DT_Payment))
            {
                using (var orderCnn = new MySqlConnection(ConnectionStrings.DT_Order))
                {
                    payCnn.Open();
                    using (var payTrans = payCnn.BeginTransaction())
                    {
                        orderCnn.Open();
                        using (var orderTrans = orderCnn.BeginTransaction())
                        {
                            var payUserRepoUtil   = new RepoUtil <Model.Databases.DT_Payment.User>();
                            var orderUserRepoUtil = new RepoUtil <Model.Databases.DT_Order.User>();

                            payCnn.Execute(payUserRepoUtil.InsertSql, new Model.Databases.DT_Payment.User()
                            {
                                CreateAt = DateTime.Now,
                                Name     = "RAW",
                                Password = "******",
                                UpdateAt = DateTime.Now,
                            });
                            orderCnn.Execute(orderUserRepoUtil.InsertSql, new Model.Databases.DT_Order.User()
                            {
                                CreateAt = DateTime.Now,
                                Name     = "RAW",
                                Password = "******",
                                UpdateAt = DateTime.Now,
                            });

                            payTrans.Commit();
                            orderTrans.Commit();
                        }
                    }
                }
            }
        }
示例#14
0
        public void TestZipScenarios(ZipScenario scenario)
        {
            var config = new Config {
                Sources = GetTestRepoPaths(scenario.Sources),
                Target  = TestData.GetCleanTempDir(),
                Force   = true,
                Silent  = true
            };
            var zipper = new RepoZipper(config);
            var repo   = zipper.Zip();

            var branches = repo.Branches.Where(b => !b.IsRemote).ToList();

            Assert.That(branches.Select(b => b.FriendlyName),
                        Is.EquivalentTo(scenario.Branches.Keys));

            foreach (var branch in branches)
            {
                var commits = RepoUtil.GetPrimaryParents(branch.Tip).Select(c => c.Message).Reverse();
                Assert.That(commits,
                            Is.EqualTo(scenario.Branches[branch.FriendlyName].Select(sha => (repo.Lookup(sha) as Commit).Message)),
                            "Commits do not match for branch: " + branch.FriendlyName
                            );
            }

            // TODO this may be unified with ZippedRepoTest
            var merges = RepoUtil.GetMerges(branches.Select(b => b.Tip)).ToList();             // just retrieve merges for zipped branches

            Assert.That(merges.Select(m => m.Message), Is.EquivalentTo(scenario.Merges.Select(c => Lookup(repo, c.Sha).Message)));

            // We have to skip the 1st parent as this one may be different
            var actual   = merges.Select(c => c.Parents.Skip(1).Select(p => p.Message));
            var expected = scenario.Merges.Select(c => c.Parents.Skip(1).Select(p => Lookup(repo, p).Message));

            Assert.That(actual, Is.EquivalentTo(expected));
        }
        /// <summary>
        /// Preprocessing prior to menu opening.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnOpened(object sender, System.Windows.RoutedEventArgs e)
        {
            var menuItemIndex       = 0;
            var commit              = GetCurrentSelectedCommit();
            var repositoryViewModel = GetRepositoryViewModel();
            var highlightColor      = new SolidColorBrush()
            {
                Color = Color.FromRgb(8, 94, 160)
            };

            // Remove previously added Dynamic menu items. We determine dynamically added menu items by their Tag == "Dynamic".
            RemoveDynamicallyAddedMenuItems();

            if (commit == null)
            {
                return;
            }

            // Add Checkout menu items. TODO: Add also non-branch-checkouts.
            var numberOfCheckoutItems = 0;

            foreach (var branch in commit.Branches)
            {
                // Only if the right clicked commit is the tip of the branch, AND the branch is not already checkout out, continue.
                if (branch.Tip == commit && (repositoryViewModel.Head) != branch && branch.IsRemote == false)
                {
                    var text = new TextBlock();
                    text.Inlines.AddRange(new Inline[]
                    {
                        new Run("Checkout "),
                        new Run(branch.Name)
                        {
                            Foreground = highlightColor
                        }
                    });

                    Items.Insert(menuItemIndex++, CreateMenuItem(text, "Checkout"));
                    numberOfCheckoutItems++;
                }
            }

            if (numberOfCheckoutItems == 0)
            {
                var text = new TextBlock();
                text.Inlines.AddRange(new Inline[]
                {
                    new Run("Checkout commit "),
                    new Run(commit.HashShort)
                    {
                        Foreground = highlightColor
                    }
                });

                Items.Insert(menuItemIndex++, CreateMenuItem(text, "Checkout"));
                numberOfCheckoutItems++;
            }

            if (numberOfCheckoutItems > 1)
            {
                Items.Insert(menuItemIndex++, new Separator
                {
                    Tag = "Dynamic"
                });
            }

            // Add Merge menu items.
            var numberOfMergeItems = 0;

            foreach (Branch branch in commit.Branches)
            {
                if (branch.Tip == commit && branch != (Branch)repositoryViewModel.Head)
                {
                    // Add those that track this branch.
                    foreach (Branch branchThatTracks in RepoUtil.GetBranchesThatTrack(branch, repositoryViewModel.Branches))
                    {
                        if (branchThatTracks.BehindBy > 0 &&
                            branchThatTracks.IsRemote == false &&
                            branch.Tip != branchThatTracks.Tip &&
                            repositoryViewModel.Head is DetachedHead == false &&
                            branch.Tip != branchThatTracks.Tip)
                        {
                            var text = new TextBlock();
                            text.Inlines.AddRange(new Inline[]
                            {
                                new Run("Merge "),
                                new Run(branch.Name)
                                {
                                    Foreground = highlightColor
                                },
                                new Run(" into "),
                                new Run(branchThatTracks.Name)
                                {
                                    Foreground = highlightColor
                                }
                            });

                            Items.Insert(menuItemIndex++, CreateMenuItem(text, "Merge"));
                            numberOfCheckoutItems++;
                        }
                    }
                }

                if (branch.Tip == commit &&
                    branch != (Branch)repositoryViewModel.Head &&
                    repositoryViewModel.Head is DetachedHead == false &&
                    commit != ((Branch)repositoryViewModel.Head).Tip)
                {
                    var text = new TextBlock();
                    text.Inlines.AddRange(new Inline[]
                    {
                        new Run("Merge "),
                        new Run(branch.Name)
                        {
                            Foreground = highlightColor
                        },
                        new Run(" into "),
                        new Run(((Branch)repositoryViewModel.Head).Name)
                        {
                            Foreground = highlightColor
                        }
                    });

                    Items.Insert(menuItemIndex++, CreateMenuItem(text, "Merge"));
                    numberOfCheckoutItems++;
                }
            }

            if (numberOfMergeItems > 1)
            {
                Items.Insert(menuItemIndex++, new Separator
                {
                    Tag = "Dynamic"
                });
            }
        }
示例#16
0
 public async Task <Repo> SearchRepo([FromQuery] string Owner, [FromQuery] string Repo)
 {
     return(await RepoUtil.GetRepoAsync(Owner, Repo));
 }
示例#17
0
        /// <summary>
        /// Loads branches and commits.
        /// </summary>
        /// <param name="repo"></param>
        private void LoadBranchesAndCommits(LibGit2Sharp.Repository repo = null)
        {
            var dispose = false;

            if (repo == null)
            {
                repo    = new LibGit2Sharp.Repository(RepositoryFullPath);
                dispose = true;
            }

            // Small performance boosts.
            Commits.DisableNotifications();
            Branches.DisableNotifications();

            // Create commits.
            Commits.Clear();
            var commitList = new List <Commit>();

            foreach (var commit in repo.Commits.QueryBy(new LibGit2Sharp.Filter {
                Since = repo.Branches
            }).Take(CommitsPerPage))
            {
                commitList.Add(Commit.Create(repo, commit, Tags));
            }
            Commits.AddRange(commitList);

            // Create branches.
            Branches.Clear();
            foreach (var branch in repo.Branches)
            {
                var b = Branch.Create(this, repo, branch);
                Branches.Add(b);
            }

            // Post-process branches (tips and tracking branches).
            foreach (var branch in Branches)
            {
                // Set the HEAD property if it matches.
                if (repo.Head.Name == branch.Name)
                {
                    Head = branch;
                    branch.Tip.IsHead = true;
                }

                branch.PostProcess(Branches, Commits);
            }

            // Post-process commits (commit parents).
            foreach (var commit in Commits)
            {
                // Set the HEAD property to a DetachedHead branch if the HEAD matched and it was null.
                if (Head == null && repo.Head.Tip.Sha == commit.Hash)
                {
                    Head = new DetachedHead
                    {
                        Tip = commit
                    };

                    commit.IsHead = true;
                }

                commit.PostProcess(Commits, Branches);
            }

            // Calculate commit visual positions for each branch tree.
            foreach (var branch in Branches)
            {
                RepoUtil.IncrementCommitTreeVisualPositionsRecursively(branch.Tip);
            }

            // Fire notifications for the collections on the UI thread.
            Application.Current.Dispatcher.Invoke(
                DispatcherPriority.Normal,
                (Action)(() =>
            {
                Commits.EnableNotifications(true);
                Branches.EnableNotifications(true);

                var tabControl = UIHelper.FindChild <TabControl>(Application.Current.MainWindow, "RepositoryTabs");
                var changesetHistory = UIHelper.FindChild <ChangesetHistory>(tabControl);

                if (changesetHistory != null)
                {
                    changesetHistory.RedrawGraph();
                }
            })
                );

            if (dispose)
            {
                repo.Dispose();
            }
        }
示例#18
0
        /// <summary>
        /// Loads branches and commits.
        /// </summary>
        /// <param name="repo"></param>
        private void LoadBranchesAndCommits(LibGit2Sharp.Repository repo)
        {
            var dispose = false;

            if (repo == null)
            {
                repo    = new LibGit2Sharp.Repository(RepositoryFullPath);
                dispose = true;
            }

            // Small performance boosts.
            Commits.DisableNotifications();
            Branches.DisableNotifications();

            // Create commits.
            Commits.Clear();
            List <Commit> commitList = new List <Commit>();

            foreach (LibGit2Sharp.Commit commit in repo.Commits.QueryBy(new LibGit2Sharp.Filter {
                Since = repo.Branches
            }).Take(CommitsPerPage))
            {
                commitList.Add(Commit.Create(repo, commit, Tags));
            }
            Commits.AddRange(commitList);

            // Create branches.
            Branches.Clear();
            foreach (LibGit2Sharp.Branch branch in repo.Branches)
            {
                Branch b = Branch.Create(this, repo, branch);
                Branches.Add(b);
            }

            // Post-process branches (tips and tracking branches).
            foreach (Branch branch in Branches)
            {
                // Set the HEAD property if it matches.
                if (repo.Head.Name == branch.Name)
                {
                    Head = branch;
                    branch.Tip.IsHead = true;
                }

                branch.PostProcess(Branches, Commits);
            }

            // Post-process commits (commit parents).
            foreach (Commit commit in Commits)
            {
                // Set the HEAD property to a DetachedHead branch if the HEAD matched and it was null.
                if (Head == null && repo.Head.Tip.Sha == commit.Hash)
                {
                    Head = new DetachedHead
                    {
                        Tip = commit
                    };

                    commit.IsHead = true;
                }

                commit.PostProcess(Commits, Branches);
            }

            // Calculate commit visual positions for each branch tree.
            foreach (Branch branch in Branches)
            {
                RepoUtil.IncrementCommitTreeVisualPositionsRecursively(branch.Tip);
            }

            Commits.EnableNotifications();
            Branches.EnableNotifications();

            if (dispose)
            {
                repo.Dispose();
            }
        }