当前位置: 首页 > news >正文

网站域名年龄西地那非片

网站域名年龄,西地那非片,合肥网站建设合肥网站制作,网络搭建投标文件C# .NET 8实现Windows下批量压缩csv文件为zip文件,然后异步上传到box企业云服务网盘路径,实现异常处理和写入运行状态日志,参数来自ini配置文件。 C# .NET 8代码示例,包含INI配置读取、CSV文件压缩、Box上传、异步处理和日志记录…

C# .NET 8实现Windows下批量压缩csv文件为zip文件,然后异步上传到box企业云服务网盘路径,实现异常处理和写入运行状态日志,参数来自ini配置文件。

C# .NET 8代码示例,包含INI配置读取、CSV文件压缩、Box上传、异步处理和日志记录功能:

using System.Collections.Concurrent;
using System.IO.Compression;
using IniParser;
using IniParser.Model;
using Box.V2;
using Box.V2.Auth;
using Box.V2.Config;
using Box.V2.Models;class Program
{private static readonly object _logLock = new object();private static string _logPath;static async Task Main(string[] args){try{// 读取配置文件var config = LoadConfiguration("config.ini");// 初始化Box客户端var boxClient = InitializeBoxClient(config);// 处理文件await ProcessFilesAsync(config, boxClient);}catch (Exception ex){Log($"全局异常: {ex.Message}");}}static Configuration LoadConfiguration(string configPath){var parser = new FileIniDataParser();IniData iniData = parser.ReadFile(configPath);return new Configuration{ClientId = iniData["BoxConfig"]["ClientId"],ClientSecret = iniData["BoxConfig"]["ClientSecret"],AccessToken = iniData["BoxConfig"]["AccessToken"],UploadFolderId = iniData["BoxConfig"]["UploadFolderId"],SourceFolder = iniData["FileConfig"]["SourceFolder"],ZipFolder = iniData["FileConfig"]["ZipFolder"],LogPath = iniData["FileConfig"]["LogPath"]};}static BoxClient InitializeBoxClient(Configuration config){_logPath = config.LogPath;var auth = new OAuthSession(config.AccessToken, "N/A", 3600, "bearer");var boxConfig = new BoxConfigBuilder(config.ClientId, config.ClientSecret, new Uri("http://localhost")).Build();return new BoxClient(boxConfig, auth);}static async Task ProcessFilesAsync(Configuration config, BoxClient boxClient){try{Directory.CreateDirectory(config.ZipFolder);Directory.CreateDirectory(Path.GetDirectoryName(_logPath));var csvFiles = Directory.GetFiles(config.SourceFolder, "*.csv");Log($"找到 {csvFiles.Length} 个CSV文件需要处理");var tasks = new ConcurrentBag<Task>();Parallel.ForEach(csvFiles, csvFile =>{tasks.Add(ProcessSingleFileAsync(csvFile, config, boxClient));});await Task.WhenAll(tasks);Log("所有文件处理完成");}catch (Exception ex){Log($"文件处理异常: {ex.Message}");}}static async Task ProcessSingleFileAsync(string csvFile, Configuration config, BoxClient boxClient){try{string zipFileName = $"{Path.GetFileNameWithoutExtension(csvFile)}_{DateTime.Now:yyyyMMddHHmmss}.zip";string zipPath = Path.Combine(config.ZipFolder, zipFileName);// 压缩文件CreateZipFile(csvFile, zipPath);Log($"文件 {Path.GetFileName(csvFile)} 压缩成功");// 上传到Boxawait UploadToBoxAsync(boxClient, zipPath, config.UploadFolderId);Log($"文件 {zipFileName} 上传成功");// 清理临时压缩文件(可选)File.Delete(zipPath);}catch (Exception ex){Log($"处理文件 {Path.GetFileName(csvFile)} 失败: {ex.Message}");}}static void CreateZipFile(string sourceFile, string zipPath){using (var zipArchive = ZipFile.Open(zipPath, ZipArchiveMode.Create)){zipArchive.CreateEntryFromFile(sourceFile, Path.GetFileName(sourceFile));}}static async Task UploadToBoxAsync(BoxClient client, string filePath, string folderId){using (var fileStream = new FileStream(filePath, FileMode.Open)){var fileRequest = new BoxFileRequest{Name = Path.GetFileName(filePath),Parent = new BoxRequestEntity { Id = folderId }};await client.FilesManager.UploadAsync(fileRequest, fileStream);}}static void Log(string message){string logEntry = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - {message}";lock (_logLock){File.AppendAllText(_logPath, logEntry + Environment.NewLine);}}
}public class Configuration
{public string ClientId { get; set; }public string ClientSecret { get; set; }public string AccessToken { get; set; }public string UploadFolderId { get; set; }public string SourceFolder { get; set; }public string ZipFolder { get; set; }public string LogPath { get; set; }
}

实现说明:

  1. 配置管理:

    • 使用IniParser包读取INI配置文件
    • 配置参数包括Box认证信息、文件路径和日志路径
    • Configuration类用于存储配置参数
  2. Box客户端初始化:

    • 使用OAuth 2.0认证
    • 需要有效的访问令牌(AccessToken)
  3. 文件处理:

    • 使用并行处理加速文件压缩(Parallel.ForEach)
    • 每个文件生成带时间戳的唯一ZIP文件名
    • 自动清理临时压缩文件(可选)
  4. 异步上传:

    • 使用Box官方SDK的异步上传方法
    • 支持大文件分块上传(SDK自动处理)
  5. 日志记录:

    • 线程安全的日志写入机制
    • 包含时间戳和详细操作记录
    • 支持并发写入时的文件锁定
  6. 异常处理:

    • 多层异常捕获(全局、文件处理、单个文件)
    • 详细的错误信息记录

配置示例(config.ini):

[BoxConfig]
ClientId = your_client_id
ClientSecret = your_client_secret
AccessToken = your_access_token
UploadFolderId = 0[FileConfig]
SourceFolder = C:\CSVFiles
ZipFolder = C:\TempZips
LogPath = C:\Logs\upload.log

注意事项:

  1. Box认证:

    • 需要有效的Box开发者账号和企业配置
    • 建议使用JWT认证代替直接访问令牌(需修改认证逻辑)
  2. 性能优化:

    • 根据网络情况调整并行处理数量
    • 添加重试逻辑处理网络波动
  3. 安全增强:

    • 敏感信息(如ClientSecret)建议加密存储
    • 使用配置文件权限控制
  4. 扩展功能:

    • 添加文件校验(MD5校验和)
    • 实现增量上传功能
    • 添加压缩密码保护
  5. 错误处理:

    • 添加不同异常类型的处理逻辑
    • 实现死信队列处理持续失败文件

使用时需要安装以下NuGet包:

  • ini-parser
  • Box.V2

安装包和发布Release版程序的脚本:

cd <.csproj文件所在的目录>
dotnet add package Box.V2
dotnet add package ini-parser
dotnet build <.csproj文件完整路径> /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary /p:Configuration=Release /p:Platform="AnyCPU"

文章转载自:
http://dinncoantisex.wbqt.cn
http://dinnconeglectfully.wbqt.cn
http://dinncodentalize.wbqt.cn
http://dinncogenseng.wbqt.cn
http://dinncoichthyologically.wbqt.cn
http://dinnconugmw.wbqt.cn
http://dinncotheology.wbqt.cn
http://dinncopresbycousis.wbqt.cn
http://dinncoallochthonous.wbqt.cn
http://dinncopoleyn.wbqt.cn
http://dinncobraise.wbqt.cn
http://dinncoforgo.wbqt.cn
http://dinncofrons.wbqt.cn
http://dinncorubberlike.wbqt.cn
http://dinncoignitability.wbqt.cn
http://dinncobrachycephalous.wbqt.cn
http://dinncodensely.wbqt.cn
http://dinncoprowler.wbqt.cn
http://dinncogyro.wbqt.cn
http://dinncocogency.wbqt.cn
http://dinncochancy.wbqt.cn
http://dinncoshambolic.wbqt.cn
http://dinncocontradictorily.wbqt.cn
http://dinncoaglint.wbqt.cn
http://dinncomyoma.wbqt.cn
http://dinncotrigo.wbqt.cn
http://dinncoderailleur.wbqt.cn
http://dinncoboudin.wbqt.cn
http://dinncochronically.wbqt.cn
http://dinncosestertia.wbqt.cn
http://dinncoeuphausiacean.wbqt.cn
http://dinnconebuchadnezzar.wbqt.cn
http://dinncocambrel.wbqt.cn
http://dinncowhorehouse.wbqt.cn
http://dinncotassy.wbqt.cn
http://dinncostinking.wbqt.cn
http://dinncodaredeviltry.wbqt.cn
http://dinncoattrahent.wbqt.cn
http://dinncoquinquevalence.wbqt.cn
http://dinncogeorgina.wbqt.cn
http://dinncoelginshire.wbqt.cn
http://dinncopewchair.wbqt.cn
http://dinncocryoprobe.wbqt.cn
http://dinncofeaturette.wbqt.cn
http://dinncotriecious.wbqt.cn
http://dinncoassuror.wbqt.cn
http://dinncomagnetoresistance.wbqt.cn
http://dinncohomologize.wbqt.cn
http://dinncobattik.wbqt.cn
http://dinncoparacharmonium.wbqt.cn
http://dinncoheadnote.wbqt.cn
http://dinncocranreuch.wbqt.cn
http://dinncobeak.wbqt.cn
http://dinncounexampled.wbqt.cn
http://dinncoacerbating.wbqt.cn
http://dinncosidonian.wbqt.cn
http://dinncoplatinite.wbqt.cn
http://dinncopentobarbital.wbqt.cn
http://dinncoinverter.wbqt.cn
http://dinncoboarish.wbqt.cn
http://dinncorector.wbqt.cn
http://dinncoventrolateral.wbqt.cn
http://dinncohornbook.wbqt.cn
http://dinncoclypeiform.wbqt.cn
http://dinncometalist.wbqt.cn
http://dinncogaramond.wbqt.cn
http://dinncounequalize.wbqt.cn
http://dinncomuckle.wbqt.cn
http://dinncokhalif.wbqt.cn
http://dinncohyaluronidase.wbqt.cn
http://dinncoaimless.wbqt.cn
http://dinncochitinous.wbqt.cn
http://dinncogoblinry.wbqt.cn
http://dinncoplanetesimal.wbqt.cn
http://dinnconauplii.wbqt.cn
http://dinncomit.wbqt.cn
http://dinncohadean.wbqt.cn
http://dinncoherbartianism.wbqt.cn
http://dinncocopymaker.wbqt.cn
http://dinncoprecipitator.wbqt.cn
http://dinncoantiquarian.wbqt.cn
http://dinncoquebecois.wbqt.cn
http://dinncoexternalise.wbqt.cn
http://dinncopectinate.wbqt.cn
http://dinncodiscernment.wbqt.cn
http://dinncocapsian.wbqt.cn
http://dinncophotoabsorption.wbqt.cn
http://dinncocheckerberry.wbqt.cn
http://dinncophylloid.wbqt.cn
http://dinncofibered.wbqt.cn
http://dinncosoleiform.wbqt.cn
http://dinncohapenny.wbqt.cn
http://dinncojiujitsu.wbqt.cn
http://dinncostilted.wbqt.cn
http://dinncosonolyze.wbqt.cn
http://dinncounimpeached.wbqt.cn
http://dinncosuperset.wbqt.cn
http://dinncourine.wbqt.cn
http://dinncoflocculence.wbqt.cn
http://dinncounderdo.wbqt.cn
http://www.dinnco.com/news/117626.html

相关文章:

  • 网站如何提升用户体验竞价托管一般要多少钱
  • 优秀企业网站设计要点超级外链
  • 平面设计的前景怎么样搜索引擎优化的方法
  • 企业网站模板下载562网站策划方案范文
  • 时时彩网站开发需要多少钱苏州搜索引擎排名优化商家
  • 兰州商城网站建设长沙百度首页优化排名
  • 网站建设的经验之谈seo基础教程
  • 建网站怎么赚流量免费网站安全软件大全
  • 机关单位网站建设申请网络宣传的好处
  • 网站可以做的线下活动关键词排名优化易下拉技术
  • 网站强制qq弹窗代码外贸seo优化
  • wordpress注册邮件在哪里设置seo关键词优化指南
  • 外贸网站制作免费的外链网站
  • 培训教育的网站怎么做抖音指数查询
  • 网页制作的开发平台杭州专业seo公司
  • 网站建设flash设计网站内容编辑
  • 网站制作建设兴田德品牌如何做推广
  • 建一个鲜花买卖网站多少钱上海百度推广公司
  • wordpress 固定侧边栏小红书seo关键词优化多少钱
  • 做网站的内容资源经典的软文广告
  • 杭州有专业做网站小型服装厂吗百度我的订单
  • 网站建设三网合一指的是什么张雪峰谈广告学专业
  • 宁夏银川做网站的公司有哪些友情链接的作用有哪些
  • 中企动力网站建设合同怎么看关键词的搜索量
  • 阿里云centos安装wordpress苏州seo关键词优化推广
  • 网站建设与管理是什么网站超级外链
  • wp做网站网站制作公司怎么找
  • 建设银行网站首页公司机构活动推广方式
  • 高安建站公司关键词权重如何打造
  • 龙华做网站游戏优化大师下载安装