├── .editorconfig ├── .gitignore ├── App.config ├── App.xaml ├── App.xaml.cs ├── DateConverter.cs ├── Fap.cs ├── FodyWeavers.xml ├── FodyWeavers.xsd ├── Handlers ├── HttpProgressEventArgs.cs ├── ProgressContent.cs ├── ProgressMessageHandler.cs ├── ProgressStream.cs └── ProgressWriteAsyncResult.cs ├── Hclient.cs ├── LocalFile.cs ├── Login.xaml ├── Login.xaml.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs ├── NumTextBox.cs ├── Properties ├── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Settings.Designer.cs └── Settings.settings ├── README.md ├── SyncFile.xaml ├── SyncFile.xaml.cs ├── TaskInfo.cs ├── TaskMange.cs ├── WinAPI.cs ├── alipay.jpg ├── aliyundrive-Client-CSharp.csproj ├── aliyundrive-Client-CSharp.sln ├── aliyundrive ├── Hclient.cs ├── MsgBase.cs ├── Util.cs ├── databox.cs ├── file.cs └── token.cs ├── favicon.ico ├── packages.config └── windows.png /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{cs,vb}] 2 | 3 | # IDE0060: 删除未使用的参数 4 | dotnet_code_quality_unused_parameters = non_public:suggestion 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vs/ 2 | obj/ 3 | bin/ 4 | packages/ -------------------------------------------------------------------------------- /App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 22 | 23 | 24 | 34 | 35 | 36 | 54 | 55 | 70 | 71 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace aliyundrive_Client_CSharp 10 | { 11 | /// 12 | /// App.xaml 的交互逻辑 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /DateConverter.cs: -------------------------------------------------------------------------------- 1 | using aliyundrive_Client_CSharp.aliyundrive; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows.Data; 9 | 10 | namespace aliyundrive_Client_CSharp 11 | { public class DateConverter : IValueConverter 12 | { 13 | object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) 14 | { 15 | try 16 | { 17 | switch (parameter) 18 | { 19 | case "FormatDate": return FormatDate(value.ToString()); 20 | case "FileSize": return FileSize(value); 21 | } 22 | } 23 | catch { } 24 | return value; 25 | } 26 | 27 | object FormatDate(string value) 28 | { 29 | return DateTime.Parse(value).ToString("yyyy-MM-dd\r\nHH:mm:ss"); 30 | } 31 | object FileSize(object value) 32 | { 33 | var v = value as info_file; 34 | if (v.type == "folder") return "目录"; 35 | long size = v.size; 36 | String[] units = new String[] { "B", "KB", "MB", "GB", "TB", "PB" }; 37 | long mod = 1024; 38 | int i = 0; 39 | while (size >= mod) 40 | { 41 | size /= mod; 42 | i++; 43 | } 44 | return size + "\r\n"+ units[i]; 45 | } 46 | 47 | object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 48 | { 49 | throw new NotImplementedException(); 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /Fap.cs: -------------------------------------------------------------------------------- 1 | using aliyundrive_Client_CSharp.aliyundrive; 2 | using Newtonsoft.Json; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | using System.Threading.Tasks; 9 | 10 | namespace aliyundrive_Client_CSharp 11 | { 12 | class FapShare : MagBase 13 | { 14 | public string code { get; set; } 15 | public string message { get; set; } 16 | public string id { get; set; } 17 | } 18 | class Fap 19 | { 20 | public string ver { get; set; } 21 | public string des { get; set; } 22 | public string tab { get; set; } 23 | public string pwd { get; set; } 24 | public long expires { get; set; } 25 | public string id { get; set; } 26 | public string user { get; set; } 27 | public string flag { get; set; } 28 | public List list { get; set; } 29 | public static Fap FAP_get(string hex) 30 | { 31 | try 32 | { 33 | return JsonConvert.DeserializeObject(Encoding.UTF8.GetString(Util.Hex2Bin(hex))); 34 | } 35 | catch { } 36 | return null; 37 | } 38 | public static string FAP_set(Fap fap) 39 | { 40 | try 41 | { 42 | return Util.Bin2Hex(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(fap))); 43 | } 44 | catch { } 45 | return null; 46 | } 47 | public static void FAP_rapid_upload(Fap fap,string fid, Action invoke) 48 | { 49 | foreach (var item in fap.list) 50 | { 51 | //dir 所在相对当前路径的目录 格式为 一层目录(aaa/) 二层目录(aaa/bbb/) 52 | if (string.IsNullOrEmpty(item.dir)) 53 | { 54 | invoke(() => { 55 | TaskMange.Add(new TaskInfo { Type = TaskType.上传, Name = item.name, sha1 = item.sha1, size = item.size, parent_file_id = fid }); 56 | }); 57 | } 58 | else 59 | { 60 | Task.Run(async () => { 61 | try 62 | { 63 | var u = new upload(); 64 | var ms = Regex.Matches(item.dir, "([^/]+?)/"); 65 | if (ms.Count == 0) throw new Exception("目录错误"); 66 | 67 | string _fid = fid; 68 | if (!AsyncTaskMange.Instance.ParentIDs.ContainsKey(item.dir)) 69 | { 70 | foreach (Match m in ms) 71 | { 72 | Console.WriteLine($"fap创建目录[{item.dir}]:{m.Groups[1].Value}"); 73 | _fid = await u.getfolder(_fid, m.Groups[1].Value); 74 | } 75 | AsyncTaskMange.Instance.ParentIDs[item.dir] = _fid; 76 | } 77 | _fid = AsyncTaskMange.Instance.ParentIDs[item.dir]; 78 | invoke(() => { 79 | TaskMange.Add(new TaskInfo { Type = TaskType.上传, Name = item.name, sha1 = item.sha1, size = item.size, parent_file_id = _fid }); 80 | }); 81 | } 82 | catch (Exception ex) 83 | { 84 | invoke(() => { 85 | TaskMange.Add(new TaskInfo { Type = TaskType.上传, Status = 3, Name = item.name + $"[{ex.Error()}]", sha1 = item.sha1, size = item.size, parent_file_id = fid }); 86 | }); 87 | } 88 | }); 89 | } 90 | } 91 | 92 | } 93 | } 94 | class FapInfo 95 | { 96 | public string name { get; set; } 97 | public string author { get; set; } 98 | public long size { get; set; } 99 | public string sha1 { get; set; } 100 | public string md5 { get; set; } 101 | public string c1 { get; set; } 102 | public string c2 { get; set; } 103 | public string c3 { get; set; } 104 | public string url { get; set; } 105 | public string tmp { get; set; } 106 | public string ext { get; set; } 107 | public string type { get; set; } 108 | public string mime { get; set; } 109 | public string dir { get; set; } 110 | public long created { get; set; } 111 | public long updated { get; set; } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /FodyWeavers.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /FodyWeavers.xsd: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks 13 | 14 | 15 | 16 | 17 | A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks. 18 | 19 | 20 | 21 | 22 | A list of unmanaged 32 bit assembly names to include, delimited with line breaks. 23 | 24 | 25 | 26 | 27 | A list of unmanaged 64 bit assembly names to include, delimited with line breaks. 28 | 29 | 30 | 31 | 32 | The order of preloaded assemblies, delimited with line breaks. 33 | 34 | 35 | 36 | 37 | 38 | This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file. 39 | 40 | 41 | 42 | 43 | Controls if .pdbs for reference assemblies are also embedded. 44 | 45 | 46 | 47 | 48 | Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option. 49 | 50 | 51 | 52 | 53 | As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off. 54 | 55 | 56 | 57 | 58 | Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code. 59 | 60 | 61 | 62 | 63 | Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior. 64 | 65 | 66 | 67 | 68 | A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with | 69 | 70 | 71 | 72 | 73 | A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |. 74 | 75 | 76 | 77 | 78 | A list of unmanaged 32 bit assembly names to include, delimited with |. 79 | 80 | 81 | 82 | 83 | A list of unmanaged 64 bit assembly names to include, delimited with |. 84 | 85 | 86 | 87 | 88 | The order of preloaded assemblies, delimited with |. 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. 97 | 98 | 99 | 100 | 101 | A comma-separated list of error codes that can be safely ignored in assembly verification. 102 | 103 | 104 | 105 | 106 | 'false' to turn off automatic generation of the XML Schema file. 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /Handlers/HttpProgressEventArgs.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. 2 | 3 | using System.ComponentModel; 4 | 5 | namespace System.Net.Http.Handlers 6 | { 7 | /// 8 | /// Provides data for the events generated by . 9 | /// 10 | public class HttpProgressEventArgs : ProgressChangedEventArgs 11 | { 12 | /// 13 | /// Initializes a new instance of the with the parameters given. 14 | /// 15 | /// The percent completed of the overall exchange. 16 | /// Any user state provided as part of reading or writing the data. 17 | /// The current number of bytes either received or sent. 18 | /// The total number of bytes expected to be received or sent. 19 | public HttpProgressEventArgs(int progressPercentage, object userToken, int bytesTransferred, long? totalBytes) 20 | : base(progressPercentage, userToken) 21 | { 22 | BytesTransferred = bytesTransferred; 23 | TotalBytes = totalBytes; 24 | } 25 | 26 | /// 27 | /// Gets the current number of bytes transferred. 28 | /// 29 | public int BytesTransferred { get; private set; } 30 | 31 | /// 32 | /// Gets the total number of expected bytes to be sent or received. If the number is not known then this is null. 33 | /// 34 | public long? TotalBytes { get; private set; } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Handlers/ProgressContent.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. 2 | 3 | using System.Diagnostics.Contracts; 4 | using System.IO; 5 | using System.Threading.Tasks; 6 | 7 | namespace System.Net.Http.Handlers 8 | { 9 | /// 10 | /// Wraps an inner in order to insert a on writing data. 11 | /// 12 | internal class ProgressContent : HttpContent 13 | { 14 | private readonly HttpContent _innerContent; 15 | private readonly ProgressMessageHandler _handler; 16 | private readonly HttpRequestMessage _request; 17 | 18 | public ProgressContent(HttpContent innerContent, ProgressMessageHandler handler, HttpRequestMessage request) 19 | { 20 | Contract.Assert(innerContent != null); 21 | Contract.Assert(handler != null); 22 | Contract.Assert(request != null); 23 | 24 | _innerContent = innerContent; 25 | _handler = handler; 26 | _request = request; 27 | 28 | innerContent.Headers.CopyTo(Headers); 29 | } 30 | 31 | protected override Task SerializeToStreamAsync(Stream stream, TransportContext context) 32 | { 33 | ProgressStream progressStream = new ProgressStream(stream, _handler, _request, response: null); 34 | return _innerContent.CopyToAsync(progressStream); 35 | } 36 | 37 | protected override bool TryComputeLength(out long length) 38 | { 39 | long? contentLength = _innerContent.Headers.ContentLength; 40 | if (contentLength.HasValue) 41 | { 42 | length = contentLength.Value; 43 | return true; 44 | } 45 | 46 | length = -1; 47 | return false; 48 | } 49 | 50 | protected override void Dispose(bool disposing) 51 | { 52 | base.Dispose(disposing); 53 | if (disposing) 54 | { 55 | _innerContent.Dispose(); 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Handlers/ProgressMessageHandler.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. 2 | 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | namespace System.Net.Http.Handlers 7 | { 8 | /// 9 | /// The provides a mechanism for getting progress event notifications 10 | /// when sending and receiving data in connection with exchanging HTTP requests and responses. 11 | /// Register event handlers for the events and 12 | /// to see events for data being sent and received. 13 | /// 14 | public class ProgressMessageHandler : DelegatingHandler 15 | { 16 | /// 17 | /// Initializes a new instance of the class. 18 | /// 19 | public ProgressMessageHandler() 20 | { 21 | } 22 | 23 | /// 24 | /// Initializes a new instance of the class. 25 | /// 26 | /// The inner handler to which this handler submits requests. 27 | public ProgressMessageHandler(HttpMessageHandler innerHandler) 28 | : base(innerHandler) 29 | { 30 | } 31 | 32 | /// 33 | /// Occurs every time the client sending data is making progress. 34 | /// 35 | public event EventHandler HttpSendProgress; 36 | 37 | /// 38 | /// Occurs every time the client receiving data is making progress. 39 | /// 40 | public event EventHandler HttpReceiveProgress; 41 | 42 | protected override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) 43 | { 44 | AddRequestProgress(request); 45 | return base.SendAsync(request, cancellationToken).Then(response => AddResponseProgress(request, response)); 46 | } 47 | 48 | /// 49 | /// Raises the event. 50 | /// 51 | /// The request. 52 | /// The instance containing the event data. 53 | protected internal virtual void OnHttpRequestProgress(HttpRequestMessage request, HttpProgressEventArgs e) 54 | { 55 | if (HttpSendProgress != null) 56 | { 57 | HttpSendProgress(request, e); 58 | } 59 | } 60 | 61 | /// 62 | /// Raises the event. 63 | /// 64 | /// The request. 65 | /// The instance containing the event data. 66 | protected internal virtual void OnHttpResponseProgress(HttpRequestMessage request, HttpProgressEventArgs e) 67 | { 68 | if (HttpReceiveProgress != null) 69 | { 70 | HttpReceiveProgress(request, e); 71 | } 72 | } 73 | 74 | private void AddRequestProgress(HttpRequestMessage request) 75 | { 76 | if (HttpSendProgress != null && request != null && request.Content != null) 77 | { 78 | HttpContent progressContent = new ProgressContent(request.Content, this, request); 79 | request.Content = progressContent; 80 | } 81 | } 82 | 83 | private Task AddResponseProgress(HttpRequestMessage request, HttpResponseMessage response) 84 | { 85 | Task responseTask; 86 | if (HttpReceiveProgress != null && response != null && response.Content != null) 87 | { 88 | responseTask = response.Content.ReadAsStreamAsync().Then( 89 | stream => 90 | { 91 | ProgressStream progressStream = new ProgressStream(stream, this, request, response); 92 | HttpContent progressContent = new StreamContent(progressStream); 93 | response.Content.Headers.CopyTo(progressContent.Headers); 94 | response.Content = progressContent; 95 | return response; 96 | }, runSynchronously: true); 97 | } 98 | else 99 | { 100 | responseTask = TaskHelpers.FromResult(response); 101 | } 102 | 103 | return responseTask; 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /Handlers/ProgressStream.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. 2 | 3 | using System.Diagnostics.Contracts; 4 | using System.IO; 5 | using System.Net.Http.Internal; 6 | 7 | namespace System.Net.Http.Handlers 8 | { 9 | /// 10 | /// This implementation of registers how much data has been 11 | /// read (received) versus written (sent) for a particular HTTP operation. The implementation 12 | /// is client side in that the total bytes to send is taken from the request and the total 13 | /// bytes to read is taken from the response. In a server side scenario, it would be the 14 | /// other way around (reading the request and writing the response). 15 | /// 16 | internal class ProgressStream : DelegatingStream 17 | { 18 | private readonly ProgressMessageHandler _handler; 19 | private readonly HttpRequestMessage _request; 20 | 21 | private int _bytesReceived; 22 | private long? _totalBytesToReceive; 23 | 24 | private int _bytesSent; 25 | private long? _totalBytesToSend; 26 | 27 | public ProgressStream(Stream innerStream, ProgressMessageHandler handler, HttpRequestMessage request, HttpResponseMessage response) 28 | : base(innerStream) 29 | { 30 | Contract.Assert(handler != null); 31 | Contract.Assert(request != null); 32 | 33 | if (request.Content != null) 34 | { 35 | _totalBytesToSend = request.Content.Headers.ContentLength; 36 | } 37 | 38 | if (response != null && response.Content != null) 39 | { 40 | _totalBytesToReceive = response.Content.Headers.ContentLength; 41 | } 42 | 43 | _handler = handler; 44 | _request = request; 45 | } 46 | 47 | public override int Read(byte[] buffer, int offset, int count) 48 | { 49 | int bytesRead = InnerStream.Read(buffer, offset, count); 50 | ReportBytesReceived(bytesRead, null); 51 | return bytesRead; 52 | } 53 | 54 | public override int ReadByte() 55 | { 56 | int byteRead = InnerStream.ReadByte(); 57 | ReportBytesReceived(byteRead == -1 ? 0 : 1, null); 58 | return byteRead; 59 | } 60 | 61 | public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) 62 | { 63 | return InnerStream.BeginRead(buffer, offset, count, callback, state); 64 | } 65 | 66 | public override int EndRead(IAsyncResult asyncResult) 67 | { 68 | int bytesRead = InnerStream.EndRead(asyncResult); 69 | ReportBytesReceived(bytesRead, asyncResult.AsyncState); 70 | return bytesRead; 71 | } 72 | 73 | public override void Write(byte[] buffer, int offset, int count) 74 | { 75 | InnerStream.Write(buffer, offset, count); 76 | ReportBytesSent(count, null); 77 | } 78 | 79 | public override void WriteByte(byte value) 80 | { 81 | InnerStream.WriteByte(value); 82 | ReportBytesSent(1, null); 83 | } 84 | 85 | public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) 86 | { 87 | return new ProgressWriteAsyncResult(InnerStream, this, buffer, offset, count, callback, state); 88 | } 89 | 90 | public override void EndWrite(IAsyncResult asyncResult) 91 | { 92 | ProgressWriteAsyncResult.End(asyncResult); 93 | } 94 | 95 | internal void ReportBytesSent(int bytesSent, object userState) 96 | { 97 | if (bytesSent > 0) 98 | { 99 | _bytesSent += bytesSent; 100 | int percentage = 0; 101 | if (_totalBytesToSend.HasValue && _totalBytesToSend != 0) 102 | { 103 | percentage = (int)((100L * _bytesSent) / _totalBytesToSend); 104 | } 105 | 106 | // We only pass the request as it is guaranteed to be non-null (the response may be null) 107 | _handler.OnHttpRequestProgress(_request, new HttpProgressEventArgs(percentage, userState, _bytesSent, _totalBytesToSend)); 108 | } 109 | } 110 | 111 | private void ReportBytesReceived(int bytesReceived, object userState) 112 | { 113 | if (bytesReceived > 0) 114 | { 115 | _bytesReceived += bytesReceived; 116 | int percentage = 0; 117 | if (_totalBytesToReceive.HasValue && _totalBytesToReceive != 0) 118 | { 119 | percentage = (int)((100L * _bytesReceived) / _totalBytesToReceive); 120 | } 121 | 122 | // We only pass the request as it is guaranteed to be non-null (the response may be null) 123 | _handler.OnHttpResponseProgress(_request, new HttpProgressEventArgs(percentage, userState, _bytesReceived, _totalBytesToReceive)); 124 | } 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /Handlers/ProgressWriteAsyncResult.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information. 2 | 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.Diagnostics.Contracts; 5 | using System.IO; 6 | using System.Net.Http.Internal; 7 | 8 | namespace System.Net.Http.Handlers 9 | { 10 | internal class ProgressWriteAsyncResult : AsyncResult 11 | { 12 | private static readonly AsyncCallback _writeCompletedCallback = WriteCompletedCallback; 13 | 14 | private readonly Stream _innerStream; 15 | private readonly ProgressStream _progressStream; 16 | private readonly int _count; 17 | 18 | [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Exception is handled as part of IAsyncResult completion.")] 19 | public ProgressWriteAsyncResult(Stream innerStream, ProgressStream progressStream, byte[] buffer, int offset, int count, AsyncCallback callback, object state) 20 | : base(callback, state) 21 | { 22 | Contract.Assert(innerStream != null); 23 | Contract.Assert(progressStream != null); 24 | Contract.Assert(buffer != null); 25 | 26 | _innerStream = innerStream; 27 | _progressStream = progressStream; 28 | _count = count; 29 | 30 | try 31 | { 32 | IAsyncResult result = innerStream.BeginWrite(buffer, offset, count, _writeCompletedCallback, this); 33 | if (result.CompletedSynchronously) 34 | { 35 | WriteCompleted(result); 36 | } 37 | } 38 | catch (Exception e) 39 | { 40 | Complete(true, e); 41 | } 42 | } 43 | 44 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Exception is handled as part of IAsyncResult completion.")] 45 | private static void WriteCompletedCallback(IAsyncResult result) 46 | { 47 | if (result.CompletedSynchronously) 48 | { 49 | return; 50 | } 51 | 52 | ProgressWriteAsyncResult thisPtr = (ProgressWriteAsyncResult)result.AsyncState; 53 | try 54 | { 55 | thisPtr.WriteCompleted(result); 56 | } 57 | catch (Exception e) 58 | { 59 | thisPtr.Complete(false, e); 60 | } 61 | } 62 | 63 | private void WriteCompleted(IAsyncResult result) 64 | { 65 | _innerStream.EndWrite(result); 66 | _progressStream.ReportBytesSent(_count, AsyncState); 67 | Complete(result.CompletedSynchronously); 68 | } 69 | 70 | public static void End(IAsyncResult result) 71 | { 72 | AsyncResult.End(result); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Hclient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net.Http; 5 | using System.Net.Http.Headers; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace aliyundrive_Client_CSharp.aliyundrive 10 | { 11 | class Hclient : HttpClient 12 | { 13 | public Hclient() : base() 14 | { 15 | DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); 16 | } 17 | public async Task GetAsJsonAsync(string url) 18 | { 19 | var response = await GetAsync(url); 20 | if (response.IsSuccessStatusCode) 21 | return JsonSerializer.Deserialize(await response.Content.ReadAsStringAsync(), new JsonSerializerOptions 22 | { 23 | PropertyNameCaseInsensitive = true 24 | }); 25 | else 26 | throw new HttpRequestException(); 27 | 28 | } 29 | public async Task PostAsJsonAsync(string url, object data) 30 | { 31 | var response = await PostAsync(url, new StringContent(JsonSerializer.Serialize(data), System.Text.Encoding.UTF8, "application/json")); 32 | if (!response.IsSuccessStatusCode) 33 | throw new Exception(); 34 | 35 | } 36 | public async Task PostAsJsonAsync(string url, object data) 37 | { 38 | var response = await PostAsync(url, new StringContent(JsonSerializer.Serialize(data), System.Text.Encoding.UTF8, "application/json")); 39 | if (response.IsSuccessStatusCode) 40 | { 41 | var content = await response.Content.ReadAsStringAsync(); 42 | T d = JsonSerializer.Deserialize(content, new JsonSerializerOptions 43 | { 44 | PropertyNameCaseInsensitive = true 45 | }); 46 | return d; 47 | } 48 | else 49 | throw new Exception(response.StatusCode + " " + await response.Content.ReadAsStringAsync()); 50 | 51 | } 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /LocalFile.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace aliyundrive_Client_CSharp 9 | { 10 | class LocalFile 11 | { 12 | public static void Watch(string path, Action action) 13 | { 14 | FileListenerServer f1 = new FileListenerServer(path, action); 15 | f1.Start(); 16 | } 17 | 18 | } 19 | public class FileListenerServer 20 | { 21 | private FileSystemWatcher _watcher; 22 | Action action; 23 | public FileListenerServer() 24 | { 25 | } 26 | public FileListenerServer(string path,Action action) 27 | { 28 | this.action = action; 29 | this._watcher = new FileSystemWatcher(); 30 | _watcher.Path = path; 31 | _watcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.DirectoryName; 32 | _watcher.IncludeSubdirectories = true; 33 | _watcher.Created += FileWatcher_Created; 34 | _watcher.Changed += FileWatcher_Changed; 35 | _watcher.Deleted += FileWatcher_Deleted; 36 | _watcher.Renamed += FileWatcher_Renamed; 37 | _watcher.Error += _watcher_Error; 38 | } 39 | 40 | private void _watcher_Error(object sender, ErrorEventArgs e) 41 | { 42 | throw new NotImplementedException(); 43 | } 44 | 45 | public void Start() 46 | { 47 | 48 | this._watcher.EnableRaisingEvents = true; 49 | Console.WriteLine("文件监控已经启动[{0}]", _watcher.Path); 50 | } 51 | 52 | public void Stop() 53 | { 54 | 55 | this._watcher.EnableRaisingEvents = false; 56 | this._watcher.Dispose(); 57 | this._watcher = null; 58 | } 59 | 60 | protected void FileWatcher_Created(object sender, FileSystemEventArgs e) 61 | { 62 | Console.WriteLine("新增:" + e.ChangeType + ";" + e.FullPath + ";" + e.Name); 63 | action(e.Name,e.FullPath,e.ChangeType); 64 | } 65 | protected void FileWatcher_Changed(object sender, FileSystemEventArgs e) 66 | { 67 | Console.WriteLine("变更:" + e.ChangeType + ";" + e.FullPath + ";" + e.Name); 68 | action(e.Name, e.FullPath, e.ChangeType); 69 | } 70 | protected void FileWatcher_Deleted(object sender, FileSystemEventArgs e) 71 | { 72 | Console.WriteLine("删除:" + e.ChangeType + ";" + e.FullPath + ";" + e.Name); 73 | action(e.Name, e.FullPath, e.ChangeType); 74 | } 75 | protected void FileWatcher_Renamed(object sender, RenamedEventArgs e) 76 | { 77 | Console.WriteLine("重命名: OldPath:{0} NewPath:{1} OldFileName{2} NewFileName:{3}", e.OldFullPath, e.FullPath, e.OldName, e.Name); 78 | action(e.Name, e.FullPath, e.ChangeType); 79 | } 80 | 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Login.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 | 12 | 14 |