示例#1
0
 private void OnCmdSpeichern()
 {
     if (CheckRequiredFields())
     {
         _metadataItem = new MetadataItem(this);
         _fileSystemService.AddFile(_metadataItem, IsRemoveFileEnabled, _filePath);
         _navigateBack();
     }
     else
     {
         MessageBox.Show("Es müssen alle Pflichtfelder ausgewählt werden");
     }
 }
示例#2
0
        public void AddFile_CheckContentMetadata_ReturnTrue()
        {
            var documentId = new Guid("34CB2DFC-EB7F-45BB-8E82-C7CC9A30F871");

            //arrange
            var stubMetaDataItemFactory = new MetaDataItemFactory();
            var metadataItemStub        = stubMetaDataItemFactory.GetMetadataItem();

            var directoryServiceStub = A.Fake <IDirectoryService>();

            A.CallTo(() => directoryServiceStub.GetExtension(@"C:\Temp\sourcePath\bla.pdf")).Returns(".pdf");
            A.CallTo(() => directoryServiceStub.Combine(@"C:\Temp\DMS", "2018")).Returns(@"C:\Temp\DMS\2018");
            //A.CallTo(directoryServiceStub).WithVoidReturnType().DoesNothing();

            var guidGeneratorStub = A.Fake <IGuidGeneratorService>();

            A.CallTo(() => guidGeneratorStub.GetNewGuid()).Returns(documentId);

            var filenameGeneratorServiceStub = A.Fake <IFilenameGeneratorService>();

            A.CallTo(() => filenameGeneratorServiceStub.GetContentFilename(metadataItemStub.DocumentId, ".pdf")).Returns(metadataItemStub.DocumentId + "_content");
            A.CallTo(() => filenameGeneratorServiceStub.GetMetadataFilename(metadataItemStub.DocumentId)).Returns(metadataItemStub.DocumentId + "_metadata");

            var xmlServiceStub = A.Fake <IXmlService>();

            A.CallTo(() => xmlServiceStub.MetadataItemToXml(metadataItemStub, "targetPath2018")).DoesNothing();

            var sut = new FileSystemService(xmlServiceStub, filenameGeneratorServiceStub, directoryServiceStub, guidGeneratorStub);

            //act
            sut.AddFile(metadataItemStub, false, @"C:\Temp\sourcePath\bla.pdf");

            //assert
            Assert.AreEqual(@"C:\Temp\sourcePath\bla.pdf", metadataItemStub.OrginalPath);
            Assert.AreEqual(@"C:\Temp\DMS\2018" + metadataItemStub.ContentFilename, metadataItemStub.PathInRepo);
            Assert.AreEqual(".pdf", metadataItemStub.ContentFileExtension);
            Assert.AreEqual(documentId + "_content", metadataItemStub.ContentFilename);
            Assert.AreEqual(documentId + "_metadata", metadataItemStub.MetadataFilename);
            Assert.AreEqual(documentId.ToString(), metadataItemStub.DocumentId.ToString());
        }
示例#3
0
        public string Index()
        {
            ResponseTypes      tip;
            TipTypes           information;
            string             str      = ConfigurationManager.AppSettings["StorageRelativePath"];
            string             str2     = ConfigurationManager.AppSettings["StorageAbsolutePath"];
            HandlerResponse    response = null;
            HttpPostedFileBase base2    = base.Request.Files[0];
            string             fileName = base2.FileName;
            string             parentID = base.Request.QueryString["CommentID"];
            int recordCount             = 0;

            using (IEnumerator <KaYi.FileSystem.Model.File> enumerator = FileSystemService.GetFilesBy("", "", parentID, "", "", FileStates.Normal, FileTypes.File, "", false, 0, 0x270f, out recordCount).GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    if (enumerator.Current.OriginalFileName.ToUpper() == fileName.ToUpper())
                    {
                        tip         = ResponseTypes.Tip;
                        information = TipTypes.Information;
                        response    = new HandlerResponse("FILE_ALREADY_EXIST", string.Format("文件{0}已存在", fileName), tip.ToString(), information.ToString(), "", "", "");
                        base.Response.Write(response.GenerateJsonResponse());
                        return(null);
                    }
                }
            }
            if (((base.Request.RequestType == "POST") && (base.Request.Files.Count > 0)) && (!StringHelper.isNullOrEmpty(base.Request.QueryString["LotID"]) && !StringHelper.isNullOrEmpty(base.Request.QueryString["CommentID"])))
            {
                string str6 = base.Request.QueryString["LotID"];
                parentID = base.Request.QueryString["CommentID"];
                DateTime now = DateTime.Now;
                KaYi.FileSystem.Model.File file = new KaYi.FileSystem.Model.File();
                string str7 = Guid.NewGuid().ToString();
                file.ContentType           = base2.ContentType;
                file.ConvertToPDFSuccessed = false;
                file.CreateTime            = DateTime.Now;
                file.ExtendFileName        = FileService.GetExtendFileName(base2.FileName);
                file.FileID             = str7;
                file.FileSize           = base2.ContentLength;
                file.FileState          = FileStates.Normal;
                file.FileType           = FileTypes.File;
                file.FullPathForDisplay = "";
                file.Keyword            = "";
                file.Memo                    = "";
                file.OriginalFileName        = base2.FileName;
                file.OwnerID                 = str6;
                file.ParentID                = parentID;
                file.PDFAbsolutePath         = "";
                file.PDFAbsoluteFileName     = "";
                file.PDFRelativePath         = "";
                file.RelativeProjectNames    = "";
                file.RelativeUserNames       = "";
                file.StoreAbsolutePath       = string.Format(@"{0}{1}\{2}\", str2, str6, parentID);
                file.StorageAbsoluteFileName = file.StoreAbsolutePath + @"\" + file.OriginalFileName;
                file.StoreRelativePath       = string.Format(@"{0}{1}\{2}\", str, str6, parentID);
                file.StoreRelativePath       = file.StoreRelativePath.Replace('\\', '/');
                file.Tag        = "Unconfirmed";
                file.Title      = "";
                file.TokenID    = Guid.NewGuid().ToString();
                file.UploaderID = BaseController.CurrentUserInfo.UserID;
                Directory.CreateDirectory(file.StoreAbsolutePath);
                base2.SaveAs(file.StorageAbsoluteFileName);
                FileSystemService.AddFile(file);
                tip         = ResponseTypes.Tip;
                information = TipTypes.Information;
                response    = new HandlerResponse("FILE_UPLOADED_SUCCESSED", file.OriginalFileName, tip.ToString(), information.ToString(), "", "", file.FileID);
                base.Response.Write(response.GenerateJsonResponse());
                return("");
            }
            tip         = ResponseTypes.Tip;
            information = TipTypes.Information;
            response    = new HandlerResponse("FILE_UPLOAD_FAILED", "文件上传错误", tip.ToString(), information.ToString(), "", "", "");
            base.Response.Write(response.GenerateJsonResponse());
            return("");
        }