public string Acquire(string taskName, DateTime expiredUtc) { var cacheKey = MakeCacheKey(taskName); var machineName = _machineNameProvider.GetMachineName(); var existingLease = _cacheService.Get(cacheKey); if (existingLease != null && ((string)existingLease) != machineName) { return(null); } _cacheService.Put(cacheKey, machineName, expiredUtc - _clock.UtcNow); return(_decorated.Acquire(taskName, expiredUtc)); }
public string Generate(IMachineNameProvider machineNameProvider, CounterDefinition counterDefinition) { var machineName = machineNameProvider.GetMachineName(); if (string.IsNullOrEmpty(counterDefinition.InstanceName)) { return string.Format("{0}.{1}.{2}", machineName, counterDefinition.CategoryName, counterDefinition.CounterName); } return string.Format("{0}.{1}.{2}.{3}", machineName, counterDefinition.CategoryName, counterDefinition.CounterName, counterDefinition.InstanceName); }
public string Acquire(string taskName, DateTime expiredUtc) { var machineName = _machineNameProvider.GetMachineName(); // retrieve current lease for the specified task var taskLease = _repository.Get(x => x.TaskName == taskName); // create a new lease if there is no current lease for this task if (taskLease == null) { taskLease = new TaskLeaseRecord { TaskName = taskName, MachineName = machineName, State = String.Empty, UpdatedUtc = _clock.UtcNow, ExpiredUtc = expiredUtc }; _repository.Create(taskLease); _repository.Flush(); return(String.Empty); } // lease can't be aquired only if for a different machine and it has not expired if (taskLease.MachineName != machineName && taskLease.ExpiredUtc >= _clock.UtcNow) { return(null); } // otherwise update information taskLease.MachineName = machineName; taskLease.UpdatedUtc = _clock.UtcNow; taskLease.ExpiredUtc = expiredUtc; _repository.Flush(); return(taskLease.State); }
public IActionResult SystemInfo() { var model = new SystemInfoModel(); model.GrandVersion = GrandVersion.CurrentVersion; try { model.OperatingSystem = RuntimeInformation.OSDescription; } catch (Exception) { } try { model.AspNetInfo = RuntimeEnvironment.GetSystemVersion(); } catch (Exception) { } model.MachineName = _machineNameProvider.GetMachineName(); model.ServerTimeZone = TimeZoneInfo.Local.StandardName; model.ServerLocalTime = DateTime.Now; model.ApplicationTime = _dateTimeHelper.ConvertToUserTime(DateTime.UtcNow, TimeZoneInfo.Utc, _dateTimeHelper.DefaultStoreTimeZone); model.UtcTime = DateTime.UtcNow; foreach (var header in HttpContext.Request.Headers) { model.ServerVariables.Add(new SystemInfoModel.ServerVariableModel { Name = header.Key, Value = header.Value }); } foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies()) { model.LoadedAssemblies.Add(new SystemInfoModel.LoadedAssembly { FullName = assembly.FullName, }); } return(View(model)); }
/// <summary> /// Get machine name /// </summary> /// <returns>Machine name</returns> public virtual string GetMachineName() { return(_machineNameProvider.GetMachineName()); }
public async Task <IActionResult> SystemInfo() { var model = new SystemInfoModel(); model.GrandVersion = GrandVersion.FullVersion; try { model.OperatingSystem = RuntimeInformation.OSDescription; } catch (Exception) { } try { model.AspNetInfo = RuntimeEnvironment.GetSystemVersion(); } catch (Exception) { } model.MachineName = _machineNameProvider.GetMachineName(); model.ServerTimeZone = TimeZoneInfo.Local.StandardName; model.ServerLocalTime = DateTime.Now; model.ApplicationTime = _dateTimeService.ConvertToUserTime(DateTime.UtcNow, TimeZoneInfo.Utc, _dateTimeService.CurrentTimeZone); model.UtcTime = DateTime.UtcNow; foreach (var header in HttpContext.Request.Headers) { model.ServerVariables.Add(new SystemInfoModel.ServerVariableModel { Name = header.Key, Value = header.Value }); } foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies().ToList().OrderBy(x => x.FullName)) { model.LoadedAssemblies.Add(new SystemInfoModel.LoadedAssembly { FullName = assembly.FullName, }); } //store URL var currentStoreUrl = _workContext.CurrentStore.Url; if (!String.IsNullOrEmpty(currentStoreUrl) && (currentStoreUrl.Equals(HttpContext.Request.Host.Host, StringComparison.OrdinalIgnoreCase))) { model.SystemWarnings.Add(new SystemInfoModel.SystemWarningModel { Level = SystemInfoModel.SystemWarningModel.SystemWarningLevel.Pass, Text = _translationService.GetResource("Admin.System.Warnings.URL.Match") }); } else { model.SystemWarnings.Add(new SystemInfoModel.SystemWarningModel { Level = SystemInfoModel.SystemWarningModel.SystemWarningLevel.Warning, Text = string.Format(_translationService.GetResource("Admin.System.Warnings.URL.NoMatch"), currentStoreUrl, HttpContext.Request.Host.Host) }); } //primary exchange rate currency var perCurrency = await _currencyService.GetCurrencyById(_currencySettings.PrimaryExchangeRateCurrencyId); if (perCurrency != null) { model.SystemWarnings.Add(new SystemInfoModel.SystemWarningModel { Level = SystemInfoModel.SystemWarningModel.SystemWarningLevel.Pass, Text = _translationService.GetResource("Admin.System.Warnings.ExchangeCurrency.Set"), }); if (perCurrency.Rate != 1) { model.SystemWarnings.Add(new SystemInfoModel.SystemWarningModel { Level = SystemInfoModel.SystemWarningModel.SystemWarningLevel.Fail, Text = _translationService.GetResource("Admin.System.Warnings.ExchangeCurrency.Rate1") }); } } else { model.SystemWarnings.Add(new SystemInfoModel.SystemWarningModel { Level = SystemInfoModel.SystemWarningModel.SystemWarningLevel.Fail, Text = _translationService.GetResource("Admin.System.Warnings.ExchangeCurrency.NotSet") }); } //primary store currency var pscCurrency = await _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId); if (pscCurrency != null) { model.SystemWarnings.Add(new SystemInfoModel.SystemWarningModel { Level = SystemInfoModel.SystemWarningModel.SystemWarningLevel.Pass, Text = _translationService.GetResource("Admin.System.Warnings.PrimaryCurrency.Set"), }); } else { model.SystemWarnings.Add(new SystemInfoModel.SystemWarningModel { Level = SystemInfoModel.SystemWarningModel.SystemWarningLevel.Fail, Text = _translationService.GetResource("Admin.System.Warnings.PrimaryCurrency.NotSet") }); } //base measure weight var bWeight = await _measureService.GetMeasureWeightById(_measureSettings.BaseWeightId); if (bWeight != null) { model.SystemWarnings.Add(new SystemInfoModel.SystemWarningModel { Level = SystemInfoModel.SystemWarningModel.SystemWarningLevel.Pass, Text = _translationService.GetResource("Admin.System.Warnings.DefaultWeight.Set"), }); if (bWeight.Ratio != 1) { model.SystemWarnings.Add(new SystemInfoModel.SystemWarningModel { Level = SystemInfoModel.SystemWarningModel.SystemWarningLevel.Fail, Text = _translationService.GetResource("Admin.System.Warnings.DefaultWeight.Ratio1") }); } } else { model.SystemWarnings.Add(new SystemInfoModel.SystemWarningModel { Level = SystemInfoModel.SystemWarningModel.SystemWarningLevel.Fail, Text = _translationService.GetResource("Admin.System.Warnings.DefaultWeight.NotSet") }); } //base dimension weight var bDimension = await _measureService.GetMeasureDimensionById(_measureSettings.BaseDimensionId); if (bDimension != null) { model.SystemWarnings.Add(new SystemInfoModel.SystemWarningModel { Level = SystemInfoModel.SystemWarningModel.SystemWarningLevel.Pass, Text = _translationService.GetResource("Admin.System.Warnings.DefaultDimension.Set"), }); if (bDimension.Ratio != 1) { model.SystemWarnings.Add(new SystemInfoModel.SystemWarningModel { Level = SystemInfoModel.SystemWarningModel.SystemWarningLevel.Fail, Text = _translationService.GetResource("Admin.System.Warnings.DefaultDimension.Ratio1") }); } } else { model.SystemWarnings.Add(new SystemInfoModel.SystemWarningModel { Level = SystemInfoModel.SystemWarningModel.SystemWarningLevel.Fail, Text = _translationService.GetResource("Admin.System.Warnings.DefaultDimension.NotSet") }); } //shipping rate coputation methods var srcMethods = await _shippingService.LoadActiveShippingRateCalculationProviders(); if (srcMethods.Count == 0) { model.SystemWarnings.Add(new SystemInfoModel.SystemWarningModel { Level = SystemInfoModel.SystemWarningModel.SystemWarningLevel.Fail, Text = _translationService.GetResource("Admin.System.Warnings.Shipping.NoComputationMethods") }); } if (srcMethods.Count(x => x.ShippingRateCalculationType == ShippingRateCalculationType.Off) > 1) { model.SystemWarnings.Add(new SystemInfoModel.SystemWarningModel { Level = SystemInfoModel.SystemWarningModel.SystemWarningLevel.Warning, Text = _translationService.GetResource("Admin.System.Warnings.Shipping.OnlyOneOffline") }); } //payment methods if ((await _paymentService.LoadActivePaymentMethods()).Any()) { model.SystemWarnings.Add(new SystemInfoModel.SystemWarningModel { Level = SystemInfoModel.SystemWarningModel.SystemWarningLevel.Pass, Text = _translationService.GetResource("Admin.System.Warnings.PaymentMethods.OK") }); } else { model.SystemWarnings.Add(new SystemInfoModel.SystemWarningModel { Level = SystemInfoModel.SystemWarningModel.SystemWarningLevel.Fail, Text = _translationService.GetResource("Admin.System.Warnings.PaymentMethods.NoActive") }); } //performance settings if (CommonHelper.IgnoreStoreLimitations) { model.SystemWarnings.Add(new SystemInfoModel.SystemWarningModel { Level = SystemInfoModel.SystemWarningModel.SystemWarningLevel.Warning, Text = _translationService.GetResource("Admin.System.Warnings.Performance.IgnoreStoreLimitations") }); } if (CommonHelper.IgnoreAcl) { model.SystemWarnings.Add(new SystemInfoModel.SystemWarningModel { Level = SystemInfoModel.SystemWarningModel.SystemWarningLevel.Warning, Text = _translationService.GetResource("Admin.System.Warnings.Performance.IgnoreAcl") }); } return(View(model)); }