Ejemplo n.º 1
0
        public HomeController(ILanguageResourceService languageResourceService)
        {
            if (UserContext.IsAuthenticated)
            {
                var tenantId = UserContext.RetrieveTenantId();

                _languageResourceService = languageResourceService;
                _orderService            = OrderServiceFactory.Create(tenantId);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The reason this is not in the constructor is solely for the purpose of exception handling.
        /// If you leave this in the controller and someone who is not authenticated calls the API you will not get a tenantId not found error.
        /// The error will be ugly and be hard to figure out you are not authorized.
        /// This way if the all methods have the ClaimsAuthorize attribute on them they will first be authenticated if not get a nice error message of not authorized.
        /// </summary>
        /// <exception cref="System.Exception">No Tenant Id Found.</exception>
        private void Setup()
        {
            //var isAllowed = ClaimsAuthorization.CheckAccess("Get", "CustomerId", "00");
            //isAllowed = true;
            //Get the current claims principal
            var identity = (ClaimsPrincipal)Thread.CurrentPrincipal;
            var tenant   = identity.Claims.Where(c => c.Type == ClaimsConstants.TenantIdClaimType).Select(c => c.Value).SingleOrDefault();

            if (string.IsNullOrEmpty(tenant))
            {
                throw new Exception("No Tenant Id Found.");
            }

            _tenantId = Guid.Parse(tenant);
            _user     = identity.Identity.Name;

            _iOrderService = OrderServiceFactory.Create(_tenantId);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            //All the decisions behind refactoring this project are explained in commit messages.
            var connectionStringBuilderProvider = new ConfigFileConnectionStringBuilderProvider("MyConnectionString");
            var customerRepository = new CustomerRepositoryImplementation(connectionStringBuilderProvider);
            var orderValidator     = new OrderValidator();
            var vatApplicator      = new VatApplicator();

            var orderServiceFactory = new OrderServiceFactory(customerRepository,
                                                              connectionStringBuilderProvider, orderValidator, vatApplicator);

            var orderService = orderServiceFactory.Create();

            //Load all customers and their linked orders
            var customers = customerRepository.Load(3);

            //Place an order, linked to a customer
            var success = orderService.PlaceOrder(new Order()
            {
                OrderId = 1,
                Amount  = 1,
            }, 1);
        }
Ejemplo n.º 4
0
        private void Provision()
        {
            try
            {
                var iEngineService = EngineServiceFactory.Create(_tenantId);
                var iOrderService  = OrderServiceFactory.Create(_tenantId);

                // Get Settings for current companyId
                var engineSettings = iEngineService.RetrieveProvisioningEngineSetting(_companyId);

                //Todo check if this can run right now based off schedule.

                if (engineSettings.ProvisioningPaused)
                {
                    _iLogger.WriteLogEntry(_tenantId.ToString(), null, _name + " Provisioning Paused.", LogLevelType.Info);
                }
                else
                {
                    //Make this thread safe.
                    //Only allow one timer instance to get in at a time.
                    lock (_syncProvisioningStartRoot)
                    {
                        switch (engineSettings.ProvisionByMethod)
                        {
                        case ProvisionByMethodType.Order:
                            var domainOrder = iOrderService.RetrieveNextOrderToProvisionByCompanyIdAndActionType(_companyId, engineSettings.ProvisionableOrderOrServiceActionTypes);

                            int previousOrderId = 0;
                            //var services = new List<Service>();


                            //While there are orders pending and I am not using max threads get another order.
                            while (domainOrder != null && engineSettings.MaxThreadsPerDispatcher > _currentThreads)
                            {
                                if (previousOrderId != domainOrder.Id)
                                {
                                    Task.Factory.StartNew(() => ProcessOrderThread(domainOrder));
                                }

                                //Set current to old.
                                previousOrderId = domainOrder.Id;

                                //Get next Service Order
                                domainOrder = iOrderService.RetrieveNextOrderToProvisionByCompanyIdAndActionType(_companyId, engineSettings.ProvisionableOrderOrServiceActionTypes);
                            }

                            break;

                        case ProvisionByMethodType.Service:
                            var domainService = iOrderService.RetrieveNextServiceToProvisionByCompanyIdAndActionType(_companyId, engineSettings.ProvisionableOrderOrServiceActionTypes);

                            int previousServiceId = 0;

                            //While there are orders pending and I am not using max threads get another order.
                            while (domainService != null && engineSettings.MaxThreadsPerDispatcher > _currentThreads)
                            {
                                if (previousServiceId != domainService.Id)
                                {
                                    Task.Factory.StartNew(() => ProcessServiceThread(domainService));
                                }

                                //Set current to old.
                                previousServiceId = domainService.Id;

                                //Get next Service
                                domainService = iOrderService.RetrieveNextServiceToProvisionByCompanyIdAndActionType(_companyId, engineSettings.ProvisionableOrderOrServiceActionTypes);
                            }

                            break;

                        case ProvisionByMethodType.Item:
                            int orderId        = 0;
                            int serviceId      = 0;
                            int itemId         = 0;
                            int previousItemId = 0;

                            object domainItem = iOrderService.RetrieveNextItemToProvisionByCompanyIdAndActionTypeAndItemType(_companyId, engineSettings.ProvisionableItemActionTypes);

                            if (domainItem is PhoneItem)
                            {
                                var phoneItem = domainItem as PhoneItem;
                                itemId    = phoneItem.Id;
                                serviceId = phoneItem.ServiceId;
                                var service = iOrderService.RetrieveServiceById(serviceId);
                                orderId = service.OrderId;
                            }

                            if (domainItem is VideoItem)
                            {
                                var videoItem = domainItem as VideoItem;
                                itemId    = videoItem.Id;
                                serviceId = videoItem.ServiceId;
                                var service = iOrderService.RetrieveServiceById(serviceId);
                                orderId = service.OrderId;
                            }

                            if (domainItem is InternetItem)
                            {
                                var internetItem = domainItem as InternetItem;
                                itemId    = internetItem.Id;
                                serviceId = internetItem.ServiceId;
                                var service = iOrderService.RetrieveServiceById(serviceId);
                                orderId = service.OrderId;
                            }

                            previousItemId = 0;

                            //While there are orders pending and I am not using max threads get another order.
                            while (domainItem != null && engineSettings.MaxThreadsPerDispatcher > _currentThreads)
                            {
                                if (previousItemId != itemId)
                                {
                                    Task.Factory.StartNew(() => ProcessItemThread(orderId, serviceId, itemId));
                                }

                                //Set current to old.
                                previousItemId = itemId;

                                //Get next Service
                                domainItem = iOrderService.RetrieveNextItemToProvisionByCompanyIdAndActionTypeAndItemType(_companyId, engineSettings.ProvisionableItemActionTypes);
                            }

                            break;

                        default:
                            throw new NotImplementedException(_name + " this type is not implemented yet.");
                        }

                        // Continue on this thread...
                    }
                }
            }
            catch (AggregateException ae)
            {
                foreach (var ex in ae.Flatten().InnerExceptions)
                {
                    _iLogger.WriteLogEntry(_tenantId.ToString(), null, _name + " error on retrieving next order.", LogLevelType.Error, ex);
                }
            }
            catch (Exception ex)
            {
                _iLogger.WriteLogEntry(_tenantId.ToString(), null, _name + " error on retrieving next order.", LogLevelType.Error, ex);
            }
        }