internal override void ExecuteInternal()

in code/src/CoreTemplateStudio/CoreTemplateStudio.Core/PostActions/Catalog/Merge/MergeResourceDictionaryPostAction.cs [28:93]


        internal override void ExecuteInternal()
        {
            string originalFilePath = Regex.Replace(Config.FilePath, MergeConfiguration.PostactionRegex, ".");
            if (!File.Exists(originalFilePath))
            {
                // If original file does not exist, rename the postaction file, add it to projectitems and app.xamls mergedictionary
                File.Copy(Config.FilePath, originalFilePath);
                GenContext.Current.ProjectInfo.ProjectItems.Add(originalFilePath.GetDestinationPath());
                AddToAppMergeDictionary(originalFilePath);
            }
            else
            {
                var mergeRoot = XElement.Load(Config.FilePath);
                var sourceRoot = XElement.Load(originalFilePath);

                var originalEncoding = GetEncoding(originalFilePath);

                // Only check encoding on new project, might have changed on right click
                if (GenContext.Current.GenerationOutputPath == GenContext.Current.DestinationPath)
                {
                    var otherEncoding = GetEncoding(Config.FilePath);

                    if (originalEncoding.EncodingName != otherEncoding.EncodingName
                        || !Enumerable.SequenceEqual(originalEncoding.GetPreamble(), otherEncoding.GetPreamble()))
                    {
                        HandleMismatchedEncodings(originalFilePath, Config.FilePath, originalEncoding, otherEncoding);
                        return;
                    }
                }

                foreach (var node in GetNodesToMerge(mergeRoot))
                {
                    var sourceNode = sourceRoot.Elements().FirstOrDefault(e => GetKey(e) == GetKey(node));
                    if (sourceNode == null)
                    {
                        AddNode(sourceRoot, node);
                    }
                    else
                    {
                        if (!XNode.DeepEquals(node, sourceNode))
                        {
                            var errorMessage = string.Format(StringRes.FailedMergePostActionKeyAlreadyDefined, GetKey(node), RelatedTemplate);
                            if (Config.FailOnError)
                            {
                                throw new InvalidDataException(errorMessage);
                            }
                            else
                            {
                                var relativeFilePath = originalFilePath.GetPathRelativeToGenerationParentPath();
                                HandleFailedMergePostActions(relativeFilePath, MergeFailureType.KeyAlreadyDefined, MergeConfiguration.Suffix, errorMessage);
                                return;
                            }
                        }
                    }
                }

                using (TextWriter writeFile = new StreamWriter(originalFilePath, false, originalEncoding))
                {
                    var writer = new ResourceDictionaryWriter(writeFile);
                    writer.WriteResourceDictionary(sourceRoot);
                    writer.Flush();
                }
            }

            File.Delete(Config.FilePath);
        }