예제 #1
0
        IEnumerable <IApplicationLocation> GetLocationSegmentsFrom(ISegmentMatches match)
        {
            var matchAsDictionary = match.AsDictionary();

            var               segments       = new List <IApplicationLocation>();
            BoundedContext    boundedContext = null;
            Module            module         = null;
            Feature           feature        = null;
            List <SubFeature> subFeatures    = new List <SubFeature>();

            if (matchAsDictionary.ContainsKey(BoundedContextKey))
            {
                boundedContext = new BoundedContext(matchAsDictionary[BoundedContextKey].Single());
                segments.Add(boundedContext);

                if (matchAsDictionary.ContainsKey(ModuleKey))
                {
                    module = new Module(boundedContext, matchAsDictionary[ModuleKey].Single());
                    segments.Add(module);

                    if (matchAsDictionary.ContainsKey(FeatureKey))
                    {
                        feature = new Feature(module, matchAsDictionary[FeatureKey].Single());
                        segments.Add(feature);

                        if (matchAsDictionary.ContainsKey(SubFeatureKey))
                        {
                            foreach (var subFeatureName in matchAsDictionary[SubFeatureKey])
                            {
                                var subFeature = new SubFeature(feature, subFeatureName);
                                segments.Add(subFeature);
                            }
                        }
                    }
                }
            }

            return(segments);
        }
        /// <inheritdoc/>
        public IApplicationResourceIdentifier FromString(string identifierAsString)
        {
            var applicationSeparatorIndex = identifierAsString.IndexOf('#');

            ThrowIfApplicationSeparatorMissing(applicationSeparatorIndex, identifierAsString);

            var applicationResourceSeparatorIndex = identifierAsString.IndexOf('-');

            ThrowIfApplicationResourceMissing(applicationResourceSeparatorIndex, identifierAsString);

            var applicationIdentifier = identifierAsString.Substring(0, applicationSeparatorIndex);

            ThrowIfApplicationMismatches(applicationIdentifier, identifierAsString);

            var applicationResourceTypeSeparatorIndex = identifierAsString.IndexOf('+');

            ThrowIfApplicationResourceTypeMissing(applicationResourceTypeSeparatorIndex, identifierAsString);

            var resourceIdentifier     = identifierAsString.Substring(applicationResourceSeparatorIndex + 1, applicationResourceTypeSeparatorIndex - (applicationResourceSeparatorIndex + 1));
            var locationIdentifiers    = identifierAsString.Substring(applicationSeparatorIndex + 1, applicationResourceSeparatorIndex - (applicationSeparatorIndex + 1));
            var resourceTypeIdentifier = identifierAsString.Substring(applicationResourceTypeSeparatorIndex + 1);

            ThrowIfApplicationLocationsMissing(locationIdentifiers, identifierAsString);

            var locationStrings = locationIdentifiers.Split(ApplicationLocationSeparator).Where(s => s.Length > 0).ToArray();
            var locations       = new List <IApplicationLocation>();

            var boundedContext = new BoundedContext(locationStrings[0]);

            locations.Add(boundedContext);

            if (locationStrings.Length >= 2)
            {
                var module = new Module(boundedContext, locationStrings[1]);
                locations.Add(module);

                if (locationStrings.Length >= 3)
                {
                    var feature = new Feature(module, locationStrings[2]);
                    locations.Add(feature);

                    if (locationStrings.Length >= 4)
                    {
                        var parentFeature       = feature;
                        var locationStringIndex = 3;
                        do
                        {
                            var subFeature = new SubFeature(parentFeature, locationStrings[locationStringIndex]);
                            locations.Add(subFeature);

                            locationStringIndex++;
                        } while (locationStringIndex < locationStrings.Length);
                    }
                }
            }

            var resource = new ApplicationResource(resourceIdentifier, _applicationResourceTypes.GetFor(resourceTypeIdentifier));

            return(new ApplicationResourceIdentifier(
                       _application,
                       locations,
                       resource
                       ));
        }