Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add connect block transfer #53

Merged
merged 1 commit into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AasxServerBlazor/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"AasxServerBlazor": {
"commandName": "Project",
"commandLineArgs": "--data-path C:\\Users\\7wrmhx\\Documents\\_Standardization\\Diedrich\\test --rest --no-security --connect --name aorzelski.local",
"commandLineArgs": "--data-path C:\\Development\\AASX_DigTyp40 --rest --no-security --connect --name aorzelski.local",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
Expand Down
86 changes: 76 additions & 10 deletions src/AasxServerStandardBib/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,13 @@ public TransmitFrame()
static bool getDirectory = true;
static string getDirectoryDestination = "";

static string getaasxFile_destination = "";
static string getaasxFile_fileName = "";
static string getaasxFile_fileData = "";
static int getaasxFile_fileLen = 0;
static int getaasxFile_fileTransmitted = 0;
static int blockSize = 2000000;

static List<TransmitData> tdPending = new List<TransmitData> { };

public static void connectThreadLoop()
Expand Down Expand Up @@ -829,6 +836,49 @@ public static void connectThreadLoop()
getDirectoryDestination = "";
}

if (getaasxFile_destination != "") // block transfer
{
dynamic res = new System.Dynamic.ExpandoObject();

td = new TransmitData
{
source = connectNodeName
};

int len = 0;
if ((getaasxFile_fileLen - getaasxFile_fileTransmitted) > blockSize)
{
len = blockSize;
}
else
{
len = getaasxFile_fileLen - getaasxFile_fileTransmitted;
}

res.fileData = getaasxFile_fileData.Substring(getaasxFile_fileTransmitted, len);
res.fileName = getaasxFile_fileName;
res.fileLen = getaasxFile_fileLen;
res.fileTransmitted = getaasxFile_fileTransmitted;

string responseJson = JsonConvert.SerializeObject(res, Formatting.Indented);

td.destination = getaasxFile_destination;
td.type = "getaasxBlock";
td.publish.Add(responseJson);
tf.data.Add(td);

getaasxFile_fileTransmitted += len;

if (getaasxFile_fileTransmitted == getaasxFile_fileLen)
{
getaasxFile_destination = "";
getaasxFile_fileName = "";
getaasxFile_fileData = "";
getaasxFile_fileLen = 0;
getaasxFile_fileTransmitted = 0;
}
}

if (tdPending.Count != 0)
{
foreach (TransmitData tdp in tdPending)
Expand Down Expand Up @@ -975,18 +1025,29 @@ public static void connectThreadLoop()
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
string fileToken = Jose.JWT.Encode(payload, enc.GetBytes(AasxRestServerLibrary.AasxHttpContextHelper.secretString), JwsAlgorithm.HS256);

res.fileName = Path.GetFileName(Program.envFileName[aasIndex]);
res.fileData = fileToken;
if (fileToken.Length <= blockSize)
{
res.fileName = Path.GetFileName(Program.envFileName[aasIndex]);
res.fileData = fileToken;

string responseJson = JsonConvert.SerializeObject(res, Formatting.Indented);
string responseJson = JsonConvert.SerializeObject(res, Formatting.Indented);

TransmitData tdp = new TransmitData();
TransmitData tdp = new TransmitData();

tdp.source = connectNodeName;
tdp.destination = td2.source;
tdp.type = "getaasxFile";
tdp.publish.Add(responseJson);
tdPending.Add(tdp);
tdp.source = connectNodeName;
tdp.destination = td2.source;
tdp.type = "getaasxFile";
tdp.publish.Add(responseJson);
tdPending.Add(tdp);
}
else
{
getaasxFile_destination = td2.source;
getaasxFile_fileName = Path.GetFileName(Program.envFileName[aasIndex]);
getaasxFile_fileData = fileToken;
getaasxFile_fileLen = getaasxFile_fileData.Length;
getaasxFile_fileTransmitted = 0;
}
}

if (td2.type == "submodel")
Expand Down Expand Up @@ -1160,7 +1221,12 @@ public static void connectThreadLoop()
}
}

Thread.Sleep(connectUpdateRate);
if (getaasxFile_destination != "") // block transfer
{
Thread.Sleep(200);
}
else
Thread.Sleep(connectUpdateRate);
}
}

Expand Down