/// <summary> /// Callback method to handle socket closing. /// </summary> /// <param name="client">The client to receive messages from.</param> internal void ClientCloseHandler(AsyncSocketClient client) { lock (_bindingLock) { _Log.Warn("Socket closed, scheduling a rebind operation."); _ReBindRequired = true; } DispatchOnClose(new EventArgs()); }
/// <summary> /// Sets the disposed flag to true and disconnects the socket. /// </summary> public void Dispose() { using (new WriteLock(_socketLock)) { try { _Log.DebugFormat("Disposing instance ({0}).", this.GetHashCode()); _IsDisposed = true; Disconnect(); } catch (Exception ex) { _Log.Warn("Exception thrown while disposing.", ex); } } }
private void Dispose(bool disposing) { if (_disposed) { _Log.Warn("Disposed was called more than once?!"); return; } if (disposing) { // Dispose managed resources.. Begin = null; PhaseChanged = null; ProgressChanged = null; Finished = null; Error = null; Warning = null; } // Dispose un-managed resources.. try { NativeCalls.wkhtmltopdf_deinit(); } catch (DllNotFoundException) { // We may not be initialized yet } _disposed = true; }
private MultiplexingConverter _GetConverter() { var obj = new MultiplexingConverter(); obj.Begin += (s, e) => _Log.DebugFormat("Conversion begin, phase count: {0}", e.Value); obj.Error += (s, e) => _Log.Error(e.Value); obj.Warning += (s, e) => _Log.Warn(e.Value); obj.PhaseChanged += (s, e) => _Log.InfoFormat("PhaseChanged: {0} - {1}", e.Value, e.Value2); obj.ProgressChanged += (s, e) => _Log.InfoFormat("ProgressChanged: {0} - {1}", e.Value, e.Value2); obj.Finished += (s, e) => _Log.InfoFormat("Finished: {0}", e.Value ? "success" : "failed!"); return(obj); }
public void QueueRequest(MergeRequest mergeRequest) { // initially update the merge request with information from the POST request (or wherever it came from). // we might do another update later to make sure the data is still relevant. UpdateIssueDetails(mergeRequest, mergeRequest.IssueDetails); if (!ShouldTryToMerge(mergeRequest)) { return; } Task.Run(() => { bool shouldMerge; if (mergeRequest.IssueDetails == null) { Logger.Info(m => m("Got a merge request without associated Jira issue. Guess we should merge that one either way.")); shouldMerge = true; } else { Logger.Debug(m => m("Waiting a bit before queuing merge request for '{0}'", mergeRequest.IssueDetails.Key)); // wait a bit before actually queuing the request; someone might have accidentally closed the Jira issue Thread.Sleep(_gitSettings.MergeDelay); var issueDetails = _jira.GetIssueDetails(mergeRequest.IssueDetails.Key); if (issueDetails == null) { Logger.Warn(m => m("Jira didn't return any issue information while trying to check if we should still merge '{0}'; not doing a merge.", mergeRequest.IssueDetails.Key)); shouldMerge = false; } else if (!_jiraSettings.ClosedStatus.Contains(issueDetails.Status)) { Logger.Info(m => m("Related Jira issue is NOT closed; not doing a merge.")); shouldMerge = false; } else { shouldMerge = !ShouldPreventAutomerge(issueDetails); Logger.Info(m => m("Related Jira issue indicates it should {0}be merged, {0}preceding with merge.", shouldMerge ? "" : "not ")); if (shouldMerge) { UpdateIssueDetails(mergeRequest, issueDetails); } } } if (shouldMerge) { // HandleMergeRequests should only get valid ones, so check if the request is still valid _mergeRequests.Add(mergeRequest); } }); }
private byte[] WaitBytes(int length) { byte[] bytes = new byte[length]; int remaining = length; int received = 0; while (remaining > 0) { int receiveCount = vTcpIpSession.Receive(bytes, received, remaining); if (receiveCount == 0) { _Log.Warn("200014:TCP/IP receive operation returned zero bytes;"); } if (receiveCount == 0 && vTraceSwitch.TraceWarning) { Trace.WriteLine("200014:TCP/IP receive operation returned zero bytes;"); } received += receiveCount; remaining = length - received; } return(bytes); }
private void Dispose(bool disposing) { if (_disposed) { _Log.Warn("Disposed was called more than once?!"); return; } if (disposing) { // Dispose managed resources.. Begin = null; PhaseChanged = null; ProgressChanged = null; Finished = null; Error = null; Warning = null; } // Dispose un-managed resources.. wkhtmltopdf_deinit(); _disposed = true; }
public void Warn(Object message, Exception exception) { _log.Warn(message, exception); }
public IEnumerable <GitRepositoryBranch> FindBranch(string branchName, bool isExactBranchName) { Logger.Debug(m => m("Trying to find matching repositories for '{0}' (exact match: {1})", branchName, isExactBranchName)); foreach (var repositoryInfo in _gitSettings.Repositories) { var repository = Get(repositoryInfo); if (!repository.Exists()) { if (!repository.Initialize()) { // TODO: notify someone that the repository couldn't be initialized? continue; } } else { if (!repository.Fetch()) { // TODO: notify someone that the fetch failed? continue; } } string[] branches = repository.Branches(); Logger.Debug(m => m("Found {0} branches: {1}", branches.Length, string.Join(", ", branches))); if (isExactBranchName) { // assume an exact branch match is always intentional, and must never be ignored. // might happen that a review/testing/whatever branch supersedes the real one, // and the lazy developer simply inputs their branch name as source. if (branches.Contains(branchName)) { Logger.Info(m => m("Got an exact branch name match for '{0}' in '{1}'.", branchName, repository.RepositoryIdentifier)); yield return(new GitRepositoryBranch(repository, branchName)); } // else: no such branch. probably, nothing to do for this repository // TODO: maybe check if theres a matching branch of different casing? } else { // since its not an exact match, we can assume it is a Jira issue key. // they follow the pattern "<project key>-<issue number>", where the issue number is strictly numeric; // and the project key only contains letters, numbers or the underscore (always starting with a letter). // append a negative look-ahead for digits, which should prevent matching partial issue numbers. // we cannot use word-boundaries here, since it will not match names such as JRA-123b or JRA-123_fixed. // NOTE: this is mostly convention being used in practise; this might not match all configurations on all systems. // FIXME: this does not account for the beginning of the branch name; but in practise we do not have overlap // (and therefore don't need to check for it right now) var jiraIssueKey = new Regex(branchName + @"(?!\d)", RegexOptions.IgnoreCase); var matchingBranches = branches.Where(branch => jiraIssueKey.IsMatch(branch)); var nonIgnoredBranches = matchingBranches.Where(IsEligibleBranchForMerging).ToArray(); var ignoredBranches = matchingBranches.Except(nonIgnoredBranches).Select(b => $"{b} (ignored)").ToArray(); if (nonIgnoredBranches.Count() == 1) { Logger.Info(m => m("Found a branch name match for '{0}' (exact spelling is '{1}') in '{2}'.", branchName, matchingBranches.First(), repository.RepositoryIdentifier)); yield return(new GitRepositoryBranch(repository, matchingBranches.First())); } else if (nonIgnoredBranches.Count() + ignoredBranches.Count() > 0) { var branchesToLog = nonIgnoredBranches.Concat(ignoredBranches); Logger.Warn(m => m("Found {0} branches matching '{1}' in repository '{2}', cannot decide which one they wanted: {3}", matchingBranches.Count(), branchName, repository.RepositoryIdentifier, string.Join(", ", branchesToLog))); foreach (string matchingBranchName in nonIgnoredBranches) { yield return(new GitRepositoryBranch(repository, matchingBranchName)); } foreach (string matchingBranchName in ignoredBranches) { yield return new GitRepositoryBranch(repository, matchingBranchName) { IsIgnored = true } } ; } } } }
/// <summary> /// Checks for existence of library. /// </summary> /// <param name="checkHashes"><code>True</code> to compare hashes.</param> /// <param name="tryLoad"><code>True</code> to try load of library.</param> /// <returns><code>False</code> if library does not exists.</returns> public bool CheckVlcLibraryExistence(bool checkHashes, bool tryLoad) { // VlcDeploymentFailReason failReason = deploymentFailReason; try { deploymentFailReason = 0; DirectoryInfo info = new DirectoryInfo(deploymentLocation); if (!info.Exists) { deploymentFailReason = VlcDeploymentFailReason.EmptyDeployment; return(false); } else { // FileInfo[] files = info.GetFiles(); // List <string> fileNames = new List <string> (); // foreach (FileInfo file in files) { fileNames.Add(file.Name); } // foreach (KeyValuePair <string, string> pair in deploymentContent) { string filePath = pair.Key.Replace('\\', Path.DirectorySeparatorChar); if (filePath.StartsWith(Path.DirectorySeparatorChar.ToString())) { filePath = filePath.Substring(1); } string fileHash = pair.Value; // string fullFilePath = Path.GetFullPath(Path.Combine(deploymentLocation, filePath)); if (filePath.LastIndexOf(Path.DirectorySeparatorChar) > 0) { string directoryName = Path.GetDirectoryName(filePath); string directoryPath = Path.Combine(deploymentLocation, directoryName); if (!Directory.Exists(directoryPath)) { deploymentFailReason = FailReason | VlcDeploymentFailReason.NotAllFilesDeployed; return(false); } else { if (!File.Exists(fullFilePath)) { deploymentFailReason = FailReason | VlcDeploymentFailReason.NotAllFilesDeployed; return(false); } } } else { // this is file in root if (!fileNames.Contains(filePath)) { deploymentFailReason = FailReason | VlcDeploymentFailReason.NotAllFilesDeployed; return(false); } } if (checkHashes) { using (Stream stream = File.Open(fullFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { byte[] hash = hashReceiver.ComputeHash(stream); string hashBase64 = Convert.ToBase64String(hash); if (string.Compare(fileHash, hashBase64) != 0) { deploymentFailReason = FailReason | VlcDeploymentFailReason.InvalidHashOfFile; return(false); } } } } // } // if (tryLoad) { try { List <string> parameters = new List <string>(); if (osType == VlcDeployment.DeterminedOSType.MacOS) { string path = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "plugins"); parameters.Add("--plugin-path"); parameters.Add(path); } using (VlcMediaLibraryFactory factory = new VlcMediaLibraryFactory(parameters.ToArray())) { string version = factory.Version; if (string.Compare(version, vlcVersion, StringComparison.Ordinal) != 0) { deploymentFailReason = FailReason | VlcDeploymentFailReason.LibraryVersionDiffers; } return(true); } } catch (VlcInternalException exc) { deploymentFailReason = FailReason | VlcDeploymentFailReason.LibraryCannotBeLoaded; if (logger.IsWarnEnabled) { logger.Warn("Cannot check vlc version.", exc); } } } return(FailReason == 0); } catch (Exception) { deploymentFailReason = failReason; throw; } }