Esempio n. 1
0
        static void Test()
        {
            try
            {
                NetTcpBinding binding = new NetTcpBinding();
                binding.TransferMode = TransferMode.Streamed;
                binding.SendTimeout = new TimeSpan(0, 0, 2);

                channelFactory = new ChannelFactory<IFileUpload>(binding, ClientConfig.WCFAddress);

                _proxy = channelFactory.CreateChannel();

                (_proxy as ICommunicationObject).Open();

                Console.WriteLine("主方法开始执行:" + DateTime.Now.ToString());
                _proxy.BeginAdd(1, 2, EndAdd, null);
                Console.WriteLine("主方法结束:" + DateTime.Now.ToString());

            }
            catch (Exception ex)
            {
                Tools.LogWrite(ex.ToString());
                Console.WriteLine(ex.ToString());
            }
        }
 public PostImagesController(ApplicationContext context, IPostRepository postRepository, IPostImageRepository postImageRepository, IFileUpload fileUpload)
 {
     this._postRepository      = postRepository;
     this._postImageRepository = postImageRepository;
     this._fileUpload          = fileUpload;
     _context = context;
 }
 public MobileCoverImageController(ApplicationDbContext dbContext, IDataProtectionProvider dataProtectionProvider,
                                   IConfiguration configuration)
 {
     mobileCoverImageService = new MobileCoverImageService(dbContext);
     _protector        = dataProtectionProvider.CreateProtector("");
     fileUploadService = new FileUploadService();
 }
Esempio n. 4
0
 /// <summary>
 /// 初始化图标管理器
 /// </summary>
 /// <param name="fileUpload">文件上传操作</param>
 /// <param name="iconRepository">图标仓储</param>
 /// <param name="fileManager">文件管理器</param>
 public IconManager(IFileUpload fileUpload, IIconRepository iconRepository, IFileManager fileManager)
 {
     FileUpload = fileUpload;
     FileUpload.UploadPathStrategy = new DefaultUploadPathStrategy();
     IconRepository = iconRepository;
     FileManager    = fileManager;
 }
 public MessagesController(IMessageInfoRepository messageContext, IUserInfoRepository userContext, IHostingEnvironment env, ILogger <MessagesController> logger, IFileUpload fileUploade)
 {
     _messageInfoRepository = messageContext;
     _userInfoRepository    = userContext;
     _logger      = logger;
     _fileUploade = fileUploade;
 }
Esempio n. 6
0
 public void TestInit()
 {
     _mockUpload         = Substitute.For <IFileUpload>();
     _mockIconRepository = Substitute.For <IIconRepository>();
     _mockFileManager    = Substitute.For <IFileManager>();
     _manager            = new IconManager(_mockUpload, _mockIconRepository, _mockFileManager);
 }
Esempio n. 7
0
 public ProductService(IUnitOfWork unitOfWork, IMapper mapper, IFileUpload upload, ICategoryService categoryService)
 {
     _upload          = upload;
     _categoryService = categoryService;
     _mapper          = mapper;
     _unitOfWork      = unitOfWork;
 }
Esempio n. 8
0
 public int CreateFileUploadLog(IFileUpload FileU, int tenantid, string filename, bool isuploaded, string errorlogfilename,
                                string successlogfilename, int createdby, string filetype, string succesFilepath, string errorFilepath, int fileuploadFor)
 {
     _FileUpload = FileU;
     return(_FileUpload.CreateFileUploadLog(tenantid, filename, isuploaded, errorlogfilename, successlogfilename, createdby, filetype,
                                            succesFilepath, errorFilepath, fileuploadFor));
 }
Esempio n. 9
0
 public BookController(ApplicationContext context, IConfiguration configuration, IMapper mapper, IFileUpload fileUpload)
 {
     _context       = context;
     _configuration = configuration;
     _mapper        = mapper;
     _fileUpload    = fileUpload;
 }
Esempio n. 10
0
        public PostImagesController(IFileUpload fileUpload, ApplicationContext _context, IPostImageRepository postImageRepository, IPostRepository postRepository, ApplicationContext context)
        {
            _context                  = context;
            this._fileUpload          = fileUpload;
            this._postImageRepository = postImageRepository;

            this._postRepository = postRepository;
        }
Esempio n. 11
0
 public CatagoryController(ApplicationDbContext dbContext, IDataProtectionProvider dataProtectionProvider,
                           IConfiguration configuration)
 {
     catagoryService     = new CatagoryService(dbContext);
     fileUploadService   = new FileUploadService();
     _protector          = dataProtectionProvider.CreateProtector("");
     azureStorageService = new AzureStorageService(configuration);
 }
Esempio n. 12
0
 public PostService(IHttpContextAccessor httpContext, IUnitOfWork unitOfWork, IMapper mapper, IConfiguration configuration, IFileUpload uploadFile)
 {
     this.configuration = configuration;
     this.httpContext = httpContext;
     this.mapper = mapper;
     this.unitOfWork = unitOfWork;
     this.uploadFile = uploadFile;
 }
Esempio n. 13
0
 public HomeController(ILogger <HomeController> logger, ApplicationContext context, IFileUpload fileUpload, IContactService contactService, IInfoTable infoTable)
 {
     _context        = context;
     _logger         = logger;
     _contactService = contactService;
     _fileUpload     = fileUpload;
     _infoTable      = infoTable;
 }
Esempio n. 14
0
 public MainHomeController(MyContext context,
                           IFileUpload upload,
                           IWebHostEnvironment env)
 {
     _context = context;
     _upload  = upload;
     _env     = env;
 }
Esempio n. 15
0
        public string uploadFile([FromForm] IFormFile arquivo, [FromServices] IFileUpload fileUpload)
        {
            var abc = arquivo.OpenReadStream();

            _logger.LogInformation(arquivo.FileName);
            return("oi");
            //return await fileUpload.Upload(arquivo);
            //return this.userServices.createUser(user);
        }
Esempio n. 16
0
        public void RemoveHttpDataFromCleanShouldIdentifiesDataByTheirIdentities()
        {
            // Create some equal data items belonging to the same request
            IAttribute  attribute1 = _factory.CreateAttribute(_req1, "attribute", "value");
            IAttribute  attribute2 = _factory.CreateAttribute(_req1, "attribute", "value");
            IFileUpload file1      = _factory.CreateFileUpload(
                _req1,
                "file",
                "file.txt",
                HttpPostBodyUtil.DefaultTextContentType,
                HttpHeaderValues.Identity.ToString(),
                Encoding.UTF8,
                123);
            IFileUpload file2 = _factory.CreateFileUpload(
                _req1,
                "file",
                "file.txt",
                HttpPostBodyUtil.DefaultTextContentType,
                HttpHeaderValues.Identity.ToString(),
                Encoding.UTF8,
                123);

            file1.SetContent(Unpooled.CopiedBuffer(Encoding.UTF8.GetBytes("file content")));
            file2.SetContent(Unpooled.CopiedBuffer(Encoding.UTF8.GetBytes("file content")));

            // Before doing anything, assert that the data items are equal
            Assert.Equal(attribute1.GetHashCode(), attribute2.GetHashCode());
            Assert.True(attribute1.Equals(attribute2));
            Assert.Equal(file1.GetHashCode(), file2.GetHashCode());
            Assert.True(file1.Equals(file2));

            // Remove attribute2 and file2 from being cleaned up by factory
            _factory.RemoveHttpDataFromClean(_req1, attribute2);
            _factory.RemoveHttpDataFromClean(_req1, file2);

            // Clean up by req1
            _factory.CleanRequestHttpData(_req1);

            // Assert that attribute1 and file1 have been cleaned up
            Assert.Null(attribute1.GetByteBuffer());
            Assert.Null(file1.GetByteBuffer());
            Assert.Equal(0, attribute1.ReferenceCount);
            Assert.Equal(0, file1.ReferenceCount);

            // But not attribute2 and file2
            Assert.NotNull(attribute2.GetByteBuffer());
            Assert.NotNull(file2.GetByteBuffer());
            Assert.Equal(1, attribute2.ReferenceCount);
            Assert.Equal(1, file2.ReferenceCount);

            // Cleanup attribute2 and file2 manually to avoid memory leak, not via factory
            attribute2.Release();
            file2.Release();
            Assert.Equal(0, attribute2.ReferenceCount);
            Assert.Equal(0, file2.ReferenceCount);
        }
Esempio n. 17
0
 public LoginController(IUserService users, IFileUpload fileUpload,
                        IUnitOfWork uow,
                        IUser userRepo,
                        IUserInfo userInfo)
 {
     _uow        = uow;
     _users      = users;
     _userInfo   = userInfo;
     _fileUpload = fileUpload;
     _userRepo   = userRepo;
 }
Esempio n. 18
0
        static UploadFileHelper()
        {
            string windowsazure = ConfigurationManager.AppSettings["WindowsAzure"];

            if (windowsazure == "true")
            {
                _FileUpload = (IFileUpload)ConfigurationManager.GetSection("WindowsAzureFileUpload");
            }
            else
            {
                _FileUpload = (IFileUpload)ConfigurationManager.GetSection("ServerFileUpload");
            }
        }
Esempio n. 19
0
        public BLLUpload(IFileUpload proxy, FileServerInfo fileServerInfo, ListBox listBoxUploadDirectory, ListBox listBoxSucessfulDirectory, ListBox listBoxFailDirectory)
        {
            _proxy = proxy;
            _fileServerInfo = fileServerInfo;
            _listBoxUploadDirectory = listBoxUploadDirectory;
            _listBoxSucessfulDirectory = listBoxSucessfulDirectory;
            _listBoxFailDirectory = listBoxFailDirectory;
            _isRun = false;
            _semaphoreTask = new Semaphore(ClientConfig.MaxThread, ClientConfig.MaxThread);

            _delegateTurnToSucessful = UploadDirectoryTurnToSucessful;
            _delegateTurnToFail = UploadDirectoryTurnToFail;
        }
Esempio n. 20
0
        public void CleanRequestHttpDataShouldIdentifiesRequestsByTheirIdentities()
        {
            // Create some data belonging to req1 and req2
            IAttribute  attribute1 = _factory.CreateAttribute(_req1, "attribute1", "value1");
            IAttribute  attribute2 = _factory.CreateAttribute(_req2, "attribute2", "value2");
            IFileUpload file1      = _factory.CreateFileUpload(
                _req1,
                "file1",
                "file1.txt",
                HttpPostBodyUtil.DefaultTextContentType,
                HttpHeaderValues.Identity.ToString(),
                Encoding.UTF8,
                123);

            IFileUpload file2 = _factory.CreateFileUpload(
                _req2,
                "file2",
                "file2.txt",
                HttpPostBodyUtil.DefaultTextContentType,
                HttpHeaderValues.Identity.ToString(),
                Encoding.UTF8,
                123);

            file1.SetContent(Unpooled.CopiedBuffer(Encoding.UTF8.GetBytes("file1 content")));
            file2.SetContent(Unpooled.CopiedBuffer(Encoding.UTF8.GetBytes("file2 content")));

            // Assert that they are not deleted
            Assert.NotNull(attribute1.GetByteBuffer());
            Assert.NotNull(attribute2.GetByteBuffer());
            Assert.NotNull(file1.GetByteBuffer());
            Assert.NotNull(file2.GetByteBuffer());
            Assert.Equal(1, attribute1.ReferenceCount);
            Assert.Equal(1, attribute2.ReferenceCount);
            Assert.Equal(1, file1.ReferenceCount);
            Assert.Equal(1, file2.ReferenceCount);

            // Clean up by req1
            _factory.CleanRequestHttpData(_req1);

            // Assert that data belonging to req1 has been cleaned up
            Assert.Null(attribute1.GetByteBuffer());
            Assert.Null(file1.GetByteBuffer());
            Assert.Equal(0, attribute1.ReferenceCount);
            Assert.Equal(0, file1.ReferenceCount);

            // But not req2
            Assert.NotNull(attribute2.GetByteBuffer());
            Assert.NotNull(file2.GetByteBuffer());
            Assert.Equal(1, attribute2.ReferenceCount);
            Assert.Equal(1, file2.ReferenceCount);
        }
        public void SetBodyHttpDatas(List <IInterfaceHttpData> list)
        {
            Contract.Requires(list != null);

            this.globalBodySize = 0;
            this.bodyListDatas.Clear();
            this.currentFileUpload = null;
            this.duringMixedMode   = false;
            this.MultipartHttpDatas.Clear();
            foreach (IInterfaceHttpData data in list)
            {
                this.AddBodyHttpData(data);
            }
        }
Esempio n. 22
0
        public FileUpload() : base()
        {
            if (isMultiDatabase)
            {
                base.Init(this.GetType().FullName, System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, dicmultiDatabase[this.GetType().Name].ToString());
            }
            else
            {
                base.Init(this.GetType().FullName, System.Reflection.Assembly.GetExecutingAssembly().GetName().Name);
            }

            baseDal.OnOperationLog += new OperationLogEventHandler(OperationLog.OnOperationLog);            //如果需要记录操作日志,则实现这个事件

            dal = baseDal as IFileUpload;
        }
Esempio n. 23
0
        public void CustomBaseDirAndDeleteOnExit()
        {
            DefaultHttpDataFactory defaultHttpDataFactory = new DefaultHttpDataFactory(true);
            string dir = "target/DefaultHttpDataFactoryTest/customBaseDirAndDeleteOnExit";

            defaultHttpDataFactory.SetBaseDir(dir);
            defaultHttpDataFactory.SetDeleteOnExit(true);
            IAttribute  attr = defaultHttpDataFactory.CreateAttribute(_req1, "attribute1");
            IFileUpload fu   = defaultHttpDataFactory.CreateFileUpload(
                _req1, "attribute1", "f.txt", "text/plain", null, null, 0);

            Assert.Equal(dir, ((DiskAttribute)attr).BaseDirectory);
            Assert.Equal(dir, ((DiskFileUpload)fu).BaseDirectory);
            Assert.True(((DiskAttribute)attr).DeleteOnExit);
            Assert.True(((DiskFileUpload)fu).DeleteOnExit);
        }
Esempio n. 24
0
        private void Form_Project_Docs_UpLoad_Load(object sender, EventArgs e)
        {
            label_filename.Text = Uploadfilename;
            IFileUpload upload = new IFileUpload(LoginInfo.GetLoginId());

            upload.EventFileUploadProgress += web_UploadProgressChanged;

            try
            {
                upload.Upload(Uploadfilename, md5, key);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 25
0
        private static UploadRetMsg UploadFile(string fileName, string fileType, long fileSize, Stream fileData)
        {
            IFileUpload client = ServiceProxyFactory <IFileUpload> .CreateProxy(ConfigHelper.GetConfigString("UploadIP"));

            UploadInMsg uploadMessage = new UploadInMsg()
            {
                BID      = fileType,
                ticket   = "5e8b1cm8#%",
                FileName = fileName,
                FileData = fileData,
                FileSize = fileSize
            };
            UploadRetMsg resultMessage = client.UploadFile(uploadMessage);

            return(resultMessage);
        }
 public MixedFileUpload(string name, string fileName, string contentType,
                        string contentTransferEncoding, Encoding charset, long size,
                        long limitSize)
 {
     this.limitSize = limitSize;
     if (size > this.limitSize)
     {
         this.fileUpload = new DiskFileUpload(name, fileName, contentType,
                                              contentTransferEncoding, charset, size);
     }
     else
     {
         this.fileUpload = new MemoryFileUpload(name, fileName, contentType,
                                                contentTransferEncoding, charset, size);
     }
     this.definedSize = size;
 }
Esempio n. 27
0
        /// <summary>
        /// Set the Body HttpDatas list
        /// </summary>
        /// <param name="list"></param>
        public void SetBodyHttpDatas(List <IInterfaceHttpData> list)
        {
            if (list is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.list);
            }

            this.globalBodySize = 0;
            this.bodyListDatas.Clear();
            this.currentFileUpload = null;
            this.duringMixedMode   = false;
            this.MultipartHttpDatas.Clear();
            foreach (IInterfaceHttpData data in list)
            {
                this.AddBodyHttpData(data);
            }
        }
Esempio n. 28
0
        public void AddBodyFileUpload(string name, string fileName, FileStream fileStream, string contentType, bool isText)
        {
            if (name is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.name);
            }
            if (fileStream is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.fileStream);
            }

            if (fileName is null)
            {
                fileName = StringUtil.EmptyString;
            }
            string scontentType            = contentType;
            string contentTransferEncoding = null;

            if (contentType is null)
            {
                scontentType = isText
                    ? HttpPostBodyUtil.DefaultTextContentType
                    : HttpPostBodyUtil.DefaultBinaryContentType;
            }
            if (!isText)
            {
                contentTransferEncoding = HttpPostBodyUtil.TransferEncodingMechanism.Binary.Value;
            }

            IFileUpload fileUpload = this.factory.CreateFileUpload(this.request, name, fileName, scontentType,
                                                                   contentTransferEncoding, null, fileStream.Length);

            try
            {
                fileUpload.SetContent(fileStream);
            }
            catch (IOException e)
            {
                ThrowHelper.ThrowErrorDataEncoderException(e);
            }

            this.AddBodyHttpData(fileUpload);
        }
Esempio n. 29
0
 public MixedFileUpload(string name, string fileName, string contentType,
                        string contentTransferEncoding, Encoding charset, long size,
                        long limitSize, string baseDir, bool deleteOnExit)
 {
     _limitSize = limitSize;
     if (size > _limitSize)
     {
         _fileUpload = new DiskFileUpload(name, fileName, contentType,
                                          contentTransferEncoding, charset, size);
     }
     else
     {
         _fileUpload = new MemoryFileUpload(name, fileName, contentType,
                                            contentTransferEncoding, charset, size);
     }
     _definedSize  = size;
     _baseDir      = baseDir;
     _deleteOnExit = deleteOnExit;
 }
Esempio n. 30
0
        public void DecodeWithLanguageContentDispositionFieldParametersForFix()
        {
            string boundary = "952178786863262625034234";

            string encoding        = "UTF-8";
            string filename        = "测试test.txt";
            string filenameEncoded = UrlEncoder.Default.Encode(filename /*, encoding*/);

            string body = "--" + boundary + "\r\n" +
                          "Content-Disposition: form-data; name=\"file\"; filename*=\"" +
                          encoding + "''" + filenameEncoded + "\"\r\n" +
                          "\r\n" +
                          "foo\r\n" +
                          "\r\n" +
                          "--" + boundary + "--";

            DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.Http11,
                                                                    HttpMethod.Post,
                                                                    "http://localhost",
                                                                    Unpooled.WrappedBuffer(Encoding.UTF8.GetBytes(body)));

            req.Headers.Add(HttpHeaderNames.ContentType, "multipart/form-data; boundary=" + boundary);
            DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
            HttpPostRequestDecoder decoder         = new HttpPostRequestDecoder(inMemoryFactory, req);

            Assert.NotEmpty(decoder.GetBodyHttpDatas());
            IInterfaceHttpData part1 = decoder.GetBodyHttpDatas()[0];

            Assert.True(part1 is IFileUpload); // "the item should be a FileUpload"
            IFileUpload fileUpload = (IFileUpload)part1;

            Assert.Equal(filename, fileUpload.FileName); // "the filename should be decoded"

            decoder.Destroy();
            req.Release();
        }
Esempio n. 31
0
        public void DecodeOtherMimeHeaderFields()
        {
            string boundary    = "74e78d11b0214bdcbc2f86491eeb4902";
            string filecontent = "123456";

            string body = "--" + boundary + "\r\n" +
                          "Content-Disposition: form-data; name=\"file\"; filename=" + "\"" + "attached.txt" + "\"" +
                          "\r\n" +
                          "Content-Type: application/octet-stream" + "\r\n" +
                          "Content-Encoding: gzip" + "\r\n" +
                          "\r\n" +
                          filecontent +
                          "\r\n" +
                          "--" + boundary + "--";

            DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.Http11,
                                                                    HttpMethod.Post,
                                                                    "http://localhost",
                                                                    Unpooled.WrappedBuffer(Encoding.UTF8.GetBytes(body)));

            req.Headers.Add(HttpHeaderNames.ContentType, "multipart/form-data; boundary=" + boundary);
            req.Headers.Add(HttpHeaderNames.TransferEncoding, HttpHeaderValues.Chunked);
            DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
            HttpPostRequestDecoder decoder         = new HttpPostRequestDecoder(inMemoryFactory, req);

            Assert.False(decoder.GetBodyHttpDatas().Count == 0);
            IInterfaceHttpData part1 = decoder.GetBodyHttpDatas()[0];

            Assert.True(part1 is IFileUpload, "the item should be a FileUpload");
            IFileUpload fileUpload = (IFileUpload)part1;

            byte[] fileBytes = fileUpload.GetBytes();
            Assert.True(filecontent.Equals(Encoding.UTF8.GetString(fileBytes)), "the filecontent should not be decoded");
            decoder.Destroy();
            req.Release();
        }
Esempio n. 32
0
 public static int HashCode(IFileUpload upload) => upload.Name.GetHashCode();
Esempio n. 33
0
 public BLLFileServer(IFileUpload proxy)
 {
     _proxy = proxy;
 }
Esempio n. 34
0
 static UploadFileHelper()
 {
     string windowsazure = ConfigurationManager.AppSettings["WindowsAzure"];
     if (windowsazure == "true")
         _FileUpload = (IFileUpload)ConfigurationManager.GetSection("WindowsAzureFileUpload");
     else
         _FileUpload = (IFileUpload)ConfigurationManager.GetSection("ServerFileUpload");
 }
Esempio n. 35
0
        private void Init()
        {
            try
            {
                ClientConfig.Init();
                ProgramRepeatCheck();

                NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);
                binding.TransferMode = TransferMode.Streamed;
                binding.MaxReceivedMessageSize = 2147483648;
                binding.SendTimeout = new TimeSpan(0, ClientConfig.SendTimeout, 0);

                ChannelFactory<IFileUpload> channelFactory = new ChannelFactory<IFileUpload>(binding, ClientConfig.WCFAddress);
                _proxy = channelFactory.CreateChannel();
                (_proxy as ICommunicationObject).Open();
            }
            catch (Exception ex)
            {
                Tools.LogWrite(ex.ToString());
                throw new Exception("连接WCF服务端失败:" + ex.Message);
            }
        }
Esempio n. 36
0
 static UploadFileHelper()
 {
     _FileUpload = (IFileUpload)ConfigurationManager.GetSection("ServerFileUpload");
 }
Esempio n. 37
0
 /// <summary>
 /// 初始化图标管理器
 /// </summary>
 /// <param name="fileUpload">文件上传操作</param>
 /// <param name="fileManager">文件管理器</param>
 public IconManager( IFileUpload fileUpload,IFileManager fileManager ) {
     FileUpload = fileUpload;
     FileUpload.UploadPathStrategy = new DefaultUploadPathStrategy();
     FileManager = fileManager;
 }