Inheritance: ITask
        private async ThreadingTask InstallFromStream(Task <Stream> getStream, PackageIdentity package,
                                                      string packagesFolder, CancellationToken token)
        {
            bool isValid = true;

            if (OfflineFeedUtility.PackageExists(package, packagesFolder, out isValid))
            {
                return;
            }

            var logger = new NugetMsBuildLogger(new TaskLoggingHelper(this));

            var versionFolderPathContext = new VersionFolderPathContext(
                package,
                packagesFolder,
                isLowercasePackagesDirectory: false,
                logger: logger,
                packageSaveMode: PackageSaveMode.Defaultv3,
                xmlDocFileSaveMode: XmlDocFileSaveMode.None);

            await PackageExtractor.InstallFromSourceAsync(
                async dest =>
            {
                var source = await getStream;
                await source.CopyToAsync(dest, bufferSize: DefaultBufferSize, cancellationToken: token);
            },
                versionFolderPathContext,
                token);
        }
        private static IEnumerable<PropertyInfo> GetInputProperties(Task task)
        {
            var propertyInfos = from propertyInfo in task.GetType().GetProperties()
                                where propertyInfo.HasAttribute<RequiredAttribute>()
                                select propertyInfo;

            return propertyInfos;
        }
 private static void LogItemMetadata(Task task, ITaskItem item, MessageImportance importance)
 {
     var metadata = item.CloneCustomMetadata();
     foreach (var name in metadata.Keys.Cast<string>())
     {
         LogMetadata(task, name, (string)metadata[name], importance);
     }
 }
        private static void LogTaskItems(ITaskItem[] taskItems, string itemGroup, MessageImportance importance, Task task)
        {
            task.Log.LogMessage(importance, "  {0} =", itemGroup);

            foreach (var item in taskItems)
            {
                LogTaskItem(task, item, importance);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initialies a new instance of this class.
        /// </summary>
        /// <param name="task">The task which is hosting this bundler.</param>
        /// <param name="options">The options for the bundler.</param>
        public MSBuildBundler(Task task, BundlerOptions options = null)
            : base(options)
        {
            if (task == null)
            {
                throw new System.ArgumentNullException("task");
            }

            Task = task;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Logs the specified message.
        /// </summary>
        /// <param name="task">
        /// A task to provide actual logger.
        /// </param>
        /// <param name="message">
        /// Message.
        /// </param>
        /// <param name="messageImportance">
        /// Message importance.
        /// </param>
        public void Log(Task task, string message, MessageImportance messageImportance)
        {
            if (task == null)
                throw new ArgumentNullException("task");

            if (message == null)
                throw new ArgumentNullException("message");

            task.Log.LogMessageFromText(message, messageImportance);
        }
 public SchemaManagerModule(Task owner, 
     string pathToSchemaScripts,
     string pathToAlwaysRunScripts,
     string connectionString,
     SchemaManagerGlobalOptions globalOptions)
 {
     _owner = owner;
     _pathToSchemaScripts = pathToSchemaScripts;
     _connectionString = connectionString;
     _pathToAlwaysRunScripts = pathToAlwaysRunScripts;
     _globalOptions = globalOptions;
 }
 private static void LogProperty(PropertyInfo propertyInfo, MessageImportance importance, Task task)
 {
     string name = propertyInfo.Name;
     var value = propertyInfo.GetValue(task);
     if (value is ITaskItem[])
     {
         LogTaskItems(value as ITaskItem[], name, importance, task);
     }
     else
     {
         task.Log.LogMessage(importance, "  {0} = {1}", name, value);
     }
 }
Exemplo n.º 9
0
 public static void LogError(this Microsoft.Build.Utilities.Task task, string message, params object[] messageParams)
 {
     // If BuildEngine is null, we're not running in an MSBuild context,
     // so we'll output to the console in that case.
     // Otherwise, we'll use the Log object.
     if (task.BuildEngine == null)
     {
         Console.WriteLine(string.Format(message, messageParams));
     }
     else
     {
         task.Log.LogError(message, messageParams);
     }
 }
        internal bool LogTaskMessages(Task task)
        {
            foreach (OutputMessage message in this.list)
            {
                switch (message.Type)
                {
                    case OutputMessageType.Warning:
                        task.Log.LogWarningWithCodeFromResources(message.Name, message.GetArguments());
                        break;

                    case OutputMessageType.Error:
                        task.Log.LogErrorWithCodeFromResources(message.Name, message.GetArguments());
                        break;
                }
            }
            return (this.errorCount <= 0);
        }
Exemplo n.º 11
0
        public static Action <TraceLevel, string> CreateTaskLogger(this Task task)
        {
            void logger(TraceLevel level, string value)
            {
                switch (level)
                {
                case TraceLevel.Error:
                    task.Log.LogError("{0}", value);
                    break;

                case TraceLevel.Warning:
                    task.Log.LogWarning("{0}", value);
                    break;

                default:
                    task.Log.LogDebugMessage("{0}", value);
                    break;
                }
            }

            return(logger);
        }
Exemplo n.º 12
0
 public static void MyDeleteFolder(Task buildTask, string folderName, DeleteDirectoryOption OnDirectoryNotEmpty, bool failOnError, string logText)
 {
     var myComputer = new Computer();
     if (Directory.Exists(folderName))
     {
         if (Strings.Len(logText) > 0)
         {
             MyLogMessage(buildTask, string.Format(logText, folderName), MessageImportance.Normal);
         }
         try
         {
             myComputer.FileSystem.DeleteDirectory(folderName, OnDirectoryNotEmpty);
         }
         catch (UnauthorizedAccessException exception1)
         {
             ProjectData.SetProjectError(exception1);
             UnauthorizedAccessException exception = exception1;
             if (OnDirectoryNotEmpty == DeleteDirectoryOption.DeleteAllContents)
             {
                 foreach (string str in Directory.GetFiles(folderName, "*.*", System.IO.SearchOption.AllDirectories))
                 {
                     MyDeleteFile(str, true);
                 }
                 MyDeleteFolder(buildTask, folderName, DeleteDirectoryOption.ThrowIfDirectoryNonEmpty, failOnError, logText);
             }
             ProjectData.ClearProjectError();
         }
         catch (IOException exception4)
         {
             ProjectData.SetProjectError(exception4);
             IOException exception2 = exception4;
             if ((Strings.InStr(exception2.Message, "is not empty", CompareMethod.Binary) > 0) && (OnDirectoryNotEmpty == DeleteDirectoryOption.DeleteAllContents))
             {
                 foreach (string str2 in Directory.GetDirectories(folderName, "*", System.IO.SearchOption.TopDirectoryOnly))
                 {
                     MyDeleteFolder(buildTask, str2, DeleteDirectoryOption.ThrowIfDirectoryNonEmpty, failOnError, logText);
                 }
             }
             else
             {
                 if (failOnError)
                 {
                     throw;
                 }
                 MyLogWarning(buildTask, string.Format("Deleting folder '{0}' failed with exception '{1}'. The exception type was '{2}'. This may result in a later build error.", folderName, exception2.Message, exception2.GetType().Name));
             }
             ProjectData.ClearProjectError();
         }
         catch (Exception exception5)
         {
             ProjectData.SetProjectError(exception5);
             Exception exception3 = exception5;
             if (failOnError)
             {
                 throw;
             }
             MyLogWarning(buildTask, string.Format("Deleting folder '{0}' failed with exception '{1}'. The exception type was '{2}'. This may result in a later build error.", folderName, exception3.Message, exception3.GetType().Name));
             ProjectData.ClearProjectError();
         }
     }
 }
Exemplo n.º 13
0
 public static void MyLogMessage(Task myTask, string message, MessageImportance Importance = MessageImportance.Normal)
 {
     if (Strings.Len(message) > 0)
     {
         if (IsRunFromMSBuild(myTask))
         {
             myTask.Log.LogMessage(Importance, message, null);
         }
         else
         {
             Trace.WriteLine(message, "Information");
             EventHandler<AutomationLogEventArgs> automationLogEventEvent = AutomationLogEvent;
             if (automationLogEventEvent != null)
             {
                 automationLogEventEvent(myTask, new AutomationLogEventArgs(message, MessageType.Information));
             }
         }
     }
 }
 public static bool IsUpToDate(Task hostTask, UpToDateCheckType upToDateCheckType, ITaskItem[] readTLogNames, ITaskItem[] writeTLogNames)
 {
     FlatTrackingData inputs = new FlatTrackingData(hostTask, readTLogNames, DateTime.MaxValue);
     FlatTrackingData outputs = new FlatTrackingData(hostTask, writeTLogNames, DateTime.MinValue);
     bool flag = IsUpToDate(hostTask.Log, upToDateCheckType, inputs, outputs);
     if (!flag)
     {
         inputs.DependencyTable.Clear();
         inputs.SaveTlog();
         outputs.DependencyTable.Clear();
         outputs.SaveTlog();
     }
     return flag;
 }
Exemplo n.º 15
0
 public TaskReporter(Task task) {
     this.task = task;
 }
Exemplo n.º 16
0
 public static void MyLogError(Task myTask, string message)
 {
     if (Strings.Len(message) > 0)
     {
         if (!IsRunFromMSBuild(myTask))
         {
             throw new AutomationException(message);
         }
         myTask.Log.LogError(message, new object[0]);
     }
 }
Exemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExecutionLogger"/> class.
 /// </summary>
 /// <param name="task">The task.</param>
 public ExecutionLogger(Task task)
 {
     this.task = task;
 }
Exemplo n.º 18
0
        private static void ReturnFiles(string signedStage, Dictionary<string, string> fileDictionary, string buildType, Task callingTask)
        {
            if(!Directory.Exists(signedStage + buildType))
            {   //Empty folders don't get created; such as when there are no client files in the job.
                return;
            }

            string[] files = Directory.GetFiles(signedStage + buildType);

            foreach (string file in files)
            {
                string key = buildType + "\\" + Path.GetFileName(file);

                if (!fileDictionary.ContainsKey(key))
                {
                    callingTask.Log.LogWarning("Extra file found in signed stage directory: {0}", file);
                    continue;
                }
                callingTask.Log.LogMessage("Replacing file {0} with signed file {1}", fileDictionary[key], file);
                try
                {
                    File.Copy( file, fileDictionary[ key ], true );
                }
                catch(Exception ex)
                {
                    callingTask.Log.LogErrorFromException( ex, true, true, file );
                    throw ex;
                }
            }
        }
Exemplo n.º 19
0
        public static bool SignFiles(string [] files, string stageRoot, SignInfo info, Task callingTask)
        {
            m_CallingTask = callingTask;
            m_Info = info;

            bool retVal = true;

            if (!stageRoot.EndsWith("\\"))
            {
                stageRoot += "\\";
            }

            string[] level1 = { "Unsigned\\" };
            string[] level2 = { "Client", "Server" };

            string unsignedStage = stageRoot + level1[0];
            
            // Set up staging area
            if (Directory.Exists(stageRoot))
                Directory.Delete(stageRoot, true);

            Directory.CreateDirectory(stageRoot);

            foreach (string level in level1)
            {
                string parent = stageRoot + level;

                if (!Directory.Exists(parent))
                {
                    Directory.CreateDirectory(parent);
                }

                foreach (string nextLevel in level2)
                {
                    string child = parent + nextLevel;

                    if (!Directory.Exists(child))
                    {
                        Directory.CreateDirectory(child);
                    }
                }
            }

            Dictionary<string, string> fileDictionary = new Dictionary<string, string>();

            foreach (string file in files)
            {
                if (!File.Exists(file))
                {
                    callingTask.Log.LogWarning("File not found: {0}", file);
                    continue;
                }

                if ((File.GetAttributes(file) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                {
                    callingTask.Log.LogMessage("File \"{0}\" is read only and will not be signed.", file);
                    continue;
                }

                string directory = Path.GetDirectoryName(file).ToLower();
                bool client = directory.Contains("\\client\\");

                string key = (client ? "Client\\" : "Server\\") + Path.GetFileName(file);
                if (!fileDictionary.ContainsKey(key))
                {
                    fileDictionary.Add(key, file);
                    File.Copy(file, unsignedStage + (client ? "Client\\" : "Server\\") + Path.GetFileName(file), true);
                }
            }


            string signedStage = stageRoot + "Signed\\";
            retVal = SubmitJob(unsignedStage, signedStage);

            ReturnFiles(signedStage, fileDictionary, "Client", callingTask);
            ReturnFiles(signedStage, fileDictionary, "Server", callingTask);

            Directory.Delete(unsignedStage, true);
            
            return retVal;
        }
Exemplo n.º 20
0
 public LogProxy(Task parent)
 {
     _parent = parent;
 }
Exemplo n.º 21
0
 private static void MyCopyAllFilesWithRoboCopy(Task buildTask, RobocopyWrapper myWrapper, string sourceFolder, string targetFolder, string wildCards, bool onlyReplaceWithNewerFile, bool continueOnError, string versionToCopy)
 {
     myWrapper.SourceFolder = sourceFolder;
     myWrapper.TargetFolder = targetFolder;
     myWrapper.FilesToInclude.Add(wildCards);
     myWrapper.UseRestartMode = false;
     myWrapper.CopyNewerFilesOnly = onlyReplaceWithNewerFile;
     if (Strings.Len(versionToCopy) > 0)
     {
         myWrapper.LogFileName = string.Format("FileDeploymentRobocopyLog_{0}.txt", versionToCopy);
     }
     else
     {
         myWrapper.LogFileName = "FileDeploymentRobocopyLog.txt";
     }
     myWrapper.AppendToExistingLogFile = true;
     try
     {
         RoboCopyExitCodes codes = myWrapper.Execute();
         switch (codes)
         {
             case RoboCopyExitCodes.SeveralFilesFailedtoCopy:
             case RoboCopyExitCodes.SevereErrorNoFilesCopied:
                 if (!continueOnError)
                 {
                     throw new AutomationException(string.Format("RoboCopy returned an error code which indicates that some or all files may not have copied successfully: {0}", codes.ToString()));
                 }
                 MyLogWarning(buildTask, string.Format("RoboCopy returned an error code which indicates that some or all files may not have copied successfully: {0}", codes.ToString()));
                 break;
         }
     }
     catch (Exception exception1)
     {
         ProjectData.SetProjectError(exception1);
         Exception exception = exception1;
         if (continueOnError)
         {
             MyLogWarning(buildTask, string.Format("Unexpected exception occurred while using RoboCopy. The continueOnError flag as set to true and the exception will be logged as a warning: {0}", exception.Message));
         }
         ProjectData.ClearProjectError();
     }
 }
Exemplo n.º 22
0
 public static void MyLogWarning(Task myTask, string message)
 {
     if (IsRunFromMSBuild(myTask))
     {
         myTask.Log.LogWarning(message, null);
     }
     else
     {
         Trace.WriteLine(message, "Warning");
         EventHandler<AutomationLogEventArgs> automationLogEventEvent = AutomationLogEvent;
         if (automationLogEventEvent != null)
         {
             automationLogEventEvent(myTask, new AutomationLogEventArgs(message, MessageType.Warning));
         }
     }
 }
Exemplo n.º 23
0
 public static void MyDeleteFolder(Task buildTask, string folderName, DeleteDirectoryOption OnDirectoryNotEmpty, bool failOnError)
 {
     MyDeleteFolder(buildTask, folderName, OnDirectoryNotEmpty, failOnError, "About to delete folder '{0}'");
 }
 private static void LogMetadata(Task task, string metadataName, string value, MessageImportance importance)
 {
     task.Log.LogMessage(importance, "      {0}={1}", metadataName, value);
 }
        private ProjectInfo ExecuteAndCheckSucceeds(Task task, string testFolder)
        {
            string expectedOutputFile = Path.Combine(testFolder, ExpectedProjectInfoFileName);
            Assert.IsFalse(File.Exists(expectedOutputFile), "Test error: output file should not exist before the task is executed");

            bool result = task.Execute();

            Assert.IsTrue(result, "Expecting the task execution to succeed");
            Assert.IsTrue(File.Exists(expectedOutputFile), "Expected output file was not created by the task. Expected: {0}", expectedOutputFile);
            this.TestContext.AddResultFile(expectedOutputFile);

            ProjectInfo reloadedProjectInfo = ProjectInfo.Load(expectedOutputFile);
            Assert.IsNotNull(reloadedProjectInfo, "Not expecting the reloaded project info file to be null");
            return reloadedProjectInfo;
        }
 private static void LogTaskItem(Task task, ITaskItem item, MessageImportance importance)
 {
     task.Log.LogMessage(importance, "    {0}", item.ItemSpec);
     LogItemMetadata(task, item, importance);
 }
Exemplo n.º 27
0
 public MsbuildDfltLogger(Task t)
 {
     _task = t;
 }
Exemplo n.º 28
0
        public static bool IsUpToDate(Task hostTask, UpToDateCheckType upToDateCheckType, ITaskItem[] readTLogNames, ITaskItem[] writeTLogNames)
        {
            bool isUpToDate;
            // Read the input graph (missing inputs are infinitely new - i.e. outputs are out of date)
            FlatTrackingData inputs = new FlatTrackingData(hostTask, readTLogNames, DateTime.MaxValue);

            // Read the output graph (missing outputs are infinitely old - i.e. outputs are out of date)
            FlatTrackingData outputs = new FlatTrackingData(hostTask, writeTLogNames, DateTime.MinValue);

            // Find out if we are up to date
            isUpToDate = IsUpToDate(hostTask.Log, upToDateCheckType, inputs, outputs);

            // We're going to execute, so clear out the tlogs so
            // the new execution will correctly populate the tlogs a-new
            if (!isUpToDate)
            {
                // Remove all from inputs tlog
                inputs.DependencyTable.Clear();
                inputs.SaveTlog();

                // Remove all from outputs tlog
                outputs.DependencyTable.Clear();
                outputs.SaveTlog();
            }
            return isUpToDate;
        }
Exemplo n.º 29
0
        public override bool Execute()
        {
            SqlConnection conn = null;
              //Debugger.Launch();
              try {
            //check that we have the necessary info
            Validate();
            SqlDataReader dr = null;
            StringBuilder sb = new StringBuilder();
            int x = 0;
            t = this;
            conn = new SqlConnection(ConnectionString);
            conn.Open();
            SqlCommand cmd = new SqlCommand(CmdText);
            cmd.Connection = conn;
            Utility.LogMyComment(this, "About to execute statement: '" + cmdText + "'");

            if (CmdText.ToUpper().Contains("SELECT")) {
              dr = cmd.ExecuteReader();
            }
            else {
              x = cmd.ExecuteNonQuery();
            }
            Utility.LogMyComment(this, "Succeeded executing statement!");
            if (dr != null) {
              for (int i = 0; i < dr.FieldCount; i++) {
            string colName = dr.GetName(i);
            if (colName == string.Empty || colName == null)
              colName = "No Name";
            sb.Append(colName);
            if (i < dr.FieldCount - 1)
              sb.Append("\t");
            else if (i == dr.FieldCount - 1)
              sb.Append("\n");
              }
              string u = "";
              for (int i = 0; i < dr.FieldCount; i++) {
            string colName = dr.GetName(i);
            if(colName == string.Empty || colName == null)
              colName = "No Name";
            sb.Append(u.PadRight(colName.Length, '.'));
            if (i < dr.FieldCount - 1)
              sb.Append("\t");
            else if (i == dr.FieldCount - 1)
              sb.Append("\n");
              }
              while (dr.Read()) {
            for (int i = 0; i < dr.FieldCount; i++) {
              sb.Append(dr[i].ToString());
              if (i < dr.FieldCount - 1)
                sb.Append(",");

             }
             sb.Append("\n");
              }
              Utility.LogMyComment(this, sb.ToString());

            }
            else if(dr==null && !CmdText.ToUpper().Contains("SELECT"))
              Utility.LogMyComment(this, x.ToString());

            return true;
              }
              catch (Exception e) {
            Utility.LogMyComment(this, "Error(s) Occured");
            Utility.LogMyComment(this, "Could not execute statement.");
            Utility.LogMyErrorFromException(this, e);
            return false;

              }
              finally {
            if (conn != null && conn.State != ConnectionState.Closed)
            conn.Close();

              }
        }
Exemplo n.º 30
0
 public TaskLogger(Task task)
 {
     this.task = task;
 }
Exemplo n.º 31
0
 public TaskLogger(Microsoft.Build.Utilities.Task task)
 {
     this.task = task;
 }
Exemplo n.º 32
0
		public TaskLogger(Task task)
		{
			_task = task;
		}
Exemplo n.º 33
0
 public MsbuildDfltLogger(Task t)
 {
     _task = t;
 }
Exemplo n.º 34
0
 public MSBuildTaskLogger(Task task)
 {
     if (task == null) throw new ArgumentNullException("task");
       _log = task.Log;
 }
Exemplo n.º 35
0
 public static void MyLogException(Task myTask, Exception exception, bool showStackTrace = true)
 {
     if (IsRunFromMSBuild(myTask))
     {
         myTask.Log.LogErrorFromException(exception, showStackTrace);
     }
     else
     {
         Trace.WriteLine(exception.Message, "Error");
         throw exception;
     }
 }