|
If you want to access PDF data without recourse to a third-party library then you need to start at the Adobe Development Centre[^], and learn how to use their tools. Or, you can download the PDF specification document and figure out how to do it directly with your own code. This may be easy or difficult depending on your skill level.
|
|
|
|
|
I have the following code in a C# 2010 application that uses linq to sql when connecting to a sql server 2008 r2 database.
var attplan = from p in attDataContext.At_Pln
where p.At_id.Equals((int)Session["AttD"])
select p;
attDataContext.At_Pln.DeleteOnSubmit(attplan.FirstOrDefault());
var att = from c in attDataContext.At
where c.At_id.Equals((int)Session["AttD"])
select c;
attDataContext.At.DeleteOnSubmit(att.First());
attDataContext.SubmitChanges();
My problem is the following line of code:
attDataContext.At_Pln.DeleteOnSubmit(attplan.FirstOrDefault());
The At_Plan table can contain 1 to 500 rows that are related to the At table.
I want to use some other statement besides FirstOrDefault() since this only deletes one row in the attplan table. However, the application will not let me try another commands without obtaining a compile error.
Thus can tell me what other linq statement that I can use that will let me delete all the records in the
attplan table?
|
|
|
|
|
DeleteOnSubmit is designed to work with a single entity. If you want to use this method, you simply iterate over att and call DeleteOnSubmit for each element.
foreach (var item in att)
{
attDataContext.At.DeleteOnSubmit(item);
}
attDataContext.SubmitChanges(); As you can imagine, this will not be the most efficient operation as it will result in multiple delete statements being made when you submit the changes.
So, there must be a way to delete more than one element. Well, there is, and it's called DeleteAllOnSubmit . It looks like this:
attDataContext.At.DeleteAllOnSubmit(att.ToList());
attDataContext.SubmitChanges();
|
|
|
|
|
I have an application wherein I have H.264 frames from an RTSP stream stored in a proprietary database. I need to be able to present a frame to the H.264 decoder (frames in sequence, of course) and get back the decoded frame (bitmap, whatever) output. I cannot use the traditional DirectShow streams because I don't have a stream. Is there any codec can be used in this manner? Later I will need to go the other way as well (given bitmaps or other format images, create an H.264 stream). Any help you can give would be greatly appreciated.
|
|
|
|
|
I have this string:
Dev: 0 Model: TOSHIBA MK3265GSX Serial: 20FDF20WS FW: GJ002H STW: 0 MaxLBA: 625142447 FDESUPPORTED: 0 PREBOOT: 0 DRIVETRUSTENABLED: 0 DRIVETRUSTSUPPORTED: 0 w128: 41 FULLFW: GJ002H SERVOFW: SDLSUPPORTED: 1 PLATFORM: 0 SAFE: 1 DSTTIMEOUT: 103 ISBOOTORSYSTEM: 1
I need to parse it into Key/Value pairs. I thought of RegEx, but I'm not sure how to code that.
Any suggestions?
If it's not broken, fix it until it is
|
|
|
|
|
Kevin Marois wrote: RegEx
How about (?:(?'Key'\S+): (?'Value'.*?)) with the RightToLeft option.
And, of course, we have a Regex forum.
|
|
|
|
|
But how does RegEx know where the value ends and the next key starts?
If it's not broken, fix it until it is
|
|
|
|
|
It just does. Read up on "Regular Expressions" first.
RegEx doesn't just look at a string from one end work one character at a time to the other end. It's a pattern matching library that does a really good job at string manipulations.
|
|
|
|
|
That's what the pattern does. It's looking for single words terminated by : to create the Key. Anything else is the Value.
|
|
|
|
|
Thanks. I could use some help with this. Never done RegEx, so I'm totally unsure how to code it.
So far I have:
var expression = @"(?:(?'Key'\S+): (?'Value'.*?)) ";
Match match = Regex.Match(Line, expression,RegexOptions.IgnoreCase);
if (match.Success)
{
string key = match.Groups[1].Value;
}
I have the key, but how do I get the value out?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Kevin Marois wrote: Never done RegEx, so I'm totally unsure how to code it.
In any spare time you may have, it may be worth your while to learn how to use regular expressions and work with them. It's a powerful skill to have in your skill set
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
modified 19-Jun-12 18:34pm.
|
|
|
|
|
To add to what Paul said, you also need to install this[^].
|
|
|
|
|
|
You can stop looking at mine. I wondered why there were fingerprints on the outside of the bedroom window.
|
|
|
|
|
Those aren't finger prints.
|
|
|
|
|
*Mind bleach* OK, I'm going to have to move house now.
|
|
|
|
|
with the RightToLeft option.
|
|
|
|
|
Your regex should actually look like this:
public static Regex regex = new Regex(
"(?:(?'Key'\\S+): (?'Value'.*?))",
RegexOptions.RightToLeft
| RegexOptions.CultureInvariant
| RegexOptions.Compiled
);
|
|
|
|
|
Ok, so how so I call it? This doesn't compile:
regex.Match(Line, expression);
I don't understand RegEx at all... It's all greek to me.
If it's not broken, fix it until it is
|
|
|
|
|
Sorry Kevin - you posted after I logged off for the night. Anyway, you don't want to use Match , you want to use Matches because you are returning a collection:
MatchCollection matches = regex.Matches(expression);
foreach (Match match in matches)
{
Console.WriteLine("Key: {0} - Value: {1}", match.Groups["Key"], match.Groups["Value"]);
} Basically, you have returned a collection of matches here. In the expression, you created two named capture groups so you need to reference the items by name by looking in the Groups property.
|
|
|
|
|
[EDIT] - Never mind. I'm stupid. I changed it to...
MatchCollection matches = regex.Matches(Line);
Now it works.
Thanks for the code. I'm still getting nothing in the collection. Here's my code:
var Line = "Dev: 0 Model: TOSHIBA MK3265GSX Serial: 20FDF20WS FW: GJ002H STW: 0 MaxLBA: 625142447 FDESUPPORTED: 0 PREBOOT: 0 DRIVETRUSTENABLED: 0 DRIVETRUSTSUPPORTED: 0 w128: 41 FULLFW: GJ002H SERVOFW: SDLSUPPORTED: 1 PLATFORM: 0 SAFE: 1 DSTTIMEOUT: 103 ISBOOTORSYSTEM: 1";
var WordToFind = "Model";
Regex regex = new Regex("(?:(?'Key'\\S+): (?'Value'.*?))",
RegexOptions.RightToLeft |
RegexOptions.CultureInvariant |
RegexOptions.Compiled);
MatchCollection matches = regex.Matches(WordToFind);
foreach (Match match in matches)
{
Console.WriteLine("Key: {0} - Value: {1}", match.Groups["Key"], match.Groups["Value"]);
}
I'm guessing the regex string is wrong, but kI really don't knnow.
If it's not broken, fix it until it is
|
|
|
|
|
Kevin Marois wrote: EDIT] - Never mind. I'm stupid. I changed it to...
MatchCollection matches = regex.Matches(Line);
OK, I was just about to point that out - good job.
|
|
|
|
|
Thanks for your help.
If it's not broken, fix it until it is
|
|
|
|
|
No problem. I'm glad we could help.
|
|
|
|
|
with the RightToLeft option it knows where the key ends and the previous value starts.
modified 19-Jun-12 18:44pm.
|
|
|
|