none
Creating history of backup jobs with an index in XML? that I can show in listview and then click to open relevant log RRS feed

  • Question

  • Hi

    Hopefully the title gives an idea, but this is one of those questions where I know what I want to achieve but just lost as to how to implement it

    Basically I have a tool which will sync (copy) data from c:\examplepath1 to d:\examplepath2

    When the job finishes it saves a log file with current date/time e.g. 1006181322.log

    So I end up with several logs

    Each job also ends with a status for ease at this points lets just say Success, Failure, Cancelled

    I would like a form with a listview which can load some sort of "index" of all logs - and I thought XML would be good for this?

    So when I open form the listview populates with say a Date and Description column listing each log and if I then double click an entry it will open the relevant full log file

    I hope this make sense - if not please ask

    Below is idea of what I thought XML would be like

    So how can I parse this, show it in form etc etc, and how can I add to this XML when a new log is saved

    Thank you :)

    <?xml version="1.0" encoding="utf-8"?>
    <log>
        <entry>
          <timeStamp>2018-04-27 21:08:50Z</timeStamp>
          <message>Success: D:\Newfolder1 synced to D:\Newfolder2</message>
          <dataRef>2704182108.log</dataRef>
        </entry>
        <entry>
          <timeStamp>2018-06-06 17:19:58Z</timeStamp>
         <message>Failed: D:\Newfolder not synced to D:\Newfolder2</message>
          <dataRef>0606181719.log</dataRef>
        </entry>
        <entry>
          <timeStamp>2018-06-06 21:17:58Z</timeStamp>
         <message>Cancelled: D:\Newfolder not synced to D:\Newfolder2</message>
          <dataRef>0606182117.log</dataRef>
        </entry>
    </log>


    Darren Rose

    Sunday, June 10, 2018 12:26 PM

All replies

  • You could use Linq-2-XML to read the XML, that could convert the XML into a List of anonymous objects or a List(of T) of concrete objects and bind the List to a datagrid control not a ListView.  You can also use a datatable too.

    Sorry, the example is in C#. 

    https://www.intertech.com/Blog/query-an-xml-document-using-linq-to-xml/

    But these links should help you with VB.NET

    https://www.youtube.com/watch?v=ne_lirklHnk

    https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/xml/overview-of-linq-to-xml

    https://code.msdn.microsoft.com/LINQ-Sample-Queries-13a42a54

    I'll keep it simple for you by using the datatable approach in binding XML to a datagridview.

    http://vb.net-informations.com/xml/vb.net-xml-to-DataGridView.htm

    From the datagridview, you should be able to figure out how to click on a row to display the XML if you choose to do so.

    Sunday, June 10, 2018 3:06 PM

  • I would like a form with a listview which can load some sort of "index" of all logs - and I thought XML would be good for this?

    So when I open form the listview populates with say a Date and Description column listing each log and if I then double click an entry it will open the relevant full log file


    Darren Rose

    Hi

    Am I misunderstanding, but it seems that what you are asking for is just a list of the file names. The file names contain the information you are asking for. If you saved the log files with (say) a date and time formatted differently (say "ddd dd MMM yyyy HHmm"), that would make it almost identical to your question,


    Regards Les, Livingston, Scotland


    • Edited by leshay Sunday, June 10, 2018 3:28 PM
    Sunday, June 10, 2018 3:27 PM
  • @ Leshay

    The listview or whatever control what show the information from the XML example I posted so it would be showing more than just a filename

    So as a rough mockup for example:-

    Date/Time                     Job Summary                                                   Job Status

    10/06/18 13:34             D:\Newfolder1 synced to D:\Newfolder2             Success

    09/06/18 12:24             C:\Folder to \\server1\c$\folder                         Failed


    Darren Rose

    Sunday, June 10, 2018 3:37 PM
  • @ Leshay

    The listview or whatever control what show the information from the XML example I posted so it would be showing more than just a filename

    So as a rough mockup for example:-

    Date/Time                     Job Summary                                                   Job Status

    10/06/18 13:34             D:\Newfolder1 synced to D:\Newfolder2             Success

    09/06/18 12:24             C:\Folder to \\server1\c$\folder                         Failed


    Darren Rose

    Again, the datagridview would do this automatically with column headings and all, even the ability to sort on a gridrow column, if you bind that datatable to the control that is derived from the XML.

    It doesn't get any simpler nor does it need to complicated.

    Sunday, June 10, 2018 4:38 PM
  • Again, the datagridview would do this automatically with column headings and all, even the ability to sort on a gridrow column, if you bind that datatable to the control that is derived from the XML.

    It doesn't get any simpler nor does it need to complicated.

    Hi DA924x

    I hadn't got round to reading all the pages you had linked - I was simply replying to Leshay's question so wasn't ignoring your reply

    I will have a proper read later and then have a go - don't need ability to sort on columns or anything which is why I had originally gone for more basic control such as listview, but I get your point


    Darren Rose

    Sunday, June 10, 2018 4:55 PM
  • Hi all

    Thanks for replies

    Decided I was overcomplicating matters, so just saving logs with Success-1306181444 or Failed-1306181344 etc, and then showing them in a list splitting them at - so can show status in one column and date in another and clicking then opens full log


    Darren Rose

    Wednesday, June 13, 2018 8:19 PM