Ejemplo n.º 1
0
        /// <summary>
        ///     Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing">
        ///     <c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.
        /// </param>
        private void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }

            if (_reportingService2006 == null)
            {
                return;
            }

            _reportingService2006.Dispose();
            _reportingService2006 = null;
        }
Ejemplo n.º 2
0
        protected override void RenderWebPart(HtmlTextWriter output)
        {
            if (!ReportViewer.CheckActivationStatus(output))
            {
                return;
            }

            ReportViewer.SetReportsLinksAndPaths(
                PropReportsPath,
                IsIntegratedMode,
                PropSRSUrl,
                UseDefaults,
                ref ReportingServicesURL,
                ref Integrated,
                ref ReportsRootFolderName);


            if (ReportingServicesURL == null || ReportingServicesURL == "")
            {
                output.Write("ReportingServicesURL has not been set.");
            }
            else
            {
                string username = "";
                string password = "";
                EPMLiveCore.ReportAuth _chrono = SPContext.Current.Site.WebApplication.GetChild <EPMLiveCore.ReportAuth>("ReportAuth");
                if (_chrono != null)
                {
                    username = _chrono.Username;
                    password = EPMLiveCore.CoreFunctions.Decrypt(_chrono.Password, "KgtH(@C*&@Dhflosdf9f#&f");
                }

                /////////////////////////////////////////////////////////////////////
                //Code Here For Integrated Mode (If integrated checked, do the code below)
                /////////////////////////////////////////////////////////////////////
                if (Integrated)
                {
                    srs2006 = new ReportingService2006();
                    srs2006.UseDefaultCredentials = true;
                    string rptWS = ReportingServicesURL + "/ReportService2006.asmx";
                    srs2006.Url = rptWS;

                    try
                    {
                        curWeb = SPContext.Current.Web;
                        web    = curWeb.Site.RootWeb;


                        SPSecurity.RunWithElevatedPrivileges(delegate()
                        {
                            using (SPSite site = new SPSite(web.Url))
                            {
                                SPWebApplication app = site.WebApplication;

                                if (password != "")
                                {
                                    srs2006.UseDefaultCredentials = false;
                                    if (username.Contains("\\"))
                                    {
                                        srs2006.Credentials = new NetworkCredential(username.Substring(username.IndexOf("\\") + 1), password, username.Substring(0, username.IndexOf("\\")));
                                    }
                                    else
                                    {
                                        srs2006.Credentials = new NetworkCredential(username, password);
                                    }
                                }
                            }
                        });

                        output.WriteLine("<script language=\"javascript\">");
                        output.WriteLine("function openWindow(report){");
                        //output.WriteLine("window.open(\"" + ReportingServicesURL + "?" + System.Web.HttpUtility.UrlEncode(web.Url + "/Report Library" + ReportsFolderName + "/") + "\" + report + \"" + "&rs:Command=Render&URL=" + HttpUtility.UrlEncode(web.ServerRelativeUrl) + "\",\"Report\",\"toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, directories=no, status=yes\");");
                        output.WriteLine("window.open(\"" + ReportingServicesURL + "?" + System.Web.HttpUtility.UrlEncode(web.Url + "/") + "\" + report + \"" + "&rs:Command=Render&URL=" + HttpUtility.UrlEncode(SPContext.Current.Web.ServerRelativeUrl) + "\",\"Report\",\"toolbar=no, menubar=no, scrollbars=yes, resizable=yes,location=no, directories=no, status=yes\");");
                        output.WriteLine("}</script>");

                        if (tvReportView != null)
                        {
                            SPDocumentLibrary doc;

                            try
                            {
                                doc = (SPDocumentLibrary)web.Lists["Report Library"];
                            }
                            catch
                            {
                                throw new Exception("Document Library 'Report Library' does not exist.");
                            }

                            // Get the appropriate EPMLive folder
                            SPFolder reportFolder  = doc.RootFolder;
                            string   rootFolderURL = "Report Library" + this.ReportsFolderName;

                            foreach (SPListItem itemFolder in doc.Folders)
                            {
                                if (itemFolder.Url.ToLower() == rootFolderURL.ToLower())
                                {
                                    reportFolder = itemFolder.Folder;
                                    break;
                                }
                            }

                            if (reportFolder == doc.RootFolder)
                            {
                                throw new Exception("Folder '" + ReportsFolderName + "' does not exist.");
                            }

                            SPListItemCollection folderItems = doc.GetItemsInFolder(doc.DefaultView, reportFolder);

                            TreeNode tnTree = loadTree(folderItems, doc);
                            if (tnTree != null)
                            {
                                int iChildNodeCount = tnTree.ChildNodes.Count;
                                for (int i = 0; i < iChildNodeCount; i++)
                                {
                                    //It looks like we're adding the same node, but we're not
                                    //Each time you add a node, it removes it from tnTree
                                    tvReportView.Nodes.Add(tnTree.ChildNodes[0]);
                                }
                                tvReportView.DataBind();
                            }

                            tvReportView.RenderControl(output);
                        }
                    }
                    catch (Exception ex)
                    {
                        output.Write(ex.Message + ex.StackTrace);
                    }
                }
                else
                {
                    ///SSRS Output
                    try
                    {
                        web     = SPContext.Current.Web;
                        srs2005 = new ReportingService2005();
                        srs2005.UseDefaultCredentials = true;
                        string rptWS = ReportingServicesURL + "/ReportService2005.asmx";
                        srs2005.Url = rptWS;

                        SPSecurity.RunWithElevatedPrivileges(delegate()
                        {
                            using (SPSite site = new SPSite(web.Url))
                            {
                                SPWebApplication app = site.WebApplication;

                                if (password != "")
                                {
                                    srs2005.UseDefaultCredentials = false;
                                    if (username.Contains("\\"))
                                    {
                                        srs2005.Credentials = new NetworkCredential(username.Substring(username.IndexOf("\\") + 1), password, username.Substring(0, username.IndexOf("\\")));
                                    }
                                    else
                                    {
                                        srs2005.Credentials = new NetworkCredential(username, password);
                                    }
                                }
                            }
                        });

                        SSRS2005.CatalogItem[] items;
                        // Retrieve a list of all items from the report server database.
                        try
                        {
                            items = srs2005.ListChildren(ReportsFolderName, true);
                            BuildTree(items);
                            output.Write(sbRptList.ToString());
                        }
                        catch (SoapException e)
                        {
                            output.Write("Soap Error: " + e.Detail.OuterXml);
                        }
                    }
                    catch
                    {
                        output.Write("Error connecting to Report Server");
                    }
                }
                //////////
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(SPContext.Current.Web.Url))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        string customUrl = "";
                        string url       = "";
                        bool integrated  = false;

                        string ssrsUrl = CoreFunctions.getWebAppSetting(web.Site.WebApplication.Id, "ReportingServicesURL");
                        bool.TryParse(CoreFunctions.getWebAppSetting(site.WebApplication.Id, "ReportsUseIntegrated"), out integrated);
                        string username = "";
                        string password = "";

                        ReportAuth _chrono = site.WebApplication.GetChild <ReportAuth>("ReportAuth");
                        if (_chrono != null)
                        {
                            username = _chrono.Username;
                            password = CoreFunctions.Decrypt(_chrono.Password, "KgtH(@C*&@Dhflosdf9f#&f");
                        }
                        Guid lGuid = CoreFunctions.getLockedWeb(web);
                        if (lGuid != web.ID)
                        {
                            using (SPWeb lWeb = site.OpenWeb(lGuid))
                            {
                                customUrl = CoreFunctions.getConfigSetting(lWeb, "ResToolsReportURL");
                            }
                        }
                        else
                        {
                            customUrl = CoreFunctions.getConfigSetting(web, "ResToolsReportURL");
                        }


                        if (ssrsUrl != "")
                        {
                            try
                            {
                                if (integrated)
                                {
                                    srs2006 = new ReportingService2006();
                                    srs2006.UseDefaultCredentials = true;
                                    string rptWS = ssrsUrl + "/ReportService2006.asmx";
                                    srs2006.Url  = rptWS;
                                    if (username != "")
                                    {
                                        srs2006.UseDefaultCredentials = false;
                                        if (username.Contains("\\"))
                                        {
                                            srs2006.Credentials = new NetworkCredential(username.Substring(username.IndexOf("\\") + 1), password, username.Substring(0, username.IndexOf("\\")));
                                        }
                                        else
                                        {
                                            srs2006.Credentials = new NetworkCredential(username, password);
                                        }
                                    }

                                    if (customUrl == "")
                                    {
                                        customUrl = "/Report Library/Resource Work vs. Capacity.rdl";
                                    }
                                    string sparams = RS(site.RootWeb.Url + customUrl, web);

                                    url = ((web.ServerRelativeUrl == "/") ? "" : web.ServerRelativeUrl) + "/_layouts/ReportServer/RSViewerPage.aspx?rv:RelativeReportUrl=" + ((site.RootWeb.ServerRelativeUrl == "/") ? "" : site.RootWeb.ServerRelativeUrl) + customUrl + sparams;
                                }
                                else
                                {
                                    srs2005 = new ReportingService2005();
                                    srs2005.UseDefaultCredentials = true;
                                    string rptWS = ssrsUrl + "/ReportService2005.asmx";
                                    srs2005.Url  = rptWS;
                                    if (username != "")
                                    {
                                        srs2005.UseDefaultCredentials = false;
                                        if (username.Contains("\\"))
                                        {
                                            srs2005.Credentials = new NetworkCredential(username.Substring(username.IndexOf("\\") + 1), password, username.Substring(0, username.IndexOf("\\")));
                                        }
                                        else
                                        {
                                            srs2005.Credentials = new NetworkCredential(username, password);
                                        }
                                    }

                                    if (customUrl == "")
                                    {
                                        customUrl = "/Resource Work vs. Capacity";
                                    }
                                    string sparams = RSNOIM(customUrl, web);

                                    url = ssrsUrl + "?" + customUrl + sparams;
                                }
                                Response.Redirect(url);
                            }
                            catch (Exception ex)
                            {
                                lblError.Text = "Error: " + ex.Message;
                            }
                        }
                        else
                        {
                            lblError.Text = "Reporting Services URL not set";
                        }
                    }
                }
            });
        }
Ejemplo n.º 4
0
        protected override void RenderWebPart(HtmlTextWriter output)
        {
            if (!CheckActivationStatus(output))
            {
                return;
            }

            SetReportsLinksAndPaths(
                PropReportsPath,
                IsIntegratedMode,
                PropSRSUrl,
                UseDefaults,
                ref ReportingServicesURL,
                ref Integrated,
                ref ReportsRootFolderName);

            if (ReportingServicesURL == null || ReportingServicesURL == "")
            {
                output.Write("ReportingServicesURL has not been set.");
            }
            else
            {
                string username = "";
                string password = "";
                EPMLiveCore.ReportAuth _chrono = SPContext.Current.Site.WebApplication.GetChild <EPMLiveCore.ReportAuth>("ReportAuth");
                if (_chrono != null)
                {
                    username = _chrono.Username;
                    password = EPMLiveCore.CoreFunctions.Decrypt(_chrono.Password, "KgtH(@C*&@Dhflosdf9f#&f");
                }

                srs2005 = new ReportingService2005();
                srs2005.UseDefaultCredentials = true;
                string rptWS = ReportingServicesURL + "/ReportService2005.asmx";
                srs2005.Url = rptWS;

                /////////////////////////////////////////////////////////////////////
                //Code Here For Integrated Mode (If integrated checked, do the code below)
                /////////////////////////////////////////////////////////////////////
                if (Integrated)
                {
                    srs2006 = new ReportingService2006();
                    srs2006.UseDefaultCredentials = true;
                    rptWS       = ReportingServicesURL + "/ReportService2006.asmx";
                    srs2006.Url = rptWS;
                    try
                    {
                        curWeb = SPContext.Current.Web;
                        web    = curWeb.Site.RootWeb;

                        SPSecurity.RunWithElevatedPrivileges(delegate()
                        {
                            using (SPSite site = new SPSite(web.Url))
                            {
                                SPWebApplication app = site.WebApplication;
                                if (username != "")
                                {
                                    srs2006.UseDefaultCredentials = false;
                                    if (username.Contains("\\"))
                                    {
                                        srs2006.Credentials = new NetworkCredential(username.Substring(username.IndexOf("\\") + 1), password, username.Substring(0, username.IndexOf("\\")));
                                    }
                                    else
                                    {
                                        srs2006.Credentials = new NetworkCredential(username, password);
                                    }
                                }
                            }
                        });

                        if (tvReportView != null)
                        {
                            SPDocumentLibrary doc;

                            try
                            {
                                doc = (SPDocumentLibrary)web.Lists["Report Library"];
                            }
                            catch
                            {
                                throw new Exception("Document Library 'Report Library' does not exist.");
                            }

                            // Get the appropriate EPMLive folder
                            SPFolder reportFolder  = doc.RootFolder;
                            string   rootFolderURL = "Report Library" + this.ReportsFolderName;

                            foreach (SPListItem itemFolder in doc.Folders)
                            {
                                if (itemFolder.Url.ToLower() == rootFolderURL.ToLower())
                                {
                                    reportFolder = itemFolder.Folder;
                                    break;
                                }
                            }

                            if (reportFolder == doc.RootFolder)
                            {
                                throw new Exception("Folder '" + ReportsFolderName + "' does not exist.");
                            }

                            SPListItemCollection folderItems = doc.GetItemsInFolder(doc.DefaultView, reportFolder);

                            output.WriteLine("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" height=\"100%\" ><tr><td id=\"coltohide\" style=\"vertical-align:top\" width=\"250\" height=\"100%\"><img src=\"/_layouts/images/blank.gif\" height=\"1\" width=\"250\">");

                            TreeNode tnTree = loadTree(folderItems, doc);
                            if (tnTree != null)
                            {
                                int iChildNodeCount = tnTree.ChildNodes.Count;
                                for (int i = 0; i < iChildNodeCount; i++)
                                {
                                    //It looks like we're adding the same node, but we're not
                                    //Each time you add a node, it removes it from tnTree
                                    tvReportView.Nodes.Add(tnTree.ChildNodes[0]);
                                }
                                tvReportView.DataBind();
                            }
                            tvReportView.RenderControl(output);
                            output.WriteLine("</td><td bgcolor=\"#D9D9D9\" onMouseOver=\"this.bgColor='#BBC4D9'\" onMouseOut=\"this.bgColor='#D9D9D9'\" width=\"10px\" height=\"100%\" onclick=\"show_hide_column1();\" align=\"center\">");
                            output.WriteLine("<img src=\"/_layouts/images/blank.gif\" height=\"1\" width=\"12\"><img src=\"/_layouts/epmlive/images/arrow.gif\" alt=\"\">");
                        }
                    }
                    catch (Exception ex)
                    {
                        output.Write(ex.Message);
                    }
                }
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                else
                {
                    ///SSRS Output
                    try
                    {
                        web = SPContext.Current.Web;

                        SPSecurity.RunWithElevatedPrivileges(delegate()
                        {
                            using (SPSite site = new SPSite(web.Url))
                            {
                                SPWebApplication app = site.WebApplication;

                                if (username != "")
                                {
                                    srs2005.UseDefaultCredentials = false;
                                    if (username.Contains("\\"))
                                    {
                                        srs2005.Credentials = new NetworkCredential(username.Substring(username.IndexOf("\\") + 1), password, username.Substring(0, username.IndexOf("\\")));
                                    }
                                    else
                                    {
                                        srs2005.Credentials = new NetworkCredential(username, password);
                                    }
                                }
                            }
                        });


                        SSRS2005.CatalogItem[] items;
                        //CatalogItem[] items;

                        // Retrieve a list of all items from the report server database.
                        try
                        {
                            items = srs2005.ListChildren(ReportsFolderName, true);
                            //items = srs2005.ListChildren(ReportsFolderName);
                            BuildTree(items);
                            output.Write(sbRptList.ToString());
                        }
                        catch (SoapException e)
                        {
                            output.Write("Soap Error: " + e.Detail.OuterXml);
                        }
                    }
                    catch
                    {
                        output.Write("Error connecting to Report Server");
                    }
                }

                output.WriteLine("</td><td width=\"100%\" height=\"100%\">");
                output.WriteLine("<iframe  id=\"Frameviewer\"  frameborder=\"0\"  vspace=\"0\"  hspace=\"0\"  marginwidth=\"0\" src=\"\"  marginheight=\"0\"");
                output.WriteLine("width=\"100%\"  scrolling=\"yes\"  height=\"100%\">");
                output.WriteLine("</iframe>");
                output.WriteLine("</td></tr></table>");
                output.WriteLine("<script>");
                //output.WriteLine("function show_hide_column1(td) {");
                //output.WriteLine("if(td.previousSibling.style.display==\"none\"){td.previousSibling.style.display = \"\";}");
                //output.WriteLine("else{td.previousSibling.style.display = \"none\";}}");
                output.WriteLine("function show_hide_column1() {");
                output.WriteLine("if(document.getElementById('coltohide').style.display==\"none\"){document.getElementById('coltohide').style.display=\"\";}");
                output.WriteLine("else{document.getElementById('coltohide').style.display=\"none\";}}");
                output.WriteLine("</script>");
                output.WriteLine("<script language=\"javascript\">");
                output.WriteLine("function frameview(link){");
                output.WriteLine("document.getElementById('Frameviewer').src=link;");
                output.WriteLine("document.getElementById('coltohide').style.display=\"none\";");
                output.WriteLine("}");
                output.WriteLine("</script>");
            }
        }
        private bool SetupSSRS(string webUrl)
        {
            if (_reportingServicesUrl.StartsWith("/"))
            {
                _reportingServicesUrl = webUrl + _reportingServicesUrl;
            }


            var valid = false;

            try
            {
                _srs2006 = new ReportingService2006 {
                    UseDefaultCredentials = true
                };
                var username = "";
                var password = "";
                var chrono   = SPContext.Current.Site.WebApplication.GetChild <ReportAuth>("ReportAuth");
                if (chrono != null)
                {
                    username = chrono.Username;
                    password = CoreFunctions.Decrypt(chrono.Password, "KgtH(@C*&@Dhflosdf9f#&f");
                }

                if (!bool.Parse(EPMLiveCore.CoreFunctions.getWebAppSetting(SPContext.Current.Site.WebApplication.Id, "ReportsUseIntegrated")))
                {
                    return(valid);
                }


                _srs2006 = new ReportingService2006 {
                    UseDefaultCredentials = true
                };
                var rptWs = _reportingServicesUrl + "/ReportService2006.asmx";
                _srs2006.Url = rptWs;

                SPSecurity.RunWithElevatedPrivileges(delegate
                {
                    if (password == "")
                    {
                        return;
                    }
                    _srs2006.UseDefaultCredentials = false;
                    if (username.Contains("\\"))
                    {
                        _srs2006.Credentials = new NetworkCredential(username.Substring(username.IndexOf("\\") + 1),
                                                                     password, username.Substring(0, username.IndexOf("\\")));
                    }
                    else
                    {
                        _srs2006.Credentials = new NetworkCredential(username, password);
                    }
                });

                try
                {
                    var authCookie = HttpContext.Current.Request.Cookies["FedAuth"];
                    var fedAuth    = new Cookie(authCookie.Name, authCookie.Value, authCookie.Path, string.IsNullOrEmpty(authCookie.Domain) ? HttpContext.Current.Request.Url.Host : authCookie.Domain);
                    _srs2006.CookieContainer = new CookieContainer();
                    _srs2006.CookieContainer.Add(fedAuth);
                }
                catch { }

                valid = true;
            }
            catch { }

            return(valid);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Configures the reporting service.
        /// </summary>
        private void ConfigureReportingService()
        {
            Guid webAppId = Web.Site.WebApplication.Id;

            bool   ssrsIntegrated      = bool.Parse(CoreFunctions.getWebAppSetting(webAppId, "ReportsUseIntegrated"));
            string reportingServiceUrl = CoreFunctions.getWebAppSetting(webAppId, "ReportingServicesURL");

            if (!ssrsIntegrated)
            {
                throw new APIException((int)Errors.GetAllReportsNotIntegrated,
                                       "Reporting API only supports Integrated SSRS setup.");
            }

            if (string.IsNullOrEmpty(reportingServiceUrl))
            {
                throw new APIException((int)Errors.GetAllReportsNoRSUrl, "ReportingServicesURL has not been set.");
            }

            string reportingServiceUsername = string.Empty;
            string reportingServicePassword = string.Empty;

            var reportAuth = Web.Site.WebApplication.GetChild <ReportAuth>("ReportAuth");

            if (reportAuth != null)
            {
                reportingServiceUsername = reportAuth.Username;
                reportingServicePassword = CoreFunctions.Decrypt(reportAuth.Password, "KgtH(@C*&@Dhflosdf9f#&f");
            }

            try
            {
                _reportingService2006 = new ReportingService2006
                {
                    UseDefaultCredentials = true,
                    Url = string.Format("{0}/ReportService2006.asmx", reportingServiceUrl)
                };

                try
                {
                    HttpCookie authCookie = HttpContext.Current.Request.Cookies["FedAuth"];
                    var        fedAuth    = new Cookie(authCookie.Name, authCookie.Value, authCookie.Path,
                                                       string.IsNullOrEmpty(authCookie.Domain)
                            ? HttpContext.Current.Request.Url.Host
                            : authCookie.Domain);
                    _reportingService2006.CookieContainer = new CookieContainer();
                    _reportingService2006.CookieContainer.Add(fedAuth);
                }
                catch { }
            }
            catch (Exception)
            {
                throw new Exception("Cannot connect to the reporting service.");
            }

            if (string.IsNullOrEmpty(reportingServicePassword))
            {
                return;
            }

            _reportingService2006.UseDefaultCredentials = false;

            if (reportingServiceUsername.Contains("\\"))
            {
                int index = reportingServiceUsername.IndexOf("\\", StringComparison.Ordinal);

                _reportingService2006.Credentials = new NetworkCredential(reportingServiceUsername.Substring(index + 1),
                                                                          reportingServicePassword,
                                                                          reportingServiceUsername.Substring(0, index));
            }
            else
            {
                _reportingService2006.Credentials = new NetworkCredential(reportingServiceUsername,
                                                                          reportingServicePassword);
            }
        }