コード例 #1
0
        //--------------------------------------------------------------------------------------------------

        public bool SaveModelAs()
        {
            var dlg = new SaveFileDialog()
            {
                Title           = "Saving Model...",
                CheckPathExists = true,
                Filter          = "Macad3D Models|*." + Model.FileExtension,
                DefaultExt      = Model.FileExtension
            };
            var result = dlg.ShowDialog(Application.Current.MainWindow);

            if (result ?? false)
            {
                var relativeFilePath = dlg.FileName;
                var model            = InteractiveContext.Current.Document;
                if (model.SaveToFile(relativeFilePath))
                {
                    AddToMruList(model.FilePath);
                    return(true);
                }
                else
                {
                    ErrorDialogs.CannotSaveFile(dlg.FileName);
                }
            }
            return(false);
        }
コード例 #2
0
        //--------------------------------------------------------------------------------------------------

        void _OpenRecentCommandExecute(string fileName)
        {
            if (!File.Exists(fileName))
            {
                bool remove = false;
                _BeginInvoke(() =>
                {
                    remove = ErrorDialogs.RecentFileNotFound(fileName);
                    if (remove)
                    {
                        InteractiveContext.Current?.DocumentController?.RemoveFromMruList(fileName);

                        MruList = _LoadMRU();
                        RaisePropertyChanged(nameof(MruList));
                    }
                });


                return;
            }

            using (new WaitCursor())
            {
                WelcomeDialog.Current.Cursor = Cursors.Wait;
                _BeginInvoke(() => { InteractiveContext.Current?.DocumentController?.OpenFile(fileName, false); });
            }

            WelcomeDialog.Current?.Close();
        }
コード例 #3
0
        //--------------------------------------------------------------------------------------------------

        public Model CreateModelAs(string baseDirectory = null)
        {
            var dlg = new SaveFileDialog()
            {
                Title           = "Create Model...",
                CheckPathExists = true,
                Filter          = "Macad3D Models|*." + Model.FileExtension,
                DefaultExt      = Model.FileExtension,
            };

            if (!(baseDirectory is null))
            {
                dlg.InitialDirectory = baseDirectory;
            }

            var result = dlg.ShowDialog(Application.Current.MainWindow);

            if (!(result ?? false))
            {
                return(null);
            }

            var relativeFilePath = dlg.FileName;
            var model            = NewModel();

            if (model.SaveToFile(relativeFilePath))
            {
                return(model);
            }
            else
            {
                ErrorDialogs.CannotSaveFile(dlg.FileName);
            }
            return(null);
        }
コード例 #4
0
ファイル: ModelController.cs プロジェクト: Macad3D/Macad3D
        //--------------------------------------------------------------------------------------------------

        public bool SaveModelAs()
        {
            var dlg = new SaveFileDialog()
            {
                Title            = "Saving Model...",
                InitialDirectory = Path.GetDirectoryName(InteractiveContext.Current.Document.FilePath),
                FileName         = Path.GetFileName(InteractiveContext.Current.Document.FilePath),
                CheckPathExists  = true,
                Filter           = "Macad3D Models|*." + Model.FileExtension,
                DefaultExt       = Model.FileExtension
            };
            var result = dlg.ShowDialog(Application.Current.MainWindow);

            if (result ?? false)
            {
                var filePath = dlg.FileName;
                if (PathUtils.GetExtensionWithoutPoint(filePath).ToLower() != Model.FileExtension)
                {
                    filePath += "." + Model.FileExtension;
                }
                var model = InteractiveContext.Current.Document;
                if (model.SaveToFile(filePath))
                {
                    AddToMruList(model.FilePath);
                    return(true);
                }
                else
                {
                    ErrorDialogs.CannotSaveFile(dlg.FileName);
                }
            }
            return(false);
        }
コード例 #5
0
        private async Task UseExistDatafile()
        {
            try
            {
                //TODO current workaround: check permission to the file system (broadFileSystemAccess)
                string      path = @"C:\Windows\explorer.exe";
                StorageFile file = await StorageFile.GetFileFromPathAsync(path);

                UseDatafileContentDialog dialog = new UseDatafileContentDialog();
                ContentDialogResult      result = await _dialogService.ShowAsync(dialog);

                //result is also none, when the datafileDB is correct created
                if (result == ContentDialogResult.None)
                {
                    var datafileDB = await App.Repository.Datafile.GetAsync();

                    if (datafileDB != null)
                    {
                        //_canNavigate = true;
                        await _navigationService.NavigateAsync("/" + nameof(AccountCodePage));
                    }
                }
            }
            catch (UnauthorizedAccessException)
            {
                ErrorDialogs.UnauthorizedAccessDialog();
            }
        }
コード例 #6
0
        void ExecuteExport()
        {
            {
                if (!ExportDialog.Execute <IVectorExporter>(out string fileName, out var exporter))
                {
                    return;
                }

                if (!_Tool.Component.Export(fileName, exporter))
                {
                    ErrorDialogs.CannotExport(fileName);
                }
            }
        }
コード例 #7
0
        //--------------------------------------------------------------------------------------------------

        public bool OpenModel(string filePath)
        {
            try
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                var context = new SerializationContext(SerializationScope.Storage);
                var model   = Model.CreateFromFile(filePath, context);
                if (model == null)
                {
                    switch (context.Result)
                    {
                    case SerializationResult.VersionMismatch:
                        ErrorDialogs.FileVersionIsNewer(filePath);
                        break;

                    default:
                        ErrorDialogs.CannotLoadFile(filePath);
                        break;
                    }

                    return(false);
                }

                if (context.HasErrors)
                {
                    ErrorDialogs.FileLoadedWithErrors(filePath);
                }

                InteractiveContext.Current.Document = model;

                model.ResetUnsavedChanges();
                AddToMruList(filePath);

                stopwatch.Stop();
                Messages.Info(string.Format("Model " + model.Name + " loaded in {0}:{1} seconds.", stopwatch.Elapsed.Seconds, stopwatch.Elapsed.Milliseconds));
                return(true);
            }
            catch (Exception e)
            {
                Messages.Exception($"Exception while loading model {filePath}.", e);
                ErrorDialogs.CannotLoadFile(filePath);
                return(false);
            }
        }
コード例 #8
0
        public async Task <bool> UseExistDatafile()
        {
            try
            {
                //TODO current workaround: check permission to the file system (broadFileSystemAccess)
                string      path = @"C:\Windows\explorer.exe";
                StorageFile file = await StorageFile.GetFileFromPathAsync(path);

                await SetLocalFile();

                return(true);
            }
            catch (UnauthorizedAccessException)
            {
                ErrorDialogs.UnauthorizedAccessUseLocalFileDialog();
                return(false);
            }
        }
コード例 #9
0
        //--------------------------------------------------------------------------------------------------

        public bool SaveModel()
        {
            var model = InteractiveContext.Current.Document;

            if (model.FilePath.IsNullOrEmpty())
            {
                return(SaveModelAs());
            }
            else
            {
                if (model.Save())
                {
                    AddToMruList(model.FilePath);
                    return(true);
                }
                ErrorDialogs.CannotSaveFile(model.FilePath);
            }
            return(false);
        }
コード例 #10
0
ファイル: DataService.cs プロジェクト: 2fast-team/2fast
        /// <summary>
        /// Displays a FileNotFoundException message and the option for factory reset or correcting the path
        /// </summary>
        private async void ShowFileOrFolderNotFoundError()
        {
            var dialogService = App.Current.Container.Resolve <IDialogService>();

            try
            {
                //TODO current workaround: check permission to the file system (broadFileSystemAccess)
                string path = @"C:\Windows\explorer.exe";
                var    file = await StorageFile.GetFileFromPathAsync(path);
            }
            catch (UnauthorizedAccessException)
            {
                ErrorDialogs.UnauthorizedAccessDialog();
            }
            _errorOccurred = true;
            // disable shell navigation
            App.ShellPageInstance.NavigationIsAllowed = false;
            Logger.Log("no datafile found", Category.Exception, Priority.High);
            bool selectedOption = false;

            var dialog = new ContentDialog();

            dialog.Closed += Dialog_Closed;
            dialog.Title   = Resources.ErrorHandle;
            var markdown = new MarkdownTextBlock();

            markdown.Text = Resources.ExceptionDatafileNotFound;
            var stackPanel = new StackPanel();

            stackPanel.Children.Add(markdown);

            var changePathBTN = new Button();

            changePathBTN.Margin  = new Thickness(0, 10, 0, 0);
            changePathBTN.Content = Resources.ChangeDatafilePath;
            changePathBTN.Command = new DelegateCommand(async() =>
            {
                selectedOption = true;
                dialog.Hide();
                var result = await dialogService.ShowAsync(new UpdateDatafileContentDialog());
                if (result == ContentDialogResult.Primary)
                {
                    ErrorResolved();
                    CheckDatafile();
                }
                if (result == ContentDialogResult.None)
                {
                    ShowFileOrFolderNotFoundError();
                }
            });
            stackPanel.Children.Add(changePathBTN);

            var factoryResetBTN = new Button();

            factoryResetBTN.Margin  = new Thickness(0, 10, 0, 10);
            factoryResetBTN.Content = Resources.FactoryReset;
            factoryResetBTN.Command = new DelegateCommand(async() =>
            {
                var passwordHash = await App.Repository.Password.GetAsync();
                //delete password in the secret vault
                SecretService.Helper.RemoveSecret(Constants.ContainerName, passwordHash.Hash);
                // reset data and restart app
                await ApplicationData.Current.ClearAsync();
                await CoreApplication.RequestRestartAsync("Factory reset");
            });
            stackPanel.Children.Add(factoryResetBTN);

            dialog.Content              = stackPanel;
            dialog.PrimaryButtonText    = Resources.CloseApp;
            dialog.PrimaryButtonStyle   = App.Current.Resources["AccentButtonStyle"] as Style;
            dialog.PrimaryButtonCommand = new DelegateCommand(() =>
            {
                Prism.PrismApplicationBase.Current.Exit();
            });

            async void Dialog_Closed(ContentDialog sender, ContentDialogClosedEventArgs args)
            {
                if (!(Window.Current.Content is ShellPage))
                {
                    Prism.PrismApplicationBase.Current.Exit();
                }
                else
                {
                    if (!selectedOption)
                    {
                        await dialogService.ShowAsync(dialog);
                    }
                }
            }

            await dialogService.ShowAsync(dialog);
        }
コード例 #11
0
ファイル: DataService.cs プロジェクト: 2fast-team/2fast
        /// <summary>
        /// Checks and reads the current local datafile
        /// </summary>
        /// <param name="dbDatafile"></param>
        private async void CheckLocalDatafile(DBDatafileModel dbDatafile)
        {
            try
            {
                ObservableCollection <TwoFACodeModel> deserializeCollection = new ObservableCollection <TwoFACodeModel>();

                StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(dbDatafile.Path);

                if (await FileService.FileExistsAsync(dbDatafile.Name, folder))
                {
                    var dbHash = await App.Repository.Password.GetAsync();

                    // prevent write of the datafile
                    _initialization = true;
                    try
                    {
                        string datafileStr = await FileService.ReadStringAsync(dbDatafile.Name, folder);

                        if (!string.IsNullOrEmpty(datafileStr))
                        {
                            // read the iv for AES
                            DatafileModel datafile = NewtonsoftJSONService.Deserialize <DatafileModel>(datafileStr);
                            var           iv       = datafile.IV;

                            datafile = NewtonsoftJSONService.DeserializeDecrypt <DatafileModel>(
                                SecretService.Helper.ReadSecret(Constants.ContainerName, dbHash.Hash),
                                iv,
                                datafileStr);
                            deserializeCollection = datafile.Collection;
                        }
                    }
                    catch (Exception)
                    {
                        ShowPasswordError();
                    }
                }
                // file not found case
                else
                {
                    ShowFileOrFolderNotFoundError();
                }

                if (deserializeCollection != null)
                {
                    Collection.AddRange(deserializeCollection);
                    if (Collection.Count == 0)
                    {
                        // if no error has occured
                        if (!_errorOccurred)
                        {
                            EmptyAccountCollectionTipIsOpen = true;
                        }
                    }
                    else
                    {
                        if (EmptyAccountCollectionTipIsOpen)
                        {
                            EmptyAccountCollectionTipIsOpen = false;
                        }
                    }
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception exc)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                if (exc is UnauthorizedAccessException)
                {
                    ShowUnauthorizedAccessError();
                }
                else if (exc is FileNotFoundException)
                {
                    ShowFileOrFolderNotFoundError();
                }
                else
                {
                    _errorOccurred = true;
                    TrackingManager.TrackException(exc);
                    ErrorDialogs.ShowUnexpectedError(exc);
                }
            }
            // writing the data file is activated again
            _initialization = false;
        }
コード例 #12
0
 private void CheckUnhandledExceptionLastSession()
 {
     ErrorDialogs.ShowUnexpectedError(SettingsService.Instance.UnhandledExceptionStr);
 }