Пример #1
0
        /// <summary>
        /// Initializes a Autoprefixer
        /// </summary>
        private void Initialize()
        {
            if (_initialized)
            {
                return;
            }

            lock (_initializationSynchronizer)
            {
                if (_initialized)
                {
                    return;
                }

                try
                {
                    _jsEngine.EmbedHostObject(COUNTRY_STATISTICS_SERVICE_VARIABLE_NAME,
                                              CountryStatisticsService.Instance);

                    Assembly assembly = this.GetType()
#if !NET40
                                        .GetTypeInfo()
#endif
                                        .Assembly
                    ;

                    _jsEngine.ExecuteResource(ResourceHelpers.GetResourceName(AUTOPREFIXER_LIBRARY_FILE_NAME),
                                              assembly);
                    _jsEngine.ExecuteResource(ResourceHelpers.GetResourceName(AUTOPREFIXER_HELPER_FILE_NAME),
                                              assembly);
                    _jsEngine.Execute($"var autoprefixerHelper = new AutoprefixerHelper({_serializedOptions});");
                }
                catch (JsException e)
                {
                    throw AutoprefixerErrorHelpers.WrapAutoprefixerLoadException(e, true);
                }

                _initialized = true;
            }
        }
Пример #2
0
        /// <summary>
        /// Constructs an instance of the Autoprefixer
        /// </summary>
        /// <param name="jsEngineFactory">JS engine factory</param>
        /// <param name="options">Processing options</param>
        public Autoprefixer(IJsEngineFactory jsEngineFactory, ProcessingOptions options)
        {
            if (jsEngineFactory == null)
            {
                throw new ArgumentNullException(nameof(jsEngineFactory));
            }

            _options           = options ?? _defaultOptions;
            _serializedOptions = SerializeProcessingOptions(_options);

            try
            {
                _jsEngine = jsEngineFactory.CreateEngine();
            }
            catch (JsEngineLoadException e)
            {
                throw AutoprefixerErrorHelpers.WrapAutoprefixerLoadException(e);
            }
            catch (Exception e)
            {
                throw AutoprefixerErrorHelpers.WrapAutoprefixerLoadException(e, true);
            }
        }
Пример #3
0
        /// <summary>
        /// Constructs an instance of the Autoprefixer
        /// </summary>
        /// <param name="createJsEngineInstance">Delegate that creates an instance of JS engine</param>
        /// <param name="options">Processing options</param>
        public Autoprefixer(Func <IJsEngine> createJsEngineInstance, ProcessingOptions options)
        {
            if (createJsEngineInstance == null)
            {
                throw new ArgumentNullException(nameof(createJsEngineInstance));
            }

            _options           = options ?? _defaultOptions;
            _serializedOptions = SerializeProcessingOptions(_options);

            try
            {
                _jsEngine = createJsEngineInstance();
            }
            catch (JsEngineLoadException e)
            {
                throw AutoprefixerErrorHelpers.WrapAutoprefixerLoadException(e);
            }
            catch (Exception e)
            {
                throw AutoprefixerErrorHelpers.WrapAutoprefixerLoadException(e, true);
            }
        }