コード例 #1
0
 public DinteroPaymentGateway(IFeatureSwitch featureSwitch, IInventoryProcessor inventoryProcessor,
                              IOrderRepository orderRepository)
 {
     _featureSwitch      = featureSwitch;
     _inventoryProcessor = inventoryProcessor;
     _orderRepository    = orderRepository;
     _requestsHelper     = new DinteroRequestsHelper();
 }
コード例 #2
0
 public PayooCartService(
     IFeatureSwitch featureSwitch,
     IInventoryProcessor inventoryProcessor,
     IOrderRepository orderRepository)
 {
     _featureSwitch      = featureSwitch;
     _inventoryProcessor = inventoryProcessor;
     _orderRepository    = orderRepository;
 }
コード例 #3
0
ファイル: InProcProvider.cs プロジェクト: hotstone/femah
        /// <summary>
        /// Save the feature switch's details and type.
        /// </summary>
        /// <param name="featureSwitch"></param>
        public void Save(IFeatureSwitch featureSwitch)
        {
            var currentFeatureSwitch = _featureSwitches.FirstOrDefault(fs => String.Equals(fs.Name, featureSwitch.Name, StringComparison.InvariantCultureIgnoreCase));

            if (currentFeatureSwitch != null)
            {
                _featureSwitches.Remove(currentFeatureSwitch);
                _featureSwitches.Add(featureSwitch);
            }
        }
コード例 #4
0
        public DIBSPaymentGateway(
            IFeatureSwitch featureSwitch,
            IInventoryProcessor inventoryProcessor,
            IOrderRepository orderRepository,
            LocalizationService localizationService)
        {
            _featureSwitch       = featureSwitch;
            _inventoryProcessor  = inventoryProcessor;
            _orderRepository     = orderRepository;
            _localizationService = localizationService;

            _dibsRequestHelper = new DIBSRequestHelper();
        }
コード例 #5
0
        public void EndToEnd_True()
        {
            string xml = @"<?xml version=""1.0"" encoding=""utf-8""?>

<Features xmlns=""https://www.kcl-data.com"">
    <Feature Key=""Login"" Enabled=""true""/>
</Features>";

            System.IO.MemoryStream stream = new System.IO.MemoryStream(System.Text.Encoding.Default.GetBytes(xml));

            IFeatureSwitch fs = FeatureSwitch.Create(stream);

            Assert.IsTrue(fs["Login"]);
        }
コード例 #6
0
        public PayPalPaymentGateway(
            IFeatureSwitch featureSwitch,
            IInventoryProcessor inventoryProcessor,
            IOrderNumberGenerator orderNumberGenerator,
            IOrderRepository orderRepository,
            IOrderGroupCalculator orderGroupCalculator,
            PayPalAPIHelper paypalAPIHelper)
        {
            _featureSwitch        = featureSwitch;
            _inventoryProcessor   = inventoryProcessor;
            _orderNumberGenerator = orderNumberGenerator;
            _orderRepository      = orderRepository;
            _orderGroupCalculator = orderGroupCalculator;
            _payPalAPIHelper      = paypalAPIHelper;

            _paymentMethodConfiguration = new PayPalConfiguration(Settings);
        }
コード例 #7
0
        public DataCashPaymentGateway(
            IOrderRepository orderRepository,
            IInventoryProcessor inventoryProcessor,
            IOrderNumberGenerator orderNumberGenerator,
            IFeatureSwitch featureSwitch,
            LocalizationService localizationService,
            DataCashConfiguration dataCashConfiguration,
            RequestDocumentCreation requestDocumentCreation)
        {
            _orderRepository      = orderRepository;
            _inventoryProcessor   = inventoryProcessor;
            _orderNumberGenerator = orderNumberGenerator;
            _localizationService  = localizationService;
            _featureSwitch        = featureSwitch;

            _dataCashConfiguration   = dataCashConfiguration;
            _requestDocumentCreation = requestDocumentCreation;
        }
コード例 #8
0
        public void CreateFeatures()
        {
            var mockAlwaysEnabled = new Mock <IFeatureSwitch>();

            mockAlwaysEnabled.Setup(x => x.IsEnabledForRequest(It.IsAny <IRequest>()))
            .Returns(Task.FromResult(true));
            alwaysEnabledSwitch = mockAlwaysEnabled.Object;

            var mockAlwaysDisabled = new Mock <IFeatureSwitch>();

            mockAlwaysDisabled.Setup(x => x.IsEnabledForRequest(It.IsAny <IRequest>()))
            .Returns(Task.FromResult(false));
            alwaysDisabledSwitch = mockAlwaysDisabled.Object;

            var mockLocalhostOnly = new Mock <IFeatureSwitch>();

            mockLocalhostOnly.Setup(x => x.IsEnabledForRequest(It.IsAny <IRequest>()))
            .Returns(Task.FromResult(false));
            mockLocalhostOnly.Setup(x => x.IsEnabledForRequest(It.Is <IRequest>(req => req.Url.IsLoopback)))
            .Returns(Task.FromResult(true));
            localhostOnlySwitch = mockLocalhostOnly.Object;

            var mockLocalRequest = new Mock <IRequest>();

            mockLocalRequest.SetupGet(x => x.Url).Returns(new Uri("http://localhost/"));
            localRequest = mockLocalRequest.Object;

            var mockNonLocalRequest = new Mock <IRequest>();

            mockNonLocalRequest.SetupGet(x => x.Url).Returns(new Uri("http://example.com"));
            nonLocalRequest = mockNonLocalRequest.Object;


            switchboard = new FeatureSwitchboard(null)
                          .Add(this.alwaysEnabledSwitch, this.alwaysEnabled)
                          .Add(this.alwaysDisabledSwitch, this.alwaysDisabled)
                          .Add(this.localhostOnlySwitch, this.localhostOnly);
        }
コード例 #9
0
ファイル: FemahHttpHandler.cs プロジェクト: hotstone/femah
        /// <summary>
        /// Render a single feature row to the table of features.
        /// </summary>
        /// <param name="writer">A <see cref="HtmlTextWriter"/> to use to render the HTML.</param>
        /// <param name="feature">The <see cref="IFeatureSwitch"/> to render.</param>
        private void RenderFeatureRow(HtmlTextWriter writer, IFeatureSwitch feature)
        {
            writer.RenderBeginTag(HtmlTextWriterTag.Tr);

            // Feature name.
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
            writer.Write(feature.Name);
            writer.RenderEndTag(/* Td */);

            // Feature type.
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
            writer.Write(feature.GetType().Name);

            var switchTypes = Core.Femah.AllSwitchTypes();
            if ( switchTypes.Count >= 2 )
            {
                writer.AddAttribute("action", "/femah.axd");
                writer.RenderBeginTag(HtmlTextWriterTag.Form);
                writer.Write(String.Format("<input type='hidden' name='action' value='{0}'></input>", _setSwitchTypeAction ));
                writer.Write(String.Format("<input type='hidden' name='name' value='{0}'></input>", feature.Name));
                writer.AddAttribute(HtmlTextWriterAttribute.Name, "switchtype");
                writer.RenderBeginTag(HtmlTextWriterTag.Select);
                foreach ( var switchType in switchTypes )
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Value, switchType.AssemblyQualifiedName);
                    writer.RenderBeginTag(HtmlTextWriterTag.Option);
                    writer.Write(switchType.Name);
                    writer.RenderEndTag(/* Option */);
                }
                writer.RenderEndTag(/* Select */);
                writer.Write("<input type='submit' value='Change'></input>");
                writer.RenderEndTag(/* Form */);
            }
            writer.RenderEndTag(/* Td */);

            // Enabled or disabled.
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
            writer.Write(feature.IsEnabled ? "Enabled" : "Disabled");

            writer.AddAttribute("action","/femah.axd");
            writer.RenderBeginTag(HtmlTextWriterTag.Form);
            writer.Write(String.Format("<input type='hidden' name='action' value='{0}'></input>", _enableFeatureAction));
            writer.Write(String.Format("<input type='hidden' name='name' value='{0}'></input>", feature.Name));
            writer.Write(String.Format("<input type='hidden' name='enabled' value='{0}'></input>", !feature.IsEnabled));
            writer.Write(String.Format("<input type='submit' value='{0}'></input>", feature.IsEnabled ? "Disable" : "Enable"));
            writer.RenderEndTag(/* Form */);
            writer.RenderEndTag(/* Td */);

            // Custom attributes.
            writer.RenderBeginTag(HtmlTextWriterTag.Td);
            writer.RenderBeginTag(HtmlTextWriterTag.Form);
            writer.Write(String.Format("<input type='hidden' name='name' value='{0}'></input>", feature.Name));
            writer.Write(String.Format("<input type='hidden' name='action' value='{0}'></input>", _setCustomAttributesAction));
            feature.RenderUi(writer);
            writer.RenderEndTag(/* Form*/);
            writer.RenderEndTag(/* Td */);

            writer.RenderEndTag(/* Tr */);
        }
コード例 #10
0
 public FeatureSwitchboard Add(IFeatureSwitch @switch, Feature feature)
 {
     this.switches.Add(new FeatureSwitchLink(@switch, feature));
     return(this);
 }
コード例 #11
0
 public FeatureSwitchLink(IFeatureSwitch @switch, Feature feature)
 {
     this.Switch  = @switch;
     this.Feature = feature;
 }
コード例 #12
0
ファイル: ApiResponseBuilder.cs プロジェクト: hotstone/femah
 public ApiResponseBuilder CreateWithUpdatedFeatureSwitch(IFeatureSwitch featureSwitch)
 {
     _update = true;
     var fs = new List<IFeatureSwitch> { featureSwitch };
     _featureSwitches = fs;
     return this;
 }
コード例 #13
0
ファイル: ApiResponseBuilder.cs プロジェクト: hotstone/femah
 public ApiResponseBuilder CreateWithFeatureSwitches(IFeatureSwitch featureSwitch)
 {
     var fs = new List<IFeatureSwitch> {featureSwitch};
     _featureSwitches = fs;
     return this;
 }
コード例 #14
0
ファイル: SqlServerProvider.cs プロジェクト: hotstone/femah
        /// <summary>
        /// Save the feature switch to the database.  If the switch already exists in the db, it
        /// is updated, otherwise inserted.
        /// </summary>
        /// <param name="featureSwitch">The feature switch to be written to the database</param>
        /// <param name="conn">An open connection to the database</param>
        protected void SaveOrUpdateSwitch(IFeatureSwitch featureSwitch, SqlConnection conn)
        {
            var nameParam = new SqlParameter("@Param1", SqlDbType.NVarChar);
            nameParam.Value = featureSwitch.Name;
            var cmd = new SqlCommand(this.SwitchCountSql, conn);
            cmd.Parameters.Add(nameParam);

            Int32 rowCount = (Int32) cmd.ExecuteScalar();
            if (rowCount >= 1)
            {
                // Update.
                cmd = new SqlCommand(this.UpdateSwitchSql, conn);
            }
            else
            {
                // Insert.
                cmd = new SqlCommand(this.InsertSwitchSql, conn);
            }

            nameParam = new SqlParameter("@SwitchName", SqlDbType.NVarChar);
            nameParam.Value = featureSwitch.Name;
            cmd.Parameters.Add(nameParam);

            var param = new SqlParameter("@IsEnabled", SqlDbType.Bit);
            param.Value = featureSwitch.IsEnabled;
            cmd.Parameters.Add(param);

            param = new SqlParameter("@AssemblyName", SqlDbType.NVarChar);
            param.Value = featureSwitch.GetType().Assembly.FullName;
            cmd.Parameters.Add(param);

            param = new SqlParameter("@TypeName", SqlDbType.NVarChar);
            param.Value = featureSwitch.GetType().FullName;
            cmd.Parameters.Add(param);

            param = new SqlParameter("@SwitchXml", SqlDbType.Xml);
            XmlSerializer serializer = new XmlSerializer(featureSwitch.GetType());
            var sb = new StringBuilder();
            var writer = new StringWriter(sb);
            serializer.Serialize(writer, featureSwitch);
            param.Value = sb.ToString();
            cmd.Parameters.Add(param);

            cmd.ExecuteNonQuery();
        }
コード例 #15
0
ファイル: SqlServerProvider.cs プロジェクト: hotstone/femah
 /// <summary>
 /// Save a feature switch.
 /// </summary>
 /// <param name="featureSwitch">The feature to be saved</param>
 public void Save(IFeatureSwitch featureSwitch)
 {
     using (var conn = new SqlConnection(_connectionString))
     {
         conn.Open();
         this.SaveOrUpdateSwitch(featureSwitch, conn);
     }
 }