Ejemplo n.º 1
0
        public void Copy(IFileConfig config)
        {
            lock (_lockObject)
            {
                CopyFileConfig fileConfig = config as CopyFileConfig;
                if (this.CheckConfigIsError(fileConfig))
                {
                    return;
                }

                FileStream fs = fileConfig.IsAsync
                    ? new FileStream(fileConfig.OriginalFileUrl, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true)
                    : new FileStream(fileConfig.OriginalFileUrl, FileMode.Open);

                byte[] originalByte = new byte[fs.Length];
                using (fs)
                {
                    if (fs.IsAsync)
                    {
                        fileConfig.OriginalFileByte = originalByte;
                        fileConfig.OriginalStream   = fs;
                        if (fs.CanRead)
                        {
                            fs.BeginRead(originalByte, 0, originalByte.Length, End_CreateFileCallBack, fileConfig);
                        }
                    }
                    else
                    {
                        if (fs.CanRead)
                        {
                            fs.Read(originalByte, 0, originalByte.Length);
                        }

                        FileStream fs2 = new FileStream(fileConfig.DestinationFileUrl, FileMode.CreateNew);
                        using (fs2)
                        {
                            fs2.Write(originalByte, 0, originalByte.Length);
                            fs2.Close();
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private static void ExampleB()
        {
            string           filePath   = "H:\\mine2\\MyApi\\src\\MyWebApi\\DtoLib\\File\\FileFileCreate.txt";
            CreateFileConfig fileConfig = new CreateFileConfig()
            {
                FileName  = "FileFileCreate.txt",
                IsAsync   = false,
                CreateUrl = filePath
            };

            CopyFileConfig copyConfig = new CopyFileConfig()
            {
                OriginalFileUrl    = "H:\\mine2\\MyApi\\src\\MyWebApi\\DtoLib\\File\\FileFileCreate.txt",
                DestinationFileUrl = "H:\\mine2\\MyApi\\src\\MyWebApi\\DtoLib\\File\\FileFileCreate2.txt",
                IsAsync            = true
            };

            FileStreamTest fs = new FileStreamTest();

            fs.Create(fileConfig);

            fs.Copy(copyConfig);
        }