Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion doc/distrib/xml/en-US/DSCoreNodes.xml

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

1 change: 1 addition & 0 deletions src/DynamoCore/Configuration/ExecutionSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public ExecutionSession(Scheduler.UpdateGraphAsyncTask updateTask, DynamoModel m
parameters[ParameterKeys.LastExecutionDuration] = new TimeSpan(updateTask.ExecutionEndTime.TickCount - updateTask.ExecutionStartTime.TickCount);
parameters[ParameterKeys.PackagePaths] = pathManager.PackagesDirectories;
parameters[ParameterKeys.Logger] = model.Logger;
parameters[ParameterKeys.NoNetworkMode] = model.NoNetworkMode;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public static string Version
internal bool IsServiceMode { get; set; }

/// <summary>
/// True if Dynamo starts up in offline mode.
/// True if Dynamo is used in offline mode.
/// </summary>
internal bool NoNetworkMode { get; }

Expand Down
4 changes: 2 additions & 2 deletions src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2810,12 +2810,12 @@ internal void ShowPackageManager(object parameters)

internal bool CanShowPackageManagerSearch(object parameters)
{
return !model.IsServiceMode;
return !model.IsServiceMode && !model.NoNetworkMode;
}

internal bool CanShowPackageManager(object parameters)
{
return !model.IsServiceMode;
return !model.IsServiceMode && !model.NoNetworkMode;
}

/// <summary>
Expand Down
20 changes: 20 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,24 @@ private void AddPythonEnginesOptions()
/// </summary>
public TrustedPathViewModel TrustedPathsViewModel { get; set; }

private bool noNetworkMode;

/// <summary>
/// True if Dynamo is used in offline mode.
/// </summary>
public bool NoNetworkMode
{
get => noNetworkMode;
private set
{
if (noNetworkMode != value)
{
noNetworkMode = value;
RaisePropertyChanged(nameof(NoNetworkMode));
}
}
}

/// <summary>
/// Returns a boolean value indicating if the Settings importing was successful or not
/// </summary>
Expand Down Expand Up @@ -1469,6 +1487,8 @@ public PreferencesViewModel(DynamoViewModel dynamoViewModel)
this.pythonScriptEditorTextOptions = dynamoViewModel.PythonScriptEditorTextOptions;
this.dynamoViewModel = dynamoViewModel;

NoNetworkMode = dynamoViewModel.Model.NoNetworkMode;

if (dynamoViewModel.PackageManagerClientViewModel != null)
{
installedPackagesViewModel = new InstalledPackagesViewModel(dynamoViewModel, dynamoViewModel.PackageManagerClientViewModel.PackageManagerExtension.PackageLoader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public void PublishCurrentWorkspace(object m)

public bool CanPublishCurrentWorkspace(object m)
{
return DynamoViewModel.Model.CurrentWorkspace is CustomNodeWorkspaceModel && AuthenticationManager.HasAuthProvider;
return DynamoViewModel.Model.CurrentWorkspace is CustomNodeWorkspaceModel && AuthenticationManager.HasAuthProvider && !Model.NoNetworkMode;
}

public void PublishNewPackage(object m)
Expand All @@ -363,7 +363,7 @@ public void PublishNewPackage(object m)

public bool CanPublishNewPackage(object m)
{
return AuthenticationManager.HasAuthProvider;
return AuthenticationManager.HasAuthProvider && !Model.NoNetworkMode;
}

public void PublishCustomNode(Function m)
Expand Down Expand Up @@ -393,7 +393,7 @@ public void PublishCustomNode(Function m)

public bool CanPublishCustomNode(Function m)
{
return AuthenticationManager.HasAuthProvider && m != null;
return AuthenticationManager.HasAuthProvider && m != null && !Model.NoNetworkMode;
}

public void PublishSelectedNodes(object m)
Expand Down Expand Up @@ -453,7 +453,7 @@ public void PublishSelectedNodes(object m)
public bool CanPublishSelectedNodes(object m)
{
return DynamoSelection.Instance.Selection.Count > 0 &&
DynamoSelection.Instance.Selection.All(x => x is Function) && AuthenticationManager.HasAuthProvider; ;
DynamoSelection.Instance.Selection.All(x => x is Function) && AuthenticationManager.HasAuthProvider && !Model.NoNetworkMode;
}

private void ShowNodePublishInfo()
Expand Down
15 changes: 14 additions & 1 deletion src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
xmlns:fa="clr-namespace:FontAwesome5;assembly=FontAwesome5.Net"
xmlns:packagemanager="clr-namespace:Dynamo.Wpf.Views.PackageManager"
xmlns:trustedpaths="clr-namespace:Dynamo.Wpf.Views"
xmlns:converters="clr-namespace:Dynamo.Controls;assembly=DynamoCoreWpf"
xmlns:wpfControls="clr-namespace:Dynamo.Wpf.Controls"
d:DataContext="{d:DesignInstance Type=viewModels:PreferencesViewModel}"
WindowStartupLocation="CenterOwner"
Expand Down Expand Up @@ -1949,7 +1950,19 @@
<Hyperlink Click="OnInstalledPackagesHyperlinkClicked"
Foreground="{StaticResource TextBlockLinkForegroundColor}">
<TextBlock Name="PackageManagerLink"
Text="{x:Static p:Resources.InstalledPackagePartialHyperlinkMessage}" />
Text="{x:Static p:Resources.InstalledPackagePartialHyperlinkMessage}"
IsHitTestVisible="{Binding NoNetworkMode, Converter={StaticResource InverseBooleanConverter}}">
<TextBlock.Style>
<Style TargetType="TextBlock">
<!--<Setter Property="Foreground" Value="Black" />-->
<Style.Triggers>
<DataTrigger Binding="{Binding NoNetworkMode}" Value="True">
<Setter Property="Foreground" Value="Gray" />
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Hyperlink>
<Run>.</Run>
</TextBlock>
Expand Down
15 changes: 11 additions & 4 deletions src/DynamoPackages/PackageManagerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Dynamo.Graph.Workspaces;
using Greg;
Expand Down Expand Up @@ -49,14 +52,18 @@ public string BaseUrl
get { return this.client.BaseUrl; }
}

internal readonly bool NoNetworkMode;

#endregion

internal PackageManagerClient(IGregClient client, IPackageUploadBuilder builder, string packageUploadDirectory)
internal PackageManagerClient(IGregClient client, IPackageUploadBuilder builder, string packageUploadDirectory,
bool noNetworkMode = false)
{
this.packageUploadDirectory = packageUploadDirectory;
this.uploadBuilder = builder;
this.client = client;
this.packageMaintainers = new Dictionary<string, bool>();
this.NoNetworkMode = noNetworkMode;
}

internal bool Upvote(string packageId)
Expand Down Expand Up @@ -340,13 +347,13 @@ internal PackageManagerResult Undeprecate(string name)
internal bool DoesCurrentUserOwnPackage(Package package,string username)
{
bool value;
if (this.packageMaintainers.Count > 0 && this.packageMaintainers.TryGetValue(package.Name, out value)) {
if (packageMaintainers.Count > 0 && packageMaintainers.TryGetValue(package.Name, out value)) {
return value;
}
var pkg = new PackageInfo(package.Name, new Version(package.VersionName));
var mnt = GetPackageMaintainers(pkg);
value = (mnt != null) && (mnt.maintainers.Any(maintainer => maintainer.username.Equals(username)));
this.packageMaintainers[package.Name] = value;
packageMaintainers[package.Name] = value;
return value;
}

Expand Down Expand Up @@ -386,7 +393,7 @@ internal void LoadCompatibilityMap()
{
compatibilityMap = new Dictionary<string, Dictionary<string, string>>();

var compatibilityMapList = this.CompatibilityMap();
var compatibilityMapList = CompatibilityMap();
PackageManagerClient.compatibilityMapList = compatibilityMapList; // Loads the full CompatibilityMap as a side-effect

foreach (var host in compatibilityMapList)
Expand Down
32 changes: 28 additions & 4 deletions src/DynamoPackages/PackageManagerExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Dynamo.Extensions;
using Dynamo.Graph.Workspaces;
using Dynamo.Interfaces;
Expand All @@ -15,6 +19,25 @@ namespace Dynamo.PackageManager
{
public class PackageManagerExtension : IExtension, ILogSource, IExtensionSource
{
private class NoNetworkModeHandler : DelegatingHandler
{
public NoNetworkModeHandler() : base(new HttpClientHandler())
{
}

protected override Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request, CancellationToken cancellationToken)
{
var json = "{\"success\":false,\"message\":\"Application is in offline mode\",\"content\":null}";
var response = new HttpResponseMessage(HttpStatusCode.ServiceUnavailable)
{
Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json"),
ReasonPhrase = "Offline Mode Enabled"
};
return Task.FromResult(response);
}
}

#region Fields & Properties

private Action<Assembly> RequestLoadNodeLibraryHandler;
Expand Down Expand Up @@ -157,12 +180,13 @@ public void Startup(StartupParams startupParams)

var packageUploadDirectory = startupParams.PathManager.DefaultPackagesDirectory;

PackageManagerClient = new PackageManagerClient(
new GregClient(startupParams.AuthProvider, url),
uploadBuilder, packageUploadDirectory);

noNetworkMode = startupParams.NoNetworkMode;

var client = noNetworkMode ? new GregClient(startupParams.AuthProvider, url,
new HttpClient(new NoNetworkModeHandler())) : new GregClient(startupParams.AuthProvider, url);
PackageManagerClient = new PackageManagerClient(client, uploadBuilder, packageUploadDirectory, noNetworkMode);


//we don't ask dpm for the compatibility map in offline mode.
if (!noNetworkMode)
{
Expand Down
9 changes: 9 additions & 0 deletions src/DynamoPackages/Properties/Resources.Designer.cs

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

5 changes: 4 additions & 1 deletion src/DynamoPackages/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@
<data name="CannotRemovePackageAssemblyTitle" xml:space="preserve">
<value>Cannot update assembly</value>
</data>
<data name="DownloadPackageDisabled" xml:space="preserve">
<value>Package download is disabled in no-network mode.</value>
</data>
<data name="InvalidPackageFolderWarning" xml:space="preserve">
<value>The folder '{0}' does not exist</value>
<comment>This warning message is shown (during start up) when user specifies additional folders in DynamoSettings.xml file but the folders do not exist.</comment>
Expand All @@ -140,4 +143,4 @@
<value>{0} was not scanned for packages because a preference setting disabled loading from that location."</value>
<comment>This warning message is shown when a package directory is skipped due to a preference setting disabling loads from that location type.</comment>
</data>
</root>
</root>
5 changes: 4 additions & 1 deletion src/DynamoPackages/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@
<data name="CannotRemovePackageAssemblyTitle" xml:space="preserve">
<value>Cannot update assembly</value>
</data>
<data name="DownloadPackageDisabled" xml:space="preserve">
<value>Package download is disabled in no-network mode.</value>
</data>
<data name="InvalidPackageFolderWarning" xml:space="preserve">
<value>The folder '{0}' does not exist</value>
<comment>This warning message is shown (during start up) when user specifies additional folders in DynamoSettings.xml file but the folders do not exist.</comment>
Expand All @@ -140,4 +143,4 @@
<value>{0} was not scanned for packages because a preference setting disabled loading from that location."</value>
<comment>This warning message is shown when a package directory is skipped due to a preference setting disabling loads from that location type.</comment>
</data>
</root>
</root>
6 changes: 4 additions & 2 deletions src/Libraries/CoreNodeModels/WebRequest.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
using System;
using System;
using System.Collections.Generic;
using CoreNodeModels.Properties;
using DSCore;
using Dynamo.Events;
using Dynamo.Graph.Nodes;
using Dynamo.Session;
Comment thread
aparajit-pratap marked this conversation as resolved.
Outdated
using Newtonsoft.Json;
using ProtoCore.AST.AssociativeAST;

namespace CoreNodeModels
{
[NodeName("Web Request")]
[NodeDescription("WebRequestDescription", typeof(Resources))]
[NodeDescription(nameof(Resources.WebRequestDescription), typeof(Resources))]
[NodeCategory(BuiltinNodeCategories.CORE_WEB)]
[IsDesignScriptCompatible]
[OutPortTypes("var[]..[]")]
Expand Down
2 changes: 1 addition & 1 deletion src/Libraries/CoreNodes/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/Libraries/CoreNodes/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
<value>Input must be a single value or a non-nested list.</value>
</data>
<data name="CurveMapperEqualMinMaxWarning" xml:space="preserve">
<value>• Min and Max values must not be the same.</value>
<value>• Min and Max values must be different.</value>
</data>
<data name="CurveMapperInvalidCountWarning" xml:space="preserve">
<value>• Values must be a list of numbers or a single number ≥ 2.</value>
Expand Down
2 changes: 1 addition & 1 deletion src/Libraries/CoreNodes/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
<value>Input must be a single value or a non-nested list.</value>
</data>
<data name="CurveMapperEqualMinMaxWarning" xml:space="preserve">
<value>• Min and Max values must not be the same.</value>
<value>• Min and Max values must be different.</value>
</data>
<data name="CurveMapperInvalidCountWarning" xml:space="preserve">
<value>• Values must be a list of numbers or a single number ≥ 2.</value>
Expand Down
5 changes: 5 additions & 0 deletions src/Libraries/CoreNodes/Web.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.IO;
using Autodesk.DesignScript.Runtime;
using Dynamo.Configuration;
using Dynamo.Events;
using Dynamo.Session;

namespace DSCore
{
Expand All @@ -10,6 +12,9 @@ public class Web
{
public static string WebRequestByUrl(string url)
{
// Prevent the node from executing in no network mode.
ExecutionSessionHelper.ThrowIfNoNetworkMode();

if (string.IsNullOrEmpty(url))
{
throw new ArgumentException(Properties.Resources.WebRequestNullUrlMessage);
Expand Down
16 changes: 16 additions & 0 deletions src/NodeServices/DynamoServices.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,20 @@
<!--exclude these dependencies as Sys.Ref.MetadataLoadContext.dll is already pulled in from other projects and the transitive deps are part of the .net8 runtime.-->
<PackageReference Include="System.Reflection.MetadataLoadContext" Version="8.0.0" ExcludeAssets="runtime" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.en-US.resx">
<Generator></Generator>
</EmbeddedResource>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>
Loading
Loading