Exemplo n.º 1
0
        /// <summary>
        /// Update the properties of a subscription
        /// </summary>
        /// <param name="reportSchedule">report schedule parmater</param>
        public void UpdateSubscription(ReportSchedule reportSchedule)
        {
            reportSchedule.ReportSubscriptionId = db.ReportSchedules.Where(r => r.ReportId == reportSchedule.ReportId).Select(r => r.ReportSubscriptionId).FirstOrDefault();
            reportSchedule.Report = db.Reports.Where(r => r.ReportId == reportSchedule.ReportId).FirstOrDefault();

            ReportingService2010 rs = new ReportingService2010();

            rs.Url = ConfigurationManager.AppSettings[ReportServerURL];

            //rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
            rs.UseDefaultCredentials = true;

            ActiveState       active      = null;
            ExtensionSettings extSettings = null;

            ParameterValue[] values;
            string           desc      = string.Empty;
            string           eventType = string.Empty;
            string           matchData = string.Empty;
            string           status;

            Subscription[] subscriptions = null;

            //string subscriptionFileName = String.Concat(/*reportSchedule.Schedule_ID,*/ FileNameSplitter, reportSchedule.Report.ReportName, FileNameSplitter, TimestampParameter);
            //subscriptions = rs.ListSubscriptions(reportSchedule.Report.ReportPath);

            ////Get the subscription from the filename
            //var subscription = subscriptions.ToList().Select(r => { r.DeliverySettings.ParameterValues.Cast<ParameterValue>().Where(d => d.Name == FileName && d.Value == subscriptionFileName); return r; }).FirstOrDefault();

            //Get Subscription properties
            rs.GetSubscriptionProperties(reportSchedule.ReportSubscriptionId, out extSettings, out desc, out active, out status, out eventType, out matchData, out values);

            //Get  the schedule data
            matchData = new ReportScheduleFormatter().GetMatchData(reportSchedule);

            //Set the Report Name Descriptions
            desc = reportSchedule.Report.ReportName;

            //TODO: Below code is needed because for the password. Giving an error with out the password
            ParameterValue[] extensionParamsTemp = new ParameterValue[extSettings.ParameterValues.Count() + 1];

            //extSettings.ParameterValues.CopyTo(extensionParamsTemp, 0);
            //extensionParamsTemp[extSettings.ParameterValues.Count()] = new ParameterValue { Name = Password, Value = ConfigurationManager.AppSettings[ReportPassword] };

            //extSettings.ParameterValues = extensionParamsTemp;

            rs.SetSubscriptionProperties(reportSchedule.ReportSubscriptionId, extSettings, desc, eventType, matchData, values);

            db.Entry(reportSchedule).State = EntityState.Modified;
            db.SaveChanges();

            //Console.WriteLine("Report Succesfully Updated");
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method will create required subscription if not exist
        /// </summary>
        /// <param name="reportSchedule">Name of the Report</param>
        /// <param name="parametersDictionary">Report Parameters</param>
        /// <returns></returns>
        public bool CreateFileSubscription(ReportSchedule reportSchedule)
        {
            //Getting the shared folder path from the config file
            string shareFolderPath = ConfigurationManager.AppSettings[ReportSubscirptionSharedPath];
            //string shareFolderPath = sharedSubscriptionFolderPath;

            bool isSuccessful = false;

            //ReportingService2010 rs = new ReportingService2010();
            //rs.Url = ConfigurationManager.AppSettings[ReportServerURL];

            //rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

            //rs.UseDefaultCredentials = true;

            //Check whether the subscription already exist
            //bool isExist = IsSubscriptionExist(rs, reportSchedule);
            bool isExist = false;

            if (!isExist)
            {
                string report    = reportSchedule.Report.ReportPath;
                string desc      = reportSchedule.Report.ReportDescription;
                string eventType = TimedSubscription;

                //Getting the schedule data
                string scheduleXml = new ReportScheduleFormatter().GetMatchData(reportSchedule);

                //Populating the the extension parameters
                ParameterValue[] extensionParams = new ParameterValue[7]
                {
                    new ParameterValue {
                        Name = Path, Value = shareFolderPath
                    },
                    new ParameterValue {
                        Name = FileName, Value = String.Concat(/*reportSchedule.Schedule_ID,*/ FileNameSplitter, reportSchedule.Report.ReportName, FileNameSplitter, TimestampParameter)
                    },
                    new ParameterValue {
                        Name = FileExtention, Value = "TRUE"
                    },
                    new ParameterValue {
                        Name = UserName, Value = ConfigurationManager.AppSettings[ReportUsername]
                    },
                    new ParameterValue {
                        Name = Password, Value = ConfigurationManager.AppSettings[ReportPassword]
                    },
                    new ParameterValue {
                        Name = Render_Format, Value = RenderFormat.EXCEL.ToString()
                    },
                    new ParameterValue {
                        Name = FileWriteMode, Value = WriteMode.Overwrite.ToString()
                    }
                };

                ExtensionSettings extSettings = new ExtensionSettings();
                extSettings.ParameterValues = extensionParams;
                extSettings.Extension       = SubscriptionMode;

                ParameterValue[] parameters = PopulateParamters(reportSchedule);

                var subscriptionId = rs.CreateSubscription(report, extSettings, desc,
                                                           eventType, scheduleXml, parameters);

                isSuccessful = true;

                reportSchedule.ReportSubscriptionId = subscriptionId;
                reportSchedule.Report = null;

                db.ReportSchedules.Add(reportSchedule);
                db.SaveChanges();

                //Add the subscription to the Schedule table


                //Console.WriteLine("Report subscription successFully created");
            }

            else
            {
                //Console.WriteLine("Report subscription already exist");
            }

            return(isSuccessful);
        }
Exemplo n.º 3
0
        public bool CreateEmailSubscription(ReportSchedule reportSchedule)
        {
            string report       = reportSchedule.Report.ReportPath;
            string desc         = reportSchedule.Report.ReportDescription;
            string eventType    = TimedSubscription;
            bool   isSuccessful = false;

            //Getting the schedule data
            string scheduleXml = new ReportScheduleFormatter().GetMatchData(reportSchedule);

            //string scheduleXml = @"<ScheduleDefinition>";
            //scheduleXml += @"<StartDateTime>2003-02-24T09:00:00-08:00</StartDateTime><WeeklyRecurrence><WeeksInterval>1</WeeksInterval>";
            //scheduleXml += @"<DaysOfWeek><Monday>True</Monday></DaysOfWeek>";
            //scheduleXml += @"</WeeklyRecurrence></ScheduleDefinition>";

            ParameterValue[] extensionParams = new ParameterValue[8];

            extensionParams[0]       = new ParameterValue();
            extensionParams[0].Name  = "TO";
            extensionParams[0].Value = reportSchedule.EmailTo;//"*****@*****.**";

            extensionParams[1]       = new ParameterValue();
            extensionParams[1].Name  = "ReplyTo";
            extensionParams[1].Value = "*****@*****.**";

            extensionParams[2]       = new ParameterValue();
            extensionParams[2].Name  = "IncludeReport";
            extensionParams[2].Value = "True";

            extensionParams[3]       = new ParameterValue();
            extensionParams[3].Name  = "RenderFormat";
            extensionParams[3].Value = "MHTML";

            extensionParams[4]       = new ParameterValue();
            extensionParams[4].Name  = "Subject";
            extensionParams[4].Value = "@ReportName was executed at @ExecutionTime";

            extensionParams[5]       = new ParameterValue();
            extensionParams[5].Name  = "Comment";
            extensionParams[5].Value = reportSchedule.EmailComment;//"Here is your daily sales report for Michael.";

            extensionParams[6]       = new ParameterValue();
            extensionParams[6].Name  = "IncludeLink";
            extensionParams[6].Value = "True";

            extensionParams[7]       = new ParameterValue();
            extensionParams[7].Name  = "Priority";
            extensionParams[7].Value = "NORMAL";

            ParameterValue parameter = new ParameterValue();

            parameter.Name  = "BranchID";
            parameter.Value = "1";

            ParameterValue[] parameters = new ParameterValue[1];
            parameters[0] = parameter;

            string            matchData   = scheduleXml;
            ExtensionSettings extSettings = new ExtensionSettings();

            extSettings.ParameterValues = extensionParams;
            extSettings.Extension       = "Report Server Email";

            try
            {
                var subscriptionId = rs.CreateSubscription(report, extSettings, desc, eventType, matchData, parameters);

                isSuccessful = true;

                reportSchedule.ReportSubscriptionId = subscriptionId;
                reportSchedule.Report = null;

                db.ReportSchedules.Add(reportSchedule);
                db.SaveChanges();
            }

            catch (SoapException e)
            {
                Console.WriteLine(e.Detail.InnerXml.ToString());
            }
            return(isSuccessful);
        }