|
Something like that, yea. I'm creating a delegate for a type that constructs it and all of it's dependencies. I'm trying to write the data input/"parser" layer very generically so it can support a lot of cases, but the original idea related to parsing would be something like:
class User {
[OverrideMethodBind(Method = "Add")]
[OverrideParameterBind(Type = typeof(Address))]
List<Address> addresses;
[DataBind]
string firstName;
[DataBind(ID = "LN")]
string lastName;
}
class Address {
[DataBind(ID = "street")]
string streetAddress;
string city;
[DataBind]
StateAbbrev state;
int zipCode;
}
enum StateAbbrev {
AL,
WA,
MI,
}
In this example you want to create the object based on (state, streetAddress)+ (i.e. one or more times), firstName, and lastName from the data.
You can add metadata to the items of interest, supply "parsers" for various members (based on whatever condition you want - type, member, or ID), and it uses the data to then create (possibly many) Users based on that data. Removes the need for boilerplate related to loading a domain object with parsing results or whatever your data source is (another object, database, etc). So instead of writing something like:
MatchCollection results = regex.Matches();
User u = new User(results["firstName"], results["LN"]);
Address a = new Address(results["street"], results["state"]);
u.addresses.Add(a);
You'd write:
ObjectGenerator g = new ObjectGenerator<User>().AddParser(regex);
ObjectGenerator g = new ObjectGenerator(typeof(User)).AddParser(regex);
User user = g.GenerateObject();
User[] users = g.GenerateObjects();
Not a finalized interface but that's the jist of it.
|
|
|
|
|
Very cool. I've been wanting to do something like that for a long time myself - a way to "bind" grammar constructs from say, an XBNF document to fields/properties in object models via metadata but i haven't found an expressive enough way to do it that isn't more work than just manually coding it. The upshot of doing that would be to get your parsed stuff directly into your final objects.
hack everything.
|
|
|
|
|
honey the codewitch wrote: The upshot of doing that would be to get your parsed stuff directly into your final objects.
That's the goal! You nailed the main issue - that for simple single-use cases it's more work to do this than to just write the code manually. I'm attempting to make it expressive (and fast) enough to justify using with complex objects and/or multiple data source formats (XML, JSON, CSV, etc into the same object tree).
|
|
|
|
|
That's a very tall order. I'd love to know what you come up with. My interests are closely related.
hack everything.
|
|
|
|
|
Since you seem to be the resident parsing expert, do you have any "must read" suggestions? I admittedly only know the basics but I've been interested in parsing for quite awhile since regular expressions in Perl were my introduction to programming. I got "Programming Perl" (a book I still own) as a gift over 18 years ago and after learning the basics of Perl, regular expressions were what cultivated my interest in programming.
|
|
|
|
|
|
Premature optimization is the root of all evil
-- D. Knuth
- Make it work (check - Slang generator)
- Automate it (check - Parsley generator)
- Profile... profile... and profile again. Only then can you make intelligent decisions about what to improve.
Smaller and faster code is obviously better, but you eventually reach the point of diminishing returns. Is it really worth a few months of your life to improve code speed/size by (say) 1%?
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
My hand written parser is 1/10th the size of the generated one, so hopefully there's room for improvement.
For now, I'm rewriting the handwritten parser, but I'm using Parsley to help me do it, using the /noparser option so I get its tokenizers from its grammars but it doesn't generated the parser for me.
I'm using the grammars as a guide to do it again, this time much more correctly and with some other foundational improvements.
I expect the code size to be within spitting distance of 100K, so that will cut my CodeDOM Go Kit! distro size down compared to using the generated code.
Later I'm going to go back and experiment with code synthesis in parsing, and see if i can't replace things like standard LL "loops" with actual while loops and such.
That should make it smaller. I just want to trim a lot of this boilerplate out of it, but it's not straightforward to do, especially in such a way as to keep the code readable.
hack everything.
|
|
|
|
|
Daniel Pfeffer wrote: Smaller and faster code is obviously better
But unfortunately, they are often mutually exclusive. My first thought on seeing the code sample was ...
if ({ ExpressionParser.add, ExpressionParser.sub, ..., ExpressionParser.charType }.Contains(context.SymbolId))
This would be smaller, but Contains requires iteration over an array, much slower to execute than a simple short-circuiting Boolean expression. So, the old metric of Lines Of Code is flawed.
|
|
|
|
|
A quick look at the brackets and I don't think a contains would do the same thing in that example.
But, your point still makes sense as an example.
|
|
|
|
|
You're right! I should have checked the syntax first. The code should look like ...
ExpressionParser[] ep = { ExpressionParser.add, ExpressionParser.sub, ExpressionParser.charType };
if (ep.Contains(context.SymbolId)) { }
or
if (new [] { ExpressionParser.add, ExpressionParser.sub, ExpressionParser.charType }.Contains(context.SymbolId)) { } assuming that ExpressionParser is an enum .
My delay in replying was that I hadn't realised that Contains is an extension method of System.Linq (but is easy to hand-code).
|
|
|
|
|
Sorry, I meant the brackets in the OP code. It isn't a simple OR list that can be handled with a "contains".
|
|
|
|
|
I did a major hardware upgrade yesterday (motherboard, cpu , ram, gpu ... )
I tried re-activating but alas, it does not work (or I would not be asking).
On my device page it shows 2 devices, my old one and my current one (by motherboard model); I tought I could find the info on the old device and deactivate it (delete device) and apply it on the new device
Is there a way to get back my activation code/key from there ? I can't seem to find it.
I remember that I upgraded from Windows 8-ish when it was a free update; maybe I should hunt down my old CD/DVD of windows 8 ? Is that the way to go ?
Thanks
I'd rather be phishing!
|
|
|
|
|
When my son and I built his new PC last month we bought an upgrade license -- the old system was running Win 10 Home, we installed Win 10 Pro.
We replaced nearly everything -- kept only the CPU and an HDD -- and the install didn't want to accept the licence, so I eventually had to talk with a real live person at Microsoft who was able to do something with the kid's Microsoft account then zing bang it be worked.
So, I say, "try calling Microsoft".
|
|
|
|
|
If all else fails, perhaps buy a new (OEM) key as described here? I'm looking to go this route when I eventually upgrade my personal dev box from Win7.
/ravi
|
|
|
|
|
I do computer service. I avoid hardware swaps with win 10 for this reason but had to do it for myself I forget if I actually called ms or whether it was over chat but the ran belarc advisor which served up some windows 10 data left for a bit then came back and plugged something else in and it was activated again.
|
|
|
|
|
Piebald is right - contact MS. Have electronic receipts handy and let them dive in and take over if necessary.
I had to do that when I changed MB, and it worked really well - the only complication was that his control software could only see my centre screen (of three) and the taskbar, start menu, etc. was on the left hand one - and wouldn't move because windows wasn't activated ... so he had to ask for an app, I open it and drag it onto the centre screen, etc. Took him a load longer than he expected, I think ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I saw a post the other day that the free upgrade to W10 is still available. There's a powershell script to do it. Google
|
|
|
|
|
This might interest you - it's a VBScript file he left on my computer which fetches the Win 10 key:
Option Explicit
Dim objshell,path,DigitalID, Result
Set objshell = CreateObject("WScript.Shell")
'Set registry key path
Path = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
'Registry key value
DigitalID = objshell.RegRead(Path & "DigitalProductId")
Dim ProductName,ProductID,ProductKey,ProductData
'Get ProductName, ProductID, ProductKey
ProductName = "Product Name: " & objshell.RegRead(Path & "ProductName")
ProductID = "Product ID: " & objshell.RegRead(Path & "ProductID")
ProductKey = "Installed Key: " & ConvertToKey(DigitalID)
ProductData = ProductName & vbNewLine & ProductID & vbNewLine & ProductKey
'Show messbox and save to a file
If vbYes = MsgBox(ProductData & vblf & vblf, vbOK + vbInformation, "BackUp Windows Key Information") then
Save ProductData
Else
Save ProductData
End If
'Convert binary to chars
Function ConvertToKey(Key)
Const KeyOffset = 52
Dim isWin8, Maps, i, j, Current, KeyOutput, Last, keypart1, insert
'Check if OS is Windows 8
isWin8 = (Key(66) \ 6) And 1
Key(66) = (Key(66) And &HF7) Or ((isWin8 And 2) * 4)
i = 24
Maps = "BCDFGHJKMPQRTVWXY2346789"
Do
Current= 0
j = 14
Do
Current = Current* 256
Current = Key(j + KeyOffset) + Current
Key(j + KeyOffset) = (Current \ 24)
Current=Current Mod 24
j = j -1
Loop While j >= 0
i = i -1
KeyOutput = Mid(Maps,Current+ 1, 1) & KeyOutput
Last = Current
Loop While i >= 0
If (isWin8 = 1) Then
keypart1 = Mid(KeyOutput, 2, Last)
insert = "N"
KeyOutput = Replace(KeyOutput, keypart1, keypart1 & insert, 2, 1, 0)
If Last = 0 Then KeyOutput = insert & KeyOutput
End If
ConvertToKey = Mid(KeyOutput, 1, 5) & "-" & Mid(KeyOutput, 6, 5) & "-" & Mid(KeyOutput, 11, 5) & "-" & Mid(KeyOutput, 16, 5) & "-" & Mid(KeyOutput, 21, 5)
End Function
'Save data to a file
Function Save(Data)
Dim fso, fName, txt,objshell,UserName
Set objshell = CreateObject("wscript.shell")
'Get current user name
UserName = objshell.ExpandEnvironmentStrings("%UserName%")
'Create a text file on desktop
fName = "C:\Users\" & UserName & "\Desktop\WindowsKeyInfo.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set txt = fso.CreateTextFile(fName)
txt.Writeline Data
txt.Close
End Function
If I recall correctly, he used this and entered it on the activation screen. I'd forgotten about that.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I've been on a streak, both offline and on Codeproject - where I got MVA, 2nd best article for november, and may very well get best article for december.
My code has compiled and ran usually on the first try. My code has been clever. My code has worked better than I expected.
What more could I want? I am a happy lil monster.
hack everything.
|
|
|
|
|
I believe you are now ready for what has only been talked about in legends so far....
The Uuuuuuultimate Prrrrrise!
|
|
|
|
|
A one-way trip to Q&A?
Anything that is unrelated to elephants is irrelephant Anonymous
- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944
- Never argue with a fool. Onlookers may not be able to tell the difference. Mark Twain
|
|
|
|
|
Johnny J. wrote: A one-way trip to Q&A? URGENT PLZ WRIT PARZER
|
|
|
|
|
That explains the quantity and frequency of some Lounge posts...
Anything that is unrelated to elephants is irrelephant Anonymous
- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944
- Never argue with a fool. Onlookers may not be able to tell the difference. Mark Twain
|
|
|
|
|
Go to Disneyland. Like totally.
|
|
|
|
|