forked from jamesnovak/CrmSvcUtilTS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXrm2TSRenderBase.cs
80 lines (71 loc) · 2.7 KB
/
Xrm2TSRenderBase.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System.Text;
using Microsoft.Xrm.Sdk.Metadata;
using System.Text.RegularExpressions;
using System.Collections.Generic;
namespace Xrm.Tools
{
/// <summary>
/// Abstract base class for the EntityRendering component
/// </summary>
public abstract class Xrm2TSRenderBase
{
#region Protected
protected EntityMetadata _entityMeta = null;
protected StringBuilder _sb = null;
protected string _formattedName = null;
protected ConfigurationInfo _configuration { get; private set; }
#endregion
public StringBuilder Logger { get; private set; }
public Xrm2TSRenderBase(EntityMetadata entityMeta, StringBuilder appendTo, StringBuilder logger, ConfigurationInfo config) {
_sb = appendTo;
_entityMeta = entityMeta;
_formattedName = firstUpper(_entityMeta.LogicalName);
Logger = logger;
_configuration = config;
}
#region Utility functions
/// <summary>
/// Format the name for the Web API call for lookups
/// </summary>
/// <param name="attrib"></param>
/// <returns></returns>
protected string lookupFixer(AttributeMetadata attrib)
{
var name = attrib.LogicalName;
if ((attrib.AttributeType.Value == AttributeTypeCode.Lookup) && (!attrib.IsPrimaryId.Value) && !name.Contains("activity")) {
name = "_" + name + "_value";
}
return name;
}
/// <summary>
/// Convert first char to upper
/// </summary>
/// <param name="stringValue"></param>
/// <returns></returns>
protected string firstUpper(string val)
{
char[] a = val.ToCharArray();
a[0] = char.ToUpper(a[0]);
return new string(a);
}
/// <summary>
/// Get data type string based on AttributeTypeCode
/// </summary>
/// <param name="attr"></param>
/// <returns></returns>
protected string getDataType(AttributeMetadata attr)
{
var dataType = "string";
// assign a type based on attributetypecode
if (attr.AttributeType == AttributeTypeCode.Virtual || attr.AttributeType == AttributeTypeCode.State ||
attr.AttributeType == AttributeTypeCode.Integer || attr.AttributeType == AttributeTypeCode.BigInt ||
attr.AttributeType == AttributeTypeCode.Money || attr.AttributeType == AttributeTypeCode.Decimal ||
attr.AttributeType == AttributeTypeCode.Double)
{
dataType = "number";
}
return dataType;
}
#endregion
}
}