Skip to content

Commit

Permalink
fixed the bug the external reference definiton file cannot be loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
kerryjiang committed May 30, 2019
1 parent a495c46 commit 1957976
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build/Common.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>0.2.0</Version>
<Version>0.2.2</Version>
<Company>SciSharp</Company>
<Product>SciSharp.ICSharpCore</Product>
<Authors>Kerry Jiang, Haiping Chen</Authors>
Expand Down
4 changes: 2 additions & 2 deletions kernel-spec/kernel-docker.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"argv": ["icsharp-kernel", "{connection_file}"],
"argv": ["icsharp-kernel", "{connection_file}", "/scisharp/refs.txt"],
"display_name": "SciSharp Cube",
"language": "csharp"
}
}
8 changes: 7 additions & 1 deletion src/ICSharpCore/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using ICSharpCore.Script;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;
using Newtonsoft.Json;
Expand Down Expand Up @@ -33,6 +34,11 @@ public static void Main(string[] args)
var connInfo = JsonConvert.DeserializeObject<ConnInfo>(json);
Console.WriteLine(JsonConvert.SerializeObject(connInfo));

if (args.Length > 1)
{
InteractiveScriptEngine.RefsFilePath = args[1];
}

// Handling messages

// After reading the connection file and binding to the necessary sockets,
Expand Down
15 changes: 12 additions & 3 deletions src/ICSharpCore/Script/InteractiveScriptEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,18 @@ public class InteractiveScriptEngine

private string[] _references;

public static string RefsFilePath { get; set; }

public InteractiveScriptEngine(string currentDir, ILogger logger)
{
_currentDirectory = currentDir;
_logger = logger;

_scriptOptions = CreateScriptOptions();

var referencesFile = Path.Combine(Directory.GetCurrentDirectory(), "refs.txt");
var referencesFile = RefsFilePath;

if (File.Exists(referencesFile))
if (!string.IsNullOrEmpty(referencesFile) && File.Exists(referencesFile))
{
_references = File.ReadAllLines(referencesFile, Encoding.UTF8);
}
Expand Down Expand Up @@ -94,12 +96,19 @@ public async Task<object> ExecuteAsync(string statement)
"using static ICSharpCore.Primitives.DisplayDataEmitter;"
};

var refsFromFile = string.Empty;

var references = _references;

if (references != null && references.Any())
{
foreach (var line in references)
{
if (line.StartsWith("#r ") || line.StartsWith("#load "))
{
TryLoadReferenceFromScript(line);
}
}

usingStatements = references.Union(usingStatements).ToArray();
}

Expand Down

0 comments on commit 1957976

Please sign in to comment.