George Duckett

C#

General discussions about the c# language, Squirrels | gist.gi...
Jan 14, 2014 12:50
@RoelvanUden Very true, thanks for the help.
Jan 14, 2014 12:44
@RoelvanUden Thanks for the clarification there. I had a feeling I was going down the wrong road, hence the question.
Jan 14, 2014 12:43
@RoelvanUden Ok, that makes sense. As I understand it you're saying keep an in-memory cache lookup mapping usernames to my DB user objects, caching them as they get authenticated.
Jan 14, 2014 11:15
Does this seem like something reasonable to do? I'm new to public facing services/sites, so I'm worried I may have missed some security implications.
Jan 14, 2014 11:14
I'd like to avoid the database hit to lookup the user for every request. I don't want to use session/cookies etc. as webapi is supposed to be stateless, so my idea was to get the service to send back a json string (encrypted) that contained the properties of my user object. The calling application would send that same json string back. If the web api found that json string in the request's header it would just use that rather than a DB lookup
Jan 14, 2014 11:12
Once authenticated I'm populating a custom IPrincipal with various properties from the database.
Jan 14, 2014 11:12
I'm passing a username (encrypted) to my webapi service in the header, so it can authenticate against a DB.
Jan 14, 2014 11:11
Got a question about best practices etc:
Jan 14, 2014 11:11
Anyone here know much about WebAPI?
Oct 29, 2012 07:59
20
Q: What version(s) of the .NET framework are included in windows 8?

George DuckettIf I install windows 8 what version(s) of the .NET framework will be installed before any auto-updating? What about after applying any automatic updates?

Oct 26, 2012 10:02
17
Q: What version(s) of the .NET framework are included in windows 8?

George DuckettIf I install windows 8 what version(s) of the .NET framework will be installed before any auto-updating? What about after applying any automatic updates?

 
Apr 22, 2013 11:36
          ||
        /    \
       ||     &&
      /  \   /  \
     &&   c d   e
    /  \
   a    b
Apr 22, 2013 11:36
||
/ \
|| &&
/ \ / \
&& c d e
/ \
a b
Apr 22, 2013 11:33
then work outwards, using the brackets to work up the tree, finally arriving at the root node, which in our case is the || to the right of c
Apr 22, 2013 11:32
When visualising the tree, start with the inner most brackets. They are the "leaves"
Apr 22, 2013 11:31
note that i'm not 100% sure about either the bracket would put c with the first && or the last, but it doens't matter, the logic is the same
Apr 22, 2013 11:30
((a && b) || c) || (d && e)
Apr 22, 2013 11:30
Ok, taking into account higher precidence we get the following:
Apr 22, 2013 11:25
i.e. to calculate a && b || c you first do a && b, then || that with c
Apr 22, 2013 11:25
it's because of the operator precedence and they way the sub-expressions are evaluated
Apr 22, 2013 11:20
the result is the same
Apr 22, 2013 11:20
instead of left and right making the branches, the list of predicates makes the branches
Apr 22, 2013 11:20
but it still sort of looks like a tree
Apr 22, 2013 11:20
If you imagine the whole expression as a tree as in my example imagine replacing the binaryexpressions with predicategroup
Apr 22, 2013 11:19
2) c
Apr 22, 2013 11:19
1) the predicate group we created for a && b
Apr 22, 2013 11:19
grr, formatting 1 sec.
Apr 22, 2013 11:19
1) the predicate group we created for a && b2) c
Apr 22, 2013 11:19
its list contains 1) the predicate group we created for a && b2) c
Apr 22, 2013 11:17
it goes down the right now, which is simple an individual predicate and so it can add it to its list.
Apr 22, 2013 11:17
then we're back up to the orignal call to the function which now has a predicate group with the lower expression on the left converted to a different predicate group and added.
Apr 22, 2013 11:16
so that recursion is working on only a && b. It chooses left first, sees a simple predicate, a which means it can simply add it to the predicate group, it does the same for the right
Apr 22, 2013 11:15
ok, left is another binary expression, so it calls its self to get a predicategroup that your target library understands
Apr 22, 2013 11:15
it chooses left first (doesn't matter).
Apr 22, 2013 11:14
it creates a predicate group ready to add the expressions to its list
Apr 22, 2013 11:14
i.e. your code sees the ||.
Apr 22, 2013 11:14
In your logic to convert a binaryexpression to a predicate group you would first use that same function to convert the left and the right into a predicate group
Apr 22, 2013 11:13
In your example you have (a && b) || c with the || at the top. What you want to end up with is each time you have an operator you want to create a predicate group, with the left and right as the list of expressions.
Apr 22, 2013 11:12
right, ok, I understand now. There no reason to parse from right to left though.
Apr 22, 2013 11:08
Under the left or right of that predicate group you might have another predicate group.
Apr 22, 2013 11:08
My question then is, why do you want to parse it from right to left? It looks like you're trying to create 2 predicate groups, one for the ands and one for the ors to which should be logically equivilent. While that might work in your example case it won't in the general case. Consider (a && b) || (c && d) What would you do then? I think what should happen is that each and and each or should translate into its own predicate group. See the "Multiple Compound Predicates (Predicate Group)" section of your linked article. You'd simply replace BinaryExpression with a predicate group.
Apr 22, 2013 11:08
Could you look at the tree structure in my answer and know what output you want, knowing nothing of how the expression is written in the first place? (because the code doesn't see how it's written)
Apr 22, 2013 11:08
Sorry, I don't really follow the general case here. I understand that in this example you want to group the John/Jack tests with the OR operator but I don't understand the general problem you want to solve, are there different rules of operator precedence in your target language for example? Remember that the lambda expression isn't written down, it's a tree structure (as in my answer here). I think what you want is to produce one where && is at the top and Jack and John are on the right with the ||, but I don't know why you want that, or what else you'd want with different inputs.
 
Aug 31, 2011 10:07
I definitely think you should have the sizemode as normal, as anything else will complicate things. When you say 'move the y axis' what do you mean? You should be doing a Matrix.Translate(..., ...., Append).
Aug 31, 2011 09:47
That is definitely making a difference as it's changing where the picture is drawn, which probably changes the rotation. Try changing the sizemode to Normal.
Aug 31, 2011 09:10
Hi, i am, however i'm pretty busy at the moment, i'll have to look at this tomorrow. I'll alter my program to use your image file, and always rotate around the center of the form.
Aug 31, 2011 09:08
Translate it by rc.Width / 2 instead of image.width / 2. The key is what i said in my answer: "The way you can get around this is to first translate the image so the point you want to rotate around is on that origin". You know that without any translation the image rotates around the top left. So, to get it to rotate around where the red cross is, you need to move the image so that the red cross would be on the top left. Then you do the rotation. Of course you've also got to move it back. In my program, try removing all matrix lines, adding them in one by one.
Aug 31, 2011 09:08
I've added a complete sample of what i think you want to achieve to the bottom of my post.
Aug 31, 2011 09:08
Ok, i understand now. Instead of translating by half the image width/height before and after the rotation, translate by the coordinates of the red cross (i.e. half the map window/radar size).
Aug 31, 2011 09:08
See my edit, at the bottom of my answer.