/// <summary>
        /// Converts a CRM <c>AttributeType</c> into a simple .NET type.
        /// </summary>
        /// <param name="typeToConvert">The CRM <c>AttributeType</c> to be converted.</param>
        /// <returns>A .NET <see cref="Type"/> that represents the CRM type.</returns>
        public static Type SimpleTypeConvert(AttributeTypeCode typeToConvert)
        {
            switch (typeToConvert)
            {
            case AttributeTypeCode.Boolean:
                return(typeof(bool?));

            case AttributeTypeCode.DateTime:
                return(typeof(DateTime?));

            case AttributeTypeCode.Decimal:
                return(typeof(decimal?));

            case AttributeTypeCode.Double:
                return(typeof(double?));

            case AttributeTypeCode.Integer:
                return(typeof(int?));

            case AttributeTypeCode.Memo:
            case AttributeTypeCode.String:
                return(typeof(string));

            case AttributeTypeCode.Uniqueidentifier:
                return(typeof(Guid));

            default:
                return(typeof(object));
            }
        }
Пример #2
0
            /// <summary>
            /// Gets the sql datatype name for the attribute type.
            /// </summary>
            /// <param name="metadata"></param>
            /// <returns></returns>
            public static string GetSqlDataTypeName(AttributeTypeCode attTypeCode, string attributeTypeDisplayName)
            {
                switch (attTypeCode)
                {
                case AttributeTypeCode.String:
                case AttributeTypeCode.Memo:
                    return("nvarchar");

                case AttributeTypeCode.Lookup:
                case AttributeTypeCode.Owner:
                    return("uniqueidentifier");

                case AttributeTypeCode.Virtual:
                    if (attributeTypeDisplayName != null && attributeTypeDisplayName == AttributeTypeDisplayName.ImageType.Value)
                    {
                        return("image");
                    }
                    return("nvarchar");

                case AttributeTypeCode.Double:
                    return("float");

                case AttributeTypeCode.State:
                case AttributeTypeCode.Status:
                case AttributeTypeCode.Picklist:
                    return("int");

                case AttributeTypeCode.Boolean:
                    return("bit");

                default:
                    return(attributeTypeDisplayName.ToString());
                }
            }
        /// <summary>
        /// Converts a CRM complex type into a <see cref="ComplexType"/>.
        /// </summary>
        /// <param name="typeToConvert">The CRM <c>AttributeTypeCode</c> to be converted.</param>
        /// <param name="objDef">The <see cref="ObjectDefinition"/> that holds the type data.</param>
        /// <returns>A <see cref="ComplexType"/> that contains the converted CRM type information.</returns>
        public static ComplexType ComplexTypeConvert(AttributeTypeCode typeToConvert, ObjectDefinition objDef)
        {
            switch (typeToConvert)
            {
            case AttributeTypeCode.Customer:
            case AttributeTypeCode.Lookup:
            case AttributeTypeCode.Owner:
                return(GetComplexTypeForReference(objDef, "EntityReference"));

            case AttributeTypeCode.Money:
                return(GetComplexTypeForMoney(objDef));

            case AttributeTypeCode.Picklist:
            case AttributeTypeCode.State:
                return(GetComplexTypeForPicklist(objDef));

            case AttributeTypeCode.PartyList:
                return(GetComplexTypeForPartyList(objDef, typeToConvert.ToString()));

            case AttributeTypeCode.Status:
                return(GetComplexTypeForPicklist(objDef));    // Added support for the Status Code field for any entity with a status code setting

            default:
                return(null);
            }
        }
        public bool ValidateOperand2BasedOnOperand1Type(AttributeTypeCode operand1Type, string operand2, bool multiOperand2Values)
        {
            DataTypeValidator validator = new DataTypeValidator();

            string[] operand2Values = operand2.Split('^');

            switch (operand1Type)
            {
            case AttributeTypeCode.State:
            case AttributeTypeCode.Status:
            case AttributeTypeCode.Integer:
            case AttributeTypeCode.Picklist:
                return(validator.IsInteger(operand2Values));

            case AttributeTypeCode.Double:
                return(validator.IsDouble(operand2Values));

            case AttributeTypeCode.Decimal:
                return(validator.IsDecimal(operand2Values));

            case AttributeTypeCode.Lookup:
                return(validator.IsLookup(operand2Values));

            case AttributeTypeCode.DateTime:
                return(validator.IsDate(operand2Values));

            case AttributeTypeCode.String:
            case AttributeTypeCode.Memo:
                return(true);

            default:
                throw new InvalidCastException("Unrecognized Operand1 type");
            }
        }
        /// <summary>
        /// The entry point of the Rule JS generator. This function constructs the If statement and wraps it with a documentready function.
        /// </summary>
        /// <param name="operand1"></param>
        /// <param name="operatorValue"></param>
        /// <param name="operand2"></param>
        /// <param name="operand1Type"></param>
        /// <param name="positiveJson"></param>
        /// <param name="negativeJson"></param>
        /// <returns></returns>
        public string GenerateJavacript(string ruleName, Guid ruleId, string operand1, int operatorValue, string operand2, string positiveJson, string negativeJson)
        {
            try
            {
                AttributeTypeCode operand1Type = GetAttributeType(Service, EntityName, operand1);
                string            ifStatement  = GenerateIfStatement(operand1, operatorValue, operand2, operand1Type);
                string            ifTrueBody   = GenerateIfElseBody(positiveJson, operand1Type);
                string            ifFalseBody  = GenerateIfElseBody(negativeJson, operand1Type);

                string finalOutput = ConstructFinalOutput(operand1, operand1Type, ifStatement, ifTrueBody, ifFalseBody);

                return(finalOutput);
            }

            catch (InvalidCastException castException)
            {
                castException.Data.Add("RuleName", ruleName);
                castException.Data.Add("RuleId", ruleId);
                TracingService.Trace("An invalid cast exception has been caught.");
                throw castException;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// This function injects the if/else statement inside a document ready Jquery function and adds an onchange trigger.
        /// This will allow the logic to run on load and on change of the field (operand1)
        /// </summary>
        /// <param name="operand1"></param>
        /// <param name="ifStatement"></param>
        /// <param name="ifTrueBody"></param>
        /// <param name="ifFalseBody"></param>
        /// <param name="ruleId"></param>
        /// <returns></returns>
        private string ConstructFinalOutput(string operand1, AttributeTypeCode operand1Type, string ifStatement, string ifTrueBody, string ifFalseBody)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(CurrentRuleStartBlock);
            if (operand1Type == AttributeTypeCode.DateTime)
            {
                sb.Append($"$(\"#{operand1}\").parent().on(\"dp.change\",function(){{\n");
            }
            else
            {
                sb.Append($"$(\"#{operand1}\").change(function(){{\n");
            }

            sb.Append($"{ifStatement}{{ \n{ifTrueBody} \n }} \n else {{ \n{ifFalseBody} \n }}\n");
            sb.Append("});//end on change function\n");

            if (operand1Type == AttributeTypeCode.DateTime)
            {
                sb.Append($"$(\"#{operand1}\").parent().trigger(\"dp.change\");\n");
            }
            else
            {
                sb.Append($"$(\"#{operand1}\").change();\n");
            }
            sb.Append(CurrentRuleEndBlock);
            return(sb.ToString());
        }
Пример #7
0
 public AttributeInfo AddPseudoAttribute(string name, AttributeTypeCode attTypeCode, AttributeTypeDisplayName attDisplayName = null)
 {
     var factory = new AttributeInfoFactory();
     var attInfo = factory.CreatePseudo(this.EntityName, name, attTypeCode, attDisplayName);
     this.Attributes.Add(attInfo);
     return attInfo;
 }
Пример #8
0
        public AttributeInfo AddPseudoAttribute(string name, AttributeTypeCode attTypeCode, AttributeTypeDisplayName attDisplayName = null)
        {
            var factory = new AttributeInfoFactory();
            var attInfo = factory.CreatePseudo(this.EntityName, name, attTypeCode, attDisplayName);

            this.Attributes.Add(attInfo);
            return(attInfo);
        }
        public void GetPropertyTypeString(AttributeTypeCode code, string expected)
        {
            var attributeMetadata = new AttributeMetadata();

            typeof(AttributeMetadata).GetProperty("AttributeType").SetValue(attributeMetadata, code);

            Assert.Equal(expected, new PropertyGenerator(attributeMetadata, Template.Property).GetPropertyTypeString());
        }
Пример #10
0
        public object Output(string input, AttributeTypeCode outAttributeTypeCode)
        {
            if (input == null)
            {
                return(null);
            }

            OutputAttributeTypeCode = outAttributeTypeCode;
            return(AmIResponsible ? InnerOutput(input) : NextChain.Output(input, outAttributeTypeCode));
        }
        public CodeTypeReference GetTypeForAttributeType(
            EntityMetadata entityMetadata
            , AttributeMetadata attributeMetadata
            , ICodeGenerationServiceProvider iCodeGenerationServiceProvider
            )
        {
            Type type = typeof(object);

            if (attributeMetadata.AttributeType.HasValue)
            {
                AttributeTypeCode key = attributeMetadata.AttributeType.Value;

                if (key == AttributeTypeCode.PartyList)
                {
                    return(this.BuildCodeTypeReferenceForPartyList(iCodeGenerationServiceProvider));
                }

                if (_attributeTypeMapping.ContainsKey(key))
                {
                    type = _attributeTypeMapping[key];
                }
                else if (attributeMetadata is ImageAttributeMetadata)
                {
                    type = typeof(byte[]);
                }
                else if (attributeMetadata is MultiSelectPicklistAttributeMetadata)
                {
                    type = typeof(OptionSetValueCollection);
                }
                //else
                //{
                //    OptionSetMetadataBase attributeOptionSet = TypeMappingService.GetAttributeOptionSet(attributeMetadata);
                //    if (attributeOptionSet != null)
                //    {
                //        CodeTypeReference codeTypeReference = this.BuildCodeTypeReferenceForOptionSet(attributeMetadata.LogicalName, entityMetadata, attributeMetadata, attributeOptionSet, iCodeGenerationServiceProvider);
                //        if (!codeTypeReference.BaseType.Equals("System.Object"))
                //        {
                //            return codeTypeReference;
                //        }

                //        if (key.Equals(AttributeTypeCode.Picklist) || key.Equals(AttributeTypeCode.Status))
                //        {
                //            type = typeof(OptionSetValue);
                //        }
                //    }
                //}
            }

            if (type.IsValueType)
            {
                type = typeof(Nullable <>).MakeGenericType(type);
            }

            return(TypeMappingService.TypeRef(type));
        }
Пример #12
0
        /// <summary>
        /// Gets the sql datatype name for the attribute type.
        /// </summary>
        /// <param name="metadata"></param>
        /// <returns></returns>
        public static string GetSqlDataTypeName(this AttributeTypeCode attType, AttributeTypeDisplayName attTypeDisplayName)
        {
            switch (attType)
            {
            case AttributeTypeCode.String:
            case AttributeTypeCode.Memo:
            case AttributeTypeCode.EntityName:
                return("nvarchar");

            case AttributeTypeCode.Lookup:
            case AttributeTypeCode.Owner:
            case AttributeTypeCode.Customer:
            case AttributeTypeCode.Uniqueidentifier:
                return("uniqueidentifier");

            case AttributeTypeCode.Virtual:
                if (attTypeDisplayName != null && attTypeDisplayName.Value == AttributeTypeDisplayName.ImageType.Value)
                {
                    return("image");
                }
                return("nvarchar");

            case AttributeTypeCode.Double:
                return("float");

            case AttributeTypeCode.Decimal:
                return("decimal");

            case AttributeTypeCode.State:
            case AttributeTypeCode.Status:
            case AttributeTypeCode.Picklist:
            case AttributeTypeCode.Integer:
                return("int");

            case AttributeTypeCode.Boolean:
            case AttributeTypeCode.ManagedProperty:
                return("bit");

            case AttributeTypeCode.DateTime:
                return("datetime");

            case AttributeTypeCode.Money:
                return("money");

            case AttributeTypeCode.BigInt:
                return("bigint");

            default:
                return(attType.ToString().ToLower());
            }
        }
Пример #13
0
        static Entity AddAttribute(Entity Entity, string attribute, string value)
        {
            Entity            tempEnt  = Entity;
            AttributeTypeCode datatype = Globals.legend[attribute];

            switch (datatype)
            {
            case AttributeTypeCode.BigInt:
                tempEnt[attribute] = BigInteger.Parse(value);
                break;

            case AttributeTypeCode.Boolean:
                tempEnt[attribute] = Boolean.Parse(value);
                break;

            case AttributeTypeCode.DateTime:
                tempEnt[attribute] = Convert.ToDateTime(value);
                break;

            case AttributeTypeCode.Decimal:
                tempEnt[attribute] = Decimal.Parse(value);
                break;

            case AttributeTypeCode.Double:
                tempEnt[attribute] = Double.Parse(value);
                break;

            case AttributeTypeCode.Integer:
                tempEnt[attribute] = int.Parse(value);
                break;

            case AttributeTypeCode.Picklist:
                Dictionary <string, int?> options = GetoptionsetText(attribute);
                tempEnt[attribute] = new OptionSetValue((int)options[value]);
                break;

            case AttributeTypeCode.String:
                tempEnt[attribute] = value;
                break;

            case AttributeTypeCode.Uniqueidentifier:
                tempEnt[attribute] = new Guid(value);
                break;

            default:
                break;
            }
            return(tempEnt);
        }
Пример #14
0
        public bool TryGetAttributeType(string attributeLogicalName, out AttributeTypeCode attributeType)
        {
            attributeType = AttributeTypeCode.Virtual;

            var attributeMetadata = _entityMetadata.Value.Attributes.FirstOrDefault(a => a.LogicalName == attributeLogicalName);

            if (attributeMetadata == null || attributeMetadata.AttributeType == null)
            {
                return(false);
            }

            attributeType = attributeMetadata.AttributeType.Value;

            return(true);
        }
Пример #15
0
        private IFieldExt GetTypedFieldExt(AttributeTypeCode attributeTypeCode)
        {
            switch (attributeTypeCode)
            {
            case AttributeTypeCode.Boolean:
                return(new FieldExt <bool?, Entity>(this.Initial, this.Current, this.LogicalName, this.IgnoreIsSpecifiedProperty));

            case AttributeTypeCode.Lookup:
            case AttributeTypeCode.Customer:
            case AttributeTypeCode.Owner:
                return(new FieldExt <EntityReference, Entity>(this.Initial, this.Current, this.LogicalName, this.IgnoreIsSpecifiedProperty));

            case AttributeTypeCode.DateTime:
                return(new FieldExt <DateTime?, Entity>(this.Initial, this.Current, this.LogicalName, this.IgnoreIsSpecifiedProperty));

            case AttributeTypeCode.Decimal:
                return(new FieldExt <decimal?, Entity>(this.Initial, this.Current, this.LogicalName, this.IgnoreIsSpecifiedProperty));

            case AttributeTypeCode.Double:
                return(new FieldExt <double?, Entity>(this.Initial, this.Current, this.LogicalName, this.IgnoreIsSpecifiedProperty));

            case AttributeTypeCode.Integer:
                return(new FieldExt <int?, Entity>(this.Initial, this.Current, this.LogicalName, this.IgnoreIsSpecifiedProperty));

            case AttributeTypeCode.Money:
                return(new FieldExt <Money, Entity>(this.Initial, this.Current, this.LogicalName, this.IgnoreIsSpecifiedProperty));

            case AttributeTypeCode.String:
                return(new FieldExt <string, Entity>(this.Initial, this.Current, this.LogicalName, this.IgnoreIsSpecifiedProperty));

            case AttributeTypeCode.Picklist:
            case AttributeTypeCode.State:
            case AttributeTypeCode.Status:
                return(new FieldExt <OptionSetValue, Entity>(this.Initial, this.Current, this.LogicalName, this.IgnoreIsSpecifiedProperty));

            case AttributeTypeCode.Memo:
                return(new FieldExt <string, Entity>(this.Initial, this.Current, this.LogicalName, this.IgnoreIsSpecifiedProperty));

            case AttributeTypeCode.PartyList:
                return(new CollectionFieldExt <Entity, Entity>(this.Initial, this.Current, this.LogicalName, this.IgnoreIsSpecifiedProperty));

            case AttributeTypeCode.BigInt:
                return(new FieldExt <long?, Entity>(this.Initial, this.Current, this.LogicalName, this.IgnoreIsSpecifiedProperty));

            default:
                throw new NotImplementedException();
            }
        }
Пример #16
0
        private static object ConvertCrmTypeToDotNetType(AttributeTypeCode typeCode, object value)
        {
            switch (typeCode)
            {
            case AttributeTypeCode.Boolean:
                return(Convert.ToBoolean(value, CultureInfo.InvariantCulture));

            case AttributeTypeCode.Customer:
            case AttributeTypeCode.Lookup:
            case AttributeTypeCode.Money:
            case AttributeTypeCode.Owner:
            case AttributeTypeCode.PartyList:
            case AttributeTypeCode.State:
            case AttributeTypeCode.Status:
            case AttributeTypeCode.Uniqueidentifier:
            case AttributeTypeCode.CalendarRules:
            case AttributeTypeCode.Virtual:
            case AttributeTypeCode.ManagedProperty:
            case AttributeTypeCode.EntityName:
                throw new NotSupportedException();

            case AttributeTypeCode.DateTime:
            case AttributeTypeCode.Decimal:
                return(Convert.ToDecimal(value, CultureInfo.InvariantCulture));

            case AttributeTypeCode.Double:
                return(Convert.ToDouble(value, CultureInfo.InvariantCulture));

            case AttributeTypeCode.Integer:
                return(Convert.ToInt32(value, CultureInfo.InvariantCulture));

            case AttributeTypeCode.Memo:
                return(Convert.ToString(value, CultureInfo.InvariantCulture));

            case AttributeTypeCode.Picklist:
                return(new OptionSetValue(Convert.ToInt32(value, CultureInfo.InvariantCulture)));

            case AttributeTypeCode.String:
                return(Convert.ToString(value, CultureInfo.InvariantCulture));

            case AttributeTypeCode.BigInt:
                return(Convert.ToInt32(value, CultureInfo.InvariantCulture));

            default:
                throw new InvalidOperationException("Unsupported field type: [" + typeCode + "]");
            }
        }
        private CustomFieldDataType MapDynamicsTypeToCampmonType(AttributeTypeCode dynamicsType)
        {
            switch (dynamicsType)
            {
            case AttributeTypeCode.DateTime:
                return(CustomFieldDataType.Date);

            case AttributeTypeCode.BigInt:
            case AttributeTypeCode.Double:
            case AttributeTypeCode.Integer:
            case AttributeTypeCode.Money:
                return(CustomFieldDataType.Number);

            default:
                return(CustomFieldDataType.Text);
            }
        }
Пример #18
0
        /// <summary>
        /// Converts (parses) the supplied text value into a value compatible with <see cref="type"/>
        /// </summary>
        /// <param name="value"></param>
        /// <param name="type"></param>
        /// <returns>A value or null.</returns>
        private object ConvertValue(string value, AttributeTypeCode type)
        {
            if (value == null)
            {
                return(null);
            }
            try
            {
                switch (type)
                {
                case AttributeTypeCode.BigInt:
                    return(Int64.Parse(value));

                case AttributeTypeCode.Boolean:
                    return(Boolean.Parse(value));

                case AttributeTypeCode.DateTime:
                    return(DateTime.Parse(value));

                case AttributeTypeCode.Decimal:
                    return(Decimal.Parse(value));

                case AttributeTypeCode.Double:
                    return(double.Parse(value));

                case AttributeTypeCode.Integer:
                    return(int.Parse(value));

                case AttributeTypeCode.Memo:
                case AttributeTypeCode.String:
                    return(value as string);

                case AttributeTypeCode.Money:
                    return(new Money(Decimal.Parse(value)));

                case AttributeTypeCode.Picklist:
                    return(new OptionSetValue(int.Parse(value)));

                default:
                    return(null);
                }
            } catch (FormatException)
            {
                return(null);
            }
        }
        private string GenerateJSArray(string operand2, AttributeTypeCode operand1Type)
        {
            string[] operand2Values = operand2.Split('^');
            if (!ValidateOperand2BasedOnOperand1Type(operand1Type, operand2, true))
            {
                throw new InvalidCastException("Operand 2 value types don't match operand 1 type");
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("[");
            foreach (string s in operand2Values)
            {
                sb.Append($"\"{s}\",");
            }
            sb.Append("]");
            return(sb.ToString());
        }
Пример #20
0
        string GetDataType(AttributeTypeCode atc)
        {
            var dataType = "string";

            switch (atc)
            {
            case AttributeTypeCode.Virtual:
            case AttributeTypeCode.State:
            case AttributeTypeCode.Integer:
            case AttributeTypeCode.BigInt:
            case AttributeTypeCode.Money:
            case AttributeTypeCode.Decimal:
            case AttributeTypeCode.Double:
                dataType = "number";
                break;
            }
            LogMessage(string.Format("Get attribute script datatype: {0} => {1}", atc.ToString(), dataType), EnumLoggingLevel.Verbose);
            return(dataType);
        }
Пример #21
0
        public CrmAttribute(string schemaName, string friendlyName, AttributeTypeCode type,
                            bool validForCreate, bool validForUpdate, bool validForRead, bool isPrimaryId)
        {
            if (schemaName == null)
            {
                throw new ArgumentNullException("schemaName");
            }
            else if (friendlyName == null)
            {
                throw new ArgumentNullException("friendlyName");
            }

            m_schemaName     = schemaName;
            m_friendlyName   = friendlyName;
            m_attributeType  = type;
            m_validForCreate = validForCreate;
            m_validForRead   = validForRead;
            m_validForUpdate = validForUpdate;
            m_isPrimaryId    = isPrimaryId;
        }
Пример #22
0
        public static string ToWebApiValue(AttributeTypeCode attributeType, object value)
        {
            if (value == null)
            {
                return("null");
            }

            switch (attributeType)
            {
            case AttributeTypeCode.Boolean:
                return(value.ToString().ToLowerInvariant());

            case AttributeTypeCode.Decimal:
            case AttributeTypeCode.Double:
            case AttributeTypeCode.Integer:
            case AttributeTypeCode.Money:
            case AttributeTypeCode.Uniqueidentifier:
            case AttributeTypeCode.BigInt:
                return(value.ToString());

            case AttributeTypeCode.Picklist:
            case AttributeTypeCode.Status:
            case AttributeTypeCode.State:
                return(((int)value).ToString());

            case AttributeTypeCode.Customer:
            case AttributeTypeCode.Lookup:
            case AttributeTypeCode.Owner:
                return(value.ToString());

            case AttributeTypeCode.DateTime:
                return(((DateTime)value).ToString("yyyy/MM/ddTHH:mm:ss"));

            case AttributeTypeCode.Memo:
            case AttributeTypeCode.String:
            case AttributeTypeCode.EntityName:
                return($"'{value}'");
            }

            return(string.Empty);
        }
Пример #23
0
        private void ReadAttributes(byte[] stream, uint maxLength, int offset)
        {
            int offsetCpy = offset;

            while (true)
            {
                AttributeTypeCode attType = AttributeRecord.GetTypeCode(stream, offsetCpy);
                if (attType == AttributeTypeCode.EndOfAttributes)
                {
                    break;
                }

                uint length = AttributeRecord.GetRecordLength(stream, offsetCpy);

                AttributeRecord attributeRecord = AttributeRecord.ReadSingleAttribute(stream, (int)length, offsetCpy);
                attributeRecord.RecordOwner = MftSegmentReference;
                attributes.Add(attributeRecord);

                offsetCpy += attributeRecord.RecordLength;
            }
        }
 /// <summary>
 /// Converts a CRM complex type into a <see cref="ComplexType"/>.
 /// </summary>
 /// <param name="typeToConvert">The CRM <c>AttributeTypeCode</c> to be converted.</param>
 /// <param name="objDef">The <see cref="ObjectDefinition"/> that holds the type data.</param>
 /// <returns>A <see cref="ComplexType"/> that contains the converted CRM type information.</returns>
 public static ComplexType ComplexTypeConvert(AttributeTypeCode typeToConvert, ObjectDefinition objDef)
 {
     switch (typeToConvert)
     {
         case AttributeTypeCode.Customer:
         case AttributeTypeCode.Lookup:
         case AttributeTypeCode.Owner:
             return GetComplexTypeForReference(objDef, "EntityReference");
         case AttributeTypeCode.Money:
             return GetComplexTypeForMoney(objDef);
         case AttributeTypeCode.Picklist:
         case AttributeTypeCode.State:
             return GetComplexTypeForPicklist(objDef);
         case AttributeTypeCode.PartyList:
             return GetComplexTypeForPartyList(objDef, typeToConvert.ToString());
         case AttributeTypeCode.Status:
             return GetComplexTypeForPicklist(objDef); // Added support for the Status Code field for any entity with a status code setting
         default:
             return null;
     }
 }
Пример #25
0
        private void GetAttributeByFilter()
        {
            IEnumerable <AttributeMetadata> result = _repository.GetAttribute(Entity, CustomOnly.ToBool(), ExcludeManaged.ToBool(), IncludeLinked.ToBool());

            if (!string.IsNullOrWhiteSpace(Name))
            {
                WildcardPattern includePattern = new WildcardPattern(Name, WildcardOptions.IgnoreCase);
                result = result.Where(a => includePattern.IsMatch(a.LogicalName));
            }
            if (!string.IsNullOrWhiteSpace(Exclude))
            {
                WildcardPattern excludePattern = new WildcardPattern(Exclude, WildcardOptions.IgnoreCase);
                result = result.Where(a => !excludePattern.IsMatch(a.LogicalName));
            }

            if (!string.IsNullOrWhiteSpace(AttributeType))
            {
                if (CrmVersionManager.IsSupported(CrmVersion.CRM2013_RTM))
                {
                    string attributeTypeName = AttributeType;
                    if (!attributeTypeName.EndsWith("Type", StringComparison.InvariantCultureIgnoreCase))
                    {
                        attributeTypeName = string.Format("{0}Type", attributeTypeName);
                    }
                    result = result.Where(a => a.AttributeTypeName == attributeTypeName);
                }
                else
                {
                    AttributeTypeCode typeCode = AttributeTypeCode.String;
                    if (Enum.TryParse <AttributeTypeCode>(AttributeType, true, out typeCode))
                    {
                        result = result.Where(a => a.AttributeType == typeCode);
                    }
                }
            }

            result = result.OrderBy(a => a.LogicalName);

            WriteObject(result, true);
        }
Пример #26
0
        public CrmAttribute(AttributeMetadata md, bool isPrimaryId)
        {
            if (md == null)
            {
                throw new ArgumentNullException("md");
            }

            m_schemaName = md.LogicalName;
            if (md.DisplayName.LocalizedLabels.Count == 0)
            {
                m_friendlyName = md.LogicalName;
            }
            else
            {
                m_friendlyName = md.DisplayName.UserLocalizedLabel.Label;
            }

            m_attributeType  = md.AttributeType.Value;
            m_validForCreate = md.IsValidForCreate.Value;
            m_validForRead   = md.IsValidForUpdate.Value;
            m_validForUpdate = md.IsValidForUpdate.Value;
            m_isPrimaryId    = isPrimaryId;
        }
 private CrmMappingAttribute(string attributeName, AttributeTypeCode attributeType)
 {
     AttributeName = attributeName;
     AttributeType = attributeType;
 }
Пример #28
0
        private Type GetAttributeType(AttributeTypeCode? attributeType)
        {
            if (attributeType == null)
            {
                return null;
            }

            switch (attributeType)
            {
                case AttributeTypeCode.Customer:
                case AttributeTypeCode.Lookup:
                case AttributeTypeCode.Owner:
                    return typeof(EntityReference);
                case AttributeTypeCode.Money:
                    return typeof(Money);
                case AttributeTypeCode.Picklist:
                case AttributeTypeCode.State:
                case AttributeTypeCode.Status:
                    return typeof(OptionSetValue);
                default:
                    return null;
            }
        }
Пример #29
0
 /// <summary>
 /// Gets the sql datatype name for the attribute type. 
 /// </summary>
 /// <param name="metadata"></param>
 /// <returns></returns>
 public static string GetSqlDataTypeName(AttributeTypeCode attTypeCode, string attributeTypeDisplayName)
 {
     switch (attTypeCode)
     {
         case AttributeTypeCode.String:
         case AttributeTypeCode.Memo:
             return "nvarchar";
         case AttributeTypeCode.Lookup:
         case AttributeTypeCode.Owner:
             return "uniqueidentifier";
         case AttributeTypeCode.Virtual:
             if (attributeTypeDisplayName != null && attributeTypeDisplayName == AttributeTypeDisplayName.ImageType.Value)
             {
                 return "image";
             }
             return "nvarchar";
         case AttributeTypeCode.Double:
             return "float";
         case AttributeTypeCode.State:
         case AttributeTypeCode.Status:
         case AttributeTypeCode.Picklist:
             return "int";
         case AttributeTypeCode.Boolean:
             return "bit";
         default:
             return attributeTypeDisplayName.ToString();
     }
 }
Пример #30
0
        private AttributeTypeDisplayName GetAttributeTypeDisplayName(AttributeTypeCode attTypeCode)
        {
            AttributeTypeDisplayName displayType = null;
            switch (attTypeCode)
            {
                case AttributeTypeCode.BigInt:
                    displayType = AttributeTypeDisplayName.BigIntType;
                    break;

                case AttributeTypeCode.Boolean:
                    displayType = AttributeTypeDisplayName.BooleanType;
                    break;

                case AttributeTypeCode.CalendarRules:
                    displayType = AttributeTypeDisplayName.CalendarRulesType;
                    break;

                case AttributeTypeCode.Customer:
                    displayType = AttributeTypeDisplayName.CustomerType;
                    break;

                case AttributeTypeCode.DateTime:
                    displayType = AttributeTypeDisplayName.DateTimeType;
                    break;

                case AttributeTypeCode.Decimal:
                    displayType = AttributeTypeDisplayName.DecimalType;
                    break;

                case AttributeTypeCode.Double:
                    displayType = AttributeTypeDisplayName.DoubleType;
                    break;

                case AttributeTypeCode.EntityName:
                    displayType = AttributeTypeDisplayName.EntityNameType;
                    break;

                case AttributeTypeCode.Integer:
                    displayType = AttributeTypeDisplayName.IntegerType;
                    break;

                case AttributeTypeCode.Lookup:
                    displayType = AttributeTypeDisplayName.LookupType;
                    break;

                case AttributeTypeCode.ManagedProperty:
                    displayType = AttributeTypeDisplayName.ManagedPropertyType;
                    break;

                case AttributeTypeCode.Memo:
                    displayType = AttributeTypeDisplayName.MemoType;
                    break;

                case AttributeTypeCode.Money:
                    displayType = AttributeTypeDisplayName.MoneyType;
                    break;

                case AttributeTypeCode.Owner:
                    displayType = AttributeTypeDisplayName.OwnerType;
                    break;

                case AttributeTypeCode.PartyList:
                    displayType = AttributeTypeDisplayName.PartyListType;
                    break;

                case AttributeTypeCode.Picklist:
                    displayType = AttributeTypeDisplayName.PicklistType;
                    break;

                case AttributeTypeCode.State:
                    displayType = AttributeTypeDisplayName.StateType;
                    break;

                case AttributeTypeCode.Status:
                    displayType = AttributeTypeDisplayName.StatusType;
                    break;

                case AttributeTypeCode.String:
                    displayType = AttributeTypeDisplayName.StringType;
                    break;

                case AttributeTypeCode.Uniqueidentifier:
                    displayType = AttributeTypeDisplayName.UniqueidentifierType;
                    break;

                case AttributeTypeCode.Virtual:
                    displayType = AttributeTypeDisplayName.VirtualType;
                    break;
            }

            return displayType;
        }
        public static List <string> GetValidTypes(AttributeTypeCode typeCode)
        {
            var list = new List <string>();

            switch (typeCode)
            {
            case AttributeTypeCode.Integer:
            case AttributeTypeCode.BigInt:
                list.Add(WholeNumber);
                list.Add(WholeNumberNegative);
                list.Add(WholeNumberOneToTen);
                list.Add(WholeNumberPositive);
                list.Add(Age);
                break;

            case AttributeTypeCode.DateTime:
                list.Add(Date);
                list.Add(DateFuture);
                list.Add(DatePast);
                list.Add(DateFuture30);
                list.Add(DatePast30);
                break;

            case AttributeTypeCode.Decimal:
                list.Add(Decimal);
                break;

            case AttributeTypeCode.Double:
                list.Add(Double);
                list.Add(WholeNumber);
                list.Add(WholeNumberNegative);
                list.Add(WholeNumberOneToTen);
                list.Add(WholeNumberPositive);
                break;

            case AttributeTypeCode.Owner:
                list.Add(CurrentUser);
                list.Add(RandomUser);
                break;

            case AttributeTypeCode.Money:
                list.Add(Money);
                break;

            case AttributeTypeCode.Picklist:
                list.Add(OptionSet);
                break;

            case AttributeTypeCode.Lookup:
                list.Add(Lookup);
                break;

            case AttributeTypeCode.Customer:
                list.Add(Customer);
                list.Add(Contact);
                list.Add(Account);
                break;

            case AttributeTypeCode.String:
                list.Add(LoremSmall);
                list.Add(LoremBig);
                list.Add(Name);
                list.Add(FirstName);
                list.Add(LastName);
                list.Add(CompanyNames);
                list.Add(Email);
                list.Add(PhoneNumber);
                list.Add(Country);
                list.Add(City);
                list.Add(Street);
                list.Add(NumberStr);
                break;

            case AttributeTypeCode.Boolean:
                list.Add(Boolean);
                break;

            default:
                throw new NotImplementedException($"Attributes of type \"{typeCode}\" is not yet supported by this tool :(");
            }

            return(list);
        }
Пример #32
0
        protected object GetValue(JToken token, AttributeTypeCode attributeType)
        {
            var value = token.ToObject <object>();

            if (value == null)
            {
                return(null);
            }

            if (attributeType == AttributeTypeCode.Customer || attributeType == AttributeTypeCode.Lookup || attributeType == AttributeTypeCode.Owner)
            {
                EntityReference entityReference;

                if (TryGetEntityReference(value, out entityReference))
                {
                    return(entityReference);
                }

                throw new FormatException("Unable to convert value {0} for attribute {1} to {2}.".FormatWith(value, Attribute.LogicalName, typeof(EntityReference)));
            }

            // Option set values will be in Int64 form from the JSON deserialization -- convert those to OptionSetValues
            // for option set attributes.
            if (attributeType == AttributeTypeCode.EntityName || attributeType == AttributeTypeCode.Picklist || attributeType == AttributeTypeCode.State || attributeType == AttributeTypeCode.Status)
            {
                return(new OptionSetValue(Convert.ToInt32(value)));
            }

            if (attributeType == AttributeTypeCode.Memo || attributeType == AttributeTypeCode.String)
            {
                return(value is string?value : value.ToString());
            }

            if (attributeType == AttributeTypeCode.BigInt)
            {
                return(Convert.ToInt64(value));
            }

            if (attributeType == AttributeTypeCode.Boolean)
            {
                return(Convert.ToBoolean(value));
            }

            if (attributeType == AttributeTypeCode.DateTime)
            {
                var dateTimeValue = Convert.ToDateTime(value);

                return(dateTimeValue.Kind == DateTimeKind.Utc ? dateTimeValue : dateTimeValue.ToUniversalTime());
            }

            if (attributeType == AttributeTypeCode.Decimal)
            {
                return(Convert.ToDecimal(value));
            }

            if (attributeType == AttributeTypeCode.Double)
            {
                return(Convert.ToDouble(value));
            }

            if (attributeType == AttributeTypeCode.Integer)
            {
                return(Convert.ToInt32(value));
            }

            if (attributeType == AttributeTypeCode.Money)
            {
                return(new Money(Convert.ToDecimal(value)));
            }

            if (attributeType == AttributeTypeCode.Uniqueidentifier)
            {
                return(value is Guid ? value : new Guid(value.ToString()));
            }

            return(value);
        }
 /// <summary>
 /// Converts a CRM <c>AttributeType</c> into a simple .NET type.
 /// </summary>
 /// <param name="typeToConvert">The CRM <c>AttributeType</c> to be converted.</param>
 /// <returns>A .NET <see cref="Type"/> that represents the CRM type.</returns>
 public static Type SimpleTypeConvert(AttributeTypeCode typeToConvert)
 {
     switch (typeToConvert)
     {
         case AttributeTypeCode.Boolean:
             return typeof(bool?);
         case AttributeTypeCode.DateTime:
             return typeof(DateTime?);
         case AttributeTypeCode.Decimal:
             return typeof(decimal?);
         case AttributeTypeCode.Double:
             return typeof(double?);
         case AttributeTypeCode.Integer:
             return typeof(int?);
         case AttributeTypeCode.Memo:
         case AttributeTypeCode.String:
             return typeof(string);
         case AttributeTypeCode.Uniqueidentifier:
             return typeof(Guid);
         default:
             return typeof(object);
     }
 }
Пример #34
0
        public static OperatorItem[] GetConditionsByAttributeType(AttributeTypeCode valueType)
        {
            var validConditionsList = new List<OperatorItem>
            {
                new OperatorItem(ConditionOperator.Equal),
                new OperatorItem(ConditionOperator.NotEqual),
                new OperatorItem(ConditionOperator.In),
                new OperatorItem(ConditionOperator.NotIn),
                new OperatorItem(ConditionOperator.Null),
                new OperatorItem(ConditionOperator.NotNull)
            };

            if (valueType != AttributeTypeCode.Boolean &&
                valueType != AttributeTypeCode.DateTime &&
                valueType != AttributeTypeCode.Integer &&
                valueType != AttributeTypeCode.State &&
                valueType != AttributeTypeCode.Status &&
                valueType != AttributeTypeCode.Picklist &&
                valueType != AttributeTypeCode.BigInt &&
                valueType != AttributeTypeCode.Decimal &&
                valueType != AttributeTypeCode.Double &&
                valueType != AttributeTypeCode.Money &&
                valueType != AttributeTypeCode.Money &&
                valueType != AttributeTypeCode.Lookup &&
                valueType != AttributeTypeCode.Customer &&
                valueType != AttributeTypeCode.Owner &&
                valueType != AttributeTypeCode.Uniqueidentifier)
            {
                validConditionsList.Add(new OperatorItem(ConditionOperator.BeginsWith));
                validConditionsList.Add(new OperatorItem(ConditionOperator.DoesNotBeginWith));
                validConditionsList.Add(new OperatorItem(ConditionOperator.Contains));
                validConditionsList.Add(new OperatorItem(ConditionOperator.DoesNotContain));
                validConditionsList.Add(new OperatorItem(ConditionOperator.EndsWith));
                validConditionsList.Add(new OperatorItem(ConditionOperator.DoesNotEndWith));
                validConditionsList.Add(new OperatorItem(ConditionOperator.Like));
                validConditionsList.Add(new OperatorItem(ConditionOperator.NotLike));
            }
            if (valueType == AttributeTypeCode.DateTime ||
                valueType == AttributeTypeCode.Integer ||
                valueType == AttributeTypeCode.State ||
                valueType == AttributeTypeCode.Status ||
                valueType == AttributeTypeCode.Picklist ||
                valueType == AttributeTypeCode.BigInt ||
                valueType == AttributeTypeCode.Decimal ||
                valueType == AttributeTypeCode.Double ||
                valueType == AttributeTypeCode.Money ||
                valueType == AttributeTypeCode.Lookup ||
                valueType == AttributeTypeCode.Customer ||
                valueType == AttributeTypeCode.Owner ||
                valueType == AttributeTypeCode.Uniqueidentifier)
            {
                validConditionsList.Add(new OperatorItem(ConditionOperator.Between));
                validConditionsList.Add(new OperatorItem(ConditionOperator.NotBetween));
                validConditionsList.Add(new OperatorItem(ConditionOperator.GreaterThan));
                validConditionsList.Add(new OperatorItem(ConditionOperator.GreaterEqual));
                validConditionsList.Add(new OperatorItem(ConditionOperator.LessThan));
                validConditionsList.Add(new OperatorItem(ConditionOperator.LessEqual));
            }
            switch (valueType)
            {
                case AttributeTypeCode.DateTime:
                    validConditionsList.Add(new OperatorItem(ConditionOperator.InFiscalPeriod));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.InFiscalPeriodAndYear));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.InFiscalYear));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.InOrAfterFiscalPeriodAndYear));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.InOrBeforeFiscalPeriodAndYear));

                    validConditionsList.Add(new OperatorItem(ConditionOperator.Last7Days));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.LastFiscalPeriod));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.LastFiscalYear));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.LastMonth));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.LastWeek));

                    validConditionsList.Add(new OperatorItem(ConditionOperator.LastXDays));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.LastXFiscalPeriods));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.LastXFiscalYears));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.LastXHours));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.LastXMonths));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.LastXWeeks));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.LastXYears));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.LastYear));

                    validConditionsList.Add(new OperatorItem(ConditionOperator.Next7Days));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.NextFiscalPeriod));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.NextFiscalYear));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.NextMonth));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.NextWeek));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.NextXDays));

                    validConditionsList.Add(new OperatorItem(ConditionOperator.NextXFiscalPeriods));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.NextXFiscalYears));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.NextXHours));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.NextXMonths));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.NextXWeeks));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.NextXYears));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.NextYear));

                    validConditionsList.Add(new OperatorItem(ConditionOperator.OlderThanXMonths));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.On));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.OnOrAfter));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.OnOrBefore));

                    validConditionsList.Add(new OperatorItem(ConditionOperator.ThisFiscalPeriod));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.ThisFiscalYear));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.ThisMonth));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.ThisWeek));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.ThisYear));

                    validConditionsList.Add(new OperatorItem(ConditionOperator.Today));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.Tomorrow));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.Yesterday));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.NotOn));

                    break;
                case AttributeTypeCode.Uniqueidentifier:
                    validConditionsList.Add(new OperatorItem(ConditionOperator.Above));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.AboveOrEqual));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.Under));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.UnderOrEqual));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.NotUnder));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.EqualBusinessId));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.EqualUserId));
                    break;
                case AttributeTypeCode.Lookup:
                case AttributeTypeCode.Customer:
                case AttributeTypeCode.Owner:
                    validConditionsList.Add(new OperatorItem(ConditionOperator.EqualBusinessId));
                    validConditionsList.Add(new OperatorItem(ConditionOperator.EqualUserId));
                    break;
            }
            return validConditionsList.ToArray();
        }
        /// <summary>
        /// Generate a string out of the list of actions stored in the actionJson string.
        /// Generates the proper javascript call based on the action type.
        /// </summary>
        /// <param name="actionsJson">A json array of the actions</param>
        /// <returns></returns>
        private string GenerateIfElseBody(string actionsJson, AttributeTypeCode operand1Type)
        {
            StringBuilder sb = new StringBuilder();
            JSONConverter <List <RuleAction> > converter = new JSONConverter <List <RuleAction> >();

            try
            {
                List <RuleAction> actions = converter.Deserialize(actionsJson);
                foreach (RuleAction action in actions)
                {
                    string targetName = action.target; // can be a section or a field
                    string message    = action.message;
                    string value      = action.value;

                    switch (action.type)
                    {
                    case "Show Field":
                        sb.Append($"setVisible(\"{targetName}\",true);\n");
                        break;

                    case "Hide Field":
                        sb.Append($"setVisible(\"{targetName}\",false);\n");
                        break;

                    case "Enable Field":
                        sb.Append($"setDisabled(\"{targetName}\",false);\n");
                        break;

                    case "Disable Field":
                        sb.Append($"setDisabled(\"{targetName}\",true);\n");
                        break;

                    case "Set Field Value":
                        AttributeTypeCode actionTargetType = GetAttributeType(Service, EntityName, targetName);
                        bool nonTextualValue = actionTargetType == AttributeTypeCode.Picklist || actionTargetType == AttributeTypeCode.Boolean || actionTargetType == AttributeTypeCode.Money || actionTargetType == AttributeTypeCode.Integer || actionTargetType == AttributeTypeCode.Double || actionTargetType == AttributeTypeCode.Decimal;
                        if (nonTextualValue)
                        {
                            sb.Append($"setValue(\"{targetName}\",{value});\n");
                        }
                        else
                        {
                            sb.Append($"setValue(\"{targetName}\",\"{value}\");\n");
                        }
                        break;

                    case "Make Required":
                        sb.Append($"setRequired(\"{targetName}\",true,\"{message}\");\n");
                        break;

                    case "Make not Required":
                        sb.Append($"setRequired(\"{targetName}\",false);\n");
                        break;

                    case "Prevent Past Date":
                        sb.Append($"blockPastDate(\"{targetName}\",\"{message}\");\n");
                        break;

                    case "Prevent Future Date":
                        sb.Append($"blockFutureDate(\"{targetName}\",\"{message}\");\n");
                        break;

                    case "Show Section":
                        sb.Append($"setSectionVisible(\"{targetName}\",true);\n");
                        break;

                    case "Hide Section":
                        sb.Append($"setSectionVisible(\"{targetName}\",false);\n");
                        break;

                    case "Show Tab":
                        sb.Append($"setTabVisible(\"{targetName}\",true);\n");
                        break;

                    case "Hide Tab":
                        sb.Append($"setTabVisible(\"{targetName}\",false);\n");
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(sb.ToString());
        }
        /// <summary>
        /// Based on the operand and operator types, generate the proper If statement.
        /// </summary>
        /// <param name="operand1"></param>
        /// <param name="operatorValue"></param>
        /// <param name="operand2"></param>
        /// <param name="operand1Type"></param>
        /// <returns></returns>
        private string GenerateIfStatement(string operand1, int operatorValue, string operand2, AttributeTypeCode operand1Type)
        {
            string operatorSymbol = "";
            string ifStatement    = "";
            string operand2JsArray;

            switch (operatorValue)
            {
            case 497060000:
                operatorSymbol = "==";
                break;

            case 497060001:
                operatorSymbol = "!=";
                break;

            case 497060002:
                operatorSymbol = "<";
                break;

            case 497060006:
                operatorSymbol = "<=";
                break;

            case 497060003:
                operatorSymbol = ">";
                break;

            case 497060004:
                operatorSymbol = ">=";
                break;

            case 497060005:     // contains
                ifStatement = $"if (Boolean(getFieldValue(\"{operand1}\")) &&getFieldValue(\"{operand1}\")!=\"\" )";
                return(ifStatement);

            case 497060007:     // doesn't contain
                ifStatement = $"if (!Boolean(getFieldValue(\"{operand1}\")))";
                return(ifStatement);

            case 497060008:     //in
                operand2JsArray = GenerateJSArray(operand2, operand1Type);
                ifStatement     = $"if ({operand2JsArray}.includes(getFieldValue(\"{operand1}\")))";
                return(ifStatement);

            case 497060009:     // not in
                operand2JsArray = GenerateJSArray(operand2, operand1Type);
                ifStatement     = $"if (!{operand2JsArray}.includes(getFieldValue(\"{operand1}\")))";
                return(ifStatement);

            default:
                throw new InvalidOperationException($"Unrecognized Operator Value: {operatorValue}");
            }

            DataTypeValidator validator = new DataTypeValidator();

            switch (operand1Type)
            {
            case AttributeTypeCode.DateTime:
                //make sure operand 2 is valid date
                if (validator.IsDate(operand2))
                {
                    string date1 = $"new Date(getFieldValue(\"{operand1}\"))";
                    string date2 = $"new Date(\"{operand2}\")";
                    ifStatement = $"if ({date1} {operatorSymbol} {date2})";
                }
                else
                {
                    throw new InvalidCastException("Operand 2 Should be a formatted as a datetime");
                }
                break;

            case AttributeTypeCode.Boolean:
                if (validator.IsBoolean(operand2))
                {
                    ifStatement = $"if (getFieldValue(\"{operand1}\") {operatorSymbol} {operand2})";
                }
                else
                {
                    throw new InvalidCastException("Operand 2 Should be a boolean (true or false)");
                }
                break;

            case AttributeTypeCode.State:
            case AttributeTypeCode.Status:
            case AttributeTypeCode.Integer:
            case AttributeTypeCode.Picklist:
                if (validator.IsInteger(operand2))
                {
                    ifStatement = $"if (getFieldValue(\"{operand1}\") {operatorSymbol} {operand2})";
                }
                else
                {
                    throw new InvalidCastException("Operand 2 Should be an integer");
                }
                break;

            case AttributeTypeCode.Double:
                if (validator.IsDouble(operand2))
                {
                    ifStatement = $"if (getFieldValue(\"{operand1}\") {operatorSymbol} {operand2})";
                }
                else
                {
                    throw new InvalidCastException("Operand 2 Should be an double");
                }
                break;

            case AttributeTypeCode.Decimal:
                if (validator.IsDecimal(operand2))
                {
                    ifStatement = $"if (getFieldValue(\"{operand1}\") {operatorSymbol} {operand2})";
                }
                else
                {
                    throw new InvalidCastException("Operand 2 Should be decimal");
                }
                break;

            case AttributeTypeCode.Lookup:
                if (validator.IsLookup(operand2))
                {
                    ifStatement = $"if (getFieldValue(\"{operand1}\") {operatorSymbol} \"{operand2}\")";
                }
                else
                {
                    throw new InvalidCastException("Operand 2 Should be a GUID");
                }
                break;

            default:     // everything else is handled as string
                ifStatement = $"if (getFieldValue(\"{operand1}\") {operatorSymbol} \"{operand2}\")";
                break;
            }

            return(ifStatement);
        }
 public MockOption(AttributeTypeCode attributeTypeCode, List <BaseMock> mocks)
 {
     AttributeTypeCode = attributeTypeCode;
     Mocks             = mocks;
 }
 public AttributeMetadataAttribute(AttributeTypeCode type)
 {
     Type = type;
 }
Пример #39
0
        public static OperatorItem[] GetConditionsByAttributeType(AttributeTypeCode valueType)
        {
            var validConditionsList = new List <OperatorItem>
            {
                new OperatorItem(ConditionOperator.Equal),
                new OperatorItem(ConditionOperator.NotEqual),
                new OperatorItem(ConditionOperator.In),
                new OperatorItem(ConditionOperator.NotIn),
                new OperatorItem(ConditionOperator.Null),
                new OperatorItem(ConditionOperator.NotNull)
            };

            if (valueType != AttributeTypeCode.Boolean &&
                valueType != AttributeTypeCode.DateTime &&
                valueType != AttributeTypeCode.Integer &&
                valueType != AttributeTypeCode.State &&
                valueType != AttributeTypeCode.Status &&
                valueType != AttributeTypeCode.Picklist &&
                valueType != AttributeTypeCode.BigInt &&
                valueType != AttributeTypeCode.Decimal &&
                valueType != AttributeTypeCode.Double &&
                valueType != AttributeTypeCode.Money &&
                valueType != AttributeTypeCode.Money &&
                valueType != AttributeTypeCode.Lookup &&
                valueType != AttributeTypeCode.Customer &&
                valueType != AttributeTypeCode.Owner &&
                valueType != AttributeTypeCode.Uniqueidentifier)
            {
                validConditionsList.Add(new OperatorItem(ConditionOperator.BeginsWith));
                validConditionsList.Add(new OperatorItem(ConditionOperator.DoesNotBeginWith));
                validConditionsList.Add(new OperatorItem(ConditionOperator.Contains));
                validConditionsList.Add(new OperatorItem(ConditionOperator.DoesNotContain));
                validConditionsList.Add(new OperatorItem(ConditionOperator.EndsWith));
                validConditionsList.Add(new OperatorItem(ConditionOperator.DoesNotEndWith));
                validConditionsList.Add(new OperatorItem(ConditionOperator.Like));
                validConditionsList.Add(new OperatorItem(ConditionOperator.NotLike));
            }
            if (valueType == AttributeTypeCode.DateTime ||
                valueType == AttributeTypeCode.Integer ||
                valueType == AttributeTypeCode.State ||
                valueType == AttributeTypeCode.Status ||
                valueType == AttributeTypeCode.Picklist ||
                valueType == AttributeTypeCode.BigInt ||
                valueType == AttributeTypeCode.Decimal ||
                valueType == AttributeTypeCode.Double ||
                valueType == AttributeTypeCode.Money ||
                valueType == AttributeTypeCode.Lookup ||
                valueType == AttributeTypeCode.Customer ||
                valueType == AttributeTypeCode.Owner ||
                valueType == AttributeTypeCode.Uniqueidentifier)
            {
                validConditionsList.Add(new OperatorItem(ConditionOperator.Between));
                validConditionsList.Add(new OperatorItem(ConditionOperator.NotBetween));
                validConditionsList.Add(new OperatorItem(ConditionOperator.GreaterThan));
                validConditionsList.Add(new OperatorItem(ConditionOperator.GreaterEqual));
                validConditionsList.Add(new OperatorItem(ConditionOperator.LessThan));
                validConditionsList.Add(new OperatorItem(ConditionOperator.LessEqual));
            }
            switch (valueType)
            {
            case AttributeTypeCode.DateTime:
                validConditionsList.Add(new OperatorItem(ConditionOperator.InFiscalPeriod));
                validConditionsList.Add(new OperatorItem(ConditionOperator.InFiscalPeriodAndYear));
                validConditionsList.Add(new OperatorItem(ConditionOperator.InFiscalYear));
                validConditionsList.Add(new OperatorItem(ConditionOperator.InOrAfterFiscalPeriodAndYear));
                validConditionsList.Add(new OperatorItem(ConditionOperator.InOrBeforeFiscalPeriodAndYear));

                validConditionsList.Add(new OperatorItem(ConditionOperator.Last7Days));
                validConditionsList.Add(new OperatorItem(ConditionOperator.LastFiscalPeriod));
                validConditionsList.Add(new OperatorItem(ConditionOperator.LastFiscalYear));
                validConditionsList.Add(new OperatorItem(ConditionOperator.LastMonth));
                validConditionsList.Add(new OperatorItem(ConditionOperator.LastWeek));

                validConditionsList.Add(new OperatorItem(ConditionOperator.LastXDays));
                validConditionsList.Add(new OperatorItem(ConditionOperator.LastXFiscalPeriods));
                validConditionsList.Add(new OperatorItem(ConditionOperator.LastXFiscalYears));
                validConditionsList.Add(new OperatorItem(ConditionOperator.LastXHours));
                validConditionsList.Add(new OperatorItem(ConditionOperator.LastXMonths));
                validConditionsList.Add(new OperatorItem(ConditionOperator.LastXWeeks));
                validConditionsList.Add(new OperatorItem(ConditionOperator.LastXYears));
                validConditionsList.Add(new OperatorItem(ConditionOperator.LastYear));

                validConditionsList.Add(new OperatorItem(ConditionOperator.Next7Days));
                validConditionsList.Add(new OperatorItem(ConditionOperator.NextFiscalPeriod));
                validConditionsList.Add(new OperatorItem(ConditionOperator.NextFiscalYear));
                validConditionsList.Add(new OperatorItem(ConditionOperator.NextMonth));
                validConditionsList.Add(new OperatorItem(ConditionOperator.NextWeek));
                validConditionsList.Add(new OperatorItem(ConditionOperator.NextXDays));

                validConditionsList.Add(new OperatorItem(ConditionOperator.NextXFiscalPeriods));
                validConditionsList.Add(new OperatorItem(ConditionOperator.NextXFiscalYears));
                validConditionsList.Add(new OperatorItem(ConditionOperator.NextXHours));
                validConditionsList.Add(new OperatorItem(ConditionOperator.NextXMonths));
                validConditionsList.Add(new OperatorItem(ConditionOperator.NextXWeeks));
                validConditionsList.Add(new OperatorItem(ConditionOperator.NextXYears));
                validConditionsList.Add(new OperatorItem(ConditionOperator.NextYear));

                validConditionsList.Add(new OperatorItem(ConditionOperator.OlderThanXYears));
                validConditionsList.Add(new OperatorItem(ConditionOperator.OlderThanXMonths));
                validConditionsList.Add(new OperatorItem(ConditionOperator.OlderThanXWeeks));
                validConditionsList.Add(new OperatorItem(ConditionOperator.OlderThanXDays));
                validConditionsList.Add(new OperatorItem(ConditionOperator.OlderThanXHours));
                validConditionsList.Add(new OperatorItem(ConditionOperator.OlderThanXMinutes));
                validConditionsList.Add(new OperatorItem(ConditionOperator.On));
                validConditionsList.Add(new OperatorItem(ConditionOperator.OnOrAfter));
                validConditionsList.Add(new OperatorItem(ConditionOperator.OnOrBefore));

                validConditionsList.Add(new OperatorItem(ConditionOperator.ThisFiscalPeriod));
                validConditionsList.Add(new OperatorItem(ConditionOperator.ThisFiscalYear));
                validConditionsList.Add(new OperatorItem(ConditionOperator.ThisMonth));
                validConditionsList.Add(new OperatorItem(ConditionOperator.ThisWeek));
                validConditionsList.Add(new OperatorItem(ConditionOperator.ThisYear));

                validConditionsList.Add(new OperatorItem(ConditionOperator.Today));
                validConditionsList.Add(new OperatorItem(ConditionOperator.Tomorrow));
                validConditionsList.Add(new OperatorItem(ConditionOperator.Yesterday));
                validConditionsList.Add(new OperatorItem(ConditionOperator.NotOn));

                break;

            case AttributeTypeCode.Uniqueidentifier:
                validConditionsList.Add(new OperatorItem(ConditionOperator.Above));
                validConditionsList.Add(new OperatorItem(ConditionOperator.AboveOrEqual));
                validConditionsList.Add(new OperatorItem(ConditionOperator.Under));
                validConditionsList.Add(new OperatorItem(ConditionOperator.UnderOrEqual));
                validConditionsList.Add(new OperatorItem(ConditionOperator.NotUnder));
                validConditionsList.Add(new OperatorItem(ConditionOperator.EqualBusinessId));
                validConditionsList.Add(new OperatorItem(ConditionOperator.EqualUserId));
                break;

            case AttributeTypeCode.Lookup:
            case AttributeTypeCode.Customer:
            case AttributeTypeCode.Owner:
                validConditionsList.Add(new OperatorItem(ConditionOperator.EqualBusinessId));
                validConditionsList.Add(new OperatorItem(ConditionOperator.EqualUserId));
                validConditionsList.Add(new OperatorItem(ConditionOperator.EqualUserOrUserHierarchy));
                validConditionsList.Add(new OperatorItem(ConditionOperator.EqualUserOrUserHierarchyAndTeams));
                validConditionsList.Add(new OperatorItem(ConditionOperator.EqualUserOrUserTeams));
                validConditionsList.Add(new OperatorItem(ConditionOperator.EqualUserTeams));
                break;
            }
            return(validConditionsList.ToArray());
        }
Пример #40
0
        public virtual AttributeInfo CreatePseudo(string entityName, string logicalName, AttributeTypeCode attTypeCode, AttributeTypeDisplayName attDisplayName = null)
        {
            var newAtt = new PseudoAttributeInfo();
            newAtt.AttributeType = attTypeCode;
            newAtt.AttributeOf = string.Empty;
            newAtt.AttributeType = attTypeCode;
            if (attDisplayName == null)
            {
                newAtt.AttributeTypeDisplayName = GetAttributeTypeDisplayName(attTypeCode);
            }
            else
            {
                newAtt.AttributeTypeDisplayName = attDisplayName;
            }

            newAtt.CanBeSecuredForCreate = false;
            newAtt.CanBeSecuredForRead = false;
            newAtt.CanBeSecuredForUpdate = false;
            newAtt.CanModifyAdditionalSettings = false;
            // newAtt.ColumnNumber = attributeMetadata.ColumnNumber;
            //newAtt.DataType = attributeMetadata.GetSqlDataType
            newAtt.DeprecatedVersion = string.Empty;
            newAtt.Description = string.Empty;
            newAtt.DisplayName = string.Empty;

            newAtt.EntityLogicalName = entityName;
            // newAtt.IdentityIncrement;
            // newAtt.IdentitySeed;
            newAtt.IntroducedVersion = string.Empty;
            newAtt.IsAuditEnabled = false;
            newAtt.IsCustomAttribute = true;
            newAtt.IsCustomizable = false;
            // newAtt.IsIdentity = GetBooleanManagedValue(attributeMetadata.is);
            newAtt.IsManaged = false;
            newAtt.IsPrimaryId = false;
            newAtt.IsPrimaryName = false;
            newAtt.IsPseudo = true;
            newAtt.IsRenameable = false;
            newAtt.IsSecured = false;
            newAtt.IsValidForAdvancedFind = false;
            newAtt.IsValidForCreate = false;
            newAtt.IsValidForRead = false;
            newAtt.IsValidForUpdate = false;
            //newAtt.Length
            newAtt.LinkedAttributeId = null;
            newAtt.LogicalName = logicalName;
            newAtt.MetadataId = Guid.Empty;
            newAtt.RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None);
            newAtt.SchemaName = logicalName;
            return newAtt;
        }
 private static object ConvertCrmTypeToDotNetType(AttributeTypeCode typeCode, object value)
 {
     switch (typeCode)
     {
         case AttributeTypeCode.Boolean:
             return Convert.ToBoolean(value, CultureInfo.InvariantCulture);
         case AttributeTypeCode.Customer:
         case AttributeTypeCode.Lookup:
         case AttributeTypeCode.Money:
         case AttributeTypeCode.Owner:
         case AttributeTypeCode.PartyList:
         case AttributeTypeCode.State:
         case AttributeTypeCode.Status:
         case AttributeTypeCode.Uniqueidentifier:
         case AttributeTypeCode.CalendarRules:
         case AttributeTypeCode.Virtual:
         case AttributeTypeCode.ManagedProperty:
         case AttributeTypeCode.EntityName:
             throw new NotSupportedException();
         case AttributeTypeCode.DateTime:
         case AttributeTypeCode.Decimal:
             return Convert.ToDecimal(value, CultureInfo.InvariantCulture);
         case AttributeTypeCode.Double:
             return Convert.ToDouble(value, CultureInfo.InvariantCulture);
         case AttributeTypeCode.Integer:
             return Convert.ToInt32(value, CultureInfo.InvariantCulture);
         case AttributeTypeCode.Memo:
             return Convert.ToString(value, CultureInfo.InvariantCulture);
         case AttributeTypeCode.Picklist:
             return new OptionSetValue(Convert.ToInt32(value, CultureInfo.InvariantCulture));
         case AttributeTypeCode.String:
             return Convert.ToString(value, CultureInfo.InvariantCulture);
         case AttributeTypeCode.BigInt:
             return Convert.ToInt32(value, CultureInfo.InvariantCulture);
         default:
             throw new InvalidOperationException("Unsupported field type: [" + typeCode + "]");
     }
 }
Пример #42
0
 private object GetValue(AttributeTypeCode? type)
 {
     switch (type)
     {
         case AttributeTypeCode.String:
         case AttributeTypeCode.Memo:
             return cmbValue.Text;
             break;
         case AttributeTypeCode.BigInt:
         case AttributeTypeCode.Integer:
             return int.Parse(cmbValue.Text);
             break;
         case AttributeTypeCode.Picklist:
         case AttributeTypeCode.State:
         case AttributeTypeCode.Status:
             var value = ((OptionsetItem)cmbValue.SelectedItem).meta.Value;
             return new OptionSetValue((int)value);
             break;
         default:
             throw new Exception("Attribute of type " + type.ToString() + " is currently not supported.");
     }
 }
Пример #43
0
        private List<string> ClassBreaklist(List<string> valuelist, AttributeTypeCode Fieldtype, int ClassNum, string ClassBreakMethod)
        {
            List<string> result = null;
            //根据字段类型,将值列表转换为相应类型并获取分段方案
            if (valuelist.Count > 0)
            {
                if (Fieldtype == AttributeTypeCode.AT_INTEGER)
                {
                    List<int> Outputlist = new List<int>();
                    Outputlist = valuelist.ConvertAll<int>(new Converter<string, int>(StringToInt));
                    Outputlist.Sort();

                    List<int> ResultInt = new List<int>();
                    if (ClassBreakMethod == "等距分段")
                    {
                        ResultInt.Add(Outputlist[0]);
                        int Step = (Outputlist[Outputlist.Count - 1] - Outputlist[0]) / ClassNum;
                        for (int i = 1; i < ClassNum; i++)
                        {
                            ResultInt.Add(ResultInt[i - 1] + Step);
                        }
                        ResultInt.Add(Outputlist[Outputlist.Count - 1]);
                        result = ResultInt.ConvertAll<string>(new Converter<int, string>(IntToString));
                    }
                    else //对数分段
                    {
                        if (Outputlist[0] > 0)
                        {
                            double Max = Math.Log10((double)Outputlist[Outputlist.Count - 1]);
                            double Min = Math.Log10((double)Outputlist[0]);

                            ResultInt.Add(Outputlist[0]);
                            double Step = (Max - Min) / ClassNum;
                            for (int i = 1; i < ClassNum; i++)
                            {
                                ResultInt.Add((int)Math.Pow(10, (Min + Step * i)));
                            }
                            ResultInt.Add(Outputlist[Outputlist.Count - 1]);
                            result = ResultInt.ConvertAll<string>(new Converter<int, string>(IntToString));
                        }
                        else
                            MessageBox.Show("字段值存在负值,无法采用对数分段");
                    }
                }
                else
                {
                    List<double> Outputlist = new List<double>();
                    Outputlist = valuelist.ConvertAll<double>(new Converter<string, double>(StringToDouble));
                    Outputlist.Sort();

                    Double Step;
                    List<double> Resultdouble = new List<double>();
                    if (ClassBreakMethod == "等距分段")
                    {
                        Resultdouble.Add(Outputlist[0]);
                        Step = (Outputlist[Outputlist.Count - 1] - Outputlist[0]) / ClassNum;
                        for (int i = 1; i < ClassNum; i++)
                        {
                            Resultdouble.Add(Resultdouble[i - 1] + Step);
                        }
                        Resultdouble.Add(Outputlist[Outputlist.Count - 1]);
                        result = Resultdouble.ConvertAll<string>(new Converter<double, string>(DoubleToString));
                    }
                    else //对数分段
                    {
                        if (Outputlist[0] > 0)
                        {
                            double Max = Math.Log10(Outputlist[Outputlist.Count - 1]);
                            double Min = Math.Log10(Outputlist[0]);

                            Resultdouble.Add(Outputlist[0]);
                            Step = (Max - Min) / ClassNum;
                            for (int i = 1; i < ClassNum; i++)
                            {
                                Resultdouble.Add(Math.Pow(10, (Min + Step * i)));
                            }
                            Resultdouble.Add(Outputlist[Outputlist.Count - 1]);
                            result = Resultdouble.ConvertAll<string>(new Converter<double, string>(DoubleToString));
                        }
                        else
                            MessageBox.Show("字段值存在负值,无法采用对数分段");
                    }
                }

            }
            else
                MessageBox.Show("该字段空白!");

            return result;
        }