예제 #1
0
        /// <summary>
        /// 下载游戏
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <param name="model"></param>
        public override async void Edit <TModel>(TModel model)
        {
            try
            {
                DisplayMetro = Visibility.Visible;
                var gamesEntity = model as UserGamesEntity;
                if (CommonsCall.UserGames.Any(s => s.gameId.Equals(gamesEntity.gameId)))
                {
                    Msg.Info(gamesEntity.title + "已经进入下载队列中");
                    return;
                }
                if (CommonsCall.UserGames.Count > 1)
                {
                    Msg.Info("下载队列已满,请等待下载完毕再进行下载");
                    return;
                }
                IStore store    = BridgeFactory.BridgeManager.GetStoreManager();
                var    genrator = await store.GetGameFiles(gamesEntity.gameId);

                if (!genrator.code.Equals("000"))
                {
                    Msg.Info(genrator.Message);
                    return;
                }
                var Results = JsonConvert.DeserializeObject <List <DwonloadEntity> >(genrator.result.ToString());
                if (Results.Count == 0)
                {
                    Msg.Info("游戏获取失败,请重试");
                    return;
                }


                GameDwonloadViewModel viewModel = new GameDwonloadViewModel();
                viewModel.PageCollection   = CommonsCall.CopyOjbect(gamesEntity);
                viewModel.dwonloadEntities = Results;
                viewModel.InitAsyncViewModel();
                viewModel.stuepGo += (() =>
                {
                    gamesEntity.MineContent = "安装中";
                });
                var dialog = ServiceProvider.Instance.Get <IModelDialog>("EGameDwonloadDlg");
                viewModel.stuepEnd += (t, a) =>
                {
                    gamesEntity.StrupPath = t;
                    gamesEntity.gameName  = a;
                };
                dialog.BindViewModel(viewModel);

                var d = Dialog.Show(dialog.GetDialog());

                viewModel.ShowList += (async() =>
                {
                    d.Close();
                });
            }
            catch (Exception ex)
            {
                Msg.Error(ex);
            }
            finally
            {
                DisplayMetro = Visibility.Collapsed;
            }
        }
예제 #2
0
        /// <summary>
        //常用游戏购买
        /// </summary>
        /// <param name="gameId"></param>
        public async void GainGamesHotgame(Hotgame model)
        {
            try
            {
                if (model.Purchased == 2)
                {
                    IStore store    = BridgeFactory.BridgeManager.GetStoreManager();
                    var    genrator = await store.GetGameFiles(model.id);

                    if (!genrator.code.Equals("000"))
                    {
                        Msg.Info(genrator.Message);
                        return;
                    }
                    var Results = JsonConvert.DeserializeObject <List <DwonloadEntity> >(genrator.result.ToString());
                    if (Results.Count == 0)
                    {
                        Msg.Info("游戏获取失败,请重试");
                        return;
                    }
                    if (CommonsCall.UserGames.Any(s => s.gameId.Equals(model.id)))
                    {
                        Msg.Info(model.title + "已经进入下载队列中");
                        return;
                    }
                    GameDwonloadViewModel viewModel = new GameDwonloadViewModel();
                    viewModel.PageCollection   = Loginer.LoginerUser.UserGameList.Where(s => s.gameId.Equals(model.id)).First();
                    viewModel.dwonloadEntities = Results;
                    viewModel.InitAsyncViewModel();
                    var dialog = ServiceProvider.Instance.Get <IModelDialog>("EGameDwonloadDlg");

                    dialog.BindViewModel(viewModel);

                    var d = Dialog.Show(dialog.GetDialog());

                    viewModel.ShowList += (async() =>
                    {
                        d.Close();
                    });
                    return;
                }
                var GameRoute = CommonsCall.ReadUserGameInfo(model.id.ToString());
                if (!string.IsNullOrEmpty(GameRoute.Key))
                {
                    if (File.Exists(GameRoute.Key))//判断文件是否存在
                    {
                        Process.Start(GameRoute.Key);
                    }
                    else
                    {
                        model.Purchased = 2;
                        CommonsCall.DeleteSubKeyTree(GameRoute.Key);
                        Msg.Info("游戏损坏,请重新安装游戏");
                    }
                }
                else
                {
                    if (await Msg.Question("是否购买游戏"))
                    {
                        IStore store    = BridgeFactory.BridgeManager.GetStoreManager();
                        var    genrator = await store.BuyGame(model.id);

                        model.Purchased = 2;
                        Msg.Info(genrator.Message);
                        if (genrator.code.Equals("000"))
                        {
                            if (genrator.result.Equals("888"))
                            {
                                return;
                            }
                            CommonsCall.BuyGame(genrator.result.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Msg.Error(ex);
            }
        }