Exemple #1
0
        private static bool IsRemoteServerConnectionOK(RepoModel repoModel, SummaryRecord summaryRecord)
        {
            if (IsSiteAccessible(repoModel.RemoteURL))
            {
                return(true);
            }

            summaryRecord.Result  = "Error";
            summaryRecord.Message = $"Could not connect to remote server: {repoModel.RemoteURL}";
            return(false);
        }
Exemple #2
0
        public static void DoGitReset(RepoModel repoModel, ref SummaryRecord summaryRecord)
        {
            if (!IsRemoteServerConnectionOK(repoModel, summaryRecord))
            {
                return;
            }

            using (var repo = new Repository(repoModel.Path))
            {
                Commands.Stage(repo, "*");

                repo.Reset(ResetMode.Hard, repo.Head.Tip);
            }
        }
Exemple #3
0
        public static void DoGitFetch(RepoModel repoModel, ref SummaryRecord summaryRecord)
        {
            if (!IsRemoteServerConnectionOK(repoModel, summaryRecord))
            {
                return;
            }

            using (var repo = new Repository(repoModel.Path))
            {
                var hasUserNameOrPassword = GetUserNameAndPassword(out var userName,
                                                                   out var password, repoModel.RepoSourceType);

                const string logMessage = "";

                var options = new FetchOptions();

                if (hasUserNameOrPassword)
                {
                    options.CredentialsProvider = (url, usernameFromUrl, types) =>
                                                  new UsernamePasswordCredentials {
                        Username = userName, Password = password
                    };
                }

                foreach (var remote in repo.Network.Remotes)
                {
                    var refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);
                    try
                    {
                        Commands.Fetch(repo, remote.Name, refSpecs, options, logMessage);
                    }
                    catch (Exception ex)
                    {
                        if (!hasUserNameOrPassword)
                        {
                            summaryRecord.Result  = "Error";
                            summaryRecord.Message = "Need to configure repository connection credentials.";
                        }
                        else
                        {
                            summaryRecord.Result = "Error";
                            var message = ex.Message.Replace("too many redirects or authentication replays",
                                                             "Incorrect username or password");
                            summaryRecord.Message = message;
                        }
                    }
                }
            }
        }
        public IPIDEntity Map(CsvReader csv)
        {
            if (csv == null)
            {
                throw new ArgumentNullException(nameof(csv));
            }

            var record = new SummaryRecord()
            {
                ReportingMonth = csv.GetField <string>(0),
                ReportingUnit  = csv.GetField <string>(1),
                ProjectNumber  = csv.GetField <string>(2),
                ProjectName    = csv.GetField <string>(3),
                ChangeCount    = csv.GetField <string>(4)
            };

            return(record);
        }
Exemple #5
0
        public void Setup()
        {
            _target = new SummaryRecord();

            _records = new List <YearlyData>()
            {
                new YearlyData {
                    ProductName = "Comp", DevelopmentYear = 1992, OriginYear = 1992, IncrementalValue = 110m
                },
                new YearlyData {
                    ProductName = "Comp", DevelopmentYear = 1993, OriginYear = 1992, IncrementalValue = 170m
                },
                new YearlyData {
                    ProductName = "Comp", DevelopmentYear = 1993, OriginYear = 1993, IncrementalValue = 200m
                },
                new YearlyData {
                    ProductName = "Non-Comp", DevelopmentYear = 1990, OriginYear = 1990, IncrementalValue = 45.2m
                },
                new YearlyData {
                    ProductName = "Non-Comp", DevelopmentYear = 1990, OriginYear = 1991, IncrementalValue = 64.8m
                },
                new YearlyData {
                    ProductName = "Non-Comp", DevelopmentYear = 1990, OriginYear = 1993, IncrementalValue = 37.0m
                },
                new YearlyData {
                    ProductName = "Non-Comp", DevelopmentYear = 1991, OriginYear = 1991, IncrementalValue = 50.0m
                },
                new YearlyData {
                    ProductName = "Non-Comp", DevelopmentYear = 1991, OriginYear = 1992, IncrementalValue = 75.0m
                },
                new YearlyData {
                    ProductName = "Non-Comp", DevelopmentYear = 1991, OriginYear = 1993, IncrementalValue = 25.0m
                },
                new YearlyData {
                    ProductName = "Non-Comp", DevelopmentYear = 1992, OriginYear = 1992, IncrementalValue = 55.0m
                },
                new YearlyData {
                    ProductName = "Non-Comp", DevelopmentYear = 1992, OriginYear = 1993, IncrementalValue = 85.0m
                },
                new YearlyData {
                    ProductName = "Non-Comp", DevelopmentYear = 1993, OriginYear = 1993, IncrementalValue = 100.0m
                }
            };
        }
 public void Setup()
 {
     _target = new SummaryRecord();
 }
Exemple #7
0
        public static void DoGitPull(RepoModel repoModel, ref SummaryRecord summaryRecord)
        {
            if (!IsRemoteServerConnectionOK(repoModel, summaryRecord))
            {
                return;
            }

            using (var repo = new Repository(repoModel.Path))
            {
                var hasUserNameOrPassword = GetUserNameAndPassword(out var userName,
                                                                   out var password, repoModel.RepoSourceType);

                try
                {
                    var options = new PullOptions
                    {
                        FetchOptions = new FetchOptions
                        {
                            CredentialsProvider = (url, usernameFromUrl, types) =>
                                                  new UsernamePasswordCredentials
                            {
                                Username = userName,
                                Password = password
                            }
                        }
                    };

                    // User information to create a merge commit
                    //Todo: Change this to be actual email
                    var signature = new Signature(
                        new Identity(userName, $"{userName}@gmail.com"), DateTimeOffset.Now);

                    // Pull
                    var mergeResult = Commands.Pull(repo, signature, options);

                    switch (mergeResult.Status)
                    {
                    case MergeStatus.Conflicts:
                        summaryRecord.Message = "The merge had conflicts. Resolve them before continuing.";
                        break;

                    case MergeStatus.FastForward:
                        summaryRecord.Message =
                            $"Fast forward to commit: {mergeResult.Commit.Author} {mergeResult.Commit.Message}";
                        break;

                    case MergeStatus.NonFastForward:
                        summaryRecord.Message =
                            $"Non-fast forward to commit: {mergeResult.Commit.Author} {mergeResult.Commit.Message}";
                        break;

                    case MergeStatus.UpToDate:
                        summaryRecord.Message = "The branch was already up-to-date.";
                        break;

                    default:
                        Debug.WriteLine($"Unknown mergeResult: {mergeResult.Status}");
                        break;
                    }
                }
                catch (Exception ex)
                {
                    if (!hasUserNameOrPassword)
                    {
                        summaryRecord.Result  = "Error";
                        summaryRecord.Message = "Need to configure repository connection credentials.";
                    }
                    else
                    {
                        summaryRecord.Result = "Error";
                        var message = ex.Message.Replace("too many redirects or authentication replays",
                                                         "Incorrect username or password");
                        summaryRecord.Message = message;
                    }
                }
            }
        }
        //static ClassRef @class = new ClassRef(typeof(SummaryCell));

        public SummaryCell(SummaryRecord summary)
        {
            //Debug.EnableTracing(@class);
            Summary = summary ?? throw new ArgumentNullException(nameof(summary));
            Summary.PropertyChanged += (s, e) => FirePropertyChanged(e.PropertyName);
        }