httpcontext.current.request default return value if not set - httpcontext

I've spent a lot of time googling this and testing in my program, but I can't get any output. I'm coding in C# codebehind aspx. I'm trying to query the url of
anUnknownWebsite.aspx?SerialNumber=CND0340482
And getting the serial number with the httpcontext.current.request["SerialNumber"] method.
One half of my program works fine, where if the serial number is set in the URL, everything works fine, but I want to have a boolean statement like the following:
if(HttpContext.Current.Request["SerialNumber"] == null)
{
Do this
}else
{
Do something else
}
I just want to know if the method will have a default value or a null value to get a boolean from because the if statement above doesn't work.
Open to try any new ideas or theories on this.
Thanks guys

It should be null (not an empty string / default value), but try this...
if(HttpContext.Current.Request.QueryString["SerialNumber"] == null) {
// ...
}
If you know SerialNumber is in the query string, you can use Request.QueryString, otherwise you'll be also be checking the form variables, cookies, and server variables.

Related

arduino: loop until int gets value assigned to it

I am trying to get a value from serial input. The rest of the programm behaves different if the value changes. This value gest assigned once in the ```void setup()``` function.
My goal is to let the program run an infinite loop or something similar until a value (type int) is recived, and only then resume the flow.
I know about ```Serial.parseInt()``` and tried to implement it ``` while (variable == null) variable = Serial.parseInt() ``` but I got an error that 'null' was not declared in this scope.
Any suggestions?
Oke, i was kinda dumb.
There is an easy way, simply check
while (!variable)
variable = Serial.parseInt()
This worked for me and should work for you as well

Checking if condition on Long type for velocity template

Long type from java is not working with velocity if condition
I am using velocity engine for email with Java where one of the variables type is Long.
While trying if condition on that variable it never succeeds.
Tried following ways but none was helpful,
#if($customTypeList.LongTypeId == 1)
#if($customTypeList.LongTypeId == '1')
#if($customTypeList.LongTypeId == "1")
It should go inside the if condition as variables value is 1.
I have validated that with sysout and even by printing in template.
Actually got the answer after number of trials...
Posting to help others.
#if($customTypeList.longTypeId.intValue() == 1)

Returning variable from method

for(Element synonym: Words){
synonyms.add(synonym);
}
return synonyms.get(7);
}
i am retrieving an unknown amount of words every time i add a synonym to the synonyms list, so if i try access a portion of the list that doesnt exist (eg. element 7 when there are only 3), i get an index out of bounds error, how can i check to see if the element exists and if it doesn't, return something else?
i have tried checking to see if there is an element or not but i dont know how
Short answer would be to check for the length of the array for the index that you want to return. If it exists, return that, otherwise do something else.
return synonyms.length == 7 ? synonyms.get(7) : somethingElse;

How to cast a Revit Element as a Revit.DB.Opening

I am relatively new at programming in Revit. I am currently getting a list of elements in my drawing that are of type door or window. What I want to do is cast these as an opening however I get an error when I try to cast them as a Autodesk.Revit.DB.Opening.
Code Below:
// filter for current design option
var designOptionFilter = S2E.Revit.Tools.Library.Cache.DesignOptionFilter;
List<Element> elements = collector.WherePasses(designOptionFilter).ToElements().ToList();
var list = new List<Autodesk.Revit.DB.Opening>();
foreach (var element in elements) {
var opening = (Opening)element;
if (opening.Host.Id == wallId) {
list.Add(opening);
}
}
return list;
As you can see I am testing if the id of the host matches the wall I am woking on. At least that is what I would like to do. All I am looking for is how to cast an element as an Opening.
Thanks, Rich
Considering a Door is a FamilyInstance and an Opening is not, I am unsure of how you would cast the door FamilyInstance to an opening type.
But, since the FamilyInstance has a Host parameter, just check that against the wall ID and it should work, no casting needed.
It depends on what your filter is selecting on whether the cast you have will work. As you don't provide details on the exact error you are getting it is hard to be more precise.
Also you have in one place (Opening) used as your cast yet you use the full type name "Autodesk.Revit.DB.Opening" when you create your list. If you really need to do that maybe Opening is not the "Opening" you thought it was.
You can also use element.Cast() to perform the cast.
Likewise if you know that all your elements returned by the filter are only ever going to be Opening types then you can use
collector.WherePasses(designOptionFilter).Cast<Opening>()
to achieve the same thing.

Codeigniter database query bug - does not return expected results

I tested this query in my database, and it works fine:
select * from variables where value = 'commas-:-)';
I get a result. Now, I stored the value in a variable and use the query class.
$value = 'commas-:-)' <<< this is passed as a parameter
$query = "select * from variables where value = '$value'";
$this->db->query($query);
Now, this query works for every other value except for this one - but what's odd is that if I PRINT out the exact query (print_r of $query) and execute it on the database, it returns the correct result. So I'm left to think that the query class is screwing with my query, which it shouldn't because everything is properly escaped and $value is a string literal.
What is going on?
$sql = "SELECT * FROM variables WHERE value = ?";
$this->db->query($sql, array('commas-:-)'));
More info
$get_data = $this->db->from('variables')
->where('value', $value)
->get();
Hope this will work...!
try to use these things for checking the queries
echo $this->db->last_query();
print_r($this->db->result_array($get_data));
I found the issue - it was the rerouting function that was causing the mishap. More specifically, the segment filtering function within the route folder in the system core.
This is what happened:
I created an anchor with the encoded value (commas:-)) and I configured the route to reroute the uri to a function I had in my controller. Each time I clicked the link, the value gets passed, and (supposedly) rerouted to the function. Which it did, for almost all the values I used. Except this one.
1st assumption: the db query function is escaping the values. But I turned off the escape, as well as checked the query by printing. The value was correct. I then tried other query formats, and still no results. Conclusion: There's nothing wrong with the database query functions.
2nd assumption: the data must be corrupt - although the value is correct (I'm getting commas:-)), it's not returning anything except when I type in the value manually. So I tested this:
I created a seperate value, and set it equals to the one I typed in(the one that works). I then printed the original value(one passed) and the newly created value using VAR_DUMP.
Turns out, the argument value (one that doesn't work) is a string with length 14 whereas my new variable was a string with a length of 10. WTF? Conclusion: Something occured during the rerouting / passing process that changed the variable.
I went back to the config folder, and replace the variable $i in the reroute to the literal string value commas:-). And guess what? It worked perfectly. And just to make sure it wasn't the regex, I wrote my own custom regex and it matched fine, but the value was still being changed. So I decided to get under the hood.
I traced the URI manipulation in the routes class to the _explode_segment() function, which was used to perform the regex and analyse the uri for other variables. It also did this thing ...
_filter_uri($str)
for each part of the uri segment that was matched.
What did it do? It replaces programmable characters like ( and ) with their HTML ENTITY. Now, if you don't know, html entities have long lengths than url encoding. LOL. So what happened was this:
Original segment : commas-%3A-%29 <- very nice!
Filtered segment : commas-%3A-) <- NOOOOOOOOO! (the right paren encoded with &#41.)
urldecode("&#41") = string(4)
urldecode("%29") = string(1)
Fail.
or WIN?!