예제 #1
0
        /// <summary>
        /// Save results to a file.
        /// </summary>
        private async void AsyncSaveResultsToFile()
        {
            //Debug.WriteLine($"AsyncSaveResultsToFile(): Method start.");
            FileOpenPicker fileOpenPicker = new FileOpenPicker
            {
                SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
                ViewMode = PickerViewMode.List
            };

            // Need at least one filter to prevent exception.
            fileOpenPicker.FileTypeFilter.Add("*");
            StorageFile storageFilePicked = await fileOpenPicker.PickSingleFileAsync();

            if (storageFilePicked != null)
            {
                string stringOutputTitle = mainPage.stringAppTitle;
                if (!CommonItems.boolAppPurchased)
                {
                    // App not purchased.
                    stringOutputTitle += " - Application in trial mode since not purchased.";
                }
                //Debug.WriteLine($"AsyncSaveResultsToFile(): stringOutputTitle={stringOutputTitle}");
                DateTime dateTime         = DateTime.Now;
                string   stringOutputNote = $"{TblkDisplayResultsNote.Text}: {dateTime:d} @ {dateTime:t}";
                //Debug.WriteLine($"AsyncSaveResultsToFile(): Day: {dateTime:d} Time: {dateTime:t}");
                string stringOutput = $"{stringOutputTitle}\n\n{stringOutputNote}\n{TblkDisplayResultsOutput.Text}";
                await FileIO.WriteTextAsync(storageFilePicked, stringOutput);

                LibMPC.OutputMsgSuccess(TblkDisplayResultsSaveMsgs, $"Saved results to {storageFilePicked.Path}.");
                //Debug.WriteLine($"AsyncSaveResultsToFile(): Saved results to { storageFilePicked.Path}.");
            }
            else   // User did not select a file.
            {
                LibMPC.OutputMsgError(TblkDisplayResultsSaveMsgs, "Did not save results since no file selected.");
                //Debug.WriteLine($"AsyncSaveResultsToFile(): Did not save results since no file selected.");
            }
        }
예제 #2
0
        /*** Page Events *******************************************************************************************************/

        /// <summary>
        /// On page load set focus to ButSFFolderPicker.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            _ = sender;     // Discard unused parameter.
            _ = e;          // Discard unused parameter.
            // Hide XAML layout rectangles by setting to same color as RelativePanel Background;
            RectLayoutCenter.Fill = Rpanel.Background;
            RectLayoutLeft.Fill   = Rpanel.Background;
            RectLayoutRight.Fill  = Rpanel.Background;
            LibMPC.ButtonVisibility(mainPage.mainPageButAbout, false);
            LibMPC.ButtonVisibility(mainPage.mainPageButBack, false);
            LibMPC.ButtonVisibility(mainPage.mainPageButSettings, false);
            List <Button> listButtonsThisPage = new List <Button>()
            {
                ButFolderPicker,
                ButContinue
            };

            LibMPC.SizePageButtons(listButtonsThisPage);
            LibMPC.OutputMsgSuccess(TblkPageTitle, mainPage.resourceLoader.GetString("SF_TblkPageTitle"));
            CboxSamples.Content = mainPage.resourceLoader.GetString("SF_CboxSamples");
            if (mainPage.boolVerbose)                                                                                                                     // Display long message.
            {
                LibMPC.OutputMsgBright(TblkPageMsg, LibMPC.JoinListString(Translate.TRS_SF_List_TblkPageMsg_Text_Long, EnumStringSeparator.TwoNewlines)); // Do not assemble string until needed to save memory.
            }
            else                                                                                                                                          // Display short message.
            {
                LibMPC.OutputMsgBright(TblkPageMsg, LibMPC.JoinListString(Translate.TRS_SF_List_TblkPageMsg_Text_Short, EnumStringSeparator.TwoSpaces));  // Do not assemble string until needed to save memory.
            }
            TblkResult.Text        = string.Empty;                                                                                                        // Show empty string until a value is set by App.
            CboxSamples.Visibility = Visibility.Collapsed;                                                                                                // Hide CboxSamples until needed.
            LibMPC.ButtonVisibility(ButContinue, false);                                                                                                  // Hide ButContinue until needed.
            DataStoreFirstRun();
            //Setup scrolling for this page.
            LibMPC.ScrollViewerOn(mainPage.mainPageScrollViewer, horz: ScrollMode.Disabled, vert: ScrollMode.Auto, horzVis: ScrollBarVisibility.Disabled, vertVis: ScrollBarVisibility.Auto, zoom: ZoomMode.Disabled);
            ButFolderPicker.Focus(FocusState.Programmatic);
        }
예제 #3
0
        /// <summary>
        /// Add support to beam.
        /// </summary>
        private void AddSupport()
        {
            //Debug.WriteLine($"AddSupport(): doubleSupportPosition={doubleSupportPosition}, boolSupportDisplacement={boolSupportDisplacement}, boolSupportRotation={boolSupportRotation}");
            // Check displacement and rotation bools are not both true since not a support if so.
            if (!(boolSupportDisplacement == true && boolSupportRotation == true))
            {
                bool boolDuplicateSupportFound = false;
                foreach (SupportValues supportValues in CommonItems.listSupportValues)
                {
                    if (supportValues.DoubleSupportPosition.Equals(doubleSupportPosition))
                    {
                        boolDuplicateSupportFound = true;
                        break;
                    }
                }
                if (boolDuplicateSupportFound)
                {
                    if (boolDefinedSupportEntered)
                    {
                        boolDefinedSupportEnteredAll = false;
                        LibMPC.OutputMsgError(TblkSupportResult, "One or more supports not added since support already entered at position.");
                    }
                    else
                    {
                        LibMPC.OutputMsgError(TblkSupportResult, "Support not added since support already entered at position.");
                    }
                }
                else
                {
                    SupportValues supportValuesAdd = new SupportValues
                    {
                        DoubleSupportPosition   = doubleSupportPosition,
                        BoolSupportDisplacement = boolSupportDisplacement,
                        BoolSupportRotation     = boolSupportRotation
                    };
                    CommonItems.listSupportValues.Add(supportValuesAdd);     // Add support values to support list.


                    if (boolDefinedSupportEntered)
                    {
                        if (boolDefinedSupportEnteredAll)           // Do not overwrite error message if false.
                        {
                            LibMPC.OutputMsgSuccess(TblkSupportResult, "Support(s) added.");
                        }
                    }
                    else
                    {
                        LibMPC.OutputMsgSuccess(TblkSupportResult, "Support added.");
                    }
                    if (CommonItems.listSupportValues.Count > 0)
                    {
                        // More than one support entered so sort by DoubleSupportPosition.
                        CommonItems.listSupportValues.Sort((x, y) => x.DoubleSupportPosition.CompareTo(y.DoubleSupportPosition));
                    }
                    CommonItems.boolEnteredSupport = true;
                }
            }
            else
            {
                LibMPC.OutputMsgError(TblkSupportResult, "Support not added since displacement and rotation at support were both on.");
            }
            CommonItems.ButtonForegroundColorSet(ButSupportClear, CommonItems.boolEnteredSupport);
            SetDefaultValuesSupport();
        }
예제 #4
0
        /// <summary>
        /// Ask User to create folder and edit name to use as their Encryption Locker.
        /// User's folder will then be added to 'FutureAccessList' for retrieval on subsequent runs.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ButFolderPicker_Click(object sender, RoutedEventArgs e)
        {
            _ = sender;     // Discard unused parameter.
            _ = e;          // Discard unused parameter.
            try
            {
                CboxSamples.Visibility = Visibility.Collapsed;      // Hide checkbox until needed.
                LibMPC.ButtonVisibility(ButContinue, false);        // Hide continue button until needed.
                FolderPicker folderPicker = new FolderPicker()
                {
                    SuggestedStartLocation = PickerLocationId.DocumentsLibrary
                };
                folderPicker.FileTypeFilter.Add("*");   // Need at least one filter to prevent exception.
                StorageFolder storageFolderPicked = await folderPicker.PickSingleFolderAsync();

                if (storageFolderPicked != null)
                {
                    // Folder picker can create a folder anywhere.  Example, 'C:\Program Files'.  But that does not mean App can get Read/Write access to it.  If folder
                    // location is protected, a 'System.UnauthorizedAccessException' error will occur when attempt is made to write data there.  App needs to check if it
                    // can get R/W access by attempting to create a file there.  if exception occurs, folder is in protected location. Make User pick a different location.
                    // Do not need to translate this since should only exist for an instant.
                    StorageFile storageFileFolderTest = await storageFolderPicked.CreateFileAsync("EL_XYZ_FILE_TEST.txt", CreationCollisionOption.ReplaceExisting);

                    if (storageFileFolderTest != null)
                    {
                        await storageFileFolderTest.DeleteAsync(StorageDeleteOption.PermanentDelete);
                    }
                    // If above file did not throw exception, then App has R/W access to folder.  So continue...
                    mainPage.storageFolderLocker = storageFolderPicked;
                    mainPage.stringLockerPath    = mainPage.storageFolderLocker.Path;                                                      // Save path since used often.
                                                                                                                                           // Application now has Read/Write access to contents 'inside' picked folder.  INSIDE is key word here.  App cannot delete or rename picked folder.
                    StorageApplicationPermissions.FutureAccessList.Clear();                                                                // Empty FutureAccessList and start fresh.
                    StorageApplicationPermissions.FutureAccessList.AddOrReplace(mainPage.stringTokenLocker, mainPage.storageFolderLocker); //Add new token to FutureAccessList.
                    List <string> list_stringMessagePage = new List <string>()
                    {
                        mainPage.resourceLoader.GetString("SF_Success_Picker_Msg1"),       // Folder selected was:
                        mainPage.stringLockerPath,
                        mainPage.resourceLoader.GetString("SF_Success_Picker_Msg2")        // Click following button to use this folder.  Click above button to select different folder.
                    };
                    LibMPC.OutputMsgSuccess(TblkResult, LibMPC.JoinListString(list_stringMessagePage, EnumStringSeparator.OneNewline));
                    CboxSamples.Visibility = Visibility.Visible;    // Show checkbox only if verbose mode?????
                    LibMPC.ButtonVisibility(ButContinue, true);     // Show continue button.
                    ButContinue.Focus(FocusState.Programmatic);
                }
                else                                                                                                        // User did not select a folder.
                {
                    LibMPC.OutputMsgError(TblkResult, mainPage.resourceLoader.GetString("UMP_Error_Picker_NothingPicked")); // Did not pick anything.
                    ButFolderPicker.Focus(FocusState.Programmatic);
                }
            }
            catch (UnauthorizedAccessException)
            {
                // Catch 'UnauthorizedAccessException' exception if User picks protected location for Locker folder.
                // This exception can be triggered by attempting to create the test file in a protected folder. Example, try to create Locker in C:\Program Files.
                // Cannot get read and write access to selected folder.  Folder likely in protected location.  Create folder in different location.
                LibMPC.OutputMsgError(TblkResult, mainPage.resourceLoader.GetString("SF_Error_Picker_FolderException"));
                CboxSamples.Visibility = Visibility.Collapsed;      // Hide checkbox.
                LibMPC.ButtonVisibility(ButContinue, false);        // Hide continue button.
                throw;
            }
            catch (Exception ex)    // Catch any other exceptions.
            {
                LibMPC.OutputMsgError(TblkResult, mainPage.UnhandledExceptionMessage("SetupFolder.ButFolderPicker_Click()", ex.GetType()));
                throw;
            }
        }
        /// <summary>
        /// Add uniform load if User has entered valid position and force values for load. Otherwise show error message.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButLoadUniformAdd_Click(object sender, RoutedEventArgs e)
        {
            _ = sender;     // Discard unused parameter.
            _ = e;          // Discard unused parameter.
            //Debug.WriteLine($"ButLoaduniformAdd_Click() event fired.");
            TblkLoadUniformLostFocus.Text = string.Empty;
            if (boolEnteredLoadUniformPositionLeft && boolEnteredLoadUniformPositionRight && boolEnteredLoadUniformForceLeft && boolEnteredLoadUniformForceRight)
            {
                CommonItems.AddLoadUniformToList(doubleLoadUniformPositionLeft, doubleLoadUniformPositionRight, doubleLoadUniformForceLeft, doubleLoadUniformForceRight);
                TblkLoadUniformDisplay.Text = CommonItems.ShowEnteredSupportsAndLoads();
                LibMPC.OutputMsgSuccess(TblkLoadUniformResult, $"Uniform load added.");
                LoadUniformDefaultValues();
            }
            else
            {
                //Debug.WriteLine($"ButLoaduniformAdd_Click() One or more input values not valid.");
                // Build error message to show User if position or force values not entered.
                string stringErrorMsg         = "Uniform load not added since one or more following values not entered or not valid:\n";
                bool   boolErrorPositionLeft  = false;
                bool   boolErrorForceLeft     = false;
                bool   boolErrorPositionRight = false;

                if (!boolEnteredLoadUniformPositionLeft)
                {
                    boolErrorPositionLeft = true;
                    stringErrorMsg       += $"{CommonItems.stringConstPositionLeft}";
                }
                if (!boolEnteredLoadUniformForceLeft)
                {
                    boolErrorForceLeft = true;
                    if (boolErrorPositionLeft)
                    {
                        stringErrorMsg += $", {CommonItems.stringConstForceLeft}";
                    }
                    else
                    {
                        stringErrorMsg += $"{CommonItems.stringConstForceLeft}";
                    }
                }
                if (!boolEnteredLoadUniformPositionRight)
                {
                    boolErrorPositionRight = true;
                    if (boolErrorPositionLeft || boolErrorForceLeft)
                    {
                        stringErrorMsg += $", {CommonItems.stringConstPositionRight}";
                    }
                    else
                    {
                        stringErrorMsg += $"{CommonItems.stringConstPositionRight}";
                    }
                }
                if (!boolEnteredLoadUniformForceRight)
                {
                    if (boolErrorPositionLeft || boolErrorForceLeft || boolErrorPositionRight)
                    {
                        stringErrorMsg += $", {CommonItems.stringConstForceRight}";
                    }
                    else
                    {
                        stringErrorMsg += $"{CommonItems.stringConstForceRight}";
                    }
                }
                LibMPC.OutputMsgError(TblkLoadUniformResult, stringErrorMsg);
            }

            CommonItems.ButtonForegroundColorSet(ButLoadUniformClear, CommonItems.boolEnteredLoadUniform);
            CommonItems.ButtonForegroundColorSet(ButLoadUniformSimulatedLoads, CommonItems.boolEnteredLoadUniform);
        }
예제 #6
0
        /*** Page Events *******************************************************************************************************/

        /// <summary>
        /// Set focus to ST_HButAboutToggles when page loads.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            _ = sender;     // Discard unused parameter.
            _ = e;          // Discard unused parameter.
            // Hide XAML layout rectangles by setting to same color as RelativePanel Background;
            RectLayoutCenter.Fill = Rpanel.Background;
            RectLayoutLeft.Fill   = Rpanel.Background;
            RectLayoutRight.Fill  = Rpanel.Background;
            LibMPC.ButtonVisibility(mainPage.mainPageButAbout, false);
            LibMPC.ButtonVisibility(mainPage.mainPageButBack, true);
            LibMPC.ButtonVisibility(mainPage.mainPageButSettings, false);
            ButAppReset.Foreground = LibMPC.colorError; List <ToggleSwitch> listToggleSwitchesThisPage = new List <ToggleSwitch>()
            {
                TogExitApp,
                TogDeleteSecure,
                TogVerbose
            };
            LibMPC.SizePageToggleSwitches(listToggleSwitchesThisPage);
            List <Button> listButtonsThisPage = new List <Button>()
            {
                ButAboutToggles,
                ButLockerReset,
                ButAppReset
            };

            LibMPC.SizePageButtons(listButtonsThisPage);
            CboxLanguage.MinWidth     = ButAboutToggles.ActualWidth; // Set CboxLanguage.MinWidth to value of other buttons on page.
            ButLockerReset.Foreground = LibMPC.colorError;
            LibMPC.OutputMsgSuccess(TblkPageTitle, mainPage.resourceLoader.GetString("ST_TblkPageTitle"));
            CboxLanguage.PlaceholderText = mainPage.resourceLoader.GetString("ST_CboxLanguage_PlaceholderText");
            // XAML margin setting is 16,2,16,2. Margin Setting Order: left, top, right, bottom.
            // Margin for ToggleSwitches needs to be adjusted for some cultures to keep them centered.
            // TODO: Will need to add new item here if a new translation is added!
            switch (mainPage.stringCultureCurrent)
            {
            case "en-US":
                TogExitApp.Margin      = new Thickness(29, 2, 2, 2);
                TogDeleteSecure.Margin = new Thickness(29, 2, 2, 2);
                TogVerbose.Margin      = new Thickness(29, 2, 2, 2);
                break;

            case "en":
                TogExitApp.Margin      = new Thickness(29, 2, 2, 2);
                TogDeleteSecure.Margin = new Thickness(29, 2, 2, 2);
                TogVerbose.Margin      = new Thickness(29, 2, 2, 2);
                break;

            case "es":
                TogExitApp.Margin      = new Thickness(17, 2, 2, 2);
                TogDeleteSecure.Margin = new Thickness(17, 2, 2, 2);
                TogVerbose.Margin      = new Thickness(17, 2, 2, 2);
                break;

            case "hi":
                TogExitApp.Margin      = new Thickness(17, 2, 2, 2);
                TogDeleteSecure.Margin = new Thickness(17, 2, 2, 2);
                TogVerbose.Margin      = new Thickness(17, 2, 2, 2);
                break;

            case "fr":
                TogExitApp.Margin      = new Thickness(17, 2, 2, 2);
                TogDeleteSecure.Margin = new Thickness(17, 2, 2, 2);
                TogVerbose.Margin      = new Thickness(17, 2, 2, 2);
                break;

            case "zh-Hans":
                TogExitApp.Margin      = new Thickness(44, 2, 2, 2);
                TogDeleteSecure.Margin = new Thickness(44, 2, 2, 2);
                TogVerbose.Margin      = new Thickness(44, 2, 2, 2);
                break;

            default:        // Throw exception so error can be discovered and corrected.
                throw new NotSupportedException($"Settings.Page_Loaded(): mainPage.stringCultureCurrent={mainPage.stringCultureCurrent} not found in switch statement.");
            }

            // TODO: Will need to add new item here if a new translation is added!
            CboxItem_LanguageDevice.Content = mainPage.resourceLoader.GetString("ST_CboxItem_LanguageDevice");
            CboxItem_LanguageEN.Content     = mainPage.resourceLoader.GetString("ST_CboxItem_LanguageEN");
            CboxItem_LanguageES.Content     = mainPage.resourceLoader.GetString("ST_CboxItem_LanguageES");
            CboxItem_LanguageHI.Content     = mainPage.resourceLoader.GetString("ST_CboxItem_LanguageHI");
            CboxItem_LanguageFR.Content     = mainPage.resourceLoader.GetString("ST_CboxItem_LanguageFR");
            CboxItem_LanguageZH.Content     = mainPage.resourceLoader.GetString("ST_CboxItem_LanguageZH");
            CboxLanguage.SelectedIndex      = DataStoreCultureIndex();                                        // Get saved index value from data store.

            LibMPC.OutputMsgNormal(TblkResult, mainPage.resourceLoader.GetString("ST_ModeToggleMsg"));        // Change application configuration using above toggles.  Click above button for more information about the toggles.
            LibMPC.OutputMsgBright(TblkLockerResetMsg, mainPage.GetLockerResetMsg());                         // Get Locker Reset message.
            LibMPC.OutputMsgBright(TblkAppResetMsg, $"{mainPage.resourceLoader.GetString("ST_TblkAppResetMsg")} {mainPage.resourceLoader.GetString("UMP_Reset_Msg")}");
            LibMPC.OutputMsgBright(TblkLanguageMsg, mainPage.resourceLoader.GetString("ST_TblkLanguageMsg")); // Select application language. Application will close if selection is changed. Selected language will load next application start.
            SetToggles();                                                                                     // Set this before next line so initial return message will be cleared by next line.  Don't want to see return message on page load.
            TblkResult.Text = string.Empty;
            // Setup scrolling for this page.
            LibMPC.ScrollViewerOn(mainPage.mainPageScrollViewer, ScrollMode.Disabled, vert: ScrollMode.Auto, horzVis: ScrollBarVisibility.Disabled, vertVis: ScrollBarVisibility.Auto, zoom: ZoomMode.Disabled);
            ButAboutToggles.Focus(FocusState.Programmatic);
        }