/// <summary>
        /// 如果是删除 目录 ,查找该目录的所有子目录,查找所有的文件
        /// 若是删除文档,则直接删除
        /// </summary>
        /// <returns></returns>
        public List <DBItem> FindTarget(string dbName, string collectionName, string id)
        {
            List <DBItem> list = new List <DBItem>();
            var           db   = DataStorage.GetInstance(DBType.MongoDB);

            if (collectionName == CONST.DB.CollectionName_CategoryItem)
            {
                var categoryList = CategoryManager.GetInstance().GetSubCategory(id);
                categoryList.Add(CategoryItem.Load(id));
                foreach (var category in categoryList)
                {
                    var dbItem1 = DBItem.Create(CONST.DB.DBName_DocService, CONST.DB.CollectionName_CategoryItem, category.id);
                    list.Add(dbItem1);
                    var docList = DocManager.GetInstance().Find("{'CategoryID':'" + dbItem1.ID + "'}", "{}", "{}", 0, int.MaxValue);
                    foreach (var doc in docList)
                    {
                        var dbItem2 = DBItem.Create(CONST.DB.DBName_DocService, CONST.DB.CollectionName_DocItem, doc.ID);
                        list.Add(dbItem2);
                    }
                }
            }
            else
            {
                list.Add(DBItem.Create(dbName, collectionName, id));
            }
            return(list);
        }
Example #2
0
        /// <summary>
        /// 根据新增,修改情况 热词分析 分词 发文/修改统计
        /// </summary>
        public void DataAnalyse()
        {
            var startTime = DateTime.Now;///开始运行时间

            Console.Title = "文档维护进程进程 启动时间:" + startTime;
            while (true)
            {
                ///遍历写入数据
                var dbName         = CONST.DB.DBName_DocService;
                var collectionName = CONST.DB.CollectionName_ModifyLogItem;
                var db             = DataStorage.GetInstance(DBType.MongoDB);
                db.EventTraverse += (object sender, EventArgs e) =>
                {
                    EventProcEventArgs ee = e as EventProcEventArgs;
                    var dict                 = ee.Default as Dictionary <string, object>;
                    var targetDbName         = dict["DatabaseName"].ToString();
                    var targetCollectionName = dict["CollectionName"].ToString();
                    var targetID             = (ObjectId)dict["TargetID"];
                    var id = dict["_id"].ToString();

                    if (targetCollectionName == CONST.DB.CollectionName_DocItem)
                    {
                        ///重新分词,聚类
                        var doc       = new DocItem();
                        var plainText = doc.PlainText;
                        var res       = FenCi.GetResult(plainText);
                        var queryDel  = "{'TargetID':ObjectId('" + targetID.ToString() + "')}";
                        db.Remove(dbName, collectionName, queryDel);
                        foreach (var item in res)
                        {
                            var svItem = new
                            {
                                DbName           = targetDbName,
                                CollectionName   = targetCollectionName,
                                TargetID         = targetID,
                                Word             = item.Key,
                                Count            = item.Value,
                                CreateTime       = DateTime.Now,
                                TargetCreateTime = dict["CreateTime"]
                            };

                            db.Save3(CONST.DB.DBName_DocService, CONST.DB.CollectionName_FenCi, svItem);
                        }
                    }
                    else if (targetCollectionName == CONST.DB.CollectionName_CategoryItem)
                    {
                        ///重新统计,当前目录的子目录数量 , 每一级文档数量
                        var subCategoryList = CategoryManager.GetInstance().GetSubCategory(targetID.ToString());
                        var category        = CategoryItem.Load(targetID.ToString());
                        category.SubCategoryCount = subCategoryList.Count;
                        category.Save();
                    }

                    //ModifyLogItem.Remove(id);
                };
                db.Traverse(dbName, collectionName, "{}");
                ThreadManager.Pause(minutes: 2);
            }
        }
Example #3
0
        public static CategoryItem Load(string id)
        {
            var _id   = ObjectId.Parse(id);
            var query = CONST.DB.MongoDBFilterCreator_ByObjectId(id);
            var inst  = CategoryManager.GetInstance().Find(query);

            return(inst.First());
        }
        public void MoveToRecycleBin(string dbName, string collectionName, string id)
        {
            if (!string.IsNullOrWhiteSpace(dbName) && !string.IsNullOrWhiteSpace(collectionName) && StringChecker.IsObjectId(id))
            {
                var res = this.FindTarget(dbName, collectionName, id);
                var db  = DataStorage.GetInstance(DBType.MongoDB);
                foreach (var item in res)
                {
                    var query          = "{'_id':ObjectId('" + item.ID + "')}";
                    var targetDataItem = new object();
                    if (item.TableName == CONST.DB.CollectionName_CategoryItem)
                    {
                        targetDataItem = CategoryManager.GetInstance().Find(query).First();
                    }
                    else if (item.TableName == CONST.DB.CollectionName_DocItem)
                    {
                        targetDataItem = DocManager.GetInstance().Find(query).First();
                    }

                    db.Save3(CONST.DB.DBName_DocService, CONST.DB.CollectionName_RecycleBin, targetDataItem);
                    db.Remove(item.DatabaseName, item.TableName, query);
                }
            }
        }
Example #5
0
        public List <CategoryItem> Test()
        {
            var res = CategoryManager.GetInstance().Find("{}", "{}", "{}", 0, 1000);

            return(res);
        }
Example #6
0
        /// <summary>
        /// 加载目录
        /// </summary>
        /// <param name="query"></param>
        /// <param name="protection"></param>
        /// <param name="sort"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public List <CategoryItem> LoadCategory(string query, string protection = "{}", string sort = "{}", int pageIndex = 0, int pageSize = 50)
        {
            var res = CategoryManager.GetInstance().Find(query, protection, sort, pageIndex, pageSize);

            return(res);
        }