Skip to content

Commit

Permalink
code format
Browse files Browse the repository at this point in the history
  • Loading branch information
konakonall committed Apr 28, 2021
1 parent 9d383f1 commit 045c63d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 46 deletions.
18 changes: 10 additions & 8 deletions QCloudCSharpSDK/COSXML/Transfer/COSXMLDownloadTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ internal void Download()
{
resumableTaskFile = getObjectRequest.GetSaveFilePath() + ".cosresumabletask";
}
resumeDownloadInPossible(result, getObjectRequest.GetSaveFilePath());
ResumeDownloadInPossible(result, getObjectRequest.GetSaveFilePath());
}

//download
Expand Down Expand Up @@ -142,7 +142,7 @@ internal void Download()
});
}

private void resumeDownloadInPossible(HeadObjectResult result, string localFile)
private void ResumeDownloadInPossible(HeadObjectResult result, string localFile)
{
DownloadResumableInfo resumableInfo = DownloadResumableInfo.loadFromResumableFile(resumableTaskFile);

Expand Down Expand Up @@ -173,25 +173,26 @@ private void resumeDownloadInPossible(HeadObjectResult result, string localFile)
}
}

private bool compareCrc64(string localFile, string crc64ecma)
private bool CompareCrc64(string localFile, string crc64ecma)
{
CRC64.InitECMA();
Crc64.InitECMA();
String hash = String.Empty;

using (FileStream fs = File.Open(localFile, FileMode.Open))
{
byte[] buffer = new byte[2048];
int bytesRead;
ulong crc = 0;
while((bytesRead = fs.Read(buffer, 0, buffer.Length)) > 0) {
ulong partCrc = CRC64.Compute(buffer, 0, bytesRead);
while((bytesRead = fs.Read(buffer, 0, buffer.Length)) > 0)
{
ulong partCrc = Crc64.Compute(buffer, 0, bytesRead);
if (crc == 0)
{
crc = partCrc;
}
else
{
crc = CRC64.Combine(crc, partCrc, bytesRead);
crc = Crc64.Combine(crc, partCrc, bytesRead);
}
}
localFileCrc64 = crc.ToString();
Expand Down Expand Up @@ -230,7 +231,7 @@ private void GetObject(GetObjectRequest getObjectRequest, string crc64ecma)
}
}

if (resumable && crc64ecma != null && !compareCrc64(getObjectRequest.GetSaveFilePath(), crc64ecma))
if (resumable && crc64ecma != null && !CompareCrc64(getObjectRequest.GetSaveFilePath(), crc64ecma))
{
// crc64 is not match
if (UpdateTaskState(TaskState.Failed))
Expand Down Expand Up @@ -377,6 +378,7 @@ public static DownloadResumableInfo loadFromResumableFile(string taskFile)
using (FileStream stream = File.OpenRead(taskFile))
{
DownloadResumableInfo resumableInfo = XmlParse.Deserialize<DownloadResumableInfo>(stream);

return resumableInfo;
}
}
Expand Down
20 changes: 8 additions & 12 deletions QCloudCSharpSDK/COSXML/Utils/CRC64.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
// Copyright (c) Damien Guard. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Originally published at http://damieng.com/blog/2007/11/19/calculating-crc-64-in-c-and-net

using System;
using System.Collections.Generic;
using System.Security.Cryptography;

namespace COSXML.Utils
{
public class CRC64
public class Crc64
{
private static ulong[] _table;
private static object _lock = new object();
private const int GF2_DIM = 64; /* dimension of GF(2) vectors (length of CRC) */
private const int GF2_DIM = 64;
private static ulong _poly;

private static void GenStdCrcTable(ulong poly)
Expand All @@ -36,6 +29,7 @@ private static void GenStdCrcTable(ulong poly)
crc = (crc >> 1);
}
}

_table[n] = crc;
}
}
Expand Down Expand Up @@ -85,7 +79,9 @@ private static ulong Gf2MatrixTimes(ulong[] mat, ulong vec)
while (vec != 0)
{
if ((vec & 1) == 1)
{
sum ^= mat[idx];
}
vec >>= 1;
idx++;
}
Expand All @@ -106,11 +102,11 @@ static public ulong Combine(ulong crc1, ulong crc2, long len2)

int n;
ulong row;
ulong[] even = new ulong[GF2_DIM]; // even-power-of-two zeros operator
ulong[] odd = new ulong[GF2_DIM]; // odd-power-of-two zeros operator
ulong[] even = new ulong[GF2_DIM];
ulong[] odd = new ulong[GF2_DIM];

// put operator for one zero bit in odd
odd[0] = _poly; // CRC-64 polynomial
odd[0] = _poly;

row = 1;
for (n = 1; n < GF2_DIM; n++)
Expand Down
1 change: 1 addition & 0 deletions QCloudCSharpSDK/COSXMLTests/CITest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public void QRCodeRecognition()
o["rules"] = rules;

string ruleString = o.ToString(Formatting.None);

request.SetRequestHeader("Pic-Operations", ruleString);
//执行请求
PutObjectResult result = QCloudServer.Instance().cosXml.PutObject(request);
Expand Down
7 changes: 5 additions & 2 deletions QCloudCSharpSDK/COSXMLTests/ObjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,8 +1237,10 @@ public void TestDownloadResumableTask()
{
downloadTask.Cancel();
}

Thread.Sleep(500);
} else
}
else
{
Console.WriteLine("localFileCrc64 = " + downloadTask.GetLocalFileCrc64());
Thread.Sleep(500);
Expand Down Expand Up @@ -1521,7 +1523,8 @@ public void DeletePrefix()

do
{
string prefix = "folder1/"; //对象键
//对象键
string prefix = "folder1/";
GetBucketRequest listRequest = new GetBucketRequest(bucket);
//获取 a/ 下的对象以及子目录
listRequest.SetPrefix(prefix);
Expand Down
49 changes: 25 additions & 24 deletions QCloudCSharpSDK/COSXMLTests/ServerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,6 @@

namespace COSXMLTests
{
public class CustomQCloudCredentialProvider : QCloudCredentialProvider
{
public override QCloudCredentials GetQCloudCredentials()
{
return base.GetQCloudCredentials();
}

public override void Refresh()
{
throw new NotImplementedException();
}
}
public class CustomQCloudCredentialProvider2 : QCloudCredentialProvider
{
public override QCloudCredentials GetQCloudCredentialsWithRequest(Request request)
{
return base.GetQCloudCredentialsWithRequest(request);
}

public override void Refresh()
{
throw new NotImplementedException();
}
}

[TestFixture()]
public class ServerTest
Expand Down Expand Up @@ -112,4 +88,29 @@ private void ValidateBucketList(ListAllMyBuckets bucketList)
}

}

public class CustomQCloudCredentialProvider : QCloudCredentialProvider
{
public override QCloudCredentials GetQCloudCredentials()
{
return base.GetQCloudCredentials();
}

public override void Refresh()
{
throw new NotImplementedException();
}
}
public class CustomQCloudCredentialProvider2 : QCloudCredentialProvider
{
public override QCloudCredentials GetQCloudCredentialsWithRequest(Request request)
{
return base.GetQCloudCredentialsWithRequest(request);
}

public override void Refresh()
{
throw new NotImplementedException();
}
}
}

0 comments on commit 045c63d

Please sign in to comment.