aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Stubs Collection/stubs/file read from machine.cs
blob: 7298c3c98d9c24addd682a76b5a529c7abfa1780 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Text;
using System.Linq;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;
using Tango.PMR.Hardware;
using Tango.PMR.Stubs;
using Tango.PMR.IO;
using Google.Protobuf;
using System.IO;
using Tango.Stubs;

public void OnExecute(StubManager stubManager)
{
	
UploadHardwareConfigurationRequest uploadHardwareConfigurationRequest = new UploadHardwareConfigurationRequest();

/*
	
FileChunkDownloadResponse fileChunkDownloadResponse = new FileChunkDownloadResponse();

ByteString byteString = new ByteString();
byteString.Length = 0;
byteString.IsEmpty = false;
byteString.Item = 0;

fileChunkDownloadResponse.Buffer = buffer;
fileChunkDownloadResponse.IsCanceled = false;
*/

	FileDownloadRequest fileDownloadRequest = new FileDownloadRequest();
	fileDownloadRequest.FileName = "0://SysInfo//GenHwCfg.cfg";
	FileDownloadResponse response2 = stubManager.Run<FileDownloadResponse>(fileDownloadRequest);
	
	long chunk_size = response2.MaxChunkLength;
   stubManager.Write( chunk_size+" \r\n");

   byte[] chunk = new byte[chunk_size];
	
	FileStream fs = new FileStream("C:\\Temp\\GenHwCfg.cfg",FileMode.Create);
	bool done = false;
	int location = 0;	
	while (done == false)
	{
			stubManager.Write("Position "+ fs.Position+ " Length "+ fs.Length +"\n\n");
			FileChunkDownloadRequest fileChunkDownloadRequest = new FileChunkDownloadRequest();
			fileChunkDownloadRequest.DownloadID = response2.DownloadID;
			var response3 = stubManager.Run<FileChunkDownloadResponse>(fileChunkDownloadRequest);
			response3.Buffer.CopyTo(chunk,location);
			stubManager.Write("Length "+ response3.Buffer.Length + "\n\n");
			fs.Write(chunk,location,response3.Buffer.Length);
			if (response3.Buffer.Length<chunk_size)
				done = true;
			location+=response3.Buffer.Length;
			Thread.Sleep(2000);
			stubManager.Write( location+" \r\n");
	}
	
	byte[] fileBytes = File.ReadAllBytes("C:\\Temp\\GenHwCfg.cfg");


	var config = UploadHardwareConfigurationRequest.Parser.ParseFrom(fileBytes);
	
		stubManager.Write( config+"% \n");

}