Ejemplo n.º 1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                if (Creating != null)
                {
                    Creating.Invoke(this, EventArgs.Empty);
                }

                //ToolMobile.log("set form [" + this.GetType().FullName + "] layout");

                base.OnCreate(savedInstanceState);

                //   setEnvironment(ToolMobile.getEnvironment());

                if (designId >= 0)
                {
                    SetContentView(designId == 0 ? Resource.Layout.form : designId);
                }

                if (Created != null)
                {
                    Created.Invoke(this, EventArgs.Empty);
                }

                this.Window.SetSoftInputMode(SoftInput.StateAlwaysHidden);
                //   (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
            }
            catch (Exception exc)
            {
                ToolMobile.setException(exc);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates and saves a payment
        /// </summary>
        /// <param name="paymentTfKey">The payment typefield key</param>
        /// <param name="amount">The amount of the payment</param>
        /// <param name="paymentMethodKey">The optional paymentMethodKey</param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param>
        /// <returns>Returns <see cref="IPayment"/></returns>
        internal IPayment CreatePaymentWithKey(Guid paymentTfKey, decimal amount, Guid?paymentMethodKey, bool raiseEvents = true)
        {
            Mandate.ParameterCondition(!Guid.Empty.Equals(paymentTfKey), "paymentTfKey");


            var payment = new Payment(paymentTfKey, amount, paymentMethodKey, new ExtendedDataCollection());

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IPayment>(payment), this))
                {
                    payment.WasCancelled = true;
                    return(payment);
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreatePaymentRepository(uow))
                {
                    repository.AddOrUpdate(payment);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IPayment>(payment), this);
            }

            return(payment);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a <see cref="Subscription"/>.
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <returns>
        /// The <see cref="Attempt{Subscription}"/>.
        /// </returns>
        public Attempt <Subscription> Create(SubscriptionRequest request)
        {
            Creating.RaiseEvent(new Core.Events.NewEventArgs <SubscriptionRequest>(request), this);

            LogHelper.Info <BraintreeTransactionApiService>(string.Format("Braintree create subscription attempt PlanID: {0}, Price: {1}", request.PlanId, request.Price));
            var attempt = this.TryGetApiResult(() => this.BraintreeGateway.Subscription.Create(request));

            if (!attempt.Success)
            {
                return(Attempt <Subscription> .Fail(attempt.Exception));
            }

            var result = attempt.Result;

            if (result.IsSuccess())
            {
                Created.RaiseEvent(new Core.Events.NewEventArgs <Subscription>(result.Target), this);

                return(Attempt <Subscription> .Succeed(result.Target));
            }

            var error = new BraintreeApiException(result.Errors, result.Message);

            LogHelper.Error <BraintreeSubscriptionApiService>("Failed to create a subscription", error);

            return(Attempt <Subscription> .Fail(error));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a note and saves it to the database
        /// </summary>
        /// <param name="entityKey">
        /// The entity key.
        /// </param>
        /// <param name="entityTfKey">
        /// The entity type field key.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="INote"/>.
        /// </returns>
        public INote CreateNoteWithKey(Guid entityKey, Guid entityTfKey, string message, bool raiseEvents = true)
        {
            var note = CreateNote(entityKey, entityTfKey, message, raiseEvents);

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <INote>(note), this))
                {
                    ((Note)note).WasCancelled = true;
                    return(note);
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateNoteRepository(uow))
                {
                    repository.AddOrUpdate(note);
                    uow.Commit();
                }
            }

            Created.RaiseEvent(new Events.NewEventArgs <INote>(note), this);

            return(note);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a <see cref="IShipment"/> without persisting it to the database.
        /// </summary>
        /// <param name="shipmentStatus">
        /// The shipment status.
        /// </param>
        /// <param name="origin">
        /// The origin.
        /// </param>
        /// <param name="destination">
        /// The destination.
        /// </param>
        /// <param name="items">
        /// The items.
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="IShipment"/>.
        /// </returns>
        public IShipment CreateShipment(IShipmentStatus shipmentStatus, IAddress origin, IAddress destination, LineItemCollection items, bool raiseEvents = true)
        {
            Mandate.ParameterNotNull(shipmentStatus, "shipmentStatus");
            Mandate.ParameterNotNull(origin, "origin");
            Mandate.ParameterNotNull(destination, "destination");
            Mandate.ParameterNotNull(items, "items");

            // Use the visitor to filter out and validate shippable line items
            var visitor = new ShippableProductVisitor();

            items.Accept(visitor);

            var lineItemCollection = new LineItemCollection();

            foreach (var item in visitor.ShippableItems)
            {
                lineItemCollection.Add(item);
            }

            var shipment = new Shipment(shipmentStatus, origin, destination, lineItemCollection)
            {
                VersionKey = Guid.NewGuid()
            };

            if (!raiseEvents)
            {
                return(shipment);
            }

            Creating.RaiseEvent(new Events.NewEventArgs <IShipment>(shipment), this);
            return(shipment);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a <see cref="IProductVariant"/> of the <see cref="IProduct"/> passed defined by the collection of <see cref="IProductAttribute"/>
        /// </summary>
        /// <param name="product">The <see cref="IProduct"/></param>
        /// <param name="name">The name of the product variant</param>
        /// <param name="sku">The unique sku of the product variant</param>
        /// <param name="price">The price of the product variant</param>
        /// <param name="attributes">The <see cref="IProductVariant"/></param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param>
        /// <returns>Either a new <see cref="IProductVariant"/> or, if one already exists with associated attributes, the existing <see cref="IProductVariant"/></returns>
        public IProductVariant CreateProductVariantWithKey(IProduct product, string name, string sku, decimal price, ProductAttributeCollection attributes, bool raiseEvents = true)
        {
            var productVariant = CreateProductVariant(product, name, sku, price, attributes);

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IProductVariant>(productVariant), this))
                {
                    ((ProductVariant)productVariant).WasCancelled = true;
                    return(productVariant);
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = _uowProvider.GetUnitOfWork();
                using (var repository = _repositoryFactory.CreateProductVariantRepository(uow))
                {
                    repository.AddOrUpdate(productVariant);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IProductVariant>(productVariant), this);
            }

            product.ProductVariants.Add(productVariant);

            return(productVariant);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a Braintree <see cref="Customer"/> from a Merchello <see cref="ICustomer"/>
        /// </summary>
        /// <param name="customer">
        /// The customer.
        /// </param>
        /// <param name="paymentMethodNonce">
        /// The "nonce-from-the-client"
        /// </param>
        /// <param name="billingAddress">
        /// The billing address
        /// </param>
        /// <param name="shippingAddress">
        /// The shipping Address.
        /// </param>
        /// <returns>
        /// The <see cref="Attempt{Customer}"/>.
        /// </returns>
        public Attempt <Customer> Create(ICustomer customer, string paymentMethodNonce = "", IAddress billingAddress = null, IAddress shippingAddress = null)
        {
            if (this.Exists(customer))
            {
                return(Attempt.Succeed(this.GetBraintreeCustomer(customer)));
            }

            var request = this.RequestFactory.CreateCustomerRequest(customer, paymentMethodNonce, billingAddress);

            Creating.RaiseEvent(new Core.Events.NewEventArgs <CustomerRequest>(request), this);

            // attempt the API call
            LogHelper.Info <BraintreeTransactionApiService>(string.Format("Braintree Create customer attempt for CustomerKey: {0}, name: {1}", customer.Key, customer.FullName));
            var attempt = this.TryGetApiResult(() => this.BraintreeGateway.Customer.Create(request));

            if (!attempt.Success)
            {
                return(Attempt <Customer> .Fail(attempt.Exception));
            }

            var result = attempt.Result;

            if (result.IsSuccess())
            {
                Created.RaiseEvent(new Core.Events.NewEventArgs <Customer>(result.Target), this);

                return(Attempt.Succeed((Customer)this.RuntimeCache.GetCacheItem(this.MakeCustomerCacheKey(customer), () => result.Target, TimeSpan.FromHours(6))));
            }

            var error = new BraintreeApiException(result.Errors);

            LogHelper.Error <BraintreeCustomerApiService>("Braintree API Customer Create return a failure", error);

            return(Attempt <Customer> .Fail(error));
        }
Ejemplo n.º 8
0
        /// <summary />
        internal static OpenStackNetConfigurationOptions Create()
        {
            var createEvent = new CreateEvent();

            Creating?.Invoke(createEvent);
            return(createEvent.Result);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates and saves a <see cref="IProduct"/> to the database
        /// </summary>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="sku">
        /// The SKU.
        /// </param>
        /// <param name="price">
        /// The price.
        /// </param>
        /// <returns>
        /// The <see cref="IProduct"/>.
        /// </returns>
        public IProduct CreateProductWithKey(string name, string sku, decimal price)
        {
            var templateVariant = new ProductVariant(name, sku, price);
            var product         = new Product(templateVariant);

            if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IProduct>(product), this))
            {
                product.WasCancelled = true;
                return(product);
            }

            using (new WriteLock(Locker))
            {
                var uow = _uowProvider.GetUnitOfWork();
                using (var repository = _repositoryFactory.CreateProductRepository(uow))
                {
                    repository.AddOrUpdate(product);
                    uow.Commit();
                }
            }

            Created.RaiseEvent(new Events.NewEventArgs <IProduct>(product), this);

            return(product);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates a customer and saves the record to the database
        /// </summary>
        /// <param name="loginName">
        /// The login Name.
        /// </param>
        /// <param name="firstName">
        /// The first name of the customer
        /// </param>
        /// <param name="lastName">
        /// The last name of the customer
        /// </param>
        /// <param name="email">
        /// the email address of the customer
        /// </param>
        /// <returns>
        /// <see cref="ICustomer"/>
        /// </returns>
        public ICustomer CreateCustomerWithKey(string loginName, string firstName, string lastName, string email)
        {
            Mandate.ParameterNotNullOrEmpty(loginName, "loginName");

            var customer = new Customer(loginName)
            {
                FirstName = firstName,
                LastName  = lastName,
                Email     = email
            };

            if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <ICustomer>(customer), this))
            {
                customer.WasCancelled = true;
                return(customer);
            }

            using (new WriteLock(Locker))
            {
                var uow = _uowProvider.GetUnitOfWork();
                using (var repository = _repositoryFactory.CreateCustomerRepository(uow))
                {
                    repository.AddOrUpdate(customer);
                    uow.Commit();
                }
            }

            SaveAddresses(customer);

            Created.RaiseEvent(new Events.NewEventArgs <ICustomer>(customer), this);

            return(customer);
        }
        /// <summary>
        /// Creates a <see cref="IProductOption"/> without saving it to the database.
        /// </summary>
        /// <param name="name">
        /// The option name.
        /// </param>
        /// <param name="shared">
        /// A value indicating whether or not this is a shared option (usable by multiple products).
        /// </param>
        /// <param name="required">
        /// The required.
        /// </param>
        /// <param name="raiseEvents">
        ///  Optional boolean indicating whether or not to raise events.
        /// </param>
        /// <returns>
        /// The <see cref="IProductOption"/>.
        /// </returns>
        public IProductOption CreateProductOption(string name, bool shared = false, bool required = true, bool raiseEvents = true)
        {
            var option = new ProductOption(name)
            {
                UseName  = name,
                Shared   = shared,
                Required = required
            };

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IProductOption>(option), this))
                {
                    option.WasCancelled = true;
                    return(option);
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IProductOption>(option), this);
            }

            return(option);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates an audit record and saves it to the database
        /// </summary>
        /// <param name="entityKey">
        /// The entity key.
        /// </param>
        /// <param name="entityTfKey">
        /// The entity type field key.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <param name="extendedData">
        /// The extended data.
        /// </param>
        /// <param name="isError">
        /// Designates whether or not this is an error log record
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="IAuditLog"/>.
        /// </returns>
        public IAuditLog CreateAuditLogWithKey(Guid?entityKey, Guid?entityTfKey, string message, ExtendedDataCollection extendedData, bool isError = false, bool raiseEvents = true)
        {
            var auditLog = new AuditLog()
            {
                EntityKey    = entityKey,
                EntityTfKey  = entityTfKey,
                Message      = message,
                ExtendedData = extendedData,
                IsError      = isError
            };

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IAuditLog>(auditLog), this))
                {
                    auditLog.WasCancelled = true;
                    return(auditLog);
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateAuditLogRepository(uow))
                {
                    repository.AddOrUpdate(auditLog);
                    uow.Commit();
                }
            }

            Created.RaiseEvent(new Events.NewEventArgs <IAuditLog>(auditLog), this);

            return(auditLog);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates an <see cref="IMedia"/> object using the alias of the <see cref="IMediaType"/>
        /// that this Media should based on.
        /// </summary>
        /// <remarks>
        /// This method returns an <see cref="IMedia"/> object that has been persisted to the database
        /// and therefor has an identity.
        /// </remarks>
        /// <param name="name">Name of the Media object</param>
        /// <param name="parent">Parent <see cref="IMedia"/> for the new Media item</param>
        /// <param name="mediaTypeAlias">Alias of the <see cref="IMediaType"/></param>
        /// <param name="userId">Optional id of the user creating the media item</param>
        /// <returns><see cref="IMedia"/></returns>
        public IMedia CreateMediaWithIdentity(string name, IMedia parent, string mediaTypeAlias, int userId = 0)
        {
            var mediaType = FindMediaTypeByAlias(mediaTypeAlias);
            var media     = new Models.Media(name, parent, mediaType);

            if (Creating.IsRaisedEventCancelled(new NewEventArgs <IMedia>(media, mediaTypeAlias, parent), this))
            {
                media.WasCancelled = true;
                return(media);
            }

            using (new WriteLock(Locker))
            {
                var uow = _uowProvider.GetUnitOfWork();
                using (var repository = _repositoryFactory.CreateMediaRepository(uow))
                {
                    media.CreatorId = userId;
                    repository.AddOrUpdate(media);
                    uow.Commit();

                    var xml = media.ToXml();
                    CreateAndSaveMediaXml(xml, media.Id, uow.Database);
                }
            }

            Created.RaiseEvent(new NewEventArgs <IMedia>(media, false, mediaTypeAlias, parent), this);

            Audit.Add(AuditTypes.New, "", media.CreatorId, media.Id);

            return(media);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Creates a Braintree <see cref="Customer"/> from a Merchello <see cref="ICustomer"/>
        /// </summary>
        /// <param name="customer">
        /// The customer.
        /// </param>
        /// <param name="paymentMethodNonce">
        /// The "nonce-from-the-client"
        /// </param>
        /// <param name="billingAddress">
        /// The billing address
        /// </param>
        /// <param name="shippingAddress">
        /// The shipping Address.
        /// </param>
        /// <returns>
        /// The <see cref="Attempt{Customer}"/>.
        /// </returns>
        public Attempt <Customer> Create(ICustomer customer, string paymentMethodNonce = "", IAddress billingAddress = null, IAddress shippingAddress = null)
        {
            if (Exists(customer))
            {
                return(Attempt.Succeed(GetBraintreeCustomer(customer)));
            }

            var request = RequestFactory.CreateCustomerRequest(customer, paymentMethodNonce, billingAddress);

            Creating.RaiseEvent(new Core.Events.NewEventArgs <CustomerRequest>(request), this);

            // attempt the API call
            var attempt = TryGetApiResult(() => BraintreeGateway.Customer.Create(request));

            if (!attempt.Success)
            {
                return(Attempt <Customer> .Fail(attempt.Exception));
            }

            var result = attempt.Result;

            if (result.IsSuccess())
            {
                Created.RaiseEvent(new Core.Events.NewEventArgs <Customer>(result.Target), this);

                return(Attempt.Succeed((Customer)RuntimeCache.GetCacheItem(MakeCustomerCacheKey(customer), () => result.Target)));
            }

            var error = new BraintreeApiException(result.Errors);

            LogHelper.Error <BraintreeCustomerApiService>("Braintree API Customer Create return a failure", error);

            return(Attempt <Customer> .Fail(error));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Creates a <see cref="IInvoice"/> without saving it to the database
        /// </summary>
        /// <param name="invoiceStatusKey">The <see cref="IInvoiceStatus"/> key</param>
        /// <param name="raiseEvents">Optional boolean indicating whether or not to raise events</param>
        /// <returns><see cref="IInvoice"/></returns>
        public IInvoice CreateInvoice(Guid invoiceStatusKey, bool raiseEvents = true)
        {
            Mandate.ParameterCondition(Guid.Empty != invoiceStatusKey, "invoiceStatusKey");

            var status = GetInvoiceStatusByKey(invoiceStatusKey);

            var invoice = new Invoice(status)
            {
                VersionKey  = Guid.NewGuid(),
                InvoiceDate = DateTime.Now
            };

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IInvoice>(invoice), this))
                {
                    invoice.WasCancelled = true;
                    return(invoice);
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IInvoice>(invoice), this);
            }

            return(invoice);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Creates a customer and saves the record to the database
        /// </summary>
        /// <param name="firstName">The first name of the customer</param>
        /// <param name="lastName">The last name of the customer</param>
        /// <param name="email">the email address of the customer</param>
        /// <param name="memberId">The Umbraco member Id of the customer</param>
        /// <returns><see cref="ICustomer"/></returns>
        internal ICustomer CreateCustomerWithKey(string firstName, string lastName, string email, int?memberId = null)
        {
            var customer = new Customer(0, 0, null)
            {
                FirstName = firstName,
                LastName  = lastName,
                Email     = email,
                MemberId  = memberId
            };

            if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <ICustomer>(customer), this))
            {
                customer.WasCancelled = true;
                return(customer);
            }

            using (new WriteLock(Locker))
            {
                var uow = _uowProvider.GetUnitOfWork();
                using (var repository = _repositoryFactory.CreateCustomerRepository(uow))
                {
                    repository.AddOrUpdate(customer);
                    uow.Commit();
                }
            }

            Created.RaiseEvent(new Events.NewEventArgs <ICustomer>(customer), this);

            return(customer);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Creates a <see cref="IOrder"/> without saving it to the database
        /// </summary>
        /// <param name="orderStatusKey">
        /// The <see cref="IOrderStatus"/> key
        /// </param>
        /// <param name="invoiceKey">
        /// The invoice key
        /// </param>
        /// <param name="orderNumber">
        /// The order Number.
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="IOrder"/>.
        /// </returns>
        /// <remarks>
        /// Order number must be a positive integer value or zero
        /// </remarks>
        public IOrder CreateOrder(Guid orderStatusKey, Guid invoiceKey, int orderNumber, bool raiseEvents = true)
        {
            Mandate.ParameterCondition(!Guid.Empty.Equals(orderStatusKey), "orderStatusKey");
            Mandate.ParameterCondition(!Guid.Empty.Equals(invoiceKey), "invoiceKey");
            Mandate.ParameterCondition(orderNumber >= 0, "orderNumber must be greater than or equal to 0");

            var status = GetOrderStatusByKey(orderStatusKey);

            var order = new Order(status, invoiceKey)
            {
                VersionKey  = Guid.NewGuid(),
                OrderNumber = orderNumber,
                OrderDate   = DateTime.Now
            };

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IOrder>(order), this))
                {
                    order.WasCancelled = true;
                    return(order);
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IOrder>(order), this);
            }

            return(order);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Creates an <see cref="IOfferRedeemed"/> record
        /// </summary>
        /// <param name="offerSettings">
        /// The offer settings.
        /// </param>
        /// <param name="invoice">
        /// The invoice.
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="IOfferRedeemed"/>.
        /// </returns>
        public IOfferRedeemed CreateOfferRedeemedWithKey(IOfferSettings offerSettings, IInvoice invoice, bool raiseEvents = true)
        {
            var redemption = new OfferRedeemed(
                offerSettings.OfferCode,
                offerSettings.OfferProviderKey,
                invoice.Key,
                offerSettings.Key);

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IOfferRedeemed>(redemption), this))
                {
                    redemption.WasCancelled = true;
                    return(redemption);
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateOfferRedeemedRepository(uow))
                {
                    repository.AddOrUpdate(redemption);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IOfferRedeemed>(redemption), this);
            }

            return(redemption);
        }
        /// <summary>
        /// Creates a <see cref="Subscription"/>.
        /// </summary>
        /// <param name="request">
        /// The request.
        /// </param>
        /// <returns>
        /// The <see cref="Attempt{Subscription}"/>.
        /// </returns>
        public Attempt <Subscription> Create(SubscriptionRequest request)
        {
            Creating.RaiseEvent(new Core.Events.NewEventArgs <SubscriptionRequest>(request), this);

            var attempt = TryGetApiResult(() => BraintreeGateway.Subscription.Create(request));

            if (!attempt.Success)
            {
                return(Attempt <Subscription> .Fail(attempt.Exception));
            }

            var result = attempt.Result;

            if (result.IsSuccess())
            {
                Created.RaiseEvent(new Core.Events.NewEventArgs <Subscription>(result.Target), this);

                return(Attempt <Subscription> .Succeed(result.Target));
            }

            var error = new BraintreeApiException(result.Errors, result.Message);

            LogHelper.Error <BraintreeSubscriptionApiService>("Failed to create a subscription", error);

            return(Attempt <Subscription> .Fail(error));
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Creates a <see cref="IDigitalMedia"/> and saves it to the database.
        /// </summary>
        /// <param name="productVariantKey">
        /// Tkey for the item to work
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="IDigitalMedia"/>.
        /// </returns>
        public IDigitalMedia CreateDigitalMediaForProductVariant(Guid productVariantKey, bool raiseEvents = true)
        {
            var digitalMedia = new DigitalMedia()
            {
                FirstAccessed     = null,
                ProductVariantKey = productVariantKey
            };

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IDigitalMedia>(digitalMedia), this))
                {
                    digitalMedia.WasCancelled = true;
                    return(digitalMedia);
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateDigitalMediaRepository(uow))
                {
                    repository.AddOrUpdate(digitalMedia);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IDigitalMedia>(digitalMedia), this);
            }

            return(digitalMedia);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// A message handler for "Created" events to set the date created
        /// </summary>
        /// <param name="createMessage">The object message containing the object</param>
        public virtual void AcceptMessage(Creating <T> createMessage)
        {
            if (createMessage is null)
            {
                throw new ArgumentNullException(nameof(createMessage));
            }

            createMessage.Target.DateCreated = DateTime.Now;
        }
Ejemplo n.º 22
0
 private void Awake()
 {
     if (instance != null)
     {
         Destroy(gameObject);
     }
     instance = this;
     DontDestroyOnLoad(gameObject);
 }
Ejemplo n.º 23
0
        /* Crud */
        public Comment Save(Comment comment, bool updateTopicPostCount = true)
        {
            var newComment = comment.Id <= 0;
            var eventArgs  = new CommentEventArgs()
            {
                Comment = comment
            };

            if (newComment)
            {
                Creating.Raise(this, eventArgs);
            }
            else
            {
                Updating.Raise(this, eventArgs);
            }

            if (!eventArgs.Cancel)
            {
                //save comment
                _databaseContext.Database.Save(comment);


                //topic post count
                if (updateTopicPostCount)
                {
                    UpdateTopicPostsCount(comment);
                }

                //parent comment state
                if (comment.ParentCommentId > 0)
                {
                    var p = GetById(comment.ParentCommentId);
                    if (p != null)
                    {
                        p.HasChildren = true;
                    }
                    Save(p, false);
                }

                if (newComment)
                {
                    Created.Raise(this, eventArgs);
                }
                else
                {
                    Updated.Raise(this, eventArgs);
                }
            }
            else
            {
                CancelledByEvent.Raise(this, eventArgs);
            }

            return(comment);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="названиеи задачи"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="content"></param>
        /// <param name="priority"></param>
        /// <param name="type"></param>
        public Task([NotNull] string name, int argument1, int argument2, [NotNull] Expression <Func <int, int, bool> > content, TaskType type = TaskType.Type1, TaskPriority priority = TaskPriority.VeryLow)
        {
            Name         = name;
            _contentFunc = content ?? throw new ArgumentNullException(nameof(content));
            _argument1   = argument1;
            _argument2   = argument2;

            Priority = priority;
            Type     = type;
            Creating?.Invoke(this, new TaskEventArgs($"Задача {Name} Priority:{Priority} Type:{Type} Создание"));
        }
        public void AcceptMessage(Creating <DatabaseFile> message)
        {
            if (message is null)
            {
                throw new System.ArgumentNullException(nameof(message));
            }

            if (this.ConfigurationProvider.GetBool(ConfigurationNames.IMPORT_IMAGES_AUTOMATICALLY))
            {
                this.ImportImage(message.Target);
            }
        }
Ejemplo n.º 26
0
Archivo: Pool.cs Proyecto: GF47/GRT
        /// <summary>
        /// 池初始化,根据传入的实例化方法来生成新的实例
        /// </summary>
        /// <param name="count">初始数量</param>
        /// <param name="createNewFunc">生成一个新实例的方法</param>
        public void Initialize(int count, Func <T> createNewFunc)
        {
            _queue         = new Queue <T>(count);
            _createNewFunc = createNewFunc;
            for (int i = 0; i < count; i++)
            {
                T item = _createNewFunc();
                _queue.Enqueue(item);

                Creating?.Invoke(item);
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Jaffaフレームワークにページ開始を通知します。
        /// InitializeComponentの前に実行する必要があります。
        /// </summary>
        /// <param name="win">Jaffaフレームワークを利用するページのインスタンスを指定します。</param>
        public static void Start(Windows.UI.Xaml.Controls.Page page)
        {
            // ページ生成完了通知イベント
            Creating?.Invoke(page, new EventArgs());

            // カルチャに合わせてリソースを切り替え
            if (Jaffa.Application.WaitingChangeCulture == true)
            {
                Jaffa.Application.Current.Resources    = Internal.Core.MakeChangedResources(Jaffa.Application.Current.Resources, Jaffa.International.GetAvailableLanguageCodeList(), Jaffa.International.CurrentCulture);
                Jaffa.Application.WaitingChangeCulture = false;
            }
            page.Resources = Internal.Core.MakeChangedResources(page.Resources, Jaffa.International.GetAvailableLanguageCodeList(), Jaffa.International.CurrentCulture);
        }
Ejemplo n.º 28
0
 public void Create(CancellationToken cancellationToken)
 {
     if (!IsCreated)
     {
         m_Element = m_Creator.Invoke(cancellationToken);
         Creating?.Invoke(m_Element);
         IsCreated = true;
     }
     else
     {
         throw new ElementAlreadyCommittedException();
     }
 }
Ejemplo n.º 29
0
        /// <summary>
        /// Creates a Product without saving it to the database
        /// </summary>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="sku">
        /// The SKU.
        /// </param>
        /// <param name="price">
        /// The price.
        /// </param>
        /// <returns>
        /// The <see cref="IProduct"/>.
        /// </returns>
        public IProduct CreateProduct(string name, string sku, decimal price)
        {
            var templateVariant = new ProductVariant(name, sku, price);
            var product         = new Product(templateVariant);

            if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IProduct>(product), this))
            {
                product.WasCancelled = true;
                return(product);
            }

            Created.RaiseEvent(new Events.NewEventArgs <IProduct>(product), this);

            return(product);
        }
        /// <summary>
        /// Adds a credit card to an existing customer.
        /// </summary>
        /// <param name="customer">
        /// The customer.
        /// </param>
        /// <param name="paymentMethodNonce">
        /// The payment method nonce.
        /// </param>
        /// <param name="token">
        /// The token.
        /// </param>
        /// <param name="billingAddress">
        /// The billing address.
        /// </param>
        /// <param name="isDefault">
        /// A value indicating whether or not this payment method should become the default payment method.
        /// </param>
        /// <returns>
        /// The <see cref="Attempt{PaymentMethod}"/> indicating whether the payment method creation was successful.
        /// </returns>
        public Attempt <PaymentMethod> Create(ICustomer customer, string paymentMethodNonce, string token, IAddress billingAddress = null, bool isDefault = true)
        {
            //// Asserts the customer exists or creates one in BrainTree if it does not exist
            var btc = _braintreeCustomerApiService.GetBraintreeCustomer(customer);

            var request = RequestFactory.CreatePaymentMethodRequest(customer, paymentMethodNonce);

            if (!string.IsNullOrEmpty(token))
            {
                request.Token = token;
            }

            if (billingAddress != null)
            {
                request.BillingAddress = RequestFactory.CreatePaymentMethodAddressRequest(billingAddress);
            }


            Creating.RaiseEvent(new Core.Events.NewEventArgs <PaymentMethodRequest>(request), this);

            var attempt = TryGetApiResult(() => BraintreeGateway.PaymentMethod.Create(request));

            if (!attempt.Success)
            {
                return(Attempt <PaymentMethod> .Fail(attempt.Exception));
            }

            var result = attempt.Result;

            if (result.IsSuccess())
            {
                var cacheKey = MakePaymentMethodCacheKey(token);
                RuntimeCache.ClearCacheItem(cacheKey);

                var customerCacheKey = MakeCustomerCacheKey(customer);
                RuntimeCache.ClearCacheItem(customerCacheKey);

                Created.RaiseEvent(new Core.Events.NewEventArgs <PaymentMethod>(result.Target), this);

                return(Attempt <PaymentMethod> .Succeed((PaymentMethod)RuntimeCache.GetCacheItem(cacheKey, () => result.Target)));
            }

            var error = new BraintreeApiException(result.Errors, result.Message);

            LogHelper.Error <BraintreeCustomerApiService>("Failed to add a credit card to a customer", error);

            return(Attempt <PaymentMethod> .Fail(error));
        }