Example #1
0
        public bool GoodDatabaseInstance(string SQLSrvrInstance, IntPtr WindowHandle)
        {
            ServerConnection SQLSrvrConnection = new ServerConnection(SQLSrvrInstance);

            SQLSrvrConnection.ServerInstance = SQLSrvrInstance;

            // Setup capture and execute to be able to display script
            SQLSrvrConnection.SqlExecutionModes = SqlExecutionModes.ExecuteAndCaptureSql;

            // Use Windows authentication
            SQLSrvrConnection.LoginSecure = true;

            // Go ahead and connect
            try
            {
                SQLSrvrConnection.Connect();
            }
            catch (Exception ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox();
                emb.Message = ex;
                emb.Show(new WindowWrapper(WindowHandle));
                return(false);
            }

            bool Connected = SQLSrvrConnection.InUse;

            SQLSrvrConnection.Disconnect();
            return(Connected);
        }
Example #2
0
        private void ConnectButton_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                sqlServer = new GeneralSqlServer(defaultDatabase);

                sqlServer.Connect(sqlConfig.ServerName);

                this.FillDatabases();

                OptionsButton.Enabled = true;

                this.HideConnectPanel(sqlServer.Server.Name);

                CancelButton.Enabled = true;
                OnConnected(new EventArgs());
            }
            catch (Exception ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Example #3
0
        private void   更新并初始化数据UToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                Synchronize syncSub = new Synchronize();

                // Disable the current form
                this.Enabled = false;

                syncSub.Show(this);

                syncSub.ReinitializeSubscriptionWithUpload();
            }
            catch (Exception ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex,
                                                                  ExceptionMessageBoxButtons.OK);
                emb.Show(this);
            }
            finally
            {
                loadLastAgentSessionSummary();
                // Enable the current form
                this.Enabled = true;
            }
        }
Example #4
0
        private void 只上传数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                Synchronize syncSub = new Synchronize();

                // Disable the current form
                this.Enabled = false;

                syncSub.Show(this);

                syncSub.SynchronizeSubscriptionUploadOnly();
                syncWhenConnectedStatus.Visible = false;
            }
            catch (Exception ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex,
                                                                  ExceptionMessageBoxButtons.OK);
                emb.Show(this);
            }
            finally
            {
                // Enable the current form
                this.Enabled = true;
            }
        }
        public static ExceptionMessageBoxDialogResult ShowExceptionMessageBox(IWin32Window owner, Exception ex)
        {
            //try
            //{

            ExceptionMessageBoxDialogResult exceptionMessageBoxDialogResult;

            CustomException customEx = ex as CustomException;
            if (customEx != null)
            {
                CustomExceptionMessageBox customExceptionMessageBox = new CustomExceptionMessageBox(customEx);
                exceptionMessageBoxDialogResult = (ExceptionMessageBoxDialogResult)customExceptionMessageBox.ShowDialog(owner);
            }
            else
            {
                System.Data.Common.DbException dbException = ex as System.Data.Common.DbException;
                if (dbException != null && dbException.ErrorCode == -2146232060)
                    ex = new Exception("Không thể lưu do trùng dữ liệu. Vui lòng kiểm tra lại.");


                ExceptionMessageBox exceptionMessageBox = new ExceptionMessageBox(ex); //exceptionMessageBox.ShowToolBar = false;
                exceptionMessageBoxDialogResult = (ExceptionMessageBoxDialogResult)exceptionMessageBox.Show(owner);
            }
            return exceptionMessageBoxDialogResult;
            //}
            //catch {}// Environment.Exit(0); return ExceptionMessageBoxDialogResult.None; }
        }
 public virtual void StartWatching()
 {
     try
     {
         _log.Debug(string.Format("Started watching build status, poling interval: {0} seconds", Settings.PollInterval));
         while (true)
         {
             GetBuildStatusAndFireEvents();
             Thread.Sleep(Settings.PollInterval * 1000);
         }
     }
     catch (ThreadAbortException)
     {
         _log.Debug("Stopped watching build status (ThreadAbortException)");
         StopWatching();
         OnStoppedWatching();
     }
     catch (TaskCanceledException)
     {
         _log.Debug("Stopped watching build status (TaskCanceledException)");
         StopWatching();
         OnStoppedWatching();
     }
     catch (Exception ex)
     {
         _log.Error("uncaught exception in watcher", ex);
         StopWatching();
         ExceptionMessageBox.Show(null, "Drat", "Error connecting to server", ex);
     }
 }
Example #7
0
        /// <summary>
        /// Select the second object to compare.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void objectBrowse2Button_Click(object sender, EventArgs e)
        {
            if (serverTextBox2.Text == null || serverTextBox2.Text.Length == 0)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox();
                emb.Text = Properties.Resources.SecondServerMustBeSpecified;
                emb.Show(this);

                return;
            }

            if (serverChanged2)
            {
                this.serverConn2 = new ServerConnection(this.serverTextBox2.Text);
                this.serverConn2.NonPooledConnection = false;
                this.serverConn2.LoginSecure         = loginTextBox2.Text.Trim().Length
                                                       == 0 ? true : false;
                if (!this.serverConn2.LoginSecure)
                {
                    this.serverConn2.Login    = loginTextBox2.Text;
                    this.serverConn2.Password = passwordTextBox2.Text;
                }

                serverChanged2 = false;
            }

            this.objectBrowser = new SqlObjectBrowser(this.serverConn2);
            if (this.objectBrowser.Connected == true)
            {
                if (DialogResult.OK == this.objectBrowser.ShowDialog(this))
                {
                    this.urnTextBox2.Text = this.objectBrowser.Urn;
                }
            }
        }
Example #8
0
        private void ShowDatabases(bool selectDefault)
        {
            // Show the current databases on the server
            try
            {
                // Clear control
                DatabasesComboBox.Items.Clear();

                // Limit the properties returned to just those that we use
                SqlServerSelection.SetDefaultInitFields(typeof(Database),
                                                        new String[] { "Name", "IsSystemObject", "IsAccessible" });

                // Add database objects to combobox; the default ToString
                // will display the database name
                foreach (Database db in SqlServerSelection.Databases)
                {
                    if (db.IsSystemObject == false && db.IsAccessible == true)
                    {
                        DatabasesComboBox.Items.Add(db);
                    }
                }

                if ((selectDefault == true) &&
                    (DatabasesComboBox.Items.Count > 0))
                {
                    DatabasesComboBox.SelectedIndex = 0;
                }
            }
            catch (SmoException ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }
        }
 public override void Generate(string wszInputFilePath,
                               string bstrInputFileContents,
                               string wszDefaultNamespace,
                               out IntPtr rgbOutputFileContents,
                               out int pcbOutput,
                               IVsGeneratorProgress pGenerateProgress)
 {
     try
     {
         byte[] data = CodeGeneratorCustomTool.GenerateUnitTestCode(wszDefaultNamespace, wszInputFilePath);
         if (data == null)
         {
             rgbOutputFileContents = IntPtr.Zero;
             pcbOutput             = 0;
         }
         else
         {
             rgbOutputFileContents = Marshal.AllocCoTaskMem(data.Length);
             Marshal.Copy(data, 0, rgbOutputFileContents, data.Length);
             pcbOutput = data.Length;
         }
     }
     catch (Exception e)
     {
         var applicationException = new ApplicationException("Unable to generate code", e);
         var messageBox           = new ExceptionMessageBox(applicationException);
         messageBox.Show(null);
         throw;
     }
 }
Example #10
0
        private void GetServerList()
        {
            DataTable dt;

            // Set local server as default
            dt = SmoApplication.EnumAvailableSqlServers(false);
            if (dt.Rows.Count > 0)
            {
                // Load server names into combo box
                foreach (DataRow dr in dt.Rows)
                {
                    ServerNamesComboBox.Items.Add(dr["Name"]);
                }

                // Default to this machine
                ServerNamesComboBox.SelectedIndex
                    = ServerNamesComboBox.FindStringExact(
                          System.Environment.MachineName);

                // If this machine is not a SQL server
                // then select the first server in the list
                if (ServerNamesComboBox.SelectedIndex < 0)
                {
                    ServerNamesComboBox.SelectedIndex = 0;
                }
            }
            else
            {
                ExceptionMessageBox emb = new ExceptionMessageBox();
                emb.Text = Properties.Resources.NoSqlServers;
                emb.Show(this);
            }
        }
Example #11
0
        public SqlObjectBrowser(ServerConnection serverConn)
        {
            InitializeComponent();

            // Connect to SQL Server
            server = new Server(serverConn);
            try
            {
                server.ConnectionContext.Connect();

                // In case connection succeeded we add the sql server node as root in object explorer (treeview)
                TreeNode tn = new TreeNode();
                tn.Text     = server.Name;
                tn.Tag      = server.Urn;
                this.objUrn = server.Urn;
                objectBrowserTreeView.Nodes.Add(tn);

                AddDummyNode(tn);

                connected = true;
            }
            catch (ConnectionException)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox();
                emb.Text = Properties.Resources.ConnectionFailed;
                emb.Show(this);
            }
            catch (ApplicationException ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }
        }
Example #12
0
        private void ListDatabaseSpace()
        {
            try
            {
                this.dataGridView1.Rows.Clear();

                foreach (Database db in SqlServerSelection.Databases)
                {
                    if (db.IsSystemObject == false)
                    {
                        if (db.LogFiles.Count > 0)
                        {
                            this.dataGridView1.Rows.Add(new object[] { db.Name,
                                                                       db.Size, db.SpaceAvailable / 1024.0,
                                                                       db.LogFiles[0].Size / 1024.0,
                                                                       db.LogFiles[0].UsedSpace / 1024.0 });
                        }
                        else
                        {
                            this.dataGridView1.Rows.Add(new object[] { db.Name,
                                                                       db.Size, db.SpaceAvailable / 1024.0,
                                                                       0.0, 0.0 });
                        }
                    }
                }
            }
            catch (SmoException ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }
        }
Example #13
0
 private void UpgradeThread()
 {
     try
     {
         byte[] hexFileData = File.ReadAllBytes(_firmwareFile.Text);
         using (var hexFileStream = new MemoryStream(hexFileData))
         {
             SetStatus("Waiting for device to connect.");
             Program.SirenOfShameDevice.PerformFirmwareUpgrade(hexFileStream, UpdateProgress);
             SetStatus("Upgrade complete.");
             if (_onInstallFirmwareSuccess != null)
             {
                 this.Invoke(() => _onInstallFirmwareSuccess());
             }
         }
     }
     catch (Exception ex)
     {
         Log.Error("Error performing upgrade", ex);
         SetStatus("Error installing firmware");
         ExceptionMessageBox.Show(this, "Error Performing Upgrade", "Error Performing Upgrade", ex);
     }
     finally
     {
         this.Invoke(() =>
         {
             _begin.Enabled = true;
         });
     }
 }
Example #14
0
        private void objectBrowserTreeView_AfterExpand(object sender, TreeViewEventArgs e)
        {
            // Remove dummy node
            e.Node.Nodes.RemoveAt(0);
            SqlSmoObject smoObj  = null;
            Urn          urnNode = (Urn)e.Node.Tag;

            try
            {
                smoObj = server.GetSmoObject(urnNode);
                AddCollections(e, smoObj);
            }
            catch (UnsupportedVersionException)
            {
                // Right now don't do anything... but you might change the
                // Icon so it will emphasize the version issue
            }
            catch (SmoException)
            {
                try
                {
                    AddItemInCollection(e, server);
                }
                catch (Exception except)
                {
                    ExceptionMessageBox emb = new ExceptionMessageBox(except);
                    emb.Show(this);
                }
            }
            catch (ApplicationException ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }
        }
        public void OpenPort(string strCom)
        {
            _serialPort = new SerialPort(strCom, 19200, Parity.None, 8, StopBits.Two);
            try
            {
                _serialPort.Open();
                _serialPort.RtsEnable = false;

                _serialPort.DataReceived += OnDataReceived;
                //serialPort.ErrorReceived += new SerialErrorReceivedEventHandler(OnErrorReceived);
                //serialPort.PinChanged += new SerialPinChangedEventHandler(OnSerialPinChanged);

                var buffer = new byte[1];

                buffer[0] = 0x55;
                if (_serialPort.IsOpen)
                {
                    _serialPort.Write(buffer, 0, buffer.Length);
                }

                Thread.Sleep(100);
                buffer[0] = 0xAA;
                if (_serialPort.IsOpen)
                {
                    _serialPort.Write(buffer, 0, buffer.Length);
                }
                Thread.Sleep(500);
            }
            catch (Exception e)
            {
                ExceptionMessageBox.Show(e);
            }
        }
Example #16
0
        public void EditTag(string filename)
        {
            Mp3File mp3File = null;

            try
            {
                // create mp3 file wrapper; open it and read the tags
                mp3File = new Mp3File(filename);
            }
            catch (Exception e)
            {
                ExceptionMessageBox.Show(_form, e, "Error Reading Tag");
                return;
            }

            // create dialog and give it the ID3v2 block for editing
            // this is a bit sneaky; it uses the edit dialog straight out of TagScanner.exe as if it was a dll.
            TagEditor.ID3AdapterEdit id3Edit = new TagEditor.ID3AdapterEdit(mp3File);

            if (id3Edit.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    using (new CursorKeeper(Cursors.WaitCursor))
                    {
                        mp3File.Update();
                    }
                }
                catch (Exception e)
                {
                    ExceptionMessageBox.Show(_form, e, "Error Writing Tag");
                }
            }
        }
Example #17
0
        private void GetServices()
        {
            Cursor          csr = null;
            ManagedComputer mc;
            ListViewItem    ServiceListViewItem;

            try
            {
                csr         = this.Cursor;        // Save the old cursor
                this.Cursor = Cursors.WaitCursor; // Display the waiting cursor

                // Clear control
                ServicesListView.Items.Clear();
                mc = new ManagedComputer(SqlServerSelection.Name);

                foreach (Service svc in mc.Services)
                {
                    ServiceListViewItem = ServicesListView.Items.Add(svc.Name);
                    ServiceListViewItem.SubItems.Add(svc.DisplayName);
                    ServiceListViewItem.SubItems.Add(svc.ServiceState.ToString());
                    ServiceListViewItem.SubItems.Add(svc.StartMode.ToString());
                    ServiceListViewItem.SubItems.Add(svc.ServiceAccount);
                    ServiceListViewItem.SubItems.Add(svc.State.ToString());
                }
            }
            catch (SmoException ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }
            finally
            {
                this.Cursor = csr;  // Restore the original cursor
            }
        }
Example #18
0
        private static void HandleException(object sender, bool isTerminating, Exception exception)
        {
            ExceptionMessageBox emb = new ExceptionMessageBox(exception, ExceptionMessageBoxButtons.OK, ExceptionMessageBoxSymbol.Error);

            emb.Caption = "Unhandled Exception";
            emb.Show(Program._form);
        }
Example #19
0
        public void ShowExceptionMessage()
        {
            try
            {
                // Do something that you don't expect to generate an exception.
                throw new ApplicationException(ExceptionMessage);
            }
            catch (ApplicationException ex)
            {
                // Define a new top-level error message.
                string str = "An Error has ocurred in while logging the Exception Information on System. " + Environment.NewLine
                             + "Please contact support";

                // Add the new top-level message to the handled exception.
                ApplicationException exTop = new ApplicationException(str, ex);
                ExceptionMessageBox box = new ExceptionMessageBox(exTop);
                box.Buttons = ExceptionMessageBoxButtons.OK;
                box.Caption = title;
                box.ShowCheckBox = false;
                box.ShowToolBar = true;
                box.Symbol = ExceptionMessageBoxSymbol.Stop;
                box.Show(this);
                this.Close();
            }
        }
Example #20
0
        public SqlObjectBrowser(ServerConnection serverConn)
        {
            InitializeComponent();

            // Connect to SQL Server
            server = new Server(serverConn);
            try
            {
                server.ConnectionContext.Connect();

                // In case connection succeeded we add the sql server node as root in object explorer (treeview)
                TreeNode tn = new TreeNode();
                tn.Text = server.Name;
                tn.Tag = server.Urn;
                this.objUrn = server.Urn;
                objectBrowserTreeView.Nodes.Add(tn);

                AddDummyNode(tn);

                connected = true;
            }
            catch (ConnectionException)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox();
                emb.Text = Properties.Resources.ConnectionFailed;
                emb.Show(this);
            }
            catch (ApplicationException ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }
        }
Example #21
0
        public static ExceptionMessageBoxDialogResult ShowExceptionMessageBox(IWin32Window owner, Exception ex)
        {
            //try
            //{

            ExceptionMessageBoxDialogResult exceptionMessageBoxDialogResult;

            CustomException customEx = ex as CustomException;

            if (customEx != null)
            {
                CustomExceptionMessageBox customExceptionMessageBox = new CustomExceptionMessageBox(customEx);
                exceptionMessageBoxDialogResult = (ExceptionMessageBoxDialogResult)customExceptionMessageBox.ShowDialog(owner);
            }
            else
            {
                ExceptionMessageBox exceptionMessageBox = new ExceptionMessageBox(ex); //exceptionMessageBox.ShowToolBar = false;
                exceptionMessageBoxDialogResult = (ExceptionMessageBoxDialogResult)exceptionMessageBox.Show(owner);
            }


            return(exceptionMessageBoxDialogResult);
            //}
            //catch {}// Environment.Exit(0); return ExceptionMessageBoxDialogResult.None; }
        }
Example #22
0
        private IConfiguration NewObject(string classType, string caption, int height)
        {
            EditObject     obj;
            IConfiguration config = null;

            try
            {
                ConfigurationPanel.EditObjectButton.Text = caption;

                Assembly a = Assembly.GetAssembly(this.GetType());

                object[] args = new object[1];
                args[0] = SqlConnectionControl.ServiceBroker;
                //Create a new instance of class type stored in classType.
                config = (IConfiguration)a.CreateInstance
                             (classType, true, BindingFlags.CreateInstance, null, args,
                             System.Globalization.CultureInfo.CurrentCulture, null);

                obj = ConfigurationPanel.AddObject("(New)", config);
                obj.Expand(height);
                obj.ButtonVisible = false;
            }
            catch (Exception ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }

            return(config);
        }
        private void LoadButton_Click(object sender, RoutedEventArgs e)
        {
            this.IsEnabled = false;

            WebClient webClient = new WebClient();

            webClient.DownloadStringCompleted += WebClient_DownloadStringCompleted;

            try
            {
                Uri uri = new Uri(URLTextBox.Text);

                webClient.DownloadStringAsync(uri);
            }
            catch (UriFormatException uriFormatEx)
            {
                ExceptionMessageBox.Show(this.Title, "The format of the URL " +
                                         $"{Environment.NewLine}{Environment.NewLine}{URLTextBox.Text}{Environment.NewLine}{Environment.NewLine}" +
                                         " is not correct.", uriFormatEx);
            }
            catch (Exception ex)
            {
                ExceptionMessageBox.Show(this.Title, "The following error occurred:", ex);
            }
            finally
            {
                webClient.Dispose();

                this.IsEnabled = true;
            }
        }
Example #24
0
        public static void LoadRegexJob(String path)
        {
            TaskWindow taskWindow = new TaskWindow
                                    (
                delegate(Object argument)
            {
                return(RegexHelper.Match(AppState.Current.Input));
            },
                path
                                    )
            {
                Owner = App.MainWindow
            };

            taskWindow.ShowDialog();

            if (taskWindow.Exception == null)
            {
                RegexInput regexInput = taskWindow.Result as RegexInput;

                if (regexInput != null)
                {
                    AppState.Current.Input = regexInput;
                    AppState.Current.Update(path);
                }
            }
            else
            {
                ExceptionMessageBox.Show(App.MainWindow, App.Metadata.AssemblyTitle,
                                         "Invalid job file format.", taskWindow.Exception.InnerException);
            }
        }
Example #25
0
        public static void SaveRegexJob(String path)
        {
            TaskWindow taskWindow = new TaskWindow
                                    (
                delegate(Object argument)
            {
                FileHelper.SaveRegexInput(argument.ToString(), AppState.Current.Input);

                return(null);
            },
                path
                                    )
            {
                Owner = App.MainWindow
            };

            taskWindow.ShowDialog();

            if (taskWindow.Exception == null)
            {
                AppState.Current.Update(path);
            }
            else
            {
                ExceptionMessageBox.Show(App.MainWindow, App.Metadata.AssemblyTitle,
                                         "Unexpected exception happened.", taskWindow.Exception.InnerException);
            }
        }
Example #26
0
        /// <summary>
        /// Used to create a custom app exception dialog.
        /// </summary>
        /// <param name="sender"><see cref="Form1.cmdApplicationExceptionDialog_Click"/>Calling form</param>
        /// <param name="ex">ApplicationException instance</param>
        /// <param name="title">Title for dialog</param>
        /// <returns>ExceptionMessageBoxDialogResult</returns>
        /// <remarks>
        /// https://docs.microsoft.com/en-us/dotnet/api/microsoft.sqlserver.messagebox.exceptionmessagebox?view=sqlserver-2016
        /// </remarks>
        public static ExceptionMessageBoxDialogResult AppExceptionDialog(Form sender, ApplicationException ex, string title = "Action failed. What do you want to do?")
        {
            var applicationException = new ApplicationException(title, ex)
            {
                Source = "Source"
            };

            // Show the exception message box with three custom buttons.
            var box = new ExceptionMessageBox(applicationException)
            {
                Caption = "Karen's great application"
            };

            // set the window caption/title

            // Set the names of the three custom buttons.
            box.SetButtonText("Skip", "Retry", "Stop Processing");

            // Set the Retry button as the default.
            box.DefaultButton = ExceptionMessageBoxDefaultButton.Button2;
            box.Symbol        = ExceptionMessageBoxSymbol.Question;
            box.Buttons       = ExceptionMessageBoxButtons.Custom;

            box.Show(sender);
            return(box.CustomDialogResult);
        }
Example #27
0
        private void DependenciesTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            SqlSmoObject smoObject;
            Urn          urn;
            ListViewItem item;
            Cursor       csr = null;

            try
            {
                csr         = this.Cursor;        // Save the old cursor
                this.Cursor = Cursors.WaitCursor; // Display the waiting cursor

                // Get the Urn from the selected node
                urn = (Urn)(e.Node.Tag);

                // Clear the list
                this.PropertiesListView.Items.Clear();

                // No Urn : we cannot display
                if (urn == null)
                {
                    return;
                }

                // Instantiate the SMO object using the Urn
                smoObject = server.GetSmoObject(urn);

                // Initialize its properties
                smoObject.Initialize(true);

                // Now print each retrieved property in the ListView
                foreach (Property prop in smoObject.Properties)
                {
                    if (prop.Retrieved == true)
                    {
                        item = new ListViewItem(prop.Name);
                        if (prop.Value != null)
                        {
                            item.SubItems.Add(prop.Value.ToString());
                        }

                        this.PropertiesListView.Items.Add(item);
                    }
                }

                // Size it
                this.PropertiesListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
            }
            catch (SmoException ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }
            finally
            {
                // Restore the original cursor
                this.Cursor = csr;
            }
        }
Example #28
0
        static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var form = new ExceptionMessageBox(e.ExceptionObject as Exception);

            form.Caption = "Unexpected Error";
            form.Text    = "An unexpected error has occurred";
            form.Show(null);
        }
Example #29
0
        private void OnStatementExecuted(object sender,
                                         StatementEventArgs args)
        {
            ExceptionMessageBox emb = new ExceptionMessageBox();

            emb.Text = args.SqlStatement;
            emb.Show(this);
        }
Example #30
0
        private void mnuTellMeMore_Click(object sender, EventArgs e)
        {
            ExceptionMessageBox emb = new ExceptionMessageBox(
                Properties.Resources.TellMeMoreWebSync);

            emb.Symbol = ExceptionMessageBoxSymbol.Information;
            emb.Show(this);
        }
Example #31
0
        private void RefreshTables()
        {
            Cursor   csr = null;
            Database database;

            try
            {
                csr         = this.Cursor;        // Save the old cursor
                this.Cursor = Cursors.WaitCursor; // Display the waiting cursor

                this.TableListView.BeginUpdate();

                // Clear the list
                this.TableListView.Items.Clear();

                // Get selected database from DatabaseComboBox
                database = (Database)(this.DatabasesComboBox.SelectedItem);

                // Set default initial fields for table
                database.Parent.SetDefaultInitFields(typeof(Table),
                                                     "Name", "CreateDate", "RowCount", "DataSpaceUsed",
                                                     "IsSystemObject");

                // Get the updated list of tables
                database.Tables.Refresh();

                // Iterate user Tables and add to ListView Using AddTableItem
                foreach (Table tbl in database.Tables)
                {
                    if (tbl.IsSystemObject == false)
                    {
                        this.AddTableItem(tbl);
                    }
                }

                // Resize columns
                this.TableListView.AutoResizeColumns(
                    ColumnHeaderAutoResizeStyle.ColumnContent);

                // Select the first item
                if (this.TableListView.Items.Count > 0)
                {
                    this.TableListView.Items[0].Selected = true;
                }
            }
            catch (SmoException ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }
            finally
            {
                this.TableListView.EndUpdate();

                // Restore the original cursor
                this.Cursor = csr;
            }
        }
Example #32
0
        private void ConnectToServer(string server)
        {
            try
            {
                Server srvr = new Server(server);
                srvr.ConnectionContext.ConnectTimeout = 5;
                srvr.ConnectionContext.Connect();
                this.sqlServerSelection = srvr;
            }
            catch (ConnectionFailureException ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);

                Cursor = Cursors.Default;
                this.sqlServerSelection = null;
            }

            this.serverVersionToolStripStatusLabel.Text
                = this.sqlServerSelection.Information.Version.ToString()
                + " " + this.sqlServerSelection.Information.Edition;
            this.SqlServerTreeView.Nodes.Clear();

            // Add Server node
            TreeNode node = new TreeNode(this.sqlServerSelection.ConnectionContext.TrueName);
            node.Name = Properties.Resources.Server;
            root = node;
            node.Tag = this.sqlServerSelection;
            this.SqlServerTreeView.Nodes.Add(node);

            // Add Databases node
            node = new TreeNode(Properties.Resources.Databases);
            node.Name = Properties.Resources.Databases;
            node.Tag = this.sqlServerSelection.Databases;
            root.Nodes.Add(node);
            AddDummyNode(node);

            this.SqlServerTreeView.SelectedNode = root;

            // Optimizing code
            this.sqlServerSelection.SetDefaultInitFields(typeof(Database),
                "CreateDate", "IsSystemObject", "CompatibilityLevel");
            this.sqlServerSelection.SetDefaultInitFields(typeof(Table),
                "CreateDate", "IsSystemObject");
            this.sqlServerSelection.SetDefaultInitFields(typeof(Microsoft.SqlServer.Management.Smo.View),
                "CreateDate", "IsSystemObject");
            this.sqlServerSelection.SetDefaultInitFields(typeof(StoredProcedure),
                "CreateDate", "IsSystemObject");
            this.sqlServerSelection.SetDefaultInitFields(typeof(Column), true);
        }
Example #33
0
 private void runButton_Click(object sender, EventArgs e)
 {
     // Perform run on the connection         
     // Connect to SQL Server
     Server server = new Server(serverConn);
     try
     {
         server.ConnectionContext.ExecuteNonQuery(collScript, ExecutionTypes.ContinueOnError);
     }
     catch (SmoException ex)
     {
         ExceptionMessageBox emb = new ExceptionMessageBox(ex);
         emb.Show(this);
     }
 }
Example #34
0
        private void CreateStripButton_Click(object sender, EventArgs e)
        {
            if (this.ActiveEditObject != null)
            {
                try
                {
                    this.ActiveEditObject.Configuration.Create();
                    this.outputTextBox.Text = this.ActiveEditObject.Configuration.SqlScript;

                    this.SetStripButtonState(ObjectsSplitPanel.operations.Show);
                }
                catch (Exception ex)
                {
                    ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                    emb.Show(this);
                }
            }
        }
Example #35
0
        private void AlterStripButton_Click(object sender, EventArgs e)
        {
            if (this.ActiveEditObject != null)
            {
                try
                {
                    this.ActiveEditObject.Configuration.Alter();

                    this.outputTextBox.Text = this.ActiveEditObject.Configuration.SqlScript;
                    this.outputDataGridView.AutoGenerateColumns = true;

                }
                catch (Exception ex)
                {
                    ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                    emb.Show(this);
                }
            }
        }
Example #36
0
 private void mnuTellMeMore_Click(object sender, EventArgs e)
 {
     ExceptionMessageBox emb = new ExceptionMessageBox(
         Properties.Resources.TellMeMoreWebSync);
     emb.Symbol = ExceptionMessageBoxSymbol.Information;
     emb.Show(this);
 }
Example #37
0
        private void AddTableButton_Click(object sender, System.EventArgs e)
        {
            Database db;
            Table tbl;
            Column col;
            Index idx;
            Default dflt;
            Cursor csr = null;

            try
            {
                csr = this.Cursor;   // Save the old cursor
                this.Cursor = Cursors.WaitCursor;   // Display the waiting cursor

                // Show the current tables for the selected database
                db = (Database)DatabasesComboBox.SelectedItem;
                if (db.Tables.Contains(TableNameTextBox.Text) == false)
                {
                    // Create an empty string default
                    dflt = db.Defaults["dfltEmptyString"];
                    if (dflt == null)
                    {
                        dflt = new Default(db, "dfltEmptyString");
                        dflt.TextHeader = "CREATE DEFAULT [dbo].[dfltEmptyString] AS ";
                        dflt.TextBody = @"'';";
                        dflt.Create();
                    }

                    // Create a new table object
                    tbl = new Table(db,
                        TableNameTextBox.Text, db.DefaultSchema);

                    // Add the first column
                    col = new Column(tbl, @"Column1", DataType.Int);
                    tbl.Columns.Add(col);
                    col.Nullable = false;
                    col.Identity = true;
                    col.IdentitySeed = 1;
                    col.IdentityIncrement = 1;

                    // Add the primary key index
                    idx = new Index(tbl, @"PK_" + TableNameTextBox.Text);
                    tbl.Indexes.Add(idx);
                    idx.IndexedColumns.Add(new IndexedColumn(idx, col.Name));
                    idx.IsClustered = true;
                    idx.IsUnique = true;
                    idx.IndexKeyType = IndexKeyType.DriPrimaryKey;

                    // Add the second column
                    col = new Column(tbl, @"Column2", DataType.NVarChar(1024));
                    tbl.Columns.Add(col);
                    col.DataType.MaximumLength = 1024;
                    col.AddDefaultConstraint(null); // Use SQL Server default naming
                    col.DefaultConstraint.Text = Properties.Resources.DefaultConstraintText;
                    col.Nullable = false;

                    // Add the third column
                    col = new Column(tbl, @"Column3", DataType.DateTime);
                    tbl.Columns.Add(col);
                    col.Nullable = false;

                    // Create the table
                    tbl.Create();

                    // Refresh list and select the one we just created
                    ShowTables();

                    // Clear selected items
                    TablesComboBox.SelectedIndex = -1;

                    // Find the table just created
                    TablesComboBox.SelectedIndex = TablesComboBox.FindStringExact(tbl.ToString());
                }
                else
                {
                    ExceptionMessageBox emb = new ExceptionMessageBox();
                    emb.Text = string.Format(System.Globalization.CultureInfo.InvariantCulture,
                        Properties.Resources.TableExists, TableNameTextBox.Text);
                    emb.Show(this);
                }
            }
            catch (SmoException ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }
            finally
            {
                this.Cursor = csr;  // Restore the original cursor
            }
        }
Example #38
0
        private void RefreshService(Service svc)
        {
            // Update the service status field
            try
            {
                svc.Refresh();

                ListViewItem ServiceListViewItem;

                ServiceListViewItem = ServicesListView.SelectedItems[0];
                ServiceListViewItem.SubItems[2].Text = svc.ServiceState.ToString();
                UpdateButtons();
            }
            catch (SmoException ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }
        }
Example #39
0
        private void DisplayIndexSizes()
        {
            Database db;
            Cursor csr = null;

            try
            {
                csr = this.Cursor;   // Save the old cursor
                this.Cursor = Cursors.WaitCursor;   // Display the waiting cursor

                db = (Database)DatabasesComboBox.SelectedItem;

                this.dataGridView1.Rows.Clear();

                foreach (Table tbl in db.Tables)
                {
                    if (tbl.IsSystemObject == false)
                    {
                        foreach (Index idx in tbl.Indexes)
                        {
                            if (idx.IndexKeyType != IndexKeyType.None)
                            {
                                continue; // Only show indexes
                            }

                            this.dataGridView1.Rows.Add(new object[] { 
                                tbl.ToString(), idx.Name, idx.SpaceUsed });
                        }
                    }
                }
            }
            catch (SmoException ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }
            finally
            {
                this.Cursor = csr;  // Restore the original cursor
            }
        }
Example #40
0
        private void ConnectButton_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                sqlServer = new GeneralSqlServer(defaultDatabase);

                sqlServer.Connect(sqlConfig.ServerName);

                this.FillDatabases();

                OptionsButton.Enabled = true;

                this.HideConnectPanel(sqlServer.Server.Name);

                CancelButton.Enabled = true;
                OnConnected(new EventArgs());

            }
            catch (Exception ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }

        }
Example #41
0
        public void Draw(esriDrawPhase drawPhase, IDisplay display, ITrackCancel trackCancel)
        {
            switch (drawPhase)
            {
                case esriDrawPhase.esriDPGeography:
                    if (Valid)
                    {
                        if (Visible)
                        {
                            try
                            {
                                var clipEnvelope = display.ClipEnvelope;

                                // when loading from a file the active map doesn't exist yet
                                // so just deal with it here.
                                if (_map == null)
                                {
                                    var mxdoc = (IMxDocument)_application.Document;
                                    _map = mxdoc.FocusMap;
                                }

                                Debug.WriteLine("Draw event");
                                var activeView = _map as IActiveView;
                                Logger.Debug("Layer name: " + Name);

                                if (activeView != null)
                                {
                                    //_envelope = activeView.Extent;
                                    _envelope = clipEnvelope;

                                    Logger.Debug("Draw extent: xmin:" + _envelope.XMin +
                                                 ", ymin:" + _envelope.YMin +
                                                 ", xmax:" + _envelope.XMax +
                                                 ", ymax:" + _envelope.YMax
                                        );
                                    if (SpatialReference != null)
                                    {
                                        Logger.Debug("Layer spatial reference: " + SpatialReference.FactoryCode);
                                    }
                                    if (_map.SpatialReference != null)
                                    {
                                        Logger.Debug("Map spatial reference: " + _map.SpatialReference.FactoryCode);
                                    }

                                    var bruTileHelper = new BruTileHelper(_tileTimeOut);
                                    //_displayFilter.Transparency = (short)(255 - ((_transparency * 255) / 100));
                                    //if (display.Filter == null)
                                    //{
                                    //    display.Filter = _displayFilter;
                                    //}
                                    var fileCache = CacheDirectory.GetFileCache(_cacheDir,_config,_enumBruTileLayer);
                                    bruTileHelper.Draw(_application.StatusBar.ProgressBar, activeView, fileCache, trackCancel, SpatialReference, ref _currentLevel, _tileSource, display);
                                }
                            }
                            catch (Exception ex)
                            {
                                var mbox = new ExceptionMessageBox(ex);
                                mbox.Show(null);
                            }
                        } // isVisible
                    }  // isValid
                    break;
                case esriDrawPhase.esriDPAnnotation:
                    break;
            }
        }
Example #42
0
        /// <summary> Exibe um DialogBox mostrando as informações sobre a exceção. </summary>
        /// <returns>Retorna um DialogResult da DialogBox</returns>
        public DialogResult ShowThreadExceptionDialog()
        {
            ApplicationException exTop = new ApplicationException(Detalhes, InnerException);
            exTop.Source = this.Message;

            ExceptionMessageBox box = new ExceptionMessageBox(exTop);
            box.Symbol = Icone;
            box.Buttons = Botoes;
            box.Caption = Titulo;
            box.ShowToolBar = true;
            return box.Show(null);
        }
Example #43
0
        private void ShowDatabases(bool selectDefault)
        {
            // Show the current databases on the server
            Cursor csr = null;

            try
            {
                csr = this.Cursor;   // Save the old cursor
                this.Cursor = Cursors.WaitCursor;   // Display the waiting cursor

                // Clear control
                DatabasesComboBox.Items.Clear();

                // Limit the database properties returned to just those that we use
                SqlServerSelection.SetDefaultInitFields(typeof(Database),
                    new String[] { "Name", "IsSystemObject", "IsAccessible" });

                // Limit the table properties returned to just those that we use
                SqlServerSelection.SetDefaultInitFields(typeof(Table),
                    new String[] { "Name", "CreateDate", "IsSystemObject" });

                // Limit the column properties returned to just those that we use
                SqlServerSelection.SetDefaultInitFields(typeof(Column), new
                    String[] {"Name", "DataType", "SystemType", "Length", 
                        "NumericPrecision", "NumericScale", 
                        "XmlSchemaNamespace", "XmlSchemaNamespaceSchema", 
                        "DataTypeSchema", "Nullable", "InPrimaryKey"
                });

                // Add database objects to combobox; the default ToString will display the database name
                foreach (Database db in SqlServerSelection.Databases)
                {
                    if (db.IsSystemObject == false && db.IsAccessible == true)
                    {
                        DatabasesComboBox.Items.Add(db);
                    }
                }

                if ((selectDefault == true) &&
                    (DatabasesComboBox.Items.Count > 0))
                {
                    DatabasesComboBox.SelectedIndex = 0;
                }
            }
            catch (SmoException ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }
            finally
            {
                this.Cursor = csr;  // Restore the original cursor
            }
        }
Example #44
0
        private void ResumeButton_Click(System.Object sender,
            System.EventArgs e)
        {
            // Resume a paused service
            Cursor csr = null;
            Service svc;

            try
            {
                csr = this.Cursor;   // Save the old cursor
                this.Cursor = Cursors.WaitCursor;   // Display the waiting cursor
                svc = GetSelectedService();
                if (svc != null)
                {
                    if (svc.ServiceState == ServiceState.Paused)
                    {
                        sbrStatus.Text = Properties.Resources.Resuming;
                        sbrStatus.Refresh();
                        svc.Resume();
                    }

                    // Wait for service state to change
                    WaitServiceStateChange(svc, ServiceState.Running);

                    RefreshService(svc);
                    sbrStatus.Text = Properties.Resources.Ready;
                }
            }
            catch (SmoException ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }
            finally
            {
                this.Cursor = csr;  // Restore the original cursor
            }
        }
Example #45
0
        private void GetServices()
        {
            Cursor csr = null;
            ManagedComputer mc;
            ListViewItem ServiceListViewItem;

            try
            {
                csr = this.Cursor;   // Save the old cursor
                this.Cursor = Cursors.WaitCursor;   // Display the waiting cursor

                // Clear control
                ServicesListView.Items.Clear();
                mc = new ManagedComputer(SqlServerSelection.Name);

                foreach (Service svc in mc.Services)
                {
                    ServiceListViewItem = ServicesListView.Items.Add(svc.Name);
                    ServiceListViewItem.SubItems.Add(svc.DisplayName);
                    ServiceListViewItem.SubItems.Add(svc.ServiceState.ToString());
                    ServiceListViewItem.SubItems.Add(svc.StartMode.ToString());
                    ServiceListViewItem.SubItems.Add(svc.ServiceAccount);
                    ServiceListViewItem.SubItems.Add(svc.State.ToString());
                }
            }
            catch (SmoException ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }
            finally
            {
                this.Cursor = csr;  // Restore the original cursor
            }
        }
Example #46
0
        private void DropStripButton_Click(object sender, EventArgs e)
        {
            if (this.ActiveEditObject != null)
            {
                try
                {
                    if (MessageBox.Show
                    ("Drop this object?", "Drop Message",
                    MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk)
                    == DialogResult.OK)
                    {
                        this.ActiveEditObject.Configuration.Drop();
                        this.SetStripButtonState(ObjectsSplitPanel.operations.Drop);
                        this.RemoveAllObjects();
                    }

                }
                catch (Exception ex)
                {
                    ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                    emb.Show(this);
                }
            }
        }
Example #47
0
        private IConfiguration NewObject(string classType, string caption, int height)
        {
            EditObject obj;
            IConfiguration config = null;
            try
            {
                ConfigurationPanel.EditObjectButton.Text = caption;

                Assembly a = Assembly.GetAssembly(this.GetType());

                object[] args = new object[1];
                args[0] = SqlConnectionControl.ServiceBroker;
                //Create a new instance of class type stored in classType. 
                config = (IConfiguration)a.CreateInstance
                    (classType, true, BindingFlags.CreateInstance, null, args,
                    System.Globalization.CultureInfo.CurrentCulture, null);

                obj = ConfigurationPanel.AddObject("(New)", config);
                obj.Expand(height);
                obj.ButtonVisible = false;


            }
            catch (Exception ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }

            return config;
        }
Example #48
0
        private void exportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.ActiveEditObject != null)
            {
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    this.outputTextBox.Text = this.ActiveEditObject.Configuration.Export(String.Empty);
                    DataSet ds = this.ActiveEditObject.Configuration.Query();
                    if (ds != null)
                        this.outputDataGridView.DataSource = ds.Tables[0];

                }
                catch (Exception ex)
                {
                    ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                    emb.Show(this);
                }
                finally
                {
                    Cursor.Current = Cursors.Default;
                }
            }
        }
Example #49
0
        private void ListDatabaseSpace()
        {
            try
            {
                this.dataGridView1.Rows.Clear();

                foreach (Database db in SqlServerSelection.Databases)
                {
                    if (db.IsSystemObject == false)
                    {
                        if (db.LogFiles.Count > 0)
                        {
                            this.dataGridView1.Rows.Add(new object[] { db.Name, 
                                db.Size, db.SpaceAvailable / 1024.0, 
                                db.LogFiles[0].Size / 1024.0, 
                                db.LogFiles[0].UsedSpace / 1024.0 });
                        }
                        else
                        {
                            this.dataGridView1.Rows.Add(new object[] { db.Name, 
                                db.Size, db.SpaceAvailable / 1024.0, 
                                0.0, 0.0 });
                        }
                    }
                }
            }
            catch (SmoException ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }
        }
Example #50
0
 private void QueryStripButton_Click(object sender, EventArgs e)
 {
     if (this.ActiveEditObject != null)
     {
         try
         {
             this.QueryObject(this.ActiveEditObject.Configuration);
         }
         catch (Exception ex)
         {
             ExceptionMessageBox emb = new ExceptionMessageBox(ex);
             emb.Show(this);
         }
     }
 }
Example #51
0
        private void DeleteTableButton_Click(object sender, System.EventArgs e)
        {
            Database db;
            Table tbl;
            Cursor csr = null;

            try
            {
                csr = this.Cursor;   // Save the old cursor
                this.Cursor = Cursors.WaitCursor;   // Display the waiting cursor

                // Show the current tables for the selected database
                db = (Database)DatabasesComboBox.SelectedItem;
                if (TablesComboBox.Items.Count > 0)
                {
                    tbl = db.Tables[((Table)TablesComboBox.SelectedItem).Name,
                        ((Table)TablesComboBox.SelectedItem).Schema];
                    if (tbl != null)
                    {
                        // Are you sure?  Default to No to avoid accidents
                        if (System.Windows.Forms.MessageBox.Show(this, string.Format(
                            System.Globalization.CultureInfo.InvariantCulture,
                            Properties.Resources.ReallyDrop, tbl.ToString()), this.Text,
                            MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                            MessageBoxDefaultButton.Button2, 0) == DialogResult.No)
                        {
                            return;
                        }

                        tbl.Drop();
                    }

                    // Refresh list and select first entry
                    ShowTables();
                    if (TablesComboBox.Items.Count > 0)
                    {
                        TablesComboBox.SelectedIndex = 0;
                    }
                }
            }
            catch (SmoException ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }
            finally
            {
                this.Cursor = csr;  // Restore the original cursor
            }
        }
Example #52
0
        private void ShowColumns()
        {
            Cursor csr = null;
            ListViewItem ColumnListViewItem;
            Table tbl;

            try
            {
                csr = this.Cursor;   // Save the old cursor
                this.Cursor = Cursors.WaitCursor;   // Display the waiting cursor

                // Delay rendering until after list filled
                ColumnsListView.BeginUpdate();

                // Clear the columns list
                ColumnsListView.Items.Clear();

                // Show the current columns for the selected table
                if (TablesComboBox.SelectedIndex >= 0)
                {
                    // Get the selected table object
                    tbl = (Table)TablesComboBox.SelectedItem;

                    // Iterate through all the columns to fill list
                    foreach (Column col in tbl.Columns)
                    {
                        ColumnListViewItem =
                            ColumnsListView.Items.Add(col.Name);
                        ColumnListViewItem.SubItems.Add(col.DataType.Name);
                        ColumnListViewItem.SubItems.Add(col.DataType.
                            MaximumLength.ToString(
                            System.Globalization.CultureInfo.InvariantCulture));
                        ColumnListViewItem.SubItems.Add(
                            col.Nullable.ToString());
                        ColumnListViewItem.SubItems.Add(
                            col.InPrimaryKey.ToString());
                    }
                }

                // Now we render the listview
                ColumnsListView.EndUpdate();
                UpdateButtons();
            }
            catch (SmoException ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }
            finally
            {
                this.Cursor = csr;  // Restore the original cursor
            }
        }
Example #53
0
        private void ShowTables()
        {
            Database db;
            Cursor csr = null;

            try
            {
                csr = this.Cursor;   // Save the old cursor
                this.Cursor = Cursors.WaitCursor;   // Display the waiting cursor

                // Clear the tables list
                TablesComboBox.Items.Clear();

                // Show the current tables for the selected database
                if (DatabasesComboBox.SelectedIndex >= 0)
                {
                    db = (Database)DatabasesComboBox.SelectedItem;

                    foreach (Table tbl in db.Tables)
                    {
                        if (tbl.IsSystemObject == false)
                        {
                            TablesComboBox.Items.Add(tbl);
                        }
                    }

                    // Select the first item in the list
                    if (TablesComboBox.Items.Count > 0)
                    {
                        TablesComboBox.SelectedIndex = 0;
                    }
                    else
                    {
                        // Clear the table detail list
                        ColumnsListView.Items.Clear();
                    }
                }

                UpdateButtons();
            }
            catch (SmoException ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
            }
            finally
            {
                this.Cursor = csr;  // Restore the original cursor
            }
        }
Example #54
0
        private void WebSyncOptions_Load(object sender, EventArgs e)
        {
            passwordTextBox.Text = string.Empty;

            try
            {
                subscriberConn = new ServerConnection(subscriberServer);
                subscriberConn.Connect();

                mergePullSub = new MergePullSubscription(subscriptionDatabase,
                    publisherServer, publicationDatabase, publicationName,
                    subscriberConn);

                mergePullSub.Load();

                if (mergePullSub.UseWebSynchronization)
                {
                    enableWebSyncChkBox.Checked = true;
                    useWebSync = true;
                }

                if (string.IsNullOrEmpty(mergePullSub.InternetUrl) == false)
                {
                    webSyncUrlTexBox.Text = mergePullSub.InternetUrl;
                }
                else
                {
                    webSyncUrlTexBox.Text = webSynchronizationUrl;
                }

                if (string.IsNullOrEmpty(mergePullSub.InternetLogin) == false)
                {
                    userNameTextBox.Text = mergePullSub.InternetLogin;
                }
                else
                {
                    if (Environment.UserDomainName.Length != 0)
                    {
                        userNameTextBox.Text = Environment.UserDomainName
                            + @"\" + Environment.UserName;
                    }
                    else
                    {
                        userNameTextBox.Text = Environment.UserName;
                    }
                }

                if (mergePullSub.UseWebSynchronization == false)
                {
                    userNameTextBox.Enabled = false;
                    passwordTextBox.Enabled = false;
                }

            }
            catch (Exception ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
                this.Close();
            }
        }
Example #55
0
        private void 重新初始化数据RToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                Synchronize syncSub = new Synchronize();

                // Disable the current form
                this.Enabled = false;

                syncSub.Show(this);

                syncSub.ReinitializeSubscription();

            }
            catch (Exception ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex,
                    ExceptionMessageBoxButtons.OK);
                emb.Show(this);
            }
            finally
            {
                loadLastAgentSessionSummary();
                // Enable the current form
                this.Enabled = true;
            }
        }
Example #56
0
 private void okButton_Click(object sender, EventArgs e)
 {
     if (enableWebSyncChkBox.Checked == true &&
         (string.IsNullOrEmpty(userNameTextBox.Text) == true ||
         string.IsNullOrEmpty(passwordTextBox.Text) == true ||
         string.IsNullOrEmpty(webSyncUrlTexBox.Text) == true))
     {
         ExceptionMessageBox emb = new ExceptionMessageBox(
             Properties.Resources.ExceptionFormValidation);
         emb.Show(this);
         return;
     }
     else
     {
         if (enableWebSyncChkBox.Checked)
         {
             mergePullSub.UseWebSynchronization = true;
             mergePullSub.InternetLogin = userNameTextBox.Text;
             mergePullSub.InternetPassword = passwordTextBox.Text;
             mergePullSub.InternetUrl = webSyncUrlTexBox.Text;
             useWebSync = true;
         }
         else
         {
             mergePullSub.UseWebSynchronization = false;
             mergePullSub.InternetLogin = string.Empty;
             mergePullSub.InternetPassword = string.Empty;
             mergePullSub.InternetUrl = string.Empty;
             useWebSync = false;
         }
         mergePullSub.CommitPropertyChanges();
         mergePullSub.Refresh();
         subscriberConn.Disconnect();
         this.Close();
     }
 }
Example #57
0
        private void 只上传数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                Synchronize syncSub = new Synchronize();

                // Disable the current form
                this.Enabled = false;

                syncSub.Show(this);

                syncSub.SynchronizeSubscriptionUploadOnly();
                syncWhenConnectedStatus.Visible = false;

            }
            catch (Exception ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex,
                    ExceptionMessageBoxButtons.OK);
                emb.Show(this);
            }
            finally
            {
                // Enable the current form
                this.Enabled = true;
            }
        }
Example #58
0
        private ConnectedState GetConnectionState()
        {
            SelectQuery wmiQuery;
            ManagementObjectSearcher searcher;
            bool isConnected;

            try
            {
                // Query the WMI provider to determine if we are connected.
                wmiQuery = new SelectQuery("SELECT * FROM Win32_NetworkAdapter");
                searcher = new ManagementObjectSearcher(wmiQuery);

                // Assume that we are not connected.
                isConnected = false;

                // Check the results for a NetConnectionStatus of 2 (connected).
                foreach (ManagementObject result in searcher.Get())
                {
                    if (Convert.ToInt32(result["NetConnectionStatus"],
                        System.Globalization.CultureInfo.InvariantCulture) == 2)
                    {
                        isConnected = true;
                    }
                }

                if (isConnected)
                {
                    return ConnectedState.Connected;
                }
                else
                {
                    return ConnectedState.Disconnected;
                }
            }
            catch (Exception ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                emb.Show(this);
                return ConnectedState.Disconnected;
            }
        }
Example #59
0
        private void showSyncDialog()
        {
            try
            {
                Synchronize syncSub = new Synchronize();

                // Disable the current form
                this.Enabled = false;

                syncSub.Show(this);

                // Check that the subscription exists.
                syncSub.CheckSubscription();

                // Disable upload only if Web synchronization is enabled.
                if (syncSub.UseWebSynchronization)
                {
                    mnuSynchronizeOnlyUploadData.Enabled = false;
                }

            }
            catch (SqlException ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(
                    Properties.Resources.ExceptionVerifySqlServerRunning,
                    Properties.Resources.ExceptionSqlServerError,
                    ExceptionMessageBoxButtons.OK);
                emb.InnerException = ex;
                emb.Show(this);

                // Shutdown the application because we can't continue.
                Application.Exit();
            }
            catch (ApplicationException ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex,
                    ExceptionMessageBoxButtons.OK);
                emb.Show(this);

                // Shutdown the application because we can't continue.
                Application.Exit();
            }
            catch (Exception ex)
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(ex,
                    ExceptionMessageBoxButtons.OK);
                emb.Show(this);

                // Shutdown the application because we can't continue.
                Application.Exit();
            }
            catch
            {
                ExceptionMessageBox emb = new ExceptionMessageBox(@"CATASTROPHIC FAILURE!",
                    @"CLOSING APPLICATION");
                emb.Show(this);

                // Shutdown the application because we can't continue.
                Application.Exit();
            }
            finally
            {
                // Enable the current form
                this.Enabled = true;
            }
        }
Example #60
-6
        public static void LoadTextDocument(String path)
        {
            TaskWindow taskWindow = new TaskWindow
                                    (
                delegate(Object argument)
            {
                // Use Encoding.Default to eliminate incorrect characters
                return(File.ReadAllText(argument.ToString(), Encoding.Default));
            },
                path
                                    )
            {
                Owner = App.MainWindow
            };

            taskWindow.ShowDialog();

            if (taskWindow.Exception == null)
            {
                String text = taskWindow.Result as String;

                if (text != null)
                {
                    AppState.Current.Input.Text = text;
                }
            }
            else
            {
                ExceptionMessageBox.Show(App.MainWindow, App.Metadata.AssemblyTitle,
                                         "Invalid job file format.", taskWindow.Exception.InnerException);
            }
        }