-
Notifications
You must be signed in to change notification settings - Fork 23
/
ReportingServicesMgmt.cs
51 lines (49 loc) · 2.07 KB
/
ReportingServicesMgmt.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using ReportSync.Properties;
using ReportSync.ReportService;
namespace ReportSync
{
public class ReportingServicesMgmt
{
private const string ServicesUrl = @"/ReportService2005.asmx";
public ReportingService2005 ReportingService { get; private set; }
public Dictionary<string, string> DataSources { get; set; }
public ReportingServicesMgmt(string url, string username, string password, bool integratedAuth)
{
var reportServerUrl = url.TrimEnd('/') + ServicesUrl;
DataSources = new Dictionary<string, string>();
ReportingService = new ReportingService2005 {Url = reportServerUrl};
if (!integratedAuth) // uses the checkbox, these weren't actively being used befare
{
var nameParts = username.Split('\\', '/');
if (nameParts.Length > 2)
{
throw new Exception(Resources.Incorrect_destination_user_name);
}
try { ReportingService.Credentials = nameParts.Length == 2
? new System.Net.NetworkCredential(nameParts[1], password, nameParts[0]) // Auth with a domain
: new System.Net.NetworkCredential(username, password); // Username/Password Only Auth
}
catch(Exception ex){
MessageBox.Show("Could not connect to server: " + ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
else // Use the system credentials
{
try
{
ReportingService.Credentials = System.Net.CredentialCache.DefaultCredentials;
}
catch(Exception ex)
{
MessageBox.Show("Could not use integrated auth:" + ex.Message, Resources.Error, MessageBoxButtons.OK);
return;
}
}
}
}
}