Exemple #1
0
        private bool OpenModelDatabase(string sqliteFilePath)
        {
            bool successful = true;

            try
            {
                Cursor.Current = Cursors.WaitCursor;

                // Close if open
                CloseModelDatabase();


                DataSource = new IdahoDataSource();
                DataSource.SetConnectionProperty(ConnectionProperty.FileName, sqliteFilePath);
                DataSource.SetConnectionProperty(ConnectionProperty.ConnectionType, ConnectionType.Sqlite);
                DataSource.SetConnectionProperty(ConnectionProperty.EnableSchemaUpdate, false);

                DataSource.Open();
                DomainDataSet = DataSource.DomainDataSetManager.DomainDataSet(1);

                Console.WriteLine($"Hydraulic model database got opened. Path: {sqliteFilePath}");

                // Now the model is open do what you need to do
                ModelOpened();
            }
            catch (System.Runtime.InteropServices.SEHException sehEx)
            {
                successful = false;
                string message =
                    "Exception occurred while opening up the model.\n May be you are trying to open a model from a directory where _ADMIN_ right is required to edit files?. \n\n";

                Console.WriteLine($"Exception: {message}");
                Console.WriteLine($"Destails: {sehEx.ToString()}");
            }
            catch (BadImageFormatException badImageEx)
            {
                successful = false;
                string message =
                    "Exception occurred while opening up the model. It appears 32/64 bit version conflict occurred. \n\n";

                Console.WriteLine($"Exception: {message}");
                Console.WriteLine($"Destails: {badImageEx.ToString()}");
            }
            catch (Exception ex)
            {
                successful = false;
                Console.WriteLine($"Destails: {ex.ToString()}");
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }

            return(successful);
        }
Exemple #2
0
        public bool Open(string sqliteFilePath, IProgressMessage progress)
        {
            bool successful = true;

            Progress = progress;


            try
            {
                Cursor.Current = Cursors.WaitCursor;

                // Close if any
                Close();


                DataSource = new IdahoDataSource();
                DataSource.SetConnectionProperty(ConnectionProperty.FileName, sqliteFilePath);
                DataSource.SetConnectionProperty(ConnectionProperty.ConnectionType, ConnectionType.Sqlite);
                DataSource.SetConnectionProperty(ConnectionProperty.EnableSchemaUpdate, false);

                DataSource.Open();
                DomainDataSet = DataSource.DomainDataSetManager.DomainDataSet(1);

                progress.Message = $"Hydraulic model database got opened. Path: {sqliteFilePath}";
            }
            catch (System.Runtime.InteropServices.SEHException sehEx)
            {
                successful = false;
                string message =
                    "Exception occurred while opening up the model.\n May be you are trying to open a model from a directory where _ADMIN_ right is required to edit files?. \n\n";

                WriteException(sehEx, message);
            }
            catch (BadImageFormatException badImageEx)
            {
                successful = false;
                string message =
                    "Exception occurred while opening up the model. It appears 32/64 bit version conflict occurred. \n\n";

                WriteException(badImageEx, message);
            }
            catch (Exception ex)
            {
                successful = false;
                WriteException(ex, "");
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }


            return(successful);
        }