Workflow Definition Language `equals` doesn't return boolean value - boolean

I'm working with the following Azure Logic App expression (Workflow Definition Language (WDL)):
equals(
int(
formatDateTime(
subtractFromTime(
utcNow(),
7,
'Day'
),
'MM'
)
),
2
)
The WDL docs say that the equals function should return with a boolean value.
However, I'm seeing a string response, NOT boolean:
The action shown on top is an actual boolean
Note the lower case "t" in true
Whereas the action shown on the bottom is the issue
Tried:
Wrapping the above function in the bool keyword, same string result(!)
Whats going on here?
EDIT 1:
Just deleted all actions and tested again, seems to be working now
Weird

Related

dart gRPC: what the meaning of the function?

I'm new in flutter(dart) gRPC. I'm learing the tutorial given by https://grpc.io/docs/languages/dart/basics/. But I got confused about the dart syntax in this function.
Future<Feature> getFeature(grpc.ServiceCall call, Point request) async {
return featuresDb.firstWhere((f) => f.location == request,
orElse: () => Feature()..location = request);
}
Actually, I don't understand what argument f means and why there is an orElse. I have found => means arrow function and it can be simply understood as return sentence, but I can't say I figure it out toally. Any explanation would be appreciated.
firstWhere method takes a Predicate. A Predicate is just a function that takes in an object, and returns true or false. So basically it's saying "give me the first object from this list where the function I'm giving you returns true. The orElse is an optional, named parameter that says, if you've gotten to the end of the list and not a single object returned true when passed through the function I just supplied, then execute this function as a last resort and return whatever value it produces. You can think of a Predicate like a filter. It takes an object and returns true if it should pass through the filter, or false if it should not pass through the filter. firstWhere basically goes through each element checking to see if it passes through the filter, and the first time something does, it returns that element. If nothing makes it through the filter, it uses the orElse producer function to generate some value to return, since nothing made it through on it's own.
(f) => f.location == request is a function that returns true or false based on it's argument - it's a Predicate
() => Feature()..location = request is a Producer. A function that has no argument, but produces a value. In this case, a value that is equal to a new Feature with a location value equal to request. An assignment evaluates to the value that was assigned. The cascade .. ensures that the Feature will be returned, instead of the Point object, request.
So basically you can think of it like this:
list.giveMeTheFirstObjectWhere(thisFunctionReturnsTrue, orElse: giveMeTheValueThisFunctionProvidesIfNoneOfTheElementsReturnedTrueUsingTheOtherFunction)
So the purpose of this code seems to be, checking if a Feature already exists, and if it does, it returns the first such Feature. If it doesn't exist, it creates a new Feature and returns it (however, this newly created one isn't automatically added to the list/db)

Multi if statement in class parameters setting

I know that in the latest version of dart we can use if else statements inside the build method. Does anyone know if we can use also if else statement when we setting class parameters? I know I can do inline statement there but inline is a bit hard to read when there are multiple conditions
const int i = 0;
class Person {
// NewClass n = NewClass(a: i == 0 ? 'a' : 'b'); //<- inline statement working
NewClass n = NewClass(a: if(i == 0) 'a' else 'b'); //<- if statement doesn't
}
class NewClass {
final String a;
const NewClass({this.a});
}
Edit:
Basically in my case I've got an TextField widget where I set its's type parameter from enum (Type.text, Type.numeric...) According to this parameter I want to set The textField parameters (textCapitalization, maxLength and so on)
As per your comment, you are already creating an enum for specifying the type of the fields.
enum Type {text, numeric}
Now for specifying the properties of that particular type, you can add an extension on this enum, as shown below:
extension TextFieldProperties on Type {
int get maxLength {
if (this == Type.text) {
return 10;
}
return 12;
}
}
So in your field class you already have a type defined, you can use that type variable to get the properties of that particular type of field.
Type type = Type.text;
print(type.maxLength); // Will print 10
type = Type.numeric;
print(type.maxLength); // Will print 12
Note: It will work only in Dart 2.7 and above
You want the conditional expression (?:), not the conditional statement or literal entry (if), as you have already discovered.
The reason if doesn't work is that if only works as a statement or as a collection literal entry. It doesn't work in arbitrary expressions.
The reason for the distinction is that the if syntax allows you to omit the else branch. That only makes sense in places where "nothing" is a valid alternative. For a statement, "doing nothing" is fine. For a collection, "adding nothing" is also fine.
In an expression context, you must evaluate to a value or throw. There is no reasonable default that we can use instead of "nothing", so an if is not allowed instead of an expression.
Doesn't work because this syntax doesn't exist in Dart. The only way to do what you would like to do is to use the ternary operator.
If you try it in the DartPad you will get an error.
I suggest you to use a function to return the right value.

What is the purpose of ValidationResult.Success field?

Msdn:
public static readonly ValidationResult ValidationResult.Success
Represents the success of the validation (true if validation was
successful; otherwise, false).
The text in above excerpt doesn't make sense to me, since Success field doesn't return a value of type bool, and the value it does return ( ie ValidationResult instance ) doesn't contain any boolean property or field which we could set to a value indicating a success or failure of a validation?!
Any ideas what is the purpose of this field?
ValidationResult.Success is always constant null. Its purpose is documentation.
In order to succeed validation you could either write:
return null;
or
return ValidationResult.Success;
In the first case I ask myself "What does this mean? What does null mean? Is this success, or fail, or something else?". In the latter case the code is inherently documented without the need for informal text docs.

Passing string parameters MVC 3

I'm trying to pass a string parameter in MVC3.
The URL that gets generated is:
http://localhost:50164/Property/Browse/Oregon
This appears to be the Property controller class in the function "Browse" with parameter "Oregon".
The right function gets called, but the string appears to be empty.
public ViewResult Browse(string location)
{
//counted_properties: 3 counted_properties_here: 0
ViewData["counted_properties"] = db.Properties.Count(); // debug 3 total
ViewData["counted_properties_here"] = db.Properties.Where(p => p.location == "Oregon").Count(); // debug 1 (the right answer!)
//return View(db.Properties.Where(p => p.location == tmp_location).ToList()); // 0 (bad!)
ViewData["the_location"] = location;
int size = tmp_location.Length; // unhandled null exception when tmp_location = location
ViewData["location_length"] = size;
// return View(db.Properties.Where(p => p.location == "Oregon").ToList()); // Right! but hardcoded
return View(db.Properties.Where(p => p.location == location).ToList());
}
When I return the lambda using the hard coded string (Oregon), I get the right answer.
When I return the lambda using the parameter (string location) I get zero results.
When I try to display ViewData["the_location"] which is a direct copy of the parameter it is blank. Maybe I'm not trying to display it correctly. Here is my view:
Location: #Html.Encode(ViewData["the_location"] )
When I call location.Length I get an unhandled null exception, but this works when I call Length on a hard coded parameter like "Oregon".
It looks like somehow the string is empty, but this doesn't make sense since I see "Oregon" in the URL when it gets to the property/browse function.
I'm beginning to wonder if I am allowed to pass strings as arguments in MVC as I haven't seen any examples with string parameters.
This is a continuation of an unsolved problem:
C#/ASP.NET lambda conversion
By the way, I'm not trying to promote Oregon here. I've never been there. Maybe it's a good place, though.
Check your routing. Traditionally URLs like the one you give will map the value ("Oregon") to the "id" parameter, rather than the location parameter that you're trying to use. Either rename the parameter or change the route to use "{controller}/{action}/{location}".

Is there a better way to test for an integer in C# than Double.TryParse?

Double.TryParse returns a value, and I don't need a value. I need to be able to tell if a string is numeric and just return a bool.
is there a way to do this?
I would consider exactly what you need to determine. "Is numeric" is vaguer than it sounds at first. Consider the following strings, and whether you'd want to consider them numeric:
"NaN"
"Nan"
"Infinity"
"0.000000000000000000000000000000000000000000000000001"
"1e5"
"1e500"
"1,000"
"+1"
Using Double.TryParse (with an en-GB culture - don't forget about cultural issues!) will give you True, False, True, True (despite it not being representable), True, False. True, True.
If you want to tell whether a later call to Double.TryParse would succeed, calling it here will be the most accurate solution. If you're using some other criteria, a regular expression may well be more appropriate. An example of the criteria you might use:
The can be a + or -, but only in the first character
There can be a single period at any character. You may want to avoid one at the end - should "1." be valid?
Other than the above, all characters must be digits
That would disallow all but the fourth and last examples above.
EDIT: I've now noticed the title of the question includes "integer". That pretty much reduces the specification checks to:
Do you want to allow leading zeroes (e.g. -00012)?
What is the range?
Do you only need decimals (instead of hex etc)?
Do you need to accept thousands separators?
What's your policy on leading/trailing whitespace?
Well, you could use a regular expression, but why not just discard the value from Double.TryParse and move on? I don't think it will be worth the effort trying to duplicate this code.
One way is to add a reference to Microsoft.VisualBasic and then use Information.IsNumeric().
using Microsoft.VisualBasic;
...
if (Information.IsNumeric("1233434.0"))
{
Console.WriteLine("Yes");
}
How about a regular expression?
string s = "13.2";
bool bIsDecimal = Regex.IsMatch("^-?\d+(\.\d+)?$");
should test whether it is a decimal value. What it won't tell you is whether it is a valid decimal, as in, will the number fit in the range of a decimal.
I just fired up Visual Studio Express (both 2005 and 2008). The Intellisense says that the return value of Double.TryParse() is a bool. The following worked for me under limited testing...
double res; // you must be under very resource-constrained
// conditions if you can't just declare a double
// and forget about it
if (Double.TryParse(textBox1.Text, out res)) {
label1.Text = "it's a number";
} else {
label1.Text = "not a number";
}
try this isnumeric:
public static bool IsNumeric(object Expression)
{
bool isNum;
double retNum;
isNum = Double.TryParse(Convert.ToString(Expression), System.Globalization.NumberStyles.Any,System.Globalization.NumberFormatInfo.InvariantInfo, out retNum );
return isNum;
}