Relative complicated linq query
-
Sunday, May 06, 2012 6:53 PM
Hello,
First of all guys i would like to precise that I'm new to LinQ and i wasn't able to find the answer my self.
here is the problem, i have an XML file (which is very big i simplified it as much as possible) i need to select only the successive Blocks which verifies a certain condition.
The XML looks like :
<MaLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="MaLogFile.xsd"> <Message MsgType="Info" MsgText="Association Established With Machine 3"> <TimeStamp Date="2012-04-23" Time="08:26:01.797" TimeBias="-60"/> <ProcessID>2460</ProcessID> <ThreadName>4484</ThreadName> <AppName>App1</AppName> <ComputerName>XPS001</ComputerName> </Message> <Message MsgType="Info" MsgText="Open Association with machine 3, ok"> <TimeStamp Date="2012-04-23" Time="08:26:01.797" TimeBias="-60"/> <ProcessID>2460</ProcessID> <ThreadName>4484</ThreadName> <AppName>App1</AppName> <ComputerName>XPS001</ComputerName> </Message> <Message MsgType="Info" MsgText="Open File 66.2216774846.15610081128145128.11"> <TimeStamp Date="2012-04-23" Time="08:26:01.797" TimeBias="-60"/> <ProcessID>2460</ProcessID> <ThreadName>4484</ThreadName> <AppName>App1</AppName> <ComputerName>XPS001</ComputerName> </Message> <Message MsgType="Info" MsgText="DestID=91370"> <TimeStamp Date="2012-04-23" Time="08:26:01.828" TimeBias="-60"/> <ProcessID>2460</ProcessID> <ThreadName>4484</ThreadName> <AppName>App1</AppName> <ComputerName>XPS001</ComputerName> </Message> <Message MsgType="Info" MsgText="Message Opened for Service"> <TimeStamp Date="2012-04-23" Time="08:26:01.849" TimeBias="-60"/> <ProcessID>2460</ProcessID> <ThreadName>4484</ThreadName> <AppName>App1</AppName> <ComputerName>XPS001</ComputerName> </Message> <Message MsgType="Info" MsgText="Send Order: CustomOrder1/14233"> <TimeStamp Date="2012-04-23" Time="08:26:01.850" TimeBias="-60"/> <ProcessID>2460</ProcessID> <ThreadName>4484</ThreadName> <AppName>App1</AppName> <ComputerName>XPS001</ComputerName> </Message> <Message MsgType="Info" MsgText="Send order Description: diagnostique"> <TimeStamp Date="2012-04-23" Time="08:26:01.850" TimeBias="-60"/> <ProcessID>2460</ProcessID> <ThreadName>4484</ThreadName> <AppName>App1</AppName> <ComputerName>XPS001</ComputerName> </Message> <Message MsgType="Info" MsgText="Send Child Order Description: diagnostique"> <TimeStamp Date="2012-04-23" Time="08:26:01.850" TimeBias="-60"/> <ProcessID>2460</ProcessID> <ThreadName>4484</ThreadName> <AppName>App1</AppName> <ComputerName>XPS001</ComputerName> </Message> <Message MsgType="Info" MsgText="Send Instance Number: 1"> <TimeStamp Date="2012-04-23" Time="08:26:01.850" TimeBias="-60"/> <ProcessID>2460</ProcessID> <ThreadName>4484</ThreadName> <AppName>App1</AppName> <ComputerName>XPS001</ComputerName> </Message> <Message MsgType="Info" MsgText="Affected UID set to 66.2216774846.15610081128145128.11"> <TimeStamp Date="2012-04-23" Time="08:26:01.851" TimeBias="-60"/> <ProcessID>2460</ProcessID> <ThreadName>4484</ThreadName> <AppName>App1</AppName> <ComputerName>XPS001</ComputerName> </Message> <Message MsgType="Info" MsgText="Message Send"> <TimeStamp Date="2012-04-23" Time="08:26:01.993" TimeBias="-60"/> <ProcessID>2460</ProcessID> <ThreadName>4484</ThreadName> <AppName>App1</AppName> <ComputerName>XPS001</ComputerName> </Message> <Message MsgType="Info" MsgText="Response Received"> <TimeStamp Date="2012-04-23" Time="08:26:02.404" TimeBias="-60"/> <ProcessID>2460</ProcessID> <ThreadName>4484</ThreadName> <AppName>App1</AppName> <ComputerName>XPS001</ComputerName> </Message> <Message MsgType="Info" MsgText="Process, Set pixels, Process, Send, Read response, "> <TimeStamp Date="2012-04-23" Time="08:26:02.404" TimeBias="-60"/> <ProcessID>2460</ProcessID> <ThreadName>4484</ThreadName> <AppName>App1</AppName> <ComputerName>XPS001</ComputerName> </Message> <Message MsgType="Info" MsgText="Association with Machine 3 Closed"> <TimeStamp Date="2012-04-23" Time="08:26:02.413" TimeBias="-60"/> <ProcessID>2460</ProcessID> <ThreadName>4484</ThreadName> <AppName>App1</AppName> <ComputerName>XPS001</ComputerName> </Message> <Message MsgType="Info" MsgText="Close Association with Machine 3, ok"> <TimeStamp Date="2012-04-23" Time="08:26:02.413" TimeBias="-60"/> <ProcessID>2460</ProcessID> <ThreadName>4484</ThreadName> <AppName>App1</AppName> <ComputerName>XPS001</ComputerName> </Message> <Message MsgType="Info" MsgText="Order Push completed, All OK"> <TimeStamp Date="2012-04-23" Time="08:26:02.414" TimeBias="-60"/> <ProcessID>2460</ProcessID> <ThreadName>4484</ThreadName> <AppName>App1</AppName> <ComputerName>XPS001</ComputerName> </Message> </MaLog>What i want to have :
1. Select only App1 : other applications are not targeted by this program
<AppName>App1</AppName>
And message type is "Info"
MsgType="Info"
2. The occurrence of all latency, a latency is when the difference between two successive Time ="hour.Min.Sec.ms" values (two blocks) is more than 10 seconds
3. This must be grouped by Machine, notice that in the xml file we can find more than association with a specific machine the beginning and the end of an association is marked with :
Association Established With Machine 3
Association with Machine 3 Closed
The 2. is the heart of this Linq query and was the most difficult part for me as i couldn't find a way to do it special when i need to go higher when a latency is detected to get the machine.
So basically this is it, go through the xml whenever a two successive messages are separated by more than 10 seconds go back find the machine ...etc those info will be stored in my collection.
Thanks a lot for your help.
-------------------------------------------------------------------------
The second Way i need to do it is with text files (sorry i couldn't find more appropriate forum for LinQ to object)
My Text file (which is the equivalent of the previous XML) is like
Info Association Established With Machine 3 App1 23.04.2012 8:26:01.797 Info Open Association with [Machine 3], ok App1 23.04.2012 8:26:01.797 Info Open File 66.2216774846.15610081128145128.11 App1 23.04.2012 8:26:01.797 Info DestID=91370 App1 23.04.2012 8:26:01.828 Info Message Opened for Service: STANDARD_PRESENT, Command: C_RQ App1 23.04.2012 8:26:01.849 Info Send Order: CustomOrder1/14233 App1 23.04.2012 8:26:01.850 Info Send Order Description: diagnostique App1 23.04.2012 8:26:01.850 Info Send Child Description: diagnostique App1 23.04.2012 8:26:01.850 Info Send Instance Number: 1 App1 23.04.2012 8:26:01.850 Info Affected UID set to 66.2216774846.15610081128145128.11 App1 23.04.2012 8:26:01.851 Info Message Send App1 23.04.2012 8:26:01.993 Info Response Received App1 23.04.2012 8:26:02.404 Info Process, Set pixels, Process, Send, Read response, App1 23.04.2012 8:26:02.404 Info Association with Machine 3 Closed App1 23.04.2012 8:26:02.413 Info Close Association with Machine 3, ok App1 23.04.2012 8:26:02.413
The same 3 points for the XML are needed for the text format (for this one i personally give up :( )
Thanks again for your help.
- Edited by Rugal1985 Sunday, May 06, 2012 8:02 PM Text format
All Replies
-
Tuesday, May 08, 2012 6:48 AMbump
-
Wednesday, May 09, 2012 10:56 AMNo body has an answer or an idea?
-
Wednesday, May 09, 2012 12:54 PMI fail to understand your requirements 2. and 3.. Can you elaborate on them, maybe by posting for a small but representative input sample the corresponding output sample you want to create, and by explaining the grouping criteria with some more sentences?
MVP Data Platform Development My blog
-
Thursday, May 10, 2012 11:40 AM
Hello,
Thank you.
So for Point 2. : the idea is to compare the
<TimeStamp Date="2012-04-23" Time="08:26:02.404" TimeBias="-60"/>
Each time it is more than 10 second we now there is a latency
example (made it):
<Message MsgType="Info" MsgText="Send Child Order Description: diagnostique"> <TimeStamp Date="2012-04-23" Time="08:26:01.850" TimeBias="-60"/> <ProcessID>2460</ProcessID> <ThreadName>4484</ThreadName> <AppName>App1</AppName> <ComputerName>XPS001</ComputerName> </Message> <Message MsgType="Info" MsgText="Send Instance Number: 1"> <TimeStamp Date="2012-04-23" Time="08:36:01.850" TimeBias="-60"/> <ProcessID>2460</ProcessID> <ThreadName>4484</ThreadName> <AppName>App1</AppName> <ComputerName>XPS001</ComputerName> </Message>here we can see that between
Time="08:26:01.850"
and
Time="08:36:01.850"
we have 10 second so we relieve a latency.
For point 3. :
the grouping criteria is by machine as we should know who caused the latency (i think it's the hardest part).
So if we detect a latency (point 2.) we also should find the responsible machine which could be found here :
<Message MsgType="Info" MsgText="Association Established With Machine 3">
so as i explained higher each time we find the criteria of point 2. we should go higher in the XML to find this tag and take the responsible machine : in this example the machine = Machine 3.
As an output we should have data like this:
Machines
latency
Machine 3
1
Machine 5
4
Machine 12
2
If it's not clear either i can explain more.
Sorry for bad English.
Thanks for your help.
- Edited by Rugal1985 Thursday, May 10, 2012 11:40 AM
-
Tuesday, May 22, 2012 1:09 PMbump
-
Wednesday, June 06, 2012 11:01 AMCan anyone help ?

