示例#1
0
        public void CreateReport(string reportName, string parentPath, byte[] definition, IEnumerable <string> dataSourcePaths)
        {
            Property[] reportProperties = new Property[1];
            Property   hidden           = new Property();

            hidden.Name         = "Hidden";
            hidden.Value        = reportName.StartsWith("_") ? "true" : "false";
            reportProperties[0] = hidden;
            _reportService.CreateReport(reportName, parentPath, true, definition, reportProperties);

            var sources = new List <DataSource>();

            foreach (var dataSourcePath in dataSourcePaths)
            {
                DataSourceReference dsRef = new DataSourceReference();
                dsRef.Reference = dataSourcePath;
                var ds = new DataSource();
                ds.Item = dsRef;
                sources.Add(ds);
            }
            //DataSourceReference dsRef = new DataSourceReference();
            //	dsRef.Reference = dataSourcePaths;
            //	DataSource[] Sources = _reportService.GetItemDataSources(parentPath + "/" + reportName);
            if (sources != null && sources.Count > 0)
            {
                try
                {
                    _reportService.SetItemDataSources(parentPath + "/" + reportName, sources.ToArray());
                }
                catch (Exception)
                {
                }
            }
        }
        private void SetReportDataSource(string reportName, string dataSourceName, string targetFolder)
        {
            Log("Setting DataSource For Report: " + reportName);

            var reference = new DataSourceReference {
                Reference = targetFolder + "/" + dataSourceName
            };
            var dataSource = rs.GetItemDataSources(targetFolder + "/" + reportName);

            Log("Report '{0}' has {1} data sources", reportName, dataSource.Length);

            var dataSources = new DataSource[dataSource.Length];
            int i;

            for (i = 0; i <= dataSource.Length - 1; i++)
            {
                var ds = new DataSource {
                    Item = reference, Name = dataSource[i].Name
                };
                dataSources[i] = ds;
                Log("Report '{0}' setting data source '{1}' to '{2}'", reportName, ds.Name, dataSourceName);
            }

            rs.SetItemDataSources(targetFolder + "/" + reportName, dataSources);
        }
        /// <summary>
        /// Build source definitions list for data controls contained in the form of the given task.
        /// </summary>
        /// <param name="task">The task whose form should be searched for data controls.</param>
        /// <returns>A list of data source definitions that correspond to the data controls. If the
        /// task does not have a form, the method will return an empty list.</returns>
        public static List <IDataSourceViewDefinition> BuildDataControlSourceDefinitions(Task task)
        {
            List <IDataSourceViewDefinition> viewDefs = new List <IDataSourceViewDefinition>();
            MgFormBase form = task.getForm();

            if (form != null)
            {
                foreach (var control in form.CtrlTab.GetControls(ControlTable.SelectDataControlPredicate))
                {
                    DataSourceId sourceId = new DataSourceId();
                    sourceId.CtlIdx = control.SourceTableReference.CtlIndex;
                    sourceId.Isn    = control.SourceTableReference.ObjectISN;

                    var dsDef = ClientManager.Instance.LocalManager.ApplicationDefinitions.DataSourceDefinitionManager.GetDataSourceDefinition(sourceId);
                    if (dsDef != null)
                    {
                        DataSourceReference dataSourceRef = new DataSourceReference(dsDef, Access.Read);
                        Property            indexProperty = control.getProp(PropInterface.PROP_TYPE_INDEX);
                        int keyIndex = indexProperty.getValueInt() - 1;

                        Property valueFieldProperty   = control.getProp(PropInterface.PROP_TYPE_LINK_FIELD);
                        int      valueFieldIndex      = valueFieldProperty.getValueInt() - 1;
                        Property displayFieldProperty = control.getProp(PropInterface.PROP_TYPE_DISPLAY_FIELD);
                        int      displayFieldIndex    = displayFieldProperty.getValueInt() - 1;

                        var viewDef = new DataControlSourceViewDefinition(dataSourceRef, keyIndex, valueFieldIndex, displayFieldIndex, control.getDitIdx());

                        viewDef.RangeDataBuilder = CreateRangeDataBuilder(((MgControl)control).RangeBoundaryFactories, task, viewDef);
                        viewDefs.Add(viewDef);
                    }
                }
            }
            return(viewDefs);
        }
示例#4
0
        private void bOK_Click(object sender, System.EventArgs e)
        {
            // Build the ConnectionProperties XML
            StringBuilder sb = new StringBuilder();

            sb.Append("<ConnectionProperties>");
            sb.AppendFormat("<DataProvider>{0}</DataProvider>",
                            this.cbDataProvider.Text);
            sb.AppendFormat("<ConnectString>{0}</ConnectString>",
                            this.tbConnection.Text.Replace("<", "&lt;"));
            sb.AppendFormat("<IntegratedSecurity>{0}</IntegratedSecurity>",
                            this.ckbIntSecurity.Checked? "true": "false");
            if (this.tbPrompt.Text.Length > 0)
            {
                sb.AppendFormat("<Prompt>{0}</Prompt>",
                                this.tbPrompt.Text.Replace("<", "&lt;"));
            }
            sb.Append("</ConnectionProperties>");
            try
            {
                DataSourceReference.Create(tbFilename.Text, sb.ToString(), tbPassword.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Unable to create data source reference file");
                return;
            }

            DialogResult = DialogResult.OK;
        }
示例#5
0
        private DataSource[] GetDataSources(DataSource[] oldDataSources)
        {
            var dataSources = DataSources;
            var results     = new List <DataSource>();

            if (oldDataSources != null)
            {
                foreach (var oldDataSource in oldDataSources)
                {
                    if (dataSources.ContainsKey(oldDataSource.Name))
                    {
                        var reference = new DataSourceReference
                        {
                            Reference = dataSources[oldDataSource.Name]
                        };
                        var newDataSource = new DataSource
                        {
                            Name = oldDataSource.Name,
                            Item = reference
                        };
                        results.Add(newDataSource);
                    }
                }
            }

            return(results.ToArray());
        }
示例#6
0
        /// <summary>
        /// Publish report through reporting service
        /// </summary>
        /// <param name="reportDefinition">Byte Array of RDL format report</param>
        /// <param name="reportName">Report Name</param>
        /// <param name="reportPath">Report Full Path</param>
        /// <returns>true: successful; false: failed</returns>
        public bool PublishReport(Byte[] reportDefinition, string reportName, string reportPath, string dataSourceName)
        {
            Warning[] warnings = null;

            ReportingService2010.ReportingService2010 CurrentService = new ReportingService2010.ReportingService2010();
            CurrentService.Credentials = System.Net.CredentialCache.DefaultCredentials;
            //set the credentials
            string UserReportID      = ConfigurationManager.AppSettings["userReportID"];
            string UerReportPassword = ConfigurationManager.AppSettings["userReportPassword"];
            string UserReportDomain  = ConfigurationManager.AppSettings["userReportDomain"];

            CurrentService.Credentials = new NetworkCredential(UserReportID, UerReportPassword, UserReportDomain);
            if (reportPath.Substring(reportPath.Length - 1) == "/")
            {
                reportPath = reportPath.Substring(0, reportPath.Length - 1);
            }
            CatalogItem myItem = CurrentService.CreateCatalogItem("Report", reportName, "/" + reportPath, true, reportDefinition, null, out warnings);

            //test if create worked OK
            if (warnings == null)
            {
                DataSource[]        dsArray = CurrentService.GetItemDataSources("/" + reportPath + "/" + reportName);
                DataSourceReference dsRef   = new DataSourceReference();
                dsRef.Reference = "/" + dataSourceName;
                dsArray[0].Item = dsRef;
                CurrentService.SetItemDataSources("/" + reportPath + "/" + reportName, dsArray);
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void CreateReport(string reportName, string parentPath, byte[] definition, string dataSourcePath)
        {
            Property[] reportProperties = new Property[1];
            Property   hidden           = new Property();

            hidden.Name         = "Hidden";
            hidden.Value        = reportName.StartsWith("_") ? "true" : "false";
            reportProperties[0] = hidden;
            _reportService.CreateReport(reportName, parentPath, true, definition, reportProperties);

            DataSourceReference dsRef = new DataSourceReference();

            dsRef.Reference = dataSourcePath;
            DataSource[] Sources = _reportService.GetItemDataSources(parentPath + "/" + reportName);
            if (Sources != null && Sources.Length > 0)
            {
                Sources[0].Item = dsRef;
                try
                {
                    _reportService.SetItemDataSources(parentPath + "/" + reportName, Sources);
                }
                catch (Exception)
                {
                }
            }
        }
示例#8
0
        private void SetReportDataSource(string reportName, string dataSourceName, string targetFolder)
        {
            Log("Setting DataSource For Report: " + reportName);

            var reference = new DataSourceReference {
                Reference = $"{targetFolder}/{dataSourceName}"
            };
            var getItemDataSourcesResponse = reportingServicesClient.GetItemDataSources(new GetItemDataSourcesRequest {
                ItemPath = $"{targetFolder}/{reportName}"
            });
            var dataSource = getItemDataSourcesResponse.DataSources;

            Log("Report '{0}' has {1} data sources", reportName, dataSource.Length);

            var dataSources = new DataSource[dataSource.Length];
            int i;

            for (i = 0; i <= dataSource.Length - 1; i++)
            {
                var ds = new DataSource {
                    Item = reference, Name = dataSource[i].Name
                };
                dataSources[i] = ds;
                Log("Report '{0}' setting data source '{1}' to '{2}'", reportName, ds.Name, dataSourceName);
            }

            reportingServicesClient.SetItemDataSources(new SetItemDataSourcesRequest {
                ItemPath = $"{targetFolder}/{reportName}", DataSources = dataSources
            });
        }
示例#9
0
        /// <summary>
        /// Creates Reports in Reporting Services.
        /// </summary>
        /// <param name="reports">XML file path holds Reports information.</param>
        private static void CreateReports(Report[] reports)
        {
            ReportingService rsc =
                new ReportingService();

            rsc.Credentials = System.Net.CredentialCache.DefaultCredentials;

            foreach (Report aReport in reports)
            {
                Byte[]    definition = null;
                Warning[] warnings   = null;

                try
                {
                    FileStream stream = File.OpenRead(aReport.Path);
                    definition = new Byte[stream.Length];
                    stream.Read(definition, 0, (int)stream.Length);
                    stream.Close();
                }

                catch (IOException e)
                {
                    Logging.Log(e.Message);
                }

                try
                {
                    rsc.CreateReport(aReport.Name, aReport.Folder, true, definition, null);

                    #region Setting Report Data Source
                    DataSourceReference reference = new DataSourceReference();
                    reference.Reference = aReport.DataSource;
                    DataSource[] dataSources = new DataSource[1];
                    DataSource   ds          = new DataSource();
                    ds.Item        = (DataSourceDefinitionOrReference)reference;
                    ds.Name        = aReport.DataSource.Split('/').Last();
                    dataSources[0] = ds;
                    rsc.SetReportDataSources(aReport.Folder + "/" + aReport.Name, dataSources);
                    #endregion

                    if (warnings != null)
                    {
                        foreach (Warning warning in warnings)
                        {
                            Logging.Log(string.Format("Report: {0} has warnings", warning.Message));
                        }
                    }
                    else
                    {
                        Logging.Log(string.Format("Report: {0} created successfully with no warnings", aReport.Name));
                    }
                }

                catch (SoapException e)
                {
                    Logging.Log(e.Detail.InnerXml.ToString());
                }
            }
        }
示例#10
0
        internal Boundary CreateBoundary(Task task, DataSourceReference dataSourceReference)
        {
            DBField field = dataSourceReference.DataSourceDefinition.Fields[BoundaryFieldIndex - 1];

            Boundary b = new Boundary(task, MinExpressionId, MaxExpressionId, (StorageAttribute)field.Attr, field.StorageFldSize());

            return(b);
        }
示例#11
0
        public bool CreateReport(string name, byte[] definition, string path = null)
        {
            string batchId = null;

            client.CreateBatch(out batchId);
            Warning[] warnings = null;
            var       result   = client.CreateReport(
                new BatchHeader()
            {
                BatchID = batchId
            },
                name,
                path ?? "/",
                true,
                definition,
                new Property[0],
                out warnings);

            string reportPath = string.Format("/{0}/{1}", path.Trim('/'), name);

            DataSourceReference reference = new DataSourceReference();

            reference.Reference = "/libservices/DS";
            DataSource[] dataSources = new DataSource[1];
            DataSource   ds          = new DataSource();

            ds.Item        = (DataSourceDefinitionOrReference)reference;
            ds.Name        = "DS";
            dataSources[0] = ds;
            client.SetItemDataSources(new BatchHeader()
            {
                BatchID = batchId
            }, reportPath, dataSources);

            client.ExecuteBatch(new BatchHeader()
            {
                BatchID = batchId
            });
            if (warnings != null && warnings.Length > 0)
            {
                StringBuilder sb = new StringBuilder();
                foreach (var w in warnings)
                {
                    sb.AppendLine(w.Severity);
                    sb.AppendLine("---");
                    sb.AppendLine(w.ObjectName);
                    sb.AppendLine(w.ObjectType);
                    sb.AppendLine(w.Message);
                    sb.AppendLine();
                }

                throw new Exception(sb.ToString());
            }
            return(true);
        }
        static internal bool GetSharedConnectionInfo(DesignerForm dsr, string filename, out string dataProvider, out string connectInfo)
        {
            dataProvider = null;
            connectInfo  = null;

            string pswd = null;
            string xml  = "";

            try
            {
                pswd = dsr.GetPassword();
                if (pswd == null)
                {
                    return(false);
                }
                if (!filename.EndsWith(".dsr", StringComparison.InvariantCultureIgnoreCase))
                {
                    filename += ".dsr";
                }

                xml = DataSourceReference.Retrieve(filename, pswd);
            }
            catch
            {
                MessageBox.Show("Unable to open shared connection, password or file is invalid.", "Test Connection");
                dsr.ResetPassword();                    // make sure to prompt again for the password
                return(false);
            }
            XmlDocument xDoc = new XmlDocument();

            xDoc.LoadXml(xml);
            XmlNode xNodeLoop = xDoc.FirstChild;

            foreach (XmlNode node in xNodeLoop.ChildNodes)
            {
                switch (node.Name)
                {
                case "DataProvider":
                    dataProvider = node.InnerText;
                    break;

                case "ConnectString":
                    connectInfo = node.InnerText;
                    break;

                default:
                    break;
                }
            }
            return(true);
        }
        /// <summary>
        /// Set the datasource of a report
        /// </summary>
        /// <param name="item">path of the item</param>
        /// <param name="datasource">path of the datasource to bind</param>
        public void SetDatasource(string item, string datasource, ReportItemTypes type)
        {
            string dataSourceName = ("/" + datasource.Split('/')[datasource.Split('/').GetUpperBound(0)]).Trim('/').Replace(".rsds", "");

            switch (type)
            {
            case ReportItemTypes.Folder:
                foreach (CatalogItem catalogItem in GetCatalogItems(item, true))
                {
                    SetDatasource(catalogItem.Path, datasource, ConvertItemType(catalogItem.Type));
                }
                break;

            case ReportItemTypes.Report:
                try
                {
                    foreach (DataSource availableDataSource in rs.GetItemDataSources(item))
                    {
                        // Only update the report when the selected datasource is used in that report
                        if (availableDataSource.Name == dataSourceName)
                        {
                            DataSourceReference dsr = new DataSourceReference();
                            dsr.Reference = datasource;

                            DataSource[] dataSources = new DataSource[1];

                            DataSource ds = new DataSource();
                            ds.Item        = (DataSourceDefinitionOrReference)dsr;
                            ds.Name        = dataSourceName;
                            dataSources[0] = ds;

                            rs.SetItemDataSources(item, dataSources);
                            Application.DoEvents();

                            toolStripStatusLabel.Text = String.Format("Updated datasource of {0}", item);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(String.Format("An error has occured: {0}", ex.Message));
                }
                break;

            default:
                toolStripStatusLabel.Text = String.Format("Cannot set datasource of item {0}", item);
                break;
            }
        }
        public void DataSourceReferenceCanBeEncodedAndDecoded()
        {
            var reference = new DataSourceReference("aws_region", "current", "name", true);
            var jtoken    = JObject.Parse(json);

            var property = (JProperty)jtoken.SelectToken("Property")?.Parent;

            property.Value = reference.ToJConstructor();
            var token1 = JObject.Parse(jtoken.ToString(Formatting.None));

            var con          = (JConstructor)token1.SelectToken("Property");
            var outReference = Reference.FromJConstructor(con);

            outReference.ReferenceExpression.Should().Be(reference.ReferenceExpression);
        }
示例#15
0
        public void SetItemDataSources(string item, string dataSourceName)
        {
            var reportDataSources = webserviceProxy.GetItemDataSources(item);

            foreach (var existingDataSource in reportDataSources)
            {
                var dsr = new DataSourceReference
                {
                    Reference = dataSourceName
                };

                existingDataSource.Item = dsr;
            }

            webserviceProxy.SetItemDataSources(item, reportDataSources);
        }
示例#16
0
        public bool CreateReport(string name, byte[] definition, string path = null)
        {
            string batchId = null;
            client.CreateBatch(out batchId);
            Warning[] warnings = null;
            var result = client.CreateReport(
                new BatchHeader()
                {
                    BatchID = batchId
                },
                name,
                path ?? "/",
                true,
                definition,
                new Property[0],
                out warnings);

            string reportPath = string.Format("/{0}/{1}", path.Trim('/'), name);

            DataSourceReference reference = new DataSourceReference();
            reference.Reference = "/libservices/DS";
            DataSource[] dataSources = new DataSource[1];
            DataSource ds = new DataSource();
            ds.Item = (DataSourceDefinitionOrReference)reference;
            ds.Name = "DS";
            dataSources[0] = ds;
            client.SetItemDataSources(new BatchHeader() { BatchID = batchId }, reportPath, dataSources);

            client.ExecuteBatch(new BatchHeader() { BatchID = batchId });
            if (warnings != null && warnings.Length > 0)
            {
                StringBuilder sb = new StringBuilder();
                foreach (var w in warnings)
                {
                    sb.AppendLine(w.Severity);
                    sb.AppendLine("---");
                    sb.AppendLine(w.ObjectName);
                    sb.AppendLine(w.ObjectType);
                    sb.AppendLine(w.Message);
                    sb.AppendLine();
                }

                throw new Exception(sb.ToString());
            }
            return true;
        }
示例#17
0
        private void Publish_Report_Set_Reference_DataSource(string layer, string report_name, string folder, string RDL_path)
        {
            DataSource[]        dsarray;
            string              reportName      = report_name;// "ACT0001";
            string              _selectedFolder = "/" + SSRS_Project + "/" + layer + "/" + folder.Replace(@"\", "") + "/";
            DataSourceReference reference       = new DataSourceReference();
            DataSource          ds = new DataSource();

            dsarray = new DataSource[1];
            string DSName = "Data_Source_" + layer;

            reference.Reference = "/" + SSRS_Project + "/" + DSName;
            ds.Item             = reference;
            ds.Name             = Publish_Report_Get_Reference_DataSource(RDL_path + "/" + report_name);
            dsarray[0]          = ds;
            rs.SetItemDataSources(_selectedFolder + reportName, dsarray);
        }
        public DataControlSourceViewDefinition(DataSourceReference dataSourceReference, int keyIndex, int valueFieldIndex, int displayFieldIndex, int boundControlId)
        {
            TaskDataSource = dataSourceReference;
            DbKey          = dataSourceReference.DataSourceDefinition.TryGetKey(keyIndex);
            DbFields       = new List <DBField>();
            DBField f = dataSourceReference.DataSourceDefinition.Fields[displayFieldIndex];

            DbFields.Add(f);
            if (valueFieldIndex == -1)
            {
                valueFieldIndex = displayFieldIndex;
            }
            f = dataSourceReference.DataSourceDefinition.Fields[valueFieldIndex];
            DbFields.Add(f);
            BoundControlId   = boundControlId;
            RangeDataBuilder = null;
        }
示例#19
0
        private void DeployReportItems(string Path, string DestinationFolder, string DataSource)
        {
            ReportingService2010 rs = new ReportingService2010();

            rs.Url         = SSRSWS;
            rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

            byte[] _reportDefinition;
            SQL_PTO_Report.localhost.Warning[] _warnings;
            string              strReportPath;
            FileStream          _stream;
            DataSourceReference reference;
            DataSource          ds;

            DataSource[] dsarray;
            string       strReportName;

            System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(Path);
            foreach (System.IO.FileInfo f in dir.GetFiles("*.rdl"))
            {
                strReportPath     = f.FullName;
                _stream           = File.OpenRead(strReportPath);
                _reportDefinition = new Byte[_stream.Length];
                _stream.Read(_reportDefinition, 0, (int)_stream.Length);
                _stream.Close();

                strReportName = f.Name.Split('.')[0];

                // Create the report into the server.
                rs.CreateCatalogItem("Report", strReportName, DestinationFolder, true, _reportDefinition, null, out _warnings);

                dsarray = rs.GetItemDataSources(DestinationFolder + @"/" + strReportName);
                if (dsarray.Length > 0)
                {
                    reference           = new DataSourceReference();
                    ds                  = new DataSource();
                    reference.Reference = DataSource;
                    ds                  = dsarray[0];
                    ds.Item             = (DataSourceReference)reference;
                    rs.SetItemDataSources(DestinationFolder + @"/" + strReportName, dsarray);
                }
            }

            rs.Dispose();
        }
示例#20
0
        /// <summary>
        /// Serializes this instance of <see cref="VmDisk" /> into a <see cref="Carbon.Json.JsonNode" />.
        /// </summary>
        /// <param name="container">The <see cref="Carbon.Json.JsonObject"/> container to serialize this object into. If the caller
        /// passes in <c>null</c>, a new instance will be created and returned to the caller.</param>
        /// <param name="serializationMode">Allows the caller to choose the depth of the serialization. See <see cref="Microsoft.Rest.ClientRuntime.SerializationMode"/>.</param>
        /// <returns>
        /// a serialized instance of <see cref="VmDisk" /> as a <see cref="Carbon.Json.JsonNode" />.
        /// </returns>
        public Carbon.Json.JsonNode ToJson(Carbon.Json.JsonObject container, Microsoft.Rest.ClientRuntime.SerializationMode serializationMode)
        {
            container = container ?? new Carbon.Json.JsonObject();

            bool returnNow = false;

            BeforeToJson(ref container, ref returnNow);
            if (returnNow)
            {
                return(container);
            }
            AddIf(null != DataSourceReference ? (Carbon.Json.JsonNode)DataSourceReference.ToJson(null) : null, "data_source_reference", container.Add);
            AddIf(null != DeviceProperties ? (Carbon.Json.JsonNode)DeviceProperties.ToJson(null) : null, "device_properties", container.Add);
            AddIf(null != DiskSizeBytes ? (Carbon.Json.JsonNode) new Carbon.Json.JsonNumber((long)DiskSizeBytes) : null, "disk_size_bytes", container.Add);
            AddIf(null != DiskSizeMib ? (Carbon.Json.JsonNode) new Carbon.Json.JsonNumber((int)DiskSizeMib) : null, "disk_size_mib", container.Add);
            AddIf(null != Uuid ? (Carbon.Json.JsonNode) new Carbon.Json.JsonString(Uuid) : null, "uuid", container.Add);
            AddIf(null != VolumeGroupReference ? (Carbon.Json.JsonNode)VolumeGroupReference.ToJson(null) : null, "volume_group_reference", container.Add);
            AfterToJson(ref container);
            return(container);
        }
示例#21
0
        public string SaveReport(string report, Stream file, string name, bool overwrite, ref Guid id)
        {
            id = Guid.Empty;
            string _report = report.ToLower().Replace(".rdl", "");

            if (this.CheckExist(ItemTypeEnum.Report, WebConfigurationManager.AppSettings["ReportsRootPath"].ToString(), (name == "" ? _report : name)) == true && overwrite == false)
            {
                return("The Report '" + (name == "" ? _report : name) + "' already exists");
            }
            Byte[] definition = null;
            try
            {
                System.IO.BinaryReader br = new System.IO.BinaryReader(file);
                definition = br.ReadBytes((Int32)file.Length);
                //Create Report
                rs.CreateReport((name == string.Empty ? _report : name), WebConfigurationManager.AppSettings["ReportsRootPath"].ToString(), overwrite, definition, null);
                //Set DataSource
                DataSourceReference Item1 = new DataSourceReference();

                DataSource[] datasources = rs.GetItemDataSources(WebConfigurationManager.AppSettings["ReportsRootPath"].ToString() + "/" + (name == "" ? _report : name));



                Item1.Reference = WebConfigurationManager.AppSettings["ReportsRootPath"].ToString() + WebConfigurationManager.AppSettings["MyDataSource"].ToString();

                datasources[0].Item = Item1;

                rs.SetItemDataSources(WebConfigurationManager.AppSettings["ReportsRootPath"].ToString() + "/" + (name == "" ? _report : name), datasources);

                string _id = GetReportID(WebConfigurationManager.AppSettings["ReportsRootPath"].ToString() + "/" + (name == "" ? _report : name));
                id = _id != string.Empty ? new Guid(_id) : Guid.Empty;

                return(string.Format("Report: {0} created successfully", name == "" ? _report : name));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(ex.Message);
            }
        }
示例#22
0
        public bool AttachDataSourceToReport(ReportingService2005 rsSource, string dataSourceName, string dataSourcePath, string report, string reportLocation)
        {
            bool resVal = false;

            try
            {
                string fullReportPath     = (reportLocation + "/" + report).Replace("//", @"/");
                string fullDataSourcePath = (dataSourcePath.Replace(dataSourceName, string.Empty) + dataSourceName).Replace(@"\", @"/");

                DataSource[] sharedDs = _reportsServerInstance.GetItemDataSources(fullReportPath);

                DataSource[] targetDs = new DataSource[sharedDs.Count()];

                int counter = 0;

                foreach (var dataSource in sharedDs)
                {
                    DataSourceReference dsRef = new DataSourceReference
                    {
                        Reference = fullDataSourcePath
                    };

                    dataSource.Item = dsRef;

                    targetDs[counter] = dataSource;
                }

                _reportsServerInstance.SetItemDataSources(fullReportPath, targetDs);

                resVal = true;
            }
            catch (Exception)
            {
                resVal = false;
            }

            return(resVal);
        }
示例#23
0
        private void uploadReport(string destinationPath, string reportName, byte[] reportDef)
        {
            try
            {
                //Create report
                destRS.CreateReport(reportName, destinationPath, true, reportDef, null);

                //Link datasources
                var reportPath = destinationPath;
                if (reportPath.EndsWith("/"))
                {
                    reportPath += reportName;
                }
                else
                {
                    reportPath += "/" + reportName;
                }
                var reportDss = destRS.GetItemDataSources(reportPath);
                List <DataSource> dataSources = new List <DataSource>();
                foreach (var reportDs in reportDss)
                {
                    if (destDS.ContainsKey(reportDs.Name))
                    {
                        DataSourceReference reference = new DataSourceReference();
                        reference.Reference = destDS[reportDs.Name];
                        var ds = new DataSource();
                        ds.Item = (DataSourceDefinitionOrReference)reference;
                        ds.Name = reportDs.Name;
                        dataSources.Add(ds);
                    }
                }
                destRS.SetItemDataSources(reportPath, dataSources.ToArray());
            }
            catch (Exception e)
            {
                MessageBox.Show("Upload " + reportName + " failed." + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#24
0
        public bool CopyReport(Report reportToPublish, StandardReport reportInfo)
        {
            Warning[] warnings   = null;
            string    reportPath = ConfigurationManager.AppSettings["ReportPublishedLocation"];
            string    reportName = reportInfo.ReportName;

            string dataSourceName = reportToPublish.DataModel_1.DatasourceName;

            ReportingService2010.ReportingService2010 CurrentService = new ReportingService2010.ReportingService2010();
            CurrentService.Credentials = System.Net.CredentialCache.DefaultCredentials;
            //set the credentials
            string UserReportID      = ConfigurationManager.AppSettings["userReportID"];
            string UerReportPassword = ConfigurationManager.AppSettings["userReportPassword"];
            string UserReportDomain  = ConfigurationManager.AppSettings["userReportDomain"];

            CurrentService.Credentials = new NetworkCredential(UserReportID, UerReportPassword, UserReportDomain);

            byte[] reportDefinition = CurrentService.GetItemDefinition("/" + reportToPublish.ReportGroup.PathName + reportToPublish.Name);

            CatalogItem myItem = CurrentService.CreateCatalogItem("Report", reportName, "/" + reportPath, true, reportDefinition, null, out warnings);

            //test if create worked OK
            if (warnings == null)
            {
                DataSource[]        dsArray = CurrentService.GetItemDataSources("/" + reportPath + "/" + reportName);
                DataSourceReference dsRef   = new DataSourceReference();
                dsRef.Reference = "/" + dataSourceName;
                dsArray[0].Item = dsRef;
                CurrentService.SetItemDataSources("/" + reportPath + "/" + reportName, dsArray);
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void SetItemDataSources(string item, string dataSourceName)
        {
            foreach (var availableDataSource in webserviceProxy.GetReportDataSources(item))
            {
                if (availableDataSource.Name != dataSourceName)
                {
                    continue;
                }

                try
                {
                    var dsr = new DataSourceReference
                    {
                        Reference = dataSourceName
                    };

                    var dataSources = new DataSource[1];

                    var ds = new DataSource
                    {
                        Item = dsr,
                        Name =
                            ("/" +
                             dataSourceName.Split('/')[
                                 dataSourceName.Split('/').GetUpperBound(0)]).Trim('/')
                    };
                    dataSources[0] = ds;

                    webserviceProxy.SetReportDataSources(item, dataSources);
                }
                catch (Exception ex)
                {
                    throw new Exception(String.Format("An error has occured: {0}", ex.Message));
                }
            }
        }
示例#26
0
        private DataSource[] GetDataSources(DataSource[] oldDataSources)
        {
            var dataSources = DataSources;
            var results = new List<DataSource>();
            if (oldDataSources != null)
            {
                foreach (var oldDataSource in oldDataSources)
                {
                    if (dataSources.ContainsKey(oldDataSource.Name))
                    {
                        var reference = new DataSourceReference
                            {
                                Reference = dataSources[oldDataSource.Name]
                            };
                        var newDataSource = new DataSource
                            {
                                Name = oldDataSource.Name,
                                Item = reference
                            };
                        results.Add(newDataSource);
                    }
                }
            }

            return results.ToArray();
        }
示例#27
0
        /// <summary>
        /// Deploys the report to the reporting server.
        /// </summary>
        private void Deploy()
        {
            foreach (object report in this.ConnectionStrings)
            {
                // Get the connection string for the report to deploy.
                //this.connectString = this.GetValueFromConfig( "ReportDetails",
                //	"Report1");
                this.ConnectString = report.ToString();

                // Continue deploying report if report details provided.
                if (this.ConnectString.Length > 0)
                {
                    // Set report details.
                    this.SetReportInfo();

                    // Open the report (rdl) file and read the data into the stream.
                    byte[]     reportDefinition;
                    Warning[]  Warnings;
                    FileStream Stream = File.OpenRead(this.ReportPath);
                    reportDefinition = new Byte[Stream.Length];
                    Stream.Read(reportDefinition, 0, (int)Stream.Length);
                    Stream.Close();

                    // Create the report into the server.
                    string reportName = this.ReportPath.Substring(
                        this.ReportPath.LastIndexOf("\\") + 1);
                    Warnings = (Warning[])ReportingService.CreateReport(reportName.Remove
                                                                            (reportName.Length - 4, 4), this.Parent + this.Folder, true,
                                                                        reportDefinition, null);

                    // Create datasource for the report.
                    DataSource           dSource     = new DataSource();
                    DataSourceDefinition dDefinition = new DataSourceDefinition();
                    dSource.Item              = dDefinition;
                    dDefinition.Extension     = this.Extension;
                    dDefinition.ConnectString = @"Data Source=" + this.ServerName
                                                + @";Initial Catalog=" + this.DatabaseName;
                    //dDefinition.ImpersonateUserSpecified = true;
                    //dDefinition.Prompt = null;
                    dDefinition.WindowsCredentials  = false;
                    dDefinition.CredentialRetrieval = CredentialRetrievalEnum.Integrated;
                    dSource.Name = this.DataSource;

                    try
                    {
                        if (this.CheckExist(ItemTypeEnum.DataSource, this.Parent,
                                            this.DatasourceLocation + "/" + this.DataSource) == false)
                        {
                            ReportingService.CreateDataSource(this.DataSource, @"/" +
                                                              this.DatasourceLocation, false, dDefinition, null);
                        }
                    }
                    catch (SoapException ex)
                    {
                        throw ex;
                    }

                    // Report and Datasource created, now fix up datasource reference to
                    // make sure report points at correct dataset.
                    try
                    {
                        DataSourceReference reference = new DataSourceReference();
                        DataSource          ds        = new DataSource();
                        reference.Reference = @"/" + this.DatasourceLocation + @"/"
                                              + this.DataSource;
                        DataSource[] dsarray = ReportingService.GetItemDataSources(this.Parent +
                                                                                   this.Folder + "/" + reportName.Remove
                                                                                       (reportName.Length - 4, 4));
                        ds      = dsarray[0];
                        ds.Item = (DataSourceReference)reference;
                        ReportingService.SetItemDataSources(this.Parent +
                                                            this.Folder + "/" + reportName.Remove
                                                                (reportName.Length - 4, 4), dsarray);
                    }
                    catch (Exception e)
                    {
                        throw (e);
                    }
                }
            }
        }
示例#28
0
        private string DeployModel(string localPath, string serverPath, string dataSourcePath, string dataSourceName)
        {
            byte[]    definition = null;
            Warning[] warnings   = null;
            string    retRes     = String.Empty;

            try
            {
                // Read the file and put it into a byte array to pass to SRS
                FileStream stream = File.OpenRead(localPath);
                definition = new byte[stream.Length];
                stream.Read(definition, 0, (int)(stream.Length));
                stream.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            // We are going to use the name of the rdl file as the name of our report
            string reportName = Path.GetFileNameWithoutExtension(localPath);


            // Now lets use this information to publish the report
            try
            {
                warnings = rs.CreateModel(reportName, serverPath, definition, null);

                if (warnings != null)
                {
                    retRes = String.Format("Report {0} failed with warnings :\n", reportName);
                    foreach (Warning warning in warnings)
                    {
                        retRes += warning.Message + "\n";
                    }
                }
                else
                {
                    retRes = String.Format("Report {0} created successfully with no warnings\n", reportName);
                }

                //set the datasource
                DataSourceReference dsr = new DataSourceReference();
                dsr.Reference = dataSourcePath + "/" + dataSourceName;


                DataSource[] dsarray = rs.GetItemDataSources(serverPath + "/" + reportName);
                DataSource   ds      = new DataSource();

                ds      = dsarray[0];
                ds.Item = (DataSourceReference)dsr;

                rs.SetItemDataSources(serverPath + "/" + reportName, dsarray);
            }
            catch (SoapException ex)
            {
                return(String.Format("Report {0} failed with exception {1}\n", reportName, ex.Detail.InnerXml.ToString()));
            }

            return(retRes);
        }
示例#29
0
        private static DataSource[] GetSharedDataSource(ReportingService2010.ReportingService2010 rs, string reportsFolder, string reportName)
        {
            V4Utils.Logger logger;
            logger = V4Utils.Logger.GetLogger("SSRSTest");

            try
            {
                DataSourceReference reference = new DataSourceReference();
                DataSource ds = new DataSource();
                reference.Reference = @"/"; //+ reportsFolder + "/" + "SharedDataSource";
                ds.Item = (DataSourceDefinitionOrReference)reference;
                //Get original report Data Source Name
                DataSource[] reportDataSource = rs.GetItemDataSources(@"/" + reportsFolder + @"/" + reportName);
                ds.Name = reportDataSource[0].Name;
                //Testing: change existing data source name to match shared data source
                //ds.Name = "V4_SPPS_V6";
                return new DataSource[] { ds };
            }

            catch (System.Web.Services.Protocols.SoapException Err)
            {

                logger.LogMsg(Err.Detail.InnerXml.ToString(), Logger.LogLevel.LogIsErr);
                //WriteLog(Err.Detail.InnerXml.ToString());
            }
            return null;
        }
        public void DeployReport(string reportPath, string folderPath, Dictionary <string, string> dicRdlDataSources)
        {
            var reportDeployedFullPath = string.Empty;

            if (File.Exists(reportPath))
            {
                var fileName = Path.GetFileName(reportPath);

                var stream           = File.OpenRead(reportPath);
                var reportDefinition = new Byte[stream.Length];
                stream.Read(reportDefinition, 0, (int)stream.Length);
                stream.Close();

                if (fileName != null)
                {
                    reportDeployedFullPath = string.Format("{0}/{1}", folderPath, Path.GetFileNameWithoutExtension(fileName));
                    this._rs.CreateReport(Path.GetFileNameWithoutExtension(fileName), folderPath, true, reportDefinition, null);
                }
                else
                {
                    throw new Exception(string.Format("File not found or can't get file name from path: {0}", reportPath));
                }
            }

            DataSource[] reportDsns = this._rs.GetItemDataSources(reportDeployedFullPath);

            foreach (var dataSource in reportDsns)
            {
                foreach (var dataSourcePath in dicRdlDataSources)
                {
                    if (string.IsNullOrEmpty(folderPath))
                    {
                        throw new Exception("Please input folder path");
                    }

                    //folder Name: /MSI Report Demo
                    folderPath = folderPath.BuildPath();

                    if (string.IsNullOrEmpty(dataSourcePath.Value))
                    {
                        throw new Exception("Please input data source path");
                    }

                    var dsnPath = dataSourcePath.Value.BuildPath();

                    if (dataSourcePath.Key.ToLower().Trim() == dataSource.Name.ToLower().Trim())
                    {
                        var reference = new DataSourceReference
                        {
                            Reference = dsnPath
                        };

                        dataSource.Item = reference;

                        break;
                    }
                }
            }

            foreach (var dataSource in reportDsns)
            {
                if (dataSource.Item is InvalidDataSourceReference)
                {
                    Utils.AddLog(string.Format("{0}{1}InvalidDataSourceReference: Please check '{2}' datasource{3}", Environment.NewLine, Environment.NewLine, dataSource.Name, Environment.NewLine), Utils.MessageType.WARNING);
                }
            }
            this._rs.SetItemDataSources(reportDeployedFullPath, reportDsns);
        }