예제 #1
0
        /// <summary>
        /// When overridden in a derived class, executes the task.
        /// </summary>
        /// <returns>
        /// true if the task successfully executed; otherwise, false.
        /// </returns>
        public override bool Execute()
        {
            try {
                if (Directory.Exists(IntermediatePath))
                {
                    foreach (var file in new DirectoryInfo(IntermediatePath).GetFiles("*.*", SearchOption.AllDirectories))
                    {
                        file.IsReadOnly = false;
                    }

                    Directory.Delete(IntermediatePath, recursive: true);
                }

                var list  = new List <ITaskItem>();
                var files = ImmutableHashSet.Create <string>(XmlFiles.Select(x => Path.GetFileName(x.ItemSpec)).ToArray());
                foreach (var xmlFile in XmlFiles)
                {
                    var xmlFileInfo = new FileInfo(xmlFile.ItemSpec);
                    var item        = ModifyAndGetNewItem(xmlFileInfo.FullName, xmlFile.GetMetadata("OutputSubPath"), out var newDirectory);
                    list.Add(item);


                    foreach (var extraFile in xmlFileInfo.Directory.GetFiles("*.*", SearchOption.AllDirectories))
                    {
                        if (extraFile.Extension == xmlFileInfo.Extension && files.Contains(extraFile.Name))
                        {
                            ModifyExtraXmlFile(newDirectory, extraFile.FullName);
                        }
                        else
                        {
                            CopyExtraFile(newDirectory, xmlFileInfo.Directory.FullName, extraFile.FullName);
                        }
                    }
                }

                NewXmlFiles = list.ToArray();
            }
            catch (Exception ex) {
                Log.LogErrorFromException(ex);
                return(false);
            }

            Log.LogMessage($"XmlUpdate Wrote: '{Value}'");
            return(true);
        }