예제 #1
0
        public static string CreateSubscription(string agentNumber, string agentRepEmail)
        {
            //Create a new subscription
            string reportPath     = "/Customer Service/Internal Delivery Window By Store";
            string subscriptionID = "";

            try {
                //Create reporting service web client proxy
                _Client             = new ReportingService2010();
                _Client.Credentials = System.Net.CredentialCache.DefaultCredentials;

                //
                ExtensionSettings extSettings = setExtSettings(agentRepEmail);
                string            description = "Send e-mail to " + agentRepEmail;
                string            eventType   = "TimedSubscription";
                string            matchData   = setMatchData(DateTime.Today);
                ParameterValue    pv1         = new ParameterValue(); pv1.Name = "AgentNumber"; pv1.Value = agentNumber;
                ParameterValue    pv2         = new ParameterValue(); pv2.Name = "EndDate"; pv2.Value = null;
                ParameterValue    pv3         = new ParameterValue(); pv3.Name = "ClientNumber"; pv3.Value = null;
                ParameterValue    pv4         = new ParameterValue(); pv4.Name = "Division"; pv4.Value = null;
                ParameterValue    pv5         = new ParameterValue(); pv5.Name = "District"; pv5.Value = null;
                ParameterValue    pv6         = new ParameterValue(); pv6.Name = "Region"; pv6.Value = null;
                ParameterValue    pv7         = new ParameterValue(); pv7.Name = "StoreNumber"; pv7.Value = null;
                ParameterValue[]  parameters  = new ParameterValue[] { pv4, pv1, pv5, pv6, pv7, pv3 };
                subscriptionID = _Client.CreateSubscription(reportPath, extSettings, description, eventType, matchData, parameters);
            }
            catch (TimeoutException te) { _Client.Abort(); throw new ApplicationException(te.Message); }
            return(subscriptionID);
        }
예제 #2
0
        public static string CreateSubscription(string reportPath, string routeClass, string driverName)
        {
            //Create a new subscription
            string subscriptionID = "";

            try {
                //Create reporting service web client proxy
                _Client             = new ReportingService2010();
                _Client.Credentials = System.Net.CredentialCache.DefaultCredentials;

                //
                ExtensionSettings extSettings = setExtSettings();
                string            description = "Send e-mail to [email protected]";
                string            eventType   = "TimedSubscription";
                string            matchData   = setMatchData(DateTime.Today);
                ParameterValue    pv1         = new ParameterValue(); pv1.Name = "RouteDate"; pv1.Value = null;
                ParameterValue    pv2         = new ParameterValue(); pv2.Name = "RouteClass"; pv2.Value = routeClass;
                ParameterValue    pv3         = new ParameterValue(); pv3.Name = "DriverName"; pv3.Value = driverName;
                ParameterValue[]  parameters  = new ParameterValue[] { pv1, pv2, pv3 };
                subscriptionID = _Client.CreateSubscription(reportPath, extSettings, description, eventType, matchData, parameters);
            }
            catch (TimeoutException te) { _Client.Abort(); throw new ApplicationException(te.Message); }
            catch (FaultException fe) { _Client.Abort(); throw new ApplicationException(fe.Message); }
            catch (CommunicationException ce) { _Client.Abort(); throw new ApplicationException(ce.Message); }
            return(subscriptionID);
        }
        public string CreateSubscription(string ItemPath, RSExtensionSettings ExtensionSettings, string Description, string EventType, string MatchData, RSParameterValue[] Parameters)
        {
            ExtensionSettings extSetting = (ExtensionSettings)Converter.Convert(ExtensionSettings);

            ParameterValue[] param  = (ParameterValue[])Converter.Convert(Parameters);
            string           outval = rs.CreateSubscription(ItemPath, extSetting, Description, EventType, MatchData, param);

            return(outval);
        }
예제 #4
0
        private void CreateSubscription(FileInfo subscriptionFile, string reportPath)
        {
            string[] subscriptionInfoText = File.ReadAllLines(subscriptionFile.FullName);

            if (SubscriptionInfo(subscriptionInfoText, "subscriptionOn").ToLower() == "true")
            {
                var eventType                  = SubscriptionInfo(subscriptionInfoText, "eventType");
                var scheduleXml                = SubscriptionInfo(subscriptionInfoText, "scheduleXml");
                var subscriptionType           = SubscriptionInfo(subscriptionInfoText, "subscriptionType");
                var subscriptionTypeParameters = GetSubscriptionTypeParameters(subscriptionInfoText);
                var extSettings                = new ExtensionSettings
                {
                    ParameterValues = subscriptionTypeParameters,
                    Extension       = string.IsNullOrEmpty(subscriptionType) ? "Report Server Email" : "Report Server FileShare"
                };

                ParameterValue[] reportParameterValues = null;
                string           reportParameters      = SubscriptionInfo(subscriptionInfoText, "reportParameters");

                if (!string.IsNullOrEmpty(reportParameters))
                {
                    string[] reportParameterParts = reportParameters.Split(';');
                    reportParameterValues = new ParameterValue[reportParameterParts.Length];
                    Log("Found {0} report parameter values to set", reportParameterParts.Length);

                    for (int i = 0; i <= reportParameterParts.Length - 1; i++)
                    {
                        var reportValue        = new ParameterValue();
                        var parameterKeyValues = reportParameterParts[i].Split('=');

                        Log("Setting parameter '{0}', with '{1}'", parameterKeyValues[0], parameterKeyValues[1]);

                        reportValue.Name         = parameterKeyValues[0];
                        reportValue.Value        = parameterKeyValues[1];
                        reportParameterValues[i] = reportValue;
                    }
                }
                else
                {
                    Log("Subscription report parameters not found in '{0}'", subscriptionFile.Name);
                }

                Log("Creating subscription '{0}'", subscriptionFile.Name);
                rs.CreateSubscription(reportPath, extSettings, subscriptionFile.Name + " - Subscription", eventType, scheduleXml, reportParameterValues);
                Log("Created subscription '{0}'", subscriptionFile.Name);
            }
            else
            {
                Log("Subscription not set to 'On' for '{0}'", subscriptionFile.Name);
            }
        }
        private void CreateSubscriptions(string reportName, string reportPath, string sourceFolder)
        {
            var reportsDirectoryInfo  = new DirectoryInfo(sourceFolder);
            var subscriptionFileInfos = reportsDirectoryInfo.GetFiles(reportName + "*.subinfo");

            if (subscriptionFileInfos.Length == 0)
            {
                Log("No subscription files found for report '{0}'", reportName);
            }
            else
            {
                foreach (var subscriptionFileInfo in subscriptionFileInfos)
                {
                    var subscriptionInfoText = File.ReadAllLines(subscriptionFileInfo.FullName);
                    var subscription         = GetSubscription(subscriptionInfoText, reportPath, subscriptionFileInfo.Name);
                    if (subscription.Enabled)
                    {
                        Log("Creating subscription '{0}'", subscription.Name);
                        rs.CreateSubscription(subscription.Path, subscription.ExtensionSettings, subscription.Description, subscription.EventType, subscription.ScheduleXml, subscription.Parameters);
                        Log("Created subscription '{0}'", subscription.Name);
                    }
                }
            }
        }
예제 #6
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);
        }
        private void ScheduleReport()
        {
            // See whether the user wants to schedule this versus run it now
            if (sharedSchedules.SelectedValue.ToString() != "NS")
            {
                string desc      = "Send report via email";
                string eventType = String.Empty;
                string matchData = String.Empty;

                // If the user selected SnapShot, then
                // set up the parameters for a snapshot
                if (sharedSchedules.SelectedValue.ToString() == "SS")
                {
                    eventType = "SnapshotUpdated";
                    matchData = null;
                }

                // otherwise the user is using a subscription
                else
                {
                    eventType = "TimedSubscription";
                    matchData = sharedSchedules.SelectedValue.ToString();
                }

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

                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 = "PDF";

                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 = "Here is your @ReportName report.";

                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[] pvs = ReportParameters();

                // Configure the extension settings required
                // for the CreateSubscription method
                ExtensionSettings extSettings = new ExtensionSettings();
                extSettings.ParameterValues = extensionParams;
                extSettings.Extension       = "Report Server Email";

                // Get the report parameters using the GetParameters form
                GetParameters reportParameters = new GetParameters(url);
                reportParameters.ShowDialog();
                Microsoft.Reporting.WinForms.ReportParameter[] rps = reportParameters.Parameters;

                // Convert the Winforms.ReportParameter returned
                // from the GetParameters to ParameterValues required for
                // the CreateSubscription method
                int i = 0;
                foreach (Microsoft.Reporting.WinForms.ReportParameter rp in rps)
                {
                    if (rp.Values.Count != 0)
                    {
                        i++;
                    }
                }

                ParameterValue[] pvs = new ParameterValue[i];
                int j = 0;
                foreach (Microsoft.Reporting.WinForms.ReportParameter rp in rps)
                {
                    if (rp.Values.Count != 0)
                    {
                        pvs[j]       = new ParameterValue();
                        pvs[j].Name  = rp.Name;
                        pvs[j].Value = rp.Values[0];
                        j++;
                    }
                }

                // Now set up the subscription
                try
                {
                    rs.CreateSubscription(report, extSettings, desc, eventType, matchData, pvs);
                }

                catch (SoapException ex)
                {
                    MessageBox.Show(ex.Detail.InnerXml.ToString());
                }
            }
        }