示例#1
0
        public ProviderCollection(EventManifest manifest)
        {
            this.manifest = manifest ?? throw new ArgumentNullException(nameof(manifest));

            this.UniqueConstraintFor(e => e.Name)
            .WithMessage("Duplicate provider name: '{0}'", e => e.Name)
            .DiagnoseUsing(DiagUtils.ReportError);
            this.UniqueConstraintFor(e => e.Id)
            .WithMessage("Duplicate provider id: '{0:B}'", e => e.Symbol)
            .DiagnoseUsing(DiagUtils.ReportError);
            this.UniqueConstraintFor(e => e.Symbol)
            .WithMessage("Duplicate provider symbol: '{0}'", e => e.Symbol)
            .DiagnoseUsing(DiagUtils.ReportError);
        }
示例#2
0
        public static EventManifest Combine(IEnumerable <EventManifest> manifests)
        {
            var combined = new EventManifest();

            int index     = 0;
            var stringMap = new Dictionary <LocalizedString, LocalizedString>();

            foreach (var manifest in manifests)
            {
                ++index;

                foreach (var provider in manifest.Providers)
                {
                    combined.Providers.Add(provider);
                }

                string manifestPrefix = "manifest" + index;

                foreach (var sourceResourceSet in manifest.Resources)
                {
                    var targetResourceSet = combined.Resources.FirstOrDefault(x => x.Culture == sourceResourceSet.Culture);
                    if (targetResourceSet == null)
                    {
                        targetResourceSet = new LocalizedResourceSet(sourceResourceSet.Culture);
                        combined.AddResourceSet(targetResourceSet);
                    }

                    foreach (var sourceString in sourceResourceSet.Strings)
                    {
                        // Just add the source string if its name is still unused.
                        var existingEntry = targetResourceSet.Strings.GetByName(sourceString.Name);
                        if (existingEntry == null)
                        {
                            targetResourceSet.Strings.Add(sourceString);
                            continue;
                        }

                        // Otherwise, try to find a matching entry to avoid duplicates.
                        var matchingEntry = targetResourceSet.Strings.FirstOrDefault(
                            x => x.Id == sourceString.Id &&
                            Equals(x.Symbol, sourceString.Symbol) &&
                            Equals(x.Value, sourceString.Value));

                        if (matchingEntry == null)
                        {
                            // The name is already used, and no matching entry
                            // exists. Add the string with a different, unique
                            // name to the resource set.
                            string uniqueName = manifestPrefix + "." + sourceString.Name;
                            matchingEntry = new LocalizedString(uniqueName, sourceString.Value)
                            {
                                Location = sourceString.Location
                            };
                            targetResourceSet.Strings.Add(matchingEntry);
                        }

                        stringMap.Add(sourceString, matchingEntry);
                    }
                }
            }

            // Replace any messages which could not be used as-is due to name
            // conflicts.
            foreach (var provider in combined.Providers)
            {
                {
                    if (provider.Message != null && stringMap.TryGetValue(provider.Message, out var replacement))
                    {
                        provider.Message = replacement;
                    }
                }
                foreach (var item in provider.Channels)
                {
                    if (item.Message != null && stringMap.TryGetValue(item.Message, out var replacement))
                    {
                        item.Message = replacement;
                    }
                }
                foreach (var item in provider.Levels)
                {
                    if (item.Message != null && stringMap.TryGetValue(item.Message, out var replacement))
                    {
                        item.Message = replacement;
                    }
                }
                foreach (var item in provider.Opcodes)
                {
                    if (item.Message != null && stringMap.TryGetValue(item.Message, out var replacement))
                    {
                        item.Message = replacement;
                    }
                }
                foreach (var item in provider.Tasks)
                {
                    if (item.Message != null && stringMap.TryGetValue(item.Message, out var replacement))
                    {
                        item.Message = replacement;
                    }
                }
                foreach (var item in provider.Keywords)
                {
                    if (item.Message != null && stringMap.TryGetValue(item.Message, out var replacement))
                    {
                        item.Message = replacement;
                    }
                }
                foreach (var item in provider.Maps.SelectMany(x => x.Items))
                {
                    if (provider.Message != null && stringMap.TryGetValue(item.Message, out var replacement))
                    {
                        item.Message = replacement;
                    }
                }
                foreach (var item in provider.Filters)
                {
                    if (item.Message != null && stringMap.TryGetValue(item.Message, out var replacement))
                    {
                        item.Message = replacement;
                    }
                }
                foreach (var item in provider.Events)
                {
                    if (item.Message != null && stringMap.TryGetValue(item.Message, out var replacement))
                    {
                        item.Message = replacement;
                    }
                }
            }

            return(combined);
        }