Exemple #1
0
 protected virtual CodeGenerationType GetTypeForAttributeInternal(Microsoft.Xrm.Sdk.Metadata.EntityMetadata entityMetadata, Microsoft.Xrm.Sdk.Metadata.AttributeMetadata attributeMetadata, IServiceProvider services)
 {
     return(DefaultService.GetTypeForAttribute(entityMetadata, attributeMetadata, services));
 }
Exemple #2
0
 public CodeGenerationType GetTypeForAttribute(Microsoft.Xrm.Sdk.Metadata.EntityMetadata entityMetadata, Microsoft.Xrm.Sdk.Metadata.AttributeMetadata attributeMetadata, IServiceProvider services)
 {
     return(GetTypeForAttributeInternal(entityMetadata, attributeMetadata, services));
 }
Exemple #3
0
        public static object GetAttributeValueFromString(Microsoft.Xrm.Sdk.IOrganizationService service, string entityName, string attribute, string value)

        {
            object retVal = null;



            var attributeRequest = new Microsoft.Xrm.Sdk.Messages.RetrieveAttributeRequest

            {
                EntityLogicalName = entityName,

                LogicalName = attribute,

                RetrieveAsIfPublished = true
            };

            Microsoft.Xrm.Sdk.Messages.RetrieveAttributeResponse attributeResponse = (Microsoft.Xrm.Sdk.Messages.RetrieveAttributeResponse)service.Execute(attributeRequest);

            Microsoft.Xrm.Sdk.Metadata.AttributeMetadata attrMetadata = (Microsoft.Xrm.Sdk.Metadata.AttributeMetadata)attributeResponse.AttributeMetadata;



            switch (attrMetadata.AttributeType.ToString())

            {
            case "Status":     //Status



                //Microsoft.Xrm.Sdk.Metadata.StatusAttributeMetadata tmp = new Microsoft.Xrm.Sdk.Metadata.StatusAttributeMetadata();

                //tmp.DefaultFormValue = int.Parse(value);

                //retVal = tmp;

                retVal = int.Parse(value);

                break;

            case "Picklist":     //Picklist



                retVal = int.Parse(value);

                break;

            case "State":     //State



                retVal = int.Parse(value);

                break;

            case "Decimal":     //Decimal



                retVal = decimal.Parse(value);

                break;

            case "Enum":     //Enum



                retVal = int.Parse(value);

                break;

            case "Memo":     //Memo

                retVal = value;

                break;

            case "Money":     //Money



                retVal = decimal.Parse(value);

                break;

            case "Lookup":

            {
                //    attrMetadata

                string[] strs = value.Split('\\');

                //Microsoft.Xrm.Sdk.EntityReference er = new Microsoft.Xrm.Sdk.EntityReference();

                //    er.LogicalName = ((Microsoft.Xrm.Sdk.Metadata.LookupAttributeMetadata) attrMetadata).Targets[0];
                //    er.Id = Guid.Parse(strs[0]);

                if (strs.Length > 1)
                {
                    retVal = Guid.Parse(strs[1]);
                }
                else if (strs.Length == 1)
                {
                    retVal = Guid.Parse(strs[0]);
                }
            }

            break;

            case "Integer":



                retVal = int.Parse(value);

                break;

            case "Owner":

            {
                string[] strs = value.Split('\\');

                Microsoft.Xrm.Sdk.EntityReference er = new Microsoft.Xrm.Sdk.EntityReference();

                er.LogicalName = strs[0];

                er.Id = Guid.Parse(strs[1]);

                retVal = er;
            }

            break;

            case "DateTime":     //DateTime



                retVal = DateTime.Parse(value);

                break;

            case "Boolean":     //Boolean

                retVal = bool.Parse(value);

                break;

            case "String":     //String

                retVal = value;

                break;

            case "Double":     //Double

                retVal = Double.Parse(value);

                break;

            case "EntityName":     //Entity Name

                retVal = value;

                break;

            case "Image":     //Image, it will return image name.

                retVal = value;

                break;

            case "BigInt":

                break;

            case "ManagedProperty":

                break;

            case "Uniqueidentifier":

                retVal = Guid.Parse(value);

                break;

            case "Virtual":

                break;

            default:

                //TODO: Write Err Exception

                break;
            }

            return(retVal);
        }
        public static string GetProperVariableName(Microsoft.Xrm.Sdk.Metadata.AttributeMetadata attribute)
        {
            // Normally we want to use the SchemaName as it has the capitalized names (Which is what CrmSvcUtil.exe does).
            // HOWEVER, If you look at the 'annual' attributes on the annualfiscalcalendar you see it has schema name of Period1
            // So if the logicalname & schema name don't match use the logical name and try to capitalize it
            // EXCEPT,  when it's RequiredAttendees/From/To/Cc/Bcc/SecondHalf/FirstHalf  (i have no idea how CrmSvcUtil knows to make those upper case)
            if (attribute.LogicalName == "requiredattendees")
            {
                return("RequiredAttendees");
            }
            if (attribute.LogicalName == "from")
            {
                return("From");
            }
            if (attribute.LogicalName == "to")
            {
                return("To");
            }
            if (attribute.LogicalName == "cc")
            {
                return("Cc");
            }
            if (attribute.LogicalName == "bcc")
            {
                return("Bcc");
            }
            if (attribute.LogicalName == "firsthalf")
            {
                return("FirstHalf");
            }
            if (attribute.LogicalName == "secondhalf")
            {
                return("SecondHalf");
            }
            if (attribute.LogicalName == "firsthalf_base")
            {
                return("FirstHalf_Base");
            }
            if (attribute.LogicalName == "secondhalf_base")
            {
                return("SecondHalf_Base");
            }
            if (attribute.LogicalName == "attributes")
            {
                return("Attributes1");
            }
            if (attribute.LogicalName == "id")
            {
                return("__Id");  // LocalConfigStore has an attribute named Id, the template will already add and Id
            }
            if (attribute.LogicalName == "entitytypecode")
            {
                return("__EntityTypeCode");  // PrincipalSyncAttributeMap has a field called EntityTypeCode, the template will already have a property called EntityTypeCode which refers to the entity's type code.
            }
            if (attribute.LogicalName.Equals(attribute.SchemaName, StringComparison.InvariantCultureIgnoreCase))
            {
                return(Clean(attribute.SchemaName));
            }

            return(Clean(Capitalize(attribute.LogicalName, true)));
        }
Exemple #5
0
        public static string GetAttributeLabel(Microsoft.Xrm.Sdk.IOrganizationService service, Microsoft.Xrm.Sdk.Entity entity, string attribute)

        {
            string strLabel = String.Empty;

            Microsoft.Xrm.Sdk.OptionSetValue option = null;



            var attributeRequest = new Microsoft.Xrm.Sdk.Messages.RetrieveAttributeRequest

            {
                EntityLogicalName = entity.LogicalName,

                LogicalName = attribute,

                RetrieveAsIfPublished = true
            };



            Microsoft.Xrm.Sdk.Messages.RetrieveAttributeResponse attributeResponse = (Microsoft.Xrm.Sdk.Messages.RetrieveAttributeResponse)service.Execute(attributeRequest);

            Microsoft.Xrm.Sdk.Metadata.AttributeMetadata attrMetadata = (Microsoft.Xrm.Sdk.Metadata.AttributeMetadata)attributeResponse.AttributeMetadata;

            Microsoft.Xrm.Sdk.Metadata.OptionMetadataCollection optionMeta = null;



            //Console.Write("\tDebug attributeType : " + attrMetadata.AttributeType.ToString() + "\t");



            #region Switch

            switch (attrMetadata.AttributeType.ToString())

            {
            case "Status":     //Status

                optionMeta = ((Microsoft.Xrm.Sdk.Metadata.StatusAttributeMetadata)attrMetadata).OptionSet.Options;

                break;

            case "Picklist":     //Picklist

                optionMeta = ((Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata)attrMetadata).OptionSet.Options;

                break;

            case "State":     //State

                optionMeta = ((Microsoft.Xrm.Sdk.Metadata.StateAttributeMetadata)attrMetadata).OptionSet.Options;

                break;

            case "Decimal":     //Decimal

                break;

            case "Enum":     //Enum

                break;

            case "Memo":     //Memo

                break;

            case "Money":     //Money

                break;

            case "Lookup":

                break;

            case "Integer":

                break;

            case "Owner":

                strLabel = ((Microsoft.Xrm.Sdk.EntityReference)entity.Attributes[attribute]).Name;

                break;

            case "DateTime":     //DateTime

                strLabel = Convert.ToDateTime(entity.Attributes[attribute].ToString()).ToString();

                break;

            case "Boolean":     //Boolean

                break;

            case "String":     //String

                strLabel = entity[attribute].ToString();

                break;

            case "Double":     //Double

                break;

            case "EntityName":     //Entity Name

                break;

            case "Image":     //Image, it will return image name.

                break;

            case "BigInt":

                break;

            case "ManagedProperty":

                break;

            case "Uniqueidentifier":

                break;

            case "Virtual":

                break;

            default:

                //TODO: Write Err Exception

                break;
            }

            #endregion Switch

            //If this attr is OptionSet, Find Label
            if (optionMeta != null)
            {
                option = ((Microsoft.Xrm.Sdk.OptionSetValue)entity.Attributes[attribute]);

                foreach (Microsoft.Xrm.Sdk.Metadata.OptionMetadata metadata in optionMeta)

                {
                    if (metadata.Value == option.Value)

                    {
                        strLabel = metadata.Label.UserLocalizedLabel.Label;
                    }
                }
            }



            return(strLabel);
        }