Пример #1
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="mDataViewInfo">Filter也是DataViewInfo的一个属性,所以这里加上参数</param>
 public frmQuery(MongoDBHelper.DataViewInfo mDataViewInfo)
 {
     InitializeComponent();
     CurrentDataViewInfo = mDataViewInfo;
     SystemManager.SelectObjectTag = mDataViewInfo.strDBTag;
     _mongoCol = SystemManager.GetCurrentCollection();
 }
Пример #2
0
 public ctlGFSView(MongoDBHelper.DataViewInfo _DataViewInfo)
 {
     InitializeComponent();
     InitTool();
     mDataViewInfo = _DataViewInfo;
     _dataShower.Add(lstData);
 }
Пример #3
0
 public ctlDocumentView(MongoDBHelper.DataViewInfo _DataViewInfo)
 {
     InitializeComponent();
     InitToolAndMenu();
     mDataViewInfo = _DataViewInfo;
     _dataShower.Add(lstData);
     _dataShower.Add(txtData);
     _dataShower.Add(trvData);
 }
        /// <summary>
        /// Delete Javascript Collection Document
        /// </summary>
        /// <param name="jsName"></param>
        /// <returns></returns>
        public static Boolean DelJavascript(String jsName)
        {
            MongoCollection jsCol = SystemManager.GetCurrentJsCollection();

            if (MongoDBHelper.IsExistByKey(jsCol, jsName))
            {
                return(MongoDBHelper.DropDocument(jsCol, (BsonString)jsName));
            }
            return(false);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="RootName"></param>
        /// <param name="doc"></param>
        /// <param name="IsOpen"></param>
        /// <returns></returns>
        public static String ConvertBsonTozTreeJson(String RootName, BsonDocument doc, Boolean IsOpen)
        {
            TreeViewColumns trvStatus = new TreeViewColumns();

            MongoDBHelper.FillDataToTreeView(RootName, trvStatus, doc);
            if (IsOpen)
            {
                trvStatus.TreeView.Nodes[0].Expand();
            }
            return(ConvertTreeViewTozTreeJson(trvStatus.TreeView));
        }
        /// <summary>
        /// 换页操作
        /// </summary>
        /// <param name="IsNext"></param>
        /// <param name="strTag"></param>
        /// <param name="dataShower"></param>
        public static void PageChanged(PageChangeOpr pageChangeMode, ref DataViewInfo mDataViewInfo, List <Control> dataShower)
        {
            switch (pageChangeMode)
            {
            case PageChangeOpr.FirstPage:
                mDataViewInfo.SkipCnt = 0;
                break;

            case PageChangeOpr.LastPage:
                if (mDataViewInfo.CurrentCollectionTotalCnt % mDataViewInfo.LimitCnt == 0)
                {
                    //没有余数的时候,600 % 100 == 0  => Skip = 600-100 = 500
                    mDataViewInfo.SkipCnt = mDataViewInfo.CurrentCollectionTotalCnt - mDataViewInfo.LimitCnt;
                }
                else
                {
                    // 630 % 100 == 30  => Skip = 630-30 = 600
                    mDataViewInfo.SkipCnt = mDataViewInfo.CurrentCollectionTotalCnt - mDataViewInfo.CurrentCollectionTotalCnt % mDataViewInfo.LimitCnt;
                }
                break;

            case PageChangeOpr.NextPage:
                mDataViewInfo.SkipCnt += mDataViewInfo.LimitCnt;
                if (mDataViewInfo.SkipCnt >= mDataViewInfo.CurrentCollectionTotalCnt)
                {
                    mDataViewInfo.SkipCnt = mDataViewInfo.CurrentCollectionTotalCnt - 1;
                }
                break;

            case PageChangeOpr.PrePage:
                mDataViewInfo.SkipCnt -= mDataViewInfo.LimitCnt;
                if (mDataViewInfo.SkipCnt < 0)
                {
                    mDataViewInfo.SkipCnt = 0;
                }
                break;

            default:
                break;
            }
            List <BsonDocument> datalist = MongoDBHelper.GetDataList(ref mDataViewInfo);

            MongoDBHelper.FillDataToControl(datalist, dataShower, mDataViewInfo);
        }
Пример #7
0
 /// <summary>
 /// 初始化
 /// </summary>
 /// <param name="_DataViewInfo"></param>
 public ctlDataView(MongoDBHelper.DataViewInfo _DataViewInfo)
 {
     InitializeComponent();
     mDataViewInfo = _DataViewInfo;
 }
Пример #8
0
 /// <summary>
 /// 获得当前数据集
 /// </summary>
 /// <returns></returns>
 public static MongoCollection GetCurrentCollection()
 {
     return(MongoDBHelper.GetMongoCollectionBySvrPath(SelectObjectTag));
 }
Пример #9
0
 /// <summary>
 /// 获得当前数据库
 /// </summary>
 /// <returns></returns>
 public static MongoDatabase GetCurrentDataBase()
 {
     return(MongoDBHelper.GetMongoDBBySvrPath(SelectObjectTag));
 }
        /// <summary>
        /// 数据库操作
        /// </summary>
        /// <param name="strObjTag"></param>
        /// <param name="dbName"></param>
        /// <param name="func"></param>
        /// <param name="tr"></param>
        /// <returns></returns>
        public static String DataBaseOpration(String strObjTag, String dbName, Oprcode func, TreeNode tr)
        {
            String        rtnResult  = String.Empty;
            MongoServer   mongoSvr   = GetMongoServerBySvrPath(strObjTag);
            String        strSvrPath = SystemManager.GetTagData(strObjTag);
            String        svrKey     = strSvrPath.Split("/".ToCharArray())[(int)PathLv.InstanceLV];
            CommandResult result     = new CommandResult(new BsonDocument());

            if (mongoSvr != null)
            {
                switch (func)
                {
                case Oprcode.Create:
                    if (!mongoSvr.DatabaseExists(dbName))
                    {
                        //从权限上看,clusterAdmin是必须的
                        //但是能够建立数据库,不表示能够看到里面的内容!
                        //dbAdmin可以访问数据库。
                        //clusterAdmin能创建数据库但是不能访问数据库。
                        try
                        {
                            mongoSvr.GetDatabase(dbName);
                            tr.Nodes.Add(FillDataBaseInfoToTreeNode(dbName, mongoSvr, svrKey + "/" + svrKey));
                        }
                        catch (Exception ex)
                        {
                            //如果使用没有dbAdmin权限的clusterAdmin。。。。
                            SystemManager.ExceptionDeal(ex);
                        }
                    }
                    break;

                case Oprcode.Drop:
                    if (mongoSvr.DatabaseExists(dbName))
                    {
                        result = mongoSvr.DropDatabase(dbName);
                        if (tr != null)
                        {
                            tr.TreeView.Nodes.Remove(tr);
                        }
                        if (!result.Response.Contains("err"))
                        {
                            return(String.Empty);
                        }
                        else
                        {
                            return(result.Response["err"].ToString());
                        }
                    }
                    break;

                case Oprcode.Repair:
                    ///其实Repair的入口不在这个方法里面
                    MongoDBHelper.ExecuteMongoDBCommand(MongoDBHelper.repairDatabase_Command, SystemManager.GetCurrentDataBase());
                    break;

                default:
                    break;
                }
            }
            return(rtnResult);
        }
        /// <summary>
        /// 当前对象的MONGO命令
        /// </summary>
        /// <param name="mMongoCommand">命令对象</param>
        /// <param name="ShowMsgBox"></param>
        /// <returns></returns>
        public static CommandResult ExecuteMongoCommand(MongoCommand mMongoCommand, Boolean ShowMsgBox = true)
        {
            List <CommandResult> ResultCommandList = new List <CommandResult>();

            CommandResult mCommandResult = new CommandResult(new BsonDocument());

            try
            {
                switch (mMongoCommand.RunLevel)
                {
                case PathLv.CollectionLV:
                    if (String.IsNullOrEmpty(mMongoCommand.CommandString))
                    {
                        mCommandResult = ExecuteMongoColCommand(mMongoCommand.cmdDocument, SystemManager.GetCurrentCollection());
                    }
                    else
                    {
                        mCommandResult = ExecuteMongoColCommand(mMongoCommand.CommandString, SystemManager.GetCurrentCollection());
                    }
                    break;

                case PathLv.DatabaseLV:
                    mCommandResult = ExecuteMongoDBCommand(mMongoCommand.cmdDocument, SystemManager.GetCurrentDataBase());
                    break;

                case PathLv.InstanceLV:
                    mCommandResult = ExecuteMongoSvrCommand(mMongoCommand.cmdDocument, SystemManager.GetCurrentServer());
                    break;

                default:
                    break;
                }
                ResultCommandList.Add(mCommandResult);
                if (ShowMsgBox)
                {
                    MyMessageBox.ShowMessage(mMongoCommand.CommandString, mMongoCommand.CommandString + " Result", MongoDBHelper.ConvertCommandResultlstToString(ResultCommandList), true);
                }
            }
            catch (System.IO.IOException ex)
            {
                SystemManager.ExceptionDeal(ex, mMongoCommand.CommandString, "IOException,Try to set Socket TimeOut more long at connection config");
            }
            catch (Exception ex)
            {
                SystemManager.ExceptionDeal(ex, mMongoCommand.CommandString);
            }

            return(mCommandResult);
        }
Пример #12
0
 /// <summary>
 /// 设置DataFilter
 /// </summary>
 public void SetCurrDataFilter(MongoDBHelper.DataViewInfo CurrentDataViewInfo)
 {
     //过滤条件
     for (int i = 0; i < _conditionCount; i++)
     {
         ctlQueryCondition ctl = (ctlQueryCondition)Controls.Find("Condition" + (i + 1).ToString(), true)[0];
         if (ctl.IsSeted)
         {
             CurrentDataViewInfo.mDataFilter.QueryConditionList.Add(ctl.ConditionItem);
         }
     }
 }
Пример #13
0
 public frmExport(MongoDBHelper.DataViewInfo info)
 {
     InitializeComponent();
     viewinfo = info;
 }
Пример #14
0
        //http://www.mongodb.org/display/DOCS/SQL+to+Mongo+Mapping+Chart(旧网址)
        //http://docs.mongodb.org/manual/reference/sql-comparison/

        /// <summary>
        /// Convert Query Sql To DataFilter
        /// </summary>
        /// <param name="Sql"></param>
        /// <returns></returns>
        public static DataFilter ConvertQuerySql(String Sql)
        {
            DataFilter rtnQuery = new DataFilter();

            Sql = Sql.Trim();
            //引号中的空格用&nbsp;代替,引号以外的东西小写
            Sql = Regular(Sql);
            //先将字符串里面的空格统一成单个空格
            //Select    A,B  From   C ->
            //Select A,B From C
            while (Sql.Contains("  "))
            {
                Sql = Sql.Replace("  ", " ");
            }
            //找出Select ,From , Group
            String[] SqlToken = Sql.Split(" ".ToCharArray());

            int SelectStartIndex  = -1;
            int FromStartIndex    = -1;
            int WhereStartIndex   = -1;
            int GroupByStartIndex = -1;
            int OrderByStartIndex = -1;

            for (int i = 0; i < SqlToken.Length; i++)
            {
                switch (SqlToken[i].ToLower())
                {
                case "select":
                    SelectStartIndex = i;
                    break;

                case "from":
                    FromStartIndex = i;
                    break;

                case "where":
                    WhereStartIndex = i;
                    break;

                case "group":
                    GroupByStartIndex = i;
                    break;

                case "order":
                    OrderByStartIndex = i;
                    break;

                default:
                    break;
                }
            }

            String[] KeyWords = new String[] { "select", "from", "where", "group", "order" };

            //From - > CollectionName
            String          strFrom = GetKeyContent(FromStartIndex, SqlToken, KeyWords);
            MongoCollection mongoCol;

            //if ((strFrom != String.Empty) & SystemManager.GetCurrentDataBase().CollectionExists(strFrom))
            //{
            //    mongoCol = SystemManager.GetCurrentDataBase().GetCollection(strFrom);
            //}
            //else
            //{
            //    return null;
            //}
            //From:由于当前肯定是从固定表里面取数据
            mongoCol = SystemManager.GetCurrentCollection();

            //Select 设定 必须项
            //Select - > FieldList
            String strSelect = GetKeyContent(SelectStartIndex, SqlToken, KeyWords);

            if (strSelect == String.Empty)
            {
                return(null);
            }
            List <String> ColumnNameLst = MongoDBHelper.GetCollectionSchame(mongoCol);

            if (strSelect == "*")
            {
                //Select *
                foreach (String item in ColumnNameLst)
                {
                    DataFilter.QueryFieldItem field = new DataFilter.QueryFieldItem();
                    field.ColName  = item;
                    field.IsShow   = true;
                    field.sortType = DataFilter.SortType.NoSort;
                    rtnQuery.QueryFieldList.Add(field);
                }
            }
            else
            {
                //Select A,B,C
                foreach (String item in strSelect.Split(",".ToCharArray()))
                {
                    DataFilter.QueryFieldItem field = new DataFilter.QueryFieldItem();
                    field.ColName  = item;
                    field.IsShow   = true;
                    field.sortType = DataFilter.SortType.NoSort;
                    rtnQuery.QueryFieldList.Add(field);
                }
            }

            //Where 设定,可选项
            String strWhere = GetKeyContent(WhereStartIndex, SqlToken, KeyWords);

            if (strWhere != String.Empty)
            {
                rtnQuery.QueryConditionList = SetQueryCondition(strWhere, ColumnNameLst);
            }

            //Order 设定,可选项
            String strOrder = GetKeyContent(OrderByStartIndex, SqlToken, KeyWords);

            if (strOrder != String.Empty)
            {
                SetQueryOrder(rtnQuery, strOrder);
            }


            //Group 设定,可选项
            String strGroup = GetKeyContent(GroupByStartIndex, SqlToken, KeyWords);

            if (strGroup != String.Empty)
            {
                //TODO:Group
            }

            return(rtnQuery);
        }
Пример #15
0
 /// <summary>
 /// 获得当前服务器
 /// </summary>
 /// <returns></returns>
 public static MongoServer GetCurrentServer()
 {
     return(MongoDBHelper.GetMongoServerBySvrPath(SelectObjectTag));
 }
Пример #16
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="uploadDir"></param>
 /// <param name="fileCount"></param>
 /// <param name="opt"></param>
 /// <returns>是否继续执行后续的所有操作</returns>
 private Boolean UploadFolder(DirectoryInfo uploadDir, ref int fileCount, MongoDBHelper.UpLoadFileOption opt)
 {
     foreach (FileInfo file in uploadDir.GetFiles())
     {
         MongoDBHelper.UploadResult rtn = MongoDBHelper.UpLoadFile(file.FullName, opt);
         switch (rtn)
         {
             case MongoDBHelper.UploadResult.Complete:
                 fileCount++;
                 break;
             case MongoDBHelper.UploadResult.Skip:
                 if (opt.AlreadyOpt == MongoDBHelper.enumGFSAlready.Stop)
                 {
                     ///这个操作返回为False,停止包括父亲过程在内的所有操作
                     return false;
                 }
                 break;
             case MongoDBHelper.UploadResult.Exception:
                 return MyMessageBox.ShowConfirm("Upload Exception", "Is Continue?");
             default:
                 break;
         }
     }
     if (!opt.IgnoreSubFolder)
     {
         foreach (DirectoryInfo dir in uploadDir.GetDirectories())
         {
             ///递归文件夹操作,如果下层有任何停止的意愿,则立刻停止,并且使上层也立刻停止
             Boolean IsContinue = UploadFolder(dir, ref fileCount, opt);
             if (!IsContinue) { return false; }
         }
     }
     return true;
 }
Пример #17
0
        /// <summary>
        /// 当前对象的MONGO命令
        /// </summary>
        /// <param name="cmd">命令对象</param>
        /// <returns></returns>
        public static void ExecuteMongoCommand(MongoCommand cmd)
        {
            var Command = new CommandDocument {
                { cmd.CommandString, 1 }
            };
            List <CommandResult> ResultCommandList = new List <CommandResult>();

            CommandResult rtn = new CommandResult();

            try
            {
                switch (cmd.RunLevel)
                {
                case PathLv.CollectionLV:
                    rtn = ExecuteMongoColCommand(cmd.CommandString, SystemManager.GetCurrentCollection());
                    break;

                case PathLv.DatabaseLV:
                    rtn = ExecuteMongoDBCommand(Command, SystemManager.GetCurrentDataBase());
                    break;

                case PathLv.ServerLV:
                    rtn = ExecuteMongoSvrCommand(Command, SystemManager.GetCurrentServer());
                    break;

                default:
                    break;
                }
                ResultCommandList.Add(rtn);
                MyMessageBox.ShowMessage(cmd.CommandString, cmd.CommandString + " Result", MongoDBHelper.ConvertCommandResultlstToString(ResultCommandList), true);
            }
            catch (System.IO.IOException ex)
            {
                MyMessageBox.ShowMessage(cmd.CommandString, "IOException,Try to set Socket TimeOut more long at connection config", ex.ToString(), true);
            }
            catch (Exception ex)
            {
                SystemManager.ExceptionDeal(ex, cmd.CommandString);
            }
        }