Exemple #1
0
 private MatchResult(MatchResultType resultType, IEnumerable<IRestriction> matchedRestrictions, IEnumerable<IRestriction> unmatchedRestrictions, string cacheKey)
 {
     _resultType = resultType;
     _matchedRestrictions = matchedRestrictions.IfNotNull(arg => new HashSet<IRestriction>(arg));
     _unmatchedRestrictions = unmatchedRestrictions.IfNotNull(arg => new HashSet<IRestriction>(arg));
     _cacheKey = cacheKey;
 }
        public override MatchResult Matches(FileInfo file, Dictionary <Type, IFileCache> fileCaches, CancellationToken token)
        {
            double          size       = UnitUtil.ConvertSize(file.Length, SizeUnits.Bytes, m_Parameters.Units, m_Parameters.Metric);
            MatchResultType resultType = CompareUtil.Compare(size, m_Parameters.ComparisonType, m_Parameters.Value);

            return(new MatchResult(resultType, new string[] { size.ToString(m_Parameters.Format) }));
        }
Exemple #3
0
 private MatchResult(MatchResultType resultType, IEnumerable <IRestriction> matchedRestrictions, IEnumerable <IRestriction> unmatchedRestrictions, string cacheKey = null)
 {
     _resultType            = resultType;
     _unmatchedRestrictions = unmatchedRestrictions.ToArray();
     _matchedRestrictions   = matchedRestrictions.ToArray();
     _cacheKey = cacheKey;
 }
 private MatchResult(MatchResultType resultType, IEnumerable <IRestriction> matchedRestrictions, IEnumerable <IRestriction> unmatchedRestrictions, string cacheKey)
 {
     _resultType            = resultType;
     _matchedRestrictions   = new HashSet <IRestriction>(matchedRestrictions ?? new IRestriction[0]);
     _unmatchedRestrictions = new HashSet <IRestriction>(unmatchedRestrictions ?? new IRestriction[0]);
     _cacheKey = cacheKey;
 }
Exemple #5
0
        public override MatchResult Matches(FileInfo file, Dictionary <Type, IFileCache> fileCaches, CancellationToken token)
        {
            DateTime fileDate;

            switch (m_Parameters.FileDateType)
            {
            case FileDateType.Created:
                fileDate = file.CreationTime;
                break;

            case FileDateType.Modified:
                fileDate = file.LastWriteTime;
                break;

            default:
                fileDate = file.LastAccessTime;
                break;
            }
            bool matches = false;

            switch (m_Parameters.ComparisonType)
            {
            case TimeComparisonType.After:
                matches = (fileDate > m_Parameters.Date);
                break;

            default:
                matches = (fileDate < m_Parameters.Date);
                break;
            }
            MatchResultType resultType = matches ? MatchResultType.Yes : MatchResultType.No;

            return(new MatchResult(resultType, new string[] { fileDate.ToString(m_Parameters.OutputFormat) }));
        }
        public override MatchResult Matches(FileInfo file, Dictionary <Type, IFileCache> fileCaches, CancellationToken token)
        {
            MatchResultType     resultType  = MatchResultType.NotApplicable;
            DetectedLineEndings lineEndings = DetectedLineEndings.NotApplicable;

            try
            {
                using (StreamReader reader = new StreamReader(file.FullName))
                {
                    lineEndings = TextUtil.GetLineEndings(reader, false, token);
                }
                if (lineEndings == m_Parameters.LineEndings)
                {
                    resultType = MatchResultType.Yes;
                }
                else
                {
                    resultType = MatchResultType.No;
                }
            }
            catch (Exception ex)
            {
            }
            return(new MatchResult(resultType, lineEndings.ToString()));
        }
Exemple #7
0
		private MatchResult(MatchResultType resultType, IEnumerable<IRestriction> matchedRestrictions, IEnumerable<IRestriction> unmatchedRestrictions, string cacheKey)
		{
			_resultType = resultType;
			_matchedRestrictions = new HashSet<IRestriction>(matchedRestrictions ?? new IRestriction[0]);
			_unmatchedRestrictions = new HashSet<IRestriction>(unmatchedRestrictions ?? new IRestriction[0]);
			_cacheKey = cacheKey;
		}
Exemple #8
0
        public override MatchResult Matches(FileInfo file, Dictionary <Type, IFileCache> fileCaches, CancellationToken token)
        {
            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                XmlUtil.LoadXmlDocument(xmlDoc, file, m_Parameters.IgnoreDefaultNamespace);
            }
            catch (Exception)
            {
                return(new MatchResult(MatchResultType.NotApplicable, "N/A"));
            }
            XPathNavigator      navigator        = xmlDoc.CreateNavigator();
            XmlNamespaceManager namespaceManager = XmlUtil.GetNamespaceManager(
                xmlDoc, navigator, m_Parameters.IgnoreDefaultNamespace,
                m_Parameters.DefaultNamespacePrefixIfNotIgnored);

            try
            {
                m_Expression.SetContext(namespaceManager);
                XPathNodeIterator iterator   = navigator.Select(m_Expression);
                MatchResultType   resultType = CompareUtil.Compare(iterator.Count,
                                                                   m_Parameters.ComparisonType, m_Parameters.Count);
                return(new MatchResult(resultType, iterator.Count.ToString()));
            }
            catch (XPathException)
            {
                return(new MatchResult(MatchResultType.No, "0"));
            }
        }
Exemple #9
0
        public override ProcessingResult Process(FileInfo originalFile,
                                                 MatchResultType matchResultType, string[] values,
                                                 FileInfo[] generatedFiles, ProcessInput whatToProcess,
                                                 CancellationToken token)
        {
            switch (m_Parameters.PathFormat)
            {
            case PathFormat.FullPath:
                m_CsvWriter.WriteField(originalFile.FullName);
                break;

            case PathFormat.NameThenDirectory:
                m_CsvWriter.WriteField(originalFile.Name);
                m_CsvWriter.WriteField(originalFile.DirectoryName);
                break;

            case PathFormat.DirectoryThenName:
                m_CsvWriter.WriteField(originalFile.DirectoryName);
                m_CsvWriter.WriteField(originalFile.Name);
                break;
            }
            m_CsvWriter.WriteField(matchResultType.ToString());
            foreach (string value in values)
            {
                m_CsvWriter.WriteField(value);
            }
            m_CsvWriter.NextRecord();
            return(new ProcessingResult(ProcessingResultType.Success, "Success", new FileInfo[] { originalFile }));
        }
 public override ProcessingResult Process(FileInfo file,
                                          MatchResultType matchResultType, string[] values,
                                          FileInfo[] generatedFiles, ProcessInput whatToProcess,
                                          CancellationToken token)
 {
     return(new ProcessingResult(ProcessingResultType.Success, "Success", new FileInfo[] { file }));
 }
 private MatchResult(MatchResultType resultType, IEnumerable<IRestriction> matchedRestrictions, IEnumerable<IRestriction> unmatchedRestrictions, string cacheKey = null)
 {
     _resultType = resultType;
     _unmatchedRestrictions = unmatchedRestrictions.ToArray();
     _matchedRestrictions = matchedRestrictions.ToArray();
     _cacheKey = cacheKey;
 }
 private MatchResultItem(MatchResultType type, ProjectStepDefinitionBinding matchedStepDefinition, ParameterMatch parameterMatch, string[] errors, UndefinedStepDescriptor undefinedStep)
 {
     Type = type;
     MatchedStepDefinition = matchedStepDefinition;
     ParameterMatch        = parameterMatch;
     UndefinedStep         = undefinedStep;
     Errors = errors ?? EmptyErrors;
 }
        public override ProcessingResult Process(FileInfo originalFile,
                                                 MatchResultType matchResultType, string[] values,
                                                 FileInfo[] generatedFiles, ProcessInput whatToProcess,
                                                 CancellationToken token)
        {
            StringBuilder        message     = new StringBuilder();
            List <FileInfo>      outputFiles = new List <FileInfo>();
            ProcessingResultType resultType  = ProcessingResultType.Success;

            foreach (IProcessor processor in Processors)
            {
                token.ThrowIfCancellationRequested();
                try
                {
                    ProcessInput what = whatToProcess;
                    if (processor.InputFileSource == InputFileSource.OriginalFile)
                    {
                        what = ProcessInput.OriginalFile;
                    }
                    ProcessingResult result = processor?.Process(originalFile, matchResultType, values,
                                                                 generatedFiles ?? new FileInfo[0], what, token);
                    if (result != null)
                    {
                        if (result.OutputFiles != null)
                        {
                            outputFiles.AddRange(result.OutputFiles);
                        }
                        if (result.Type == ProcessingResultType.Failure)
                        {
                            resultType = ProcessingResultType.Failure;
                        }
                        if (result.Message != null)
                        {
                            if (message.Length > 0)
                            {
                                message.Append(" | ");
                            }
                            message.Append(result.Message);
                        }
                    }
                }
                catch (Exception ex) when(!(ex is OperationCanceledException))
                {
                    resultType = ProcessingResultType.Failure;
                    if (message.Length > 0)
                    {
                        message.Append(" | ");
                    }
                    message.Append(ex.Message);
                    RunInfo.ExceptionInfos.Enqueue(new ExceptionInfo(ex, originalFile));
                }
            }
            if (message.Length == 0)
            {
                message.Append(resultType.ToString());
            }
            return(new ProcessingResult(resultType, message.ToString(), outputFiles.ToArray()));
        }
Exemple #14
0
        /**
         * A match is a single guessing game
         * Returns the result (WIN, LOSE or DRAW)
         */
        public MatchResultType PlayMatch()
        {
            //Create view
            //MatchView display = new MatchView(MatchView.ViewTypes.VIEW_CONSOLE);
            MatchResultType retVal = MatchResultType.DRAW;

            ms.maxAttempts = 5;
            //Host/server should make this, transmit to client(s)
            char[] clearCondition = new char[ms.CurrentWord.Length];
            for (int i = 0; i < ms.CurrentWord.Length; i++)
            {
                clearCondition[i] = '+';
            }

            //Console.WriteLine("Answer: {0}", ms.CurrentWord);
            while (ms.Progression != new string(clearCondition) && ms.Attempts.Count < ms.maxAttempts)
            {
                //Prompt guess
                string guess = "temp";
                if (guess == "I quit")
                {
                    return(MatchResultType.LOSE);
                }
                else if (guess == "I give up")
                {
                    //display.MatchDispayAnswer(ms.CurrentWord);
                    return(MatchResultType.LOSE);
                }
                else
                {
                    guess = guess.ToLower();
                }
                if (guess.Length == ms.CurrentWord.Length && FileManager.WordsListContains(guess))
                {
                    ms.Progression = MatchSession.MatchGuess(guess, ms.CurrentWord);
                    //display.MatchDisplayProgress(ms, guess);
                }
                else
                {
                    //display.MatchDisplayIncorrect(ms);
                }
                ms.Attempts.Add(new KeyValuePair <string, string>(guess, ms.Progression));
            }
            if (ms.Progression == new string(clearCondition))
            {
                retVal = MatchResultType.WIN;
                //display.MatchDisplayWin();
            }
            else
            {
                retVal = MatchResultType.WIN;
                //I want to move the display function up to GameProcedure,
                //but it should still be able to access the information of the session
                //display.MatchDisplayLose(ms);
            }
            return(retVal);
        }
Exemple #15
0
 public MatchResult(int homeScore, int awayScore)
 {
     HomeScore = homeScore;
     AwayScore = awayScore;
     Result    = homeScore > awayScore
         ? MatchResultType.HomeWin
         : homeScore < awayScore
             ? MatchResultType.AwayWin
             : MatchResultType.Draw;
 }
Exemple #16
0
        public int GetMatchesTotal(int teamId, MatchResultType result)
        {
            if (teamId <= 0)
            {
                _logger.LogWarning("TeamService.GetMatchesTotal: " + TextResources.InvalidTeamId);
                return(0);
            }

            return(_teamFactory.GetMatchesTotal(teamId, result));
        }
Exemple #17
0
        public bool AddMatch(int teamId, MatchResultType result)
        {
            if (teamId <= 0 || result.Equals(MatchResultType.All))
            {
                _logger.LogWarning("TeamService.AddMatch: " + TextResources.InvalidTeamInstance);
                return(false);
            }

            return(_teamFactory.AddMatch(teamId, result));
        }
Exemple #18
0
        // ---------------- Match Results

        public Match SaveMatchResult(int matchId, MatchResultType resultType, Team winningTeam)
        {
            Match match = _dbContext.Set <Match>().Find(matchId);

            match.ResultType  = resultType;
            match.WinningTeam = winningTeam;

            _dbContext.SaveChanges();

            return(match);
        }
Exemple #19
0
        public MatchResult(MatchResultType match, string scenarioId, bool defaultScenario)
        {
            if (String.IsNullOrWhiteSpace(scenarioId))
            {
                throw new ArgumentException("Scenario Id cannot be empty", nameof(scenarioId));
            }

            Match           = match;
            ScenarioId      = scenarioId;
            DefaultScenario = defaultScenario;
        }
Exemple #20
0
        public int GetMatchesTotal(int teamId, MatchResultType result)
        {
            var teamToUpdate = _inMemoryTeams.FirstOrDefault(x => x.Id == teamId);

            if (teamToUpdate == null)
            {
                return(0);
            }

            return(teamToUpdate.GetTotals(result));
        }
Exemple #21
0
        public IActionResult PutMatch(int id, MatchResultType matchresulttype)
        {
            if (id <= 0)
            {
                _logger.LogWarning("TeamsController.PutMatch: " + TextResources.InvalidTeamId);
                return(BadRequest());
            }

            var result = _teamService.AddMatch(id, matchresulttype);

            return(result ? (StatusCodeResult)Ok() : (StatusCodeResult)NotFound());
        }
Exemple #22
0
        public bool AddMatch(int teamId, MatchResultType result)
        {
            var teamToUpdate = _inMemoryTeams.FirstOrDefault(x => x.Id == teamId);

            if (teamToUpdate == null)
            {
                return(false);
            }

            teamToUpdate.AddMatch(result);

            return(true);
        }
Exemple #23
0
        public override MatchResult Matches(FileInfo file, Dictionary <Type, IFileCache> fileCaches, CancellationToken token)
        {
            BitmapFileCache cache = fileCaches[typeof(BitmapFileCache)] as BitmapFileCache;

            if (cache == null || !cache.IsBitmap)
            {
                return(new MatchResult(MatchResultType.NotApplicable, "N/A"));
            }
            Bitmap          bitmap     = cache.Bitmap;
            int             imageSize  = m_Parameters.Dimension == MediaDimension.Height ? bitmap.Height : bitmap.Width;
            MatchResultType resultType = CompareUtil.Compare(imageSize, m_Parameters.ComparisonType, m_Parameters.Size);

            return(new MatchResult(resultType, imageSize.ToString()));
        }
Exemple #24
0
        public void CreateMatchResultFromUserInput(Match match)
        {
            Console.WriteLine(string.Format(MATCH_DESCRIPTION, match.FirstTeam.Name, match.SecondTeam.Name));

            MatchResultType result      = GetMatchResult();
            Team            winningTeam = null;

            if (result == MatchResultType.VICTORY)
            {
                winningTeam = GetWinningTeam(match);
            }

            Repository.SaveMatchResult(match.MatchId, result, winningTeam);
        }
Exemple #25
0
        public override MatchResult Matches(FileInfo file, Dictionary <Type, IFileCache> fileCaches, CancellationToken token)
        {
            MatchResult     r    = Condition.Matches(file, fileCaches, token);
            MatchResultType type = MatchResultType.NotApplicable;

            if (r.Type == MatchResultType.Yes)
            {
                type = MatchResultType.No;
            }
            else if (r.Type == MatchResultType.No)
            {
                type = MatchResultType.Yes;
            }
            return(new MatchResult(type, r.Values));
        }
Exemple #26
0
        public override MatchResult Matches(FileInfo file, Dictionary <Type, IFileCache> fileCaches, CancellationToken token)
        {
            DateTime fileDateUtc;

            switch (m_Parameters.TimeSince)
            {
            case FileDateType.Created:
                fileDateUtc = file.CreationTimeUtc;
                break;

            case FileDateType.Modified:
                fileDateUtc = file.LastWriteTimeUtc;
                break;

            default:
                fileDateUtc = file.LastAccessTimeUtc;
                break;
            }
            TimeSpan elapsedTime = DateTime.UtcNow - fileDateUtc;
            double   elapsedValue;

            switch (m_Parameters.Units)
            {
            case TimeSpanUnits.Days:
                elapsedValue = elapsedTime.TotalDays;
                break;

            case TimeSpanUnits.Hours:
                elapsedValue = elapsedTime.TotalHours;
                break;

            case TimeSpanUnits.Minutes:
                elapsedValue = elapsedTime.TotalMinutes;
                break;

            case TimeSpanUnits.Seconds:
                elapsedValue = elapsedTime.TotalSeconds;
                break;

            default:
                elapsedValue = elapsedTime.TotalMilliseconds;
                break;
            }
            MatchResultType resultType = CompareUtil.Compare(elapsedValue,
                                                             m_Parameters.ComparisonType, m_Parameters.TimeSpan);

            return(new MatchResult(resultType, elapsedValue.ToString()));
        }
    public bool Matches(
        SeriesScores[] seriesScores)
    {
        int             teamScore     = seriesScores.Last().TeamScoreTotal;
        int             opponentScore = seriesScores.Last().OpponentScoreTotal;
        MatchResultType matchWon      = teamScore > opponentScore
            ? MatchResultType.Win
            : (teamScore < opponentScore ? MatchResultType.Loss : MatchResultType.Draw);
        int numberOfSeries = seriesScores.Length;

        bool matches = numberOfSeries == NumberOfSeries &&
                       matchWon == MatchWon &&
                       TeamScore !.Invoke(teamScore, opponentScore, seriesScores) &&
                       OpponentScore !.Invoke(teamScore, opponentScore);

        return(matches);
    }
Exemple #28
0
        public async Task Route_matching_match_with_not_played_result_returns_404(MatchResultType matchResultType)
        {
            var matchDataSource = new Mock <IMatchDataSource>();

            matchDataSource.Setup(x => x.ReadMatchByRoute(It.IsAny <string>())).ReturnsAsync(new Stoolball.Matches.Match
            {
                StartTime       = DateTime.UtcNow.AddHours(1),
                MatchResultType = matchResultType,
                Season          = new Season()
            });

            using (var controller = new TestController(matchDataSource.Object, new Uri("https://example.org/matches/example-match"), UmbracoHelper))
            {
                var result = await controller.Index(new ContentModel(Mock.Of <IPublishedContent>())).ConfigureAwait(false);

                Assert.IsType <HttpNotFoundResult>(result);
            }
        }
Exemple #29
0
        public override MatchResult Matches(FileInfo file, Dictionary <Type, IFileCache> fileCaches, CancellationToken token)
        {
            int             lineCount  = 0;
            MatchResultType resultType = MatchResultType.NotApplicable;

            try
            {
                using (StreamReader reader = new StreamReader(file.FullName))
                {
                    lineCount = TextUtil.GetLineCount(reader, token);
                }
                resultType = CompareUtil.Compare(lineCount, m_Parameters.ComparisonType, m_Parameters.Count);
            }
            catch (Exception ex)
            {
            }
            return(new MatchResult(resultType, lineCount.ToString()));
        }
Exemple #30
0
        public override ProcessingResult Process(FileInfo file,
                                                 MatchResultType matchResultType, string[] values,
                                                 FileInfo[] generatedFiles, ProcessInput whatToProcess,
                                                 CancellationToken token)
        {
            ProcessorScope  scope             = m_Parameters.OneZipFilePer;
            bool            perInput          = scope == ProcessorScope.InputFile;
            bool            perPreviousOutput = scope == ProcessorScope.GeneratedOutputFile;
            bool            scopedToMethod    = perInput || perPreviousOutput;
            List <FileInfo> outputFiles       = new List <FileInfo>();

            if (scopedToMethod)
            {
                ClearFiles();
            }
            if (whatToProcess == ProcessInput.GeneratedFiles)
            {
                if (perPreviousOutput)
                {
                    foreach (FileInfo previousFile in generatedFiles)
                    {
                        ClearFiles();
                        AddFile(previousFile);
                        outputFiles.Add(GenerateZip(previousFile, token));
                    }
                }
                else
                {
                    foreach (FileInfo f in generatedFiles)
                    {
                        AddFile(f);
                    }
                }
            }
            else
            {
                AddFile(file);
            }
            if (perInput)
            {
                outputFiles.Add(GenerateZip(file, token));
            }
            return(new ProcessingResult(ProcessingResultType.Success, "Success", outputFiles.ToArray()));
        }
    public void SetText(MatchResultType matchResultType)
    {
        switch (matchResultType)
        {
        case MatchResultType.Draw:
            MatchResultText.text = LocalizationConstants.DRAW.ToUpper();
            break;

        case MatchResultType.Win:
            MatchResultText.text = LocalizationConstants.WIN.ToUpper();
            break;

        case MatchResultType.Lose:
            MatchResultText.text = LocalizationConstants.LOSE.ToUpper();
            break;

        default:
            break;
        }
    }
Exemple #32
0
        public override MatchResult Matches(FileInfo file, Dictionary <Type, IFileCache> fileCaches, CancellationToken token)
        {
            BitmapFileCache cache = fileCaches[typeof(BitmapFileCache)] as BitmapFileCache;

            if (cache == null || !cache.IsBitmap)
            {
                return(new MatchResult(MatchResultType.NotApplicable, "N/A"));
            }
            Bitmap           bitmap   = cache.Bitmap;
            PositiveFraction val      = new PositiveFraction((uint)bitmap.Width, (uint)bitmap.Height);
            PositiveFraction paramVal = new PositiveFraction(m_Parameters.Width, m_Parameters.Height);

            if (paramVal.Denominator == 0)
            {
                return(new MatchResult(MatchResultType.NotApplicable, "N/A"));
            }
            MatchResultType resultType = CompareUtil.Compare(val, m_Parameters.ComparisonType, paramVal);

            return(new MatchResult(resultType, val.ToString()));
        }
Exemple #33
0
        public override MatchResult Matches(FileInfo file, Dictionary <Type, IFileCache> fileCaches, CancellationToken token)
        {
            List <string>   values = new List <string>();
            MatchResultType type   = MatchResultType.Yes;

            foreach (ICondition c in Conditions)
            {
                token.ThrowIfCancellationRequested();
                MatchResult result = c.Matches(file, fileCaches, token);
                if (result.Values != null)
                {
                    values.AddRange(result.Values);
                }
                if (result.Type != MatchResultType.Yes)
                {
                    type = MatchResultType.No;
                    // DO NOT short-circuit.  We need all conditions to be evaluated for their ouptut values.
                }
            }
            return(new MatchResult(type, values.ToArray()));
        }
Exemple #34
0
 public MatchResult(MatchResultType type, bool caseSensitive, int? camelCaseWeight)
 {
     this.ResultType = type;
     this.CaseSensitive = caseSensitive;
     this.CamelCaseWeight = camelCaseWeight;
 }