using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using ReportViewer.CRM; using Microsoft.Reporting.WebForms; using System.Web.Services.Protocols; using System.IO; //using Microsoft.Crm.Sdk; //using System.Web.Services.Protocols; namespace ReportViewer { public partial class ShowReportForCurrentUser : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { StreamWriter w = null; try { FileInfo f = new FileInfo(@"c:\temp\reportViewer.txt"); w = f.AppendText(); //FileInfo f = new FileInfo(@"c:\temp\reportViewer.txt"); //w = f.AppendText(); //w.WriteLine("start RandDNumerator Plugin"); //if (IsPostBack) return; //ReportViewer1.Reset(); if (!IsPostBack) { w.WriteLine("1"); //Guid userid = new Guid("49172524-59cf-dd11-b0c9-0003ff691beb"); string errMsg; CrmService crmService = new CrmService(); CrmAuthenticationToken token = new CrmAuthenticationToken(); token.AuthenticationType = 0; token.OrganizationName = Properties.Settings.Default.CrmOrganization; #if DEBUG string userName = Properties.Settings.Default.UserName; string domainName = Properties.Settings.Default.Domain; string password = Properties.Settings.Default.Password; crmService.Credentials = new System.Net.NetworkCredential(userName, password, domainName); //crmService.Credentials = new System.Net.NetworkCredential("yurig", "181078", "sitqad"); #else crmService.Credentials = System.Net.CredentialCache.DefaultCredentials; #endif crmService.CrmAuthenticationTokenValue = token; try { // Retrieve logged in user details WhoAmIRequest userRequest = new WhoAmIRequest(); w.WriteLine("2"); WhoAmIResponse user = (WhoAmIResponse)crmService.Execute(userRequest); w.WriteLine("3"); // Retrieve Report id ColumnSet cols = new ColumnSet(); cols.Attributes = new string[] { "new_dashboardreport" }; systemuser sysUser = (systemuser)crmService.Retrieve(EntityName.systemuser.ToString(), user.UserId, cols); //systemuser sysUser = (systemuser)crmService.Retrieve(EntityName.systemuser.ToString(), userid, cols); w.WriteLine("4"); w.WriteLine("user.UserId : " + user.UserId.ToString()); if (sysUser.new_dashboardreport == null) { w.WriteLine("5"); w.WriteLine("sysUser.new_dashboardreport == null"); } else { w.WriteLine("sysUser.new_dashboardreport NOT null"); } if (sysUser.new_dashboardreport != null) { w.WriteLine("6"); ReportViewer1.ProcessingMode = ProcessingMode.Remote; ReportViewer1.ShowCredentialPrompts = true; ReportViewer1.ShowExportControls = true; w.WriteLine("7"); #if DEBUG //userName = Properties.Settings.Default.UserName; //domainName = Properties.Settings.Default.Domain; //password = Properties.Settings.Default.Password; //crmService.Credentials = new System.Net.NetworkCredential(userName, password, domainName); //ReportViewer1.ServerReport.ReportServerCredentials = new ReportServerNetworkCredentials(crmService.Credentials); ReportViewer1.ServerReport.ReportServerCredentials = new ReportServerNetworkCredentials(); #else ReportViewer1.ServerReport.ReportServerCredentials = new ReportServerNetworkCredentials(); #endif w.WriteLine("10"); ReportViewer1.ServerReport.ReportServerUrl = new Uri(Properties.Settings.Default.ReportServerUrl); ReportViewer1.ServerReport.ReportPath = Properties.Settings.Default.ReportServerPath + sysUser.new_dashboardreport.name; //ReportViewer1.ServerReport.ReportPath = Properties.Settings.Default.ReportServerPath + "CSR Summary"; ReportViewer1.ServerReport.Refresh(); w.WriteLine("11 - END"); } } catch (SoapException ex) { errMsg = ex.Message + ex.Detail.InnerText; } catch (Exception ex) { errMsg = ex.Message; } } } catch (SoapException ex) { FileInfo f = new FileInfo(@"c:\temp\ExceptionReportViewer1.txt"); StreamWriter sw = f.AppendText(); sw.WriteLine("SoapException: " + ex.Detail.InnerText + " " + ex.TargetSite.ToString()); sw.Close(); throw new Exception("An SoapException occurred in the RandDNumerator plug-in." + ex.Detail.InnerText, ex); } catch (Exception ex) { FileInfo f = new FileInfo(@"c:\temp\ExceptionReportViewer1.txt"); StreamWriter sw = f.AppendText(); sw.WriteLine("Exception: " + ex.Message + " " + ex.Source); sw.Close(); throw new Exception("An general Exception occurred in the RandDNumerator plug-in." + ex.Message, ex); } finally { if (w != null) { w.WriteLine("Finally"); w.Close(); } } } } }