-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
ConnectionExtensions.cs
55 lines (53 loc) · 1.77 KB
/
ConnectionExtensions.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
52
53
54
55
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using McTools.Xrm.Connection;
using Microsoft.Xrm.Sdk;
namespace MarkMpn.Sql4Cds.XTB
{
/// <summary>
/// Thanks @rappen
/// https://github.com/rappen/FetchXMLBuilder/blob/master/FetchXmlBuilder/AppCode/ConnectionExtensions.cs
/// </summary>
static class ConnectionExtensions
{
public static string GetFullWebApplicationUrl(this ConnectionDetail connectiondetail)
{
var url = connectiondetail.WebApplicationUrl;
if (string.IsNullOrEmpty(url))
{
url = connectiondetail.ServerName;
}
if (!url.ToLower().StartsWith("http"))
{
url = string.Concat("http://", url);
}
var uri = new Uri(url);
if (!uri.Host.EndsWith(".dynamics.com"))
{
if (string.IsNullOrEmpty(uri.AbsolutePath.Trim('/')))
{
uri = new Uri(uri, connectiondetail.Organization);
}
}
return uri.ToString();
}
public static string GetEntityReferenceUrl(this ConnectionDetail connectiondetail, EntityReference entref)
{
if (string.IsNullOrWhiteSpace(entref?.LogicalName) || Guid.Empty.Equals(entref.Id))
{
return string.Empty;
}
var url = connectiondetail.GetFullWebApplicationUrl();
url = string.Concat(url,
url.EndsWith("/") ? "" : "/",
"main.aspx?etn=",
entref.LogicalName,
"&pagetype=entityrecord&id=",
entref.Id.ToString());
return url;
}
}
}