/// <summary> /// A new instance should be constructed for every issue. /// </summary> public YouTrackIssueSubmitter(string projectKey) { _youTrackProjectKey = projectKey; // Note that the headers set here apply to all following calls using _client. // So this is the only place we need to set the authorization value and accept value. // (Authorization applies to all GET, POST, and DELETE requests. Accept applies to // all GET requests, which are always JSON the way the REST API works in what we use.) var permission = $"Bearer perm:{TokenPiece1}"; IEnumerable <string> authorizations; lock (_client) { var hasAuthorization = _client.DefaultRequestHeaders.TryGetValues("Authorization", out authorizations); if (!hasAuthorization || !authorizations.Contains(permission)) { _client.DefaultRequestHeaders.Add("Authorization", permission); } var appJson = "application/json"; IEnumerable <string> accepts; var hasAccept = _client.DefaultRequestHeaders.TryGetValues("Accept", out accepts); if (!hasAccept || !accepts.Contains(appJson)) { _client.DefaultRequestHeaders.Add("Accept", appJson); } } // Get the base website address for our YouTrack instance. _youTrackBaseSite = UrlLookup.LookupUrl(UrlType.IssueTrackingSystemBackend, null, false, true); }
public SearchParameterInfo GetSearchParameter(string definitionUri) { if (UrlLookup.TryGetValue(definitionUri, out SearchParameterInfo value)) { return(value); } throw new SearchParameterNotSupportedException(definitionUri); }
public void Show() { // Ideally, we would load the page in our own window, but we need to deal with the popup and maybe cookie issues: // * didn't work well with google-login // * geckofx9 had various errors related to popup windows (e.g. login via google), and thos popup windows were yucky anyhow //ShowDialog(); //So now, we just run your browser var url = UrlLookup.LookupUrl(UrlType.UserSuggestions); Process.Start(url); }
public ProblemReporterDialog(Control targetOfScreenshot) { // Haven't tried https here, as we're not using it for live YouTrack. Someday we may want to. // If so, check Linux, as we had problems there with the old Jira reporting. Until // then we use the unsecured URL. YouTrackUrl = UrlLookup.LookupUrl(UrlType.IssueTrackingSystemBackend); Summary = "User Problem Report {0}"; InitializeComponent(); // The GeckoFx-based _status control refuses to display the "Submitting to server..." message // on Linux, although it displays just fine on Windows. Even moving the actual process of // submitting the information to another thread doesn't help -- the message still doesn't // display. Substituting a normal Label control for that particular messages works just fine. // See https://jira.sil.org/browse/BL-1004 for details. _submitMsg.Text = LocalizationManager.GetString("ReportProblemDialog.Submitting", "Submitting to server...", "This is shown while Bloom is sending the problem report to our server."); if (targetOfScreenshot != null) { //important to do this early, before this dialog obstructs the application GetScreenshot(targetOfScreenshot); _includeScreenshot.Checked = _screenshot != null; // if for some reason we couldn't get a screenshot, this will be null _includeScreenshot.Visible = _screenshot != null; if (targetOfScreenshot is WorkspaceView) { _projectName = ((WorkspaceView)targetOfScreenshot).Text; } } else { _includeScreenshot.Visible = false; _includeScreenshot.Checked = false; } _email.Text = SIL.Windows.Forms.Registration.Registration.Default.Email; _name.Text = (SIL.Windows.Forms.Registration.Registration.Default.FirstName + " " + SIL.Windows.Forms.Registration.Registration.Default.Surname).Trim(); _screenshotHolder.Image = _screenshot; ChangeState(State.WaitingForSubmission); }
public void DeleteSearchParameter(ITypedElement searchParam) { var searchParamWrapper = new SearchParameterWrapper(searchParam); SearchParameterInfo searchParameterInfo = null; if (!UrlLookup.TryRemove(new Uri(searchParamWrapper.Url), out searchParameterInfo)) { throw new Exception(string.Format(Resources.CustomSearchParameterNotfound, searchParamWrapper.Url)); } var allResourceTypes = searchParameterInfo.TargetResourceTypes.Union(searchParameterInfo.BaseResourceTypes); foreach (var resourceType in allResourceTypes) { TypeLookup[resourceType].TryRemove(searchParameterInfo.Code, out var removedParam); } CalculateSearchParameterHash(); }
public void DeleteSearchParameter(string url, bool calculateHash = true) { SearchParameterInfo searchParameterInfo = null; if (!UrlLookup.TryRemove(url, out searchParameterInfo)) { throw new ResourceNotFoundException(string.Format(Core.Resources.CustomSearchParameterNotfound, url)); } // for search parameters with a base resource type we need to delete the search parameter // from all derived types as well, so we iterate across all resources foreach (var resourceType in TypeLookup.Keys) { TypeLookup[resourceType].TryRemove(searchParameterInfo.Code, out var removedParam); } if (calculateHash) { CalculateSearchParameterHash(); } }
public void DeleteSearchParameter(string url, bool calculateHash = true) { SearchParameterInfo searchParameterInfo = null; if (!UrlLookup.TryRemove(new Uri(url), out searchParameterInfo)) { throw new ResourceNotFoundException(string.Format(Resources.CustomSearchParameterNotfound, url)); } var allResourceTypes = searchParameterInfo.TargetResourceTypes.Union(searchParameterInfo.BaseResourceTypes); foreach (var resourceType in allResourceTypes) { TypeLookup[resourceType].TryRemove(searchParameterInfo.Code, out var removedParam); } if (calculateHash) { CalculateSearchParameterHash(); } }
public PageTestFixture( IMiruApp app, UrlLookup urlLookup, PageTestingConfig config, RemoteWebDriver driver, IStorage storage, PageBody browser, MiruNavigator navigator) : base(navigator) { App = app; _urlLookup = urlLookup; _config = config; _driver = driver; _storage = storage; _browser = browser; _browser.BaseUrl = _config.BaseUrl; navigator.ConfigureExceptions(context => { var exceptionMessage = $@"{context.FailureMessage.Or(context.OriginalException.Message)} The url was: {Url} A screenshot was taken on the moment of the failure: {FailureScreenshot()} The Page's html has been saved to: {SaveHtml()} "; throw new PageTestException(exceptionMessage, context.OriginalException); }); }
public bool TryGetSearchParameter(string definitionUri, out SearchParameterInfo value) { return(UrlLookup.TryGetValue(definitionUri, out value)); }
private void MakeAceByDaisyReport(ApiRequest request) { // First check whether ace has been installed. var daisyDirectory = FindAceByDaisyOrTellUser(request); // this method does the request.fail() if needed if (string.IsNullOrEmpty(daisyDirectory)) { return; } // As of version 1.0.2, the ace report has stylesheets on the internet. See https://issues.bloomlibrary.org/youtrack/issue/BL-6118. // To be specific, https://cdn.datatables.net/1.10.15/css/dataTables.bootstrap4.min.css and // https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css. if (!UrlLookup.CheckGeneralInternetAvailability(true)) { _webSocketProgress.ErrorWithoutLocalizing( "Sorry, you must have an internet connection in order to view the Ace by DAISY report."); request.Failed(); return; } var reportRootDirectory = Path.Combine(System.IO.Path.GetTempPath(), "daisy-ace-reports"); // Do our best at clearing out previous runs. // This call is ok if the directory does not exist at all. SIL.IO.RobustIO.DeleteDirectoryAndContents(reportRootDirectory); // This call is ok if the above failed and it still exists Directory.CreateDirectory(reportRootDirectory); // was having a problem with some files from previous reports getting locked. // so give new folder names if needed var haveReportedError = false; var errorMessage = "Unknown Error"; var version = GetAceByDaisyVersion(daisyDirectory); if (version.old) { _webSocketProgress.MessageWithoutLocalizing( $"You appear to have an older version ({version.version}) of ACE by Daisy. This may cause problems.", ProgressKind.Warning); _webSocketProgress.MessageWithoutLocalizing( "We recommend you run \"npm install @daisy/ace -g\" from a command line to get the latest.", ProgressKind.Warning); } var started = DateTime.Now; var epubPath = MakeEpub(reportRootDirectory, _webSocketProgress); // Try 3 times. It could be that this is no longer needed, but working on a developer // machine isn't proof. for (var i = 0; i < 3; i++) { var randomName = Guid.NewGuid().ToString(); var reportDirectory = Path.Combine(reportRootDirectory, randomName); var arguments = $"ace.js --verbose -o \"{reportDirectory}\" \"{epubPath}\""; const int kSecondsBeforeTimeout = 60; var progress = new NullProgress(); _webSocketProgress.MessageWithoutLocalizing("Running Ace by DAISY"); ExecutionResult res = null; string ldpath = null; try { // Without this variable switching on Linux, the chrome inside ace finds the // wrong version of a library as part of our mozilla code. ldpath = Environment.GetEnvironmentVariable("LD_LIBRARY_PATH"); Environment.SetEnvironmentVariable("LD_LIBRARY_PATH", null); res = CommandLineRunner.Run("node", arguments, Encoding.UTF8, daisyDirectory, kSecondsBeforeTimeout, progress, (dummy) => { }); } finally { // Restore the variable for our next geckofx browser to find. if (!String.IsNullOrEmpty(ldpath)) { Environment.SetEnvironmentVariable("LD_LIBRARY_PATH", ldpath); } } if (res.DidTimeOut) { errorMessage = $"Daisy Ace timed out after {kSecondsBeforeTimeout} seconds."; _webSocketProgress.ErrorWithoutLocalizing(errorMessage); continue; } var answerPath = Path.Combine(reportDirectory, "report.html"); if (!File.Exists(answerPath)) { // This hasn't been effectively reproduced, but there was a case where this would fail at least // half the time on a book, reproducable. That book had 2 pages pointing at placeholder.png, // and we were getting an error related to it being locked. So we deduce that ace was trying // to copy the file twice, at the same time (normal nodejs code is highly async). // Now the problem is not reproducable, but I'm leaving in this code that tried to deal with it. errorMessage = $"Exit code{res.ExitCode}{Environment.NewLine}" + $"Standard Error{Environment.NewLine}{res.StandardError}{Environment.NewLine}" + $"Standard Out{res.StandardOutput}"; _webSocketProgress.ErrorWithoutLocalizing(errorMessage); continue; // something went wrong, try again } // The html client is set to treat a text reply as a url of the report. Make sure it's valid for being a URL. // See https://silbloom.myjetbrains.com/youtrack/issue/BL-6197. request.ReplyWithText("/bloom/" + answerPath.EscapeFileNameForHttp()); if (version.old) { // If we displayed an important message about updating ACE, make sure the user // has SOME time to see it. // Review: is this long enough? Should we look for some other way to show the // problem? At present the problems caused by an old version (1.1 is the oldest // contemporary with Bloom) is fairly minor. while (DateTime.Now - started < new TimeSpan(0, 0, 0, 5)) { Thread.Sleep(100); } } return; } // If we get this far, we give up. ReportErrorAndFailTheRequest(request, errorMessage); }
private void _webSiteMenuItem_Click(object sender, EventArgs e) { Process.Start(UrlLookup.LookupUrl(UrlType.LibrarySite)); }
public string GetRealUrl() { return(UrlLookup.LookupUrl(UrlType.Parse, BookUpload.UseSandbox)); }
public string GetRealUrl() { return(UrlLookup.LookupUrl(UrlType.Parse, BookTransfer.UseSandbox)); }
private void _askAQuestionMenuItem_Click(object sender, EventArgs e) { Process.Start(UrlLookup.LookupUrl(UrlType.Support)); }
private void _requestAFeatureMenuItem_Click(object sender, EventArgs e) { Process.Start(UrlLookup.LookupUrl(UrlType.UserSuggestions)); }
private void FeedbackDialog_Load(object sender, EventArgs e) { var url = UrlLookup.LookupUrl(UrlType.UserSuggestions); _browser.Navigate(url, false); }