Пример #1
0
 public virtual void StartMachine()
 {
     //1. 加入函数
     UpdateCenter.Add(OnUpdateHandle, UpdateType.Update);
     UpdateCenter.Add(OnFixedUpdateHandle, UpdateType.FixedUpdate);
     UpdateCenter.Add(OnLateUpdateHandle, UpdateType.LateUpdate);
 }
Пример #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            _logger.LogDebug("Configuring Services");
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddAuthentication(options => {
                options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;

                options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;

                options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            }).AddCookie(options =>
            {
                options.LoginPath  = "/auth/login";
                options.LogoutPath = "/auth/logout";
            });
            services.AddSession();
            _systemInitializer.InitSystemWithFile();
            UpdateCenter.Subscribe(_notificationsCenter.HandleUpdate);
        }
Пример #3
0
        public void CloseShopPermanently(UserIdentifier userIdentifier, Guid shopGuid)
        {
            VerifySystemIsInitialized();
            _verifier.VerifyMe(MethodBase.GetCurrentMethod(), userIdentifier, shopGuid);
            _userDomain.GetUserObject(userIdentifier).CloseShopPermanently(shopGuid);
            var newEvent = new ClosedShopPermanentlyEvent(userIdentifier.Guid, shopGuid);

            newEvent.SetMessages(_unitOfWork);
            _logger.LogInformation($"{GetUserName(userIdentifier.Guid)} closed shop {GetShopName(shopGuid)} permanently successfuly.");
            UpdateCenter.RaiseEvent(newEvent);
        }
Пример #4
0
        public bool CascadeRemoveShopOwner(Shop shop, Guid userGuid, Guid ownerToRemoveGuid)
        {
            var removedOwners = shop.CascadeRemoveShopOwner(userGuid, ownerToRemoveGuid);

            foreach (var removedOwner in removedOwners)
            {
                var newEvent = new RemovedOwnerEvent(removedOwner, ownerToRemoveGuid, shop.Guid);
                newEvent.SetMessages(_unitOfWork);
                UpdateCenter.RaiseEvent(newEvent);
            }
            _unitOfWork.ShopRepository.Update(shop);
            return(true);
        }
Пример #5
0
    /// <summary>
    /// 下载前的提示,比如弹出下载提示框,如果不需要,直接Resume即可
    /// </summary>
    /// <param name="size"></param>
    private void OnDownloadNotice(int size)
    {
        string msg = string.Format("检测到有{0:F1}MB游戏资源需要更新!", (float)size / 1024 / 1024);//MB

        UIMsgBoxForm.Open(msg, "确定", "退出", () =>
        {
            UpdateManager.Instance.CurrentFlow.Resume(true);
        }, () =>
        {
            UpdateManager.Instance.CloseThread();
            UpdateCenter.Close();
            UnityEngine.Debug.LogError("退出游戏");
            //Application.Quit();
        });
    }
Пример #6
0
        public Guid OpenShop(UserIdentifier userIdentifier)
        {
            VerifySystemIsInitialized();
            _verifier.VerifyMe(MethodBase.GetCurrentMethod(), userIdentifier);
            var shopGuid = _userDomain.GetUserObject(userIdentifier).OpenShop();

            if (!shopGuid.Equals(Guid.Empty))
            {
                var newEvent = new OpenedShopEvent(userIdentifier.Guid, shopGuid);
                newEvent.SetMessages(_unitOfWork);
                _logger.LogInformation($"{GetUserName(userIdentifier.Guid)} opened shop successfuly.");
                UpdateCenter.RaiseEvent(newEvent);
            }
            return(shopGuid);
        }
Пример #7
0
        public Guid Login(UserIdentifier userIdentifier, string username, string password)
        {
            VerifySystemIsInitialized();
            _verifier.VerifyMe(MethodBase.GetCurrentMethod(), userIdentifier, username, password);
            var result = _userDomain.Login(username, password);

            if (!result.Equals(Guid.Empty))
            {
                var newEvent = new UserLoggedInEvent(result);
                //newEvent.SetTargets(DomainData.ShopsCollection.Values, DomainData.RegisteredUsersCollection.Values);
                //newEvent.SetMessage(DomainData.ShopsCollection.Values, DomainData.RegisteredUsersCollection.Values);
                newEvent.SetMessages(_unitOfWork);
                UpdateCenter.RaiseEvent(newEvent);
                _logger.LogInformation($"{username} logged in successfuly.");
            }
            return(result);
        }
Пример #8
0
        public bool CascadeRemoveShopOwner(UserIdentifier userIdentifier, Guid shopGuid, Guid ownerToRemoveGuid)
        {
            VerifySystemIsInitialized();
            _verifier.VerifyMe(MethodBase.GetCurrentMethod(), userIdentifier, shopGuid, ownerToRemoveGuid);
            var result = _userDomain.GetUserObject(userIdentifier).CascadeRemoveShopOwner(shopGuid, ownerToRemoveGuid);

            if (result) //Maybe change CascadeRemoveShopOwner in IUser to return a collection of all removed owners.
            {
                _logger.Log(LogLevel.Information, $"{GetUserName(userIdentifier.Guid)} removed" +
                            $" {GetUserName(ownerToRemoveGuid)} as a shop owner from shop {GetShopName(shopGuid)} successfuly.");
                var newEvent = new RemovedOwnerEvent(ownerToRemoveGuid, userIdentifier.Guid, shopGuid);
                newEvent.SetMessages(_unitOfWork);
                UpdateCenter.RaiseEvent(newEvent);
            }
            else
            {
                _logger.Log(LogLevel.Information, $"{GetUserName(userIdentifier.Guid)} failed to remove" +
                            $" {GetUserName(ownerToRemoveGuid)} as a shop owner from shop {GetShopName(shopGuid)}.");
            }
            return(result);
        }
Пример #9
0
        public bool AddShopOwner(UserIdentifier userIdentifier, Guid shopGuid, Guid newShopOwnerGuid)
        {
            VerifySystemIsInitialized();
            _verifier.VerifyMe(MethodBase.GetCurrentMethod(), userIdentifier, shopGuid, newShopOwnerGuid);
            bool result = _userDomain.GetUserObject(userIdentifier).AddShopOwner(shopGuid, newShopOwnerGuid);

            if (result)
            {
                _logger.LogInformation($"{GetUserName(userIdentifier.Guid)} added {GetUserName(newShopOwnerGuid)} " +
                                       $" as a new owner of shop {GetShopName(shopGuid)}");
                var newEvent = new AddedOwnerEvent(newShopOwnerGuid, userIdentifier.Guid, shopGuid);
                newEvent.SetMessages(_unitOfWork);
                UpdateCenter.RaiseEvent(newEvent);
            }
            else
            {
                _logger.LogInformation($"{GetUserName(userIdentifier.Guid)} failed to add {GetUserName(newShopOwnerGuid)}" +
                                       $" as a new owner of shop {GetShopName(shopGuid)}.");
            }
            return(result);
        }
Пример #10
0
        public bool RemoveOwner(Shop shop, Guid toRemoveOwnerGuid)
        {
            var ownerToRemove = shop.GetOwner(toRemoveOwnerGuid);

            if (ownerToRemove.OwnerGuid.Equals(shop.Creator.OwnerGuid))
            {
                return(false);
            }
            foreach (var otherOwner in shop.Owners)
            {
                if (otherOwner.AppointerGuid.Equals(toRemoveOwnerGuid))
                {
                    RemoveOwner(shop, otherOwner.OwnerGuid);
                    var newEvent = new RemovedOwnerEvent(otherOwner.OwnerGuid, toRemoveOwnerGuid, shop.Guid);
                    newEvent.SetMessages(_unitOfWork);
                    UpdateCenter.RaiseEvent(newEvent);
                }
            }
            shop.Owners.Remove(ownerToRemove);// remove the owner from the owners list
            _unitOfWork.ShopRepository.Update(shop);
            return(true);
        }
Пример #11
0
        public bool PurchaseCart(Shop shop, ShoppingBag bag)
        {
            var  cart            = bag.GetShoppingCartAndCreateIfNeededForGuestOnlyOrInBagDomain(shop.Guid);
            bool canPurchaseCart = true;

            foreach (var productAndAmountBought in cart.PurchasedProducts)
            {
                var      userGuid = cart.UserGuid;
                BaseUser user;
                try
                {
                    user = _unitOfWork.BaseUserRepository.FindByIdOrNull(userGuid);
                }
                catch (Exception)
                {
                    user = null;
                }
                //check purchase policies
                var quantity = productAndAmountBought.Item2;
                foreach (IPurchasePolicy policy in shop.PurchasePolicies)
                {
                    if (!policy.CheckPolicy(cart, productAndAmountBought.Item1.Guid, quantity, user, _unitOfWork) && !policyInCompound(shop, policy))
                    {
                        canPurchaseCart = false;
                    }
                }
            }
            if (!canPurchaseCart)
            {
                //_unitOfWork.ShopRepository.Update(shop);
                //_unitOfWork.BagRepository.Update(bag);
                return(false);
            }

            foreach (var productAndAmountBought in cart.PurchasedProducts)
            {
                var userGuid = cart.UserGuid;

                var actualProduct = shop.ShopProducts.FirstOrDefault(p => p.Guid.Equals(productAndAmountBought.Item1.Guid));
                //decrease stock quantity if it wasnt a discount record

                var quantity = productAndAmountBought.Item2;
                if (actualProduct != null)
                {
                    shop.UsersPurchaseHistory.Add(new Tuple <Guid, ShopProduct, int>(userGuid, actualProduct, quantity));
                    actualProduct.Quantity -= quantity;
                }
                else
                {
                    shop.UsersPurchaseHistory.Add(new Tuple <Guid, ShopProduct, int>(userGuid, productAndAmountBought.Item1, quantity));
                }
            }
            double total_price = cart.PurchasedProducts.Aggregate(0d, (total, p) => total += Convert.ToDouble(p.Item1.Price) * p.Item2);
            var    newEvent    = new PurchasedCartEvent(cart.UserGuid, cart.ShopGuid, total_price);

            newEvent.SetMessages(_unitOfWork);
            UpdateCenter.RaiseEvent(newEvent);
            ShoppingBagDomain.PurchaseCart(bag, shop.Guid);
            _unitOfWork.ShopRepository.Update(shop);
            return(true);
        }