private async void cmdSelectFile_Click(object sender, EventArgs e)
        {
            // Prompt the user to select a save file to possess.
            using (OpenFileDialog openFileDialog = new OpenFileDialog
            {
                Filter = await LanguageManager.GetStringAsync("DialogFilter_HeroLab") + '|'
                         + await LanguageManager.GetStringAsync("DialogFilter_All"),
                Multiselect = false
            })
            {
                if (openFileDialog.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }
                using (CursorWait.New(this))
                {
                    string   strSelectedFile = openFileDialog.FileName;
                    TreeNode objNode         = await CacheCharacters(strSelectedFile);

                    if (objNode != null)
                    {
                        treCharacterList.Nodes.Clear();
                        treCharacterList.Nodes.Add(objNode);
                        treCharacterList.SelectedNode = objNode.Nodes.Count > 0 ? objNode.Nodes[0] : objNode;
                    }
                }
            }
        }
        private async ValueTask DoExport(CancellationToken token = default)
        {
            if (string.IsNullOrEmpty(_strXslt))
            {
                return;
            }

            CursorWait objCursorWait = await CursorWait.NewAsync(this, token : token);

            try
            {
                if (_strXslt == "JSON")
                {
                    await ExportJson(token : token);
                }
                else
                {
                    await ExportNormal(token : token);
                }
            }
            finally
            {
                await objCursorWait.DisposeAsync();
            }
        }
Beispiel #3
0
        private async void tsAttachCharacter_Click(object sender, EventArgs e)
        {
            // Prompt the user to select a save file to associate with this Contact.
            using (OpenFileDialog openFileDialog = new OpenFileDialog
            {
                Filter = await LanguageManager.GetStringAsync("DialogFilter_Chum5") + '|' + await LanguageManager.GetStringAsync("DialogFilter_All")
            })
            {
                if (!string.IsNullOrEmpty(_objContact.FileName) && File.Exists(_objContact.FileName))
                {
                    openFileDialog.InitialDirectory = Path.GetDirectoryName(_objContact.FileName);
                    openFileDialog.FileName         = Path.GetFileName(_objContact.FileName);
                }

                if (openFileDialog.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }
                using (CursorWait.New(ParentForm))
                {
                    _objContact.FileName = openFileDialog.FileName;
                    cmdLink.ToolTipText  = await LanguageManager.GetStringAsync("Tip_Contact_OpenFile");

                    // Set the relative path.
                    Uri uriApplication = new Uri(Utils.GetStartupPath);
                    Uri uriFile        = new Uri(_objContact.FileName);
                    Uri uriRelative    = uriApplication.MakeRelativeUri(uriFile);
                    _objContact.RelativeFileName = "../" + uriRelative;

                    ContactDetailChanged?.Invoke(this, new TextEventArgs("File"));
                }
            }
        }
        private async Task GenerateJson(CancellationToken token = default)
        {
            token.ThrowIfCancellationRequested();
            CursorWait objCursorWait = await CursorWait.NewAsync(this, token : token);

            try
            {
                await cmdExport.DoThreadSafeAsync(x => x.Enabled = false, token);

                await cmdExportClose.DoThreadSafeAsync(x => x.Enabled = false, token);

                try
                {
                    token.ThrowIfCancellationRequested();
                    string strText = JsonConvert.SerializeXmlNode(_objCharacterXml, Formatting.Indented);
                    token.ThrowIfCancellationRequested();
                    await SetTextToWorkerResult(strText, token);
                }
                finally
                {
                    await cmdExport.DoThreadSafeAsync(x => x.Enabled = true, token);

                    await cmdExportClose.DoThreadSafeAsync(x => x.Enabled = true, token);
                }
            }
            finally
            {
                await objCursorWait.DisposeAsync();
            }
        }
Beispiel #5
0
        private async Task DoPrint(CancellationToken token = default)
        {
            token.ThrowIfCancellationRequested();
            using (await CursorWait.NewAsync(this, true, token))
            {
                try
                {
                    token.ThrowIfCancellationRequested();
                    int intNodesCount = await treCharacters.DoThreadSafeFuncAsync(x => x.Nodes.Count, token);

                    await Task.WhenAll(cmdPrint.DoThreadSafeAsync(x => x.Enabled = false, token),
                                       prgProgress.DoThreadSafeAsync(objBar =>
                    {
                        objBar.Value   = 0;
                        objBar.Maximum = intNodesCount;
                    }, token));

                    token.ThrowIfCancellationRequested();
                    // Parallelized load because this is one major bottleneck.
                    Character[]        lstCharacters   = new Character[intNodesCount];
                    Task <Character>[] tskLoadingTasks = new Task <Character> [intNodesCount];
                    for (int i = 0; i < tskLoadingTasks.Length; ++i)
                    {
                        string strLoopFile = await treCharacters.DoThreadSafeFuncAsync(x => x.Nodes[i].Tag.ToString(), token);

                        tskLoadingTasks[i]
                            = Task.Run(() => InnerLoad(strLoopFile, token), token);
                    }

                    async Task <Character> InnerLoad(string strLoopFile, CancellationToken innerToken = default)
Beispiel #6
0
        public static CursorWait New(Control objControl = null, bool blnAppStarting = false)
        {
            CursorWait objReturn = new CursorWait(objControl, blnAppStarting);

            if (objReturn._objControl.IsNullOrDisposed())
            {
                if (Interlocked.Increment(ref _intApplicationWaitCursors) == 1)
                {
                    Application.UseWaitCursor = true;
                }
                return(objReturn);
            }
            objReturn._objTimer.Start();
            Log.Trace("CursorWait for Control \"" + objControl + "\" started with Guid \"" + objReturn._guidInstance + "\".");

            if (objReturn._objControl != null)
            {
                if (objReturn._blnAppStartingCursor)
                {
                    s_DicApplicationStartingControls.AddOrUpdate(objReturn._objControl, 1,
                                                                 (x, y) => Interlocked.Increment(ref y));
                    if (!s_DicWaitCursorControls.TryGetValue(objReturn._objControl, out int intExitingWaits) ||
                        intExitingWaits == 0)
                    {
                        objReturn.SetControlCursor(Cursors.AppStarting);
                    }
                }
                else
                {
                    s_DicWaitCursorControls.AddOrUpdate(objReturn._objControl, 1, (x, y) => Interlocked.Increment(ref y));
                    objReturn.SetControlCursor(Cursors.WaitCursor);
                }
            }
            return(objReturn);
        }
        private async Task GenerateCharacterXml(CancellationToken token = default)
        {
            token.ThrowIfCancellationRequested();
            CursorWait objCursorWait = await CursorWait.NewAsync(this, token : token);

            try
            {
                await Task.WhenAll(cmdExport.DoThreadSafeAsync(x => x.Enabled      = false, token),
                                   cmdExportClose.DoThreadSafeAsync(x => x.Enabled = false, token),
                                   LanguageManager.GetStringAsync("String_Generating_Data")
                                   .ContinueWith(
                                       y => txtText.DoThreadSafeAsync(x => x.Text = y.Result, token),
                                       token).Unwrap());

                token.ThrowIfCancellationRequested();
                using (token.Register(() => _objCharacterXmlGeneratorCancellationTokenSource.Cancel(false)))
                    _objCharacterXml = await _objCharacter.GenerateExportXml(_objExportCulture, _strExportLanguage,
                                                                             _objCharacterXmlGeneratorCancellationTokenSource
                                                                             .Token);
                token.ThrowIfCancellationRequested();
                if (_objCharacterXml != null)
                {
                    await DoXsltUpdate(token);
                }
            }
            finally
            {
                await objCursorWait.DisposeAsync();
            }
        }
        private async ValueTask RefreshSelectLifestyle()
        {
            _blnIsSelectLifestyleRefreshing = true;
            using (await CursorWait.NewAsync(this))
            {
                try
                {
                    Lifestyle objPreferredLifestyle         = null;
                    ListItem  objPreferredLifestyleItem     = default;
                    Lifestyle objCurrentlySelectedLifestyle = await cboSelectLifestyle.DoThreadSafeFuncAsync(x => x.SelectedIndex >= 0
                                                                                                             ?((ListItem)x.SelectedItem).Value as Lifestyle
                                                                                                             : null);

                    using (new FetchSafelyFromPool <List <ListItem> >(Utils.ListItemListPool,
                                                                      out List <ListItem> lstLifestyleItems))
                    {
                        foreach (Lifestyle objLifestyle in _objCharacter.Lifestyles)
                        {
                            ListItem objLifestyleItem = new ListItem(objLifestyle, objLifestyle.CurrentDisplayName);
                            lstLifestyleItems.Add(new ListItem(objLifestyle, objLifestyle.CurrentDisplayName));
                            // We already selected a lifestyle, so keep the selection if possible despite the refresh
                            if (objCurrentlySelectedLifestyle != null)
                            {
                                if (objCurrentlySelectedLifestyle == objLifestyle)
                                {
                                    objPreferredLifestyleItem = objLifestyleItem;
                                }
                            }
                            else if (objPreferredLifestyle == null ||
                                     objLifestyle.ExpectedValue > objPreferredLifestyle.ExpectedValue)
                            {
                                objPreferredLifestyleItem = objLifestyleItem;
                                objPreferredLifestyle     = objLifestyle;
                            }
                        }

                        lstLifestyleItems.Sort(CompareListItems.CompareNames);

                        await cboSelectLifestyle.PopulateWithListItemsAsync(lstLifestyleItems);

                        await cboSelectLifestyle.DoThreadSafeAsync(x =>
                        {
                            x.SelectedItem = objPreferredLifestyleItem;
                            if (x.SelectedIndex < 0 && lstLifestyleItems.Count > 0)
                            {
                                x.SelectedIndex = 0;
                            }
                            x.Enabled = lstLifestyleItems.Count > 1;
                        });
                    }
                }
                finally
                {
                    _blnIsSelectLifestyleRefreshing = false;
                }
                await RefreshBaseLifestyle();
            }
        }
Beispiel #9
0
 private async void OnSelectedSettingChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName == nameof(CharacterSettings.Books) ||
         e.PropertyName == nameof(CharacterSettings.EnabledCustomDataDirectoryPaths))
     {
         using (CursorWait.New(this))
             await LoadContent();
     }
 }
        private async void cmdEditCharacterOption_Click(object sender, EventArgs e)
        {
            using (await CursorWait.NewAsync(this))
            {
                object objOldSelected = await cboCharacterSetting.DoThreadSafeFuncAsync(x => x.SelectedValue);

                using (ThreadSafeForm <EditCharacterSettings> frmOptions
                           = await ThreadSafeForm <EditCharacterSettings> .GetAsync(
                                 () => new EditCharacterSettings(objOldSelected as CharacterSettings)))
                    await frmOptions.ShowDialogSafeAsync(this);

                await this.DoThreadSafeAsync(x => x.SuspendLayout());

                try
                {
                    // Populate the Gameplay Settings list.
                    using (new FetchSafelyFromPool <List <ListItem> >(
                               Utils.ListItemListPool, out List <ListItem> lstGameplayOptions))
                    {
                        lstGameplayOptions.AddRange(SettingsManager.LoadedCharacterSettings.Values
                                                    .Select(objLoopOptions =>
                                                            new ListItem(
                                                                objLoopOptions,
                                                                objLoopOptions.DisplayName)));
                        lstGameplayOptions.Sort(CompareListItems.CompareNames);
                        await cboCharacterSetting.PopulateWithListItemsAsync(lstGameplayOptions);

                        await cboCharacterSetting.DoThreadSafeAsync(x => x.SelectedValue = objOldSelected);

                        if (await cboCharacterSetting.DoThreadSafeFuncAsync(x => x.SelectedIndex) == -1 &&
                            lstGameplayOptions.Count > 0)
                        {
                            (bool blnSuccess, CharacterSettings objSetting)
                                = await SettingsManager.LoadedCharacterSettings.TryGetValueAsync(
                                      GlobalSettings.DefaultCharacterSetting);

                            await cboCharacterSetting.DoThreadSafeAsync(x =>
                            {
                                if (blnSuccess)
                                {
                                    x.SelectedValue = objSetting;
                                }
                                if (x.SelectedIndex == -1 && lstGameplayOptions.Count > 0)
                                {
                                    x.SelectedIndex = 0;
                                }
                            });
                        }
                    }
                }
                finally
                {
                    await this.DoThreadSafeAsync(x => x.ResumeLayout());
                }
            }
        }
Beispiel #11
0
 private async void cmdEditCharacterSetting_Click(object sender, EventArgs e)
 {
     using (CursorWait.New(this))
     {
         using (EditCharacterSettings frmOptions
                    = new EditCharacterSettings(cboCharacterSetting.SelectedValue as CharacterSettings))
             await frmOptions.ShowDialogSafeAsync(this);
         // Do not repopulate the character settings list because that will happen from frmCharacterSettings where appropriate
     }
 }
Beispiel #12
0
        private async void MasterIndex_Load(object sender, EventArgs e)
        {
            using (CursorWait.New(this))
            {
                await PopulateCharacterSettings();
                await LoadContent().AsTask().ContinueWith(x => IsFinishedLoading = true);

                _objSelectedSetting.PropertyChanged += OnSelectedSettingChanged;
            }
        }
Beispiel #13
0
        public static CursorWait New(Control objControl = null, bool blnAppStarting = false)
        {
            CursorWait objReturn = new CursorWait(objControl, blnAppStarting);

            if (objReturn._objControl == null)
            {
                if (Interlocked.Increment(ref _intApplicationWaitCursors) == 1)
                {
                    Application.UseWaitCursor            = true;
                    objReturn._blnDoUnsetCursorOnDispose = true;
                }
                return(objReturn);
            }
            Form frmControl = objReturn._objControl as Form;

            if (frmControl?.DoThreadSafeFunc(x => x.IsMdiChild) != false)
            {
                if (frmControl != null)
                {
                    objReturn._frmControlTopParent = frmControl.DoThreadSafeFunc(x => x.MdiParent);
                }
                else if (objReturn._objControl is UserControl objUserControl)
                {
                    objReturn._frmControlTopParent = objUserControl.DoThreadSafeFunc(x => x.ParentForm);
                }
                else if (objReturn._objControl != null)
                {
                    for (Control objLoop = objReturn._objControl.DoThreadSafeFunc(x => x.Parent); objLoop != null; objLoop = objLoop.DoThreadSafeFunc(x => x.Parent))
                    {
                        if (objLoop is Form objLoopForm)
                        {
                            objReturn._frmControlTopParent = objLoopForm;
                            break;
                        }
                    }
                }
            }

            if (objReturn._objControl != null)
            {
                if (objReturn._blnAppStartingCursor)
                {
                    int intNewValue = s_DicCursorControls.AddOrUpdate(objReturn._objControl, 1, (x, y) => Interlocked.Increment(ref y));
                    objReturn.SetControlCursor(intNewValue < short.MaxValue ? Cursors.AppStarting : Cursors.WaitCursor);
                    objReturn._blnDoUnsetCursorOnDispose = true;
                }
                else
                {
                    s_DicCursorControls.AddOrUpdate(objReturn._objControl, short.MaxValue, (x, y) => Interlocked.Add(ref y, short.MaxValue));
                    objReturn.SetControlCursor(Cursors.WaitCursor);
                    objReturn._blnDoUnsetCursorOnDispose = true;
                }
            }
            return(objReturn);
        }
Beispiel #14
0
        private async void cboCharacterSetting_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_blnSkipRefresh)
            {
                return;
            }
            try
            {
                using (await CursorWait.NewAsync(this, token: _objGenericToken))
                {
                    string strSelectedSetting
                        = (await cboCharacterSetting.DoThreadSafeFuncAsync(x => x.SelectedValue, _objGenericToken) as
                           CharacterSettings)?.DictionaryKey;
                    CharacterSettings objSettings = null;
                    bool blnSuccess = false;
                    if (!string.IsNullOrEmpty(strSelectedSetting))
                    {
                        (blnSuccess, objSettings)
                            = await SettingsManager.LoadedCharacterSettings.TryGetValueAsync(strSelectedSetting, _objGenericToken);
                    }

                    if (!blnSuccess)
                    {
                        (blnSuccess, objSettings)
                            = await SettingsManager.LoadedCharacterSettings.TryGetValueAsync(
                                  GlobalSettings.DefaultMasterIndexSetting, _objGenericToken);

                        if (!blnSuccess)
                        {
                            (blnSuccess, objSettings)
                                = await SettingsManager.LoadedCharacterSettings.TryGetValueAsync(
                                      GlobalSettings.DefaultMasterIndexSettingDefaultValue, _objGenericToken);

                            if (!blnSuccess)
                            {
                                objSettings = SettingsManager.LoadedCharacterSettings.Values.First();
                            }
                        }
                    }

                    if (objSettings != _objSelectedSetting)
                    {
                        _objSelectedSetting.PropertyChanged -= OnSelectedSettingChanged;
                        _objSelectedSetting = objSettings;
                        _objSelectedSetting.PropertyChanged += OnSelectedSettingChanged;

                        await LoadContent(_objGenericToken);
                    }
                }
            }
            catch (OperationCanceledException)
            {
                //swallow this
            }
        }
Beispiel #15
0
        private async void tsContactOpen_Click(object sender, EventArgs e)
        {
            if (_objSpirit.LinkedCharacter != null)
            {
                Character objOpenCharacter = await Program.OpenCharacters.ContainsAsync(_objSpirit.LinkedCharacter)
                    ? _objSpirit.LinkedCharacter
                    : null;

                using (await CursorWait.NewAsync(ParentForm))
                {
                    if (objOpenCharacter == null)
                    {
                        using (LoadingBar frmLoadingBar = await Program.CreateAndShowProgressBarAsync(_objSpirit.LinkedCharacter.FileName, Character.NumLoadingSections))
                            objOpenCharacter = await Program.LoadCharacterAsync(_objSpirit.LinkedCharacter.FileName, frmLoadingBar : frmLoadingBar);
                    }
                    if (!await Program.SwitchToOpenCharacter(objOpenCharacter))
                    {
                        await Program.OpenCharacter(objOpenCharacter);
                    }
                }
            }
            else
            {
                bool blnUseRelative = false;

                // Make sure the file still exists before attempting to load it.
                if (!File.Exists(_objSpirit.FileName))
                {
                    bool blnError = false;
                    // If the file doesn't exist, use the relative path if one is available.
                    if (string.IsNullOrEmpty(_objSpirit.RelativeFileName))
                    {
                        blnError = true;
                    }
                    else if (!File.Exists(Path.GetFullPath(_objSpirit.RelativeFileName)))
                    {
                        blnError = true;
                    }
                    else
                    {
                        blnUseRelative = true;
                    }

                    if (blnError)
                    {
                        Program.ShowMessageBox(string.Format(GlobalSettings.CultureInfo, await LanguageManager.GetStringAsync("Message_FileNotFound"), _objSpirit.FileName), await LanguageManager.GetStringAsync("MessageTitle_FileNotFound"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                string strFile = blnUseRelative ? Path.GetFullPath(_objSpirit.RelativeFileName) : _objSpirit.FileName;
                System.Diagnostics.Process.Start(strFile);
            }
        }
Beispiel #16
0
        private async void cmdRoll_Click(object sender, EventArgs e)
        {
            using (CursorWait.New(this))
            {
                int intResult = 0;
                for (int i = 0; i < Dice; ++i)
                {
                    intResult += await GlobalSettings.RandomGenerator.NextD6ModuloBiasRemovedAsync();
                }

                nudDiceResult.ValueAsInt = intResult;
            }
        }
Beispiel #17
0
 private ValueTask RefreshCalculation()
 {
     using (CursorWait.New(this))
     {
         nudDiceResult.SuspendLayout();
         nudDiceResult.MinimumAsInt =
             int.MinValue; // Temporarily set this to avoid crashing if we shift from something with more than 6 dice to something with less.
         nudDiceResult.MaximumAsInt = SelectedLifestyle?.Dice * 6 ?? 0;
         nudDiceResult.MinimumAsInt = SelectedLifestyle?.Dice ?? 0;
         nudDiceResult.ResumeLayout();
         return(RefreshResultLabel());
     }
 }
Beispiel #18
0
        private async void cmdEditCharacterOption_Click(object sender, EventArgs e)
        {
            using (CursorWait.New(this))
            {
                using (EditCharacterSettings frmOptions =
                           new EditCharacterSettings(cboCharacterSetting.SelectedValue as CharacterSettings))
                    await frmOptions.ShowDialogSafeAsync(this);

                SuspendLayout();
                try
                {
                    // Populate the Gameplay Settings list.
                    object objOldSelected = cboCharacterSetting.SelectedValue;
                    using (new FetchSafelyFromPool <List <ListItem> >(
                               Utils.ListItemListPool, out List <ListItem> lstGameplayOptions))
                    {
                        lstGameplayOptions.AddRange(SettingsManager.LoadedCharacterSettings.Values
                                                    .Select(objLoopOptions =>
                                                            new ListItem(
                                                                objLoopOptions,
                                                                objLoopOptions.DisplayName)));
                        lstGameplayOptions.Sort(CompareListItems.CompareNames);
                        await cboCharacterSetting.PopulateWithListItemsAsync(lstGameplayOptions);

                        cboCharacterSetting.SelectedValue = objOldSelected;
                        if (cboCharacterSetting.SelectedIndex == -1 && lstGameplayOptions.Count > 0)
                        {
                            (bool blnSuccess, CharacterSettings objSetting)
                                = await SettingsManager.LoadedCharacterSettings.TryGetValueAsync(
                                      GlobalSettings.DefaultCharacterSetting);

                            if (blnSuccess)
                            {
                                cboCharacterSetting.SelectedValue = objSetting;
                            }
                        }

                        if (cboCharacterSetting.SelectedIndex == -1 && lstGameplayOptions.Count > 0)
                        {
                            cboCharacterSetting.SelectedIndex = 0;
                        }
                    }
                }
                finally
                {
                    ResumeLayout();
                }
            }
        }
Beispiel #19
0
 private async void cboGamePlay_SelectedIndexChanged(object sender, EventArgs e)
 {
     using (CursorWait.New(this))
     {
         SuspendLayout();
         try
         {
             await ProcessGameplayIndexChanged();
         }
         finally
         {
             ResumeLayout();
         }
     }
 }
        private async ValueTask RefreshResultLabel()
        {
            using (await CursorWait.NewAsync(this))
            {
                string strSpace = await LanguageManager.GetStringAsync("String_Space");

                await lblResult.DoThreadSafeAsync(x => x.Text = strSpace + '+' + strSpace + Extra.ToString("#,0", GlobalSettings.CultureInfo) + ')' +
                                                  strSpace + '×'
                                                  + strSpace + (SelectedLifestyle?.Multiplier ?? 0).ToString(
                                                      _objCharacter.Settings.NuyenFormat + '¥', GlobalSettings.CultureInfo)
                                                  + strSpace + '=' + strSpace +
                                                  StartingNuyen.ToString(_objCharacter.Settings.NuyenFormat + '¥',
                                                                         GlobalSettings.CultureInfo));
            }
        }
Beispiel #21
0
 public async ValueTask ForceRepopulateCharacterSettings()
 {
     using (CursorWait.New(this))
     {
         SuspendLayout();
         try
         {
             await PopulateCharacterSettings();
         }
         finally
         {
             ResumeLayout();
         }
     }
 }
Beispiel #22
0
 private async void OnSelectedSettingChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName == nameof(CharacterSettings.Books) ||
         e.PropertyName == nameof(CharacterSettings.EnabledCustomDataDirectoryPaths))
     {
         try
         {
             using (await CursorWait.NewAsync(this, token: _objGenericToken))
                 await LoadContent(_objGenericToken);
         }
         catch (OperationCanceledException)
         {
             //swallow this
         }
     }
 }
        private async void cboGamePlay_SelectedIndexChanged(object sender, EventArgs e)
        {
            using (await CursorWait.NewAsync(this))
            {
                await this.DoThreadSafeAsync(x => x.SuspendLayout());

                try
                {
                    await ProcessGameplayIndexChanged();
                }
                finally
                {
                    await this.DoThreadSafeAsync(x => x.ResumeLayout());
                }
            }
        }
        private async void cmdRoll_Click(object sender, EventArgs e)
        {
            if (SelectedLifestyle == null)
            {
                return;
            }
            using (await CursorWait.NewAsync(this))
            {
                int intResult = 0;
                for (int i = 0; i < SelectedLifestyle.Dice; ++i)
                {
                    intResult += await GlobalSettings.RandomGenerator.NextD6ModuloBiasRemovedAsync();
                }

                await nudDiceResult.DoThreadSafeAsync(x => x.ValueAsInt = intResult);
            }
        }
Beispiel #25
0
 private async void cmdEditCharacterSetting_Click(object sender, EventArgs e)
 {
     try
     {
         using (await CursorWait.NewAsync(this, token: _objGenericToken))
         {
             using (ThreadSafeForm <EditCharacterSettings> frmOptions = await ThreadSafeForm <EditCharacterSettings> .GetAsync(
                        () => new EditCharacterSettings(cboCharacterSetting.SelectedValue as CharacterSettings), _objGenericToken))
                 await frmOptions.ShowDialogSafeAsync(this, _objGenericToken);
             // Do not repopulate the character settings list because that will happen from frmCharacterSettings where appropriate
         }
     }
     catch (OperationCanceledException)
     {
         //swallow this
     }
 }
Beispiel #26
0
        public async ValueTask ForceRepopulateCharacterSettings(CancellationToken token = default)
        {
            token.ThrowIfCancellationRequested();
            using (await CursorWait.NewAsync(this, token: token))
            {
                await this.DoThreadSafeAsync(x => x.SuspendLayout(), token);

                try
                {
                    await PopulateCharacterSettings(token);
                }
                finally
                {
                    await this.DoThreadSafeAsync(x => x.ResumeLayout(), token);
                }
            }
        }
Beispiel #27
0
        private async void cmdOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(_strXslt))
            {
                return;
            }

            using (CursorWait.New(this))
            {
                if (_strXslt == "JSON")
                {
                    await ExportJson();
                }
                else
                {
                    await ExportNormal();
                }
            }
        }
Beispiel #28
0
        private async void MasterIndex_Load(object sender, EventArgs e)
        {
            try
            {
                using (await CursorWait.NewAsync(this, token: _objGenericToken))
                {
                    await PopulateCharacterSettings(_objGenericToken);
                    await LoadContent(_objGenericToken);

                    _objSelectedSetting.PropertyChanged += OnSelectedSettingChanged;
                }
            }
            catch (OperationCanceledException)
            {
                //swallow this
            }
            finally
            {
                IsFinishedLoading = true;
            }
        }
Beispiel #29
0
        private async ValueTask RefreshBaseLifestyle()
        {
            if (_blnIsSelectLifestyleRefreshing)
            {
                return;
            }
            if (cboSelectLifestyle.SelectedIndex < 0)
            {
                return;
            }
            using (CursorWait.New(this))
            {
                _objLifestyle = ((ListItem)cboSelectLifestyle.SelectedItem).Value as Lifestyle;
                lblDice.Text  = string.Format(GlobalSettings.CultureInfo,
                                              await LanguageManager.GetStringAsync("Label_LifestyleNuyen_ResultOf"),
                                              SelectedLifestyle?.Dice ?? 0);
                await RefreshCalculation();

                cmdRoll.Enabled = SelectedLifestyle?.Dice > 0;
            }
        }
Beispiel #30
0
        private async Task GenerateJson()
        {
            using (CursorWait.New(this))
            {
                await cmdOK.DoThreadSafeAsync(x => x.Enabled = false);

                try
                {
                    string strText = JsonConvert.SerializeXmlNode(_objCharacterXml, Formatting.Indented);
                    if (_objXmlGeneratorCancellationTokenSource.IsCancellationRequested)
                    {
                        return;
                    }
                    SetTextToWorkerResult(strText);
                }
                finally
                {
                    await cmdOK.DoThreadSafeAsync(x => x.Enabled = true);
                }
            }
        }