Пример #1
0
        private async Task LoadStorePackage_Executed(object arg)
        {
            try
            {
                IsLoading = true;

                var packageInfo = Model.CurrentPackage;
                var uri         = await Model.LoadSelectedPackageUriAsync();

                var packageSource = new SIStoragePackageSource(uri, packageInfo.ID, packageInfo.Description, packageInfo.Guid);

                AddPackage?.Invoke(packageSource);

                IsLoading = false;
            }
            catch (Exception exc)
            {
                IsLoading = false;
                PlatformSpecific.PlatformManager.Instance.ShowMessage(Resources.SIStorageCallError + ": " + exc.Message, PlatformSpecific.MessageType.Warning);
            }
            finally
            {
                OnClose();
            }
        }
Пример #2
0
        public GameSettingsViewModel(
            GameSettings gameSettings,
            CommonSettings commonSettings,
            UserSettings userSettings,
            bool isNetworkGame = false)
            : base(gameSettings)
        {
            NetworkGame     = isNetworkGame;
            _commonSettings = commonSettings;

            UpdateComputerPlayers();
            UpdateComputerShowmans();

            StorageInfo             = new SIStorageViewModel(userSettings);
            StorageInfo.AddPackage += StorageInfo_AddPackage;

            gameSettings.Updated += GameSettings_Updated;

            _selectPackage = new ExtendedCommand(SelectPackage_Executed);

            _selectPackage.ExecutionArea.Add(PackageSourceTypes.Local);
            _selectPackage.ExecutionArea.Add(PackageSourceTypes.SIStorage);
            _selectPackage.ExecutionArea.Add(PackageSourceTypes.VK);

            var packageDirExists = Directory.Exists(Global.PackagesUri);

            if (packageDirExists)
            {
                _selectPackage.ExecutionArea.Add(PackageSourceTypes.Random);
            }

            if (NetworkGame && NetworkGameType == NetworkGameType.GameServer)
            {
                _selectPackage.ExecutionArea.Add(PackageSourceTypes.RandomServer);
            }

            if (packageDirExists)
            {
                _selectPackage.ExecutionArea.Add(PackageSourceTypes.Next);
            }

            if (_package == null)
            {
                if (_model.PackageKey != null && _selectPackage.ExecutionArea.Contains(_model.PackageKey.Type))
                {
                    switch (_model.PackageKey.Type)
                    {
                    case PackageSourceTypes.Next:
                        Package = new NextPackageSource();
                        break;

                    case PackageSourceTypes.Random:
                        Package = new RandomPackageSource();
                        break;

                    case PackageSourceTypes.RandomServer:
                        Package = new RandomServerPackageSource();
                        break;

                    case PackageSourceTypes.Local:
                        Package = new CustomPackageSource(_model.PackageKey.Data);
                        break;

                    case PackageSourceTypes.SIStorage:
                        var key = _model.PackageKey;
                        Uri uri;
                        if (Uri.TryCreate(key.Data, UriKind.Absolute, out uri))
                        {
                            Package = new SIStoragePackageSource(uri, key.ID, key.Name, key.PackageID);
                        }
                        break;
                    }
                }
                else if (packageDirExists)
                {
                    Package = new RandomPackageSource();
                }
            }
        }