示例#1
0
        public async Task <IFileSource> GetFileAsync(VersionSpec version)
        {
            BuildServices();
            var container = Client.GetContainerReference(ContainerName);
            await container.PrepContainer();

            var path  = BuildPath(version);
            var blobs = await container.ListBlobsAsync();

            if (MatchStrategy == null)
            {
                var blob = blobs
                           .OfType <CloudBlockBlob>()
                           .FirstOrDefault(
                    b => PatternMatcher.Match(b.Name, version)
                    );
                if (blob == null)
                {
                    throw new VersionNotFoundException($"No matches found from {blobs.Count} files using {PatternMatcher?.Name} matching!");
                }
                return(blob.ToSource(version));
            }
            var match = await MatchStrategy.MatchAsync(blobs, version);

            return(match);
        }
示例#2
0
        public async Task <IFileSource> GetFileAsync(VersionSpec version)
        {
            var blobs = new List <S3Object>();

            using (var client = BuildClient())
            {
                ListObjectsV2Request request = new ListObjectsV2Request
                {
                    BucketName = BucketName,
                    MaxKeys    = 10
                };
                ListObjectsV2Response response;
                do
                {
                    response = await client.ListObjectsV2Async(request);

                    blobs.AddRange(response.S3Objects);
                    request.ContinuationToken = response.NextContinuationToken;
                } while (response.IsTruncated == true);
            }
            if (MatchStrategy == null)
            {
                var blob = blobs.FirstOrDefault(
                    o => PatternMatcher.Match(o.Key, version)
                    );
                if (blob == null)
                {
                    throw new VersionNotFoundException();
                }
                return(ToSource(version, blob));
            }
            var match = await MatchStrategy.MatchAsync(blobs, version);

            return(match);
        }
示例#3
0
        public async Task <IFileSource> GetFileAsync(VersionSpec version)
        {
            if (Credentials == null)
            {
                _logger.LogCritical("Repo details not found! Please add GitHubStorage to your app configuration and restart the server.");
                throw new UnauthorizedAccessException("Repository details not found in configuration!");
            }
            try
            {
                var releases = await Client.Repository.Release.GetAll(Credentials.Owner, Credentials.Repo);

                if (MatchStrategy == null)
                {
                    foreach (var release in releases)
                    {
                        var asset = release.Assets.FirstOrDefault(a => PatternMatcher.Match(a.Name, version));
                        if (asset != null)
                        {
                            var source = new GitHubFileSource(version, !release.Draft);
                            source.Build(asset);
                            return(source);
                        }
                    }
                    throw new VersionNotFoundException();
                }
                return(await MatchStrategy.MatchAsync(releases, version));
            }
            catch (RateLimitExceededException)
            {
                throw new VersionNotFoundException("GitHub API rate limit exceeded! Unable to fetch releases. Please add an API token to the `GitHubStorage/ApiToken` configuration key.");
            }
        }
示例#4
0
文件: Region.cs 项目: nunb/code
        public override int GetHashCode()
        {
            int result = 17;

            result = 31 * result + Bitmap.GetHashCode();
            result = 31 * result + MatchStrategy.GetHashCode();

            return(result);
        }
示例#5
0
        private Expression <Func <Question, bool> > BuildWhereExpression()
        {
            List <Expression <Func <Question, bool> > > criterias = new List <Expression <Func <Question, bool> > >();

            if (QuestionNo.HasValue)
            {
                Expression <Func <Question, bool> > questionNoCriteria = (subject) => subject.QuestionNo == QuestionNo;
                criterias.Add(questionNoCriteria);
            }

            if (!string.IsNullOrEmpty(QuestionText))
            {
                Expression <Func <Question, bool> > questionTextCriteria = (subject) => subject.QuestionText.Contains(QuestionText);
                criterias.Add(questionTextCriteria);
            }

            if (SelectedCategory != null)
            {
                Expression <Func <Question, bool> > categoryCriteria = (subject) => subject.QuestionCategoryId.Equals(SelectedCategory.Id);
                criterias.Add(categoryCriteria);
            }

            if (Frequency != Frequency.Undefined)
            {
                Expression <Func <Question, bool> > frequencyCriteria = (subject) => subject.Frequency == Frequency;
                criterias.Add(frequencyCriteria);
            }

            if (!Notification.Equals("Any", StringComparison.InvariantCultureIgnoreCase))
            {
                Expression <Func <Question, bool> > notificationCriteria = (subject) =>
                                                                           Notification.Equals("Yes", StringComparison.InvariantCultureIgnoreCase) ? subject.Notification : !subject.Notification;
                criterias.Add(notificationCriteria);
            }

            if (!Compliance.Equals("Any", StringComparison.InvariantCultureIgnoreCase))
            {
                Expression <Func <Question, bool> > complianceCriteria = (subject) =>
                                                                         Compliance.Equals("Yes", StringComparison.InvariantCultureIgnoreCase) ? subject.Compliance : !subject.Compliance;
                criterias.Add(complianceCriteria);
            }

            if (SelectedSettings != QuestionSettings.None)
            {
                Expression <Func <Question, bool> > settingsCriteria = (subject) =>
                                                                       subject.Flags == (subject.Flags | this.SelectedSettings);
                criterias.Add(settingsCriteria);
            }

            return(MatchStrategy.Equals("All", StringComparison.InvariantCultureIgnoreCase)
                ? criterias.CombineWithAnd()
                : criterias.CombineWithOr());
        }
示例#6
0
 /// <inheritdoc/>
 public IDiffingStrategyCollection AddMatcher(MatchStrategy <SourceCollection, Comparison> matchStrategy, StrategyType strategyType)
 {
     if (strategyType == StrategyType.Specialized)
     {
         _nodeMatchers.Insert(0, matchStrategy);
     }
     else
     {
         _nodeMatchers.Add(matchStrategy);
     }
     return(this);
 }
示例#7
0
        public void Strategy_PlaysOnePlay <T>(T strategyType) where T : MatchStrategy
        {
            MatchStrategy strategy = Activator.CreateInstance <T>();
            var           board    = GameUtils.BuildBoard(4, 5);

            var availableBoardPlacesBefore = GameUtils.CountAvailableBoardPlaces(board);

            strategy.DoPlay(board, Play.X);
            var availableBoardPlacesAfter = GameUtils.CountAvailableBoardPlaces(board);

            Assert.AreEqual(1, availableBoardPlacesBefore - availableBoardPlacesAfter,
                            "A diferença da quantidade de casas antes e depois nao é 1.");
        }
示例#8
0
        public StringMatcher(MatchStrategy matchStrategy = MatchStrategy.TrieTree, ITokenizer tokenizer = null)
        {
            this.tokenizer = tokenizer ?? new SimpleTokenizer();
            switch (matchStrategy)
            {
            case MatchStrategy.AcAutomaton:
                Matcher = new AcAutomaton <string>();
                break;

            case MatchStrategy.TrieTree:
                Matcher = new TrieTree <string>();
                break;

            default:
                throw new ArgumentException($"Unsupported match strategy: {matchStrategy.ToString()}");
            }
        }