Пример #1
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);
            }
        }