private async void btnSave_Click(object sender, EventArgs e) { if (dgFilesSelected.SelectedRows.Count == 0) { return; } if (txtAlbum.Text.Equals(Constants.MultipleValues) && txtArtist.Text.Equals(Constants.MultipleValues) && txtGenre.Text.Equals(Constants.MultipleValues) && txtTrackNumber.Text.Equals(Constants.MultipleValues) && txtTrackTitle.Text.Equals(Constants.MultipleValues) && txtYear.Text.Equals(Constants.MultipleValues)) { return; } this.Enabled = false; gbMetaTags.Enabled = false; var metaTagsService = new MetaTagsService(); await metaTagsService.SetMetaTags(Files); var cts = new CancellationTokenSource(30000); var fi = new FileIndexer(cts.Token); await Task.Run(() => fi.StartIndexing(Files.Select(x => x.Id), null), cts.Token); this.Enabled = true; gbMetaTags.Enabled = true; MessageBox.Show(this, "Saved succesfully!", "Meta tags saved", MessageBoxButtons.OK); }
private void HydrateMetaTags <T>(T model) where T : BaseViewModel { List <PageMetaTags> metatag = new List <PageMetaTags>(); // instantiate the constructor to match the return type MetaTagsService metatagService = new MetaTagsService(); // instantiating the method because it's not static string currentUrl = Request.Url.AbsolutePath; // grab the currentURL to pass into service string baseUrl = Request.ApplicationPath.TrimEnd('/') + "/"; //string currentUrl = Request.Url.ToString(); // grab the currentURL to pass into service model.BaseUrl = Request.Url.GetLeftPart(UriPartial.Authority); if (currentUrl != baseUrl) { string[] currentUrlString = Request.Url.Segments; //gets the segments and sets it to an array string currentUrlFull = currentUrlString[1].ToLower(); // making path lowercase if (currentUrlFull.Contains('/')) { currentUrl = currentUrlFull.Substring(0, currentUrlFull.Length - 1); // grab substring to remove the last "/" } else { currentUrl = currentUrlFull; } } metatag = metatagService.PageMetaTags_SelectAllByOwnerName(currentUrl); // setting metatag to list result // Put an if condition here to check if this request is from the /job/options page if (Request.Url.AbsolutePath.ToLower().Contains("/jobs/option/")) { //Call to the Job Service to get Job Model JobService svc = new JobService(); //Access Job Id from Base View Model Job j = svc.JobGetById(model.JobId); metatag[0].MetaTagValue = j.Title; metatag[2].MetaTagValue = Request.Url.AbsoluteUri; string jobDescription = Regex.Replace(j.Description, "<.*?>", string.Empty); jobDescription = Regex.Replace(jobDescription, "\n", " "); jobDescription = Regex.Replace(jobDescription, "&.*?;", " "); int i = Math.Min((jobDescription.Length - 1), 149); // finding the min between string length or index metatag[4].MetaTagValue = jobDescription.Substring(0, i); } model.MetaTags = metatag; }