public void DataSourceExportSuccessEventHandler(SSRSExport sender, DataSourceExportSuccessEvent e)
        {
            string sPath = e.GetPath();

            mExportedDataSources.Add(e.GetSSRSPath());

            if (mDebug)
            {
                string sMsg = string.Format("Exported data source to '{0}'. Data={1}", sPath, e.GetDataSourceText());
                oDebugForm.LogMessage(sMsg);
            }
        }
Beispiel #2
0
        public void ExportDataSources()
        {
            string SSRSPath = this.mSSRSPath;
            string ExportPath = this.mExportPath;
            List<string> DataSourcesExportedList = new List<string>();

            if (string.IsNullOrEmpty(SSRSPath))
                throw new ArgumentNullException("Please provide a valid SSRS path for the parent folder.");

            if (string.IsNullOrEmpty(ExportPath))
                throw new ArgumentNullException("Please provide a valid export path.");

            try
            {
                if (this.mDefaultCredentials == true)
                    mReportingService.Credentials = CredentialCache.DefaultCredentials;
                else
                    mReportingService.Credentials = new NetworkCredential(this.mUsername, this.mPassword, this.mDomain);

                CatalogItem[] oItems = mReportingService.ListChildren(SSRSPath, this.mRecursiveList);

                foreach (CatalogItem oItem in oItems)
                {
                    string sItemType = oItem.TypeName;

                    try
                    {
                        if (sItemType == "DataSource")
                        {
                            string sDataSourceExportPath = string.Format("{0}{1}.json", ExportPath, oItem.Path.Replace('/', '\\'));

                            // Call DataSourceFoundEventHandler
                            DataSourceFoundEvent oDataSourceFoundEvent = new DataSourceFoundEvent();
                            oDataSourceFoundEvent.SetSSRSPath(oItem.Path);
                            DataSourceFound(this, oDataSourceFoundEvent);

                            string output = GetDataSource(oItem.Path);
                            SaveDataSource(sDataSourceExportPath, output, true);

                            // Call DataSourceExportSuccessEventHandler
                            DataSourceExportSuccessEvent oDataSourceSuccessEvent = new DataSourceExportSuccessEvent();
                            oDataSourceSuccessEvent.SetDataSourceText(output);
                            oDataSourceSuccessEvent.SetPath(sDataSourceExportPath);
                            oDataSourceSuccessEvent.SetSSRSPath(oItem.Path);
                            DataSourceExportedSuccess(this, oDataSourceSuccessEvent);
                        }
                    }
                    catch (Exception er)
                    {
                        DataSourceExportFailEvent oDataSourceFailEvent = new DataSourceExportFailEvent();
                        oDataSourceFailEvent.SetException(er);
                        oDataSourceFailEvent.SetErrorMessage(er.Message);
                        oDataSourceFailEvent.SetSSRSPath(oItem.Path);
                        oDataSourceFailEvent.SetExportedPath(ExportPath);

                        DataSourceExportFail(this, oDataSourceFailEvent);
                    }
                }
            }
            catch (Exception er)
            {
                throw new Exception(string.Format("Failed to export data sources: {0}", er.Message));
            }
        }