示例#1
0
        private static Dictionary <ResourcePivotKey[], IDictionary <string, IDictionary <string, string> > > GetUsedGroupedResources(Dictionary <ResourcePivotKey[], IDictionary <string, IDictionary <string, string> > > groupedAndUsedResources, string content, string resourcePivotGroupKey, IDictionary <string, IDictionary <string, string> > resourcePivotKeyValues)
        {
            if (resourcePivotKeyValues == null || !resourcePivotKeyValues.Any())
            {
                return(groupedAndUsedResources);
            }

            var newGroupedAndUsedResources = new Dictionary <ResourcePivotKey[], IDictionary <string, IDictionary <string, string> > >();
            var groupedResources           = ResourcesResolver.GetGroupedUsedResourceKeys(content, resourcePivotKeyValues);

            foreach (var groupedResource in groupedResources)
            {
                foreach (var groupedAndUsedResource in groupedAndUsedResources)
                {
                    var resourcePivotKeys = groupedResource.Item1.Select(key => new ResourcePivotKey(resourcePivotGroupKey, key));
                    var newResourcePivots = groupedAndUsedResource.Key.Concat(resourcePivotKeys).ToArray();

                    var resourceDictionaries = new Dictionary <string, IDictionary <string, string> >(StringComparer.OrdinalIgnoreCase);
                    resourceDictionaries.AddRange(groupedAndUsedResource.Value);
                    resourceDictionaries.Add(resourcePivotGroupKey, groupedResource.Item2);

                    newGroupedAndUsedResources.Add(newResourcePivots, resourceDictionaries);
                }
            }

            return(newGroupedAndUsedResources);
        }
示例#2
0
        /// <summary>The get merged resources.</summary>
        /// <returns>The merged resources.</returns>
        internal IDictionary <string, IDictionary <string, string> > GetMergedResources()
        {
            if (!this.HasSomethingToResolve())
            {
                return(EmptyResult);
            }

            return(this.context.SectionedAction(SectionIdParts.ResourcesResolutionActivity, this.FileType.ToString(), this.ResourceGroupKey).Execute(() =>
            {
                try
                {
                    var resourcesResolver = ResourcesResolver.Factory(this.context, this.SourceDirectory, this.ResourceGroupKey, this.ApplicationDirectoryName, this.SiteDirectoryName, this.ResourceKeys, this.DestinationDirectory);
                    return resourcesResolver.GetMergedResources();
                }
                catch (ResourceOverrideException resourceOverrideException)
                {
                    // There was a token override in folder path that does not
                    // allow token overriding. For this case, we need to
                    // show a build error.
                    var errorMessage = string.Format(CultureInfo.InvariantCulture, "ResourcesResolutionActivity - {0} has more than one value assigned. Only one value per key name is allowed in libraries and features. Resource key overrides are allowed at the product level only.", resourceOverrideException.TokenKey);
                    throw new WorkflowException(errorMessage, resourceOverrideException);
                }
                catch (Exception exception)
                {
                    throw new WorkflowException("ResourcesResolutionActivity - Error happened while executing the resolve resources activity", exception);
                }
            }));
        }
示例#3
0
        /// <summary>Applies the resojurce keys to the content item.</summary>
        /// <param name="inputItem">The input item.</param>
        /// <param name="mergedResoures">The merged resoures.</param>
        /// <returns>The list of merged/applied content items..</returns>
        internal static IEnumerable <ContentItem> ApplyResourceKeys(
            ContentItem inputItem,
            Dictionary <string, IDictionary <string, IDictionary <string, string> > > mergedResoures)
        {
            if (mergedResoures == null || !mergedResoures.Any())
            {
                return(new[] { inputItem });
            }

            var contentItems = new List <ContentItem>();

            try
            {
                var originalContent         = inputItem.Content;
                var usedAndGroupedResources = GetUsedGroupedResources(originalContent, mergedResoures);
                foreach (var usedAndGroupedResource in usedAndGroupedResources)
                {
                    var resourcedContent = originalContent;
                    foreach (var resources in usedAndGroupedResource.Value)
                    {
                        resourcedContent = ResourcesResolver.ExpandResourceKeys(resourcedContent, resources.Value);
                    }

                    contentItems.Add(ContentItem.FromContent(resourcedContent, inputItem, usedAndGroupedResource.Key));
                }
            }
            catch (ResourceOverrideException resourceOverrideException)
            {
                // There was a resource override in folder path that does not
                // allow resource overriding. For this case, we need to
                // show a build error.
                var errorMessage = string.Format(CultureInfo.CurrentUICulture, ResourceStrings.ResourcePivotActivityDuplicateKeysError, resourceOverrideException.TokenKey);
                throw new WorkflowException(errorMessage, resourceOverrideException);
            }
            catch (Exception exception)
            {
                throw new WorkflowException(ResourceStrings.ResourcePivotActivityError, exception);
            }

            return(contentItems);
        }