예제 #1
0
        private void Log(ILogMessage message, LogLevel level)
        {
            switch (level)
            {
            case LogLevel.Error:
                _log.LogError(message.Message);
                break;

            case LogLevel.Warning:
                _log.LogWarning(message.Message);
                break;

            case LogLevel.Minimal:
                _log.LogMessage(MessageImportance.Low, message.Message);
                break;

            case LogLevel.Information:
                _log.LogMessage(MessageImportance.Normal, message.Message);
                break;

            case LogLevel.Debug:
            case LogLevel.Verbose:
            default:
                _log.LogMessage(MessageImportance.High, message.Message);
                break;
            }

            return;
        }
예제 #2
0
        public void Run(string site, TaskLoggingHelper log, int maxPages, bool strict)
        {
            this.MaxPages = maxPages;
            this.Strict = strict;
            this.log = log;

            log.LogMessage("Starting site at " + site);
            using (var iis = new IisConfiguration(site, log))
            {
                var tokill = iis.StartWebsites();

                foreach (var process in tokill)
                    PipeProcessToLog(process);

                // Create a URI class
                var startUrl = new Uri("http://localhost:" + iis.Port);

                log.LogMessage("##teamcity[testSuiteStarted name='SiteVerification']");
                var report = RunAnalysis(startUrl);
                // Run a few queries...
                LogSeoViolations(report);

                LogBrokenLinks(report);

                LogResponseTimes(report);

                log.LogMessage("##teamcity[testSuiteFinished name='SiteVerification']");

                foreach (var process in tokill)
                {
                    SendStopMessageToProcess(process.Id);
                }
            }
        }
예제 #3
0
        public static bool RemoveSelectors(TaskLoggingHelper log, HtmlDocument document, IEnumerable<SelectorInfo> selectors)
        {
            bool updatedItem = false;
            HtmlNodeCollection collection = document.DocumentNode.SelectNodes("//style");
            int nodeNumber = 0;
            foreach (HtmlNode node in collection)
            {
                log.LogMessage(MessageImportance.Normal, "Processing <style/> tag #{0}", nodeNumber++);
                List<SelectorInfo> foundSelectors = selectors.Where(item => item.Expression.IsMatch(node.InnerText)).ToList();
                foreach (SelectorInfo foundSelector in foundSelectors)
                {
                    log.LogMessage(MessageImportance.Normal, "Found '{0}' selector. Removing all occurrences.", foundSelector.Name);
                    node.InnerHtml = foundSelector.Expression.Replace(node.InnerHtml, string.Empty);
                    updatedItem = true;
                }

                if (string.IsNullOrWhiteSpace(node.InnerHtml))
                {
                    log.LogMessage(MessageImportance.Normal, "No CSS Styles remain. Removing <style/>");
                    node.Remove();
                    updatedItem = true;
                }
            }
            return updatedItem;
        }
예제 #4
0
        public async Task <bool> CheckIfBlobExists(string blobPath)
        {
            string url = $"{FeedContainerUrl}/{blobPath}?comp=metadata";

            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Clear();
                var request = AzureHelper.RequestMessage("GET", url, AccountName, AccountKey).Invoke();
                using (HttpResponseMessage response = await client.SendAsync(request))
                {
                    if (response.IsSuccessStatusCode)
                    {
                        Log.LogMessage(
                            MessageImportance.Low,
                            $"Blob {blobPath} exists for {AccountName}: Status Code:{response.StatusCode} Status Desc: {await response.Content.ReadAsStringAsync()}");
                    }
                    else
                    {
                        Log.LogMessage(
                            MessageImportance.Low,
                            $"Blob {blobPath} does not exist for {AccountName}: Status Code:{response.StatusCode} Status Desc: {await response.Content.ReadAsStringAsync()}");
                    }
                    return(response.IsSuccessStatusCode);
                }
            }
        }
예제 #5
0
        public IEnumerable<string> GetAppBuildOrder(string sourceDirectory, string startAppPath, string uniqueSourceDirectoryPath, TaskLoggingHelper log)
        {
            _log = log;
            _uniqueSourceDirectoryPath = uniqueSourceDirectoryPath;
            var sourceDirectoryPath = sourceDirectory.Trim('\'', '"');
            var appList = GetAppListWithReferences(sourceDirectoryPath);

            var appPath = startAppPath.Trim('\'', '"');
            var startApps = appPath.Split('|').ToList();
            foreach (var app in startApps)
            {
                if (!string.IsNullOrEmpty(app))
                {
                    _log.LogMessage("Application path: {0}", app);
                    var startApp = appList[Path.GetFullPath(app.ToUpper().Replace(sourceDirectoryPath.ToUpper(), _uniqueSourceDirectoryPath)).ToUpper()];
                    if (startApp == null)
                    {
                        log.LogError("Application {0} could not be found.", app);
                    }
                    else
                    {
                        _orderedAppList.Add(Path.GetFullPath(app.ToUpper().Replace(sourceDirectoryPath.ToUpper(), _uniqueSourceDirectoryPath)).ToUpper());
                        LoopReferences(startApp, appList);
                    }
                }
            }

            _orderedAppList.ForEach(a => _log.LogMessage(a));

            return _orderedAppList;
        }
예제 #6
0
        public void UpdateProperties(string propertyOverrides, ITaskItem project, TaskLoggingHelper log)
        {
            log.LogMessage(MessageImportance.Normal, "Updating properties in file {0}", resourceFile.FullName);

            if (string.IsNullOrWhiteSpace(propertyOverrides)) return;

            var properties = propertyOverrides.ToDictionary(';', '=');

            // Scan meta data for project-specific overrides
            var metaDataNames = project.MetadataNames;
            foreach (string metaDataName in metaDataNames)
            {
                properties[metaDataName] = project.GetMetadata(metaDataName);
            }

            var lines = File.ReadLines(resourceFile.FullName).ToList();
            var results = new List<string>(lines.Count);

            // Now process each line in the file)
            foreach (var line in lines)
            {
                var key = GetKey(line);

                if (key == null)
                {
                    results.Add(line);
                }
                else
                {
                    var isValueKey = false;

                    if (key.Equals("VALUE", StringComparison.OrdinalIgnoreCase))
                    {
                        key = GetValueKey(line);
                        if (string.IsNullOrEmpty(key))
                        {
                            results.Add(line);
                            continue;
                        }

                        isValueKey = true;
                    }

                    if (properties.ContainsKey(key))
                    {
                        log.LogMessage(MessageImportance.Low, "Setting \"{0}\" to \"{1}\"", key, properties[key]);
                        results.Add(string.Format(isValueKey ? "VALUE \"{0}\", \"{1}\\0\"" : "{0} {1}", key, properties[key]));
                    }
                    else
                    {
                        results.Add(line);
                    }
                }
            }

            File.WriteAllLines(resourceFile.FullName, results);
        }
예제 #7
0
파일: TaskHelper.cs 프로젝트: JianwenSun/cc
        //------------------------------------------------------
        //
        //  Internal Helper Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        // <summary>
        // Output the Logo information to the logger for a given task
        // (Console or registered Loggers).
        // </summary>
        internal static void DisplayLogo(TaskLoggingHelper log, string taskName)
        {
            string acPath = Assembly.GetExecutingAssembly().Location;
            FileVersionInfo acFileVersionInfo = FileVersionInfo.GetVersionInfo(acPath);

            string avalonFileVersion = acFileVersionInfo.FileVersion;

            log.LogMessage(MessageImportance.Low,Environment.NewLine);
            log.LogMessageFromResources(MessageImportance.Low, SRID.TaskLogo, taskName, avalonFileVersion);
            log.LogMessageFromResources(MessageImportance.Low, SRID.TaskRight);
            log.LogMessage(MessageImportance.Low, Environment.NewLine);
        }
예제 #8
0
		public static ServiceTable GetServiceTable(string ConnString, int ServiceTableID, TaskLoggingHelper Log)
		{
			ServiceTable result = new ServiceTable();

			SqlConnection conn = new SqlConnection(ConnString);
			conn.Open();

			SqlCommand cmd = new SqlCommand("select ServiceTableID, DescServiceTable, Value, CreationDate, StringField1, StringField2 " +
					"from ServiceTable where ServiceTableID = @ServiceTableID", conn);

			using (conn)
			{
				SqlParameter p1 = cmd.Parameters.Add("@ServiceTableID", SqlDbType.Int);
				p1.Value = ServiceTableID;

				SqlDataReader rd = cmd.ExecuteReader();
				rd.Read();
				using (rd)
				{
					result.ServiceTableID = rd.GetInt32(0);
					result.DescServiceTable = rd.GetString(1);
					result.Value = (float)rd.GetDouble(2);
					result.CreationDate = rd.GetDateTime(3);
					result.StringField1 = rd.GetString(4);
					result.StringField2 = rd.GetString(5);
				}
			}

			if (Log != null)
				Log.LogMessage("Getting ServiceTableID: " + ServiceTableID.ToString());

			return result;
		}
예제 #9
0
        public bool Execute()
        {
            var rand = new Random();
            int i = rand.Next(0, FamousQuotes.Count);
            string quote = String.Format("{0}\r\n{1}", FamousQuotes[i].Saying, FamousQuotes[i].Author);

            var loggingHelper = new TaskLoggingHelper(this);
            loggingHelper.LogMessage(MessageImportance.Normal, quote);
            return true;
        }
예제 #10
0
 public static void RequireDirectory(TaskLoggingHelper log, string directory)
 {
     string fullDirectory = Path.GetFullPath(directory);
     if (File.Exists(fullDirectory))
         throw new ArgumentException("Not a directory", "directory");
     if (!Directory.Exists(fullDirectory))
     {
         Directory.CreateDirectory(fullDirectory);
         log.LogMessage(MessageImportance.Low, "Created directory '{0}'", fullDirectory);
     }
 }
예제 #11
0
        private async Task UploadAsync(CancellationToken ct, string item, string uploadPath, SemaphoreSlim clientThrottle, bool isLeaseRequired)
        {
            if (!File.Exists(item))
            {
                throw new Exception(string.Format("The file '{0}' does not exist.", item));
            }

            await clientThrottle.WaitAsync();

            string         leaseId   = string.Empty;
            AzureBlobLease blobLease = new AzureBlobLease(feed.AccountName, feed.AccountKey, string.Empty, feed.ContainerName, uploadPath, Log, "60", "10");

            if (isLeaseRequired)
            {
                try
                {
                    leaseId = blobLease.Acquire();
                }
                catch (Exception)
                {
                    Log.LogError($"Unable to obtain lease on {uploadPath}");
                }
            }
            try
            {
                Log.LogMessage($"Uploading {item} to {uploadPath}.");
                UploadClient uploadClient = new UploadClient(Log);
                await
                uploadClient.UploadBlockBlobAsync(
                    ct,
                    feed.AccountName,
                    feed.AccountKey,
                    feed.ContainerName,
                    item,
                    uploadPath,
                    leaseId);
            }
            catch (Exception)
            {
                Log.LogError($"Unable to upload to {uploadPath}");
            }
            finally
            {
                if (isLeaseRequired)
                {
                    blobLease.Release();
                }
                clientThrottle.Release();
            }
        }
예제 #12
0
        /// <summary>
        /// Log NUnit environment information.
        /// </summary>
        /// <param name="log">The logger.</param>
        public static void logEnvironmentInfo(TaskLoggingHelper log)
        {
            log.LogMessage(MessageImportance.Low, "AssemblyName: {0}", AssemblyName);
            log.LogMessage(MessageImportance.Low, "AssemblyCodeBase: {0}", AssemblyCodeBase);
            log.LogMessage(MessageImportance.Low, "AssemblyDirectory: {0}", AssemblyDirectory);
            log.LogMessage(MessageImportance.Low, "IsInteractive: {0}", IsInteractive);
            log.LogMessage(MessageImportance.Low, "CalledInBuildDirectory: {0}", CalledInBuildDirectory);
            log.LogMessage(MessageImportance.Low, "TestDirectory: {0}", TestDirectory);

        }
        private static Version ParseVersionFromCandidate(TaskLoggingHelper logger, string pathToBaseVersionFile, string versionLineCandidate)
        {
            try
            {
                //keep it simple. no regex or other fancy ways would be overkill.
                var assemblyVersion = versionLineCandidate.Split('"')[1];

                logger.LogMessage(MessageImportance.Normal, "Using base version: {0}.", assemblyVersion);
                Version version = new Version(assemblyVersion);
                return version;
            }
            catch (Exception exception)
            {
                throw new FormatException(pathToBaseVersionFile + " Assembly version declaration is in invalid format: '" + versionLineCandidate + "'.", exception);
            }
        }
예제 #14
0
        public async Task <bool> PushItemsToFeedAsync(IEnumerable <string> items, bool allowOverwrite)
        {
            Log.LogMessage(MessageImportance.Low, $"START pushing items to feed");
            Random rnd = new Random();

            try
            {
                bool result = await PushAsync(items.ToList(), allowOverwrite);

                return(result);
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e);
            }

            return(!Log.HasLoggedErrors);
        }
예제 #15
0
 public static bool InstallPackages(string packagesDirectory, string packagesConfigPath, string nugetExePath, TaskLoggingHelper log)
 {
     var nugetArguments = @"install -o " + packagesDirectory + " -Prerelease -NonInteractive " + packagesConfigPath;
     log.LogMessage("Installing: " + nugetExePath + " " + nugetArguments);
     ProcessStartInfo psi = new ProcessStartInfo();
     psi.UseShellExecute = false;
     psi.FileName = nugetExePath;
     psi.Arguments = nugetArguments;
     psi.CreateNoWindow = true;
     var process = Process.Start(psi);
     if (!process.WaitForExit(20000))
     {
         log.LogError("Packages installation timed out.");
         return false;
     }
     return true;
 }
예제 #16
0
        public async Task <bool> PushItemsToFeedAsync(
            IEnumerable <string> items,
            PushOptions options)
        {
            Log.LogMessage(MessageImportance.Low, $"START pushing items to feed");

            if (!items.Any())
            {
                Log.LogMessage("No items to push found in the items list.");
                return(true);
            }

            try
            {
                return(await PushAsync(items, options));
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e);
            }

            return(!Log.HasLoggedErrors);
        }
        internal static Version Extract(TaskLoggingHelper logger, ITaskItem baseVersionItem)
        {
            if (baseVersionItem == null) { throw new ArgumentNullException("baseVersionItem"); }

            var pathToBaseVersionFile = baseVersionItem.ItemSpec;
            if (!File.Exists(pathToBaseVersionFile))
            {
                logger.LogMessage(MessageImportance.Low, "Working in directory: " + Environment.CurrentDirectory);
                throw new InvalidOperationException("No base assembly info file exists with name " + pathToBaseVersionFile + ".");
            }

            // find assemblyVersion value from file: simplification, but since it is generated file, should be sufficient:
            string versionLineCandidate = File.ReadAllLines(pathToBaseVersionFile)
                .Where(line => !line.StartsWith("//"))
                .FirstOrDefault(line => line.Contains("AssemblyVersion"));

            if (versionLineCandidate == null) { throw new InvalidOperationException(pathToBaseVersionFile + " did not contain expected AssemblyVersionAttribute declaration."); }
            return ParseVersionFromCandidate(logger, pathToBaseVersionFile, versionLineCandidate);
        }
예제 #18
0
    public bool Initialize(string taskName, IDictionary<string, TaskPropertyInfo> parameterGroup, string taskBody, IBuildEngine taskFactoryLoggingHost)
    {
      TaskLoggingHelper log = new TaskLoggingHelper(taskFactoryLoggingHost, taskName);
        
      // We use the property group for the declaration
      taskProperties = (from c in parameterGroup select c.Value).ToArray();

      // Compile chunk
      try
      {
        log.LogMessage("Compile script.");
        task = lua.CompileChunk(taskBody, taskName, LuaDeskop.StackTraceCompileOptions, 
          new KeyValuePair<string, Type>("engine", typeof(IBuildEngine)), 
          new KeyValuePair<string, Type>("log", typeof(TaskLoggingHelper))
        );
        
        return true;
      }
      catch (LuaParseException e)
      {
        log.LogError("{0} (at line {1},{2})", e.Message, taskName, e.Line);
        return false;
      }
    } // func Initialize
예제 #19
0
		private static string GetWindowsJavaSdkLocation (TaskLoggingHelper log)
		{
			string subkey = @"SOFTWARE\JavaSoft\Java Development Kit";

			log.LogMessage ("Looking for Java SDK..");

			foreach (var wow64 in new[] { RegistryEx.Wow64.Key32, RegistryEx.Wow64.Key64 }) {
				string key_name = string.Format (@"{0}\{1}\{2}", "HKLM", subkey, "CurrentVersion");
				var currentVersion = RegistryEx.GetValueString (RegistryEx.LocalMachine, subkey, "CurrentVersion", wow64);

				if (!string.IsNullOrEmpty (currentVersion)) {
					log.LogMessage ("  Key {0} found: {1}.", key_name, currentVersion);

					if (CheckRegistryKeyForExecutable (RegistryEx.LocalMachine, subkey + "\\" + currentVersion, "JavaHome", wow64, "bin", JarSignerTool, log))
						return RegistryEx.GetValueString (RegistryEx.LocalMachine, subkey + "\\" + currentVersion, "JavaHome", wow64);
				}

				log.LogMessage ("  Key {0} not found.", key_name);
			}

			// We ran out of things to check..
			return null;
		}
        /// <summary>
        /// Helper method for checking filename extensions when resolving references.
        /// </summary>
        /// <param name="reference">The reference being resolved.</param>
        /// <param name="basePath">Full filename path without extension.</param>
        /// <param name="filenameExtensions">Filename extensions to check.</param>
        /// <param name="log">Logging helper.</param>
        /// <returns>True if the item was resolved, else false.</returns>
        private static bool ResolveFilenameExtensions(ITaskItem reference, string basePath, string[] filenameExtensions, TaskLoggingHelper log)
        {
            foreach (string filenameExtension in filenameExtensions)
            {
                string path = basePath + filenameExtension;
                log.LogMessage(MessageImportance.Low, "Trying path {0}", path);
                if (File.Exists(path))
                {
                    reference.ItemSpec = path;
                    return true;
                }
            }

            return false;
        }
예제 #21
0
		private static bool CheckRegistryKeyForExecutable (UIntPtr key, string subkey, string valueName, MonoDroid.RegistryEx.Wow64 wow64, string subdir, string exe, TaskLoggingHelper log)
		{
			string key_name = string.Format (@"{0}\{1}\{2}", key == RegistryEx.CurrentUser ? "HKCU" : "HKLM", subkey, valueName);

			var path = NullIfEmpty (RegistryEx.GetValueString (key, subkey, valueName, wow64));

			if (path == null) {
				log.LogMessage ("  Key {0} not found.", key_name);
				return false;
			}

			if (!File.Exists (Path.Combine (path, subdir, exe))) {
				log.LogMessage ("  Key {0} found:\n    Path does not contain {1} in \\{2} ({3}).", key_name, exe, subdir, path);
				return false;
			}

			log.LogMessage ("  Key {0} found:\n    Path contains {1} in \\{2} ({3}).", key_name, exe, subdir, path);

			return true;
		}
예제 #22
0
        public static void ProcessClientBigRequest(string ConnString, Stream requestStream, Stream responseStream, bool dispose, FlushDelegate flushDelegate, TaskLoggingHelper log)
        {
            XmlTextReader xr = new XmlTextReader(requestStream);

            XmlTextWriter xw = new XmlTextWriter(responseStream, Encoding.UTF8);

            xw.WriteStartDocument();
            xw.WriteStartElement("table");

            bool first = true;

            //using (xr)
            //{
                xr.Read();
                xr.Read();
                xr.ReadStartElement("request");
                while (xr.Name == "id")
                {
                    int serviceTableID = Convert.ToInt32(xr.ReadElementString("id"));
                    ServiceTable st = DAO.GetServiceTable(ConnString, serviceTableID);
                    if (first)
                    {
                        if (log != null)
                            log.LogMessage("Processing ID " + serviceTableID.ToString() + " response " + st.ServiceTableID.ToString());
                        first = false;
                    }

                    xw.WriteStartElement("record");
                    xw.WriteElementString("ServiceTableID", st.ServiceTableID.ToString());
                    xw.WriteElementString("DescServiceTable", st.DescServiceTable);
                    xw.WriteElementString("Value", st.Value.ToString("0.00"));
                    xw.WriteElementString("CreationDate", st.CreationDate.ToString("dd/MM/yyyy hh:mm:ss"));
                    xw.WriteElementString("StringField1", st.StringField1);
                    xw.WriteElementString("StringField2", st.StringField2);
                    xw.WriteEndElement();
                    if (flushDelegate != null)
                        flushDelegate();
                }
                xr.ReadEndElement();

            //}
                xr.Dispose();
            xw.WriteEndElement();
            xw.Flush();

            if (dispose)
                xw.Close();
        }
        /// <summary>
        /// Resolves a single reference item by searcheing for referenced items using the specified SearchPaths.
        /// This method is made public so the resolution logic can be reused by other tasks.
        /// </summary>
        /// <param name="reference">The referenced item.</param>
        /// <param name="searchPaths">The paths to search.</param>
        /// <param name="searchFilenameExtensions">Filename extensions to check.</param>
        /// <param name="log">Logging helper.</param>
        /// <returns>The resolved reference item, or the original reference if it could not be resolved.</returns>
        public static ITaskItem ResolveReference(ITaskItem reference, string[] searchPaths, string[] searchFilenameExtensions, TaskLoggingHelper log)
        {
            if (reference == null)
            {
                throw new ArgumentNullException("reference");
            }

            if (searchPaths == null)
            {
                // Nothing to search, so just return the original reference item.
                return reference;
            }

            if (searchFilenameExtensions == null)
            {
                searchFilenameExtensions = new string[] { };
            }

            // Copy all the metadata from the source
            TaskItem resolvedReference = new TaskItem(reference);
            log.LogMessage(MessageImportance.Low, "WixReference: {0}", reference.ItemSpec);

            // Now find the resolved path based on our order of precedence
            foreach (string searchPath in searchPaths)
            {
                log.LogMessage(MessageImportance.Low, "Trying {0}", searchPath);
                if (searchPath.Equals(HintPathToken, StringComparison.Ordinal))
                {
                    string path = reference.GetMetadata("HintPath");
                    log.LogMessage(MessageImportance.Low, "Trying path {0}", path);
                    if (File.Exists(path))
                    {
                        resolvedReference.ItemSpec = path;
                        break;
                    }
                }
                else if (searchPath.Equals(RawFileNameToken, StringComparison.Ordinal))
                {
                    log.LogMessage(MessageImportance.Low, "Trying path {0}", resolvedReference.ItemSpec);
                    if (File.Exists(resolvedReference.ItemSpec))
                    {
                        break;
                    }

                    if (ResolveWixReferences.ResolveFilenameExtensions(resolvedReference,
                        resolvedReference.ItemSpec, searchFilenameExtensions, log))
                    {
                        break;
                    }
                }
                else
                {
                    string path = Path.Combine(searchPath, Path.GetFileName(reference.ItemSpec));
                    log.LogMessage(MessageImportance.Low, "Trying path {0}", path);
                    if (File.Exists(path))
                    {
                        resolvedReference.ItemSpec = path;
                        break;
                    }

                    if (ResolveWixReferences.ResolveFilenameExtensions(resolvedReference,
                        path, searchFilenameExtensions, log))
                    {
                        break;
                    }
                }
            }

            // Normalize the item path
            resolvedReference.ItemSpec = resolvedReference.GetMetadata("FullPath");

            return resolvedReference;
        }
예제 #24
0
		private static RegexCompilationInfo LoadRegexCompilationInfo(TaskLoggingHelper log, string regexFilePath)
		{
			log.LogMessage("Loading RegexCompilationInfo from \"{0}\".", regexFilePath);
			bool isPublic = false;
			string name = null;
			string @namespace = null;
			string pattern = null;
			RegexOptions regexOptions = RegexOptions.Compiled;

			FileInfo fileInfo = new FileInfo(regexFilePath);
			using (FileStream fileStream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete, (int)fileInfo.Length, FileOptions.SequentialScan))
			{
				using (XmlReader xmlReader = XmlReader.Create(fileStream, XmlReaderSettings))
				{
					while (xmlReader.MoveToNextAttribute() || xmlReader.Read())
					{
						switch (xmlReader.NodeType)
						{
							case XmlNodeType.Element:
							case XmlNodeType.Attribute:
								switch (xmlReader.LocalName)
								{
									case "IsPublic":
										isPublic = xmlReader.ReadContentAsBoolean();
										break;
									case "Name":
										name = xmlReader.ReadContentAsString();
										break;
									case "Namespace":
										@namespace = xmlReader.ReadContentAsString();
										break;
									case "CultureInvariant":
										regexOptions |= RegexOptions.CultureInvariant;
										break;
									case "ECMAScript":
										regexOptions |= RegexOptions.ECMAScript;
										break;
									case "ExplicitCapture":
										regexOptions |= RegexOptions.ExplicitCapture;
										break;
									case "IgnoreCase":
										regexOptions |= RegexOptions.IgnoreCase;
										break;
									case "IgnorePatternWhitespace":
										regexOptions |= RegexOptions.IgnorePatternWhitespace;
										break;
									case "Multiline":
										regexOptions |= RegexOptions.Multiline;
										break;
									case "RightToLeft":
										regexOptions |= RegexOptions.RightToLeft;
										break;
									case "Singleline":
										regexOptions |= RegexOptions.Singleline;
										break;
									case "Pattern":
										pattern = xmlReader.ReadElementContentAsString();
										break;
								}
								break;
						}
					}
				}
			}

			RegexCompilationInfo regexCompilationInfo = new RegexCompilationInfo(pattern, regexOptions, name, @namespace, isPublic);
			log.LogMessage("RegexCompilationInfo loaded with settings:", null);
			log.LogMessage("\tNamespace:\t\t{0}", regexCompilationInfo.Namespace);
			log.LogMessage("\tName:\t\t\t{0}", regexCompilationInfo.Name);
			log.LogMessage("\tIsPublic:\t\t{0}", regexCompilationInfo.IsPublic);
			log.LogMessage("\tRegexOptions:\t{0}", regexCompilationInfo.Options);
			return regexCompilationInfo;
		}
예제 #25
0
 /// <summary>
 /// Logs a message of the given importance using the specified string.
 /// </summary>
 /// <remarks>This method is not thread-safe.</remarks>
 /// <param name="Log">The Log to log to.</param>
 /// <param name="importance">The importance level of the message.</param>
 /// <param name="message">The message string.</param>
 /// <param name="messageArgs">Optional arguments for formatting the message string.</param>
 /// <exception cref="ArgumentNullException">Thrown when <c>message</c> is null.</exception>
 internal static void LogMessage(TaskLoggingHelper Log, MessageImportance importance, string message, params object[] messageArgs)
 {
     // Only log when we have been passed a TaskLoggingHelper
     Log?.LogMessage(importance, message, messageArgs);
 }
예제 #26
0
        public async Task <bool> CheckIfBlobExistsAsync(string blobPath)
        {
            string url = $"{FeedContainerUrl}/{blobPath}?comp=metadata";

            using (HttpClient client = new HttpClient())
            {
                const int MaxAttempts = 15;
                // add a bit of randomness to the retry delay.
                var rng        = new Random();
                int retryCount = MaxAttempts;

                // Used to make sure TaskCancelledException comes from timeouts.
                CancellationTokenSource cancelTokenSource = new CancellationTokenSource();

                while (true)
                {
                    try
                    {
                        client.DefaultRequestHeaders.Clear();
                        var request = AzureHelper.RequestMessage("GET", url, AccountName, AccountKey).Invoke();
                        using (HttpResponseMessage response = await client.SendAsync(request, cancelTokenSource.Token))
                        {
                            if (response.IsSuccessStatusCode)
                            {
                                Log.LogMessage(
                                    MessageImportance.Low,
                                    $"Blob {blobPath} exists for {AccountName}: Status Code:{response.StatusCode} Status Desc: {await response.Content.ReadAsStringAsync()}");
                            }
                            else
                            {
                                Log.LogMessage(
                                    MessageImportance.Low,
                                    $"Blob {blobPath} does not exist for {AccountName}: Status Code:{response.StatusCode} Status Desc: {await response.Content.ReadAsStringAsync()}");
                            }
                            return(response.IsSuccessStatusCode);
                        }
                    }
                    catch (HttpRequestException toLog)
                    {
                        if (retryCount <= 0)
                        {
                            Log.LogError($"Unable to check for existence of blob {blobPath} in {AccountName} after {MaxAttempts} retries.");
                            throw;
                        }
                        else
                        {
                            Log.LogWarning("Exception thrown while trying to detect if blob already exists in feed:");
                            Log.LogWarningFromException(toLog, true);
                        }
                    }
                    catch (TaskCanceledException possibleTimeoutToLog)
                    {
                        // Detect timeout.
                        if (possibleTimeoutToLog.CancellationToken != cancelTokenSource.Token)
                        {
                            if (retryCount <= 0)
                            {
                                Log.LogError($"Unable to check for existence of blob {blobPath} in {AccountName} after {MaxAttempts} retries.");
                                throw;
                            }
                            else
                            {
                                Log.LogWarning("Exception thrown while trying to detect if blob already exists in feed:");
                                Log.LogWarningFromException(possibleTimeoutToLog, true);
                            }
                        }
                        else
                        {
                            throw;
                        }
                    }
                    --retryCount;
                    Log.LogWarning($"Failed to check for existence of blob {blobPath}. {retryCount} attempts remaining");
                    int delay = (MaxAttempts - retryCount) * rng.Next(1, 7);
                    await Task.Delay(delay * 1000);
                }
            }
        }
예제 #27
0
 void BeginAssembly(object sender, AssemblyEventArgs e)
 {
     log.LogMessage(MessageImportance.Normal, "Processing '{0}'...", e.Assembly.FullName);
 }
예제 #28
0
        public static async Task<HttpResponseMessage> RequestWithRetry(TaskLoggingHelper loggingHelper, HttpClient client,
            Func<HttpRequestMessage> createRequest, Func<HttpResponseMessage, bool> validationCallback = null, int retryCount = 5,
            int retryDelaySeconds = 5)
        {
            if (loggingHelper == null)
                throw new ArgumentNullException(nameof(loggingHelper));
            if (client == null)
                throw new ArgumentNullException(nameof(client));
            if (createRequest == null)
                throw new ArgumentNullException(nameof(createRequest));
            if (retryCount < 1)
                throw new ArgumentException(nameof(retryCount));
            if (retryDelaySeconds < 1)
                throw new ArgumentException(nameof(retryDelaySeconds));

            int retries = 0;
            HttpResponseMessage response = null;

            // add a bit of randomness to the retry delay
            var rng = new Random();

            while (retries < retryCount)
            {
                if (retries > 0)
                {
                    if (response != null)
                    {
                        response.Dispose();
                        response = null;
                    }

                    int delay = retryDelaySeconds * retries * rng.Next(1, 5);
                    loggingHelper.LogMessage(MessageImportance.Low, "Waiting {0} seconds before retry", delay);
                    await System.Threading.Tasks.Task.Delay(delay * 1000);
                }

                try
                {
                    using (var request = createRequest())
                        response = await client.SendAsync(request);
                }
                catch (Exception e)
                {
                    loggingHelper.LogWarningFromException(e, true);

                    // if this is the final iteration let the exception bubble up
                    if (retries + 1 == retryCount)
                        throw;
                }

                // response can be null if we fail to send the request
                if (response != null)
                {
                    if (validationCallback == null)
                    {
                        // check if the response code is within the range of failures
                        if (IsWithinRetryRange(response.StatusCode))
                        {
                            loggingHelper.LogWarning("Request failed with status code {0}", response.StatusCode);
                        }
                        else
                        {
                            loggingHelper.LogMessage(MessageImportance.Low, "Response completed with status code {0}", response.StatusCode);
                            return response;
                        }
                    }
                    else
                    {
                        bool isSuccess = validationCallback(response);
                        if (!isSuccess)
                        {
                            loggingHelper.LogMessage("Validation callback returned retry for status code {0}", response.StatusCode);
                        }
                        else
                        {
                            loggingHelper.LogMessage("Validation callback returned success for status code {0}", response.StatusCode);
                            return response;
                        }
                    }
                }

                ++retries;
            }

            // retry count exceeded
            loggingHelper.LogWarning("Retry count {0} exceeded", retryCount);

            // set some default values in case response is null
            var statusCode = "None";
            var contentStr = "Null";
            if (response != null)
            {
                statusCode = response.StatusCode.ToString();
                contentStr = await response.Content.ReadAsStringAsync();
                response.Dispose();
            }

            throw new HttpRequestException(string.Format("Request failed with status {0} response {1}", statusCode, contentStr));
        }
예제 #29
0
        public static bool ValidateNdkPlatform(TaskLoggingHelper log, string ndkPath, AndroidTargetArch arch, bool requireLibm)
        {
            // Check that we have a compatible NDK version for the targeted ABIs.
            NdkUtil.NdkVersion ndkVersion;
            bool hasNdkVersion = NdkUtil.GetNdkToolchainRelease (ndkPath, out ndkVersion);

            if (NdkUtil.IsNdk64BitArch(arch) && hasNdkVersion && ndkVersion.Version < 10) {
                log.LogMessage (MessageImportance.High,
                        "The detected Android NDK version is incompatible with the targeted 64-bit architecture, " +
                        "please upgrade to NDK r10 or newer.");
            }

            // NDK r10d is buggy and cannot link x86_64 ABI shared libraries because they are 32-bits.
            // See https://code.google.com/p/android/issues/detail?id=161421
            if (requireLibm && ndkVersion.Version == 10 && ndkVersion.Revision == "d" && arch == AndroidTargetArch.X86_64) {
                log.LogCodedError ("XA3004", "Android NDK r10d is buggy and provides an incompatible x86_64 libm.so. " +
                        "See https://code.google.com/p/android/issues/detail?id=161422.");
                return false;
            }

            return true;
        }
 internal static void LogMessage(TaskLoggingHelper Log, MessageImportance importance, string message, params object[] messageArgs)
 {
     if (Log != null)
     {
         Log.LogMessage(importance, message, messageArgs);
     }
 }
예제 #31
0
		private static string GetWindowsAndroidSdkLocation (TaskLoggingHelper log)
		{
			var roots = new[] { RegistryEx.CurrentUser, RegistryEx.LocalMachine };
			var wow = RegistryEx.Wow64.Key32;

			log.LogMessage ("Looking for Android SDK..");

			// Check for the key written by the Android SDK installer first
			foreach (var root in roots)
				if (CheckRegistryKeyForExecutable (root, ANDROID_INSTALLER_PATH, ANDROID_INSTALLER_KEY, wow, "platform-tools", AdbTool, log))
					return RegistryEx.GetValueString (root, ANDROID_INSTALLER_PATH, ANDROID_INSTALLER_KEY, wow);

			// Check for the key the user gave us in the VS options
			foreach (var root in roots)
				if (CheckRegistryKeyForExecutable (root, MDREG_KEY, MDREG_ANDROID, wow, "platform-tools", AdbTool, log))
					return RegistryEx.GetValueString (root, MDREG_KEY, MDREG_ANDROID, wow);

			// Check 2 default locations
			var program_files = GetProgramFilesX86 ();
			var installerLoc = Path.Combine (program_files, @"\Android\android-sdk-windows");
			var unzipLoc = Path.Combine (program_files, @"C:\android-sdk-windows");

			if (ValidateAndroidSdkLocation (installerLoc)) {
				log.LogMessage ("  adb.exe found in {0}", installerLoc);
				return installerLoc;
			}

			if (ValidateAndroidSdkLocation (unzipLoc)) {
				log.LogMessage ("  adb.exe found in {0}", unzipLoc);
				return unzipLoc;
			}

			// We ran out of things to check..
			return null;
		}
예제 #32
0
            public SelectorInfo(TaskLoggingHelper log, string selector)
            {
                Name = selector;
                string expression;
                if (selector.StartsWith("@"))
                {
                    log.LogMessage(MessageImportance.Normal, "Processing <style/> tag #{0}");
                    expression = string.Concat(selector, @"[^\;]*\;");
                }
                else
                {
                    expression = string.Concat(selector, @"\s*\{[^\}]*\}");
                }

                Expression = new Regex(expression);
                log.LogMessage(MessageImportance.Normal, "Style '{0}' Expression: \n{1}", Name, expression);
            }
예제 #33
0
        /// <summary>
        /// Executes a tool, logs standard error and a nonzero exit code as errors, returns the output and optionally logs that
        /// as well.
        /// </summary>
        /// <param name="log">used for logging</param>
        /// <param name="executable">the name of the executable</param>
        /// <param name="args">the command line arguments</param>
        /// <param name="logOutput">should we log the output in real time</param>
        /// <returns>the output of the tool</returns>
        public static string ExecuteWithLogging(TaskLoggingHelper log, string executable, string args, bool logOutput)
        {
            if (log == null)
            {
                throw new ArgumentNullException("log");
            }

            log.LogMessage(MessageImportance.Low, "Executing tool: {0} {1}", executable, args);

            var exec = new ShellWrapper(executable, args);

            // stderr is logged as errors
            exec.ErrorDataReceived += (sender, e) =>
            {
                if (e.Data != null)
                {
                    log.LogError(e.Data);
                }
            };

            // stdout is logged normally if requested
            if (logOutput)
            {
                exec.OutputDataReceived += (sender, e) =>
                {
                    if (e.Data != null)
                    {
                        log.LogMessage(MessageImportance.Normal, e.Data);
                    }
                };
            }

            // execute the process
            exec.Execute();

            // check the exit code
            if (exec.ExitCode != 0)
            {
                log.LogError("The tool {0} exited with error code {1}", executable, exec.ExitCode);
            }

            return exec.StandardOutput;
        }
예제 #34
0
        public static void ImportarStream(string connString, Stream stream, TaskLoggingHelper log)
        {
            XmlTextReader rd = new XmlTextReader(stream);

            CultureInfo c = new CultureInfo("pt-BR");
            c.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy hh:mm:ss";

            bool first = true;

            using (rd)
            {
                rd.Read();
                rd.Read();
                rd.ReadStartElement("table");
                while (rd.Name == "record")
                {
                    rd.ReadStartElement("record");
                    ServiceTable st = new ServiceTable();
                    st.ServiceTableID = Convert.ToInt32(rd.ReadElementContentAsString("ServiceTableID", ""));
                    if (first)
                    {
                        if (log != null)
                            log.LogMessage("Importing ID " + st.ServiceTableID.ToString());
                        first = false;
                    }
                    st.DescServiceTable = rd.ReadElementContentAsString("DescServiceTable", "");
                    st.Value = Convert.ToSingle(rd.ReadElementContentAsString("Value", ""));
                    st.CreationDate = Convert.ToDateTime(rd.ReadElementContentAsString("CreationDate", ""), c.DateTimeFormat);
                    st.StringField1 = rd.ReadElementContentAsString("StringField1", "");
                    st.StringField2 = rd.ReadElementContentAsString("StringField2", "");
                    rd.ReadEndElement();

                    /*if (Log != null)
                        Log.LogMessage("ServiceTableID: " + st.ServiceTableID.ToString());*/

                    DAO.ProcessServiceTable(connString, st);
                }
                rd.ReadEndElement();
            }
        }
예제 #35
0
        /// <summary>
        /// Logs a message of the given importance using the specified resource string. To the specified Log.
        /// </summary>
        /// <remarks>This method is not thread-safe.</remarks>
        /// <param name="Log">The Log to log to.</param>
        /// <param name="importance">The importance level of the message.</param>
        /// <param name="messageResourceName">The name of the string resource to load.</param>
        /// <param name="messageArgs">Optional arguments for formatting the loaded string.</param>
        /// <exception cref="ArgumentNullException">Thrown when <c>messageResourceName</c> is null.</exception>
        internal static void LogMessageFromResources(TaskLoggingHelper Log, MessageImportance importance, string messageResourceName, params object[] messageArgs)
        {
            // Only log when we have been passed a TaskLoggingHelper
            if (Log != null)
            {
                ErrorUtilities.VerifyThrowArgumentNull(messageResourceName, "messageResourceName");

                Log.LogMessage(importance, AssemblyResources.FormatResourceString(messageResourceName, messageArgs));
            }
        }
예제 #36
0
 public void Log(LogLevel level, string data)
 {
     _log.LogMessage(data, level);
 }
 public static bool IsUpToDate(TaskLoggingHelper Log, UpToDateCheckType upToDateCheckType, FlatTrackingData inputs, FlatTrackingData outputs)
 {
     bool flag = false;
     ResourceManager taskResources = Log.TaskResources;
     Log.TaskResources = AssemblyResources.PrimaryResources;
     inputs.UpdateFileEntryDetails();
     outputs.UpdateFileEntryDetails();
     if ((!inputs.TlogsAvailable || !outputs.TlogsAvailable) || (inputs.DependencyTable.Count == 0))
     {
         Log.LogMessageFromResources(MessageImportance.Low, "Tracking_LogFilesNotAvailable", new object[0]);
     }
     else if ((inputs.MissingFiles.Count > 0) || (outputs.MissingFiles.Count > 0))
     {
         if (inputs.MissingFiles.Count > 0)
         {
             Log.LogMessageFromResources(MessageImportance.Low, "Tracking_MissingInputs", new object[0]);
         }
         if (inputs.MissingFiles.Count > 100)
         {
             FileTracker.LogMessageFromResources(Log, MessageImportance.Low, "Tracking_InputsNotShown", new object[] { inputs.MissingFiles.Count });
         }
         else
         {
             foreach (string str in inputs.MissingFiles)
             {
                 FileTracker.LogMessage(Log, MessageImportance.Low, "\t" + str, new object[0]);
             }
         }
         if (outputs.MissingFiles.Count > 0)
         {
             Log.LogMessageFromResources(MessageImportance.Low, "Tracking_MissingOutputs", new object[0]);
         }
         if (outputs.MissingFiles.Count > 100)
         {
             FileTracker.LogMessageFromResources(Log, MessageImportance.Low, "Tracking_OutputsNotShown", new object[] { outputs.MissingFiles.Count });
         }
         else
         {
             foreach (string str2 in outputs.MissingFiles)
             {
                 FileTracker.LogMessage(Log, MessageImportance.Low, "\t" + str2, new object[0]);
             }
         }
     }
     else if ((upToDateCheckType == UpToDateCheckType.InputOrOutputNewerThanTracking) && (inputs.NewestFileTimeUtc > inputs.NewestTLogTimeUtc))
     {
         Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", new object[] { inputs.NewestFileName, inputs.NewestFileTimeUtc });
     }
     else if ((upToDateCheckType == UpToDateCheckType.InputOrOutputNewerThanTracking) && (outputs.NewestFileTimeUtc > outputs.NewestTLogTimeUtc))
     {
         Log.LogMessage(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", new object[] { outputs.NewestFileName, outputs.NewestFileTimeUtc });
     }
     else if ((upToDateCheckType == UpToDateCheckType.InputNewerThanOutput) && (inputs.NewestFileTimeUtc > outputs.NewestFileTimeUtc))
     {
         Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", new object[] { inputs.NewestFileName, inputs.NewestFileTimeUtc });
     }
     else if ((upToDateCheckType == UpToDateCheckType.InputNewerThanTracking) && (inputs.NewestFileTimeUtc > inputs.NewestTLogTimeUtc))
     {
         Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", new object[] { inputs.NewestFileName, inputs.NewestFileTimeUtc });
     }
     else if ((upToDateCheckType == UpToDateCheckType.InputNewerThanTracking) && (inputs.NewestFileTimeUtc > outputs.NewestTLogTimeUtc))
     {
         Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", new object[] { inputs.NewestFileName, inputs.NewestFileTimeUtc });
     }
     else
     {
         flag = true;
         Log.LogMessageFromResources(MessageImportance.Normal, "Tracking_UpToDate", new object[0]);
     }
     Log.TaskResources = taskResources;
     return flag;
 }
예제 #38
0
 /// <summary>
 /// Logs a message of the given importance using the specified string.
 /// </summary>
 /// <remarks>This method is not thread-safe.</remarks>
 /// <param name="importance">The importance level of the message.</param>
 /// <param name="message">The message string.</param>
 /// <param name="messageArgs">Optional arguments for formatting the message string.</param>
 /// <exception cref="ArgumentNullException">Thrown when <c>message</c> is null.</exception>
 internal static void LogMessage(TaskLoggingHelper Log, MessageImportance importance, string message, params object[] messageArgs)
 {
     // Only log when we have been passed a TaskLoggingHelper
     if (Log != null)
     {
         Log.LogMessage(importance, message, messageArgs);
     }
 }