Skip to content

Commit

Permalink
Update async naming
Browse files Browse the repository at this point in the history
  • Loading branch information
adamenagy committed Oct 18, 2021
1 parent 28f09b4 commit 4580d97
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 35 deletions.
21 changes: 8 additions & 13 deletions UpdateIPTParam/SampleAutomation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,11 @@ public async Task RunAsync(Document doc)

string data = System.IO.File.ReadAllText(paramsPath);
LogTrace("After reading " + paramsJsonFile);
//this errors out :-s >> LogTrace($"Params content = {data}");

JObject jParamsRoot = JObject.Parse(data);
string text = jParamsRoot.ToString(Formatting.None);
Trace.WriteLine(text);

//LogTrace("Updating...");
//asm.Update2(true);

var directUpload = false;
do {
directUpload = jParamsRoot["directUpload"].Value<bool>();
Expand All @@ -85,8 +81,8 @@ public async Task RunAsync(Document doc)
if (directUpload)
{
var outputPngCallback = jParamsRoot["outputPngCallback"].Value<string>();
await UploadFile(outputPngUrl, outputPngFile);
_ = UploadData(outputPngCallback, "{ }");
await UploadFileAsync(outputPngUrl, outputPngFile);
_ = UploadDataAsync(outputPngCallback, "{ }");
}
}

Expand All @@ -95,8 +91,7 @@ public async Task RunAsync(Document doc)
string positionData = SavePositions(asm.ComponentDefinition);
if (directUpload)
{
//_ = UploadFile(outputJsonUrl, outputJsonFile);
_ = UploadData(outputJsonUrl, positionData);
_ = UploadDataAsync(outputJsonUrl, positionData);
}
}

Expand All @@ -114,22 +109,22 @@ public async Task RunAsync(Document doc)

if (directUpload)
{
_ = UploadFile(outputZipUrl, outputZipFile);
_ = UploadFileAsync(outputZipUrl, outputZipFile);
}
}

t.Abort();

if (directUpload)
{
jParamsRoot = await GetData(jParamsRoot["dataCallback"].Value<string>());
jParamsRoot = await GetDataAsync(jParamsRoot["dataCallback"].Value<string>());
}
} while (directUpload);
}
catch (Exception e) { LogTrace("RunAsync. Processing failed: {0}", e.ToString()); }
}

public async Task UploadFile(string url, string fileName)
public async Task UploadFileAsync(string url, string fileName)
{
LogTrace("[UploadFile]");
LogTrace(url + " / " + fileName);
Expand All @@ -145,7 +140,7 @@ public async Task UploadFile(string url, string fileName)
}
}

public async Task UploadData(string url, string data)
public async Task UploadDataAsync(string url, string data)
{
try
{
Expand All @@ -166,7 +161,7 @@ public async Task UploadData(string url, string data)
catch (Exception e) { LogTrace("UploadData. Processing failed: {0}", e.ToString()); }
}

public async Task<JObject> GetData(string url)
public async Task<JObject> GetDataAsync(string url)
{
LogTrace("[GetData]");
LogTrace(url);
Expand Down
44 changes: 22 additions & 22 deletions forgesample/Controllers/DesignAutomationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ public async Task<IActionResult> UploadOssFiles([FromBody]JObject appBundleSpecs

dynamic res = await objects.UploadObjectAsync(BucketKey, fileName, (int)streamReader.BaseStream.Length, streamReader.BaseStream, "application/octet-stream");

_ = TranslateFile(res.objectId, null);
_ = TranslateFileAsync(res.objectId, null);
}

return Ok();
}

private async Task TranslateFile(string objectId, string rootFileName)
private async Task TranslateFileAsync(string objectId, string rootFileName)
{
dynamic oauth = await OAuthController.GetInternalAsync();

Expand Down Expand Up @@ -366,7 +366,7 @@ public async Task<IActionResult> CreateActivity([FromBody]JObject activitySpecs)
/// <summary>
/// Define a new activity
/// </summary>
public static async Task<bool> IsInCache(string fileName)
public static async Task<bool> IsInCacheAsync(string fileName)
{
dynamic oauth = await OAuthController.GetInternalAsync();
ObjectsApi objects = new ObjectsApi();
Expand Down Expand Up @@ -405,7 +405,7 @@ public async Task<IActionResult> StartWorkitems([FromBody]JObject input)
string pngFileName = hash + ".png";
string jsonFileName = browserConnectionId + ".json";

if (useCache && await IsInCache(zipFileName))
if (useCache && await IsInCacheAsync(zipFileName))
{
double[] cells = new double[] {
1, 0, 0, 0,
Expand All @@ -414,7 +414,7 @@ public async Task<IActionResult> StartWorkitems([FromBody]JObject input)
0, 0, 0, 1
};

_ = SendPictureUrlToClient(browserConnectionId, pngFileName);
_ = SendPictureUrlToClientAsync(browserConnectionId, pngFileName);

JObject data = new JObject(
new JProperty("components",
Expand All @@ -426,7 +426,7 @@ public async Task<IActionResult> StartWorkitems([FromBody]JObject input)
)
)
);
_ = SendComponentsDataToClient(browserConnectionId, data);
_ = SendComponentsDataToClientAsync(browserConnectionId, data);

return Ok(new {
PngWorkItemId = pngWorkItemId,
Expand All @@ -437,7 +437,7 @@ public async Task<IActionResult> StartWorkitems([FromBody]JObject input)

if (keepWorkitem)
{
sessionWorkItemId = await CreateSessionWorkItem(
sessionWorkItemId = await CreateSessionWorkItemAsync(
input,
new Dictionary<string, string>() { { "Authorization", "Bearer " + oauth.access_token } },
browserConnectionId,
Expand All @@ -455,7 +455,7 @@ public async Task<IActionResult> StartWorkitems([FromBody]JObject input)
});
}

pngWorkItemId = await CreateWorkItem(
pngWorkItemId = await CreateWorkItemAsync(
input,
new Dictionary<string, string>() { { "Authorization", "Bearer " + oauth.access_token } },
browserConnectionId,
Expand All @@ -466,7 +466,7 @@ public async Task<IActionResult> StartWorkitems([FromBody]JObject input)

if (useCache)
{
zipWorkItemId = await CreateWorkItem(
zipWorkItemId = await CreateWorkItemAsync(
input,
new Dictionary<string, string>() { { "Authorization", "Bearer " + oauth.access_token } },
browserConnectionId,
Expand All @@ -476,7 +476,7 @@ public async Task<IActionResult> StartWorkitems([FromBody]JObject input)
);
}

jsonWorkItemId = await CreateWorkItem(
jsonWorkItemId = await CreateWorkItemAsync(
input,
new Dictionary<string, string>() { { "Content-Type", "application/json" } },
browserConnectionId,
Expand All @@ -492,7 +492,7 @@ public async Task<IActionResult> StartWorkitems([FromBody]JObject input)
SessionWorkItemId = sessionWorkItemId
});
}
private async Task<string> CreateWorkItem(JObject input, Dictionary<string, string> headers, string browserConnectionId, string outputName, string fileName, string url)
private async Task<string> CreateWorkItemAsync(JObject input, Dictionary<string, string> headers, string browserConnectionId, string outputName, string fileName, string url)
{
input["directUpload"] = false;
input[outputName] = url;
Expand Down Expand Up @@ -530,7 +530,7 @@ private async Task<string> CreateWorkItem(JObject input, Dictionary<string, stri
return workItemStatus.Id;
}

private async Task<string> CreateSessionWorkItem(JObject input, Dictionary<string, string> headers, string browserConnectionId, string jsonFileName, string pngFileName, string zipFileName)
private async Task<string> CreateSessionWorkItemAsync(JObject input, Dictionary<string, string> headers, string browserConnectionId, string jsonFileName, string pngFileName, string zipFileName)
{
if (zipFileName != null)
{
Expand Down Expand Up @@ -583,13 +583,13 @@ private async Task<string> CreateSessionWorkItem(JObject input, Dictionary<strin
return workItemStatus.Id;
}

private async Task SendComponentsDataToClient(string id, JObject data)
private async Task SendComponentsDataToClientAsync(string id, JObject data)
{
data["urnBase"] = "urn:adsk.objects:os.object:" + BucketKey + "/";
await _hubContext.Clients.Client(id).SendAsync("onComponents", data.ToString(Formatting.None));
}

private async Task SendStringToClient(string id, string data)
private async Task SendStringToClientAsync(string id, string data)
{
await _hubContext.Clients.Client(id).SendAsync("onComplete", data);
}
Expand Down Expand Up @@ -621,7 +621,7 @@ private async Task<string> CreateSignedResourceAsync(string fileName, string acc
return signedUrl.Data.signedUrl;
}

private async Task SendPictureUrlToClient(string id, string pngFile)
private async Task SendPictureUrlToClientAsync(string id, string pngFile)
{
System.Diagnostics.Debug.WriteLine("SendPictureUrlToClient: " + pngFile);

Expand All @@ -644,10 +644,10 @@ public async Task<IActionResult> OnData([FromRoute] string fileType, [FromQuery]

// urnBase, something like "urn:adsk.objects:os.object:rgm0mo9jvssd2ybedk9mrtxqtwsa61y0-designautomation/"
if (fileType == "json")
_ = SendComponentsDataToClient(id, data);
_ = SendComponentsDataToClientAsync(id, data);

if (fileType == "png")
_ = SendPictureUrlToClient(id, outputFile);
_ = SendPictureUrlToClientAsync(id, outputFile);

return Ok();
}
Expand All @@ -658,7 +658,7 @@ public async Task<IActionResult> OnData([FromRoute] string fileType, [FromQuery]
/// </summary>
[HttpGet]
[Route("api/forge/designautomation/data")]
public async Task<IActionResult> GetData([FromQuery] string id)
public async Task<IActionResult> GetDataAsync([FromQuery] string id)
{
System.Diagnostics.Debug.WriteLine("GetData");

Expand All @@ -680,7 +680,7 @@ public async Task<IActionResult> OnComplete(string id, string outputFile, [FromB
{
// your webhook should return immediately! we can use Hangfire to schedule a job
JObject bodyJson = JObject.Parse((string)body.ToString());
_ = SendStringToClient(id, bodyJson.ToString());
_ = SendStringToClientAsync(id, bodyJson.ToString());

if (_runningWorkitems.ContainsKey(id) && _runningWorkitems[id] == bodyJson["id"].Value<string>())
{
Expand All @@ -692,17 +692,17 @@ public async Task<IActionResult> OnComplete(string id, string outputFile, [FromB

byte[] bs = client.DownloadData(request);
string report = System.Text.Encoding.Default.GetString(bs);
_ = SendStringToClient(id, report);
_ = SendStringToClientAsync(id, report);

if (outputFile.EndsWith(".png"))
{
_ = SendPictureUrlToClient(id, outputFile);
_ = SendPictureUrlToClientAsync(id, outputFile);
}

if (outputFile.EndsWith(".zip"))
{
string objectId = "urn:adsk.objects:os.object:" + BucketKey + "/" + outputFile;
_ = TranslateFile(objectId, "shelves.iam");
_ = TranslateFileAsync(objectId, "shelves.iam");
}
}
catch (Exception e)
Expand Down
Binary file modified forgesample/wwwroot/bundles/UpdateIPTParam.bundle.zip
Binary file not shown.

0 comments on commit 4580d97

Please sign in to comment.