123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Controls.Primitives;
- using System.Windows.Threading;
- using Aliyun.OSS;
- using Aliyun.OSS.Common;
- using SAGA.MBI;
- using SAGA.Models;
- namespace SAGA.GplotManage
- {
- //public class OssHelper
- //{
- // static OssClient client = new OssClient(Config.Endpoint, Config.AccessKeyId, Config.AccessKeySecret);
- // private static string prefixKey = "test/files/revit/GplotData/Prj10000000";
- // const string bucketName = "prod-data";
-
- // public static List<string> ListObjects(string bucketName)
- // {
- // List<string> fileNames = new List<string>();
- // Regex reg = new Regex($"{prefixKey}/(.+\\.json)");
- // try
- // {
- // var result = client.ListObjects(bucketName);
- // // var getObjectRequest = new GetObjectRequest(bucketName, $"{prefixKey}/SpaceDatas-20180730143438-new.json");
- // bool exist = client.DoesObjectExist(bucketName, $"{prefixKey}/SpaceDatas-20180730143438-new.json");
- // foreach (var summary in result.ObjectSummaries)
- // {
- // System.Diagnostics.Debug.WriteLine(summary.Key);
- // var match = reg.Match(summary.Key);
- // if (match.Success)
- // {
- // fileNames.Add(match.Groups[1].Value);
- // }
- // }
- // }
- // catch (OssException ex)
- // {
- // Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
- // ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
- // }
- // catch (Exception ex)
- // {
- // Console.WriteLine("Failed with error info: {0}", ex.Message);
- // }
- // return fileNames;
- // }
- // /// <summary>
- // /// 根据前缀列出
- // /// </summary>
- // /// <param name="bucketName"></param>
- // /// <param name="prefix"></param>
- // /// <returns></returns>
- // public static List<ServerFileInfo> ListObjects(string bucketName, string prefix)
- // {
- // List<ServerFileInfo> fileNames = new List<ServerFileInfo>();
- // Regex reg = new Regex($"{prefixKey}/(.+\\.json)");
- // try
- // {
- // var listObjectsRequest = new ListObjectsRequest(bucketName)
- // {
- // Prefix = prefix
- // };
- // var result = client.ListObjects(listObjectsRequest);
- // foreach (var summary in result.ObjectSummaries)
- // {
- // System.Diagnostics.Debug.WriteLine(summary.Key);
- // var match = reg.Match(summary.Key);
- // if (match.Success)
- // {
- // fileNames.Add(new ServerFileInfo()
- // {
- // FileName = match.Groups[1].Value,
- // FileKey = summary.Key
- // });
- // }
- // }
- // }
- // catch (OssException ex)
- // {
- // Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
- // ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
- // }
- // catch (Exception ex)
- // {
- // Console.WriteLine("Failed with error info: {0}", ex.Message);
- // }
- // return fileNames;
- // }
- // /// <summary>
- // /// 获取拓扑数据的时间戳
- // /// </summary>
- // /// <typeparam name="T"></typeparam>
- // /// <param name="tableName"></param>
- // /// <returns></returns>
- // public static ServerFileInfo GetTimestamp<T>(string tableName = "")
- // {
- // var file = GetTableNamePath<T>(tableName);
- // return file;
- // }
- // /// <summary>
- // /// 根据类型或者数据名称获取数据路径
- // /// </summary>
- // /// <typeparam name="T"></typeparam>
- // /// <param name="tableName"></param>
- // /// <returns></returns>
- // public static ServerFileInfo GetTableNamePath<T>(string tableName = "")
- // {
- // var name = tableName == "" ? GetTableName(typeof(T)) : tableName;
- // return GetFileNamePath(name);
- // }
- // private static string GetTableName(Type type)
- // {
- // return type.GetAttribute<TableNameAttribute>()?.Name;
- // }
- // /// <summary>
- // /// 根据名称查找文件
- // /// </summary>
- // /// <param name="tableName"></param>
- // /// <returns></returns>
- // public static ServerFileInfo GetFileNamePath(string tableName)
- // {
- // var file = ListObjects(bucketName, prefixKey).FirstOrDefault(f => f.FileName?.IndexOf(tableName) > -1);
- // return file;
- // }
-
- // public static void GetObjectProgress(string fileName,string key)
- // {
- // var filePath= Path.Combine(Models.StaticData.DbDirectory,fileName);
- // try
- // {
- // var getObjectRequest = new GetObjectRequest(bucketName, key);
- // // getObjectRequest.StreamTransferProgress += StreamProgressCallback;
- // var ossObject = client.GetObject(getObjectRequest);
- // using (var stream = ossObject.Content)
- // {
- // var buffer = new byte[1024 * 1024];
- // var bytesTotal = 0;
- // var bytesRead = 0;
- // using (var fs = File.Open(filePath, FileMode.OpenOrCreate))
- // {
- // while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
- // {
- // bytesTotal += bytesRead;
- // // Process read data
- // // TODO
- // fs.Write(buffer, 0, bytesRead);
- // }
- // }
- // }
- // Debug.WriteLine("Get object:{0} succeeded", key);
- // }
- // catch (OssException ex)
- // {
- // Debug.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
- // ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
- // }
- // catch (Exception ex)
- // {
- // Debug.WriteLine("Failed with error info: {0}", ex.Message);
- // }
- // }
- // public static void PutObject(string filePath)
- // {
- // string fileName = Path.GetFileName(filePath);
- // string key = $"{prefixKey}/{fileName}";
-
- // try
- // {
- // using (var fs = File.Open(filePath, FileMode.Open))
- // {
- // var putObjectRequest = new PutObjectRequest(bucketName, key, fs);
-
- // client.PutObject(putObjectRequest);
- // }
- // Console.WriteLine("Put object:{0} succeeded", key);
- // }
- // catch (OssException ex)
- // {
- // Console.WriteLine(@"Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
- // ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
- // }
- // catch (Exception ex)
- // {
- // Console.WriteLine($@"Failed with error info: { ex.Message}");
- // }
- // }
- // public static void PutObjectFromDir(string dirPath, Action<string> callback)
- // {
- // var files = Directory.GetFiles(dirPath);
- // foreach (var file in files)
- // {
- // PutObject(file);
- // callback?.Invoke(file);
- // }
- // }
- //}
- }
|