private string GetJsIntellisenseOptionSet()
        {
            var intellisense = string.Empty;

            intellisense += $"\t{EntityName.ToLower()}.OptionSet = {{}};\r\n";
            foreach (var crmAttribute in Fields)
            {
                if (!crmAttribute.IsValidForRead)
                {
                    continue;
                }
                if (crmAttribute.FieldType == AttributeTypeCode.Picklist ||
                    crmAttribute.FieldType == AttributeTypeCode.State ||
                    crmAttribute.FieldType == AttributeTypeCode.Status)
                {
                    intellisense += $"\t///<field name=\"{crmAttribute.SchemaName}\" type=\"PickList\"></field>\r\n";
                    intellisense += $"\t{EntityName.ToLower()}.OptionSet.{crmAttribute.SchemaName} = {{\r\n";
                    foreach (string nvc in crmAttribute.OptionSetValues)
                    {
                        intellisense +=
                            $"\t\t///<field name=\"{nvc}\" type=\"PickListValue\">{nvc} = {crmAttribute.OptionSetValues[nvc]}</field>\r\n";
                        intellisense += $"\t\t{nvc}: {crmAttribute.OptionSetValues[nvc]},\r\n";
                    }

                    intellisense  = intellisense.TrimEnd(",\r\n".ToCharArray()) + "\r\n";
                    intellisense += $"\t}};\r\n";
                }
            }

            return(intellisense);
        }
Exemplo n.º 2
0
 private string SafeDeclareName(string declareName)
 {
     declareName = SafeIdentifier(declareName);
     if (declareName.ToLower() == EntityName.ToLower())
     {
         return(declareName + "1");
     }
     if (declareName.ToLower() == "EntityLogicalName".ToLower())
     {
         return(declareName + "1");
     }
     if (declareName.ToLower() == "EntityTypeCode".ToLower())
     {
         return(declareName + "1");
     }
     if (declareName.ToLower() == "Entity".ToLower())
     {
         return(declareName + "1");
     }
     if (declareName.ToLower() == "Id".ToLower())
     {
         return(declareName + "1");
     }
     return(declareName);
 }
Exemplo n.º 3
0
 public override int GetHashCode()
 {
     return((GetType().FullName +
             "|entityid" + this.EntityId +
             "|entityname" + EntityName.ToLower() +
             "|propname" + LockedPropertyName.ToLower()).GetHashCode());
 }
 private void ddlMessage_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (FormType == FormType.CustomActionItem)
     {
         EntityName  = ddlMessage.SelectedValue.ToString();
         LogicalName = EntityName.ToLower();
     }
 }
Exemplo n.º 5
0
        protected override void VisitUpdate(UpdateBuilder item)
        {
            GuardUpdateBuilder(item);
            item.Table.Source.Accept(this);

            int whereCount = 0;

            CurrentUpdateStatementPart = UpdateStatementPart.WhereClause;
            foreach (IVisitableBuilder where in item.Where)
            {
                where.Accept(this);
                whereCount++;
            }

            // IsVisitingWhereFilter = false;
            if (whereCount != 1)
            {
                throw new ArgumentException("The update statement should have a single filter in the where clause, which should specify the entity id of the record to be updated.");
            }
            if (EqualToFilter == null)
            {
                throw new NotSupportedException("The update statement has an unsupported filter in it's where clause. The where clause should contain a single 'equal to' filter that specifies the entity id of the particular record to update.");
            }
            if (IdFilterColumn == null)
            {
                throw new NotSupportedException("The update statement has an unsupported filter in it's where clause. The'equal to' filter should specify the entity id column on one side.");
            }
            var idAttName = GetColumnLogicalAttributeName(IdFilterColumn);
            var expectedIdAttributeName = string.Format("{0}id", EntityName.ToLower());

            if (idAttName != expectedIdAttributeName)
            {
                throw new NotSupportedException("The update statement has an unsupported filter in it's where clause. The'equal to' filter should specify the id column of the entity on one side.");
            }
            EntityBuilder.WithAttribute(idAttName).SetValueWithTypeCoersion(IdFilterValue);

            CurrentUpdateStatementPart = UpdateStatementPart.Setter;
            foreach (IVisitableBuilder setter in item.Setters)
            {
                setter.Accept(this);
            }
            CurrentRequest.Target = EntityBuilder.Build();
            EntityBuilder         = null;

            CurrentUpdateStatementPart = UpdateStatementPart.OutputClause;
            OutputColumns = item.Output.ToArray();
            UpgradeToExecuteMultipleIfNecessary();
        }
        protected override void VisitDelete(DeleteBuilder item)
        {
            GuardDeleteBuilder(item);
            item.Table.Source.Accept(this);
            int whereCount = 0;

            foreach (IVisitableBuilder where in item.Where)
            {
                where.Accept(this);
                whereCount++;
            }
            if (whereCount != 1)
            {
                throw new ArgumentException("The delete statement should have a single filter in the where clause, which should specify the entity id of the record to be deleted.");
            }
            if (EqualToFilter == null)
            {
                throw new NotSupportedException("The delete statement has an unsupported filter in it's where clause. The where clause should contain a single 'equal to' filter that specifies the entity id of the particular record to delete.");
            }
            if (IdFilterColumn == null)
            {
                throw new NotSupportedException("The delete statement has an unsupported filter in it's where clause. The'equal to' filter should specify the entity id column on one side.");
            }
            var idAttName = GetColumnLogicalAttributeName(IdFilterColumn);

            var expectedIdAttributeName = string.Format("{0}id", EntityName.ToLower());

            if (idAttName != expectedIdAttributeName)
            {
                throw new NotSupportedException("The delete statement has an unsupported filter in it's where clause. The'equal to' filter should specify the id column of the entity on one side.");
            }

            EntityReference entRef = new EntityReference();

            entRef.LogicalName    = EntityName;
            entRef.Id             = DynamicsTypeProvider.GetUniqueIdentifier(IdFilterValue);
            CurrentRequest.Target = entRef;
        }
Exemplo n.º 7
0
        public void GeneratorCode()
        {
            var webApiCode = string.Empty;
            var @class     = EntityName.ToLower();
            var Class      = EntityName;

            webApiCode += $"var {ProjectName};\r\n";
            webApiCode += $"(function ({ProjectName}) {{\r\n";
            webApiCode += $"\t'use strict';\r\n";
            webApiCode += $"\t{ProjectName}.{Class}Api = function (e) {{\r\n";
            webApiCode += $"\t\tvar EMPTY_STRING = '';\r\n";
            webApiCode += $"\t\tvar f = '@OData.Community.Display.V1.FormattedValue';\r\n";
            var webapi = Utility.ReadEmbeddedResource("DynamicsCrm.DevKit.Resources.WebApi.js");

            webApiCode += webapi;
            webApiCode += $"\t\tvar {@class} = {{\r\n";
            foreach (var crmAttribute in Fields)
            {
                if (crmAttribute.IsDeprecated)
                {
                    continue;
                }
                if (crmAttribute.AttributeOf != null && crmAttribute.FieldType == AttributeTypeCode.Virtual && crmAttribute.LogicalName != "entityimage")
                {
                    continue;
                }
                if (crmAttribute.FieldType == AttributeTypeCode.EntityName || crmAttribute.FieldType == AttributeTypeCode.PartyList)
                {
                    continue;
                }
                if (crmAttribute.AttributeOf != null && crmAttribute.AttributeOf.ToLower() + "name" == crmAttribute.LogicalName)
                {
                    continue;
                }
                if (crmAttribute.AttributeOf != null && crmAttribute.LogicalName.EndsWith("yominame") && !crmAttribute.IsValidForCreate && !crmAttribute.IsValidForUpdate)
                {
                    continue;
                }
                if (crmAttribute.FieldType == AttributeTypeCode.Memo ||
                    crmAttribute.FieldType == AttributeTypeCode.String ||
                    crmAttribute.FieldType == AttributeTypeCode.Picklist ||
                    crmAttribute.FieldType == AttributeTypeCode.State ||
                    crmAttribute.FieldType == AttributeTypeCode.Status ||
                    crmAttribute.FieldType == AttributeTypeCode.Uniqueidentifier ||
                    crmAttribute.FieldType == AttributeTypeCode.Boolean ||
                    crmAttribute.FieldType == AttributeTypeCode.Integer ||
                    crmAttribute.FieldType == AttributeTypeCode.BigInt ||
                    crmAttribute.FieldType == AttributeTypeCode.Double ||
                    crmAttribute.FieldType == AttributeTypeCode.Decimal ||
                    crmAttribute.FieldType == AttributeTypeCode.Money
                    )
                {
                    webApiCode += $"\t\t\t{crmAttribute.SchemaName}: {{ a: \"{crmAttribute.LogicalName}\" }},\r\n";
                }
                else if (crmAttribute.IsMultiSelectPicklist)
                {
                    webApiCode += $"\t\t\t{crmAttribute.SchemaName}: {{ a: \"{crmAttribute.LogicalName}\", g: true }},\r\n";
                }
                else if (crmAttribute.FieldType == AttributeTypeCode.DateTime)
                {
                    if (crmAttribute.DateTimeBehavior == DateTimeBehavior.DateOnly)
                    {
                        webApiCode += $"\t\t\t{crmAttribute.SchemaName}_DateOnly: {{ a: \"{crmAttribute.LogicalName}\" }},\r\n";
                    }
                    else if (crmAttribute.DateTimeBehavior == DateTimeBehavior.TimeZoneIndependent)
                    {
                        if (crmAttribute.DateTimeFormat == DateTimeFormat.DateOnly)
                        {
                            webApiCode += $"\t\t\t{crmAttribute.SchemaName}_TimezoneDateOnly: {{ a: \"{crmAttribute.LogicalName}\" }},\r\n";
                        }
                        else
                        {
                            webApiCode += $"\t\t\t{crmAttribute.SchemaName}_TimezoneDateAndTime: {{ a: \"{crmAttribute.LogicalName}\" }},\r\n";
                        }
                    }
                    else if (crmAttribute.DateTimeBehavior == DateTimeBehavior.UserLocal)
                    {
                        if (crmAttribute.DateTimeFormat == DateTimeFormat.DateOnly)
                        {
                            webApiCode += $"\t\t\t{crmAttribute.SchemaName}_UtcDateOnly: {{ a: \"{crmAttribute.LogicalName}\" }},\r\n";
                        }
                        else
                        {
                            webApiCode += $"\t\t\t{crmAttribute.SchemaName}_UtcDateAndTime: {{ a: \"{crmAttribute.LogicalName}\" }},\r\n";
                        }
                    }
                }
                else if (crmAttribute.FieldType == AttributeTypeCode.Lookup ||
                         crmAttribute.FieldType == AttributeTypeCode.Customer)
                {
                    var entities = crmAttribute.EntityReferenceLogicalName.Split(";".ToCharArray());
                    crmAttribute.LogicalCollectionName  = GetLogicalCollectionName(crmAttribute);
                    crmAttribute.NavigationPropertyName = GetNavigationPropertyName(crmAttribute);
                    var collections = crmAttribute.LogicalCollectionName.Split(";".ToCharArray());
                    var navigations = crmAttribute.NavigationPropertyName.Split(";".ToCharArray());
                    if (entities.Length == 1)
                    {
                        if (crmAttribute.IsCustomAttribute)
                        {
                            webApiCode += $"\t\t\t{crmAttribute.SchemaName}: {{ b: \"{crmAttribute.SchemaName}\", a: \"_{crmAttribute.LogicalName}_value\", c: \"{collections[0]}\", d: \"{entities[0]}\" }},\r\n";
                        }
                        else
                        {
                            webApiCode += $"\t\t\t{crmAttribute.SchemaName}: {{ b: \"{crmAttribute.LogicalName}\", a: \"_{crmAttribute.LogicalName}_value\", c: \"{collections[0]}\", d: \"{entities[0]}\" }},\r\n";
                        }
                    }
                    else
                    {
                        if (entities.Length != collections.Length ||
                            entities.Length != navigations.Length ||
                            collections.Length != navigations.Length)
                        {
                            continue;
                        }
                        var j = 0;
                        foreach (var e in entities)
                        {
                            if (crmAttribute.EntityName == "audit" && e == "externalparty")
                            {
                                continue;
                            }
                            webApiCode += $"\t\t\t{navigations[j]}: {{ b: \"{navigations[j]}\", a: \"_{crmAttribute.LogicalName}_value\", c: \"{collections[j]}\", d: \"{entities[j]}\" }},\r\n";
                            j++;
                        }
                    }
                }
                else if (crmAttribute.FieldType == AttributeTypeCode.Owner)
                {
                    webApiCode += $"\t\t\tOwnerId_systemuser: {{ b: \"ownerid\", a: \"_ownerid_value\", c: \"systemusers\", d: \"systemuser\" }},\r\n";
                    webApiCode += $"\t\t\tOwnerId_team: {{ b: \"ownerid\", a: \"_ownerid_value\", c: \"teams\", d: \"team\" }},\r\n";
                }
                else if (crmAttribute.FieldType == AttributeTypeCode.ManagedProperty)
                {
                    webApiCode += $"\t\t\t{crmAttribute.SchemaName}: {{ a: \"{crmAttribute.LogicalName}\" }},\r\n";
                }
                else
                {
                    if (crmAttribute.SchemaName == "EntityImage" ||
                        crmAttribute.SchemaName == "FullImageData" ||
                        crmAttribute.SchemaName == "ImageData")
                    {
                        webApiCode += $"\t\t\t{crmAttribute.SchemaName}: {{ a: \"{crmAttribute.LogicalName}\" }},\r\n";
                    }
                    else
                    {
                        webApiCode += $"\t\t\t{crmAttribute.SchemaName}: {{ a: ?????????? }},\r\n";
                    }
                }
                if (!(crmAttribute.IsValidForCreate || crmAttribute.IsValidForUpdate))
                {
                    webApiCode  = webApiCode.TrimEnd(" },\r\n".ToCharArray());
                    webApiCode += $", r: true }},\r\n";
                }
            }
            webApiCode  = webApiCode.TrimEnd(",\r\n".ToCharArray()) + "\r\n";
            webApiCode += $"\t\t}};\r\n";
            webApiCode += $"\t\tif (e === undefined) e = {{}};\r\n";
            webApiCode += $"\t\tvar u = {{}};\r\n";
            webApiCode += $"\t\tfor (var field in {@class}) {{\r\n";
            webApiCode += $"\t\t\tvar a = {@class}[field].a;\r\n";
            webApiCode += $"\t\t\tvar b = {@class}[field].b;\r\n";
            webApiCode += $"\t\t\tvar c = {@class}[field].c;\r\n";
            webApiCode += $"\t\t\tvar d = {@class}[field].d;\r\n";
            webApiCode += $"\t\t\tvar g = {@class}[field].g;\r\n";
            webApiCode += $"\t\t\tvar r = {@class}[field].r;\r\n";
            webApiCode += $"\t\t\t{@class}[field] = webApiField(e, a, b, c, d, r, u, g);\r\n";
            webApiCode += $"\t\t}}\r\n";
            var hasPartyList = Fields.Where(f => f.FieldType == AttributeTypeCode.PartyList).Any();

            if (hasPartyList)
            {
                var logicalName = IsCustomEntity ? $"{Class}_activity_parties" : $"{@class}_activity_parties";
                webApiCode += $"\t\tObject.defineProperty({@class}, 'ActivityParties', {{\r\n";
                webApiCode += $"\t\t\tget: function () {{ return e['{logicalName}']; }},\r\n";
                webApiCode += $"\t\t\tset: function (value) {{\r\n";
                webApiCode += $"\t\t\t\te['{logicalName}'] = value;\r\n";
                webApiCode += $"\t\t\t\tu['{logicalName}'] = value;\r\n";
                webApiCode += $"\t\t\t}}\r\n";
                webApiCode += $"\t\t}});\r\n";
            }
            webApiCode += $"\t\t{@class}.Entity = u;\r\n";
            webApiCode += $"\t\t{@class}.EntityName = \"{@class}\";\r\n";
            webApiCode += $"\t\t{@class}.EntityCollectionName = \"{GetLogicalCollectionName(@class)}\";\r\n";
            webApiCode += $"\t\t{@class}[\"@odata.etag\"] = e[\"@odata.etag\"];\r\n";
            //webApiCode += JsOptionSetFormCode;
            //webApiCode += $"\t\t{@class}.OptionSet = optionSet;\r\n";
            webApiCode += $"\t\t{@class}.getAliasedValue = function (alias, isMultiOptionSet) {{\r\n";
            webApiCode += $"\t\t\tif (e[alias] === undefined || e[alias] === null) {{\r\n";
            webApiCode += $"\t\t\t\treturn null;\r\n";
            webApiCode += $"\t\t\t}}\r\n";
            webApiCode += $"\t\t\tif (isMultiOptionSet) {{\r\n";
            webApiCode += $"\t\t\t\treturn e[alias].toString().split(',').map(function (item) {{ return parseInt(item, 10); }});\r\n";
            webApiCode += $"\t\t\t}}\r\n";
            webApiCode += $"\t\t\treturn e[alias];\r\n";
            webApiCode += $"\t\t}}\r\n";
            webApiCode += $"\t\t{@class}.getAliasedFormattedValue = function (alias, isMultiOptionSet) {{\r\n";
            webApiCode += $"\t\t\tif (e[alias + f] === undefined || e[alias + f] === null) {{\r\n";
            webApiCode += $"\t\t\t\treturn EMPTY_STRING;\r\n";
            webApiCode += $"\t\t\t}}\r\n";
            webApiCode += $"\t\t\tif (isMultiOptionSet) {{\r\n";
            webApiCode += $"\t\t\t\treturn e[alias + f].toString().split(';').map(function (item) {{ return item.trim(); }});\r\n";
            webApiCode += $"\t\t\t}}\r\n";
            webApiCode += $"\t\t\treturn e[alias + f];\r\n";
            webApiCode += $"\t\t}}\r\n";
            webApiCode += $"\t\treturn {@class};\r\n";
            webApiCode += $"\t}};\r\n";
            webApiCode += $"}})({ProjectName} || ({ProjectName} = {{}}));";
            webApiCode  = webApiCode.Replace("\"", "'");
            webApiCode  = webApiCode.Replace("'*'", "\"*\"");
            if (!IsDebugWebApi)
            {
                webApiCode = Uglify.Js(webApiCode).Code;
                webApiCode = webApiCode.Replace("\"", "'");
                webApiCode = webApiCode.Replace("'*'", "\"*\"");
            }
            var code = string.Empty;

            code += $"'use strict';\r\n";
            code += $"/** @namespace {ProjectName} */\r\n";
            code += webApiCode;
            code  = code + "\r\n";
            var optionSet = Utility.ReadEmbeddedResource("DynamicsCrm.DevKit.Resources.OptionSet.js");

            optionSet = optionSet.Replace("[[EntityOptionSet]]", OptionSet_For_d_ts);
            var optionSetMin = optionSet;

            if (!IsDebugWebApi)
            {
                optionSetMin = Uglify.Js(optionSet).Code;
            }
            code      += $"/** @namespace OptionSet */\r\n";
            code      += optionSetMin;
            WebApiCode = code;
            var processForms = new List <SystemForm>();

            foreach (var form in Forms)
            {
                if (CheckedItems.Contains($"{form.Name}"))
                {
                    processForms.Add(form);
                }
            }
            WebApiCodeTypeScriptDeclaration = GetWebApiCodeTypeScriptDeclaration(processForms, IsDebugForm, true, IsDebugWebApi);
        }