diff --git a/MConnectSDK/MConnectClient.cs b/MConnectSDK/MConnectClient.cs index b5450f2..7b46aab 100644 --- a/MConnectSDK/MConnectClient.cs +++ b/MConnectSDK/MConnectClient.cs @@ -1516,7 +1516,7 @@ namespace MConnectSDK // return finale dello status della chiamata... return _currReq; } - public async Task TryUpLoadFile(CancellationToken token, IProgress progress, string pathFile) + public async Task TryUpLoadFile(CancellationToken token, IProgress progress, string fileName) { Result result = new Result(); @@ -1525,8 +1525,10 @@ namespace MConnectSDK result.Payload = new FileUpLoadPayload(); result.CallResultOk = true; - // trasformo filepath --> nome + bytestream... - var uplResult = Utils.uploadAsync(pageUrlFileUpload, "nomeFile", new byte[]); + byte[] fileBytes = File.ReadAllBytes(fileName); + + // trasformo filepath --> nome + bytestream... + var uplResult = Utils.uploadAsync(pageUrlFileUpload, fileName, fileBytes); @@ -1541,7 +1543,7 @@ namespace MConnectSDK result.Payload = new FileUpLoadPayload() { expiry = DateTime.Now.AddHours(1).ToString("o"), - filename = Path.GetFileNameWithoutExtension(pathFile), + filename = Path.GetFileNameWithoutExtension(fileName), link = $"http:\\" }; } diff --git a/MConnectSDK/MConnectSDK.csproj b/MConnectSDK/MConnectSDK.csproj index 95383ab..4da0161 100644 --- a/MConnectSDK/MConnectSDK.csproj +++ b/MConnectSDK/MConnectSDK.csproj @@ -35,13 +35,13 @@ ..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll - ..\packages\NLog.4.5.11\lib\net45\NLog.dll + ..\packages\NLog.4.6.0\lib\net45\NLog.dll - ..\packages\Pipelines.Sockets.Unofficial.1.1.14\lib\net461\Pipelines.Sockets.Unofficial.dll + ..\packages\Pipelines.Sockets.Unofficial.2.0.11\lib\net461\Pipelines.Sockets.Unofficial.dll - ..\packages\StackExchange.Redis.2.0.519\lib\net461\StackExchange.Redis.dll + ..\packages\StackExchange.Redis.2.0.571\lib\net461\StackExchange.Redis.dll @@ -82,8 +82,8 @@ - - ..\packages\YamlDotNet.5.4.0\lib\net45\YamlDotNet.dll + + ..\packages\YamlDotNet.6.0.0\lib\net45\YamlDotNet.dll diff --git a/MConnectSDK/Utils.cs b/MConnectSDK/Utils.cs index 6e69bb7..aaa7e1e 100644 --- a/MConnectSDK/Utils.cs +++ b/MConnectSDK/Utils.cs @@ -167,10 +167,11 @@ namespace MConnectSDK /// /// Caricamento file come multipart in modalità async /// + /// /// /// /// - public static async Task uploadAsync(string pageUrl = "https://stg.api.maestroconnect.scmgroup.com/storage-api/backups", string fileName, byte[] fileContent) + public static async Task uploadAsync(string pageUrl, string fileName, byte[] fileContent) { using (var client = new HttpClient()) { diff --git a/MConnectSDK/packages.config b/MConnectSDK/packages.config index 7db8a3d..ba937b5 100644 --- a/MConnectSDK/packages.config +++ b/MConnectSDK/packages.config @@ -1,9 +1,9 @@  - - - + + + @@ -12,5 +12,5 @@ - + \ No newline at end of file diff --git a/TestClient/MainForm.Designer.cs b/TestClient/MainForm.Designer.cs index 00a536c..b001106 100644 --- a/TestClient/MainForm.Designer.cs +++ b/TestClient/MainForm.Designer.cs @@ -63,6 +63,7 @@ this.pictBox = new System.Windows.Forms.PictureBox(); this.label6 = new System.Windows.Forms.Label(); this.lblConsole = new System.Windows.Forms.Label(); + this.btnUploadFile = new System.Windows.Forms.Button(); this.statusStrip1.SuspendLayout(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); @@ -106,12 +107,13 @@ this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.groupBox1.AutoSize = true; + this.groupBox1.Controls.Add(this.btnUploadFile); this.groupBox1.Controls.Add(this.lblUserCode); this.groupBox1.Controls.Add(this.txtConfFile); this.groupBox1.Controls.Add(this.label3); this.groupBox1.Location = new System.Drawing.Point(13, 12); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(1063, 74); + this.groupBox1.Size = new System.Drawing.Size(1063, 78); this.groupBox1.TabIndex = 11; this.groupBox1.TabStop = false; this.groupBox1.Text = "Connection Parameters"; @@ -435,6 +437,16 @@ this.lblConsole.TabIndex = 7; this.lblConsole.Text = "..."; // + // btnUploadFile + // + this.btnUploadFile.Location = new System.Drawing.Point(426, 25); + this.btnUploadFile.Name = "btnUploadFile"; + this.btnUploadFile.Size = new System.Drawing.Size(111, 32); + this.btnUploadFile.TabIndex = 31; + this.btnUploadFile.Text = "<-- Upload test"; + this.btnUploadFile.UseVisualStyleBackColor = true; + this.btnUploadFile.Click += new System.EventHandler(this.btnUploadFile_Click); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); @@ -496,6 +508,7 @@ private System.Windows.Forms.Button btnDeleteUserCloud; private System.Windows.Forms.Label lblUserCode; private System.Windows.Forms.Button btnTryEnroll; + private System.Windows.Forms.Button btnUploadFile; } } diff --git a/TestClient/MainForm.cs b/TestClient/MainForm.cs index 4274d29..3c45952 100644 --- a/TestClient/MainForm.cs +++ b/TestClient/MainForm.cs @@ -807,5 +807,38 @@ namespace TestClient MessageBox.Show("COPIED current user_code to Clipboard!\r\n" + lblUserCode.Text, "USER_CODE ACQUIRED", MessageBoxButtons.OK); } + private async void btnUploadFile_Click(object sender, EventArgs e) + { + // elimino eventuali cancel presenti... + if (_cts.IsCancellationRequested) + { + _cts = new CancellationTokenSource(); + } + CancellationToken token = _cts.Token; + // gestione progress... + var progressHandler = new Progress(value => + { + // aggiorno richeista live... + reqStatus = value; + refreshRequestStatus(); + // mostro i dati SPECIFICI x AUTH... + updateAuthData((ActivationPayload)value.Payload); + }); + var progress = progressHandler as IProgress; + + await Task.Run(() => + { + var taskResult = MCC.TryUpLoadFile(token, progress, txtConfFile.Text.Trim()); +#if false + // salvo il risultato restituito... + reqStatus = taskResult.Result; + + synchronizationContext.Post(new SendOrPostCallback(o => + { + refreshRequestStatus(); + }), ""); +#endif + }); + } } } diff --git a/TestClient/TestClient.csproj b/TestClient/TestClient.csproj index a168b0d..6638132 100644 --- a/TestClient/TestClient.csproj +++ b/TestClient/TestClient.csproj @@ -52,7 +52,7 @@ ..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll - ..\packages\NLog.4.5.11\lib\net45\NLog.dll + ..\packages\NLog.4.6.0\lib\net45\NLog.dll ..\packages\NLog.Windows.Forms.4.2.3\lib\net35\NLog.Windows.Forms.dll @@ -146,6 +146,7 @@ Always + diff --git a/TestClient/packages.config b/TestClient/packages.config index 13c15cc..189c066 100644 --- a/TestClient/packages.config +++ b/TestClient/packages.config @@ -1,7 +1,7 @@  - + diff --git a/TestClient/testing/Appunti.txt b/TestClient/testing/Appunti.txt new file mode 100644 index 0000000..4a48b08 --- /dev/null +++ b/TestClient/testing/Appunti.txt @@ -0,0 +1,17 @@ +Chiamata upload --> da errore: + +{StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: +{ + x-ratelimit-limit: 5 + x-ratelimit-remaining: 4 + access-control-allow-origin: * + access-control-allow-headers: Cache-Control,X-reqed-With,x-requested-with + content-security-policy: default-src 'self' + x-content-type-options: nosniff + Alt-Svc: clear + Date: Fri, 29 Mar 2019 20:48:07 GMT + Via: 1.1 google + X-Powered-By: Express + Content-Length: 1148 + Content-Type: text/html; charset=utf-8 +}} \ No newline at end of file