Exemple #1
0
        bool DoExecute()
        {
            var documents = Project.FindDocuments(ComponentFiles, Cancellation);

            if (Cancellation.IsCancellationRequested)
            {
                Log.LogWarning("Cancellation was requested. Aborting task.");
                return(false);
            }

            var generator = new ExportsGenerator(Compilation);
            var exports   = generator.GenerateExports(documents.Select(doc => doc.Value),
                                                      ExcludeInterfaceNamespaces == null ?
                                                      new HashSet <string>() :
                                                      new HashSet <string>(ExcludeInterfaceNamespaces.Select(x => x.ItemSpec)),
                                                      Cancellation);

            if (Cancellation.IsCancellationRequested)
            {
                Log.LogWarning("Cancellation was requested. Aborting task.");
                return(false);
            }

            var outputs = new List <ITaskItem>();

            foreach (var export in exports)
            {
                if (Cancellation.IsCancellationRequested)
                {
                    Log.LogWarning("Cancellation was requested. Aborting task.");
                    return(false);
                }

                var targetDir  = Path.Combine(IntermediateOutputPath, Path.Combine(export.Folders.ToArray()));
                var targetFile = Path.Combine(targetDir, export.Name);
                if (!Directory.Exists(targetDir))
                {
                    Directory.CreateDirectory(targetDir);
                }

                using (var writer = new StreamWriter(targetFile, false))
                {
                    var text = export.GetTextAsync(Cancellation).Result;
                    if (Cancellation.IsCancellationRequested)
                    {
                        Log.LogWarning("Cancellation was requested. Aborting task.");
                        return(false);
                    }

                    text.Write(writer);
                }

                outputs.Add(new TaskItem(targetFile));
            }

            OutputFiles = outputs.ToArray();

            return(true);
        }
Exemple #2
0
		bool DoExecute()
		{
			var documents = Project.FindDocuments(ComponentFiles, Cancellation);
			if (Cancellation.IsCancellationRequested)
			{
				Log.LogWarning("Cancellation was requested. Aborting task.");
				return false;
			}

			var generator = new ExportsGenerator(Compilation);
			var exports = generator.GenerateExports(documents.Select(doc => doc.Value), 
				ExcludeInterfaceNamespaces == null ? 
					new HashSet<string>() : 
					new HashSet<string>(ExcludeInterfaceNamespaces.Select(x => x.ItemSpec)),
				Cancellation);

			if (Cancellation.IsCancellationRequested)
			{
				Log.LogWarning("Cancellation was requested. Aborting task.");
				return false;
			}

			var outputs = new List<ITaskItem>();
			foreach (var export in exports)
			{
				if (Cancellation.IsCancellationRequested)
				{
					Log.LogWarning("Cancellation was requested. Aborting task.");
					return false;
				}

				var targetDir = Path.Combine(IntermediateOutputPath, Path.Combine(export.Folders.ToArray()));
				var targetFile = Path.Combine(targetDir, export.Name);
				if (!Directory.Exists(targetDir))
					Directory.CreateDirectory(targetDir);

				using (var writer = new StreamWriter(targetFile, false))
				{
					var text = export.GetTextAsync(Cancellation).Result;
					if (Cancellation.IsCancellationRequested)
					{
						Log.LogWarning("Cancellation was requested. Aborting task.");
						return false;
					}

					text.Write(writer);
				}

				outputs.Add(new TaskItem(targetFile));
			}

			OutputFiles = outputs.ToArray();

			return true;
		}