Esempio n. 1
0
        public void SaveAs(String fileName)
        {
            var fullPath = Path.GetFullPath(fileName);

            if (File.Exists(fullPath) &&
                (File.GetAttributes(fullPath) & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
            {
                ActiveView.ShowMessage("This file is read only.");
            }
            else
            {
                //if file path is the same as our current path, skip creating new file and just save
                if (String.Compare(
                        Path.GetFullPath(Database.Path),
                        fullPath,
                        StringComparison.InvariantCultureIgnoreCase) != 0)
                {
                    Database.CopyAs(fileName, true);
                }

                //save after copying
                this.Save();
                AppState.AddRecentFile(fullPath);
                this.MainWindow.Text = System.IO.Path.GetFileName(this.Database.Path);
            }
        }
Esempio n. 2
0
        protected void OnDatabaseChanged()
        {
            Analytics.TrackEvent(nameof(OnDatabaseChanged));

            var database = Database;
            var filePath = database.Path;

            if (database.CruiseFileType.HasFlag(CruiseFileType.Cruise))
            {
                String directroy = System.IO.Path.GetDirectoryName(filePath);
                UserSettings.CruiseSaveLocation = directroy;

                var fixMismatchSp = new FixMismatchSpeciesScript();
                if (fixMismatchSp.CheckCanExecute(database))
                {
                    fixMismatchSp.Execute(database);
                }

                if (DatabaseValidator.HasCruiseErrors(database, out var errors))
                {
                    var errorMessage = String.Join("\r\n", errors);
                    var errorData    = new Dictionary <string, string>()
                    {
                        { "errorMessage", errorMessage }
                    };

                    try
                    {
                        if (database.HasForeignKeyErrors())
                        {
                            var fkc = String.Join(",", database.QueryGeneric("PRAGMA foreign_key_check")
                                                  .Select(x => "{\r\n" + x.ToString() + "}")
                                                  .ToArray());
                            errorData.Add("foreign_key_check", fkc);
                        }
                    }
                    catch { }

                    Crashes.TrackError(new Exception("Cruise_Errors"), errorData);
                    //Analytics.TrackEvent("Cruise_Errors", errorData);

                    this.ActiveView.ShowMessage(errorMessage, null);
                }

                WindowPresenter.ShowCruiseLandingLayout();
            }
            else if (database.CruiseFileType.HasFlag(CruiseFileType.Template))
            {
                String directroy = System.IO.Path.GetDirectoryName(filePath);
                UserSettings.TemplateSaveLocation = directroy;
                WindowPresenter.ShowTemplateLandingLayout();
            }

            AppState.AddRecentFile(filePath);
            SaveCommand.Enabled = this.SaveAsCommand.Enabled = (database != null);
        }