123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- namespace OASystem.API.OAMethodLib
- {
- public class IOOperatorHelper
- {
-
-
-
-
-
-
-
- public string Write_CoverFile(string content, string dir, string fileName)
- {
- if (!System.IO.Directory.Exists(dir)) System.IO.Directory.CreateDirectory(dir);
-
- String filePath = dir + fileName;
- System.IO.StreamWriter file1 = new System.IO.StreamWriter(filePath, false);
- file1.Write(content);
- file1.Close();
- file1.Dispose();
- return filePath;
- }
- public string Read(string filePath)
- {
- string result = string.Empty;
- try
- {
-
- using (StreamReader sr = new StreamReader(filePath))
- {
- string line;
-
-
- while ((line = sr.ReadLine()) != null)
- {
- result += line;
- }
- }
- }
- catch (Exception e)
- {
- }
- result = JsonConvert.DeserializeObject<string>(result);
- return result;
- }
-
-
-
-
-
-
- public void MoveFile(string sourceFileFullPath, string recycleBinPath)
- {
-
- if (!string.IsNullOrEmpty(sourceFileFullPath) && System.IO.File.Exists(sourceFileFullPath))
- {
- string fileName = Path.GetFileName(sourceFileFullPath);
- System.IO.File.Move(sourceFileFullPath, recycleBinPath + fileName);
- }
- }
-
-
-
-
-
-
- public bool ByteToFile(byte[] byteArray, string fileName)
- {
- bool result = false;
- try
- {
- using (FileStream fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write))
- {
- fs.Write(byteArray, 0, byteArray.Length);
- result = true;
- }
- }
- catch
- {
- result = false;
- }
- return result;
- }
-
-
-
-
-
- public byte[] ConvertZipStream(Dictionary<string, Stream> streams)
- {
- byte[] buffer = new byte[6500];
- MemoryStream returnStream = new MemoryStream();
- var zipMs = new MemoryStream();
- using (ICSharpCode.SharpZipLib.Zip.ZipOutputStream zipStream = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(zipMs))
- {
- zipStream.SetLevel(9);
- foreach (var kv in streams)
- {
- string fileName = kv.Key;
- using (var streamInput = kv.Value)
- {
- ICSharpCode.SharpZipLib.Zip.ZipEntry zipEntry = new ICSharpCode.SharpZipLib.Zip.ZipEntry(fileName);
- zipEntry.IsUnicodeText = true;
- zipStream.PutNextEntry(zipEntry);
- while (true)
- {
- var readCount = streamInput.Read(buffer, 0, buffer.Length);
- if (readCount > 0)
- {
- zipStream.Write(buffer, 0, readCount);
- }
- else
- {
- break;
- }
- }
- zipStream.Flush();
- }
- }
- zipStream.Finish();
- zipMs.Position = 0;
- zipMs.CopyTo(returnStream, 5600);
- }
- returnStream.Position = 0;
-
- byte[] returnBytes = new byte[returnStream.Length];
- returnStream.Read(returnBytes, 0, returnBytes.Length);
- returnStream.Seek(0, SeekOrigin.Begin);
- return returnBytes;
- }
- }
- }
|