Ejemplo n.º 1
0
        // GET: api/ReportGenerate
        public IEnumerable<Report> Get()
        {
            string reportServiceUser = CloudConfigurationManager.GetSetting("reportServiceUser");
            string reportServicePassword = CloudConfigurationManager.GetSetting("reportServicePassword");
            ClientSection clientSec = System.Configuration.ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;
            ChannelEndpointElementCollection endpointCollection = clientSec.Endpoints;
            endpointNames = new List<string>();
            foreach (ChannelEndpointElement endpointElement in endpointCollection)
            {
                if (String.Compare(endpointElement.Contract, "ReportingService.ReportingService2010Soap", true) == 0)
                    endpointNames.Add(endpointElement.Name);
            }
            int retry = endpointNames.Count;
            blacklist = new Dictionary<string, DateTime>();

            while (retry > 0)
            {
                string rsEndpoint = PickReportingService();
                try
                {
                    System.Net.NetworkCredential clientCredential = new System.Net.NetworkCredential(reportServiceUser, reportServicePassword);
                    rs.ReportingService2010SoapClient rsClient = new rs.ReportingService2010SoapClient(rsEndpoint);
                    rsClient.ClientCredentials.Windows.ClientCredential = clientCredential;
                    rsClient.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
                    rs.TrustedUserHeader userHeader = new rs.TrustedUserHeader();
                    rs.CatalogItem[] items;

                    Trace.TraceInformation("Connecting to reporting service " + rsEndpoint);
                    rsClient.Open();
                    Trace.TraceInformation("Connected to reporting service " + rsEndpoint);
                    rs.ServerInfoHeader infoHeader = rsClient.ListChildren(userHeader, reportPath, true, out items);
                    Trace.TraceInformation("Fetched reports from reporting service " + rsEndpoint);

                    reports = new List<Report>(items.Length);

                    foreach (var item in items)
                    {
                        if (String.Compare(item.TypeName, "Report", true) == 0)
                        {
                            Report it = new Report { Name = item.Name, Path = item.Path, ModifiedDate = item.ModifiedDate };
                            reports.Add(it);
                        }
                    }
                    rsClient.Close();
                    break;
                }
                catch (Exception e)
                {
                    Trace.TraceError("Failed to fetch reports from reporting service. " + e.Message);
                    blacklist[rsEndpoint] = DateTime.Now;
                    --retry;
                    if (retry == 0) throw;
                }
            }

            return reports;
        }
        // GET: api/ReportGenerate
        public IEnumerable <Report> Get()
        {
            string        reportServiceUser     = CloudConfigurationManager.GetSetting("reportServiceUser");
            string        reportServicePassword = CloudConfigurationManager.GetSetting("reportServicePassword");
            ClientSection clientSec             = System.Configuration.ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;
            ChannelEndpointElementCollection endpointCollection = clientSec.Endpoints;

            endpointNames = new List <string>();
            foreach (ChannelEndpointElement endpointElement in endpointCollection)
            {
                if (String.Compare(endpointElement.Contract, "ReportingService.ReportingService2010Soap", true) == 0)
                {
                    endpointNames.Add(endpointElement.Name);
                }
            }
            int retry = endpointNames.Count;

            blacklist = new Dictionary <string, DateTime>();

            while (retry > 0)
            {
                string rsEndpoint = PickReportingService();
                try
                {
                    System.Net.NetworkCredential      clientCredential = new System.Net.NetworkCredential(reportServiceUser, reportServicePassword);
                    rs.ReportingService2010SoapClient rsClient         = new rs.ReportingService2010SoapClient(rsEndpoint);
                    rsClient.ClientCredentials.Windows.ClientCredential          = clientCredential;
                    rsClient.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
                    rs.TrustedUserHeader userHeader = new rs.TrustedUserHeader();
                    rs.CatalogItem[]     items;

                    Trace.TraceInformation("Connecting to reporting service " + rsEndpoint);
                    rsClient.Open();
                    Trace.TraceInformation("Connected to reporting service " + rsEndpoint);
                    rs.ServerInfoHeader infoHeader = rsClient.ListChildren(userHeader, reportPath, true, out items);
                    Trace.TraceInformation("Fetched reports from reporting service " + rsEndpoint);

                    reports = new List <Report>(items.Length);

                    foreach (var item in items)
                    {
                        if (String.Compare(item.TypeName, "Report", true) == 0)
                        {
                            Report it = new Report {
                                Name = item.Name, Path = item.Path, ModifiedDate = item.ModifiedDate
                            };
                            reports.Add(it);
                        }
                    }
                    rsClient.Close();
                    break;
                }
                catch (Exception e)
                {
                    Trace.TraceError("Failed to fetch reports from reporting service. " + e.Message);
                    blacklist[rsEndpoint] = DateTime.Now;
                    --retry;
                    if (retry == 0)
                    {
                        throw;
                    }
                }
            }

            return(reports);
        }