-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into dim/type-change-cach-invalidation
- Loading branch information
Showing
41 changed files
with
1,657 additions
and
81 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
34 changes: 34 additions & 0 deletions
34
Connectors/CSi/Speckle.Connectors.CSiShared/HostApp/CSiApplicationService.cs
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,34 @@ | ||
namespace Speckle.Connectors.CSiShared.HostApp; | ||
|
||
/// <summary> | ||
/// Create a centralized access point for ETABS and SAP APIs across the entire program. | ||
/// </summary> | ||
/// <remarks> | ||
/// All API methods are based on the objectType and objectName, not the GUID. | ||
/// CSi is already giving us the "sapModel" reference through the plugin interface. No need to attach to running instance. | ||
/// Since objectType is a single int (1, 2 ... 7) we know first index will always be the objectType. | ||
/// Prevent having to pass the "sapModel" around between classes and this ensures consistent access. | ||
/// Name "sapModel" is misleading since it doesn't only apply to SAP2000, but this is the convention in the API, so we keep it. | ||
/// </remarks> | ||
public interface ICSiApplicationService | ||
{ | ||
cSapModel SapModel { get; } | ||
void Initialize(cSapModel sapModel, cPluginCallback pluginCallback); | ||
} | ||
|
||
public class CSiApplicationService : ICSiApplicationService | ||
{ | ||
public cSapModel SapModel { get; private set; } | ||
private cPluginCallback _pluginCallback; | ||
|
||
public CSiApplicationService() | ||
{ | ||
SapModel = null!; | ||
} | ||
|
||
public void Initialize(cSapModel sapModel, cPluginCallback pluginCallback) | ||
{ | ||
SapModel = sapModel; | ||
_pluginCallback = pluginCallback; | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
Connectors/CSi/Speckle.Connectors.CSiShared/HostApp/CSiDocumentModelStore.cs
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,79 @@ | ||
using System.IO; | ||
using Microsoft.Extensions.Logging; | ||
using Speckle.Connectors.DUI.Models; | ||
using Speckle.Connectors.DUI.Utils; | ||
using Speckle.Sdk; | ||
using Speckle.Sdk.Helpers; | ||
using Speckle.Sdk.Logging; | ||
|
||
namespace Speckle.Connectors.CSiShared.HostApp; | ||
|
||
public class CSiDocumentModelStore : DocumentModelStore | ||
{ | ||
private readonly ISpeckleApplication _speckleApplication; | ||
private readonly ILogger<CSiDocumentModelStore> _logger; | ||
private readonly ICSiApplicationService _csiApplicationService; | ||
private string HostAppUserDataPath { get; set; } | ||
private string DocumentStateFile { get; set; } | ||
private string ModelPathHash { get; set; } | ||
|
||
public CSiDocumentModelStore( | ||
IJsonSerializer jsonSerializerSettings, | ||
ISpeckleApplication speckleApplication, | ||
ILogger<CSiDocumentModelStore> logger, | ||
ICSiApplicationService csiApplicationService | ||
) | ||
: base(jsonSerializerSettings) | ||
{ | ||
_speckleApplication = speckleApplication; | ||
_logger = logger; | ||
_csiApplicationService = csiApplicationService; | ||
SetPaths(); | ||
LoadState(); | ||
} | ||
|
||
private void SetPaths() | ||
{ | ||
ModelPathHash = Crypt.Md5(_csiApplicationService.SapModel.GetModelFilepath(), length: 32); | ||
HostAppUserDataPath = Path.Combine( | ||
SpecklePathProvider.UserSpeckleFolderPath, | ||
"ConnectorsFileData", | ||
_speckleApplication.Slug | ||
); | ||
DocumentStateFile = Path.Combine(HostAppUserDataPath, $"{ModelPathHash}.json"); | ||
} | ||
|
||
protected override void HostAppSaveState(string modelCardState) | ||
{ | ||
try | ||
{ | ||
if (!Directory.Exists(HostAppUserDataPath)) | ||
{ | ||
Directory.CreateDirectory(HostAppUserDataPath); | ||
} | ||
File.WriteAllText(DocumentStateFile, modelCardState); | ||
} | ||
catch (Exception ex) when (!ex.IsFatal()) | ||
{ | ||
_logger.LogError(ex.Message); | ||
} | ||
} | ||
|
||
protected override void LoadState() | ||
{ | ||
if (!Directory.Exists(HostAppUserDataPath)) | ||
{ | ||
ClearAndSave(); | ||
return; | ||
} | ||
|
||
if (!File.Exists(DocumentStateFile)) | ||
{ | ||
ClearAndSave(); | ||
return; | ||
} | ||
|
||
string serializedState = File.ReadAllText(DocumentStateFile); | ||
LoadFromString(serializedState); | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
Connectors/CSi/Speckle.Connectors.CSiShared/HostApp/CSiSendCollectionManager.cs
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,39 @@ | ||
using Speckle.Converters.Common; | ||
using Speckle.Converters.CSiShared; | ||
using Speckle.Sdk.Models.Collections; | ||
|
||
namespace Speckle.Connectors.CSiShared.HostApp; | ||
|
||
/// <summary> | ||
/// We can use the CSiWrappers to create our collection structure. | ||
/// </summary> | ||
/// <remarks> | ||
/// This class manages the collections. If the key (from the path) already exists, this collection is returned. | ||
/// If it doesn't exist, a new collection is created and added to the rootObject. | ||
/// </remarks> | ||
public class CSiSendCollectionManager | ||
{ | ||
private readonly IConverterSettingsStore<CSiConversionSettings> _converterSettings; | ||
private readonly Dictionary<string, Collection> _collectionCache = new(); | ||
|
||
public CSiSendCollectionManager(IConverterSettingsStore<CSiConversionSettings> converterSettings) | ||
{ | ||
_converterSettings = converterSettings; | ||
} | ||
|
||
// TODO: Frames could be further classified under Columns, Braces and Beams. Same for Shells which could be classified into walls, floors | ||
public Collection AddObjectCollectionToRoot(ICSiWrapper csiObject, Collection rootObject) | ||
{ | ||
var path = csiObject.GetType().Name.Replace("Wrapper", ""); // CSiJointWrapper → CSiJoint, CSiFrameWrapper → CSiFrame etc. | ||
|
||
if (_collectionCache.TryGetValue(path, out Collection? collection)) | ||
{ | ||
return collection; | ||
} | ||
|
||
Collection childCollection = new(path); | ||
rootObject.elements.Add(childCollection); | ||
_collectionCache[path] = childCollection; | ||
return childCollection; | ||
} | ||
} |
27 changes: 0 additions & 27 deletions
27
Connectors/CSi/Speckle.Connectors.CSiShared/HostApp/CSiSharedApplicationService.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.