public void CleanUp() { Retry.Do(DoCleanUp, retryInterval: TimeSpan.FromMilliseconds(250), retryCount: 10); }
public AddNewAgentDialog AddNewAgent() { Retry.Do(_addNewButton.ClickByJS); Wait.WaitForAjaxReady(By.CssSelector(".locking-mask")); return(new AddNewAgentDialog()); }
public void ClickFTEUpdate() { Retry.Do(_FTE.Click); Wait.WaitForAjaxReady(By.CssSelector(".locking-mask-loading")); }
private DownloadStream GetDownloadStreamInternal(File afile, long?start = null, long?end = null) { bool isLinked = afile.PublicLinks.Any(); Cached <ServerRequestResult> downServer = null; var pendingServers = isLinked ? ShardManager.WeblinkDownloadServersPending : ShardManager.DownloadServersPending; Stopwatch watch = new Stopwatch(); HttpWebRequest request = null; CustomDisposable <HttpWebResponse> ResponseGenerator(long instart, long inend, File file) { var resp = Retry.Do(() => { downServer = pendingServers.Next(downServer); string url; if (isLinked) { var urii = file.PublicLinks.First().Uri; var uriistr = urii.OriginalString; var baseura = PublicBaseUrls.First(pbu => uriistr.StartsWith(pbu, StringComparison.InvariantCulture)); if (string.IsNullOrEmpty(baseura)) { throw new ArgumentException("url does not starts with base url"); } url = $"{downServer.Value.Url}{WebDavPath.EscapeDataString(uriistr.Remove(0, baseura.Length))}"; } else { url = $"{downServer.Value.Url}{Uri.EscapeDataString(file.FullPath.TrimStart('/'))}"; } url += $"?client_id={HttpSettings.ClientId}&token={Authent.AccessToken}"; //string url =(isLinked // ? $"{downServer.Value.Url}{WebDavPath.EscapeDataString(file.PublicLinks.First().Uri.PathAndQuery)}" // : $"{downServer.Value.Url}{Uri.EscapeDataString(file.FullPath.TrimStart('/'))}") + // $"?client_id={HttpSettings.ClientId}&token={Authent.AccessToken}"; var uri = new Uri(url); request = (HttpWebRequest)WebRequest.Create(uri.OriginalString); request.AddRange(instart, inend); request.Proxy = HttpSettings.Proxy; request.CookieContainer = Authent.Cookies; request.Method = "GET"; request.Accept = "*/*"; request.UserAgent = HttpSettings.UserAgent; request.Host = uri.Host; request.AllowWriteStreamBuffering = false; if (isLinked) { request.Headers.Add("Accept-Ranges", "bytes"); request.ContentType = MediaTypeNames.Application.Octet; request.Referer = $"{ConstSettings.CloudDomain}/home/{Uri.EscapeDataString(file.Path)}"; request.Headers.Add("Origin", ConstSettings.CloudDomain); } request.Timeout = 15 * 1000; request.ReadWriteTimeout = 15 * 1000; watch.Start(); var response = (HttpWebResponse)request.GetResponse(); return(new CustomDisposable <HttpWebResponse> { Value = response, OnDispose = () => { pendingServers.Free(downServer); watch.Stop(); Logger.Debug($"HTTP:{request.Method}:{request.RequestUri.AbsoluteUri} ({watch.Elapsed.Milliseconds} ms)"); } }); }, exception => ((exception as WebException)?.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound, exception => { pendingServers.Free(downServer); Logger.Warn($"Retrying HTTP:{request.Method}:{request.RequestUri.AbsoluteUri} on exception {exception.Message}"); }, TimeSpan.FromSeconds(1), 2); return(resp); } var stream = new DownloadStream(ResponseGenerator, afile, start, end); return(stream); }
private void TestTimeServer(string timeserverUrl) { // This test can be brittle, so we retry it first to make this more resilient to network issues Retry.Do(() => DoTestTimeServer(timeserverUrl), TimeSpan.FromSeconds(5), retryCount: 5); }
public void Delete() { Retry.Do(_deleteButton.Click); Wait.WaitForAjaxReady(By.CssSelector(".locking-mask")); }
public ServiceTermPage Create() { Retry.Do(_createButton.ClickByJS); Wait.WaitForAjaxReady(By.CssSelector(".locking-mask")); return(new ServiceTermPage()); }
public Task Delete(TEntity obj) { return(Retry.Do(() => _dbCollection.DeleteOneAsync(Builders <TEntity> .Filter.Eq("_id", obj.Id)), _configuration.RetryCount)); }
/// <remarks></remarks> private IEnumerable <CloudEntity <T> > GetInternal <T>(TableServiceContext context, string tableName, Maybe <string> filter) { string continuationRowKey = null; string continuationPartitionKey = null; var stopwatch = Stopwatch.StartNew(); context.MergeOption = MergeOption.AppendOnly; context.ResolveType = ResolveFatEntityType; do { var query = context.CreateQuery <FatEntity>(tableName); if (filter.HasValue) { query = query.AddQueryOption("$filter", filter.Value); } if (null != continuationRowKey) { query = query.AddQueryOption(NextRowKeyToken, continuationRowKey) .AddQueryOption(NextPartitionKeyToken, continuationPartitionKey); } QueryOperationResponse response = null; FatEntity[] fatEntities = null; Retry.Do(_policies.TransientTableErrorBackOff(), CancellationToken.None, () => { try { response = query.Execute() as QueryOperationResponse; fatEntities = ((IEnumerable <FatEntity>)response).ToArray(); } catch (DataServiceQueryException ex) { // if the table does not exist, there is nothing to return var errorCode = RetryPolicies.GetErrorCode(ex); if (TableErrorCodeStrings.TableNotFound == errorCode || StorageErrorCodeStrings.ResourceNotFound == errorCode) { fatEntities = new FatEntity[0]; return; } throw; } }); NotifySucceeded(StorageOperationType.TableQuery, stopwatch); foreach (var fatEntity in fatEntities) { var etag = context.Entities.First(e => e.Entity == fatEntity).ETag; context.Detach(fatEntity); yield return(FatEntity.Convert <T>(fatEntity, _serializer, etag)); } Debug.Assert(context.Entities.Count == 0); if (null != response && response.Headers.ContainsKey(ContinuationNextRowKeyToken)) { continuationRowKey = response.Headers[ContinuationNextRowKeyToken]; continuationPartitionKey = response.Headers[ContinuationNextPartitionKeyToken]; stopwatch.Restart(); } else { continuationRowKey = null; continuationPartitionKey = null; } } while (null != continuationRowKey); }
/// <summary> /// Kavita Nunse <3-Aug-2017> /// Desc: Search Single values /// </summary> /// <param name="searchFields"></param> /// <returns></returns> public bool searchLodgements(Dictionary <IWebElement, string> searchFields, Dictionary <IWebElement, string> searchColumn) { bool flag = true; bool findSubmissionDate = false; int columnIndex = 0; int submissionDateColumnIndex = 0; string columnValue = null; string submissionDateColumnValue = null; var searchCriteria = searchFields.ToList(); var column = searchColumn.ToList(); try { for (int i = 0, j = 0; i < searchCriteria.Count && j < column.Count; i++, j++) //Iterate 2 dictionaries together { // Click on Search Magnifying Icon present on My Lodgement tab LodgementPortalApp.log.LogInfo("Click on Search Magnifying Icon"); if (SearchMagnifyingIcon.FindElement(By.XPath("..")).GetAttribute("class").Contains("collapsed")) { SearchMagnifyingIcon.Click(); } LodgementPortalApp.log.LogInfo("Search Criteria is : " + column[j].Value + " AND value :" + searchCriteria[i].Value); // Select Status from dropdown if (searchCriteria[i].Key.GetAttribute("name").Equals("StatusId")) { HelperLibrary.SelectItem(searchCriteria[i].Key, searchCriteria[i].Value); findSubmissionDate = true; } // Click on show deleted checkbox else if (searchCriteria[i].Key.GetAttribute("type").Equals("checkbox")) { searchCriteria[i].Key.Click(); } else { // Enter Value to be searched searchCriteria[i].Key.Clear(); searchCriteria[i].Key.SendKeys(searchCriteria[i].Value); //MayurP added following line for period end date searchCriteria[i].Key.SendKeys(Keys.Tab); } // Click on search button SearchButton.Click(); // Get Column data if (!findSubmissionDate) { columnIndex = WebTableHelper.GetColumnIndex(searchGrid, column[j].Value); columnValue = WebTableHelper.GetCellFromTable(searchGrid, 0, columnIndex); } else // code to search and save submission date, required for searching submission date { columnIndex = WebTableHelper.GetColumnIndex(searchGrid, column[j].Value); columnValue = WebTableHelper.GetCellFromTable(searchGrid, 0, columnIndex); submissionDateColumnIndex = WebTableHelper.GetColumnIndex(searchGrid, LodgementPortalConstants.SUBMISSION_DATE); submissionDateColumnValue = WebTableHelper.GetCellFromTable(searchGrid, 0, submissionDateColumnIndex); if (submissionDateColumnValue != null) { string[] split = submissionDateColumnValue.Split(' '); HelperLibrary.RunTimeXMl.WriteNode("submissionDate", split[0]); } } if (columnValue.Contains(searchCriteria[i].Value)) { HelperLibrary.log.LogInfo(true, string.Format("Successfully Searched Record {0} with value {1} in My Lodgement tab", column[j].Value, searchCriteria[i].Value)); } else if (NoRecordFound.Displayed) { HelperLibrary.log.LogInfo(false, string.Format("Failed to Search Record {0} with value {1} in My Lodgement tab", column[j].Value, searchCriteria[i].Value)); flag = false; } // Click on Search Magnifying Icon present on My Lodgement tab SeleniumDriver.driver.FindElement(By.CssSelector(".glyphicon.glyphicon-search")); LodgementPortalApp.log.LogInfo("Click on Search Magnifying Icon"); Retry.Do(SearchMagnifyingIcon.Click); if (!searchCriteria[i].Key.GetAttribute("name").Equals("StatusId")) { searchCriteria[i].Key.Clear(); //As we do not have clear button, so we will clear field as soon as verification is done } } return(flag); } catch (Exception ex) { HelperLibrary.log.LogException(ex, ex.StackTrace); HelperLibrary.log.LogInfo("Failed to search record"); return(false); } }
public static Task WaitForStatusAsync(EdgeModule[] modules, EdgeModuleStatus desired, CancellationToken token) { string FormatModulesList() => modules.Length == 1 ? $"module '{modules.First().Id}'" : $"modules ({string.Join(", ", modules.Select(module => module.Id))})"; async Task WaitForStatusAsync() { try { await Retry.Do( async() => { string[] result = await Process.RunAsync("iotedge", "list", token); return(result .Where( ln => { var columns = ln.Split(null as char[], StringSplitOptions.RemoveEmptyEntries); foreach (var module in modules) { // each line is "name status" if (columns[0] == module.Id && columns[1].Equals(desired.ToString(), StringComparison.OrdinalIgnoreCase)) { return true; } } return false; }).ToArray()); }, a => a.Length == modules.Length, e => { // Retry if iotedged's management endpoint is still starting up, // and therefore isn't responding to `iotedge list` yet bool DaemonNotReady(string details) => details.Contains("Could not list modules", StringComparison.OrdinalIgnoreCase) || details.Contains("Socket file could not be found", StringComparison.OrdinalIgnoreCase); return(DaemonNotReady(e.ToString())); }, TimeSpan.FromSeconds(5), token); } catch (OperationCanceledException) { throw new Exception($"Error: timed out waiting for {FormatModulesList()} to start"); } catch (Exception e) { throw new Exception($"Error searching for {FormatModulesList()}: {e}"); } } return(Profiler.Run( $"Waiting for {FormatModulesList()} to enter the '{desired.ToString().ToLower()}' state", WaitForStatusAsync)); }
private RecommendCampaignResponse GetCampaignByCustomer(AuditLogEntity auditLog, string cardNo, string hasOffered, string isInterested, string customerFlag, int campaignNum) { var stopwatch = System.Diagnostics.Stopwatch.StartNew(); Logger.Debug("I:--START--:--CmtService.CampaignByCustomer--"); try { Header profile = GetHeaderByServiceName <Header>(Constants.ServiceName.CampaignByCustomer); CMT.Header2 header = new CMT.Header2 { password = profile.password, reference_no = profile.reference_no, service_name = profile.service_name, system_code = profile.system_code, transaction_date = profile.transaction_date, user_name = profile.user_name }; CMT.CampaignByCustomersRequest reqCamp = new CMT.CampaignByCustomersRequest { header = header, CampByCitizenIdBody = new CMT.ReqCampByCusEntity { CitizenId = cardNo, HasOffered = hasOffered, IsInterested = isInterested, CustomerFlag = customerFlag, Command = profile.command, RequestDate = DateTime.Now.FormatDateTime("yyyyMMdd"), Channel = profile.channel_id, CampaignNum = campaignNum, ProductTypeId = "0,2" } }; CMT.CampaignByCustomersResponse resCamp = null; #region "Call Service" string flgCatchErrorCode = string.Empty; // Avoid error codes _commonFacade = new CommonFacade(); List <string> exceptionErrorCodes = _commonFacade.GetExceptionErrorCodes(Constants.SystemName.CMT, Constants.ServiceName.CampaignByCustomer); try { Retry.Do(() => { flgCatchErrorCode = string.Empty; Logger.DebugFormat("-- XMLRequest --\n{0}", reqCamp.SerializeObject()); using (var client = new CMT.CmtServiceClient()) { resCamp = ((CMT.ICmtService)client).CampaignByCustomers(reqCamp); if (client != null) { ((ICommunicationObject)client).Abort(); } } }, TimeSpan.FromSeconds(WebConfig.GetServiceRetryInterval()), WebConfig.GetServiceRetryNo()); } catch (AggregateException aex) { aex.Handle((x) => { if (x is EndpointNotFoundException) { flgCatchErrorCode = Constants.ErrorCode.CSM0002; Logger.Error("EndpointNotFoundException occur:\n", x); return(true); } else if (x is CommunicationException) { flgCatchErrorCode = Constants.ErrorCode.CSM0002; Logger.Error("CommunicationException occur:\n", x); return(true); } else if (x is TimeoutException) { flgCatchErrorCode = Constants.ErrorCode.CSM0001; Logger.Error("TimeoutException occur:\n", x); return(true); } else { flgCatchErrorCode = Constants.ErrorCode.CSM0003; Logger.Error("Exception occur:\n", x); return(true); } }); } if (!string.IsNullOrEmpty(flgCatchErrorCode)) { AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(flgCatchErrorCode, true)); throw new CustomException(GetMessageResource(flgCatchErrorCode, false)); } #endregion if (resCamp != null) { Logger.DebugFormat("-- XMLResponse --\n{0}", resCamp.SerializeObject()); RecommendCampaignResponse response = new RecommendCampaignResponse(); response.StatusResponse.Status = resCamp.status.status; response.StatusResponse.ErrorCode = resCamp.status.error_code; response.StatusResponse.Description = resCamp.status.description; if (exceptionErrorCodes != null && exceptionErrorCodes.Contains(resCamp.status.error_code)) { response.StatusResponse.Status = Constants.StatusResponse.Success; } if (Constants.StatusResponse.Success.Equals(response.StatusResponse.Status)) { if (resCamp.detail != null) { response.CitizenId = resCamp.detail.CitizenId; if (resCamp.detail.CitizenIds != null && resCamp.detail.CitizenIds.Count() > 0) { var results = resCamp.detail.CitizenIds.Where(x => x != null).Select(x => new CampaignDetail { CampaignCriteria = x.CampaignCreiteria, CampaignDesc = x.CampaignDescription, CampaignId = x.CampaignId, CampaignName = x.CampaignName, CampaignOffer = x.CampaignOffer, CampaignScore = x.CampaignScore, Channel = x.Channel, CitizenIds = x.CitizenIds, DescCust = x.DescCust, StrExpireDate = x.ExpireDate, IsInterested = x.IsInterested, ContractNoRefer = x.ContractNo, ProductTypeId = x.ProductTypeId, ProductTypeName = x.ProductTypeName }); response.RecommendCampaignDetails = results.OrderBy(x => x.ExpireDate).ToList(); } } AppLog.AuditLog(auditLog, LogStatus.Success, string.Empty); return(response); } // Log DB AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(Constants.SystemName.CMT, Constants.ServiceName.CampaignByCustomer, response.StatusResponse.ErrorCode, true)); throw new CustomException(GetMessageResource(Constants.SystemName.CMT, Constants.ServiceName.CampaignByCustomer, response.StatusResponse.ErrorCode, false)); } } finally { stopwatch.Stop(); Logger.DebugFormat("O:--Finish--:ElapsedMilliseconds/{0}", stopwatch.ElapsedMilliseconds); } return(null); }
private Ticket InsertLead(AuditLogEntity auditLog, CampaignSearchFilter searchFilter) { var stopwatch = System.Diagnostics.Stopwatch.StartNew(); Logger.Debug("I:--START--:--LeadService.InsertLead--"); try { Header profile = GetHeaderByServiceName <Header>(Constants.ServiceName.InsertLead); SLM.InsertLeadRequest reqLead = new SLM.InsertLeadRequest(); reqLead.RequestHeader = new SLM.Header { ChannelID = profile.channel_id, Encoding = "", Username = profile.user_name, Password = profile.password, Version = "" }; DataSet ds = ReadInsertLeadXml(); DataTable dtMandatory = ds.Tables["mandatory"]; dtMandatory.Rows[0]["firstname"] = searchFilter.FirstName; dtMandatory.Rows[0]["telNo1"] = searchFilter.PhoneNo; dtMandatory.Rows[0]["campaign"] = searchFilter.CampaignId; DataTable dtCustomerInfo = ds.Tables["customerInfo"]; dtCustomerInfo.Rows[0]["lastname"] = searchFilter.LastName; dtCustomerInfo.Rows[0]["email"] = searchFilter.Email; dtCustomerInfo.Rows[0]["cid"] = searchFilter.CardNo; dtCustomerInfo.Rows[0]["contractNoRefer"] = searchFilter.ContractNoRefer ?? string.Empty; DataTable dtCustomerDetail = ds.Tables["customerDetail"]; dtCustomerDetail.Rows[0]["availableTime"] = searchFilter.AvailableTime.ToSLMTimeFormat(); dtCustomerDetail.Rows[0]["detail"] = searchFilter.Comments; DataTable dtAppInfo = ds.Tables["appInfo"]; dtAppInfo.Rows[0]["lastOwner"] = searchFilter.OwnerLeadCode; reqLead.RequestXml = ds.ToXml(); SLM.InsertLeadResponse resLead = null; #region "Call Service" string flgCatchErrorCode = string.Empty; try { Retry.Do(() => { flgCatchErrorCode = string.Empty; Logger.DebugFormat("-- XMLRequest --\n{0}", reqLead.SerializeObject()); using (var client = new SLM.LeadServiceClient()) { resLead = ((SLM.ILeadService)client).InsertLead(reqLead); if (client != null) { ((ICommunicationObject)client).Abort(); } } }, TimeSpan.FromSeconds(WebConfig.GetServiceRetryInterval()), WebConfig.GetServiceRetryNo()); } catch (AggregateException aex) { aex.Handle((x) => { if (x is EndpointNotFoundException) { flgCatchErrorCode = Constants.ErrorCode.CSM0002; Logger.Error("EndpointNotFoundException occur:\n", x); return(true); } else if (x is CommunicationException) { flgCatchErrorCode = Constants.ErrorCode.CSM0002; Logger.Error("CommunicationException occur:\n", x); return(true); } else if (x is TimeoutException) { flgCatchErrorCode = Constants.ErrorCode.CSM0001; Logger.Error("TimeoutException occur:\n", x); return(true); } else { flgCatchErrorCode = Constants.ErrorCode.CSM0003; Logger.Error("Exception occur:\n", x); return(true); } }); } if (!string.IsNullOrEmpty(flgCatchErrorCode)) { AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(flgCatchErrorCode, true)); throw new CustomException(GetMessageResource(flgCatchErrorCode, false)); } #endregion if (resLead != null) { Logger.DebugFormat("-- XMLResponse --\n{0}", resLead.SerializeObject()); var xdoc = XDocument.Parse(resLead.ResponseStatus); Ticket ticket = (xdoc.Descendants("ticket") .Select(x => new Ticket { TicketId = x.Attribute("id").Value, ResponseCode = x.Element("responseCode").Value, ResponseMessage = x.Element("responseMessage").Value, StrResponseDate = x.Element("responseDate").Value, StrResponseTime = x.Element("responseTime").Value, })).FirstOrDefault(); if (Constants.TicketResponse.SLM_Success.Equals(ticket.ResponseCode)) { AppLog.AuditLog(auditLog, LogStatus.Success, string.Empty); return(ticket); } // Log DB AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(Constants.SystemName.SLM, Constants.ServiceName.InsertLead, ticket.ResponseCode, true)); throw new CustomException(GetMessageResource(Constants.SystemName.SLM, Constants.ServiceName.InsertLead, ticket.ResponseCode, false)); } } finally { stopwatch.Stop(); Logger.DebugFormat("O:--Finish--:ElapsedMilliseconds/{0}", stopwatch.ElapsedMilliseconds); } return(null); }
private UpdateCampaignFlagsResponse UpdateCampaignFlagsByCustomer(AuditLogEntity auditLog, string cardNo, CampaignSearchFilter searchFilter) { var stopwatch = System.Diagnostics.Stopwatch.StartNew(); Logger.Debug("I:--START--:--CmtService.UpdateCustomerFlags--"); try { Header profile = GetHeaderByServiceName <Header>(Constants.ServiceName.CampaignByCustomer); var criteria = new CMT.UpdInquiry { CampaignId = searchFilter.CampaignId, HasOffered = searchFilter.HasOffered, IsInterested = searchFilter.IsInterested, UpdatedBy = searchFilter.UpdatedBy, Comments = searchFilter.Comments, Command = profile.command }; CMT.UpdateCustomerFlagsRequest reqCamp = new CMT.UpdateCustomerFlagsRequest { header = new CMT.Header { password = profile.password, reference_no = profile.reference_no, service_name = profile.service_name, system_code = profile.system_code, transaction_date = profile.transaction_date, user_name = profile.user_name }, UpdateCustFlag = new CMT.ReqUpdFlagEntity { CitizenId = cardNo, UpdInquiries = new CMT.UpdInquiry[] { criteria } } }; CMT.UpdateCustomerFlagsResponse resCamp = null; #region "Call Service" string flgCatchErrorCode = string.Empty; try { Retry.Do(() => { flgCatchErrorCode = string.Empty; Logger.DebugFormat("-- XMLRequest --\n{0}", reqCamp.SerializeObject()); using (var client = new CMT.CmtServiceClient()) { resCamp = ((CMT.ICmtService)client).UpdateCustomerFlags(reqCamp); if (client != null) { ((ICommunicationObject)client).Abort(); } } }, TimeSpan.FromSeconds(WebConfig.GetServiceRetryInterval()), WebConfig.GetServiceRetryNo()); } catch (AggregateException aex) { aex.Handle((x) => { if (x is EndpointNotFoundException) { flgCatchErrorCode = Constants.ErrorCode.CSM0002; Logger.Error("EndpointNotFoundException occur:\n", x); return(true); } else if (x is CommunicationException) { flgCatchErrorCode = Constants.ErrorCode.CSM0002; Logger.Error("CommunicationException occur:\n", x); return(true); } else if (x is TimeoutException) { flgCatchErrorCode = Constants.ErrorCode.CSM0001; Logger.Error("TimeoutException occur:\n", x); return(true); } else { flgCatchErrorCode = Constants.ErrorCode.CSM0003; Logger.Error("Exception occur:\n", x); return(true); } }); } if (!string.IsNullOrEmpty(flgCatchErrorCode)) { AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(flgCatchErrorCode, true)); throw new CustomException(GetMessageResource(flgCatchErrorCode, false)); } #endregion if (resCamp != null) { Logger.DebugFormat("-- XMLResponse --\n{0}", resCamp.SerializeObject()); UpdateCampaignFlagsResponse response = new UpdateCampaignFlagsResponse(); response.StatusResponse.Status = resCamp.status.status; response.StatusResponse.ErrorCode = resCamp.status.error_code; response.StatusResponse.Description = resCamp.status.description; if (Constants.StatusResponse.Success.Equals(response.StatusResponse.Status)) { response.CitizenId = resCamp.detail.CitizenId; if (resCamp.detail.Result != null) { response.UpdateStatus = resCamp.detail.Result.UpdateStatus; } AppLog.AuditLog(auditLog, LogStatus.Success, string.Empty); return(response); } // Log DB AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(Constants.SystemName.CMT, Constants.ServiceName.UpdateCustomerFlags, response.StatusResponse.ErrorCode, true)); throw new CustomException(GetMessageResource(Constants.SystemName.CMT, Constants.ServiceName.UpdateCustomerFlags, response.StatusResponse.ErrorCode, false)); } } finally { stopwatch.Stop(); Logger.DebugFormat("O:--Finish--:ElapsedMilliseconds/{0}", stopwatch.ElapsedMilliseconds); } return(null); }
private Course ExtractCourse() { Course course = new Course(); UpdateUI(() => lblCurrentOperation.Text = "Logging in"); Browser browser = GetFromUI <Browser>(() => cmboxBrowser.SelectedIndex); Log.Information("Logging in"); Extractor.InitializeDriver(browser); try { Extractor.Login(txtToken.Text, txtCourseUrl.Text).Wait(); Log.Information("Logged in with course url : {0} and token of {1} characters", GetFromUI <string>(() => txtCourseUrl.Text), GetFromUI <int>(() => txtToken.Text.Length)); UpdateUI(() => { lblCurrentOperation.Text = "Logged in successfully"; UC_IsLoggedin.IsLoggedin = true; }); } catch (InvalidTokenException ex) { MessageBox.Show("The token or the course url you provided is invalid.\nPlease make sure you entered the right token and course url", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error); UpdateUI(() => { EnableControls(true); lblCurrentOperation.Text = "Login Failed"; }); Log.Error(ex, "Failed to log in with course url : {0} and token of {1} characters", GetFromUI <string>(() => txtCourseUrl.Text), GetFromUI <int>(() => txtToken.Text.Length)); return(null); } catch (Exception e) when(e.InnerException is InvalidTokenException ex) { MessageBox.Show("The token or the course url you provided is invalid.\nPlease make sure you entered the right token and course url", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error); UpdateUI(() => { EnableControls(true); lblCurrentOperation.Text = "Login Failed"; }); Log.Error(ex, "Failed to log in with course url : {0} and token of {1} characters", GetFromUI <string>(() => txtCourseUrl.Text), GetFromUI <int>(() => txtToken.Text.Length)); return(null); } catch (Exception ex) { Log.Error(ex, "Unknown Exception"); throw ex; } UpdateUI(() => { lblCurrentOperation.Text = "Starting Course Extractor"; UC_CourseExtractorStatus.Status = CourseStatus.Starting; }); Extractor.ExtractCourseStructure(out _videosCount); Quality quality = GetFromUI <Quality>(() => cmboxQuality.SelectedIndex); UpdateUI(() => { lblCurrentOperation.Text = $"Extracting Course...[0/{_videosCount}]"; UC_CourseExtractorStatus.Status = CourseStatus.Running; }); bool isExtracted = true; Retry.Do( function: () => { Extractor.ExtractionProgressChanged += Extractor_ExtractionProgressChanged; course = Extractor.ExtractCourse(quality); }, exceptionMessage: "An error occured while extracting the course", actionOnError: () => { MessageBox.Show($"An error occured while extracting the course.\nTrying again", "Unknown Error", MessageBoxButtons.OK, MessageBoxIcon.Error); UpdateUI(() => { progressBar.Value = 0; _currentVideoIndex = 0; Extractor.ExtractionProgressChanged -= Extractor_ExtractionProgressChanged; }); Extractor.CloseTabs(); }, actionOnFatal: () => { Extractor.KillDrivers(); UpdateUI(() => { EnableControls(true); UC_CourseExtractorStatus.Status = CourseStatus.Failed; lblCurrentOperation.Text = "Course Extraction Failed"; }); isExtracted = false; }); if (!isExtracted) { return(null); } UpdateUI(() => { lblCurrentOperation.Text = "Course Extracted Successfully"; UC_CourseExtractorStatus.Status = CourseStatus.Finished; }); return(course); }
/// <remarks>Upsert is making several storage calls to emulate the /// missing semantic from the Table Storage.</remarks> void UpsertInternal <T>(string tableName, IEnumerable <CloudEntity <T> > entities) { var context = _tableStorage.GetTableServiceContext(); context.MergeOption = MergeOption.AppendOnly; context.ResolveType = ResolveFatEntityType; var stopwatch = new Stopwatch(); var fatEntities = entities.Select(e => Tuple.Create(FatEntity.Convert(e, _serializer), e)); var noBatchMode = false; foreach (var slice in SliceEntities(fatEntities, e => e.Item1.GetPayload())) { stopwatch.Restart(); var cloudEntityOfFatEntity = new Dictionary <object, CloudEntity <T> >(); foreach (var fatEntity in slice) { // entities should be updated in a single round-trip context.AttachTo(tableName, fatEntity.Item1); context.UpdateObject(fatEntity.Item1); cloudEntityOfFatEntity.Add(fatEntity.Item1, fatEntity.Item2); } Retry.Do(_policies.TransientTableErrorBackOff(), CancellationToken.None, () => { try { context.SaveChanges(noBatchMode ? SaveChangesOptions.ReplaceOnUpdate : SaveChangesOptions.ReplaceOnUpdate | SaveChangesOptions.Batch); ReadETagsAndDetach(context, (entity, etag) => cloudEntityOfFatEntity[entity].ETag = etag); } catch (DataServiceRequestException ex) { var errorCode = RetryPolicies.GetErrorCode(ex); if (errorCode == StorageErrorCodeStrings.OperationTimedOut) { // if batch does not work, then split into elementary requests // PERF: it would be better to split the request in two and retry context.SaveChanges(SaveChangesOptions.ReplaceOnUpdate); ReadETagsAndDetach(context, (entity, etag) => cloudEntityOfFatEntity[entity].ETag = etag); noBatchMode = true; } else if (errorCode == TableErrorCodeStrings.TableNotFound) { Retry.Do(_policies.SlowInstantiation(), CancellationToken.None, () => { try { var table = _tableStorage.GetTableReference(tableName); table.CreateIfNotExists(); } // HACK: incorrect behavior of the StorageClient (2010-09) // Fails to behave properly in multi-threaded situations catch (StorageException cex) { var extended = cex.RequestInformation != null ? cex.RequestInformation.ExtendedErrorInformation : null; if (extended == null || extended.ErrorCode != TableErrorCodeStrings.TableAlreadyExists) { throw; } } context.SaveChanges(noBatchMode ? SaveChangesOptions.ReplaceOnUpdate : SaveChangesOptions.ReplaceOnUpdate | SaveChangesOptions.Batch); ReadETagsAndDetach(context, (entity, etag) => cloudEntityOfFatEntity[entity].ETag = etag); }); } else if (errorCode == StorageErrorCodeStrings.ResourceNotFound) { throw new InvalidOperationException("Cannot call update on a resource that does not exist", ex); } else { throw; } } catch (DataServiceQueryException ex) { // HACK: code duplicated var errorCode = RetryPolicies.GetErrorCode(ex); if (errorCode == StorageErrorCodeStrings.OperationTimedOut) { // if batch does not work, then split into elementary requests // PERF: it would be better to split the request in two and retry context.SaveChanges(SaveChangesOptions.ReplaceOnUpdate); ReadETagsAndDetach(context, (entity, etag) => cloudEntityOfFatEntity[entity].ETag = etag); noBatchMode = true; } else { throw; } } }); NotifySucceeded(StorageOperationType.TableUpsert, stopwatch); } }
public T Query <T>(IQuery <T> query) => Retry.Do(() => query.Execute(_connection, _transaction), _retryOptions);
/// <remarks></remarks> void DeleteInternal <T>(string tableName, string partitionKey, IEnumerable <Tuple <string, string> > rowKeysAndETags, bool force) { var context = _tableStorage.GetTableServiceContext(); var stopwatch = new Stopwatch(); // CAUTION: make sure to get rid of potential duplicate in rowkeys. // (otherwise insertion in 'context' is likely to fail) foreach (var s in Slice(rowKeysAndETags // Similar effect than 'Distinct' based on 'RowKey' .ToLookup(p => p.Item1, p => p).Select(g => g.First()), MaxEntityTransactionCount)) { stopwatch.Restart(); var slice = s; DeletionStart: // 'slice' might have been refreshed if some entities were already deleted foreach (var rowKeyAndETag in slice) { // Deleting entities in 1 roundtrip // http://blog.smarx.com/posts/deleting-entities-from-windows-azure-without-querying-first var mock = new FatEntity { PartitionKey = partitionKey, RowKey = rowKeyAndETag.Item1 }; context.AttachTo(tableName, mock, rowKeyAndETag.Item2); context.DeleteObject(mock); } try // HACK: [vermorel] if a single entity is missing, then the whole batch operation is aborded { try // HACK: nested try/catch to handle the special case where the table is missing { Retry.Do(_policies.TransientTableErrorBackOff(), CancellationToken.None, () => context.SaveChanges(SaveChangesOptions.Batch)); } catch (DataServiceRequestException ex) { // if the table is missing, no need to go on with the deletion var errorCode = RetryPolicies.GetErrorCode(ex); if (TableErrorCodeStrings.TableNotFound == errorCode) { NotifySucceeded(StorageOperationType.TableDelete, stopwatch); return; } throw; } } // if some entities exist catch (DataServiceRequestException ex) { var errorCode = RetryPolicies.GetErrorCode(ex); // HACK: Table Storage both implement a bizarre non-idempotent semantic // but in addition, it throws a non-documented exception as well. if (errorCode != "ResourceNotFound") { throw; } slice = Get <T>(tableName, partitionKey, slice.Select(p => p.Item1)) .Select(e => Tuple.Create(e.RowKey, MapETag(e.ETag, force))).ToArray(); // entities with same name will be added again context = _tableStorage.GetTableServiceContext(); // HACK: [vermorel] yes, gotos are horrid, but other solutions are worst here. goto DeletionStart; } NotifySucceeded(StorageOperationType.TableDelete, stopwatch); } }
public void Return_Given_Value(string returnValue, int maxRetry) { var result = Retry.Do(() => returnValue, TimeSpan.Zero, maxRetry); Assert.Equal(returnValue, result); }
public SearchResultsComponent(BaseComponent parent) : base(parent) { Retry.Do(Initialise); }
private Ticket SearchLead(AuditLogEntity auditLog, string cardNo) { var stopwatch = System.Diagnostics.Stopwatch.StartNew(); Logger.Debug("I:--START--:--COCService.SearchLead--"); try { Header profile = GetHeaderByServiceName <Header>(Constants.ServiceName.SearchLead); COC.ServiceRequest reqLead = new COC.ServiceRequest(); reqLead.RequestHeader = new COC.Header { ChannelID = profile.channel_id, Username = profile.user_name, Password = profile.password, System = profile.system_code }; DataSet ds = ReadSearchLeadXml(); DataTable dt = ds.Tables[0]; dt.Rows[0]["cid"] = cardNo; dt.Rows[0]["firstname"] = ""; dt.Rows[0]["lastname"] = ""; dt.Rows[0]["status"] = ""; dt.Rows[0]["productGroupId"] = ""; dt.Rows[0]["productId"] = ""; dt.Rows[0]["maxRecord"] = "30"; reqLead.RequestXml = ds.ToXml(); COC.ServiceResponse resLead = null; #region "Call Service" string flgCatchErrorCode = string.Empty; // Avoid error codes _commonFacade = new CommonFacade(); List <string> exceptionErrorCodes = _commonFacade.GetExceptionErrorCodes(Constants.SystemName.COC, Constants.ServiceName.SearchLead); try { Retry.Do(() => { flgCatchErrorCode = string.Empty; Logger.DebugFormat("-- XMLRequest --\n{0}", reqLead.SerializeObject()); using (var client = new COC.ServiceClient()) { resLead = ((COC.IService)client).SearchLead(reqLead); if (client != null) { ((ICommunicationObject)client).Abort(); } } }, TimeSpan.FromSeconds(WebConfig.GetServiceRetryInterval()), WebConfig.GetServiceRetryNo()); } catch (AggregateException aex) { aex.Handle((x) => { if (x is EndpointNotFoundException) { flgCatchErrorCode = Constants.ErrorCode.CSM0002; Logger.Error("EndpointNotFoundException occur:\n", x); return(true); } else if (x is CommunicationException) { flgCatchErrorCode = Constants.ErrorCode.CSM0002; Logger.Error("CommunicationException occur:\n", x); return(true); } else if (x is TimeoutException) { flgCatchErrorCode = Constants.ErrorCode.CSM0001; Logger.Error("TimeoutException occur:\n", x); return(true); } else { flgCatchErrorCode = Constants.ErrorCode.CSM0003; Logger.Error("Exception occur:\n", x); return(true); } }); } if (!string.IsNullOrEmpty(flgCatchErrorCode)) { AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(flgCatchErrorCode, true)); throw new CustomException(GetMessageResource(flgCatchErrorCode, false)); } #endregion if (resLead != null) { Logger.DebugFormat("-- XMLResponse --\n{0}", resLead.SerializeObject()); var xdoc = XDocument.Parse(resLead.ResponseXml); Ticket ticket = (xdoc.Descendants("ticket") .Select(x => new Ticket { TicketId = x.Attribute("id").Value, ResponseCode = x.Element("responseCode").Value, ResponseMessage = x.Element("responseMessage").Value, StrResponseDate = x.Element("responseDate").Value, StrResponseTime = x.Element("responseTime").Value, TotalLeads = x.Element("totalLeads") == null ? string.Empty : x.Element("totalLeads").Value })).FirstOrDefault(); if (exceptionErrorCodes != null && exceptionErrorCodes.Contains(ticket.ResponseCode)) { ticket.ResponseCode = Constants.TicketResponse.COCSuccess; } if (Constants.TicketResponse.COCSuccess.Equals(ticket.ResponseCode)) { List <TicketItem> items = null; if (xdoc.Descendants("result") != null && xdoc.Descendants("result").Count() > 0) { items = xdoc.Descendants("result") .Select(x => new TicketItem { TicketId = x.Element("ticketId").Value, CardNo = x.Element("cid").Value, FirstName = x.Element("firstname").Value, LastName = x.Element("lastname").Value, TelNo1 = x.Element("telNo1").Value, Status = x.Element("status").Value, StatusDesc = x.Element("statusDesc").Value, CampaignCode = x.Element("campaign").Value, CampaignDesc = x.Element("campaignDesc").Value, ProductGroupId = x.Element("productGroupId").Value, ProductGroupDesc = x.Element("productGroupDesc").Value, ProductId = x.Element("productId").Value, ProductDesc = x.Element("productDesc").Value, ChannelId = x.Element("channelId").Value, OwnerLead = x.Element("ownerLead").Value, OwnerLeadName = x.Element("ownerLeadName").Value, DelegateLead = x.Element("delegateLead").Value, DelegateLeadName = x.Element("delegateLeadName").Value, CreatedUser = x.Element("createdUser").Value, CreatedUserName = x.Element("createdUserName").Value, StrCreatedDate = x.Element("createdDate").Value, StrCreatedTime = x.Element("createdTime").Value, StrAssignedDate = x.Element("assignedDate").Value, StrAssignedTime = x.Element("assignedTime").Value, OwnerBranch = x.Element("ownerBranch").Value, OwnerBranchName = x.Element("ownerBranchName").Value, DelegateBranch = x.Element("delegateBranch").Value, DelegateBranchName = x.Element("delegateBranchName").Value, CreatedBranch = x.Element("createdBranch").Value, CreatedBranchName = x.Element("createdBranchName").Value }).ToList(); } ticket.Items = items; AppLog.AuditLog(auditLog, LogStatus.Success, string.Empty); return(ticket); } // Log DB AppLog.AuditLog(auditLog, LogStatus.Fail, GetMessageResource(Constants.SystemName.COC, Constants.ServiceName.SearchLead, ticket.ResponseCode, true)); throw new CustomException(GetMessageResource(Constants.SystemName.COC, Constants.ServiceName.SearchLead, ticket.ResponseCode, false)); } } finally { stopwatch.Stop(); Logger.DebugFormat("O:--Finish--:ElapsedMilliseconds/{0}", stopwatch.ElapsedMilliseconds); } return(null); }
protected override bool HasWorkItems(Changeset changeset) { return(Retry.Do(() => changeset.AssociatedWorkItems.Length > 0)); }
public void Test_Parallel_Signing() { // This test can be brittle, so we retry it first to make this more resilient to issues Retry.Do(DoParallelSigning, TimeSpan.FromSeconds(5), retryCount: 5); }
public override IIdentity GetIdentity(string username) { return(_bridge.Wrap <WrapperForIdentity, Identity>(Retry.Do(() => GroupSecurityService.ReadIdentity(SearchFactor.AccountName, username, QueryMembership.None)))); }
public async Task <IEntry> FolderInfo(RemotePath path, int offset = 0, int limit = Int32.MaxValue, int depth = 1) { if (path.IsLink) { throw new NotImplementedException(nameof(FolderInfo)); } if (path.Path.StartsWith(YadMediaPath)) { return(await MediaFolderInfo(path.Path)); } // YaD perform async deletion YadResponseModel <YadItemInfoRequestData, YadItemInfoRequestParams> itemInfo = null; YadResponseModel <YadFolderInfoRequestData, YadFolderInfoRequestParams> folderInfo = null; YadResponseModel <YadResourceStatsRequestData, YadResourceStatsRequestParams> resourceStats = null; bool hasRemoveOp = _lastRemoveOperation != null && WebDavPath.IsParentOrSame(path.Path, _lastRemoveOperation.Path) && (DateTime.Now - _lastRemoveOperation.DateTime).TotalMilliseconds < 1_000; Retry.Do( () => { var doPreSleep = hasRemoveOp ? TimeSpan.FromMilliseconds(OperationStatusCheckIntervalMs) : TimeSpan.Zero; if (doPreSleep > TimeSpan.Zero) { Logger.Debug("Has remove op, sleep before"); } return(doPreSleep); }, () => new YaDCommonRequest(HttpSettings, (YadWebAuth)Authent) .With(new YadItemInfoPostModel(path.Path), out itemInfo) .With(new YadFolderInfoPostModel(path.Path), out folderInfo) .With(new YadResourceStatsPostModel(path.Path), out resourceStats) .MakeRequestAsync() .Result, resp => { var doAgain = hasRemoveOp && folderInfo.Data.Resources.Any(r => WebDavPath.PathEquals(r.Path.Remove(0, "/disk".Length), _lastRemoveOperation.Path)); if (doAgain) { Logger.Debug("Remove op still not finished, let's try again"); } return(doAgain); }, TimeSpan.FromMilliseconds(OperationStatusCheckIntervalMs), OperationStatusCheckRetryCount); var itdata = itemInfo?.Data; switch (itdata?.Type) { case null: return(null); case "file": return(itdata.ToFile(PublicBaseUrlDefault)); default: { var entry = folderInfo.Data.ToFolder(itemInfo.Data, resourceStats.Data, path.Path, PublicBaseUrlDefault); return(entry); } } }
private async Task DownloadCourse(Course course) { try { _videosCount = course.Chapters.SelectMany(ch => ch.Videos).Count(); var courseDirectory = _courseRootDirectory.CreateSubdirectory(ToSafeFileName(course.Title)); int i = 1; foreach (var chapter in course.Chapters) { var chapterDirectory = courseDirectory.CreateSubdirectory($"[{i}] {ToSafeFileName(chapter.Title)}"); int j = 1; foreach (var video in chapter.Videos) { if (_cancellationToken.IsCancellationRequested) { return; } await Retry.Do(async() => { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; lblVideo.Text = video.Title + " - [Chapter " + i + "]"; lblCourse.Text = _currentVideoIndex++ + "/" + _videosCount; string videoName = $"[{j}] { ToSafeFileName(video.Title)}.mp4"; if (String.IsNullOrWhiteSpace(video.Transcript)) { string captionName = $"[{j}] { ToSafeFileName(video.Title)}.srt"; await SaveSubtitles(Path.Combine(chapterDirectory.FullName, ToSafeFileName(captionName)), video.Transcript); } using (var fileStream = File.Create(Path.Combine(chapterDirectory.FullName, videoName))) { await _downloader.DownloadFileAsync(new Uri(video.DownloadUrl), fileStream, _cancellationToken, DownloadProgressChanged); } if (_currentVideoIndex <= _videosCount) { UpdateUI(() => progressBarCourse.Value = _currentVideoIndex * 100 / _videosCount); } }, exceptionMessage : "Failed to download video with title " + video.Title, actionOnError : () => { UpdateUI(() => progressBarVideo.Value = 0); _currentVideoIndex--; }, actionOnFatal : () => { DownloaderStatus = CourseStatus.Failed; Close(); }); j++; } i++; } if (_toDownloadExerciseFiles && course.ExerciseFiles != null && course.ExerciseFiles.Count > 0) { await DownloadExerciseFiles(course, courseDirectory); } } catch (Exception ex) { DownloaderStatus = CourseStatus.Failed; Close(); throw ex; } }