public void UpsertPayoutHeader(Payout payout) { var existingPayout = _persistRepository.RetrievePayout(payout.id); if (existingPayout != null) { _persistRepository .UpdatePayoutHeader( payout.id, payout.SerializeToJson(), payout.status); _logger.Debug($"Shopify Payout Header {payout.id} found - updating status and skipping!"); return; } else { _logger.Debug($"Creating record for Shopify Payout Header {payout.id}"); var newPayout = new ShopifyPayout() { ShopifyPayoutId = payout.id, ShopifyLastStatus = payout.status, Json = payout.SerializeToJson(), CreatedDate = DateTime.UtcNow, LastUpdated = DateTime.UtcNow, AllTransDownloaded = false, }; _persistRepository.InsertPayoutHeader(newPayout); } }
public virtual ResponseEnvelope Get( string url, Dictionary <string, string> headers = null, string contentType = "application/json; charset=utf-8") { _logger.Debug($"HTTP GET on {url}"); var response = _executor.Do(() => _client.GetAsync(url).Result); return(response.ToEnvelope()); }
public string InsertImportBankTransaction(string content) { var response = _clientFacade.Put("ImportBankTransactions", content); _logger.Debug(content); return(response.Body); }
public void Log(string content, int level = LogLevel.Information) { try { if (level == LogLevel.Information) { _logger.Info(content); } if (level == LogLevel.Debug) { _logger.Debug(content); } if (level == LogLevel.Error) { _logger.Error(content); } var logEntry = new ExecutionLog(); logEntry.LogContent = content; logEntry.LogLevel = level; logEntry.DateCreated = DateTime.UtcNow; Entities.ExecutionLogs.Add(logEntry); Entities.SaveChanges(); } catch (Exception ex) { // Swallow the exception! - this is a logger // _logger.Info($"Failed attempt to add Execution Log ({level}) {content}"); _logger.Error(ex); } }
RetrievePayoutDetail(long?payout_id = null, long?since_id = null, int limit = 50) { var builder = new QueryStringBuilder(); if (payout_id.HasValue) { builder.Add("payout_id", payout_id.Value); } if (since_id.HasValue) { builder.Add("since_id", since_id.Value); } builder.Add("limit", limit); builder.Add("order", "created asc"); var queryString = builder.ToString(); var path = $"/admin/shopify_payments/balance/transactions.json?{queryString}"; var clientResponse = _httpClient.Get(path); _logger.Debug($"{clientResponse.Body}"); var output = clientResponse.Body; return(output); }
public void OrderSyncInChildScope(ConcurrentQueue <long> queue) { // NOTE: it's necessary to catch Exceptions, because this is running in its own thread try { var instanceId = _connectionContext.InstanceId; var monitorId = _monitoringService.CurrentScopeMonitorId; using (var childScope = _lifetimeScope.BeginLifetimeScope()) { var childConnectionContext = childScope.Resolve <InstanceContext>(); var childAcumaticaContext = childScope.Resolve <AcumaticaHttpContext>(); var childOrderSync = childScope.Resolve <AcumaticaOrderPut>(); var monitoringService = childScope.Resolve <JobMonitoringService>(); _logger.Debug( $"OrderSyncInChildScope - Acumatica Context: {childAcumaticaContext.ObjectIdentifier}"); childConnectionContext.Initialize(instanceId); monitoringService.RegisterCurrentScopeMonitorId(monitorId); childAcumaticaContext.SessionRun(() => childOrderSync.RunQueue(queue)); } } catch (Exception ex) { // NOTE => must do this, as an uncaught exception will bring the entire process down // _logger.Error(ex); } }
public ResponseEnvelope Get(string url, Dictionary <string, string> headers = null) { var urlDebug = $"HTTP GET on {url}"; var errorContext = BuildErrorContext(urlDebug); _logger.Debug(urlDebug); // Act var response = _executor.Do(() => _httpClient.GetAsync(url).Result, errorContext); // Process var output = response.ToEnvelope(); _logger.Trace(output.Body); ProcessStatusCodes(output, errorContext); return(output); }
private void RunPriceCostWeightUpdates() { var stockItems = _syncInventoryRepository.RetrieveStockItemsNotSynced(); foreach (var stockItem in stockItems) { var readyToSync = MakeSyncStatus(stockItem).ReadyToSyncPrice(); if (!readyToSync.Success) { _logger.Debug($"Skipping PriceUpdate for {stockItem.ItemId}"); continue; } _executionLogService.Log(LogBuilder.UpdateShopifyPrice(stockItem)); UpdatePriceAndCost(stockItem); } }
public ResponseEnvelope Get( string path, Dictionary <string, string> headers = null, bool excludeVersion = false) { // Arrange var address = MakeFinalUrl(path, excludeVersion); var urlDebug = $"HTTP GET on {address} (ContextId: {this.ObjectIdentifier})"; var errorContext = BuildErrorContext(urlDebug); _logger.Debug(urlDebug); // Act var response = _executor.Do(() => _httpClient.GetAsync(address).Result, errorContext); // Response var output = response.ToEnvelope(); _logger.Trace(output.Body); // Assert return(ProcessStatusCodes(output, urlDebug)); }
public void Intercept(IInvocation invocation) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); invocation.Proceed(); // Lovely but unnecessarily complicated! //var proxyTarget = (invocation.Proxy as IProxyTargetAccessor); //var typeName = (proxyTarget != null) // ? proxyTarget.DynProxyGetTarget().GetType().Name // : invocation.InvocationTarget.GetType().Name; TimeSpan ts = stopWatch.Elapsed; _pushLogger.Debug($"{invocation.TargetType.Name}.{invocation.Method.Name} - metered execution time {ts.ToFormattedString()}"); }
public bool Log(LogLevel logLevel, Func <string> messageFunc, Exception exception = null) { if (_logger == null) { return(false); } if (messageFunc == null && exception == null) { return(true); } if (logLevel == LogLevel.Trace && _logger.IsTraceEnabled) { _logger.Trace(messageFunc()); } if (logLevel == LogLevel.Debug && _logger.IsDebugEnabled) { _logger.Debug(messageFunc()); } if (logLevel == LogLevel.Info && _logger.IsInfoEnabled) { _logger.Info(messageFunc()); } if (logLevel == LogLevel.Warn && _logger.IsWarnEnabled) { _logger.Warn(messageFunc()); } if (logLevel == LogLevel.Error && _logger.IsErrorEnabled) { var message = messageFunc(); if (!message.IsNullOrEmpty()) { _logger.Error(message); } _logger.Error(exception); } if (logLevel == LogLevel.Fatal && _logger.IsFatalEnabled) { _logger.Fatal(messageFunc()); } return(true); }
public void ProcessMissingVariant(ShopifyVariant variantRecord) { var log = $"Shopify Variant {variantRecord.ShopifySku} ({variantRecord.ShopifyVariantId}) is missing"; _logger.Debug(log); using (var transaction = _inventoryRepository.BeginTransaction()) { // Flag as Missing and destroy synchronization // variantRecord.IsMissing = true; var stockItemRecord = variantRecord.AcumaticaStockItems.FirstOrDefault(); if (stockItemRecord != null) { // Remove the synchronization // stockItemRecord.ShopifyVariant = null; // Locate replacement Variant to sync with // var replacements = variantRecord .ShopifyProduct .NonMissingVariants() .Where(x => x.ShopifySku.StandardizedSku() == variantRecord.ShopifySku.StandardizedSku()) .ToList(); // Either no viable Duplicates, abort // if (replacements.Count == 1) { stockItemRecord.ShopifyVariant = replacements.First(); } stockItemRecord.LastUpdated = DateTime.UtcNow; _inventoryRepository.SaveChanges(); } transaction.Commit(); } }