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

Deprecate DayOfWeek Enum node #8311

Merged
merged 2 commits into from
Nov 8, 2017
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
28 changes: 28 additions & 0 deletions src/Engine/ProtoCore/FFI/CLRDLLModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,8 @@ private ProtoCore.AST.AssociativeAST.FunctionDefinitionNode ParseFieldAccessor(F
func.IsExternLib = true;
func.ExternLibName = Module.Name;
func.IsStatic = f.IsStatic;
//Set the method attribute for Enum properties.
func.MethodAttributes = new FFIMethodAttributes(f);

return func;
}
Expand Down Expand Up @@ -1248,6 +1250,32 @@ public IEnumerable<Attribute> Attributes
public bool AllowRankReduction { get; protected set; }
public bool RequireTracing { get; protected set; }

//Set the MethodAttributes for Enum fields.
public FFIMethodAttributes(FieldInfo f)
{
var atts = f.GetCustomAttributes(false).Cast<Attribute>();

foreach (var attr in atts)
{
//Set the obsolete message for enum fields.
if (attr is IsObsoleteAttribute)
{
HiddenInLibrary = true;
ObsoleteMessage = (attr as IsObsoleteAttribute).Message;
if (string.IsNullOrEmpty(ObsoleteMessage))
ObsoleteMessage = "Obsolete";
}
else if (attr is ObsoleteAttribute)
{
HiddenInLibrary = true;
ObsoleteMessage = (attr as ObsoleteAttribute).Message;
if (string.IsNullOrEmpty(ObsoleteMessage))
ObsoleteMessage = "Obsolete";
}

}
}

public FFIMethodAttributes(MethodInfo method, Dictionary<MethodInfo, Attribute[]> getterAttributes)
{
if (method == null)
Expand Down
8 changes: 8 additions & 0 deletions src/Libraries/CoreNodes/DateTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,22 @@ public static System.TimeSpan TimeOfDay(System.DateTime dateTime)
/// <summary>
/// Days of the Week
/// </summary>
[IsVisibleInDynamoLibrary(false)]
public enum DayOfWeek
{
[Obsolete("This node is deprecated")]
[EnumDescription("EnumDateOfWeekSunday", typeof(Properties.Resources))]Sunday,
[Obsolete("This node is deprecated")]
[EnumDescription("EnumDateOfWeekMonday", typeof(Properties.Resources))]Monday,
[Obsolete("This node is deprecated")]
[EnumDescription("EnumDateOfWeekTuesday", typeof(Properties.Resources))]Tuesday,
[Obsolete("This node is deprecated")]
[EnumDescription("EnumDateOfWeekWednesday", typeof(Properties.Resources))]Wednesday,
[Obsolete("This node is deprecated")]
[EnumDescription("EnumDateOfWeekThursday", typeof(Properties.Resources))]Thursday,
[Obsolete("This node is deprecated")]
[EnumDescription("EnumDateOfWeekFriday", typeof(Properties.Resources))]Friday,
[Obsolete("This node is deprecated")]
[EnumDescription("EnumDateOfWeekSaturday", typeof(Properties.Resources))]Saturday
}

Expand Down
16 changes: 16 additions & 0 deletions test/DynamoCoreWpfTests/DateTimeTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Dynamo;
using Dynamo.Configuration;
using Dynamo.Engine;
using Dynamo.Graph.Nodes;
using Dynamo.Tests;
using NUnit.Framework;
using DateTime = CoreNodeModels.Input.DateTime;
Expand Down Expand Up @@ -62,6 +65,19 @@ public void DateTimeNode_Open_Edit_SerializesCorrectly()
Assert.AreEqual(string.Format("{0:" + PreferenceSettings.DefaultDateFormat + "}", dt), testDate.ToString(PreferenceSettings.DefaultDateFormat));
}

[Test]

public void DateTimeNodeDeprecated_Test()
{
var path = Path.Combine(TestDirectory, "core", "dateTime", "DateTimeDeprecated.dyn");
CurrentDynamoModel.OpenFileFromPath(path);

var node = CurrentDynamoModel.CurrentWorkspace.Nodes.FirstOrDefault();
Assert.IsNotNull(node);
Assert.AreEqual(ElementState.PersistentWarning, node.State);
Assert.AreEqual("This node is deprecated", node.ToolTipText);
}

[TearDown]
public void Teardown()
{
Expand Down
13 changes: 13 additions & 0 deletions test/core/dateTime/DateTimeDeprecated.dyn
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Workspace Version="1.3.0.875" X="0" Y="0" zoom="1" ScaleFactor="1" Name="Home" Description="" RunType="Automatic" RunPeriod="1000" HasRunWithoutCrash="True">
<NamespaceResolutionMap />
<Elements>
<Dynamo.Graph.Nodes.ZeroTouch.DSFunction guid="67f8b695-d664-4d2e-8005-e262048511c5" type="Dynamo.Graph.Nodes.ZeroTouch.DSFunction" nickname="DayOfWeek.Friday" x="337.5" y="326" isVisible="true" isUpstreamVisible="true" lacing="Shortest" isSelectedInput="False" IsFrozen="false" isPinned="false" assembly="DSCoreNodes.dll" function="DSCore.DayOfWeek.Friday" />
</Elements>
<Connectors />
<Notes />
<Annotations />
<Presets />
<Cameras>
<Camera Name="Background Preview" eyeX="-17" eyeY="24" eyeZ="50" lookX="12" lookY="-13" lookZ="-58" upX="0" upY="1" upZ="0" />
</Cameras>
</Workspace>