Example #1
0
        public void GetQueryPlan(DatabaseInfo dbName, IQuery query, GetQueryPlanCompleted getQueryPlanCompleted)
        {
            if (m_serverChanel == null)
            {
                throw new NoConnectionException();
            }

            if (!m_worker.IsBusy)
            {
                m_worker = new BackgroundWorker();
                m_worker.WorkerSupportsCancellation = true;
                m_worker.DoWork += new DoWorkEventHandler(DoGetQueryPlan);

                m_worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs e)
                {
                    IsExecutingChanged(this, new IsExecutingEventArgs(false));
                    var qr = e.Result as IQueryPlanReslult;
                    IsExecutingChanged(this, new IsExecutingEventArgs(false));
                    //TODO odbsluga wyjatkow
                    if (qr == null || qr.QueryPlan == null)
                    {
                        getQueryPlanCompleted(ExecuteQueryStatus.Error, qr);
                    }
                    else if (e.Error != null)
                    {
                        messageService.ShowMessage(e.Error.Message, "Error");
                        getQueryPlanCompleted(ExecuteQueryStatus.Error, null);
                        Disconnected(this, EventArgs.Empty);
                    }
                    else if (e.Cancelled)
                    {
                        getQueryPlanCompleted(ExecuteQueryStatus.Canceled, null);
                    }
                    else
                    {
                        getQueryPlanCompleted(ExecuteQueryStatus.Done, qr);
                    }
                };

                //wraps args to query structure

                QueryStruct queryStruct = new QueryStruct();
                queryStruct.DbName = dbName;
                queryStruct.Query  = query;

                IsExecutingChanged(this, new IsExecutingEventArgs(true));
                m_worker.RunWorkerAsync(queryStruct);
            }
        }
Example #2
0
        public void DeleteDatabase(DatabaseInfo dbName, DeleteDatabaseCompleted renameDatabaseNameCompleted)
        {
            if (m_serverChanel == null)
            {
                throw new NoConnectionException();
            }

            if (!m_worker.IsBusy)
            {
                m_worker         = new BackgroundWorker();
                m_worker.DoWork += new DoWorkEventHandler(DoExecuteQuery);

                m_worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs e)
                {
                    var qr = e.Result as IQueryResult;
                    IsExecutingChanged(this, new IsExecutingEventArgs(false));
                    //TODO odbsluga wyjatkow
                    if (qr == null || qr.QueryResultType != ResultType.SystemInfo)
                    {
                        renameDatabaseNameCompleted(ExecuteQueryStatus.Error, dbName, qr);
                    }
                    else if (e.Error != null)
                    {
                        messageService.ShowMessage(e.Error.Message, "Error");
                        renameDatabaseNameCompleted(ExecuteQueryStatus.Error, dbName, qr);
                        Disconnected(this, EventArgs.Empty);
                    }
                    else
                    {
                        renameDatabaseNameCompleted(ExecuteQueryStatus.Done, dbName, qr);
                        StringReader  txtR          = new StringReader(qr.StringOutput);
                        XmlSerializer xmlSerializer = new XmlSerializer(typeof(SystemInfo));
                        SystemInfo = xmlSerializer.Deserialize(txtR) as SystemInfo;

                        DatabasesChanged(this, EventArgs.Empty);
                    }
                };

                //wraps args to query structure
                QueryStruct queryStruct = new QueryStruct();
                queryStruct.DbName = dbName;
                queryStruct.Query  = InternalQueries.DropDatabaseQuery(dbName.Name);

                IsExecutingChanged(this, new IsExecutingEventArgs(true));
                m_worker.RunWorkerAsync(queryStruct);
            }
        }
Example #3
0
        void DoGetQueryPlan(object sender, DoWorkEventArgs e)
        {
            QueryStruct queryStruct = (QueryStruct)e.Argument;

            try
            {
                e.Result = m_serverChanel.GetQueryPlan(new DatabaseInfo {
                    Name = queryStruct.DbName.Name
                },
                                                       new DTOQuery(queryStruct.Query));
            }
            catch (EndpointNotFoundException)
            {
                Disconnect();
                throw;
            }
            catch (CommunicationException ex)
            {
                Disconnect();
                throw;
            }
            if (m_worker.WorkerSupportsCancellation)
            {
                while (true)
                {
                    if (m_worker.CancellationPending)
                    {
                        e.Cancel = true;
                        return;
                    }
                    if (e.Result != null)
                    {
                        return;
                    }
                    Thread.Sleep(10);
                }
            }
        }
Example #4
0
        private void WorkWithQuery(int maxSize)
        {
            ShowName("Qurey");

            QueryStruct <long> structer;

            structer = new QueryStruct <long>(maxSize);

            Fill(structer, maxSize);

            structer.Remove();
            structer.Remove();

            structer.Insert(25);
            structer.Insert(90);
            structer.Remove();
            structer.Remove();
            structer.Insert(5);
            structer.Insert(2);
            structer.Display();
            Remove(structer);
            ShowEndMessage();
        }
Example #5
0
        public void GetSystemInfo(GetSystemInfoCompleted getSystemInfoCompleted)
        {
            if (m_serverChanel == null)
            {
                throw new NoConnectionException();
            }

            if (!m_worker.IsBusy)
            {
                m_worker = new BackgroundWorker();
                m_worker.WorkerSupportsCancellation = true;
                m_worker.DoWork += new DoWorkEventHandler(DoExecuteQuery);

                m_worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs e)
                {
                    var qr = e.Result as IQueryResult;
                    IsExecutingChanged(this, new IsExecutingEventArgs(false));
                    //TODO odbsluga wyjatkow
                    if (e.Error != null)
                    {
                        messageService.ShowMessage(e.Error.Message, "Error");
                        getSystemInfoCompleted(ExecuteQueryStatus.Error, null, qr);
                        Disconnected(this, EventArgs.Empty);
                    }
                    else if (e.Cancelled)
                    {
                        getSystemInfoCompleted(ExecuteQueryStatus.Canceled, null, qr);
                    }
                    else
                    {
                        if (qr.QueryResultType == ResultType.SystemInfo)
                        {
                            StringReader  txtR          = new StringReader(qr.StringOutput);
                            XmlSerializer xmlSerializer = new XmlSerializer(typeof(SystemInfo));
                            SystemInfo = xmlSerializer.Deserialize(txtR) as SystemInfo;

                            Databases = SystemInfo.Databases.Select(d => d.Name).ToList();

                            getSystemInfoCompleted(ExecuteQueryStatus.Done, SystemInfo, qr);
                        }
                        else if (qr.QueryResultType == ResultType.StringResult)
                        {
                            messageService.ShowMessage(qr.StringOutput, "Unexpected result");
                            getSystemInfoCompleted(ExecuteQueryStatus.Error, null, qr);
                        }
                        else
                        {
                            messageService.ShowMessage(String.Format("[{0}]", qr.QueryResultType),
                                                       "Unexpected result");
                            getSystemInfoCompleted(ExecuteQueryStatus.Error, null, qr);
                        }
                    }
                };

                //wraps args to query structure
                QueryStruct queryStruct = new QueryStruct();
                queryStruct.DbName = _databaseInfoForSystemInfoQuery;
                queryStruct.Query  = _getSystemInfo;

                IsExecutingChanged(this, new IsExecutingEventArgs(true));
                m_worker.RunWorkerAsync(queryStruct);
            }
        }
Example #6
0
        /// <summary>
        /// 產生T-SQL語法
        /// </summary>
        /// <param name="QuerySql">傳入QueryStruct</param>
        /// <returns>回傳T-SQL語法</returns>
        public static string GenerSQL(QueryStruct QuerySql)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("Select ");

            #region 列出選取欄位

            //列出選取欄位
            sb.Append(GetSelectField(QuerySql.SelectFieldList));

            #endregion

            sb.Append("From ");

            #region 列出選取的資料表

            //列出選取的資料表
            sb.Append(GetSelectTable(QuerySql.SelectTableViewList));

            #endregion

            sb.Append("Where 1=1 ");

            #region 檢查Rownum

            //檢查Rownum
            sb.Append(GetRowNumCheck(QuerySql.RowNumCheck));

            #endregion

            #region 列出條件

            //列出條件
            for (int i = 0; i < QuerySql.ConditionList.Length; i++)
            {
                //列出TSQL Operator
                sb.Append(GetTSQLOperator(QuerySql.ConditionList[i]));

                //列出欄位名稱
                sb.Append(QuerySql.ConditionList[i].ConditionField);

                //列出欄位運算子
                sb.Append(GetFieldOperator(QuerySql.ConditionList[i]));

                //列出欄位值
                sb.Append(GetFieldValue(QuerySql.ConditionList[i]));

            }

            #endregion

            #region 列出Group By 句子

            //列出Group By 句子
            sb.Append(GetGroupByProcess(QuerySql.GroupByProcess, QuerySql.SelectFieldList));

            #endregion

            #region 列出Group By Having 條件

            //列出Group By Having 條件
            for (int j = 0; j < QuerySql.HavingList.Length; j++)
            {
                if (j == 0)
                {
                    sb.Append("Having ");
                }
                else
                {
                    //列出TSQL Operator
                    sb.Append(GetTSQLOperator(QuerySql.ConditionList[j]));
                }
                //列出欄位名稱
                sb.Append(QuerySql.HavingList[j].ConditionField);

                //列出欄位運算子
                sb.Append(GetFieldOperator(QuerySql.HavingList[j]));

                //列出欄位值
                sb.Append(GetFieldValue(QuerySql.HavingList[j]));
            }

            #endregion

            #region 列出Order by內容

            //列出Order by內容
            sb.Append(GetOrderBy(QuerySql.OrderByList));

            #endregion

            return sb.ToString();

        }