|
I am talking about the repsonse itself.
|
|
|
|
|
dcof wrote: into one or two sql server 2008 database tables.
That is inprecise.
If you want to store the xml into a column in a table, then you just do that.
If you want to parse the xml, then transform it, then save data from that into columns then that is what you need to do.
If you don't need to tranform it then SQL server can parse and insert xml directly.
|
|
|
|
|
I would like to parse an xml file using linq in a C#2010 application. Listed below you will find an example of an xml file I want to parse. I would like to use the code listed below to parse the an xml file. Thus I am wondering if you can show me how to use the code I listed below to parse the xml displayed below and/or show me code that will accomplish this goal?
The following is the code:
using System;
using System.Linq;
using System.Xml.Linq;
class Program
{
static void Main()
{
XDocument document = XDocument.Load(@"d:\test.xml");
var priceInfo = from e in document.Descendants("MPrice").Elements("Price")
let start = DateTime.Parse(e.Descendants("StartDt").FirstOrDefault().Value)
let end = DateTime.Parse(e.Descendants("EndDt").FirstOrDefault().Value)
where start < DateTime.Now && end > DateTime.Now
select new { Id = e.Parent.Element("Id").Value, ListPrice = e.Element("ListPrice").Value };
Console.WriteLine(priceInfo.FirstOrDefault().Id);
Console.WriteLine(priceInfo.FirstOrDefault().ListPrice);
}
}
The following is the metatag:
<ns2:RetsubPack serviceSuccessful="true" returnCode="0" xmlns:ns2="http://test1/test">
<statusDescription>Package Details retrieved Successfully</statusDescription>
<PackageDetails>
<Type>type2</Type>
<Category>dog</Category>
<ContName>Co 1</ContgName>
<TotalTrans>0</TotalTrans>
</PackageDetails>
<NumberOfDocuments>3</NumberOfDocuments>
<subDocuments attachmentId="xx1">
<DocumentMetadata>
<DocumentTypeCode>Spreadsheet1</DocumentTypeCode>
<PackageId>pkg1</PackageId>
</DocumentMetadata>
</subDocuments>
<subDocuments attachmentId="xx2">
<DocumentMetadata>
<DocumentTypeCode>Spreadsheet2</DocumentTypeCode>
<PackageId>pkg1</PackageId>
</DocumentMetadata>
</subDocuments>
<subDocuments attachmentId="xx3">
</ns2:RetsubPack>
|
|
|
|
|
I don't use Linq, so I can't help you there, but I do manipulate XML a bit, usually in an XmlDocument, so maybe I can with that?
|
|
|
|
|
LINQ, it has been a while, but if I see you're query and the XML file, the code does not resemble the XML file? (or am I missing something?)
Some questions:
1. What do you mean with "parse" exactly, what do you want to achieve?
2. Do you know LINQ to XML?
3. Am I right that the code does not relate to the XML and if so, what is the exact problem? What have you tried yourself?
V.
|
|
|
|
|
|
Hello All,
I am using a winapp form c# (.net4.0)to login and navigate deep into a webpage, upload a file, download a file. All this works successfully... MOST of the time. Everyonce in a while, when I hit the download button, the system seems to hang. Like a webpage that never fully loads. My goal here is if ALL the pages don't load successfully, then close all webbrowsers and re-try process. Anyone have any ideas to see if page is hung on loading. My first thought was to have some sort of timer to check, if doesn't load, then start over.
I am opening a webbrowser object inside my winform in c#.
Here's my idea and please feel free to rip apart with a better concept.
Concept is timer launches Invoke(naviFunction). If it gets to the end of naviFunction then just break loop and continue. However, if the webbrowsing hangs somewhere, then the 2 minute timer will get hit, and restart the whole process.
Then maybe put some counter and if it tries twice, completely stop program so I can investigate.
just to put a bit more background... in the navigating section I am launching 2 new short threads. they both finish before the end of the main navigation. I've put them in to handle pop up windows where the main code pauses when they are on screen.
So I've implemented and I'm a bit stuck on something.
When I put a normal process everything works successfully.
When I test a fake navigation hanging point... such as below.. The code does restart at 2 minutes and it completes the re-cycle successfully. The problem is when it is done. Instead of moving on in the code, (outside the timer area) it goes right back to the point where it originally got hung on. But since I already did it successfully I need it to exit out of the whole timer area. ANy idea what I'm doing wrong?
so I think I found where the problem lies but I don't know how to fix it.
the timer I am using... I used Invoke(new naviTimer(naviTimerFunction) to launch the section of navigation/download. So when the fake hang hits... then 2 minutes passes, it resets (like its supposed to). Then completes properly... soon as the navigation/download completes, I need it to go to the main code, but instead it hits the Invoke(naviTimer) again in the timer... and it goes back to where fake hanging originally paused and tries to continure from there. ideas??
maincode
{
x=0
dountil x<>0
start timer (timer launched instantly)
if naviTimerFunction completed, then break loop
stop timer
loop
...continue code
...continue code
...continue code
...continue code
}
timer()
{
reset timer interval to 2 minutes
Invoke(new naviTimer(naviTimerFunction))
}
naviTimerFunction
{
navigate
navigate (fake hanging point!!!)
navigate (start sub thread)
download (end sub thread)
navigate (start sub thread)
navigate (end sub thread)
stoptimer
}
tried a different way, used systems.timer.timer and before it even runs the first time it gives me error stating not a single thread. Cannot create webbrowser objects. Cant get that to work either..... ugh
|
|
|
|
|
I'm not sure if I understand your question correctly, but if your problem is that the Timer event handler keeps firing, you can disable the timer as the first line of code in your Timer event handler so that it does not fire again. You can again enable it when you need it (like when navigating a page).
Alternatively, you can use a BackgroundWorker to hit the url using a WebRequest/WebResponse pair and use the WebBrowser.DocumentText property to load the resulting markup in the RunWorkerCompleted event handler.
|
|
|
|
|
sorry about the confusion. the main problem is even after I hit timer.stop(), upon the timer stopping, the code continues where it left off. hope I am making some sense. On the thread from INVOKE... not the main thread like I wanted
|
|
|
|
|
Disabling the timer does not abruptly stop its already running event handler.
The only way to circumvent this problem is to periodically check if timer is enabled and then exit the code.
|
|
|
|
|
The Navigate method is blocking execution, until it completes or times out. An easy solution would be to put the webbrowser in it's own process and have it retrieve your data. You can start the process async, and terminate it if it doesn't return results within a specified time-range. Your main-application would then run the processes one after another, until it reaches the end of it's list.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
|
I have a question on password security. This is a requirement from a client, and I want to do it right.
Here's the requirements:
1) The code needs to use best practices and in a way that will perform well, scale well under load.
This isn't that big of a deal for me. I write pretty good code.
2) Here's what he asked for in his email
A) It must contain at least one vowel.
B) It cannot contain three consecutive vowels or three consecutive consonants.
C) It cannot contain two consecutive occurrences of the same letter, except for 'ee' or 'oo'.
My problems is that I think I could use RegEx for this, but I suck at RegEx. I'v always hated it becuase it seems so cryptic.
I don't have a problem working through the problem, or coding it - my problem is knowing where to go with this.
1) Is RegEx the answer?
2) Would you use another technique? Which one?
3) Anything in the .Net class libs that I can use?
Summaary is, I'm al little unsure how to move ahead on this, so any input I get would be great.
Thanks
|
|
|
|
|
|
I too think the client is talking through the wrong end of his body, but hey, you give the man what he wants, not what he needs.
Regex is the way to go, even if it causes you a little pain right now. Grab a copy of Expresso[^], the best free Regex tool on the planet*, and go to work.
You will need to clarify the requirements a bit - min/max length, allowed character set, etc, as well as the client's rules (ee and oo allowed but not tt seems a bit silly...)
Expresso allows you to build a regex incrementally, and it provides a tree-like view of what each little bit means, as well as testing as you go. Your regex may not fit on one line, but it'll probably fit in a tweet.
If you can get your client to provide you two lists - good and bad passwords - then you can run them as tests in Expresso.
If you get stuck along the way, post a question in the Regular Expressions forum[^].
* disclaimer: I have no connection to Expresso other than as a very satisfied user.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
I've used Expresso in the past and it is a great tool to have around.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
zephaneas wrote: little unsure how to move ahead on this
You should recommend to your client the criteria he has given you will not make the passwords strong at all and advise him that more strength is a good idea.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
If a customer comes up with such ideas, try shortly to inform him on good practices. If he seems reluctant to realize the difference, give him what he insists to get.
And since new user registrations / password changes happen not so often, do not care for highest performance. Naive approaches are good enough.
Create character arrays for vowels and consonants, e.g. char[] vowels = "AaEeIiOoUu".ToCharArray(); , and condition A can be checked with the "IndexOfAny" method of string.
If the password is longer than 1 character (oh yes, "a" is a safe password for your customer...), check B and C by looping thru the characters of the password - you can access each character by the indexer, e.g. char c = password[0]; .
|
|
|
|
|
Those are really bad criteria, particularly as there's no length requirements in there which are the one thing that really makes a difference. "This is my password" is a much more secure one than "Ql5'J".
I don't think you can do C with a regex so you probably want to traverse the string yourself anyway, which makes A trivial and B rather easy.
|
|
|
|
|
He wants you to use best practices, but his own "requirements" violate best practices for passwords. I think you need to write a reply to the email, not code.
|
|
|
|
|
..and suggest that one should only use a GUID as an acceptable password, with the system sending you a new password to remember at least every two weeks
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
zephaneas wrote: A) It must contain at least one vowel.
So, a password of a is enough to satisfy the criteria.
As others have said, he needs to be educated as to best practices (e.g. use of symbols, minimum length, etc).
To answer the question though - I wouldn't use RegEx for something like this. You may get a working regular expression, but it will be tied to these requirements. If the criteria expands, you'll have to revisit the regex, and you may find that the solution is no longer valid. A fairly elegant solution would be to use the Visitor Pattern[^]. With this, you can add new rules without affecting the underlying logic, simply by adding new visitors.
|
|
|
|
|
I would like to accomplish the following tasks in a C#.net 2010 application:
1. start in a specified directory location.
2. check to see if a specified subfolder exists.
3. if the specified folder does not exist, create the subfolder called customer1.
4. if the subfolder called 'docs' does not exist, create that folder.
5. if the type of document type is '*.pdf' or '*.doc' place the data file in the subfolder called
'docs'.
if the document type is of any other document type, place that document in folder level where called 'customer1'.
Thus I am wondering if you can tell me and/or point me to references that will show me how to accomplish all and/or parts of the steps I would like to accomplish listed above my showing me showing me code and/or pointing me to links that will show me how to accomplish this goal?
|
|
|
|
|
What have you tried? Where are you stuck?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
If I were you I would be checking out the System.IO namespace.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|