Пример #1
0
        /// <summary>
        /// Gets the base website url for constructing PayPal response URLs.
        /// </summary>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static string GetBaseWebsiteUrl()
        {
            var websiteUrl = string.Empty;

            try
            {
                var url = HttpContext.Current.Request.Url;
                websiteUrl =
                    string.Format(
                        "{0}://{1}{2}",
                        url.Scheme,
                        url.Host,
                        url.IsDefaultPort ? string.Empty : ":" + url.Port).EnsureNotEndsWith('/');
            }
            catch (Exception ex)
            {
                var logData = MultiLogger.GetBaseLoggingData();
                logData.AddCategory("PayPal");

                MultiLogHelper.WarnWithException(
                    typeof(PayPalApiHelper),
                    "Failed to initialize factory setting for WebsiteUrl.  HttpContext.Current.Request is likely null.",
                    ex,
                    logData);
            }

            return(websiteUrl);
        }
Пример #2
0
        /// <summary>
        /// Handles the exception in the remove discount operation.
        /// </summary>
        /// <param name="sku">
        /// The line item SKU for the discount line item.
        /// </param>
        /// <param name="contentRedirectId">
        /// The Umbraco content Id for redirection.
        /// </param>
        /// <param name="ex">
        /// The <see cref="Exception"/>
        /// </param>
        /// <returns>
        /// The <see cref="ActionResult"/>.
        /// </returns>
        protected virtual ActionResult HandleRemoveDiscountException(string sku, int contentRedirectId, Exception ex)
        {
            var logData = MultiLogger.GetBaseLoggingData();

            logData.AddCategory("Controllers");
            MultiLogHelper.WarnWithException <CheckoutDiscountControllerBase <TDiscountModel, TLineItemModel> >("Failed to remove discount", ex, logData);
            return(RedirectToUmbracoPage(contentRedirectId));
        }
        /// <summary>
        /// A method used to format the database value to a value that can be used by the editor.
        /// </summary>
        /// <param name="contentType">
        /// The content type.
        /// </param>
        /// <param name="dcv">
        /// The detached content value.
        /// </param>
        /// <returns>
        /// The converted value.
        /// </returns>
        private KeyValuePair <string, string> ConvertDbToEditor(IContentType contentType, KeyValuePair <string, string> dcv)
        {
            var propType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == dcv.Key);

            if (propType == null)
            {
                return(dcv);
            }

            // Lookup the property editor
            var propEditor = PropertyEditorResolver.Current.GetByAlias(propType.PropertyEditorAlias);

            if (propEditor.ValueEditor.IsReadOnly)
            {
                return(dcv);
            }

            object rawValue;

            try
            {
                rawValue = !JsonHelper.IsJsonObject(dcv.Value) ?
                           JsonConvert.DeserializeObject(dcv.Value) :
                           dcv.Value;
            }
            catch (Exception ex)
            {
                // try to correct the value
                rawValue = TryFixLegacyValue(dcv.Value);
            }


            //// Adapted from Nested Content
            // Create a fake property using the property to add the stored value
            var prop = new Property(propType, rawValue);

            // Get the editor to do it's conversion
            try
            {
                var editorObject = propEditor.ValueEditor.ConvertDbToEditor(prop, propType, _dataTypeService);
                var json         = JsonConvert.SerializeObject(editorObject);
                return(new KeyValuePair <string, string>(dcv.Key, json));
            }
            catch (Exception ex)
            {
                var logData = MultiLogger.GetBaseLoggingData();
                logData.AddCategory("ValueEditor");
                MultiLogHelper.WarnWithException <DetachedValuesConverter>(
                    "Failed to convert property value for Editor",
                    ex,
                    logData);

                return(dcv);
            }
        }
        /// <summary>
        /// A method to deserialize the value that has been saved by an editor
        ///             to an object to be stored in the database.
        /// </summary>
        /// <param name="contentType">
        /// The content type.
        /// </param>
        /// <param name="dcv">
        /// The detached content value.
        /// </param>
        /// <param name="additionalData">
        /// The additional Data.
        /// </param>
        /// <returns>
        /// The converted value.
        /// </returns>
        private KeyValuePair <string, string> ConvertEditorToDb(IContentType contentType, KeyValuePair <string, string> dcv, IDictionary <string, object> additionalData)
        {
            var propType = contentType.CompositionPropertyTypes.FirstOrDefault(x => x.Alias == dcv.Key);

            if (propType == null)
            {
                return(dcv);
            }

            // Lookup the property editor
            var propEditor = PropertyEditorResolver.Current.GetByAlias(propType.PropertyEditorAlias);

            if (propEditor.ValueEditor.IsReadOnly)
            {
                return(dcv);
            }

            // Fetch the property types prevalue
            var propPreValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(propType.DataTypeDefinitionId);

            var rawValue = JsonConvert.DeserializeObject(dcv.Value.Trim());

            //// Create a fake content property data object
            if (additionalData == null)
            {
                additionalData = new Dictionary <string, object>();
            }
            var contentPropData = new ContentPropertyData(rawValue, propPreValues, additionalData);

            try
            {
                // Get the property editor to do it's conversion
                var newValue = propEditor.ValueEditor.ConvertEditorToDb(contentPropData, null);

                // Store the value back
                var value = newValue == null ? string.Empty :
                            JsonHelper.IsJsonObject(newValue) ?
                            newValue.ToString() :
                            JsonConvert.SerializeObject(newValue);


                return(new KeyValuePair <string, string>(dcv.Key, value));
            }
            catch (Exception ex)
            {
                var logData = MultiLogger.GetBaseLoggingData();
                logData.AddCategory("ValueEditor");
                MultiLogHelper.WarnWithException <DetachedValuesConverter>(
                    "Failed to convert property value for Database",
                    ex,
                    logData);

                return(dcv);
            }
        }
        /// <summary>
        /// Builds a combined list of each possible filter count next given the current context (already filtered keys).
        /// </summary>
        /// <param name="filterGroups">
        /// The filter groups.
        /// </param>
        /// <param name="collectionKeys">
        /// The collection keys.
        /// </param>
        /// <returns>
        /// The collection of possible filtered keys.
        /// </returns>
        private static IEnumerable <Guid[]> GetContextKeys(IEnumerable <IProductFilterGroup> filterGroups, params Guid[] collectionKeys)
        {
            var contextKeys = new List <Guid[]>();

            var cks = !collectionKeys.Any() ? new Guid[] { } : collectionKeys;

            var groups = filterGroups as IProductFilterGroup[] ?? filterGroups.ToArray();

            try
            {
                if (!groups.Any())
                {
                    return new[] { cks }
                }
                ;

                // we need individual sets of filter group keys, eached combined with the collection keys
                // to create the context for the filter groups
                var groupKeys = groups.Select(x => x.Key).ToArray();

                // then we need the individual filter keys, again combined with the collection keys
                // to create the context for the individual filters
                var filterKeys = new List <Guid>();
                foreach (var fg in groups)
                {
                    filterKeys.AddRange(fg.Filters.Select(f => f.Key));
                }


                // individual filter groups
                foreach (var fgk in groupKeys)
                {
                    var groupContext = cks.Select(x => x).ToList();
                    groupContext.Add(fgk);

                    contextKeys.Add(groupContext.ToArray());
                }

                // individual filters where keys are not already part of the collection keys (that would be a duplicate query)
                foreach (var fk in filterKeys.Where(x => !cks.Contains(x)))
                {
                    var filterContext = cks.Select(x => x).ToList();
                    filterContext.Add(fk);

                    contextKeys.Add(filterContext.ToArray());
                }
            }
            catch (Exception ex)
            {
                MultiLogHelper.WarnWithException <PrimedProductFilterGroupTree>("Failed to query for all filter groups", ex);
            }

            return(contextKeys);
        }
 /// <summary>
 /// Sets an object value into an extended data collection
 /// </summary>
 /// <param name="extendedData">
 /// The extended data.
 /// </param>
 /// <param name="key">
 /// The key.
 /// </param>
 /// <param name="model">
 /// The model.
 /// </param>
 /// <typeparam name="T">
 /// The type of object to be serialized
 /// </typeparam>
 public static void SetValue <T>(this ExtendedDataCollection extendedData, string key, T model) where T : class, new()
 {
     try
     {
         var value = JsonConvert.SerializeObject(model);
         extendedData.SetValue(key, value);
     }
     catch (Exception ex)
     {
         var logData = MultiLogger.GetBaseLoggingData();
         logData.AddCategory("ExtendedData");
         MultiLogHelper.WarnWithException(typeof(Extensions), "Failed to serialize value. Proceding with operation.", ex, logData);
     }
 }
Пример #7
0
        /// <summary>
        /// Maps <see cref="ICurrency"/> to <see cref="CurrencyCodeType"/>.
        /// </summary>
        /// <param name="currencyCode">
        /// The currency code.
        /// </param>
        /// <returns>
        /// The <see cref="CurrencyCodeType"/>.
        /// </returns>
        public static CurrencyCodeType GetPayPalCurrencyCode(string currencyCode)
        {
            try
            {
                return((CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), currencyCode, true));
            }
            catch (Exception ex)
            {
                var logData = MultiLogger.GetBaseLoggingData();
                logData.AddCategory("PayPal");

                MultiLogHelper.WarnWithException <PayPalBasicAmountTypeFactory>("Failed to map currency code", ex, logData);

                throw;
            }
        }
 /// <summary>
 /// Gets a typed value.
 /// </summary>
 /// <param name="extendedData">
 /// The extended data.
 /// </param>
 /// <param name="key">
 /// The key.
 /// </param>
 /// <typeparam name="T">
 /// The type to be returned.
 /// </typeparam>
 /// <returns>
 /// The typed value.
 /// </returns>
 public static T GetValue <T>(this ExtendedDataCollection extendedData, string key) where T : class, new()
 {
     try
     {
         var value = extendedData.GetValue(key);
         return(!value.IsNullOrWhiteSpace() ?
                JsonConvert.DeserializeObject <T>(value) :
                default(T));
     }
     catch (Exception ex)
     {
         var logData = MultiLogger.GetBaseLoggingData();
         logData.AddCategory("ExtendedData");
         MultiLogHelper.WarnWithException(typeof(Extensions), "Failed to deserialize value. Proceding with operation returning default T.", ex, logData);
         return(default(T));
     }
 }
        /// <summary>
        /// Deserializes the <see cref="CustomerContextData"/> from JSON
        /// </summary>
        /// <param name="contextCookie">
        /// The context cookie.
        /// </param>
        /// <returns>
        /// The <see cref="CustomerContextData"/>.
        /// </returns>
        public static CustomerContextData ToCustomerContextData(this HttpCookie contextCookie)
        {
            if (contextCookie == null || string.IsNullOrEmpty(contextCookie.Value))
            {
                LogHelper.Debug(typeof(CustomerContextDataExtensions), "The CustomerContext cookie was null");
                return(null);
            }

            try
            {
                return(JsonConvert.DeserializeObject <CustomerContextData>(EncryptionHelper.Decrypt(contextCookie.Value)));
            }
            catch (Exception ex)
            {
                MultiLogHelper.WarnWithException(typeof(CustomerContextDataExtensions), "Failed to decrypt custom context data", ex);
                return(new CustomerContextData());
            }
        }
        /// <summary>
        /// Value to pass to the notification monitors with additional contacts not defined in notification message (ex. an instance specific customer or vender)
        /// </summary>
        /// <param name="model">
        /// The model.
        /// </param>
        /// <param name="contacts">
        /// The contacts.
        /// </param>
        public virtual void Notify(object model, IEnumerable <string> contacts)
        {
            // check to see if the model passed is the correct type or null
            if (WillWork <TInputModel>(model))
            {
                Notify((TInputModel)model, contacts);
                return;
            }

            var invalid =
                new ArgumentException(
                    string.Format(
                        "Model passed to NotificationTriggerBase {0} does not match expected model {1}.  Notification trigger was skipped.",
                        model.GetType(),
                        typeof(TInputModel)));

            MultiLogHelper.WarnWithException <NotificationTriggerBase <TInputModel, TMonitorModel> >(
                "Invalid notification model",
                invalid);
        }
Пример #11
0
        /// <summary>
        /// The convert data to source.
        /// </summary>
        /// <param name="propertyType">
        /// The property type.
        /// </param>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="preview">
        /// The preview.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
        {
            var merchello = new MerchelloHelper();

            if (source == null)
            {
                return(null);
            }

            var productKeys = JsonConvert.DeserializeObject <IEnumerable <Guid> >(source.ToString());

            try
            {
                var products = productKeys.Select(key => merchello.TypedProductContent(key)).ToList();

                return(products);
            }
            catch (Exception ex)
            {
                MultiLogHelper.WarnWithException <MultiProductPickerValueConverter>("Failed to Convert property to IProductContent", ex);
                return(null);
            }
        }
        /// <summary>
        /// Gets the provider attribute for providers responsible for specified filter attribute collections.
        /// </summary>
        /// <param name="collectionKey">
        /// The collection key.
        /// </param>
        /// <returns>
        /// The <see cref="EntityCollectionProviderAttribute"/>.
        /// </returns>
        public EntityCollectionProviderAttribute GetProviderAttributeForFilter(Guid collectionKey)
        {
            var attempt = GetProviderForCollection(collectionKey);

            if (!attempt.Success)
            {
                MultiLogHelper.WarnWithException <EntityCollectionProviderResolver>(
                    "Failed to retreive provider for collection",
                    attempt.Exception);

                return(null);
            }

            var provider = attempt.Result as IEntityFilterGroupProvider;

            if (provider == null)
            {
                var nullRef = new NullReferenceException("Provider found did not implement IEntityFilterProvider");
                MultiLogHelper.WarnWithException <EntityCollectionProviderResolver>("Invalid type", nullRef);
                return(null);
            }

            return(GetProviderAttribute(provider.FilterProviderType).FirstOrDefault());
        }