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

DYN-5525: Update Insert Graph Window Title #15788

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ async void InitializeAsync()
//This indicates in which location will be created the WebView2 cache folder
documentationBrowser.CreationProperties = new CoreWebView2CreationProperties()
{
UserDataFolder = WebBrowserUserDataFolder
UserDataFolder = DynamoModel.IsTestMode ? TestUtilities.UserDataFolderDuringTests(nameof(DocumentationBrowserView)) : WebBrowserUserDataFolder
};
}

Expand Down
57 changes: 37 additions & 20 deletions src/DynamoCore/Core/IDSDKManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ public class IDSDKManager : IOAuth2AuthProvider, IOAuth2AccessTokenProvider, IOA
/// </summary>
public event Action<LoginState> LoginStateChanged;

/// <summary>
/// The event is fired when IDSDK initialization fails
/// </summary>
internal event EventHandler ErrorInitializingIDSDK;

/// <summary>
/// The flag is used to prevent multiple error messages from being shown, since initialization error can be thrown multiple times.
/// </summary>
internal bool isErrorInitializingMsgShown;
private void OnErrorInitializingIDSDK()
{
ErrorInitializingIDSDK?.Invoke(this, EventArgs.Empty);
}

/// <summary>
/// Returns the login status of the current session.
/// </summary>
Expand Down Expand Up @@ -228,38 +242,41 @@ private bool Initialize()
{
try
{
if (Client.IsInitialized()) return true;
idsdk_status_code bRet = Client.Init();
if (Client.IsInitialized())
{
isErrorInitializingMsgShown = false;
return true;
}

if (Client.IsSuccess(bRet))
idsdk_status_code bRet = Client.Init();
if (Client.IsSuccess(bRet) && Client.IsInitialized())
{
if (Client.IsInitialized())
IntPtr hWnd = Process.GetCurrentProcess().MainWindowHandle;
if (hWnd != null)
{
IntPtr hWnd = Process.GetCurrentProcess().MainWindowHandle;
if (hWnd != null)
{
Client.SetHost(hWnd);
}
Client.SetHost(hWnd);
}

bool ret = GetClientIDAndServer(out idsdk_server server, out string client_id);
if (ret)
{
Client.LogoutCompleteEvent += AuthCompleteEventHandler;
Client.LoginCompleteEvent += AuthCompleteEventHandler;
ret = SetProductConfigs(Configurations.DynamoAsString, server, client_id);
Client.SetServer(server);
return ret;
}
bool ret = GetClientIDAndServer(out idsdk_server server, out string client_id);
if (ret)
{
Client.LogoutCompleteEvent += AuthCompleteEventHandler;
Client.LoginCompleteEvent += AuthCompleteEventHandler;
ret = SetProductConfigs(Configurations.DynamoAsString, server, client_id);
Client.SetServer(server);
isErrorInitializingMsgShown = false;
return ret;
}
}
DynamoConsoleLogger.OnLogMessageToDynamoConsole("Auth Service (IDSDK) could not be initialized!");
return false;
}
catch (Exception)
{
DynamoConsoleLogger.OnLogMessageToDynamoConsole("An error occurred while initializing Auth Service (IDSDK).");
return false;
}

OnErrorInitializingIDSDK();
return false;
}
private bool Deinitialize()
{
Expand Down
1 change: 1 addition & 0 deletions src/DynamoCore/Engine/EngineController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public void Dispose()

liveRunnerServices.Dispose();
codeCompletionServices = null;
CompilationServices = null;
}

/// <summary>
Expand Down
41 changes: 19 additions & 22 deletions src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ public void ShutDown(bool shutdownHost)

AnalyticsService.ShutDown();

LuceneSearch.LuceneUtilityNodeSearch = null;
LuceneSearch.LuceneUtilityNodeAutocomplete = null;
LuceneSearch.LuceneUtilityPackageManager = null;

State = DynamoModelState.NotStarted;
OnShutdownCompleted(); // Notify possible event handlers.
}
Expand Down Expand Up @@ -1588,7 +1592,6 @@ private void InitializeIncludedNodes()

var cnbNode = new CodeBlockNodeSearchElement(cbnData, LibraryServices);
SearchModel?.Add(cnbNode);
LuceneUtility.AddNodeTypeToSearchIndex(cnbNode, iDoc);

var symbolSearchElement = new NodeModelSearchElement(symbolData)
{
Expand All @@ -1607,10 +1610,8 @@ private void InitializeIncludedNodes()
};

SearchModel?.Add(symbolSearchElement);
LuceneUtility.AddNodeTypeToSearchIndex(symbolSearchElement, iDoc);

SearchModel?.Add(outputSearchElement);
LuceneUtility.AddNodeTypeToSearchIndex(outputSearchElement, iDoc);
LuceneUtility.AddNodeTypeToSearchIndexBulk([cnbNode, symbolSearchElement, outputSearchElement], iDoc);

}

Expand Down Expand Up @@ -1751,6 +1752,7 @@ internal void LoadNodeLibrary(Assembly assem, bool suppressZeroTouchLibraryLoad
private void LoadNodeModels(List<TypeLoadData> nodes, bool isPackageMember)
{
var iDoc = LuceneUtility.InitializeIndexDocumentForNodes();
List<NodeSearchElement> nodeSearchElements = [];
foreach (var type in nodes)
{
// Protect ourselves from exceptions thrown by malformed third party nodes.
Expand All @@ -1765,14 +1767,15 @@ private void LoadNodeModels(List<TypeLoadData> nodes, bool isPackageMember)
// TODO: get search element some other way
if (ele != null)
{
LuceneUtility.AddNodeTypeToSearchIndex(ele, iDoc);
nodeSearchElements.Add(ele);
}
}
catch (Exception e)
{
Logger.Log(e);
}
}
LuceneUtility.AddNodeTypeToSearchIndexBulk(nodeSearchElements, iDoc);
}

private void InitializePreferences()
Expand Down Expand Up @@ -3474,26 +3477,20 @@ internal void HideUnhideNamespace(bool hide, string library, string namespc)
internal void AddZeroTouchNodesToSearch(IEnumerable<FunctionGroup> functionGroups)
{
var iDoc = LuceneUtility.InitializeIndexDocumentForNodes();
List<NodeSearchElement> nodes = new();
foreach (var funcGroup in functionGroups)
AddZeroTouchNodeToSearch(funcGroup, iDoc);
}

private void AddZeroTouchNodeToSearch(FunctionGroup funcGroup, Document iDoc)
{
foreach (var functionDescriptor in funcGroup.Functions)
{
AddZeroTouchNodeToSearch(functionDescriptor, iDoc);
}
}

private void AddZeroTouchNodeToSearch(FunctionDescriptor functionDescriptor, Document iDoc)
{
if (functionDescriptor.IsVisibleInLibrary)
{
var ele = new ZeroTouchSearchElement(functionDescriptor);
SearchModel?.Add(ele);
LuceneUtility.AddNodeTypeToSearchIndex(ele, iDoc);
foreach (var functionDescriptor in funcGroup.Functions)
{
if (functionDescriptor.IsVisibleInLibrary)
{
var ele = new ZeroTouchSearchElement(functionDescriptor);
SearchModel?.Add(ele);
nodes.Add(ele);
}
}
}
LuceneUtility.AddNodeTypeToSearchIndexBulk(nodes, iDoc);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCore/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/DynamoCore/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ This package likely contains an assembly that is blocked. You will need to load
<value>Failed to insert the file as some of the nodes already exist in the current worspace.</value>
</data>
<data name="InsertDialogBoxText" xml:space="preserve">
<value>Insert Dynamo Definition...</value>
<value>Insert Dynamo Graph...</value>
</data>
<data name="InsertGraphRunModeNotificationText" xml:space="preserve">
<value>Example file added to workspace. Run mode changed to Manual.</value>
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCore/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ This package likely contains an assembly that is blocked. You will need to load
<value>Failed to insert the file as some of the nodes already exist in the current worspace.</value>
</data>
<data name="InsertDialogBoxText" xml:space="preserve">
<value>Insert Dynamo Definition...</value>
<value>Insert Dynamo Graph...</value>
</data>
<data name="InsertGraphRunModeNotificationText" xml:space="preserve">
<value>Example file added to workspace. Run mode changed to Manual.</value>
Expand Down
41 changes: 32 additions & 9 deletions src/DynamoCore/Search/NodeSearchModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Xml;
using Dynamo.Configuration;
using Dynamo.Graph.Nodes;
Expand All @@ -10,7 +11,6 @@
using Dynamo.Utilities;
using DynamoUtilities;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.QueryParsers.Classic;
using Lucene.Net.Search;

Expand Down Expand Up @@ -231,29 +231,42 @@ internal string ProcessNodeCategory(string category, ref SearchElementGroup grou
return category.Substring(0, index);
}

internal IEnumerable<NodeSearchElement> Search(string search, LuceneSearchUtility luceneSearchUtility)
/// <summary>
/// Search for nodes by using a search key.
/// </summary>
/// <param name="search"></param>
/// <param name="luceneSearchUtility"></param>
/// <param name="ctk">Cancellation token to short circuit the search.</param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
internal IEnumerable<NodeSearchElement> Search(string search, LuceneSearchUtility luceneSearchUtility, CancellationToken ctk = default)
{

ctk.ThrowIfCancellationRequested();

if (luceneSearchUtility != null)
{
//The DirectoryReader and IndexSearcher have to be assigned after commiting indexing changes and before executing the Searcher.Search() method, otherwise new indexed info won't be reflected
luceneSearchUtility.dirReader = luceneSearchUtility.writer != null ? luceneSearchUtility.writer.GetReader(applyAllDeletes: true) : DirectoryReader.Open(luceneSearchUtility.indexDir);
luceneSearchUtility.Searcher = new IndexSearcher(luceneSearchUtility.dirReader);
if (luceneSearchUtility.Searcher == null)
{
throw new Exception("Invalid IndexSearcher found");
}

string searchTerm = search.Trim();
var candidates = new List<NodeSearchElement>();

var parser = new MultiFieldQueryParser(LuceneConfig.LuceneNetVersion, LuceneConfig.NodeIndexFields, luceneSearchUtility.Analyzer)
{
AllowLeadingWildcard = true,
DefaultOperator = LuceneConfig.DefaultOperator,
FuzzyMinSim = LuceneConfig.MinimumSimilarity
};

Query query = parser.Parse(luceneSearchUtility.CreateSearchQuery(LuceneConfig.NodeIndexFields, searchTerm));
Query query = parser.Parse(luceneSearchUtility.CreateSearchQuery(LuceneConfig.NodeIndexFields, searchTerm, false, ctk));
TopDocs topDocs = luceneSearchUtility.Searcher.Search(query, n: LuceneConfig.DefaultResultsCount);

for (int i = 0; i < topDocs.ScoreDocs.Length; i++)
{
ctk.ThrowIfCancellationRequested();

// read back a Lucene doc from results
Document resultDoc = luceneSearchUtility.Searcher.Doc(topDocs.ScoreDocs[i].Doc);

Expand All @@ -268,7 +281,7 @@ internal IEnumerable<NodeSearchElement> Search(string search, LuceneSearchUtilit
}
else
{
var foundNode = FindModelForNodeNameAndCategory(name, cat, parameters);
var foundNode = FindModelForNodeNameAndCategory(name, cat, parameters, ctk);
if (foundNode != null)
{
candidates.Add(foundNode);
Expand All @@ -280,8 +293,18 @@ internal IEnumerable<NodeSearchElement> Search(string search, LuceneSearchUtilit
return null;
}

internal NodeSearchElement FindModelForNodeNameAndCategory(string nodeName, string nodeCategory, string parameters)
/// <summary>
/// Finds the node model that corresponds to the input nodeName, nodeCategory and parameters.
/// </summary>
/// <param name="nodeName"></param>
/// <param name="nodeCategory"></param>
/// <param name="parameters"></param>
/// <param name="ctk">Cancellation token to short circuit the operation.</param>
/// <returns></returns>
internal NodeSearchElement FindModelForNodeNameAndCategory(string nodeName, string nodeCategory, string parameters, CancellationToken ctk = default)
{
ctk.ThrowIfCancellationRequested();

var result = Entries.Where(e => {
if (e.Name.Replace(" ", string.Empty).Equals(nodeName) && e.FullCategoryName.Equals(nodeCategory))
{
Expand Down
Loading
Loading