本文整理汇总了C#中ILocalizationService.GetResource方法的典型用法代码示例。如果您正苦于以下问题:C# ILocalizationService.GetResource方法的具体用法?C# ILocalizationService.GetResource怎么用?C# ILocalizationService.GetResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILocalizationService
的用法示例。
在下文中一共展示了ILocalizationService.GetResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetWrongCaptchaMessage
public static string GetWrongCaptchaMessage(this CaptchaSettings captchaSettings,
ILocalizationService localizationService)
{
if (captchaSettings.ReCaptchaVersion == ReCaptchaVersion.Version1)
return localizationService.GetResource("Common.WrongCaptcha");
else if (captchaSettings.ReCaptchaVersion == ReCaptchaVersion.Version2)
return localizationService.GetResource("Common.WrongCaptchaV2");
return string.Empty;
}
示例2: GetAmazonPayState
public static AmazonPayCheckoutState GetAmazonPayState(this HttpContextBase httpContext, ILocalizationService localizationService)
{
AmazonPayCheckoutState state = null;
var checkoutState = httpContext.GetCheckoutState();
if (checkoutState == null || (state = (AmazonPayCheckoutState)checkoutState.CustomProperties[AmazonPayCore.AmazonPayCheckoutStateKey]) == null)
throw new SmartException(localizationService.GetResource("Plugins.Payments.AmazonPay.MissingCheckoutSessionState"));
return state;
}
示例3: FormatStockMessage
/// <summary>
/// Formats the stock availability/quantity message
/// </summary>
/// <param name="productVariant">Product variant</param>
/// <param name="localizationService">Localization service</param>
/// <returns>The stock message</returns>
public static string FormatStockMessage(this ProductVariant productVariant, ILocalizationService localizationService)
{
if (productVariant == null)
throw new ArgumentNullException("productVariant");
if (localizationService == null)
throw new ArgumentNullException("localizationService");
string stockMessage = string.Empty;
if (productVariant.ManageInventoryMethod == ManageInventoryMethod.ManageStock
&& productVariant.DisplayStockAvailability)
{
switch (productVariant.BackorderMode)
{
case BackorderMode.NoBackorders:
{
if (productVariant.StockQuantity > 0)
{
if (productVariant.DisplayStockQuantity)
{
//display "in stock" with stock quantity
stockMessage = string.Format(localizationService.GetResource("Products.Availability.InStockWithQuantity"), productVariant.StockQuantity);
}
else
{
//display "in stock" without stock quantity
stockMessage = localizationService.GetResource("Products.Availability.InStock");
}
}
else
{
//display "out of stock"
stockMessage = localizationService.GetResource("Products.Availability.OutOfStock");
}
}
break;
case BackorderMode.AllowQtyBelow0:
{
if (productVariant.StockQuantity > 0)
{
if (productVariant.DisplayStockQuantity)
{
//display "in stock" with stock quantity
stockMessage = string.Format(localizationService.GetResource("Products.Availability.InStockWithQuantity"), productVariant.StockQuantity);
}
else
{
//display "in stock" without stock quantity
stockMessage = localizationService.GetResource("Products.Availability.InStock");
}
}
else
{
//display "in stock" without stock quantity
stockMessage = localizationService.GetResource("Products.Availability.InStock");
}
}
break;
case BackorderMode.AllowQtyBelow0AndNotifyCustomer:
{
if (productVariant.StockQuantity > 0)
{
if (productVariant.DisplayStockQuantity)
{
//display "in stock" with stock quantity
stockMessage = string.Format(localizationService.GetResource("Products.Availability.InStockWithQuantity"), productVariant.StockQuantity);
}
else
{
//display "in stock" without stock quantity
stockMessage = localizationService.GetResource("Products.Availability.InStock");
}
}
else
{
//display "backorder" without stock quantity
stockMessage = localizationService.GetResource("Products.Availability.Backordering");
}
}
break;
default:
break;
}
}
return stockMessage;
}
示例4: PrepareModel
/// <summary>
/// Prepare address model
/// </summary>
/// <param name="model">Model</param>
/// <param name="address">Address</param>
/// <param name="excludeProperties">A value indicating whether to exclude properties</param>
/// <param name="addressSettings">Address settings</param>
/// <param name="localizationService">Localization service (used to prepare a select list)</param>
/// <param name="stateProvinceService">State service (used to prepare a select list). null to don't prepare the list.</param>
/// <param name="loadCountries">A function to load countries (used to prepare a select list). null to don't prepare the list.</param>
public static void PrepareModel(this AddressModel model,
Address address, bool excludeProperties,
AddressSettings addressSettings,
ILocalizationService localizationService = null,
IStateProvinceService stateProvinceService = null,
Func<IList<Country>> loadCountries = null)
{
if (model == null)
throw new ArgumentNullException("model");
if (addressSettings == null)
throw new ArgumentNullException("addressSettings");
if (!excludeProperties && address != null)
{
model.Id = address.Id;
model.FirstName = address.FirstName;
model.LastName = address.LastName;
model.Email = address.Email;
model.Company = address.Company;
model.CountryId = address.CountryId;
model.CountryName = address.Country != null
? address.Country.GetLocalized(x => x.Name)
: null;
model.StateProvinceId = address.StateProvinceId;
model.StateProvinceName = address.StateProvince != null
? address.StateProvince.GetLocalized(x => x.Name)
: null;
model.City = address.City;
model.Address1 = address.Address1;
model.Address2 = address.Address2;
model.ZipPostalCode = address.ZipPostalCode;
model.PhoneNumber = address.PhoneNumber;
model.FaxNumber = address.FaxNumber;
}
//countries and states
if (addressSettings.CountryEnabled && loadCountries != null)
{
if (localizationService == null)
throw new ArgumentNullException("localizationService");
model.AvailableCountries.Add(new SelectListItem() { Text = localizationService.GetResource("Address.SelectCountry"), Value = "0" });
foreach (var c in loadCountries())
{
model.AvailableCountries.Add(new SelectListItem()
{
Text = c.GetLocalized(x => x.Name),
Value = c.Id.ToString(),
Selected = c.Id == model.CountryId
});
}
if (addressSettings.StateProvinceEnabled)
{
//states
if (stateProvinceService == null)
throw new ArgumentNullException("stateProvinceService");
var states = stateProvinceService
.GetStateProvincesByCountryId(model.CountryId.HasValue ? model.CountryId.Value : 0)
.ToList();
if (states.Count > 0)
{
foreach (var s in states)
{
model.AvailableStates.Add(new SelectListItem()
{
Text = s.GetLocalized(x => x.Name),
Value = s.Id.ToString(),
Selected = (s.Id == model.StateProvinceId)
});
}
}
else
{
model.AvailableStates.Add(new SelectListItem()
{
Text = localizationService.GetResource("Address.OtherNonUS"),
Value = "0"
});
}
}
}
//form fields
model.CompanyEnabled = addressSettings.CompanyEnabled;
model.CompanyRequired = addressSettings.CompanyRequired;
model.StreetAddressEnabled = addressSettings.StreetAddressEnabled;
model.StreetAddressRequired = addressSettings.StreetAddressRequired;
//.........这里部分代码省略.........
示例5: FormatStockMessage
/// <summary>
/// Formats the stock availability/quantity message
/// </summary>
/// <param name="product">Product</param>
/// <param name="attributesXml">Selected product attributes in XML format (if specified)</param>
/// <param name="localizationService">Localization service</param>
/// <param name="productAttributeParser">Product attribute parser</param>
/// <returns>The stock message</returns>
public static string FormatStockMessage(this Product product, string attributesXml,
ILocalizationService localizationService, IProductAttributeParser productAttributeParser)
{
if (product == null)
throw new ArgumentNullException("product");
if (localizationService == null)
throw new ArgumentNullException("localizationService");
if (productAttributeParser == null)
throw new ArgumentNullException("productAttributeParser");
string stockMessage = string.Empty;
switch (product.ManageInventoryMethod)
{
case ManageInventoryMethod.ManageStock:
{
#region Manage stock
if (!product.DisplayStockAvailability)
return stockMessage;
var stockQuantity = product.GetTotalStockQuantity();
if (stockQuantity > 0)
{
stockMessage = product.DisplayStockQuantity ?
//display "in stock" with stock quantity
string.Format(localizationService.GetResource("Products.Availability.InStockWithQuantity"), stockQuantity) :
//display "in stock" without stock quantity
localizationService.GetResource("Products.Availability.InStock");
}
else
{
//out of stock
switch (product.BackorderMode)
{
case BackorderMode.NoBackorders:
stockMessage = localizationService.GetResource("Products.Availability.OutOfStock");
break;
case BackorderMode.AllowQtyBelow0:
stockMessage = localizationService.GetResource("Products.Availability.InStock");
break;
case BackorderMode.AllowQtyBelow0AndNotifyCustomer:
stockMessage = localizationService.GetResource("Products.Availability.Backordering");
break;
default:
break;
}
}
#endregion
}
break;
case ManageInventoryMethod.ManageStockByAttributes:
{
#region Manage stock by attributes
if (!product.DisplayStockAvailability)
return stockMessage;
var combination = productAttributeParser.FindProductAttributeCombination(product, attributesXml);
if (combination != null)
{
//combination exists
var stockQuantity = combination.StockQuantity;
if (stockQuantity > 0)
{
stockMessage = product.DisplayStockQuantity ?
//display "in stock" with stock quantity
string.Format(localizationService.GetResource("Products.Availability.InStockWithQuantity"), stockQuantity) :
//display "in stock" without stock quantity
localizationService.GetResource("Products.Availability.InStock");
}
else if (combination.AllowOutOfStockOrders)
{
stockMessage = localizationService.GetResource("Products.Availability.InStock");
}
else
{
stockMessage = localizationService.GetResource("Products.Availability.OutOfStock");
}
}
else
{
//no combination configured
stockMessage = localizationService.GetResource("Products.Availability.InStock");
}
#endregion
}
break;
//.........这里部分代码省略.........
示例6: FormatBasePrice
/// <summary>
/// Format base price (PAngV)
/// </summary>
/// <param name="product">Product</param>
/// <param name="productPrice">Product price (in primary currency). Pass null if you want to use a default produce price</param>
/// <param name="localizationService">Localization service</param>
/// <param name="measureService">Measure service</param>
/// <param name="currencyService">Currency service</param>
/// <param name="workContext">Work context</param>
/// <param name="priceFormatter">Price formatter</param>
/// <returns>Base price</returns>
public static string FormatBasePrice(this Product product, decimal? productPrice, ILocalizationService localizationService,
IMeasureService measureService, ICurrencyService currencyService,
IWorkContext workContext, IPriceFormatter priceFormatter)
{
if (product == null)
throw new ArgumentNullException("product");
if (localizationService == null)
throw new ArgumentNullException("localizationService");
if (measureService == null)
throw new ArgumentNullException("measureService");
if (currencyService == null)
throw new ArgumentNullException("currencyService");
if (workContext == null)
throw new ArgumentNullException("workContext");
if (priceFormatter == null)
throw new ArgumentNullException("priceFormatter");
if (!product.BasepriceEnabled)
return null;
var productAmount = product.BasepriceAmount;
//Amount in product cannot be 0
if (productAmount == 0)
return null;
var referenceAmount = product.BasepriceBaseAmount;
var productUnit = measureService.GetMeasureWeightById(product.BasepriceUnitId);
//measure weight cannot be loaded
if (productUnit == null)
return null;
var referenceUnit = measureService.GetMeasureWeightById(product.BasepriceBaseUnitId);
//measure weight cannot be loaded
if (referenceUnit == null)
return null;
productPrice = productPrice.HasValue ? productPrice.Value : product.Price;
decimal basePrice = productPrice.Value /
//do not round. otherwise, it can cause issues
measureService.ConvertWeight(productAmount, productUnit, referenceUnit, false) *
referenceAmount;
decimal basePriceInCurrentCurrency = currencyService.ConvertFromPrimaryStoreCurrency(basePrice, workContext.WorkingCurrency);
string basePriceStr = priceFormatter.FormatPrice(basePriceInCurrentCurrency, true, false);
var result = string.Format(localizationService.GetResource("Products.BasePrice"),
basePriceStr, referenceAmount.ToString("G29"), referenceUnit.Name);
return result;
}
示例7: GetBasePriceInfo
/// <summary>
/// Gets the base price info
/// </summary>
/// <param name="product">Product</param>
/// <param name="productPrice">The calculated product price</param>
/// <param name="localizationService">Localization service</param>
/// <param name="priceFormatter">Price formatter</param>
/// <param name="currency">Target currency</param>
/// <param name="languageInsensitive">Whether the result string should be language insensitive</param>
/// <returns>The base price info</returns>
public static string GetBasePriceInfo(this Product product,
decimal productPrice,
ILocalizationService localizationService,
IPriceFormatter priceFormatter,
Currency currency,
bool languageInsensitive = false)
{
Guard.ArgumentNotNull(() => product);
Guard.ArgumentNotNull(() => localizationService);
Guard.ArgumentNotNull(() => priceFormatter);
Guard.ArgumentNotNull(() => currency);
if (product.BasePriceHasValue && product.BasePriceAmount != Decimal.Zero)
{
var value = Convert.ToDecimal((productPrice / product.BasePriceAmount) * product.BasePriceBaseAmount);
var valueFormatted = priceFormatter.FormatPrice(value, true, currency);
var amountFormatted = Math.Round(product.BasePriceAmount.Value, 2).ToString("G29");
var infoTemplate = localizationService.GetResource(languageInsensitive ? "Products.BasePriceInfo.LanguageInsensitive" : "Products.BasePriceInfo");
var result = infoTemplate.FormatInvariant(
amountFormatted,
product.BasePriceMeasureUnit,
valueFormatted,
product.BasePriceBaseAmount
);
return result;
}
return "";
}
示例8: GetRecurringCycleInfo
/// <summary>
/// Get a recurring cycle information
/// </summary>
/// <param name="shoppingCart">Shopping cart</param>
/// <param name="localizationService">Localization service</param>
/// <param name="cycleLength">Cycle length</param>
/// <param name="cyclePeriod">Cycle period</param>
/// <param name="totalCycles">Total cycles</param>
/// <returns>Error (if exists); otherwise, empty string</returns>
public static string GetRecurringCycleInfo(this IList<ShoppingCartItem> shoppingCart,
ILocalizationService localizationService,
out int cycleLength, out RecurringProductCyclePeriod cyclePeriod, out int totalCycles)
{
string error = "";
cycleLength = 0;
cyclePeriod = 0;
totalCycles = 0;
int? _cycleLength = null;
RecurringProductCyclePeriod? _cyclePeriod = null;
int? _totalCycles = null;
foreach (var sci in shoppingCart)
{
var product= sci.Product;
if (product == null)
{
throw new NopException(string.Format("Product (Id={0}) cannot be loaded", sci.ProductId));
}
string conflictError = localizationService.GetResource("ShoppingCart.ConflictingShipmentSchedules");
if (product.IsRecurring)
{
//cycle length
if (_cycleLength.HasValue && _cycleLength.Value != product.RecurringCycleLength)
{
error = conflictError;
return error;
}
else
{
_cycleLength = product.RecurringCycleLength;
}
//cycle period
if (_cyclePeriod.HasValue && _cyclePeriod.Value != product.RecurringCyclePeriod)
{
error = conflictError;
return error;
}
else
{
_cyclePeriod = product.RecurringCyclePeriod;
}
//total cycles
if (_totalCycles.HasValue && _totalCycles.Value != product.RecurringTotalCycles)
{
error = conflictError;
return error;
}
else
{
_totalCycles = product.RecurringTotalCycles;
}
}
}
if (_cycleLength.HasValue && _cyclePeriod.HasValue && _totalCycles.HasValue)
{
cycleLength = _cycleLength.Value;
cyclePeriod = _cyclePeriod.Value;
totalCycles = _totalCycles.Value;
}
return error;
}
示例9: GetBasePriceInfo
/// <summary>
/// gets the base price
/// </summary>
/// <param name="product">Product</param>
/// <param name="localizationService">Localization service</param>
/// <param name="priceFormatter">Price formatter</param>
/// <param name="priceAdjustment">Price adjustment</param>
/// <returns>The base price</returns>
public static string GetBasePriceInfo(this Product product, ILocalizationService localizationService, IPriceFormatter priceFormatter,
decimal priceAdjustment = decimal.Zero)
{
if (product == null)
throw new ArgumentNullException("product");
if (localizationService == null)
throw new ArgumentNullException("localizationService");
if (product.BasePriceHasValue && product.BasePriceAmount != Decimal.Zero)
{
decimal price = decimal.Add(product.Price, priceAdjustment);
decimal basePriceValue = Convert.ToDecimal((price / product.BasePriceAmount) * product.BasePriceBaseAmount);
string basePrice = priceFormatter.FormatPrice(basePriceValue, false, false);
string unit = "{0} {1}".FormatWith(product.BasePriceBaseAmount, product.BasePriceMeasureUnit);
return localizationService.GetResource("Products.BasePriceInfo").FormatWith(basePrice, unit);
}
return "";
}
示例10: GetRecurringCycleInfo
/// <summary>
/// Get a recurring cycle information
/// </summary>
/// <param name="shoppingCart">Shopping cart</param>
/// <param name="localizationService">Localization service</param>
/// <param name="cycleLength">Cycle length</param>
/// <param name="cyclePeriod">Cycle period</param>
/// <param name="totalCycles">Total cycles</param>
/// <returns>Error (if exists); otherwise, empty string</returns>
public static string GetRecurringCycleInfo(this IList<ShoppingCartItem> shoppingCart,
ILocalizationService localizationService,
out int cycleLength, out RecurringProductCyclePeriod cyclePeriod, out int totalCycles)
{
cycleLength = 0;
cyclePeriod = 0;
totalCycles = 0;
int? _cycleLength = null;
RecurringProductCyclePeriod? _cyclePeriod = null;
int? _totalCycles = null;
foreach (var sci in shoppingCart)
{
var product = Core.Infrastructure.EngineContext.Current.Resolve<IProductService>().GetProductById(sci.ProductId);
if (product == null)
{
throw new NopException(string.Format("Product (Id={0}) cannot be loaded", sci.ProductId));
}
if (product.IsRecurring)
{
string conflictError = localizationService.GetResource("ShoppingCart.ConflictingShipmentSchedules");
//cycle length
if (_cycleLength.HasValue && _cycleLength.Value != product.RecurringCycleLength)
return conflictError;
_cycleLength = product.RecurringCycleLength;
//cycle period
if (_cyclePeriod.HasValue && _cyclePeriod.Value != product.RecurringCyclePeriod)
return conflictError;
_cyclePeriod = product.RecurringCyclePeriod;
//total cycles
if (_totalCycles.HasValue && _totalCycles.Value != product.RecurringTotalCycles)
return conflictError;
_totalCycles = product.RecurringTotalCycles;
}
}
if (_cycleLength.HasValue && _cyclePeriod.HasValue && _totalCycles.HasValue)
{
cycleLength = _cycleLength.Value;
cyclePeriod = _cyclePeriod.Value;
totalCycles = _totalCycles.Value;
}
return "";
}
示例11: PrepareProductOverviewModels
public IEnumerable<ProductOverviewModel> PrepareProductOverviewModels(
IWorkContext workContext,
IStoreContext storeContext,
IProductService productService,
ILocalizationService localizationService,
IPictureService pictureService,
IWebHelper webHelper,
ICacheManager cacheManager,
CatalogSettings catalogSettings,
MediaSettings mediaSettings,
IEnumerable<Product> products,
int? productThumbPictureSize = null)
{
if (products == null)
throw new ArgumentNullException("products");
var models = new List<ProductOverviewModel>();
foreach (var product in products)
{
var model = new ProductOverviewModel
{
Id = product.Id,
Name = product.GetLocalized(x => x.Name),
ShortDescription = product.GetLocalized(x => x.ShortDescription),
FullDescription = product.GetLocalized(x => x.FullDescription),
SeName = product.GetSeName(),
};
//picture
#region Prepare product picture
//If a size has been set in the view, we use it in priority
int pictureSize = productThumbPictureSize.HasValue ? productThumbPictureSize.Value : mediaSettings.ProductThumbPictureSize;
//prepare picture model
var defaultProductPictureCacheKey = string.Format(ModelCacheEventConsumer.PRODUCT_DEFAULTPICTURE_MODEL_KEY, product.Id, pictureSize, true, workContext.WorkingLanguage.Id, webHelper.IsCurrentConnectionSecured(), storeContext.CurrentStore.Id);
model.DefaultPictureModel = cacheManager.Get(defaultProductPictureCacheKey, () =>
{
var picture = pictureService.GetPicturesByProductId(product.Id, 1).FirstOrDefault();
var pictureModel = new PictureModel
{
ImageUrl = pictureService.GetPictureUrl(picture, pictureSize),
FullSizeImageUrl = pictureService.GetPictureUrl(picture)
};
//"title" attribute
pictureModel.Title = (picture != null && !string.IsNullOrEmpty(picture.TitleAttribute)) ?
picture.TitleAttribute :
string.Format(localizationService.GetResource("Media.Product.ImageLinkTitleFormat"), model.Name);
//"alt" attribute
pictureModel.AlternateText = (picture != null && !string.IsNullOrEmpty(picture.AltAttribute)) ?
picture.AltAttribute :
string.Format(localizationService.GetResource("Media.Product.ImageAlternateTextFormat"), model.Name);
return pictureModel;
});
#endregion
models.Add(model);
}
return models;
}
示例12: GetName
/// <summary>
/// Gets the localized friendly name or the system name as fallback
/// </summary>
/// <param name="provider">Export provider</param>
/// <param name="localizationService">Localization service</param>
/// <returns>Provider name</returns>
public static string GetName(this Provider<IExportProvider> provider, ILocalizationService localizationService)
{
var systemName = provider.Metadata.SystemName;
var resourceName = provider.Metadata.ResourceKeyPattern.FormatInvariant(systemName, "FriendlyName");
var name = localizationService.GetResource(resourceName, 0, false, systemName, true);
return (name.IsEmpty() ? systemName : name);
}
示例13: GetBasePriceInfo
/// <summary>
/// Gets the base price
/// </summary>
/// <param name="product">Product</param>
/// <param name="localizationService">Localization service</param>
/// <param name="priceFormatter">Price formatter</param>
/// <param name="priceAdjustment">Price adjustment</param>
/// <param name="languageIndependent">Whether the result string should be language independent</param>
/// <returns>The base price</returns>
public static string GetBasePriceInfo(this Product product, ILocalizationService localizationService, IPriceFormatter priceFormatter,
ICurrencyService currencyService, ITaxService taxService, IPriceCalculationService priceCalculationService,
Currency currency, decimal priceAdjustment = decimal.Zero, bool languageIndependent = false)
{
if (product == null)
throw new ArgumentNullException("product");
if (localizationService == null && !languageIndependent)
throw new ArgumentNullException("localizationService");
if (product.BasePriceHasValue && product.BasePriceAmount != Decimal.Zero)
{
var workContext = EngineContext.Current.Resolve<IWorkContext>();
var taxrate = decimal.Zero;
var currentPrice = priceCalculationService.GetFinalPrice(product, workContext.CurrentCustomer, true);
decimal price = taxService.GetProductPrice(product, decimal.Add(currentPrice, priceAdjustment), out taxrate);
price = currencyService.ConvertFromPrimaryStoreCurrency(price, currency);
decimal basePriceValue = Convert.ToDecimal((price / product.BasePriceAmount) * product.BasePriceBaseAmount);
string basePrice = priceFormatter.FormatPrice(basePriceValue, true, currency);
string unit = "{0} {1}".FormatWith(product.BasePriceBaseAmount, product.BasePriceMeasureUnit);
if (languageIndependent)
{
return "{0} / {1}".FormatWith(basePrice, unit);
}
return localizationService.GetResource("Products.BasePriceInfo").FormatWith(basePrice, unit);
}
return "";
}
示例14: ToScheduleTaskModel
public static ScheduleTaskModel ToScheduleTaskModel(this ScheduleTask task, ILocalizationService localization, IDateTimeHelper dateTimeHelper, UrlHelper urlHelper)
{
var now = DateTime.UtcNow;
TimeSpan? dueIn = null;
if (task.NextRunUtc.HasValue)
{
dueIn = task.NextRunUtc.Value - now;
}
var nextRunPretty = "";
bool isOverdue = false;
if (dueIn.HasValue)
{
if (dueIn.Value.TotalSeconds > 0)
{
nextRunPretty = dueIn.Value.Prettify();
}
else
{
nextRunPretty = localization.GetResource("Common.Waiting") + "...";
isOverdue = true;
}
}
var isRunning = task.IsRunning;
var lastStartOn = task.LastStartUtc.HasValue ? dateTimeHelper.ConvertToUserTime(task.LastStartUtc.Value, DateTimeKind.Utc) : (DateTime?)null;
var lastEndOn = task.LastEndUtc.HasValue ? dateTimeHelper.ConvertToUserTime(task.LastEndUtc.Value, DateTimeKind.Utc) : (DateTime?)null;
var lastSuccessOn = task.LastSuccessUtc.HasValue ? dateTimeHelper.ConvertToUserTime(task.LastSuccessUtc.Value, DateTimeKind.Utc) : (DateTime?)null;
var nextRunOn = task.NextRunUtc.HasValue ? dateTimeHelper.ConvertToUserTime(task.NextRunUtc.Value, DateTimeKind.Utc) : (DateTime?)null;
var model = new ScheduleTaskModel
{
Id = task.Id,
Name = task.Name,
CronExpression = task.CronExpression,
CronDescription = CronExpression.GetFriendlyDescription(task.CronExpression),
Enabled = task.Enabled,
StopOnError = task.StopOnError,
LastStart = lastStartOn,
LastStartPretty = task.LastStartUtc.HasValue ? task.LastStartUtc.Value.RelativeFormat(true, "f") : "",
LastEnd = lastEndOn,
LastEndPretty = lastEndOn.HasValue ? lastEndOn.Value.ToString("G") : "",
LastSuccess = lastSuccessOn,
LastSuccessPretty = lastSuccessOn.HasValue ? lastSuccessOn.Value.ToString("G") : "",
NextRun = nextRunOn,
NextRunPretty = nextRunPretty,
LastError = task.LastError.EmptyNull(),
IsRunning = isRunning,
CancelUrl = urlHelper.Action("CancelJob", "ScheduleTask", new { id = task.Id }),
ExecuteUrl = urlHelper.Action("RunJob", "ScheduleTask", new { id = task.Id }),
EditUrl = urlHelper.Action("Edit", "ScheduleTask", new { id = task.Id }),
ProgressPercent = task.ProgressPercent,
ProgressMessage = task.ProgressMessage,
IsOverdue = isOverdue,
Duration = ""
};
var span = TimeSpan.Zero;
if (task.LastStartUtc.HasValue)
{
span = model.IsRunning ? now - task.LastStartUtc.Value : task.LastEndUtc.Value - task.LastStartUtc.Value;
if (span > TimeSpan.Zero)
{
model.Duration = span.ToString("g");
}
}
return model;
}
示例15: CreateSelectedAttributesXml
/// <summary>Takes selected elements from collection and creates a attribute XML string from it.</summary>
/// <param name="formatWithProductId">how the name of the controls are formatted. frontend includes productId, backend does not.</param>
public static string CreateSelectedAttributesXml(this NameValueCollection collection, int productId, IList<ProductVariantAttribute> variantAttributes,
IProductAttributeParser productAttributeParser, ILocalizationService localizationService, IDownloadService downloadService, CatalogSettings catalogSettings,
HttpRequestBase request, List<string> warnings, bool formatWithProductId = true, int bundleItemId = 0)
{
if (collection == null)
return "";
string controlId;
string selectedAttributes = "";
foreach (var attribute in variantAttributes)
{
controlId = AttributeFormatedName(attribute.ProductAttributeId, attribute.Id, formatWithProductId ? productId : 0, bundleItemId);
switch (attribute.AttributeControlType)
{
case AttributeControlType.DropdownList:
case AttributeControlType.RadioList:
case AttributeControlType.ColorSquares:
{
var ctrlAttributes = collection[controlId];
if (ctrlAttributes.HasValue())
{
int selectedAttributeId = int.Parse(ctrlAttributes);
if (selectedAttributeId > 0)
selectedAttributes = productAttributeParser.AddProductAttribute(selectedAttributes, attribute, selectedAttributeId.ToString());
}
}
break;
case AttributeControlType.Checkboxes:
{
var cblAttributes = collection[controlId];
if (cblAttributes.HasValue())
{
foreach (var item in cblAttributes.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
int selectedAttributeId = int.Parse(item);
if (selectedAttributeId > 0)
selectedAttributes = productAttributeParser.AddProductAttribute(selectedAttributes, attribute, selectedAttributeId.ToString());
}
}
}
break;
case AttributeControlType.TextBox:
case AttributeControlType.MultilineTextbox:
{
var txtAttribute = collection[controlId];
if (txtAttribute.HasValue())
{
string enteredText = txtAttribute.Trim();
selectedAttributes = productAttributeParser.AddProductAttribute(selectedAttributes, attribute, enteredText);
}
}
break;
case AttributeControlType.Datepicker:
{
var date = collection[controlId + "_day"];
var month = collection[controlId + "_month"];
var year = collection[controlId + "_year"];
DateTime? selectedDate = null;
try
{
selectedDate = new DateTime(Int32.Parse(year), Int32.Parse(month), Int32.Parse(date));
}
catch { }
if (selectedDate.HasValue)
{
selectedAttributes = productAttributeParser.AddProductAttribute(selectedAttributes, attribute, selectedDate.Value.ToString("D"));
}
}
break;
case AttributeControlType.FileUpload:
if (request == null)
{
Guid downloadGuid;
Guid.TryParse(collection[controlId], out downloadGuid);
var download = downloadService.GetDownloadByGuid(downloadGuid);
if (download != null)
{
selectedAttributes = productAttributeParser.AddProductAttribute(selectedAttributes, attribute, download.DownloadGuid.ToString());
}
}
else
{
var httpPostedFile = request.Files[controlId];
if (httpPostedFile != null && httpPostedFile.FileName.HasValue())
{
int fileMaxSize = catalogSettings.FileUploadMaximumSizeBytes;
if (httpPostedFile.ContentLength > fileMaxSize)
{
warnings.Add(string.Format(localizationService.GetResource("ShoppingCart.MaximumUploadedFileSize"), (int)(fileMaxSize / 1024)));
}
//.........这里部分代码省略.........