Example #1
0
        private void SafelySetStringProperty(EntityObject entity, string name, string value)
        {
            string result = value;

            MD47.Meta.Management.MetaClass metaClass = MD47.DataContext.Current.MetaModel.MetaClasses[entity.MetaClassName];
            MD47.Meta.Management.MetaField metaField = metaClass.Fields[name];
            int maximumLength = metaField.Attributes.GetValue <int>(MD47.Meta.Management.McDataTypeAttribute.StringMaxLength, int.MaxValue);

            if (value != null && value.Length > maximumLength)
            {
                result = value.Substring(0, maximumLength);
                SendWarning("Maximum string length for {0}.{1} is {2} characters. The string '{3}' will be truncated to '{4}'.", entity.MetaClassName, name, maximumLength, value, result);
            }

            entity[name] = result;
        }
Example #2
0
        private void GetFieldValue(MD45.MetaObject object45, MD47.Meta.Management.MetaField field47, ref bool fieldPresent, ref object value)
        {
            string field47Name = field47.Name;

            if (_fieldMap.ContainsKey(field47Name))
            {
                fieldPresent = true;
                string field45Name = _fieldMap[field47Name];

                if (field47.IsEnum || field47.IsMultivalueEnum)
                {
                    if (object45[field45Name] != null)
                    {
                        Dictionary <int, string> enumValues;
                        //Try find mapping id for this FieldType
                        if (!_enumValuesByType.TryGetValue(field47.GetMetaType(), out enumValues))
                        {
                            throw new ArgumentException("Not mapped enum item");
                        }

                        if (field47.IsMultivalueEnum)
                        {
                            List <string> valueList = new List <string>();
                            foreach (MD45.Configurator.MetaDictionaryItem enumItem in (MD45.Configurator.MetaDictionaryItem[])object45[field45Name])
                            {
                                valueList.Add(enumItem.Value);
                            }

                            if (valueList.Count > 0)
                            {
                                value = valueList.ToArray();
                            }
                        }
                        else
                        {
                            value = ((MD45.Configurator.MetaDictionaryItem)object45[field45Name]).Value;
                        }
                    }
                }
                else if (field47.GetMetaType().McDataType == MD47.Meta.Management.McDataType.File)
                {
                    MD45.MetaFile metaFile45 = object45[field45Name] as MD45.MetaFile;

                    if (metaFile45 != null)
                    {
                        //Begin copy file to 47
                        if (metaFile45.Buffer != null)
                        {
                            using (MemoryStream stream = new MemoryStream(metaFile45.Buffer))
                            {
                                value = new MD47.Meta.FileInfo(metaFile45.Name, stream);
                            }
                        }
                        else
                        {
                            value = new MD47.Meta.FileInfo(metaFile45.Name);
                        }
                    }
                }
                else
                {
                    switch (field47Name)
                    {
                    case "Created":
                        value = object45.Created;
                        break;

                    case "CreatorId":
                        value = object45.CreatorId;
                        break;

                    case "Modified":
                        value = object45.Modified;
                        break;

                    case "ModifierId":
                        value = object45.ModifierId;
                        break;

                    default:
                        value = object45[field45Name];
                        break;
                    }
                }
            }
            else
            {
                fieldPresent = false;
            }
        }
Example #3
0
        private static void CopyFieldFrom45(MD47.Meta.Management.MetaClass metaClass47, string fieldNamePrefix47, MD45.Configurator.MetaField field45, Field45by47 fieldMap, FieldTypeMapingValues enumValuesByType)
        {
            MD47.Meta.Management.MetaField field47 = null;

            if (!field45.IsSystem)
            {
                using (MD47.Meta.Management.MetaFieldBuilder builder = new MD47.Meta.Management.MetaFieldBuilder(metaClass47))
                {
                    string name         = fieldNamePrefix47 + field45.Name;
                    string friendlyName = field45.FriendlyName;
                    bool   allowNulls   = field45.AllowNulls;

                    switch (field45.DataType)
                    {
                    case MD45.Configurator.MetaDataType.UniqueIdentifier:
                        field47 = builder.CreateGuid(name, friendlyName, allowNulls);
                        break;

                    case MD45.Configurator.MetaDataType.Money:
                    case MD45.Configurator.MetaDataType.SmallMoney:
                        field47 = builder.CreateCurrency(name, friendlyName, allowNulls, 0, true);
                        break;

                    case MD45.Configurator.MetaDataType.Float:
                    case MD45.Configurator.MetaDataType.Numeric:
                        field47 = builder.CreateFloat(name, friendlyName, allowNulls, 0);
                        break;

                    case MD45.Configurator.MetaDataType.File:
                    case MD45.Configurator.MetaDataType.ImageFile:
                        field47 = builder.CreateFile(name, friendlyName, allowNulls, string.Empty);
                        break;

                    case MD45.Configurator.MetaDataType.Integer:
                    case MD45.Configurator.MetaDataType.Decimal:
                    case MD45.Configurator.MetaDataType.Int:
                    case MD45.Configurator.MetaDataType.BigInt:
                    case MD45.Configurator.MetaDataType.Real:
                    case MD45.Configurator.MetaDataType.SmallInt:
                    case MD45.Configurator.MetaDataType.TinyInt:
                        field47 = builder.CreateInteger(name, friendlyName, allowNulls, 0);
                        break;

                    case MD45.Configurator.MetaDataType.Boolean:
                    case MD45.Configurator.MetaDataType.Bit:
                        field47 = builder.CreateCheckBoxBoolean(name, friendlyName, allowNulls, false, friendlyName);
                        break;

                    case MD45.Configurator.MetaDataType.Date:
                    case MD45.Configurator.MetaDataType.DateTime:
                    case MD45.Configurator.MetaDataType.SmallDateTime:
                    case MD45.Configurator.MetaDataType.Timestamp:
                        field47 = builder.CreateDate(name, friendlyName, allowNulls);
                        break;

                    case MD45.Configurator.MetaDataType.Email:
                        field47 = builder.CreateEmail(name, friendlyName, allowNulls, field45.Length, false);
                        break;

                    case MD45.Configurator.MetaDataType.Url:
                        field47 = builder.CreateUrl(name, friendlyName, allowNulls, field45.Length, false, String.Empty);
                        break;

                    case MD45.Configurator.MetaDataType.ShortString:
                    case MD45.Configurator.MetaDataType.Char:
                    case MD45.Configurator.MetaDataType.NChar:
                    case MD45.Configurator.MetaDataType.NVarChar:
                    case MD45.Configurator.MetaDataType.VarChar:
                        field47 = builder.CreateText(name, friendlyName, allowNulls, field45.Length, false);
                        break;

                    case MD45.Configurator.MetaDataType.LongHtmlString:
                        field47 = builder.CreateHtml(name, friendlyName, allowNulls);
                        break;

                    case MD45.Configurator.MetaDataType.LongString:
                    case MD45.Configurator.MetaDataType.Binary:
                    case MD45.Configurator.MetaDataType.Image:
                    case MD45.Configurator.MetaDataType.NText:
                    case MD45.Configurator.MetaDataType.Text:
                    case MD45.Configurator.MetaDataType.VarBinary:
                        field47 = builder.CreateLongText(name, friendlyName, allowNulls);
                        break;

                    case MD45.Configurator.MetaDataType.DictionarySingleValue:
                    case MD45.Configurator.MetaDataType.EnumSingleValue:
                    case MD45.Configurator.MetaDataType.DictionaryMultivalue:
                    case MD45.Configurator.MetaDataType.EnumMultivalue:
                    {
                        bool isMultiValue = (field45.DataType == MD45.Configurator.MetaDataType.DictionaryMultivalue) || (field45.DataType == MD45.Configurator.MetaDataType.EnumMultivalue);
                        MD45.Configurator.MetaDictionary dictionary45 = MD45.Configurator.MetaDictionary.Load(field45.Id);

                        MD47.Meta.Management.MetaFieldType enum47 = null;

                        // Try to find existing enum type
                        foreach (MD47.Meta.Management.MetaFieldType fieldType47 in MD47.DataContext.Current.MetaModel.RegisteredTypes)
                        {
                            if (fieldType47.Name == name)
                            {
                                if (fieldType47.McDataType == MD47.Meta.Management.McDataType.Enum)
                                {
                                    enum47 = fieldType47;
                                }
                                else
                                {
                                    //Do not allow identical type names for Enum and Basic types
                                    name = name + "_" + builder.MetaClass.Name;
                                }
                                break;
                            }
                        }

                        if (enum47 == null)
                        {
                            enum47 = MD47.Meta.Management.MetaEnum.Create(name, friendlyName, isMultiValue);
                        }

                        Dictionary <int, string> enumValues47By45 = CreateEnumType47FromMetaDictionary(enum47, dictionary45);

                        enumValuesByType.Add(enum47, enumValues47By45);

                        string defaultValue = string.Empty;
                        if (!allowNulls)
                        {
                            MD47.Meta.MetaEnumItem[] items = MD47.Meta.Management.MetaEnum.GetItems(enum47);
                            if (items != null && items.Length > 0)
                            {
                                defaultValue = items[0].Handle.ToString(CultureInfo.InvariantCulture);
                            }
                        }

                        field47 = builder.CreateEnumField(name, friendlyName, enum47.Name, allowNulls, defaultValue, true);
                    }
                    break;

                    case MD45.Configurator.MetaDataType.StringDictionary:
                        //TODO:
                        break;

                    default:
                        break;
                    }
                }
            }

            if (field47 != null)
            {
                fieldMap.Add(field47.Name, field45.Name);
            }
        }
Example #4
0
 /// <summary>
 /// Binds the data.
 /// </summary>
 /// <param name="field">The field.</param>
 public void BindData(Mediachase.Ibn.Data.Meta.Management.MetaField field)
 {
 }