Example #1
0
        protected void AddorUpdateConnString()
        {
            try
            {
                if (ConnectionTest(txtConnString.Text))
                {
                    //string sVal = DropDownList1.SelectedItem.Value;
                    //SPWebApplication webApp = SPWebService.ContentService.WebApplications[new Guid(DropDownList1.SelectedValue)];
                    SPWebApplication webApp = WebApplicationSelector1.CurrentItem;

                    string sError = "";

                    CoreFunctions.setConnectionString(webApp.Id, txtConnString.Text, out sError);

                    if (sError != "")
                    {
                        lblStatusDyn.Text      = "Error: " + sError;
                        lblStatusDyn.BackColor = System.Drawing.Color.Red;
                    }
                    else
                    {
                        lblStatusDyn.Text      = "Connection test successful & connection string updated. ";
                        lblStatusDyn.BackColor = System.Drawing.Color.LightGreen;
                    }



                    CoreFunctions.setWebAppSetting(new Guid(WebApplicationSelector1.CurrentId), "ReportingServicesURL", txtReportServer.Text);
                    CoreFunctions.setWebAppSetting(new Guid(WebApplicationSelector1.CurrentId), "ReportsRootFolder", txtDefaultPath.Text);
                    CoreFunctions.setWebAppSetting(new Guid(WebApplicationSelector1.CurrentId), "ReportsUseIntegrated", chkIntegrated.Checked.ToString());
                    CoreFunctions.setWebAppSetting(new Guid(WebApplicationSelector1.CurrentId), "ReportsWindowsAuthentication", chkWindowsAuth.Checked.ToString());

                    if (txtPassword.Text != "" || txtUsername.Text == "")
                    {
                        ReportAuth _chrono = webApp.GetChild <ReportAuth>("ReportAuth");
                        if (_chrono == null)
                        {
                            _chrono = new ReportAuth("ReportAuth", webApp, Guid.NewGuid());
                            _chrono.Update();
                            //webApp.Update();
                        }
                        _chrono.Username = txtUsername.Text;
                        _chrono.Password = CoreFunctions.Encrypt(txtPassword.Text, "KgtH(@C*&@Dhflosdf9f#&f");
                        _chrono.Update();
                        //webApp.Update();
                    }
                }
                else
                {
                    lblStatusDyn.Text      = "Connection test unsuccessful. Invalid connection string.";
                    lblStatusDyn.BackColor = System.Drawing.Color.Red;
                }
            }
            catch (Exception exception)
            {
                lblStatusDyn.Text      = "Error: " + exception.Message;
                lblStatusDyn.BackColor = System.Drawing.Color.Red;
            }
        }
        private void processReports(SPWeb web)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                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");
                }

                bool reportingIntegratedMode = true;
                bool.TryParse(EPMLiveCore.CoreFunctions.getWebAppSetting(SPContext.Current.Site.WebApplication.Id, "ReportsUseIntegrated"), out reportingIntegratedMode);

                if (!reportingIntegratedMode)
                {
                    Guid fieldsFeature = new Guid("acdb86be-bfa5-41c7-91a8-7682d7edffa5");
                    if (web.Features[fieldsFeature] == null)
                    {
                        web.Features.Add(fieldsFeature);
                    }

                    Guid receiversFeature = new Guid("a8ebe311-83e1-48a4-ab31-50f237398f44");

                    if (web.Features[receiversFeature] == null)
                    {
                        web.Features.Add(receiversFeature);
                    }

                    string dataSourceString = String.Format(@"<?xml version=""1.0"" encoding=""utf-8""?>
                    <DataSourceDefinition xmlns=""http://schemas.microsoft.com/sqlserver/reporting/2006/03/reportdatasource"">
                      <Extension>SQL</Extension>
                      <ConnectString>Data Source={0};Initial Catalog={1};</ConnectString>
                      <CredentialRetrieval>Store</CredentialRetrieval>
                      <WindowsCredentials>{2}</WindowsCredentials>
                      <ImpersonateUser>False</ImpersonateUser>
                      <Enabled>True</Enabled>
                    </DataSourceDefinition>", txtReportServer.Text, txtReportDatabase.Text, chkWindows.Checked);

                    SPDocumentLibrary doclib = web.Lists["Report Library"] as SPDocumentLibrary;
                    web.AllowUnsafeUpdates   = true;
                    SPFile file = doclib.RootFolder.Files.Add(doclib.RootFolder.Url + "/Data Sources/EPMLiveReportDB.rsds", Encoding.ASCII.GetBytes(dataSourceString), new Hashtable {
                        { "Datasource Credentials", String.Format("{0}:{1}", txtReportUsername.Text, hdnReportPassword.Value == "" ? hdnSaveReportPassword.Value : hdnReportPassword.Value) }
                    }, true);

                    web.AllowUnsafeUpdates = false;
                }
                else
                {
                    SSRS2006.ReportingService2006 SSRS = new SSRS2006.ReportingService2006();
                    SSRS.Url = ssrsurl + "/ReportService2006.asmx";
                    SSRS.UseDefaultCredentials = true;


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


                    /*System.Web.HttpCookie tCookie = System.Web.HttpContext.Current.Response.Cookies["WSS_KeepSessionAuthenticated"];
                     *
                     * System.Net.Cookie oC = new System.Net.Cookie();
                     *
                     * // Convert between the System.Net.Cookie to a System.Web.HttpCookie...
                     * oC.Domain = System.Web.HttpContext.Current.Request.Url.Host;
                     * oC.Expires = tCookie.Expires;
                     * oC.Name = tCookie.Name;
                     * oC.Path = tCookie.Path;
                     * oC.Secure = tCookie.Secure;
                     * oC.Value = tCookie.Value;
                     *
                     * SSRS.CookieContainer = new System.Net.CookieContainer();
                     *
                     * SSRS.CookieContainer.Add(oC);
                     */

                    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);
                        SSRS.CookieContainer = new CookieContainer();
                        SSRS.CookieContainer.Add(fedAuth);
                    }
                    catch { }

                    SPDocumentLibrary list = (SPDocumentLibrary)web.Lists["Report Library"];

                    SPListItemCollection folders = list.GetItemsInFolder(list.DefaultView, list.RootFolder);

                    try
                    {
                        foreach (SPListItem li in folders)
                        {
                            if (li.FileSystemObjectType == SPFileSystemObjectType.Folder && li.Name == "Data Sources")
                            {
                                SSRS2006.DataSourceDefinition dsd = new SSRS2006.DataSourceDefinition();
                                dsd.ConnectString       = "Data Source=" + txtReportServer.Text + ";Initial Catalog=" + txtReportDatabase.Text + ";";
                                dsd.CredentialRetrieval = SSRS2006.CredentialRetrievalEnum.Store;
                                dsd.UserName            = txtReportUsername.Text;
                                if (hdnReportPassword.Value == "")
                                {
                                    dsd.Password = hdnSaveReportPassword.Value;
                                }
                                else
                                {
                                    dsd.Password = hdnReportPassword.Value;
                                }

                                if (chkWindows.Checked)
                                {
                                    dsd.WindowsCredentials = chkWindows.Checked;
                                }

                                dsd.Enabled   = true;
                                dsd.Extension = "SQL";

                                SSRS.CreateDataSource("EPMLiveReportDB.rsds", web.Url + "/" + li.Url, true, dsd, null);
                            }
                        }

                        SSRS2006.DataSourceReference dsr = new SSRS2006.DataSourceReference();
                        dsr.Reference = web.Url + "/Report Library/Data Sources/EPMLiveReportDB.rsds";

                        foreach (SPListItem li in folders)
                        {
                            processRDL(SSRS, web, li, dsr, list);
                        }
                    }
                    catch
                    {
                        pnlMessage.Visible = true;
                    }
                }
            });
        }
Example #3
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>");
            }
        }
Example #4
0
        protected void GetConnSettings()
        {
            try
            {
                txtConnString.Text = "";
                SPWebApplication webApp = WebApplicationSelector1.CurrentItem;
                webappid = webApp.Id.ToString();
                string sConn = CoreFunctions.getConnectionString(webApp.Id);

                if (!string.IsNullOrWhiteSpace(sConn))
                {
                    txtConnString.Text = sConn;
                    lblStatusDyn.Text  = "Active";

                    SPSecurity.RunWithElevatedPrivileges(delegate()
                    {
                        try
                        {
                            var curVersion = "";
                            using (var cn = new SqlConnection(sConn))
                            {
                                cn.Open();
                                using (var cmd = new SqlCommand("SELECT TOP 1 VERSION FROM VERSIONS order by dtInstalled DESC", cn))
                                {
                                    using (var dr = cmd.ExecuteReader())
                                    {
                                        if (dr.Read())
                                        {
                                            curVersion = dr.GetString(0);
                                        }
                                    }
                                }
                            }

                            lblVersion.Text = curVersion;
                            if (curVersion != CoreFunctions.GetFullAssemblyVersion())
                            {
                                btnUpgrade.Visible   = true;
                                lblVersion.BackColor = Color.Red;
                            }
                        }
                        catch (Exception ex)
                        {
                            lblStatusDyn.Text = "Error: " + ex.Message;
                        }
                    });
                }
                else
                {
                    lblStatusDyn.Text    = "No connection string configured.";
                    con1.Visible         = false;
                    con3.Visible         = false;
                    btnInstallDB.Visible = true;
                }

                ReportAuth _chrono = webApp.GetChild <ReportAuth>("ReportAuth");
                if (_chrono != null)
                {
                    txtUsername.Text = _chrono.Username;
                }

                if (SPFarm.Local.Solutions[new Guid("55aca119-d7c7-494a-b5a7-c3ade07d06eb")].DeployedWebApplications.Contains(webApp))
                {
                    sCoreStatus = "Deployed";
                }
                else
                {
                    sCoreStatus = "Not Deployed";
                }

                if (SPFarm.Local.Solutions[new Guid("98e5c373-e1a0-45ce-8124-30c203cd8003")].DeployedWebApplications.Contains(webApp))
                {
                    sWPStatus = "Deployed";
                }
                else
                {
                    sWPStatus = "Not Deployed";
                }

                if (SPFarm.Local.Solutions[new Guid("1858d521-0375-4a61-9281-f5210854bc12")].DeployedWebApplications.Contains(webApp))
                {
                    sTSStatus = "Deployed";
                }
                else
                {
                    sTSStatus = "Not Deployed";
                }

                if (SPFarm.Local.Solutions[new Guid("8f916fa9-1c2d-4416-8036-4a272256e23d")].DeployedWebApplications.Contains(webApp))
                {
                    sDashboardStatus = "Deployed";
                }
                else
                {
                    sDashboardStatus = "Not Deployed";
                }

                if (SPFarm.Local.Solutions[new Guid("5a3fe24c-2dc5-4a1c-aec1-6ce942825ceb")].DeployedWebApplications.Contains(webApp))
                {
                    sPFEStatus = "Deployed";
                }
                else
                {
                    sPFEStatus = "Not Deployed";
                }
            }
            catch (Exception exception)
            {
                lblStatusDyn.Text      = "Error: " + exception.Message;
                lblStatusDyn.BackColor = System.Drawing.Color.Red;
            }


            try
            {
                txtReportServer.Text   = CoreFunctions.getWebAppSetting(new Guid(WebApplicationSelector1.CurrentId), "ReportingServicesURL");
                txtDefaultPath.Text    = CoreFunctions.getWebAppSetting(new Guid(WebApplicationSelector1.CurrentId), "ReportsRootFolder");
                chkIntegrated.Checked  = bool.Parse(CoreFunctions.getWebAppSetting(new Guid(WebApplicationSelector1.CurrentId), "ReportsUseIntegrated"));
                chkWindowsAuth.Checked = bool.Parse(CoreFunctions.getWebAppSetting(new Guid(WebApplicationSelector1.CurrentId), "ReportsWindowsAuthentication"));
            }
            catch { }
        }