public virtual void OnCompleted() { var logData = MultiLogger.GetBaseLoggingData(); logData.AddCategory("Monitors"); MultiLogHelper.Debug <MonitorBase <T> >(string.Format("Completed monitoring {0}", GetType()), logData); }
/// <summary> /// Gets the <see cref="ProductVariantDisplay"/> with matching with attributes from the product. /// </summary> /// <param name="product"> /// The product. /// </param> /// <param name="optionChoices"> /// The option choices. /// </param> /// <returns> /// The <see cref="ProductVariantDisplay"/>. /// </returns> public static IProductVariantContent GetProductVariantDisplayWithAttributes(this IProductContent product, Guid[] optionChoices) { var variant = product.ProductVariants.FirstOrDefault( x => x.Attributes.Count() == optionChoices.Count() && optionChoices.All(key => x.Attributes.FirstOrDefault(att => att.Key == key) != null)); if (variant == null) { MultiLogHelper.Debug(typeof(ProductContentExtensions), "Could not find IProductVariantContent with keys matching choices in optionChoices array."); } return(variant); }
/// <summary> /// Returns a collection of available <see cref="IShippingGatewayMethod"/> associated by this provider for a given shipment /// </summary> /// <param name="shipment">the <see cref="IShipment"/></param> /// <returns>A collection of <see cref="IShippingGatewayMethod"/></returns> public virtual IEnumerable <IShippingGatewayMethod> GetShippingGatewayMethodsForShipment(IShipment shipment) { var attempt = shipment.GetValidatedShipCountry(GatewayProviderService); // quick validation of shipment if (!attempt.Success) { MultiLogHelper.Error <ShippingGatewayProviderBase>("ShipMethods could not be determined for Shipment passed to GetAvailableShipMethodsForDestination method. Attempt message: " + attempt.Exception.Message, new ArgumentException("merchWarehouseCatalogKey")); return(new List <IShippingGatewayMethod>()); } var shipCountry = attempt.Result; var shipmethods = GetAllShippingGatewayMethods(shipCountry); var gatewayShipMethods = shipmethods as IShippingGatewayMethod[] ?? shipmethods.ToArray(); if (!gatewayShipMethods.Any()) { return(new List <IShippingGatewayMethod>()); } if (!shipCountry.HasProvinces) { return(gatewayShipMethods); } var available = new List <IShippingGatewayMethod>(); foreach (var gwshipmethod in gatewayShipMethods) { var province = gwshipmethod.ShipMethod.Provinces.FirstOrDefault(x => x.Code == shipment.ToRegion); if (province == null) { MultiLogHelper.Debug <ShippingGatewayProviderBase>("Province code '" + shipment.ToRegion + "' was not found in ShipCountry with code : " + shipCountry.CountryCode); available.Add(gwshipmethod); } else { if (province.AllowShipping) { available.Add(gwshipmethod); } } } return(available); }
/// <summary> /// Saves the entire basket to the wish list and then clears the basket. /// </summary> /// <param name="basket"> /// The <see cref="IBasket"/>. /// </param> public static void SaveToWishList(this IBasket basket) { // Anonymous customers do not have wish lists if (basket.Customer.IsAnonymous) { MultiLogHelper.Debug(typeof(BasketWishListExtensions), "SaveToWishList called on an anonymous customer basket."); return; } var customer = (ICustomer)basket.Customer; customer.WishList().Items.Add(basket.Items.Select(x => x.AsLineItemOf <ItemCacheLineItem>())); customer.WishList().Save(); basket.Empty(); }
/// <summary> /// Maps a <see cref="Page{Guid}"/> to <see cref="PagedCollection{TContent}"/>. /// </summary> /// <param name="page"> /// The page. /// </param> /// <param name="sortBy"> /// The sort by. /// </param> /// <returns> /// The <see cref="PagedCollection"/>. /// </returns> public virtual PagedCollection <TContent> MapPagedCollection(Page <Guid> page, string sortBy) { var items = page.Items.Select(GetByKey).Where(x => x != null).ToArray(); if (items.Count() != page.Items.Count) { MultiLogHelper.Debug <VirtualContentCache <TContent, TEntity> >("Could not map all items to virtual content"); } return(new PagedCollection <TContent> { CurrentPage = page.CurrentPage, PageSize = items.Count(), TotalPages = page.TotalPages, TotalItems = page.TotalItems, Items = items, SortField = sortBy }); }
/// <summary> /// Assists in domain mapping. /// </summary> /// <param name="match"> /// The match. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> private string DomainMapper(Match match) { // IdnMapping class with default property values. var idn = new IdnMapping(); var domainName = match.Groups[2].Value; try { domainName = idn.GetAscii(domainName); } catch (ArgumentException) { MultiLogHelper.Debug <EmailValidationHelper>("Invalid email address"); this.invalid = true; } return(match.Groups[1].Value + domainName); }
/// <summary> /// The resolve provider. /// </summary> /// <param name="collection"> /// The collection. /// </param> /// <typeparam name="T"> /// The type of provider /// </typeparam> /// <returns> /// The <see cref="EntityCollectionProviderBase"/>. /// </returns> internal static T ResolveProvider <T>(this IEntityCollection collection) where T : class { var provider = collection.ResolveProvider(); if (provider == null) { return(null); } if (provider is T) { return(provider as T); } MultiLogHelper.Debug(typeof(EntityCollectionExtensions), "Provider was resolved but was not of expected type."); return(null); }
/// <summary> /// Initializes a new instance of the <see cref="LineItemBase"/> class. /// </summary> /// <param name="lineItemTfKey"> /// The line item type field key. /// </param> /// <param name="name"> /// The name. /// </param> /// <param name="sku"> /// The SKU. /// </param> /// <param name="quantity"> /// The quantity. /// </param> /// <param name="price"> /// The price. /// </param> /// <param name="extendedData"> /// The extended data. /// </param> protected LineItemBase(Guid lineItemTfKey, string name, string sku, int quantity, decimal price, ExtendedDataCollection extendedData) { if (lineItemTfKey.Equals(Guid.Empty)) { // This could be a custom type field MultiLogHelper.Debug <LineItemBase>("LineItemType.Custom cannot be added to a collection. You need to pass the type field key directly."); } Ensure.ParameterCondition(lineItemTfKey != Guid.Empty, "lineItemTfKey"); Ensure.ParameterNotNull(extendedData, "extendedData"); Ensure.ParameterNotNullOrEmpty(name, "name"); Ensure.ParameterNotNullOrEmpty(sku, "sku"); _lineItemTfKey = lineItemTfKey; _name = name; _sku = sku; _quantity = quantity; _price = price; _extendedData = extendedData; }
/// <summary> /// Gets the default <see cref="IProductAttributeContent"/> based on default option choices. /// </summary> /// <param name="product"> /// The product. /// </param> /// <returns> /// The <see cref="IProductVariantContent"/>. /// </returns> public static IProductVariantContent GetDefaultProductVariant(this IProductContent product) { if (!product.Options.Any()) { return(null); } var attKeys = new List <Guid>(); foreach (var opt in product.Options) { var defaultChoice = opt.Choices.FirstOrDefault(x => x.IsDefaultChoice); if (defaultChoice == null) { defaultChoice = opt.Choices.First(); MultiLogHelper.Debug(typeof(ProductCollectionExtensions), "Could not find default option choice. Using first choice as default."); } attKeys.Add(defaultChoice.Key); } return(product.GetProductVariantDisplayWithAttributes(attKeys.ToArray())); }
/// <summary> /// Adds a product to a static product collection. /// </summary> /// <param name="product"> /// The product. /// </param> /// <param name="collectionKey"> /// The collection key. /// </param> public static void AddToCollection(this IProduct product, Guid collectionKey) { if (!EntityCollectionProviderResolver.HasCurrent || !MerchelloContext.HasCurrent) { return; } var attempt = EntityCollectionProviderResolver.Current.GetProviderForCollection(collectionKey); if (!attempt.Success) { return; } var provider = attempt.Result; if (!provider.EnsureEntityType(EntityType.Product)) { MultiLogHelper.Debug(typeof(ProductExtensions), "Attempted to add a product to a non product collection"); return; } MerchelloContext.Current.Services.ProductService.AddToCollection(product.Key, collectionKey); }
/// <summary> /// The add to collection. /// </summary> /// <param name="customer"> /// The customer. /// </param> /// <param name="collectionKey"> /// The collection key. /// </param> public static void AddToCollection(this ICustomer customer, Guid collectionKey) { if (!EntityCollectionProviderResolver.HasCurrent || !MerchelloContext.HasCurrent) { return; } var attempt = EntityCollectionProviderResolver.Current.GetProviderForCollection(collectionKey); if (!attempt.Success) { return; } var provider = attempt.Result; if (!provider.EnsureEntityType(Core.EntityType.Customer)) { MultiLogHelper.Debug(typeof(Extensions), "Attempted to add a customer to a non customer collection"); return; } MerchelloContext.Current.Services.CustomerService.AddToCollection(customer.Key, collectionKey); }
/// <summary> /// The modify data. /// </summary> /// <param name="value"> /// The value. /// </param> /// <param name="propertyName"> /// The property name. /// </param> /// <param name="newValue"> /// The new value. /// </param> /// <param name="extendedData"> /// The <see cref="ExtendedDataCollection"/> /// </param> /// <typeparam name="T"> /// The type of <see cref="IDataModifierData"/> /// </typeparam> public static void ModifyData <T>(this T value, string propertyName, object newValue, ExtendedDataCollection extendedData) where T : class, IDataModifierData { var propInfo = value.GetType().GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance); if (propInfo == null || !propInfo.CanWrite || !propInfo.CanRead) { MultiLogHelper.Debug(typeof(DataModifierExtensions), "Could not change property: " + propertyName); return; } try { var oldValue = propInfo.GetValue(value, null); propInfo.SetValue(value, newValue, null); var log = new DataModifierLog() { PropertyName = propertyName, OriginalValue = oldValue, ModifiedValue = newValue, ExtendedData = extendedData }; var logs = value.ModifiedDataLogs == null ? new List <IDataModifierLog>() : value.ModifiedDataLogs as List <IDataModifierLog>; if (logs != null) { logs.Add(log); value.ModifiedDataLogs = logs; } } catch (Exception ex) { MultiLogHelper.Error(typeof(DataModifierExtensions), "Failed to set property: " + propertyName, ex); } }
/// <summary> /// Moves a item to the wish list. /// </summary> /// <param name="basket"> /// The basket. /// </param> /// <param name="lineItemKey"> /// The line item key. /// </param> public static void MoveItemToWishList(this IBasket basket, Guid lineItemKey) { // Anonymous customers do not have wish lists if (basket.Customer.IsAnonymous) { MultiLogHelper.Debug(typeof(BasketWishListExtensions), "SaveToWishList called on an anonymous customer basket."); return; } var lineItem = basket.Items.FirstOrDefault(x => x.Key == lineItemKey); if (lineItem == null) { return; } var wishList = ((ICustomer)basket.Customer).WishList(); wishList.AddItem(lineItem.AsLineItemOf <ItemCacheLineItem>()); wishList.Save(); basket.RemoveItem(lineItem.Key); basket.Save(); }
/// <summary> /// Maps the detached property values /// </summary> /// <param name="detachedContentItem"> /// The detached content item. /// </param> public static void MapDetachedProperties(TSaveModel detachedContentItem) { if (!detachedContentItem.Display.DetachedContents.Any()) { return; } // property values in the updated content are just raw strings at this point and they // need to be passed to the resprective property editors so that they can do whatever it is // they do with the value. var updatedContent = detachedContentItem.Display.DetachedContents.FirstOrDefault( x => x.CultureName == detachedContentItem.CultureName); if (updatedContent == null) { LogHelper.Debug( typeof(ProductVariantDetachedContentHelper <TSaveModel, TDisplay>), "Updated detached content was not found"); return; } var contentTypeAlias = detachedContentItem.Display.DetachedContents.First().DetachedContentType.UmbContentType.Alias; var contentTypeService = ApplicationContext.Current.Services.ContentTypeService; var contentType = contentTypeService.GetContentType(contentTypeAlias); if (contentType == null) { var logData = MultiLogger.GetBaseLoggingData(); MultiLogHelper.Debug(typeof(ProductVariantDetachedContentHelper <TSaveModel, TDisplay>), "ContentType could not be found", logData); return; } // a new container for property values returning from editors var updatedValues = new List <KeyValuePair <string, string> >(); foreach (var p in contentType.CompositionPropertyTypes.ToArray()) { //// create the property data to send to the property editor var d = new Dictionary <string, object>(); //// add the files if any var files = detachedContentItem.UploadedFiles.Where(x => x.PropertyAlias == p.Alias).ToArray(); if (files.Any()) { d.Add("files", files); } var dcv = updatedContent.DetachedDataValues.FirstOrDefault(x => x.Key == p.Alias); // only convert and add the property if it still exists on the content type if (DetachedValuesConverter.Current.VerifyPropertyExists(contentType, dcv.Key)) { updatedValues.Add(DetachedValuesConverter.Current.Convert(contentType, dcv, additionalData: d)); } } updatedContent.DetachedDataValues = updatedValues; }