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;
     }
 }
Exemple #2
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;
     }
 }
        public bool DeleteSceneItem(string sceneItemID)
        {
            try
            {
                if (string.IsNullOrEmpty(sceneItemID))
                {
                    throw new KnownException("id为空,无法删除!");
                }
                var mgdb      = new MongoDbProvider <SceneItem>();
                var sceneItem = mgdb.GetAll(o => o.Id == sceneItemID).FirstOrDefault();
                if (null == sceneItem)
                {
                    return(true);
                }
                else if (sceneItem.Status == ItemStatus.Final)
                {
                    throw new KnownException("已经归档,不能删除!");
                }

                //  如果有图片,需要删除图片
                if (null != sceneItem.Images)
                {
                    foreach (var image in sceneItem.Images)
                    {
                        mgdb.DeleteFileByName(image.OriginalPicture, PictureDbName);
                        mgdb.DeleteFileByName(image.ThumbnailPicture, PictureDbName);
                    }
                }
                mgdb.Delete(sceneItemID);

                using (var db = new BCEnterpriseContext())
                {
                    var scene = db.Scenes.First(o => o.SceneID == sceneItem.SceneID);
                    if (scene.HasData && (null == mgdb.GetByCondition(o => o.SceneID == sceneItem.SceneID)))
                    {
                        scene.HasData = false;
                    }
                    db.SaveChanges();
                }
                return(Send2MsmqAsDelete(sceneItemID, OperationEnum.Deleted, sceneItem.SceneID));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #4
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);
        }