Esempio n. 1
0
        void _appSettings_SaveSettings(object sender, MyZillaSettingsEventArgs e)
        {
            switch (e.SaveParameter.Operation)
            {
                case OperationType.AddConnection :
                    if (e.SaveParameter.ConnectionRow.ActiveUser  == true)
                    {
                        // check if catalogues for user are already cached
                        Catalogues cataloguesPerUser = this.GetCataloguesForConnection (e.SaveParameter.ConnectionRow.ConnectionId );

                        if (cataloguesPerUser != null)
                        {
                            // catalogues are already cached.
                            // no action here.
                        }
                        else
                        {
                            if (this.CatalogueEvent != null)
                            {
                                this.CatalogueEvent(this, new MyZillaSettingsEventArgs(e.SaveParameter));
                            }

                            this.LoadCataloguesForUser(e.SaveParameter);
                        }
                    }
                    else
                    {
                        if (this.CatalogueEvent != null)
                        {
                            this.CatalogueEvent(this, new MyZillaSettingsEventArgs(e.SaveParameter));
                        }
                    }
                    break;

                case OperationType.EditConnection:
                    if (e.SaveParameter.ConnectionRow.ActiveUser == true)
                    {
                        // check if catalogues for user are already cached
                        Catalogues cataloguesPerUser = this.GetCataloguesForConnection (e.SaveParameter.ConnectionRow.ConnectionId );

                        if (cataloguesPerUser != null)
                        {
                            // catalogues are already cached.
                            // fire the event to be processed by the subscribers if any
                            if (this.CatalogueEvent != null)
                            {
                                this.CatalogueEvent(this, new MyZillaSettingsEventArgs(e.SaveParameter));
                            }
                        }
                        else
                        {
                            if (this.CatalogueEvent != null)
                            {
                                this.CatalogueEvent(this, new MyZillaSettingsEventArgs(e.SaveParameter));
                            }

                            this.LoadCataloguesForUser(e.SaveParameter);

                        }
                    }
                    else
                    {

                        //this.RemoveCataloguesForConnection (e.SaveParameter.ConnectionRow.ConnectionId );

                        if (this.CatalogueEvent != null)
                        {
                            this.CatalogueEvent(this, new MyZillaSettingsEventArgs(e.SaveParameter));
                        }

                    }
                    break;

                case OperationType.DeleteConnection:

                    this.RemoveUsersForConnection(e.SaveParameter.ConnectionRow.ConnectionId );

                    if (this.CatalogueEvent != null)
                    {
                        this.CatalogueEvent(this, new MyZillaSettingsEventArgs(e.SaveParameter));
                    }

                    break;

            }
        }
Esempio n. 2
0
        void _catalogManager_CatalogueEvent(object sender, MyZillaSettingsEventArgs e)
        {
            try
            {
                int connID = e.SaveParameter.ConnectionRow.ConnectionId ;

                TDSettings.ConnectionRow  connection = _appSettings.GetConnectionById ( connID);
                TreeNode userNode = null;
                TreeNode[] nodes = tvQueries.Nodes.Find("User " + connID.ToString(), false);
                if (nodes.GetLength(0) == 1)
                {
                    userNode = nodes[0];
                }

                NodeDescription nodeDescr;

                switch (e.SaveParameter.Operation)
                {

                    #region Exceptions
                    case OperationType.AddConnectionThrowsError:
                        RemoveConnectingNode(connID);
                        break;
                    case OperationType.LogOnFailed :
                        LoginFailedMessage( connID, e.SaveParameter.ErrorMessage );
                        break;
                    #endregion

                    #region Add Connection event
                    case OperationType.AddConnection :

                        if (_catalogManager.AreCataloguesLoaded( connID ))
                        {
                            nodeDescr = (NodeDescription)nodes[0].Tag;

                            TDSQueriesTree.Instance().LoadDefaultDataForUserId(tvQueries, connection );

                            TDSQueriesTree.Instance().AddUserSubtree(tvQueries, (TDSettings.ConnectionRow )nodeDescr.NodeData);

                            _qTree.Save();

                            RemoveConnectingNode(connID);

                            BuildAsyncProcessForGenerateColumnListCookie(connID);

                            this.StartCountingBugsPerQuery(connID);

                        }
                        else
                        {
                            nodeDescr = new NodeDescription(NodeType.Connection, connection );

                            userNode = new TreeNode(_appSettings.GetConnectionInfo(connID), 2, 2);
                            userNode.Name = "User " + connID .ToString();
                            userNode.ToolTipText = String.Empty;
                            userNode.Tag = nodeDescr;

                            tvQueries.Nodes.Add(userNode);
                            if (connection.ActiveUser )
                                AddLoadingNode(userNode);
                        }
                        break;
                    #endregion

                    #region Delete Connection event
                    case OperationType.DeleteConnection :

                        DisconnectUser(connID );
                        _qTree.RemoveUserItems(connID);
                        userNode.Remove();

                        break;
                    #endregion

                    #region Edit User event
                    case OperationType.EditConnection :

                            if (_catalogManager.AreCataloguesLoaded( connID ))
                            {
                                Interlocked.Decrement(ref _startupLoadingThreads);

                                nodeDescr = (NodeDescription)nodes[0].Tag;

                                if (_qTree.Folders.Select("UserId = " + connID.ToString()).GetLength(0)==0)
                                    TDSQueriesTree.Instance().LoadDefaultDataForUserId(tvQueries, connection );

                                RemoveConnectingNode(connID);

                                BuildAsyncProcessForGenerateColumnListCookie(connID);

                                if (this.IsTreeConnectionNodeLoaded( connID ))
                                {
                                    // no code here
                                }
                                else
                                {
                                    TDSQueriesTree.Instance().AddUserSubtree(tvQueries, (TDSettings.ConnectionRow)nodeDescr.NodeData);

                                    this.StartCountingBugsPerQuery(connID);

                                }

                                nodes[0].Text = e.SaveParameter.ConnectionRow.ConnectionName;

                                this.SetTreeNodesExpandState(userNode.Nodes);

                                if (_startupLoadingThreads == 0)
                                {
                                    this.Visible = true;

                                    SplashManager.Close();

                                    this.CheckForNewMyZillaVersion(false);
                                }

                            }
                            else {
                                if (connection.ActiveUser)
                                {
                                    this.AddLoadingNode(userNode);
                                }
                            }
                        break;
                    #endregion
                } // end switch
            }
            catch (Exception ex)
            {
                // The thread could continue to execute after the form was closed.
                // In this case, an exception is generated. It is no need to be logged or be shown those type of exceptions.
                if (!_formClosed)
                {

                    MyLogger.Write(ex, "_catalogManager_CatalogueEvent", LoggingCategory.Exception);

                    MessageBox.Show(this, ex.Message, Messages.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                //just in case
                SplashManager.Close();
            }
        }