0

这适用于 BOBJ 4.0 SP5 .net SDK。

谁能帮我了解如何使用 infoStore.Commit?我的代码粘贴在下面。根据我的理解,这应该有效。但事实并非如此。IDE 不会抛出任何错误,但是当我运行代码时,我得到:

System.NullReferenceException:对象引用未设置为对象的实例。在 BusinessObjects.Enterprise.Infostore.Internal.InfoStore.commitHelper(IInfoObjects objs, CommitFlags flag) 在 BusinessObjects.Enterprise.Infostore.Internal.InfoStore.Commit(IInfoObjects objs) 在 C 中的 BOUpdate.Program.Main(String[] args): \Users\username\Documents\Visual Studio 2017\Projects\UpdateInstances\UpdateInstances\Program.cs:第 55 行

这是代码(我要问的部分是“infoStore.Commit(boInfoObjects);”):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BusinessObjects.Enterprise.Framework;
using BusinessObjects.Enterprise.Infostore;
using CrystalDecisions.Web;


namespace BOUpdate
{
    class Program
    {
        static void Main(string[] args)
        {
            string username = "username";
            string password = "password";
            string cmsname = "cmsname";
            string authType = "secEnterprise";

            string reportQuery = "Select * FROM CI_INFOOBJECTS where (SI_INSTANCE=1 or SI_RECURRING = 1) and SI_PARENTID = 4229118";

            IInfoStore infoStore;
            IInfoObjects boInfoObjects;
            ISessionMgr sm = CrystalEnterprise.GetSessionMgr();
            IEnterpriseSession es = sm.Logon(username, password, cmsname, authType);

            try
            {
                infoStore = (IInfoStore)es.GetService("", "InfoStore");

                int max_id = 0;
                int querysize = 0;
                int isCrystalReport = 0;
                String curKind = "";

                for (; ; )
                {
                    boInfoObjects = (IInfoObjects)infoStore.Query(reportQuery + " AND SI_ID > " + max_id + " ORDER BY SI_ID ASC");

                    int querySize = boInfoObjects.ResultSize;

                    for (int i = 0; i < querySize; i++)
                    {
                        IInfoObject boReport1 = (IInfoObject)boInfoObjects[0];

                        isCrystalReport = 1;
                        //Console.WriteLine(curKind);
                        if (boReport1.Properties.GetProperty("SI_KIND").Value.ToString() != "CrystalReports")
                        {
                            isCrystalReport = 0;
                            curKind = boReport1.Properties.GetProperty("SI_KIND").Value.ToString();
                            boReport1.Properties.SetProperty("SI_KIND", "CrystalReport");
                            infoStore.Commit(boInfoObjects);

                            boInfoObjects = (IInfoObjects)infoStore.Query(reportQuery + " AND SI_ID >= " + (boReport1.ID) + " ORDER BY SI_ID ASC");
                            boReport1 = (IInfoObject)boInfoObjects[0];
                            querysize = boInfoObjects.ResultSize;
                            i = 0;
                        }

                        Report tmpReport = (Report)boReport1;
                        Console.WriteLine(tmpReport.DataSources[0].ToString());
                        //ISDKList dbLogon = 
                    }
                }
            }
            catch (Exception e)
            {
                es.Logoff();
                Console.WriteLine(e);
            }


            //enterpriseSession.Logoff();            
        }
    }
}

感谢您提供的任何见解!

这是来自 SAP 的原始代码(java):

            <%@ page import = "com.crystaldecisions.sdk.exception.SDKException,
                               com.crystaldecisions.sdk.framework.*,
                               com.crystaldecisions.sdk.occa.infostore.*,
                               com.crystaldecisions.sdk.properties.*,
                               com.crystaldecisions.sdk.plugin.desktop.report.*,
                               com.crystaldecisions.sdk.plugin.desktop.common.*,
                               com.crystaldecisions.sdk.plugin.destination.diskunmanaged.*,
                               com.crystaldecisions.sdk.plugin.destination.smtp.*,
                               com.crystaldecisions.sdk.plugin.desktop.report.*,
                               java.io.*,
                               java.util.*"

            %><%

            // ------------------------------
            // How to use:
            //
            // Copy this jsp page into the folder C:\Program Files (x86)\SAP BusinessObjects\tomcat\webapps\AdminTools
            //
            // Copy the following jar files from the folder: C:\Program Files (x86)\SAP BusinessObjects\SAP BusinessObjects Enterprise XI 4.0\java\lib 
            // to the folder 
            // C:\Program Files (x86)\SAP BusinessObjects\tomcat\webapps\AdminTools\WEB-INF\lib
            //
            // SL_plugins.jar
            // cereports.jar
            // CrystalReportsSDK.jar - This one isn't needed to run the sample - but copying the other two seems to break query builder unless you include this one.
            //
            //
            // Modify the User Credentials Section to appropriate logon credentials for your system
            // Modify the infostore query to return back the reports you want to modify.  I recommend testing the query in query builder first (http://myServer:8080/AdminTools)
            // In the WriteToLog function - change the logging path to whatever desired path you want the log file to be written to.  The default is in the AdminTools folder referenced above
            // Uncomment the functions for the properties you want to change.
            // Run this by opening a new browser and going to http://myServer:8080/AdminTools/modifyrecurringinstance.jsp
            // ------------------------------

            // User Credentials
            String username = "user";
            String password = "pass";
            String cmsname  = "localhost";
            String authType = "secEnterprise";

            // This is the query used to return back the report instances you want to modify.

            // All pending instances  (Both recurring and non-recurring)
            String reportQuery = "Select * FROM CI_INFOOBJECTS where (SI_INSTANCE=1 or SI_RECURRING = 1) and SI_SCHEDULEINFO.SI_PROGRESS = 1";

            // All pending recurring instances.  Note that it does not have SI_KIND='CrystalReport' in it.  This is because if you schedule a crystal report to PDF then SI_KIND will be 'PDF'
            //String reportQuery = "Select * FROM CI_INFOOBJECTS where SI_RECURRING =1 and SI_SCHEDULEINFO.SI_PROGRESS = 1";

            // All pending recurring instances owned by administrator (ID 12)
            //String reportQuery = "Select * FROM CI_INFOOBJECTS where SI_RECURRING =1 and SI_OWNERID=12 and SI_SCHEDULEINFO.SI_PROGRESS = 1";



            IEnterpriseSession enterpriseSession  = null;
            IInfoStore infoStore;
            IInfoObjects boInfoObjects; 

            enterpriseSession = CrystalEnterprise.getSessionMgr().logon(username, password, cmsname, authType);
            infoStore = (IInfoStore)enterpriseSession.getService("", "InfoStore");

            int max_id = 0;
            int querysize = 0;
            boolean isCrystalReport = false;
            String curKind = "";
            out.println("Starting </BR>");
            writeToLog("Starting Sample");

            for(;;) { 
                boInfoObjects = (IInfoObjects)infoStore.query(reportQuery + " AND SI_ID > " + max_id +  " ORDER BY SI_ID ASC");

                querysize = boInfoObjects.size();
                if( querysize == 0) 
                    break;


                for(int i =0; i< querysize; i++) {
                    IInfoObject boReport1 = (IInfoObject)boInfoObjects.get(i);

                    isCrystalReport = true;
                    out.println("Processing Report " + boReport1.getID() + " : " + boReport1.getTitle() + "</BR>");
                    writeToLog("Starting to Process Report " + boReport1.getID() + " : " + boReport1.getTitle());
                    // If the object is not of type crystal report (Scheduled to any format other than crystalreports) then we need to modify it.
                    if (!boReport1.getKind().equals("CrystalReport")) {

                        isCrystalReport = false;
                        curKind = boReport1.getKind();
                        boReport1.properties().setProperty("SI_KIND", "CrystalReport");
                        infoStore.commit(boInfoObjects); 

                        // At this point we need to requery for the same report - otherwise the rest of the code will not work.
                        // This also involves resetting the for loop
                        boInfoObjects = (IInfoObjects)infoStore.query(reportQuery + " AND SI_ID >= " + (boReport1.getID()) +  " ORDER BY SI_ID ASC");
                        boReport1 = (IInfoObject)boInfoObjects.get(0);
                        querysize = boInfoObjects.size();
                        i = 0;

                    }

                    // Now cast it to a crystal report object
                    IReport tmpReport = (IReport)boReport1;
                    try {

                        // Change the Report
                        // Uncomment the functions for the properties you want to change for the report.

                        // Update the database username and password.
                        //Note: This assumes that all the reports are using the default database logon info.  If they are using custom database logon 
                        // then they would need to use the method setCustomDatabaseName(“MyDatabaseName”); instead.
                        //They can tell if the report is using default or custom database logon info by looking at the method “isOriginalDataSource()”.
                        changeReportDBLogons(tmpReport, "mydbName");

                        // Change how many retries are allowed
                        //changeReportRetries(tmpReport, 5);

                        // Change the file IO username and password for unmanaged disk location
                        //changeReportUnmanagedDiskLogonCredentials(tmpReport, infoStore, "myOSUsername", "myOSPassword");

                        // Change the time the next instance will run at
                        //changeScheduleStartTime(tmpReport, new java.util.Date("7/13/25 4:15:00 PM"));

                        // Change the end time of the scheduled instance (The last time it will be allowed to run - defaults to 10 years in the future)
                        //changeScheduleEndTime(tmpReport, new java.util.Date("7/13/26 4:15:00 PM"));

                        // Change the from field for a schedule to SMTP instance
                        // changeScheduleFromFieldForScheduleSMTP(tmpReport, infoStore, "default@myserver.com");

                    } catch (Exception ex) {
                        writeToLog("Error modifying report: " + ex.toString());
                    } finally {
                        //  If we changed the SI_KIND - make sure we change it back to the original type
                        if (isCrystalReport == false) {
                            writeToLog("Changing report " + boReport1.getID() + " : " + boReport1.getTitle() + " back to type " + curKind.toString());
                            tmpReport.properties().setProperty("SI_KIND", curKind);
                        }
                    }

                    writeToLog("Finished Processing Report " + boReport1.getID() + " : " + boReport1.getTitle());

                    // Update the max id so the next infostore query doesn't include this report.
                    max_id = boReport1.getID();  
                }
                // Save the changes
                infoStore.commit(boInfoObjects); 
            }
            writeToLog("Finished Sample </BR>");

            out.println("Job Completed");
            %>
            <%!

            // Helper Methods
            public void writeToLog(String msg) {
                try {
                    // Set up Logging File
                    FileOutputStream FSout;
                    PrintStream pStream; // declare a print stream object
                    FSout = new FileOutputStream("C:\\Program Files (x86)\\SAP BusinessObjects\\tomcat\\webapps\\AdminTools\\TestOutput.txt", true);  // Append
                    pStream = new PrintStream(FSout); 
                    pStream.println(msg);
                    pStream.close();
                } catch (IOException e) {
                    //error writing to log
                }
            }

                // This function sets all database logons to the same username and password.  If you want to customize it for each logon, you will need to modify this function
                public void changeReportDBLogons(IReport myReport, String dbName) {
                              try {
                                           writeToLog("Changing Database Logon for report ID " + myReport.getID() + " : " + myReport.getTitle());
                                           ISDKList dbLogons = myReport.getReportLogons();
                                           for (int k=0; k<dbLogons.size(); k++) {
                                                         IReportLogon dbLogon = (IReportLogon)dbLogons.get(k);
                                                         dbLogon.setDatabaseName(dbName);
                                           }
                              } catch (Exception ex) {
                                           writeToLog("Error changing report database logons: " + ex.toString());
                              }
                }

                public void changeReportRetries(IReport myReport, int numRetries) {
                    try {
                        writeToLog("Changing retries for report ID " + myReport.getID() + " : " + myReport.getTitle());
                        myReport.getSchedulingInfo().setRetriesAllowed(numRetries);
                    } catch (Exception ex) {
                        writeToLog("Error changing report retries: " + ex.toString());
                    }
                }

                // This function assumes that the report has only been scheduled to one destination - in this case unmanaged disk
                public void changeReportUnmanagedDiskLogonCredentials(IReport myReport, IInfoStore boInfoStore, String osUsername, String osPassword) {
                    try {
                        writeToLog("Changing Unmanaged Username and Password for report ID " + myReport.getID() + " : " + myReport.getTitle());
                        ISchedulingInfo boSchedulingInfo = myReport.getSchedulingInfo();
                        IDestinations boDestinations = boSchedulingInfo.getDestinations();
                        IDestination boDestination = (IDestination)boDestinations.get(0);
                        IDestinationPlugin destinationPlugin = (IDestinationPlugin)boInfoStore.query("SELECT TOP 1 * FROM CI_SYSTEMOBJECTS WHERE SI_NAME='CrystalEnterprise.DiskUnmanaged'").get(0);
                        boDestination.copyToPlugin(destinationPlugin);
                        IDiskUnmanagedOptions diskUnmanagedOptions = (IDiskUnmanagedOptions) destinationPlugin.getScheduleOptions();
                        diskUnmanagedOptions.setUserName(osUsername);
                        diskUnmanagedOptions.setPassword(osPassword);
                        boDestination.setFromPlugin(destinationPlugin);
                    } catch (Exception ex) {
                        writeToLog("Error changing Unmanaged Disk Logon Credentials: " + ex.toString() );
                    }
                }

                public void changeScheduleStartTime(IReport myReport, java.util.Date newDate) {
                    try {
                        writeToLog("Changing schedule Start Time " + myReport.getID() + " : " + myReport.getTitle());
                        IProperties tmpProps = myReport.getSchedulingInfo().properties();
                        tmpProps.setProperty("SI_STARTTIME", newDate);
                    } catch (Exception ex) {
                        writeToLog("Error changing schedule Start Time: " + ex.toString());
                    }
                }

                public void changeScheduleEndTime(IReport myReport, java.util.Date newDate) {
                    try {
                        writeToLog("Changing schedule End Time " + myReport.getID() + " : " + myReport.getTitle());
                        IProperties tmpProps = myReport.getSchedulingInfo().properties();
                        tmpProps.setProperty("SI_ENDTIME", newDate);
                    } catch (Exception ex) {
                        writeToLog("Error changing schedule End Time: " + ex.toString());
                    }
                }
                // This function assumes that the report has only been scheduled to one destination - in this case SMTP
                public void changeScheduleFromFieldForScheduleSMTP(IReport myReport, IInfoStore boInfoStore, String newFrom) {
                    try {
                        writeToLog("Changing SMTP Schedule From value for report ID " + myReport.getID() + " : " + myReport.getTitle());
                        ISchedulingInfo boSchedulingInfo = myReport.getSchedulingInfo();
                        IDestinations boDestinations = boSchedulingInfo.getDestinations();
                        IDestination boDestination = (IDestination)boDestinations.get(0);
                        IDestinationPlugin destinationPlugin = (IDestinationPlugin)boInfoStore.query("SELECT TOP 1 * FROM CI_SYSTEMOBJECTS WHERE SI_NAME='CrystalEnterprise.Smtp'").get(0);
                        boDestination.copyToPlugin(destinationPlugin);
                        ISMTPOptions smtpOptions = (ISMTPOptions) destinationPlugin.getScheduleOptions();
                        smtpOptions.setSenderAddress(newFrom);
                        boDestination.setFromPlugin(destinationPlugin);
                    } catch (Exception ex) {
                        writeToLog("Error changing SMTP Schedule From value: " + ex.toString() );
                    }
                }

            %>
4

0 回答 0