예제 #1
0
        /// <summary>
        /// Evaluates the pending changes for policy violations
        /// </summary>
        /// <returns></returns>
        public override PolicyFailure[] Evaluate()
        {
            try
            {
                TellMe.Instance.TrackEvent("BranchPolicyEvaluate");
                List <PolicyFailure> policyFailures    = new List <PolicyFailure>();
                Stopwatch            partialTimer      = new Stopwatch();
                Stopwatch            wholeProcessTimer = new Stopwatch();
                wholeProcessTimer.Start();

                BranchPatternEvaluator ev = new BranchPatternEvaluator();
                // process each file in the set of pending changes
                if (_pendingCheckin != null)
                {
                    partialTimer.Start();
                    List <String> serverItems = (from x in PendingCheckin.PendingChanges.CheckedPendingChanges select x.ServerItem).ToList();
                    TellMe.Instance.TrackMetric("PendingCheckinRetrieve", partialTimer.ElapsedMilliseconds);
                    TellMe.Instance.TrackMetric("PendingCheckinCount", serverItems.Count);
                    List <BranchPattern> matchingBranchPatterns = ev.EvaluateServerPaths(serverItems, branchPatterns);
                    TellMe.Instance.TrackMetric("BranchPolicyDetectedCount", matchingBranchPatterns.Count);
                    List <BranchPolicyFailure> branchPolicyFailures = new List <BranchPolicyFailure>();
                    foreach (BranchPattern bp in matchingBranchPatterns)
                    {
                        branchPolicyFailures.AddRange(bp.EvaluatePendingCheckin(_pendingCheckin));
                    }
                    policyFailures = (from bpf in branchPolicyFailures select new PolicyFailure(bpf.Message, this)).ToList();
                }
                TellMe.Instance.TrackMetric("BranchPolicyEvaluateTimespan", wholeProcessTimer.ElapsedMilliseconds);
                return(policyFailures.ToArray());
            }
            catch (Exception ex)
            {
                TellMe.Instance.TrackException(ex);
                throw ex;
            }
            return(new PolicyFailure[] { new PolicyFailure(string.Format("There was an error evaluating the policy. Pass the session ID {0} to your administrator.", TellMe.Instance.Context.Session.Id), this) });
        }
 public void Init()
 {
     evaluator = new BranchPatternEvaluator();
 }