Пример #1
0
        /// <summary>
        /// 粘贴文件
        /// </summary>
        private void PasteFile(IDataObject obj)
        {
            var files = obj.GetData(DataFormats.FileDrop) as string[];

            if (files == null)
            {
                return;
            }

            var docDao = new DocDao();
            var keyDao = new KeyDao();

            foreach (var file in files)
            {
                if (Directory.Exists(file))
                {
                    ImportCat(_CurrCat, file);
                    continue;
                }

                if (File.Exists(file))
                {
                    var docDto = ImportImg(docDao, keyDao, _CurrCat, file);
                    if (docDto != null)
                    {
                        docDto.Prepare();
                        _Docs.Add(docDto);
                    }
                    continue;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 以文件为单位导入
        /// </summary>
        /// <param name="cat"></param>
        /// <param name="files"></param>
        /// <returns>成功导入的数量</returns>
        private int ImportImg(DocDto cat, string[] files)
        {
            if (files == null)
            {
                return(0);
            }

            var qty    = 0;
            var docDao = new DocImgDao();
            var keyDao = new KeyDao();

            foreach (var srcFile in files)
            {
                var docDto = ImportImg(docDao, keyDao, cat, srcFile);
                if (docDto == null)
                {
                    continue;
                }

                _Docs.Add(docDto);
                qty += 1;
            }

            return(qty);
        }
Пример #3
0
        /// <summary>
        /// 执行文件导入
        /// </summary>
        /// <param name="docDao"></param>
        /// <param name="keyDao"></param>
        /// <param name="cat"></param>
        /// <param name="srcFile"></param>
        /// <returns></returns>
        private DocDto ImportImg(DocDao docDao, KeyDao keyDao, DocDto cat, string srcFile)
        {
            var name = Path.GetFileName(srcFile);

            var dstFile = DocDto.Combine(cat.FullRelativeFile, name);

            var docDto = new DocImgDto();

            docDto.names = cat.GenDocName(name);
            docDto.path  = dstFile;
            docDto.pid   = cat.id;
            docDto.Init(_Cfg);

            var key = DocImgDto.GetFileHash(srcFile);

            if (string.IsNullOrEmpty(key))
            {
                if (!docDto.ImportFile(srcFile, false))
                {
                    return(null);
                }
            }

            var keyDto = keyDao.Read(key);

            if (keyDto == null)
            {
                keyDto       = new KeyDto();
                keyDto.names = name;
                keyDto.key   = key;
                keyDto.qty   = 1;
                keyDto.file  = dstFile;
                keyDao.Save(keyDto);

                if (!docDto.ImportFile(srcFile, false))
                {
                    return(null);
                }
            }
            else
            {
                keyDto.qty += 1;
                keyDao.Change(keyDto.id, 1);
            }

            docDto.key = keyDto.id;
            docDao.Save(docDto);

            return(docDto);
        }
Пример #4
0
        public async Task <KeyDao> CreateKey(KeyDao key, CancellationToken cancellationToken)
        {
            Guard.Argument(key, nameof(key)).NotNull();
            Guard.Argument(key.UserId, nameof(key.UserId)).NotNull().NotEmpty().NotWhiteSpace();
            Guard.Argument(key.KeyDetails, nameof(key.KeyDetails)).NotNull().NotEmpty().NotWhiteSpace();

            var existingUserKey = await GetByUserId(key.UserId, cancellationToken);

            if (existingUserKey != null)
            {
                throw new UserException($"Key already created for the user {key.UserId}");
            }

            var response = await Client.CreateDocumentAsync(_documentCollectionUri, key, new RequestOptions(), false, cancellationToken);

            return(JsonConvert.DeserializeObject <KeyDao>(response.Resource.ToString()));
        }
Пример #5
0
        private void ListDoc(DocDto doc)
        {
            _Docs.Clear();

            var list   = new DocImgDao().ListDoc(doc);
            var keyDao = new KeyDao();

            foreach (var item in list)
            {
                item.Init(_Cfg);
                doc.AppendDocItem(item);
                var key = keyDao.Read <KeyDto>(item.key);
                if (key != null)
                {
                    item.path = key.file;
                }
                item.Prepare();

                _Docs.Add(item);
            }
        }