forked from teocomi/BCFier
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from Dangl-IT/feature/ipc
Feature/ipc
- Loading branch information
Showing
29 changed files
with
569 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace IPA.Bcfier.App.Configuration | ||
{ | ||
public class RevitParameters | ||
{ | ||
public bool IsConnectedToRevit { get; set; } = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using IPA.Bcfier.Ipc; | ||
using IPA.Bcfier.Models.Bcf; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Newtonsoft.Json; | ||
|
||
namespace IPA.Bcfier.App.Controllers | ||
{ | ||
[ApiController] | ||
[Route("api/viewpoints")] | ||
public class ViewpointsController : ControllerBase | ||
{ | ||
[HttpPost("visualization")] | ||
public async Task<IActionResult> ShowViewpointAsync([FromBody] BcfViewpoint viewpoint) | ||
{ | ||
using var ipcHandler = new IpcHandler(thisAppName: "BcfierApp", otherAppName: "Revit"); | ||
await ipcHandler.InitializeAsync(); | ||
|
||
var correlationId = Guid.NewGuid(); | ||
await ipcHandler.SendMessageAsync(JsonConvert.SerializeObject(new IpcMessage | ||
{ | ||
CorrelationId = correlationId, | ||
Command = IpcMessageCommand.ShowViewpoint, | ||
Data = JsonConvert.SerializeObject(viewpoint) | ||
})); | ||
|
||
var hasReceived = false; | ||
var start = DateTime.Now; | ||
while (DateTime.UtcNow - start < TimeSpan.FromSeconds(120)) | ||
{ | ||
if (IpcHandler.ReceivedMessages.TryDequeue(out var message)) | ||
{ | ||
var ipcMessage = JsonConvert.DeserializeObject<IpcMessage>(message)!; | ||
if (ipcMessage.CorrelationId == correlationId) | ||
{ | ||
hasReceived = true; | ||
return NoContent(); | ||
} | ||
else | ||
{ | ||
IpcHandler.ReceivedMessages.Enqueue(message); | ||
} | ||
} | ||
} | ||
|
||
return BadRequest(); | ||
} | ||
|
||
[HttpPost("")] | ||
public async Task<IActionResult> CreateViewpointAsync() | ||
{ | ||
using var ipcHandler = new IpcHandler(thisAppName: "BcfierApp", otherAppName: "Revit"); | ||
await ipcHandler.InitializeAsync(); | ||
|
||
var correlationId = Guid.NewGuid(); | ||
await ipcHandler.SendMessageAsync(JsonConvert.SerializeObject(new IpcMessage | ||
{ | ||
CorrelationId = correlationId, | ||
Command = IpcMessageCommand.CreateViewpoint, | ||
Data = null | ||
})); | ||
|
||
var hasReceived = false; | ||
var start = DateTime.Now; | ||
while (DateTime.UtcNow - start < TimeSpan.FromSeconds(120)) | ||
{ | ||
if (IpcHandler.ReceivedMessages.TryDequeue(out var message)) | ||
{ | ||
var ipcMessage = JsonConvert.DeserializeObject<IpcMessage>(message)!; | ||
if (ipcMessage.CorrelationId == correlationId) | ||
{ | ||
hasReceived = true; | ||
var bcfViewpoint = JsonConvert.DeserializeObject<BcfViewpoint>(ipcMessage.Data!.ToString())!; | ||
return Ok(bcfViewpoint); | ||
} | ||
else | ||
{ | ||
IpcHandler.ReceivedMessages.Enqueue(message); | ||
} | ||
} | ||
} | ||
|
||
return BadRequest(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.