Book a Demo

Author Topic: load Audit log via automation?  (Read 8352 times)

manfredw

  • EA User
  • **
  • Posts: 47
  • Karma: +0/-0
  • gaudeo ligneo!
    • View Profile
load Audit log via automation?
« on: February 02, 2013, 12:29:50 am »
Hello everybody,

I'm trying to load the audit logs via automation (in a C# add-in) with EA 10.
the EA help states:
Load Logs
Load a previously saved set of logs back into the project; if  the same record exists in both project and file, it is not reloaded.

This function can be accessed through the Automation Interface.

But when I look at the available methods of the Repository object I only find the SaveAuditLogs method.

Is there a way to load them?

thanks in advance!
best regards,
Manfred

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: load Audit log via automation?
« Reply #1 on: February 04, 2013, 04:17:35 pm »
Hi Manfred,

This looks like a mistake in the documentation.  I can't see any way to load audit logs via the automation interface at this time.  We will correct the help page that you mentioned for a future release.  Sorry for any inconvenience.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: load Audit log via automation?
« Reply #2 on: February 05, 2013, 12:47:13 am »
You might consider placing the logs directly into the table t_snapshot.

q.

manfredw

  • EA User
  • **
  • Posts: 47
  • Karma: +0/-0
  • gaudeo ligneo!
    • View Profile
Re: load Audit log via automation?
« Reply #3 on: February 13, 2013, 01:10:46 am »
Hi qwerty,
thanks for the hint, but how would you du that?
Isn't it risky to directly fiddle with the tables?

Hi Aaron,

would it be possible to add this function to the automation interface instead of correcting the help? It can be done through the user interface so the code allready exists, exposing its interface should not be that complicated  :)

I need to share the auditlogs with my team mates and vice versa, I allready have the synch process up and running in an add-in, using svn. The only thing i need is the LoadAuditLogs() function!

Please, please...  ;)

best regards
Manfred
« Last Edit: February 13, 2013, 01:22:48 am by manfredw »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: load Audit log via automation?
« Reply #4 on: February 13, 2013, 01:32:38 am »
Manfred,
of course it's dangerous to fiddle directly with the tables. But if you know what you're doing it's manageable. In the case of the baselines I'd say it is.

What the "Load Logs" does is simply parsing the XMI where the log had been saved and INSERT the single records in t_snapshot. You will easily recognize that XMI attributes and column names  match (e.g. SnapshotID being the primary key). So loading is really simple.

q.
« Last Edit: February 13, 2013, 01:33:50 am by qwerty »

manfredw

  • EA User
  • **
  • Posts: 47
  • Karma: +0/-0
  • gaudeo ligneo!
    • View Profile
Re: load Audit log via automation?
« Reply #5 on: February 13, 2013, 01:58:32 am »
qwerty,

thanks for the insight!
Indeed, I recognize the XML elements in the table, so that's maybe the way to go.
Any chance to get an automation code snippet that shows how to access and write to the t_snapshot table from within a c# add-in?

thanks in advance!
regards
Manfred

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: load Audit log via automation?
« Reply #6 on: February 13, 2013, 02:16:18 am »
I'm no c# coder, but generally it would be something the line
Code: [Select]
Repository.Execute ("INSERT INTO t_snapshot SnapshotID, SeriesID, Position, SnapshotName, Notes, Style, ElementID, ElementType, BinContent1, BinContent2 VALUES ('L0', 'LOG', ... )");
q.
« Last Edit: February 13, 2013, 02:17:07 am by qwerty »

manfredw

  • EA User
  • **
  • Posts: 47
  • Karma: +0/-0
  • gaudeo ligneo!
    • View Profile
Re: load Audit log via automation?
« Reply #7 on: February 13, 2013, 02:32:36 am »
qwerty,

thank you very much!!!
I think that'll get me rolling...  :)

I'm going to try that out tomorrow, a long meeting starting right now...

best regards,
Manfred

manfredw

  • EA User
  • **
  • Posts: 47
  • Karma: +0/-0
  • gaudeo ligneo!
    • View Profile
Re: load Audit log via automation?
« Reply #8 on: February 13, 2013, 05:41:54 pm »
Hello qwerty,

one more question, does the "INSERT INTO" command insert duplicates if the entry allready exists?
If this is the case how can I check whether the record allready exits?

many thanks in advance!

cheers
Manfred

manfredw

  • EA User
  • **
  • Posts: 47
  • Karma: +0/-0
  • gaudeo ligneo!
    • View Profile
Re: load Audit log via automation?
« Reply #9 on: February 13, 2013, 10:18:12 pm »
Hello again,

well sometimes life is hard...
Ijust wrote the code to parse the XML and get all the fields, wrote my SQL command and tried it in ACCESS - all was going fine until I wanted to execute the SQL query via automation...
The Repository.SQLQuery() function kept complaining about my query until I re-read the EA documentation... it only takes SELECT commands  :-[

Please tell me that there is another way to execute SQL statements via automation!  :-?

thanks in advance,
cheers
Manfred

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: load Audit log via automation?
« Reply #10 on: February 13, 2013, 10:52:02 pm »
Q. mentioned it, you need to use

Code: [Select]
Repository.Execute ("INSERT INTO t_snapshot SnapshotID, SeriesID, Position, SnapshotName, Notes, Style, ElementID, ElementType, BinContent1, BinContent2 VALUES ('L0', 'LOG', ... )");  

HTH
Günther

manfredw

  • EA User
  • **
  • Posts: 47
  • Karma: +0/-0
  • gaudeo ligneo!
    • View Profile
Re: load Audit log via automation?
« Reply #11 on: February 13, 2013, 11:28:22 pm »
Hi Günther,

sorry for my stupidity  ;)
Thank you! That works nice!

However do you guys know how to suppress or hide the DAO.Database[3022] dialog for duplicate records ?

I tried with a try / catch statement but I still get it.

thanks in advance,
cheers
Manfred

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: load Audit log via automation?
« Reply #12 on: February 14, 2013, 12:02:46 am »
Quote
Hello qwerty,

one more question, does the "INSERT INTO" command insert duplicates if the entry allready exists?
If this is the case how can I check whether the record allready exits?

many thanks in advance!

cheers
Manfred
This depends on the primary key constraints for the table. For t_snapshot the primary key is unique and EA will raise an error for a duplicate. So either you DELETE the old row or you check their existence (use SQLQuery with WHERE SnapshotID = "...") and skip the INSERT. Else you'll get a popup message for each duplicate.

q.
« Last Edit: February 14, 2013, 12:04:01 am by qwerty »

manfredw

  • EA User
  • **
  • Posts: 47
  • Karma: +0/-0
  • gaudeo ligneo!
    • View Profile
Re: load Audit log via automation?
« Reply #13 on: February 14, 2013, 12:28:22 am »
hi qwerty,

that's exactly what I was looking for!  :)
Thank you very much!!!

have a nice day!

cheers
Manfred

manfredw

  • EA User
  • **
  • Posts: 47
  • Karma: +0/-0
  • gaudeo ligneo!
    • View Profile
Re: load Audit log via automation?
« Reply #14 on: February 14, 2013, 01:10:48 am »
Hi
if anybody is interested, here is my final c# function that loads the audit logs.
And many thanks for all your help!!!  :)

Code: [Select]
       private void loadAuditLogs(EA.Repository Repository, string logFileName)
        {
                  var doc = XDocument.Load(logFileName);

                  foreach (var childElem in doc.XPathSelectElements("//Row"))
            {              
                string SnapshotID      = childElem.Element("SnapshotID").Value;
                string SeriesID            = childElem.Element("SeriesID").Value;
                string Position            = childElem.Element("Position").Value;
                string SnapshotName      = childElem.Element("SnapshotName").Value;
                string Notes            = childElem.Element("Notes").Value;
                string Style            = childElem.Element("Style").Value;
                string ElementID      = childElem.Element("ElementID").Value;
                string ElementType      = childElem.Element("ElementType").Value;
                string BinContent1      = childElem.Element("BinContent1").Value;
                string BinContent2      = childElem.Element("BinContent2").Value;                

                        string query = "INSERT INTO t_snapshot (SnapshotID, SeriesID, Position, SnapshotName, Notes, Style, ElementID, ElementType, BinContent1, BinContent2) VALUES ("+
                                                "'" + SnapshotID + "', "+            // Text  
                                                "'" + SeriesID + "', "+                  // Text
                                                "" + Position + ", "+           // Numeric
                                                "'" + SnapshotName + "', "+            // Text
                                                "'" + Notes + "', "+                  // Memo
                                                "'" + Style + "', "+                  // Text
                                                "'" + ElementID + "', "+            // Text
                                                "'" + ElementType + "', "+            // Text
                                                "'" + BinContent1 + "', "+            // Ole Object
                                                "'" + BinContent2 + "'"+            // Ole Object
                                                ");";

                        // check whether the record already exists
                        string result = Repository.SQLQuery("SELECT * FROM t_snapshot WHERE SnapshotID = \"" + SnapshotID + "\"" );
                        
                        var resultDoc = XDocument.Parse( result );
                        
                        IEnumerable<XElement> list = resultDoc.XPathSelectElements("//Row");
                  
                        // only insert the record if it is not already presents
                        if ( list.Count() == 0 )
                        {                  
                          try
                          {
                                    Repository.Execute( query );      
                          }
                          catch
                          {
                                Repository.WriteOutput("System","sql error...",0);
                          }
                        }
                        else
                        {
                          Repository.WriteOutput("System","A record already exists with SnapshotID "+SnapshotID,0);                              
                        }
            }
        }