public WebPage AddWebPage(WebPage newpage) { EfWip.WaitBombIf(); // wait for <*> to finish #if WIP LastEfCmd = EfWipEnum.AddWebPage; #endif var wp = EfDomain.WebPages.Add(newpage); // Local only (no db net work) return(wp); }
public int SaveChanges() { EfWip.WaitBombIf(); // wait for any previous async SQL traffic by EF to finish AdoWip.WaitBombIf(); // ditto wait for any previous async p_ActionWebPage sproc operation to complete [avoid internal deadlocks] #if WIP LastEfCmd = EfWipEnum.SaveChangesAsync; // although method not Async, it refreshes latest activity #endif return(EfDomain.SaveChanges()); // N.B. EF has its own retry and transaction wrappers }
//public WebPage GetWebPageById(int id) => EfDomain.WebPages.FirstOrDefault(row => row.PageId == id); public Task <WebPage> GetWebPageByUrlAsync(string url) { EfWip.WaitBombIf(); // wait for <***> to finish #if WIP LastEfCmd = EfWipEnum.GetWebPageByUrl; #endif var wplocal = EfDomain.WebPages.Local.FirstOrDefault(row => row.Url == url); if (wplocal != null) { return(Task.FromResult <WebPage>(wplocal)); // found locally (sync) } Task <WebPage> rslt; EfWip = rslt = EfDomain.WebPages.FirstOrDefaultAsync(row => row.Url == url); // async roundtrip to db return(rslt); }
public Task <List <WebPage> > GetWebPagesToLocaliseAsync(int maxrows = 15) { EfWip.WaitBombIf(); // wait for GetContentTypeToExtnsAsync / SaveChangesAsync to finish #if WIP LastEfCmd = EfWipEnum.GetWebPagesToLocalise; #endif var takeprm = new SqlParameter("@TakeN", SqlDbType.Int) // have to recreate every time (presumably as EF invents new SqlCommand) to avoid { Value = maxrows }; // "The SqlParameter is already contained by another SqlParameterCollection" error Task <List <WebPage> > rslt; EfWip = rslt = EfDomain.WebPages .SqlQuery("exec dbo.p_ToLocalise @Take=@TakeN", takeprm) .ToListAsync(); // solidify as List<WebPage> (i.e. no deferred execution), and caller will await to get # requested return(rslt); }
public Task <List <ContentTypeToExtn> > GetContentTypeToExtnsAsync() { EfWip.WaitBombIf(); // wait for <nothing> to finish #if WIP LastEfCmd = EfWipEnum.GetContentTypeToExtns; #endif Task <List <ContentTypeToExtn> > rslt; EfWip = rslt = EfDomain.ContentTypeToExtns //.AsNoTracking() // read-only here //.Where(row => !string.IsNullOrEmpty(row.Template) && !string.IsNullOrEmpty(row.Extn)) // WHERE ((LEN([Extent1].[Template])) <> 0) AND ((LEN([Extent1].[Extn])) <> 0) .OrderBy(row => row.Template) .ToListAsync(); //EfWip.WaitBombIf(); // wait for <***> to finish //var xxx = EfDomain.ContentTypeToExtns.ToList(); return(rslt); }
public Task <int> SaveChangesAsync() { EfWip.WaitBombIf(); // wait for any previous async SQL traffic by EF to finish AdoWip.WaitBombIf(); // ditto wait for any previous async p_ActionWebPage sproc operation to complete [avoid internal deadlocks] #if WIP LastEfCmd = EfWipEnum.SaveChangesAsync; #endif Task <int> rslt; EfWip = rslt = EfDomain.SaveChangesAsync(); // 3. previous upload, but exec sproc deferred to after SaveChanges, i.e. now if (ActionPage != null) { EfWip.WaitBombIf(); // wait for repository's SaveChangesAsync to finish (e.g. to persist new redirected WebPage) SaveLinks(ActionPage); // actually invoke p_ActionWebPage sproc ActionPage = null; AdoWip.WaitBombIf(); // wait for parallel ADO to quiesce (i.e. p_Action sproc) } return(rslt); // caller can await to get integer rowcount }
//public IEnumerable<WebPage> GetWebPages() => EfDomain.WebPages; public Task <List <WebPage> > GetWebPagesToDownloadAsync(int maxrows = 15) { EfWip.WaitBombIf(); // wait for GetContentTypeToExtnsAsync / SaveChangesAsync to finish //AdoWip.WaitBombIf(); // *** TEMP *** // sadly this results in setting change-tracking for all rows to EnumEntityState.Deleted so don't enable ! // imho best to live with the gradual growth of this collection - else incur high cost to cycle in a new DbContext as replacement //EfDomain.WebPages.Local.Clear(); // toss all previous locally cached rows to improve search speed (cf. big-O!) #if WIP LastEfCmd = EfWipEnum.GetWebPagesToDownload; #endif var takeprm = new SqlParameter("@TakeN", SqlDbType.Int) // have to recreate every time (presumably as EF invents new SqlCommand) to avoid { Value = maxrows }; // "The SqlParameter is already contained by another SqlParameterCollection" error var N = EfDomain.WebPages.Local.Count; Task <List <WebPage> > rslt; EfWip = rslt = EfDomain.WebPages .SqlQuery("exec p_ToDownload @Take=@TakeN", takeprm) .ToListAsync(); // solidify as List<WebPage> (i.e. no deferred execution), and caller will await to get # requested return(rslt); }