Ejemplo n.º 1
0
        public override bool Execute()
        {
            try
            {
                string text = File.ReadAllText(InputFile.GetMetadata("FullPath"));

                foreach (string replacement in Replacements)
                {
                    string[] parts = replacement.Split('=');
                    if (parts.Length != 2)
                    {
                        Log.LogError("Malformed replacement '{0}': Expected exactly one equals sign", replacement);
                        continue;
                    }

                    text = text.Replace(parts[0], parts[1]);
                }

                if (!Log.HasLoggedErrors)
                {
                    File.WriteAllText(OutputFile.GetMetadata("FullPath"), text);
                }
            }
            catch (FileNotFoundException ex)
            {
                Log.LogError("File not found: {0}", ex.FileName);
            }

            return(!Log.HasLoggedErrors);
        }
        /// <summary>
        ///     Execute the task.
        /// </summary>
        /// <returns>
        ///     <c>true</c>, if the task executed succesfully; otherwise, <c>false</c>.
        /// </returns>
        public override bool Execute()
        {
            FileInfo inputFile = new FileInfo(
                InputFile.GetMetadata("FullPath")
                );

            if (!inputFile.Exists)
            {
                Log.LogError($"Input file '{inputFile.FullName}' not found.");

                return(false);
            }

            using (StreamReader reader = inputFile.OpenText())
            {
                Content = reader.ReadToEnd();
            }

            return(true);
        }
        public override bool Execute()
        {
            try
            {
                Dictionary <string, DateTime> dateCache = new Dictionary <string, DateTime>();

                foreach (ITaskItem file in OutputFiles)
                {
                    FileInfo outputInfo = new FileInfo(file.GetMetadata("FullPath"));
                    if (!outputInfo.Exists)
                    {
                        Log.LogMessage(MessageImportance.Normal, $"File {outputInfo.FullName} does not exist");
                        dateCache.Add(outputInfo.FullName, new DateTime(0));
                    }
                    else
                    {
                        dateCache.Add(outputInfo.FullName, outputInfo.LastWriteTimeUtc);
                    }
                }

                var      updated   = new List <ITaskItem>();
                FileInfo inputInfo = new FileInfo(InputFile.GetMetadata("FullPath"));
                if (!dateCache.Values.Any(outputDate => outputDate > inputInfo.LastWriteTimeUtc))
                {
                    Log.LogMessage(MessageImportance.Normal, $"File {inputInfo.FullName} needs to be rebuilt");
                    updated.Add(InputFile);
                }
                else
                {
                    Log.LogMessage(MessageImportance.Normal, $"File {inputInfo.FullName} is up-to-date.");
                }

                UpdatedFiles = updated.ToArray();
            }
            catch (Exception ex)
            {
                Log.LogErrorFromException(ex);
            }

            return(!Log.HasLoggedErrors);
        }
Ejemplo n.º 4
0
        public override bool Execute()
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Log.LogWarning("Skipping task on non-Windows platform");
                return(true);
            }

            string       outputPath     = OutputFile.GetMetadata("FullPath");
            ResourceInfo inputResources = new ResourceInfo();

            inputResources.Load(InputFile.GetMetadata("FullPath"));

            // ResourceInfo.Save() is not implemented, so I must save each resource one at a time.
            foreach (var rsrc in inputResources)
            {
                rsrc.SaveTo(outputPath);
            }

            inputResources.Dispose();
            return(true);
        }