Esempio n. 1
0
 private void UpdateMetadataFilename(string filenameMetaOld, string filenameMetaNew, string mediaFile, MetaDataType type)
 {
     if (!File.Exists(filenameMetaNew))
     {
         if (File.Exists(filenameMetaOld))
         {
             cxzxc("Renamed: " + filenameMetaOld + " -> " + filenameMetaNew);
             System.IO.File.Move(filenameMetaOld, filenameMetaNew);
         }
         else
         {
             cxzxc("!!! No meta for " + mediaFile + " (" + type.ToString() + ")");
         }
     }
     else
     {
         cxzxc("ALREADY EXISTS " + filenameMetaNew);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Returns the fully qualified type name of this instance.
 /// </summary>
 /// <returns>A <see cref="T:System.String" /> containing a fully qualified type name.</returns>
 public override String ToString()
 {
     return(String.Format(CultureInfo.CurrentCulture, "DataType: {0}, Data: {1}", new Object[] { m_dataType.ToString(), (m_data == null) ? "null" : m_data.ToString() }));
 }
Esempio n. 3
0
 protected override object ConvertToDictionary(object value, MetaDataType DestType, string DestFieldName, int RowIndex, out MDPImportWarning[] warnings)
 {
     warnings = null;
     if (DestType == MetaDataType.StringDictionary)
     {
         MetaStringDictionary dic        = new MetaStringDictionary();
         JavaScriptSerializer serializer = new JavaScriptSerializer();
         object[]             col        = serializer.DeserializeObject((string)value) as object[];
         foreach (Dictionary <string, object> item in col)
         {
             dic.Add((string)item["Key"], (string)item["Value"]);
         }
         value = dic;
     }
     else if (DestType == MetaDataType.DictionaryMultiValue || DestType == MetaDataType.EnumMultiValue)
     {
         string[] values = value.ToString().Split(new char[] { ',' });
         for (int i = 0; i < values.Length; i++)
         {
             ((MetaDictionaryItem[])value)[i] = findDictionaryItem(values[i].Trim(), DestFieldName);
             if (((MetaDictionaryItem[])value)[i] == null)
             {
                 throw new Mediachase.MetaDataPlus.Import.InvalidCastException(DestType.ToString(), value.GetType().ToString());
             }
         }
     }
     else
     {
         object val = findDictionaryItem(value.ToString().Trim(), DestFieldName);
         if (val == null)
         {
             throw new Mediachase.MetaDataPlus.Import.MDPImportException(String.Format("Invalid value '{0}' for dictionary '{1}'.", value, DestFieldName));
         }
         value = val;
     }
     return(value);
 }
Esempio n. 4
0
 private void UpdateMetadataFilename(string filenameMetaOld, string filenameMetaNew, string mediaFile, MetaDataType type)
 {
     if (!File.Exists(filenameMetaNew))
     {
         if (File.Exists(filenameMetaOld))
         {
             cxzxc("Renamed: " + filenameMetaOld + " -> " + filenameMetaNew);
             System.IO.File.Move(filenameMetaOld, filenameMetaNew);
         }
         else
             cxzxc("!!! No meta for " + mediaFile + " (" + type.ToString() + ")");
     }
     else
         cxzxc("ALREADY EXISTS " + filenameMetaNew);
 }
Esempio n. 5
0
        protected virtual object ConvertDataType(Type source, MetaDataType destination, object value, string destFieldName, bool allowNull, int rowIndex, out MdpImportWarning[] warnings)
        {
            warnings = null;
            switch (destination)
            {
                case MetaDataType.BigInt:
                    return Convert.ChangeType(value, typeof(Int64));
                case MetaDataType.Binary:
                case MetaDataType.Image:
                case MetaDataType.VarBinary:
                    return Convert.ChangeType(value, typeof(byte[]));	// TODO: does it work?
                case MetaDataType.Bit:
                case MetaDataType.Boolean:
                    switch (value.ToString().ToLower())
                    {
                        case "true":
                            return true;
                        case "false":
                            return false;
                        default:
                            try
                            {
                                return (int.Parse(value.ToString()) != 0);
                            }
                            catch
                            {
                            }
                            return false;
                    }
                case MetaDataType.Char:
                case MetaDataType.NChar:
                case MetaDataType.NText:
                case MetaDataType.NVarChar:
                case MetaDataType.UniqueIdentifier:
                case MetaDataType.Text:
                case MetaDataType.VarChar:
                case MetaDataType.Sysname:
                case MetaDataType.ShortString:
                case MetaDataType.LongString:
                case MetaDataType.Url:
                case MetaDataType.Email:
                case MetaDataType.LongHtmlString:
                    return value.ToString();
                case MetaDataType.DateTime:
                    return Convert.ChangeType(value, typeof(DateTime));
                case MetaDataType.Decimal:
                case MetaDataType.Numeric:
                    return Convert.ChangeType(value, typeof(Decimal));
                case MetaDataType.Money:
                case MetaDataType.SmallMoney:							// TODO:?? + temporal code for currency symbol
                    if (value is string)
                        return Convert.ChangeType(value.ToString().TrimStart('$'), typeof(Decimal));
                    else
                        return Convert.ChangeType(value, typeof(Decimal));
                case MetaDataType.Float:
                    return Convert.ChangeType(value, typeof(Double));
                case MetaDataType.Int:
                case MetaDataType.Integer:
                    return Convert.ChangeType(value, typeof(Int32));
                case MetaDataType.Real:
                    return Convert.ChangeType(value, typeof(Single));
                case MetaDataType.SmallDateTime:
                    return Convert.ChangeType(value, typeof(DateTime));		// TODO:??
                case MetaDataType.SmallInt:
                    return Convert.ChangeType(value, typeof(Int16));
                case MetaDataType.TinyInt:
                    return Convert.ChangeType(value, typeof(Byte));
                case MetaDataType.Date:
                    return Convert.ChangeType(value, typeof(DateTime));
                case MetaDataType.DictionaryMultivalue:
                case MetaDataType.EnumMultivalue:
                    value = ConvertToDictionary(value, destination, destFieldName, rowIndex, out warnings);
                    if (value == null && !allowNull)
                        throw new Mediachase.MetaDataPlus.Import.InvalidCastException(destination.ToString(), source.ToString());
                    break;
                case MetaDataType.DictionarySingleValue:
                case MetaDataType.EnumSingleValue:
                    value = ConvertToDictionary(value, destination, destFieldName, rowIndex, out warnings);
                    if (value == null && !allowNull)
                        throw new Mediachase.MetaDataPlus.Import.InvalidCastException(destination.ToString(), source.ToString());
                    break;
                case MetaDataType.File:
                case MetaDataType.ImageFile:
                    value = ConvertToFile(value, destination, destFieldName, rowIndex, out warnings);
                    if (value == null && !allowNull)
                        throw new Mediachase.MetaDataPlus.Import.InvalidCastException(destination.ToString(), source.ToString());
                    break;
                default:
                    throw new Mediachase.MetaDataPlus.Import.InvalidCastException(destination.ToString(), source.ToString());

            }
            return value;
        }
Esempio n. 6
0
        protected virtual object ConvertDataType(Type source, MetaDataType destination, object value, string destFieldName, bool allowNull, int rowIndex, out MdpImportWarning[] warnings)
        {
            warnings = null;
            switch (destination)
            {
            case MetaDataType.BigInt:
                return(Convert.ChangeType(value, typeof(Int64)));

            case MetaDataType.Binary:
            case MetaDataType.Image:
            case MetaDataType.VarBinary:
                return(Convert.ChangeType(value, typeof(byte[])));                              // TODO: does it work?

            case MetaDataType.Bit:
            case MetaDataType.Boolean:
                switch (value.ToString().ToLower())
                {
                case "true":
                    return(true);

                case "false":
                    return(false);

                default:
                    try
                    {
                        return(int.Parse(value.ToString()) != 0);
                    }
                    catch
                    {
                    }
                    return(false);
                }

            case MetaDataType.Char:
            case MetaDataType.NChar:
            case MetaDataType.NText:
            case MetaDataType.NVarChar:
            case MetaDataType.UniqueIdentifier:
            case MetaDataType.Text:
            case MetaDataType.VarChar:
            case MetaDataType.Sysname:
            case MetaDataType.ShortString:
            case MetaDataType.LongString:
            case MetaDataType.Url:
            case MetaDataType.Email:
            case MetaDataType.LongHtmlString:
                return(value.ToString());

            case MetaDataType.DateTime:
                return(Convert.ChangeType(value, typeof(DateTime)));

            case MetaDataType.Decimal:
            case MetaDataType.Numeric:
                return(Convert.ChangeType(value, typeof(Decimal)));

            case MetaDataType.Money:
            case MetaDataType.SmallMoney:                                                                       // TODO:?? + temporal code for currency symbol
                if (value is string)
                {
                    return(Convert.ChangeType(value.ToString().TrimStart('$'), typeof(Decimal)));
                }
                else
                {
                    return(Convert.ChangeType(value, typeof(Decimal)));
                }

            case MetaDataType.Float:
                return(Convert.ChangeType(value, typeof(Double)));

            case MetaDataType.Int:
            case MetaDataType.Integer:
                return(Convert.ChangeType(value, typeof(Int32)));

            case MetaDataType.Real:
                return(Convert.ChangeType(value, typeof(Single)));

            case MetaDataType.SmallDateTime:
                return(Convert.ChangeType(value, typeof(DateTime)));                                    // TODO:??

            case MetaDataType.SmallInt:
                return(Convert.ChangeType(value, typeof(Int16)));

            case MetaDataType.TinyInt:
                return(Convert.ChangeType(value, typeof(Byte)));

            case MetaDataType.Date:
                return(Convert.ChangeType(value, typeof(DateTime)));

            case MetaDataType.DictionaryMultivalue:
            case MetaDataType.EnumMultivalue:
                value = ConvertToDictionary(value, destination, destFieldName, rowIndex, out warnings);
                if (value == null && !allowNull)
                {
                    throw new Mediachase.MetaDataPlus.Import.InvalidCastException(destination.ToString(), source.ToString());
                }
                break;

            case MetaDataType.DictionarySingleValue:
            case MetaDataType.EnumSingleValue:
                value = ConvertToDictionary(value, destination, destFieldName, rowIndex, out warnings);
                if (value == null && !allowNull)
                {
                    throw new Mediachase.MetaDataPlus.Import.InvalidCastException(destination.ToString(), source.ToString());
                }
                break;

            case MetaDataType.File:
            case MetaDataType.ImageFile:
                value = ConvertToFile(value, destination, destFieldName, rowIndex, out warnings);
                if (value == null && !allowNull)
                {
                    throw new Mediachase.MetaDataPlus.Import.InvalidCastException(destination.ToString(), source.ToString());
                }
                break;

            default:
                throw new Mediachase.MetaDataPlus.Import.InvalidCastException(destination.ToString(), source.ToString());
            }
            return(value);
        }