/// <summary>
		/// Создать дескриптор на основе файла
		/// </summary>
		/// <param name="file"></param>
		
		public WikiObjectDescriptor(WikiBinary file) {
			Code = file.Code;
			Type = WikiObjectType.File;
			ContentType = file.MimeType;
			Size = file.Size;
			Name = file.Title;
			LastWriteTime = file.LastWriteTime;
		}
Esempio n. 2
0
		/// <summary>
		/// Сохраняет файл в Wiki
		/// </summary>
		/// <returns></returns>
		protected override object MainProcess() {
			var srcname = _file.FileName;
			var ext = Path.GetExtension(srcname);
			var mime = MimeHelper.GetMimeByExtension(ext);
			var binobj = new WikiBinary();
			binobj.Code = Code;
			binobj.Title = string.IsNullOrWhiteSpace(Title) ? Code : Title;
			binobj.MimeType = mime;
			var data = new byte[_file.ContentLength];
			using (var s = _file.InputStream) {
				s.Read(data, 0, (int)s.Length);
			}
			binobj.Data = data;
			WikiSource.SaveBinary(binobj);
			return true;
		}
Esempio n. 3
0
        /// <summary>
        /// Сохраняет файл в Wiki
        /// </summary>
        /// <returns></returns>
        protected override object MainProcess()
        {
            var srcname = _file.FileName;
            var ext     = Path.GetExtension(srcname);
            var mime    = MimeHelper.GetMimeByExtension(ext);
            var binobj  = new WikiBinary();

            binobj.Code     = Code;
            binobj.Title    = string.IsNullOrWhiteSpace(Title) ? Code : Title;
            binobj.MimeType = mime;
            var data = new byte[_file.ContentLength];

            using (var s = _file.InputStream) {
                s.Read(data, 0, (int)s.Length);
            }
            binobj.Data = data;
            WikiSource.SaveBinary(binobj);
            return(true);
        }
        /// <summary>
        /// Поиск файлов по маске
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        public IEnumerable<WikiBinary> FindBinaries(string search) {
            var queryJson = "{$or : [{_id : {$regex : '(?ix)_REGEX_'}},{code : {$regex : '(?ix)_REGEX_'}},{'metadata.title':{$regex:'(?ix)_REGEX_'}},{'metadata.owner':{$regex:'(?ix)_REGEX_'}},{contentType:{$regex:'(?ix)_REGEX_'}}]}".Replace("_REGEX_", search);
            var queryDoc = new QueryDocument(BsonDocument.Parse(queryJson));

            foreach (var doc in GridFs.Find(queryDoc).SetFields("code", "metadata.title", "metadata.owner", "length", "contentType", "metadata.lastwrite", "uploadDate", "chunkSize")) {
                var file = new WikiBinary {
                    Code = doc.Id.AsString,
                    Title = doc.Metadata["title"].AsString,
                    LastWriteTime = doc.UploadDate,
                    Size = doc.Length,
                    MimeType = doc.ContentType
                };

                if (doc.Metadata.Contains("lastwrite")) {
                    file.LastWriteTime = doc.Metadata["lastwrite"].ToLocalTime();
                }
                yield return file;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="binary"></param>
        /// <returns></returns>
        private MongoGridFSStream ConvertToMongoGridInfo(WikiBinary binary) {
            return GridFs.Create(
                binary.Code,
                new MongoGridFSCreateOptions {
                    Id = binary.Code,
                    Metadata = new BsonDocument {
                        {"title", binary.Title},
                        {"editor", Application.Principal.CurrentUser.Identity.Name},
                        {"owner", Application.Principal.CurrentUser.Identity.Name},
                        {"lastwrite", DateTime.Now},
		            },
                    UploadDate = DateTime.Now,
                    ContentType = binary.MimeType,
                }
            );
        }
        private MongoGridFSStream CreateStream(WikiBinary binary) {
            if (!GridFs.ExistsById(binary.Code)) {
                return ConvertToMongoGridInfo(binary);
            }
            var info = GridFs.FindOne(binary.Code);
            info.Metadata["editor"] = Application.Principal.CurrentUser.Identity.Name;
            info.Metadata["lastwrite"] = DateTime.Now;
            GridFs.SetMetadata(info, info.Metadata);
            return info.OpenWrite();

        }
        /// <summary>
        /// Сохраняет в Wiki файл с указанным кодом
        /// </summary>
        public void SaveBinary(WikiBinary binary) {
            using (var s = CreateStream(binary)) {
                s.Write(binary.Data, 0, binary.Data.Length);
                s.Flush();
            }

        }
 /// <summary>
 /// Сохраняет в Wiki файл с указанным кодом
 /// </summary>
 public void SaveBinary(WikiBinary binary) {
     CheckPersister();
     CurrentWikiPersister.SaveBinary(binary);
 }