Ejemplo n.º 1
0
        private async void ExportCharacter_Load(object sender, EventArgs e)
        {
            await LanguageManager.PopulateSheetLanguageListAsync(cboLanguage, GlobalSettings.DefaultCharacterSheet, _objCharacter.Yield(), _objExportCulture);

            using (new FetchSafelyFromPool <List <ListItem> >(
                       Utils.ListItemListPool, out List <ListItem> lstExportMethods))
            {
                // Populate the XSLT list with all of the XSL files found in the sheets directory.
                string exportDirectoryPath = Path.Combine(Utils.GetStartupPath, "export");
                foreach (string strFile in Directory.GetFiles(exportDirectoryPath))
                {
                    // Only show files that end in .xsl. Do not include files that end in .xslt since they are used as "hidden" reference sheets (hidden because they are partial templates that cannot be used on their own).
                    if (!strFile.EndsWith(".xslt", StringComparison.OrdinalIgnoreCase) &&
                        strFile.EndsWith(".xsl", StringComparison.OrdinalIgnoreCase))
                    {
                        string strFileName = Path.GetFileNameWithoutExtension(strFile);
                        lstExportMethods.Add(new ListItem(strFileName, strFileName));
                    }
                }
                lstExportMethods.Sort();
                lstExportMethods.Insert(0, new ListItem("JSON", await LanguageManager.GetStringAsync("String_Export_JSON")));

                await cboXSLT.PopulateWithListItemsAsync(lstExportMethods);

                if (cboXSLT.Items.Count > 0)
                {
                    cboXSLT.SelectedIndex = 0;
                }
            }

            _blnLoading = false;
            await Task.WhenAll(
                this.DoThreadSafeAsync(async x => x.Text += await LanguageManager.GetStringAsync("String_Space") + _objCharacter?.Name),
                DoLanguageUpdate().AsTask());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Set List of Characters to print.
        /// </summary>
        public async Task SetCharacters(CancellationToken token = default, params Character[] lstCharacters)
        {
            token.ThrowIfCancellationRequested();
            IAsyncDisposable objLocker = await _lstCharacters.LockObject.EnterWriteLockAsync(token);

            try
            {
                token.ThrowIfCancellationRequested();
                foreach (Character objCharacter in _lstCharacters)
                {
                    objCharacter.PropertyChanged         -= ObjCharacterOnPropertyChanged;
                    objCharacter.SettingsPropertyChanged -= ObjCharacterOnSettingsPropertyChanged;
                }
                await _lstCharacters.ClearAsync();

                if (lstCharacters != null)
                {
                    await _lstCharacters.AddRangeAsync(lstCharacters);
                }
                foreach (Character objCharacter in _lstCharacters)
                {
                    objCharacter.PropertyChanged         += ObjCharacterOnPropertyChanged;
                    objCharacter.SettingsPropertyChanged += ObjCharacterOnSettingsPropertyChanged;
                }
            }
            finally
            {
                await objLocker.DisposeAsync();
            }

            await UpdateWindowTitleAsync(token);

            token.ThrowIfCancellationRequested();
            bool blnOldLoading = _blnLoading;

            try
            {
                _blnLoading = true;
                // Populate the XSLT list with all of the XSL files found in the sheets directory.
                await LanguageManager.PopulateSheetLanguageListAsync(cboLanguage, _strSelectedSheet, _lstCharacters);
                await PopulateXsltList(token);
                await RefreshCharacters(token);
            }
            finally
            {
                _blnLoading = blnOldLoading;
            }
        }
Ejemplo n.º 3
0
        private async void CharacterSheetViewer_Load(object sender, EventArgs e)
        {
            _blnLoading = true;
            // Populate the XSLT list with all of the XSL files found in the sheets directory.
            await LanguageManager.PopulateSheetLanguageListAsync(cboLanguage, _strSelectedSheet, _lstCharacters);

            await PopulateXsltList();

            cboXSLT.SelectedValue = _strSelectedSheet;
            // If the desired sheet was not found, fall back to the Shadowrun 5 sheet.
            if (cboXSLT.SelectedIndex == -1)
            {
                string strLanguage = cboLanguage.SelectedValue?.ToString();
                int    intNameIndex;
                if (string.IsNullOrEmpty(strLanguage) || strLanguage.Equals(GlobalSettings.DefaultLanguage, StringComparison.OrdinalIgnoreCase))
                {
                    intNameIndex = cboXSLT.FindStringExact(GlobalSettings.DefaultCharacterSheet);
                }
                else
                {
                    intNameIndex = cboXSLT.FindStringExact(GlobalSettings.DefaultCharacterSheet.Substring(GlobalSettings.DefaultLanguage.LastIndexOf(Path.DirectorySeparatorChar) + 1));
                }
                if (intNameIndex != -1)
                {
                    cboXSLT.SelectedIndex = intNameIndex;
                }
                else if (cboXSLT.Items.Count > 0)
                {
                    if (string.IsNullOrEmpty(strLanguage) || strLanguage.Equals(GlobalSettings.DefaultLanguage, StringComparison.OrdinalIgnoreCase))
                    {
                        _strSelectedSheet = GlobalSettings.DefaultCharacterSheetDefaultValue;
                    }
                    else
                    {
                        _strSelectedSheet = Path.Combine(strLanguage, GlobalSettings.DefaultCharacterSheetDefaultValue);
                    }
                    cboXSLT.SelectedValue = _strSelectedSheet;
                    if (cboXSLT.SelectedIndex == -1)
                    {
                        cboXSLT.SelectedIndex = 0;
                        _strSelectedSheet     = cboXSLT.SelectedValue?.ToString();
                    }
                }
            }
            _blnLoading = false;
            await SetDocumentText(await LanguageManager.GetStringAsync("String_Loading_Characters"));
        }
Ejemplo n.º 4
0
        private async void ExportCharacter_Load(object sender, EventArgs e)
        {
            _objCharacter.PropertyChanged         += ObjCharacterOnPropertyChanged;
            _objCharacter.SettingsPropertyChanged += ObjCharacterOnSettingsPropertyChanged;
            await LanguageManager.PopulateSheetLanguageListAsync(cboLanguage, GlobalSettings.DefaultCharacterSheet, _objCharacter.Yield(), _objExportCulture);

            using (new FetchSafelyFromPool <List <ListItem> >(
                       Utils.ListItemListPool, out List <ListItem> lstExportMethods))
            {
                // Populate the XSLT list with all of the XSL files found in the sheets directory.
                foreach (string strFile in Directory.EnumerateFiles(Path.Combine(Utils.GetStartupPath, "export")))
                {
                    // Only show files that end in .xsl. Do not include files that end in .xslt since they are used as "hidden" reference sheets (hidden because they are partial templates that cannot be used on their own).
                    if (!strFile.EndsWith(".xslt", StringComparison.OrdinalIgnoreCase) &&
                        strFile.EndsWith(".xsl", StringComparison.OrdinalIgnoreCase))
                    {
                        string strFileName = Path.GetFileNameWithoutExtension(strFile);
                        lstExportMethods.Add(new ListItem(strFileName, strFileName));
                    }
                }
                lstExportMethods.Sort();
                lstExportMethods.Insert(0, new ListItem("JSON", string.Format(GlobalSettings.CultureInfo, await LanguageManager.GetStringAsync("String_Export_Blank"), "JSON")));

                await cboXSLT.PopulateWithListItemsAsync(lstExportMethods, _objGenericToken);

                await cboXSLT.DoThreadSafeAsync(x =>
                {
                    if (x.Items.Count > 0)
                    {
                        x.SelectedIndex = 0;
                    }
                }, _objGenericToken);
            }

            _blnLoading = false;
            try
            {
                await Task.WhenAll(
                    UpdateWindowTitleAsync(_objGenericToken),
                    DoLanguageUpdate(_objGenericToken));
            }
            catch (OperationCanceledException)
            {
                //swallow this
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Set List of Characters to print.
        /// </summary>
        public async ValueTask SetCharacters(params Character[] lstCharacters)
        {
            IAsyncDisposable objLocker = await _lstCharacters.LockObject.EnterWriteLockAsync();

            try
            {
                foreach (Character objCharacter in _lstCharacters)
                {
                    objCharacter.PropertyChanged -= ObjCharacterOnPropertyChanged;
                }

                await _lstCharacters.ClearAsync();

                if (lstCharacters != null)
                {
                    await _lstCharacters.AddRangeAsync(lstCharacters);
                }
                foreach (Character objCharacter in _lstCharacters)
                {
                    objCharacter.PropertyChanged += ObjCharacterOnPropertyChanged;
                }
            }
            finally
            {
                await objLocker.DisposeAsync();
            }

            bool blnOldLoading = _blnLoading;

            try
            {
                _blnLoading = true;
                // Populate the XSLT list with all of the XSL files found in the sheets directory.
                await LanguageManager.PopulateSheetLanguageListAsync(cboLanguage, _strSelectedSheet, _lstCharacters);
                await PopulateXsltList();
                await RefreshCharacters();
            }
            finally
            {
                _blnLoading = blnOldLoading;
            }
        }
Ejemplo n.º 6
0
        private async void CharacterSheetViewer_Load(object sender, EventArgs e)
        {
            _blnLoading = true;
            // Populate the XSLT list with all of the XSL files found in the sheets directory.
            await LanguageManager.PopulateSheetLanguageListAsync(cboLanguage, _strSelectedSheet, _lstCharacters);

            await PopulateXsltList(_objGenericToken);

            await cboXSLT.DoThreadSafeAsync(x => x.SelectedValue = _strSelectedSheet, _objGenericToken);

            // If the desired sheet was not found, fall back to the Shadowrun 5 sheet.
            if (await cboXSLT.DoThreadSafeFuncAsync(x => x.SelectedIndex, _objGenericToken) == -1)
            {
                string strLanguage = await cboLanguage.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString(), _objGenericToken);

                int intNameIndex;
                if (string.IsNullOrEmpty(strLanguage) ||
                    strLanguage.Equals(GlobalSettings.DefaultLanguage, StringComparison.OrdinalIgnoreCase))
                {
                    intNameIndex
                        = await cboXSLT.DoThreadSafeFuncAsync(
                              x => x.FindStringExact(GlobalSettings.DefaultCharacterSheet), _objGenericToken);
                }
                else
                {
                    intNameIndex = await cboXSLT.DoThreadSafeFuncAsync(
                        x => x.FindStringExact(GlobalSettings.DefaultCharacterSheet.Substring(
                                                   GlobalSettings.DefaultLanguage.LastIndexOf(
                                                       Path.DirectorySeparatorChar) + 1)), _objGenericToken);
                }
                if (intNameIndex != -1)
                {
                    await cboXSLT.DoThreadSafeAsync(x => x.SelectedIndex = intNameIndex, _objGenericToken);
                }
                else if (await cboXSLT.DoThreadSafeFuncAsync(x => x.Items.Count > 0, _objGenericToken))
                {
                    if (string.IsNullOrEmpty(strLanguage) || strLanguage.Equals(GlobalSettings.DefaultLanguage, StringComparison.OrdinalIgnoreCase))
                    {
                        _strSelectedSheet = GlobalSettings.DefaultCharacterSheetDefaultValue;
                    }
                    else
                    {
                        _strSelectedSheet = Path.Combine(strLanguage, GlobalSettings.DefaultCharacterSheetDefaultValue);
                    }
                    await cboXSLT.DoThreadSafeAsync(x =>
                    {
                        x.SelectedValue = _strSelectedSheet;
                        if (x.SelectedIndex == -1)
                        {
                            x.SelectedIndex   = 0;
                            _strSelectedSheet = x.SelectedValue?.ToString();
                        }
                    }, _objGenericToken);
                }
            }
            _blnLoading = false;
            try
            {
                await SetDocumentText(await LanguageManager.GetStringAsync("String_Loading_Characters"),
                                      _objGenericToken);
            }
            catch (OperationCanceledException)
            {
                //swallow this
            }
        }