示例#1
0
        /// <summary>
        /// Get collection of given database and collection name.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dbName"></param>
        /// <param name="collectionName"></param>
        /// <returns></returns>
        public IMongoCollection <T> GetCollection <T>(string dbName = DatabaseConstants.DefaultDatabaseName, string collectionName = null) where T : IDataModel
        {
            collectionName = collectionName ?? typeof(T).Name;
            var res = _client == null?MongoDbProvider.GetCollection <T>(dbName, collectionName) : _client.GetDatabase(dbName).GetCollection <T>(collectionName);

            return(res);
        }
示例#2
0
 public SceneItem AddCommentItem(string sceneItemID, Comment comment, ItemStatus status)
 {
     try
     {
         if (string.IsNullOrEmpty(sceneItemID) || null == comment)
         {
             throw new KnownException("id或信息对象为空,无法添加!");
         }
         var db   = new MongoDbProvider <SceneItem>();
         var item = db.GetById(sceneItemID);
         if (item == null)
         {
             throw new KnownException("此数据在服务器上已被删除,请手动删除此条数据!");
         }
         if (ItemStatus.Final == item.Status)
         {
             throw new KnownException("已经归档,无法评论!");
         }
         if (item.Comments == null)
         {
             item.Comments = new List <Comment>();
         }
         comment.Time = DBTimeHelper.DBNowTime();
         item.Comments.Add(comment);
         item.Status     = status;
         item.UpdateTime = DBTimeHelper.DBNowTime();
         var re = db.Update(item);
         re.Images = MakeUrlWithPictureName(re.Images);
         return(re);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#3
0
 public InfoStatisticsDto GetEnterpriseInfoStatistics(string enterpriseId)
 {
     try
     {
         using (var db = new BCEnterpriseContext())
         {
             var mgdb            = new MongoDbProvider <SceneItem>();
             var users           = db.FrontUsers.Where(x => x.EnterpiseID.Equals(enterpriseId)).Count();
             var projects        = db.Projects.Where(x => !x.Deleted && x.EnterpriseID.Equals(enterpriseId)).Count();
             var sceneIDlist     = db.Scenes.Where(x => !x.Deleted && x.EnterpriseID.Equals(enterpriseId)).Select(n => n.SceneID).ToList();
             var pictrues        = mgdb.GetAll(x => sceneIDlist.Contains(x.SceneID)).Select(n => n.Count).Sum();
             var sceneItemStatus = mgdb.GetAll(x => x.Status == ItemStatus.Redo && sceneIDlist.Contains(x.SceneID) && !x.IsExamine).Count();
             return(new InfoStatisticsDto()
             {
                 Users = users,
                 Scenes = sceneIDlist.Count(),
                 Projects = projects,
                 Pictures = pictrues,
                 ItemStatus = sceneItemStatus
             });
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public bool AddLog(OperationLog log)
        {
            try
            {
                if (null == log)
                {
                    return(false);
                }
                if (string.IsNullOrEmpty(log.ClientIP) || string.IsNullOrEmpty(log.UserID) ||
                    string.IsNullOrEmpty(log.EnterpriseID) || string.IsNullOrEmpty(log.EnterpriseID))
                {
                    var logger = log4net.LogManager.GetLogger(typeof(OperationLogService));
                    logger.Error("缺失必要日志信息IP:" + log.ClientIP + ",UserID:" + log.UserID + ",EnterpriseID:" + log.EnterpriseID + ",OperationID:" + log.EnterpriseID + "");
                }

                var db = new MongoDbProvider <OperationLog>();
                db.Insert(log);
                return(true);
            }
            catch (Exception ex)
            {
                //  输出到log4net
                var msg    = ex.Message;
                var logger = log4net.LogManager.GetLogger(typeof(OperationLogService));
                logger.Error(msg);
                return(false);
            }
        }
        //  可选优化,IEnumerable查询会加载所有结果,IQueryable只会加载分页结果
        //  controller已确保EnterpriseID的正确使用
        private static IEnumerable <OperationLog> SearchOperationLogsByMongo(SearchLogConditionDto condition)
        {
            try
            {
                IEnumerable <OperationLog> reList;
                List <string> uIDList = new List <string>();
                var           mgdb    = new MongoDbProvider <OperationLog>();

                //  不存在UserID时候查询过程
                if (string.IsNullOrEmpty(condition.UserID))
                {
                    using (var db = new BCEnterpriseContext())
                    {
                        uIDList = db.FrontUsers.Where(obj => (string.IsNullOrEmpty(condition.EnterpriseID) ? true : obj.EnterpiseID == condition.EnterpriseID) && (string.IsNullOrEmpty(condition.UserName) ? true : obj.Name.Contains(condition.UserName))).Select(o => o.UserID).ToList();
                    }
                    if (0 == uIDList.Count)
                    {
                        if (string.IsNullOrEmpty(condition.OperationID))
                        {
                            // 第一次显示操作日志判断
                            reList = mgdb.GetAll(obj => (string.IsNullOrEmpty(condition.EnterpriseID) || obj.EnterpriseID == condition.EnterpriseID) && (obj.OperateTime > (condition.StartTime ?? DateTime.MinValue)) &&
                                                 (obj.OperateTime < (condition.EndTime ?? DateTime.Now)));
                        }
                        else
                        {
                            //  UserID和UserName为空,仅根据企业ID和操作ID查询
                            reList = mgdb.GetAll(obj => (string.IsNullOrEmpty(condition.EnterpriseID) || obj.EnterpriseID == condition.EnterpriseID) &&
                                                 (obj.OperationID.ToLower().Contains(condition.OperationID.ToLower())) &&
                                                 (obj.OperateTime > (condition.StartTime ?? DateTime.MinValue)) &&
                                                 (obj.OperateTime < (condition.EndTime ?? DateTime.Now)));
                        }
                    }
                    else
                    {
                        //  输入UserName查询得到uIDList模糊查询
                        var tempCondition = string.IsNullOrEmpty(condition.OperationID) ? "" : condition.OperationID.ToLower();
                        reList = mgdb.GetAll(obj => (uIDList.Contains(obj.UserID)) &&
                                             (string.IsNullOrEmpty(condition.EnterpriseID) || obj.EnterpriseID == condition.EnterpriseID) &&
                                             (string.IsNullOrEmpty(condition.OperationID) || obj.OperationID.ToLower().Contains(tempCondition)) &&
                                             (obj.OperateTime > (condition.StartTime ?? DateTime.MinValue)) &&
                                             (obj.OperateTime < (condition.EndTime ?? DateTime.Now)));
                    }
                }

                //  指定UserID查询过程
                else
                {
                    //  指定了UserID查询
                    reList = mgdb.GetAll(obj => (obj.UserID == condition.UserID) &&
                                         (string.IsNullOrEmpty(condition.EnterpriseID) || obj.EnterpriseID == condition.EnterpriseID) &&
                                         (obj.OperateTime > (condition.StartTime ?? DateTime.MinValue)) &&
                                         (obj.OperateTime < (condition.EndTime ?? DateTime.Now)));
                }
                return(reList);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#6
0
 public byte[] DownLoading(Guid fileGuid)
 {
     try
     {
         var mgdb = new MongoDbProvider <KnowledgeBaseFile>();
         using (var db = new BCEnterpriseContext())
         {
             var filelist = db.KnowledgeBase.Where(x => x.FileGUID == fileGuid && !x.Deleted).OrderBy(n => n.FileNumber).ToList();
             if (!(filelist.Count() > 0))
             {
                 throw new Exception("没有在数据库中找到该Guid");
             }
             byte[] filearry = new byte[Convert.ToInt32(filelist.First().FileAllSize)];
             byte[] temp     = null;
             double flag     = 0;
             foreach (var file in filelist)
             {
                 temp = mgdb.GetFileAsStream(file.ID, KnowlegeDbName);
                 temp.CopyTo(filearry, Convert.ToInt64(flag));
                 flag = flag + file.DocumentSize;
             }
             return(filearry);
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
示例#7
0
 public bool DeleteFile(Guid fileGuid)
 {
     try
     {
         if (null == fileGuid)
         {
             return(false);
         }
         var mgdb = new MongoDbProvider <KnowledgeBaseFile>();
         using (var db = new BCEnterpriseContext())
         {
             var list = db.KnowledgeBase.Where(x => x.FileGUID == fileGuid);
             if (list.Count() > 0)
             {
                 foreach (var file in list)
                 {
                     file.Deleted = true;
                     mgdb.DeleteFileByName(file.ID, KnowlegeDbName);
                 }
             }
             return(0 < db.SaveChanges());
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
示例#8
0
 public InfoStatisticsDto GetBackInfoStatistics()
 {
     try
     {
         using (var db = new BCEnterpriseContext())
         {
             var mgdb            = new MongoDbProvider <SceneItem>();
             var users           = db.FrontUsers.Count();
             var projects        = db.Projects.Where(x => !x.Deleted).Count();
             var scenes          = db.Scenes.Where(x => !x.Deleted).Count();
             var pictrues        = mgdb.GetAll(x => true).Select(n => n.Count).Sum();
             var sceneItemStatus = mgdb.GetAll(x => x.Status == ItemStatus.Redo && !x.IsExamine && !x.IsExamine).Count();
             return(new InfoStatisticsDto()
             {
                 Users = users,
                 Scenes = scenes,
                 Projects = projects,
                 Pictures = pictrues,
                 ItemStatus = sceneItemStatus
             });
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public void DeleteSceneItemPicture(string sceneItemId, string orgPicName)
 {
     try
     {
         if (string.IsNullOrEmpty(sceneItemId) || string.IsNullOrEmpty(orgPicName))
         {
             throw new KnownException("参数不允许为空");
         }
         var db        = new MongoDbProvider <SceneItem>();
         var sceneItem = db.GetById(sceneItemId);
         if (null == sceneItem)
         {
             throw new KnownException("该现场数据不存在");
         }
         var pic = sceneItem.Images.FirstOrDefault(x => x.OriginalPicture.Equals(orgPicName));
         if (pic != null)
         {
             var orglen = db.GetFileAsStream(orgPicName, PictureDbName).Length;
             var thulen = db.GetFileAsStream(pic.ThumbnailPicture, PictureDbName).Length;
             db.DeleteFileByName(pic.OriginalPicture, PictureDbName);
             db.DeleteFileByName(pic.ThumbnailPicture, PictureDbName);
             sceneItem.TotalOrgImageBytes = sceneItem.TotalOrgImageBytes - orglen - thulen;
             sceneItem.Images.Remove(pic);
             sceneItem.UpdateTime = DBTimeHelper.DBNowTime();
             sceneItem.Count      = sceneItem.Count - 1;
             db.Update(sceneItem);
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public bool SyncSceneItemStatusAndComments(string sceneItemID, ItemStatus status, Comment[] comments)
 {
     try
     {
         if (string.IsNullOrEmpty(sceneItemID))
         {
             throw new ArgumentNullException("sceneItemID");
         }
         var db   = new MongoDbProvider <SceneItem>();
         var item = db.GetById(sceneItemID);
         if (item == null)
         {
             throw new KnownException("此现场数据不存在.");
         }
         item.Comments   = comments.ToList();
         item.Status     = status;
         item.UpdateTime = DBTimeHelper.DBNowTime();
         db.Update(item);
         return(true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public bool SetSceneItemStatus(string sceneItemID, Examine examine)
        {
            try
            {
                if (string.IsNullOrEmpty(sceneItemID))
                {
                    throw new KnownException("id为空,无法设置!");
                }
                var db = new MongoDbProvider <SceneItem>();
//                var item = db.GetByCondition(x=>x.);
                //if (examine.ExamineStatus == ItemStatus.Final)
                //{
                //    SetSceneStatusFinal(sceneItemID);
                //}
                var tempstring = GetSceneItemByRelation(sceneItemID, db);
                var item       = db.GetByCondition(x => x.Id == tempstring);
                item.Status  = examine.ExamineStatus;
                examine.Time = DBTimeHelper.DBNowTime();
                (item.Examines ?? new List <Examine>()).Add(examine);
                item.UpdateTime = examine.Time;
                db.Update(item);
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public bool DeleteCommentItem(string sceneItemID, Guid commentGuid, DateTime updateTime)
        {
            var mgdb      = new MongoDbProvider <SceneItem>();
            var sceneItem = mgdb.GetById(sceneItemID);

            if (sceneItem.Status == ItemStatus.Final)
            {
                throw new KnownException("已经归档,无法删除");
            }
            var del = sceneItem.Comments.FirstOrDefault(o => o.CommentGuid == commentGuid);

            if (null == del)
            {
                throw new KnownException("评论不存在,无法删除");
            }
            if (sceneItem.Comments.Remove(del))
            {
                sceneItem.UpdateTime = DBTimeHelper.DBNowTime();
            }
            mgdb.Update(sceneItem);

            //  删除评论分发消息
            Send2MsmqAsDelete(commentGuid.ToString(), OperationEnum.Deleted, sceneItem.SceneID);
            return(true);
        }
示例#13
0
        public List <UserMessageQueueItem> PopupUserMessageQueueItem(string userId, string device)
        {
            if (userId == null)
            {
                throw new ArgumentNullException("userId");
            }
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            var db     = new MongoDbProvider <UserMessageQueueItem>();
            var list   = db.GetAll(n => n.State == AppSyncDataStateEnum.Normal && n.UserID == userId && n.Device == device).ToList();
            var result = list.ToArray().Clone() as UserMessageQueueItem[];

            foreach (var l in list)
            {
                l.Time = l.Time.ToLocalTime();
                var chatMessage = l.Data as ChatMessage;
                if (chatMessage == null)
                {
                    continue;
                }
                chatMessage.SendTime = chatMessage.SendTime.ToLocalTime();
                chatMessage.IsRead   = ReadStatus.Read;
            }
            list.ForEach(n =>
            {
                n.State      = AppSyncDataStateEnum.Sent;
                n.UpdateTime = DBTimeHelper.DBNowTime();
                db.Update(n);
            });

            return(null != result?result.ToList() : new List <UserMessageQueueItem>());
        }
示例#14
0
        public static void ImportProductReportsFromSqlServer()
        {
            SuperMarketContext supermarketDb = new SuperMarketContext();

            var salesInfo =
                from sale in supermarketDb.Sales
                join product in supermarketDb.Products
                on sale.ProductId equals product.ID
                select new
            {
                ProductId   = product.ID,
                ProductName = product.ProductName,
                VendorName  = product.Vendor.VendorName,
                Quantity    = supermarketDb.Sales.Where(s => s.ProductId == product.ID).Select(s => s.Quantity).Sum(),
                Income      = supermarketDb.Sales.Where(s => s.ProductId == product.ID).Select(s => s.Sum).Sum()
            };

            foreach (var sale in salesInfo)
            {
                Mongo.Product product = new Mongo.Product();
                product.ProductId         = sale.ProductId;
                product.ProductName       = sale.ProductName;
                product.VendorName        = sale.VendorName;
                product.TotalQuantitySold = sale.Quantity;
                product.TotalIncomes      = sale.Income;

                int productId = MongoDbProvider.LoadData <Mongo.Product>().Where(x => x.ProductId == sale.ProductId).Select(x => x.ProductId).FirstOrDefault();
                if (productId == 0)
                {
                    MongoDbProvider.SaveData <Mongo.Product>(product);
                }
            }
        }
示例#15
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var log          = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            var errorHandler = new ErrorHandler(log);

            var dbProvider           = new MongoDbProvider(errorHandler);
            var defBuilder           = new MongoDbDefinitionBuilder();
            var encryptor            = new Encryptor();
            var serversProvider      = new ServersProvider(dbProvider, defBuilder, encryptor);
            var tcpListener          = new TcpListenerWrapper();
            var streamFactory        = new StreamFactory();
            var stripMessenger       = new StripMessenger(errorHandler);
            var httpProcessorFactory = new HttpProcessorFactory();

            var mainForm = new MainForm(
                serversProvider,
                new PlayersProvider(dbProvider, defBuilder, encryptor),
                dbProvider,
                new MasterServerHttpServer(tcpListener,
                                           streamFactory,
                                           serversProvider,
                                           httpProcessorFactory,
                                           encryptor,
                                           stripMessenger),
                stripMessenger);

            Application.Run(mainForm);
        }
示例#16
0
 public bool UpLoading(KnowlegeDto newFile)
 {
     try
     {
         var mgdb = new MongoDbProvider <KnowledgeBaseFile>();
         using (var db = new BCEnterpriseContext())
         {
             var temp = new KnowledgeBase();
             temp.ID            = newFile.ID;
             temp.Name          = newFile.Name;
             temp.EnterpriseID  = newFile.EnterpriseID;
             temp.Deleted       = newFile.Deleted;
             temp.DocumentSize  = newFile.DocumentSize;
             temp.DocumentType  = (int)newFile.DocumentType;
             temp.KnowledgeType = newFile.KnowledgeType;
             temp.UpdateTime    = newFile.UpdateTime;
             temp.FileGUID      = newFile.FileGUID;
             temp.FileNumber    = newFile.FileNumber;
             temp.FileAllSize   = newFile.FileAllSize;
             db.KnowledgeBase.Add(temp);
             mgdb.SaveFileByStream(newFile.FileStream, newFile.ID, KnowlegeDbName);
             return(0 < db.SaveChanges());
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        private DepartmentInfoFormDto GetDepartmentInfoFormOfMyDepartment(int?departmentId, string enterpriseId, DateTime?beginTime, DateTime?endTime, BCEnterpriseContext db)
        {
            try
            {
                var mgdb = new MongoDbProvider <SceneItem>();
                //get my sceneId
                var scenlist = (from scene in db.Scenes
                                join project in db.Projects on scene.ProjectID equals project.ProjectID
                                where project.EnterpriseID == enterpriseId
                                select new
                {
                    SceneId = scene.SceneID,
                    Deleted = scene.Deleted,
                    RegistDate = scene.RegistDate,
                    Departments = project.Departments
                }).ToList();
                //由原来获取当前部门下的所有部门的现场数 改为 获取当前部门的现场数
                var scenelist = scenlist.Where(o => o.Departments.Split("|".ToCharArray()).Any(x => x == (!departmentId.HasValue ? "" : departmentId.Value.ToString())));
                //get projectId in my department
                var projectlist = db.Projects.Where(x => !x.Deleted).ToList();
                //由原来获取当前部门下的所有部门的项目数 改为 获取当前部门的项目数
                var newprolist = projectlist.Where(x => x.Departments.Split("|".ToCharArray()).Any(n => n == (!departmentId.HasValue ? "" : departmentId.Value.ToString())));
                //get pictures of scene on my department
                var sceneIdlist = scenelist.Select(x => x.SceneId);

                var Picount = mgdb.GetAll(x => sceneIdlist.Contains(x.SceneID) && (x.CreateTime > (beginTime ?? DateTime.MinValue)) && (x.CreateTime < (endTime ?? DateTime.MaxValue))).Select(n => n.Count).Sum();
                var pByte   = mgdb.GetAll(x => sceneIdlist.Contains(x.SceneID) && (x.CreateTime > (beginTime ?? DateTime.MinValue)) && (x.CreateTime < (endTime ?? DateTime.MaxValue))).Select(n => n.TotalOrgImageBytes).Sum();
                //由原来获取属于当前部门及其子部门的人 改成只获取属于当前部门的人
                var userlist = db.FrontUsers.Where(x => x.DepartmentID == departmentId);


                var depart = db.Departments.FirstOrDefault(x => x.DepartmentID == departmentId.Value);

                return(new DepartmentInfoFormDto
                {
                    DepartmentName = depart.Name,
                    DepartmentID = depart.DepartmentID,
                    ParentID = depart.ParentID,
                    PictureByte = pByte,
                    //get users in my department
                    UsersCount = userlist.Where(n =>
                                                n.EnterpiseID.Equals(enterpriseId) &&
                                                n.RegistDate <(endTime ?? DateTime.MaxValue) &&
                                                              n.RegistDate> (beginTime ?? DateTime.MinValue)).Count(),
                    ProjectCount = newprolist.Where(n =>
                                                    n.RegistDate > (beginTime ?? DateTime.MinValue) &&
                                                    n.RegistDate < (endTime ?? DateTime.MaxValue)).Count(),
                    SceneCount = scenelist.Where(n =>
                                                 !n.Deleted &&
                                                 n.RegistDate > (beginTime ?? DateTime.MinValue) &&
                                                 n.RegistDate < (endTime ?? DateTime.MaxValue)).Count(),
                    PictureCount = Picount
                });
            }
            catch (Exception e)
            {
                throw e;
            }
        }
示例#18
0
 static void Main(string[] args)
 {
     _configProvider  = new ConfigProvider();
     _mongoDbProvider = new MongoDbProvider(_configProvider);
     _imageConverter  = new ImageToByteArrayToByteArrayConverer();
     MigrateAbout();
     MigrateContaqct();
 }
 public ProjectStatisDto GetAllProjectStatisInfo(string enterpriseId, int?departmentID, out int amount)
 {
     try
     {
         using (var db = new BCEnterpriseContext())
         {
             var result = new ProjectStatisDto();
             var depart = GetOwnerDepartment(departmentID ?? 0, db).Select(x => x.DepartmentID.ToString()).ToList();
             depart.Add((departmentID ?? -1).ToString());
             var ProjList    = db.Projects.Where(p => p.EnterpriseID.Equals(enterpriseId) && p.Deleted == false).ToList();
             var allProjList = ProjList.Where(p => p.Departments.Split("|".ToCharArray()).Any(x => depart.Contains(x)));
             if ((amount = allProjList.Count()) < 1)
             {
                 amount = 0;
                 return(result);
             }
             else
             {
                 var mgdb = new MongoDbProvider <SceneItem>();
                 foreach (var proj in allProjList)
                 {
                     //计算各类型数量
                     for (int i = 0; i < 7; i++)
                     {
                         List <string> sceneIDs = new List <string>();
                         int           idx      = 0;
                         if (i != 0 && i != 5)
                         {
                             idx      = (int)Math.Pow(2, i);
                             sceneIDs = db.Scenes.Where(s => s.ProjectID.Equals(proj.ProjectID) && s.Deleted == false).Select(s => s.SceneID).ToList();
                         }
                         if (sceneIDs.Count() < 1)
                         {
                             result.typeCount[i] += 0;
                         }
                         else
                         {
                             try
                             {
                                 result.typeCount[i] += (int)mgdb.Count(s => sceneIDs.Contains(s.SceneID) && s.Type.Equals(idx));
                             }
                             catch (Exception)
                             {
                                 result.typeCount[i] += 0;
                             }
                         }
                     }
                 }
                 result.projectName = "所有项目";
                 return(result);
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
示例#20
0
        public string MakeUrlWithFileName(string fileName)
        {
            if (null == fileName)
            {
                return(null);
            }
            var mgdb = new MongoDbProvider <KnowledgeBaseFile>();

            using (var db = new BCEnterpriseContext())
            {
                var fileGuid     = db.KnowledgeBase.First(x => x.ID.Equals(fileName)).FileGUID;
                var fileNameList = db.KnowledgeBase.Where(x => x.FileGUID == fileGuid && !x.Deleted).OrderBy(n => n.FileNumber);
                var newobj       = fileNameList.First();
                if (1 < fileNameList.Count())
                {
                    byte[] filearry = new byte[Convert.ToInt64(fileNameList.First().FileAllSize)];
                    byte[] tempobj  = null;
                    double flag     = 0;
                    foreach (var file in fileNameList)
                    {
                        tempobj = mgdb.GetFileAsStream(file.ID, KnowlegeDbName);
                        if (0 != tempobj.Length)
                        {
                            tempobj.CopyTo(filearry, Convert.ToInt64(flag));
                            flag = flag + file.DocumentSize;
                        }
                    }
                    if (filearry.Length > 0)
                    {
                        Stream stream      = new MemoryStream(filearry);
                        var    newFileName = fileName.Replace(fileName.Split('.')[0], DateTime.Now.ToFileTime().ToString());
                        mgdb.SaveFileByStream(stream, newFileName, KnowlegeDbName);
                        var temp = new KnowledgeBase();
                        temp.ID            = newFileName;
                        temp.Name          = newobj.Name;
                        temp.EnterpriseID  = newobj.EnterpriseID;
                        temp.Deleted       = newobj.Deleted;
                        temp.DocumentSize  = newobj.FileAllSize;
                        temp.DocumentType  = (int)newobj.DocumentType;
                        temp.KnowledgeType = newobj.KnowledgeType;
                        temp.UpdateTime    = newobj.UpdateTime;
                        temp.FileGUID      = newobj.FileGUID;
                        temp.FileNumber    = newobj.FileNumber;
                        temp.FileAllSize   = newobj.FileAllSize;
                        db.KnowledgeBase.Add(temp);
                        foreach (var file in fileNameList)
                        {
                            mgdb.DeleteFileByName(file.ID, KnowlegeDbName);
                            db.KnowledgeBase.Remove(file);
                        }
                        fileName = newFileName;
                    }
                }
            }
            var baseUrl = ConfigurationManager.ConnectionStrings["FileBaseUrlByName"].ToString();

            return(baseUrl + fileName);
        }
示例#21
0
 public MongoDbProviderTests()
 {
     _dbProvider = new MongoDbProvider();
     _dbProvider.ConnectionString = ConnectionString;
     _dbProvider.Database         = "euro_monitor_db_dev";
     _dbProvider.Collection       = "users_test";
     _dbProvider.Initialize();
     _client = new MongoClient(ConnectionString);
 }
示例#22
0
        public RectificationStatisticalDto GetRectificationStatistical(string enterpriseID, int?departmentID, string userID)
        {
            try
            {
                var mgdb = new MongoDbProvider <SceneItem>();
                using (var db = new BCEnterpriseContext())
                {
                    var itemAllList = new List <SceneItem>();
                    if (string.IsNullOrEmpty(userID))
                    {
                        var departmentlist = GetOwnerDepartment(departmentID ?? -1, db);

                        var tempscenelist = (from scene in db.Scenes
                                             join project in db.Projects on scene.ProjectID equals project.ProjectID
                                             where project.EnterpriseID == enterpriseID && !project.Deleted && !scene.Deleted
                                             select new
                        {
                            DepartmentIDs = project.Departments,
                            SceneID = scene.SceneID
                        }).ToList();

                        var scenelist =
                            tempscenelist.Where(
                                x => x.DepartmentIDs.Split("|".ToCharArray()).Contains(departmentID.ToString())).Select(n => n.SceneID).ToList();
                        //所有现场数据
                        itemAllList = mgdb.GetAll(x => scenelist.Contains(x.SceneID)).ToList();
                    }
                    else
                    {
                        //所有现场数据
                        itemAllList = mgdb.GetAll(x => x.UserID.Equals(userID)).ToList();
                    }

                    //当前需要整改现场数据
                    var itemRectificationList = itemAllList.Where(x => (x.Examines ?? new List <Examine>()).Any(n => n.ExamineStatus == ItemStatus.Redo));
                    var itemtemlist           = itemAllList.Where(x => x.Examines != null);
                    //在记录操作状态的Examine集合中,最后一个记录状态不为整改,但是在这个集合中至少有一个为需要整改,则记录该条为整改完成.整改完成的现场数据
                    var itemFinishList =
                        itemtemlist.Where(
                            x => (((x.Examines.OrderByDescending(n => n.Time).First()).ExamineStatus !=
                                   ItemStatus.Redo) && (x.Examines.Any(m => m.ExamineStatus == ItemStatus.Redo))));
                    var pictureCount = itemAllList.Select(x => x.Count).Sum();
                    var stallitem    = itemAllList.Where(x => "" == x.Relation);
                    return(new RectificationStatisticalDto()
                    {
                        FinishCount = itemFinishList.Count(),
                        RectificationCount = itemRectificationList.Count(),
                        AllCount = stallitem.Count(),
                        PictureCount = pictureCount
                    });
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
示例#23
0
 /// <summary>
 /// Drop databse.
 /// </summary>
 /// <param name="dbName"></param>
 /// <returns></returns>
 public async Task Drop(string dbName = DatabaseConstants.DefaultDatabaseName)
 {
     if (_client == null)
     {
         await MongoDbProvider.DropDatabase(dbName);
     }
     else
     {
         await _client.DropDatabaseAsync(dbName);
     }
 }
示例#24
0
        public bool ConfirmSentSuccess(List <string> userMessaeQueueItemIDs)
        {
            if (userMessaeQueueItemIDs == null)
            {
                throw new ArgumentNullException("userMessaeQueueItemIDs");
            }
            var db = new MongoDbProvider <UserMessageQueueItem>();

            db.Delete(n => userMessaeQueueItemIDs.Any(m => n.Id == m) && n.State == AppSyncDataStateEnum.Sent);
            return(true);
        }
示例#25
0
        public void UpdateMatchDetails()
        {
            var colName     = "england";
            var provider    = new MongoDbProvider("soccerstand");
            var collections = provider.GetEntities <SoccerstandData>(colName);

            var mapping = new Dictionary <string, ConverterParth>
            {
                { "#match-summary", ConverterParth.MatchSummary },
                { "#match-statistics;0", ConverterParth.Statistics },
                { "#odds-comparison", ConverterParth.Odds }
            };

            foreach (var collection in collections)
            {
                foreach (var soccerstandMatch in collection.Matches)
                {
                    if (soccerstandMatch.Type == SoccerstandMatchType.Fixture && soccerstandMatch.DateTime.Date >= DateTime.Now.Date)
                    {
                        continue;
                    }

                    var driver = new ChromeDriver();

                    foreach (var mapItem in mapping)
                    {
                        var url = $"https://www.soccerstand.com/match/{soccerstandMatch.OriginId}/{mapItem.Key}";
                        driver.Navigate().GoToUrl(url);
                        var source = driver.PageSource;

                        switch (mapItem.Value)
                        {
                        case ConverterParth.MatchSummary:
                            var matchSummary = new MatchSummaryConverter().Convert(source);
                            soccerstandMatch.Referee    = matchSummary.Referee;
                            soccerstandMatch.Venue      = matchSummary.Venue;
                            soccerstandMatch.Attendance = matchSummary.Attendance;
                            break;

                        case ConverterParth.Statistics:
                            //var matchStatistics = new StatisticsConverter().Convert(source);
                            break;

                        case ConverterParth.Odds:
                            var matchOdds = new OddsConverter().Convert(source);
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                        }
                    }
                }
            }
        }
        public bool SavePicture(Picture picture)
        {
            try
            {
                if (null == picture || string.IsNullOrEmpty(PictureDbName))
                {
                    throw new KnownException("图片信息不存在!");
                }
                var  orgPicName    = "org" + picture.PictureName;
                var  thuPicName    = "thu" + picture.PictureName;
                long thuImageBytes = 0;
                long orgImageBytes = 0;

                var db = new MongoDbProvider <SceneItem>();
                db.SaveFileByStream(picture.PictureStream, orgPicName, PictureDbName);
                orgImageBytes = picture.PictureStream.Length;

                //  缩略图
                var miniStream = ImageHelper.MakeThumbnailImage(picture.PictureStream);
                db.SaveFileByStream(miniStream, thuPicName, PictureDbName);
                thuImageBytes = miniStream.Length;

                var sessionUrlData = HttpContext.Current.Session[picture.PictureGuid.ToString()] as List <ImageInfo>;
                if (sessionUrlData == null)
                {
                    sessionUrlData = new List <ImageInfo> {
                        new ImageInfo()
                        {
                            OriginalPicture  = orgPicName,
                            ThumbnailPicture = thuPicName,
                            OrgImageBytes    = orgImageBytes,
                            ThuImageBytes    = thuImageBytes
                        }
                    };
                    HttpContext.Current.Session[picture.PictureGuid.ToString()] = sessionUrlData;
                }
                else
                {
                    sessionUrlData.Add(new ImageInfo()
                    {
                        OriginalPicture  = orgPicName,
                        ThumbnailPicture = thuPicName,
                        OrgImageBytes    = orgImageBytes,
                        ThuImageBytes    = thuImageBytes
                    });
                }
                picture.PictureStream.Dispose();
                return(true);
            }
            catch (Exception ex)
            {
                throw new KnownException(ex.Message);
            }
        }
 public void Setup()
 {
     _configProvider = Substitute.For <IConfigProvider>();
     _configProvider.Get("mongo.host").Returns("ds063150.mongolab.com");
     _configProvider.Get("mongo.port").Returns("63150");
     _configProvider.Get("mongo.database").Returns("phillipjbuttrose");
     _configProvider.Get("mongo.user").Returns("pjb");
     _configProvider.Get("mongo.password").Returns("pjb");
     _providerUnderTest = new MongoDbProvider(_configProvider);
     _imageConverter    = new ImageToByteArrayToByteArrayConverer();
 }
示例#28
0
 public List <SyncStateDto> GetExistSyncStateDtosBySceneItemID(string sceneItemID)
 {
     try
     {
         var mgdb    = new MongoDbProvider <SceneItem>();
         var sceneID = mgdb.GetById(sceneItemID).SceneID;
         return(GetExistSyncStateDtosBySceneID(sceneID));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#29
0
        public static void ImportExpensesReportsFromXml()
        {
            var expenses = ReadXML.GetObjects("..\\..\\..\\Vendors-Expenses.xml");

            foreach (var expense in expenses)
            {
                Mongo.Expense newExpense = new Mongo.Expense();
                newExpense.VendorName = expense.Item1;
                newExpense.Month      = expense.Item2;
                newExpense.Value      = expense.Item3;

                MongoDbProvider.SaveData <Mongo.Expense>(newExpense);
            }
        }
示例#30
0
 public ProjectStatisDto GetAllProjectStatisInfo(string enterpriseId, out int amount)
 {
     try
     {
         using (var db = new BCEnterpriseContext())
         {
             var result      = new ProjectStatisDto();
             var allProjList = db.Projects.Where(p => p.EnterpriseID.Equals(enterpriseId) && p.Deleted == false);
             if ((amount = allProjList.Count()) < 1)
             {
                 amount = 0;
                 return(result);
             }
             else
             {
                 var mgdb = new MongoDbProvider <SceneItem>();
                 foreach (var proj in allProjList)
                 {
                     //计算各类型数量
                     for (int i = 0; i < 7; i++)
                     {
                         var sceneIDs = db.Scenes.Where(s => s.ProjectID.Equals(proj.ProjectID) && s.Deleted == false).Select(s => s.SceneID).ToList();
                         if (sceneIDs.Count() < 1)
                         {
                             result.typeCount[i] += 0;
                         }
                         else
                         {
                             try
                             {
                                 int idx = (int)Math.Pow(2, i);
                                 result.typeCount[i] += (int)mgdb.Count(s => sceneIDs.Contains(s.SceneID) && s.Type.Equals(idx));
                             }
                             catch (Exception)
                             {
                                 result.typeCount[i] += 0;
                             }
                         }
                     }
                 }
                 result.projectName = "所有项目";
                 return(result);
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }