Esempio n. 1
0
        public override void WriteTo(byte[] buffer, int offset)
        {
            int nameLen;

            if (string.IsNullOrEmpty(_name))
            {
                _flags &= ~ValueFlags.Named;
                nameLen = 0;
            }
            else
            {
                _flags |= ValueFlags.Named;
                nameLen = _name.Length;
            }

            Utilities.StringToBytes("vk", buffer, offset, 2);
            Utilities.WriteBytesLittleEndian(nameLen, buffer, offset + 0x02);
            Utilities.WriteBytesLittleEndian(_dataLength, buffer, offset + 0x04);
            Utilities.WriteBytesLittleEndian(_dataIndex, buffer, offset + 0x08);
            Utilities.WriteBytesLittleEndian((int)_type, buffer, offset + 0x0C);
            Utilities.WriteBytesLittleEndian((ushort)_flags, buffer, offset + 0x10);
            if (nameLen != 0)
            {
                Utilities.StringToBytes(_name, buffer, offset + 0x14, nameLen);
            }
        }
Esempio n. 2
0
    public int this[FlagTypes flag]
    {
        //I tried doing this with an array of generic enums but it caused problems so its a switch statement for now
        get
        {
            switch (flag)
            {
            case FlagTypes.CommonFlags:
                return((int)commonFlags);

            case FlagTypes.ValueFlags:
                return((int)valueFlags);

            default:
                return(0);
            }
        }
        set
        {
            switch (flag)
            {
            case FlagTypes.CommonFlags:
                commonFlags = (CommonFlags)value;
                break;

            case FlagTypes.ValueFlags:
                valueFlags = (ValueFlags)value;
                break;
            }
        }
    }
 public AccessExpression(IExpression accessee, AccessOperationType accessOperator, Positioned <string> accessor, ValueFlags flags, ITypeInfo returnType)
 {
     Accessee       = accessee;
     AccessOperator = accessOperator;
     Accessor       = accessor;
     Flags          = flags;
     ReturnType     = returnType;
 }
Esempio n. 4
0
 private bool GetValue(ValueFlags flag, out float value)
 {
     if ((flagHandler.ValueFlags & flag) != ValueFlags.None)
     {
         value = currentMove.GetAnimatedValue(moveTime, flag);
         return(true);
     }
     value = 0;
     return(false);
 }
Esempio n. 5
0
    public float GetAnimatedValue(float time, ValueFlags valueFlag)
    {
        int i    = 0;
        int flag = (int)valueFlag;

        while ((flag & 1) != 1)
        {
            i   += 1;
            flag = flag >> 1;
        }
        return(valueCurves[i].Evaluate(time));
    }
Esempio n. 6
0
        /// <summary>
        /// Returns the synopsis for the value of this option depending on the flag of value . <para> </para>
        /// If value for this option can be optional, her value flag is not <see cref="DrCmdValueFlags.Required"/> the function will be return value synopsis in square brackets <para> </para>
        /// If this option cannot contains value , her value flag is <see cref="DrCmdValueFlags.Forbidden"/> the function will be return empty string
        /// </summary>
        /// <returns></returns>
        internal string GetOptionValueSynopsis()
        {
            var text = string.Empty;

            if (!ValueFlags.HasFlag(DrCmdValueFlags.Forbidden)) // this option can have value
            {
                text = GetAttributeValue(DrCmdOptionSettings.SynopsisValue, string.Empty);
                if (!ValueFlags.HasFlag(DrCmdValueFlags.Required))
                {
                    text = "[" + text + "]";                                                // this value is optional
                }
            }
            return(text);
        }
Esempio n. 7
0
        public Value(ValueTable parentTable, string uniqueID, TypeSymbol userType, ValueFlags flags)
        {
        #if UDONSHARP_DEBUG
            if (parentTable == null)
            {
                throw new NullReferenceException();
            }
        #endif

            _parentTable = parentTable;
            UserType     = userType;
            Flags        = flags;
            UniqueID     = uniqueID;
        }
Esempio n. 8
0
        public override int ReadFrom(byte[] buffer, int offset)
        {
            int nameLen = Utilities.ToUInt16LittleEndian(buffer, offset + 0x02);
            _dataLength = Utilities.ToInt32LittleEndian(buffer, offset + 0x04);
            _dataIndex = Utilities.ToInt32LittleEndian(buffer, offset + 0x08);
            _type = (RegistryValueType)Utilities.ToInt32LittleEndian(buffer, offset + 0x0C);
            _flags = (ValueFlags)Utilities.ToUInt16LittleEndian(buffer, offset + 0x10);

            if ((_flags & ValueFlags.Named) != 0)
            {
                _name = Utilities.BytesToString(buffer, offset + 0x14, nameLen).Trim('\0');
            }

            return 0x14 + nameLen;
        }
Esempio n. 9
0
        ///////////////////////////////////////////////////////////////////////

        public static bool HasFlags(
            ValueFlags flags,
            ValueFlags hasFlags,
            bool all
            )
        {
            if (all)
            {
                return((flags & hasFlags) == hasFlags);
            }
            else
            {
                return((flags & hasFlags) != ValueFlags.None);
            }
        }
Esempio n. 10
0
 public NamedReferenceDecorator(IValueReference <TValue> originalReference,
                                [NotNull] string name,
                                ValueOriginKind kind,
                                ValueFlags flags,
                                [CanBeNull] IMetadataTypeLite declaredType,
                                IValueRoleFactory <TValue> roleFactory,
                                bool isNameFromValue = false)
 {
     myOriginalReference = originalReference;
     DefaultName         = name;
     OriginKind          = kind;
     DefaultFlags        = flags;
     DeclaredType        = declaredType;
     myRoleFactory       = roleFactory;
     IsNameFromValue     = isNameFromValue;
 }
Esempio n. 11
0
        public override int ReadFrom(byte[] buffer, int offset)
        {
            int nameLen = Utilities.ToUInt16LittleEndian(buffer, offset + 0x02);

            _dataLength = Utilities.ToInt32LittleEndian(buffer, offset + 0x04);
            _dataIndex  = Utilities.ToInt32LittleEndian(buffer, offset + 0x08);
            _type       = (RegistryValueType)Utilities.ToInt32LittleEndian(buffer, offset + 0x0C);
            _flags      = (ValueFlags)Utilities.ToUInt16LittleEndian(buffer, offset + 0x10);

            if ((_flags & ValueFlags.Named) != 0)
            {
                _name = Utilities.BytesToString(buffer, offset + 0x14, nameLen).Trim('\0');
            }

            return(0x14 + nameLen);
        }
Esempio n. 12
0
        ///////////////////////////////////////////////////////////////////////

        public static ReturnCode CreateDbConnection(
            Interpreter interpreter,
            DbConnectionType dbConnectionType,
            string connectionString,
            string typeFullName,
            string typeName,
            ValueFlags valueFlags,
            ref IDbConnection connection,
            ref Result error
            )
        {
            return(CreateDbConnection(interpreter, dbConnectionType,
                                      connectionString, typeFullName, typeName, valueFlags,
                                      GetOtherDbConnectionTypeNames(true, false),
                                      GetOtherDbConnectionTypeNames(false, false),
                                      ref connection, ref error));
        }
Esempio n. 13
0
        /// <summary>
        /// Constructs a new value.
        /// </summary>
        /// <param name="valueKind">The value kind.</param>
        /// <param name="basicBlock">The parent basic block.</param>
        /// <param name="initialType">The initial node type.</param>
        /// <param name="valueFlags">Custom value flags.</param>
        protected Value(
            ValueKind valueKind,
            BasicBlock basicBlock,
            TypeNode initialType,
            ValueFlags valueFlags)
        {
            Debug.Assert(initialType != null, "Invalid initialType");

            ValueKind  = valueKind;
            BasicBlock = basicBlock;
            Method     = basicBlock?.Method;
            type       = initialType;
            Nodes      = ImmutableArray <ValueReference> .Empty;

            ValueFlags  = valueFlags;
            Replacement = this;
        }
Esempio n. 14
0
        ///////////////////////////////////////////////////////////////////////

        public static OptionDictionary FromString(
            Interpreter interpreter,
            string text,
            AppDomain appDomain,
            ValueFlags valueFlags,
            CultureInfo cultureInfo,
            ref Result error
            )
        {
            StringList list = null;

            if (Parser.SplitList(
                    interpreter, text, 0, Length.Invalid, true,
                    ref list, ref error) == ReturnCode.Ok)
            {
                OptionDictionary options = new OptionDictionary();

                foreach (string element in list)
                {
                    IOption option = Option.FromString(
                        interpreter, element, appDomain,
                        valueFlags, cultureInfo, ref error);

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

                    if (options.Has(option))
                    {
                        error = String.Format(
                            "duplicate option name {0}",
                            FormatOps.WrapOrNull(option.Name));

                        return(null);
                    }

                    options.Add(option);
                }

                return(options);
            }

            return(null);
        }
Esempio n. 15
0
        /// <summary>
        /// Checking this option specified arguments.
        /// If arguments are incongruous the <exception cref="ArgumentException">ArgumentException</exception> will be thrown.
        /// </summary>
        public void ValidateOptionParameter()
        {
            // start validate value Type
            if (Option.Attributes.Contains(DrCmdOptionSettings.ValueType))  // validate specified Type for convert
            {
                var valueType = System.Type.GetType(Option.Attributes[DrCmdOptionSettings.ValueType].GetValueAsString());
                if (!DDValue.ValidateType(valueType))
                {
                    throw new ArgumentException(string.Format(Msg.SPECIFIED_VALUE_TYPE_IS_NOT_SUPPORTED_BY_DDVALUE, valueType.ToString()));
                }
            }
            // end validate value Type
            var isSpecifiedOption = GetAttributeValue(DrCmdOptionSettings.ResultIsOptionSpecified, false);

            if ((Type.HasFlag(DrCmdOptionType.Required)) & (isSpecifiedOption == false))
            {
                throw new ArgumentException(string.Format(Msg.REQUIRED_OPTION_IS_NOT_SPECIFIED, Name, CommandName));
            }
            // value flag
            var valueAsStringArray = GetAttributeValue(DrCmdOptionSettings.ResultValueAsStringArray, new string[] { }).GetValueAsStringArray();
            var valueAsString      = GetAttributeValue(DrCmdOptionSettings.ResultValueAsStringArray, string.Empty).GetValueAsString();

            // Single
            if ((ValueFlags.HasFlag(DrCmdValueFlags.Single)) & (valueAsStringArray.Length > 1))
            {
                throw new ArgumentException(string.Format(Msg.OPTION_CANNOT_CONTAINS_MORE_THAN_ONE_VALUE, Name, valueAsString, valueAsStringArray.Length, DrCmdValueFlags.Single, CommandName));
            }
            // Forbidden
            if ((ValueFlags.HasFlag(DrCmdValueFlags.Forbidden)) & (valueAsStringArray.Length > 0))
            {
                throw new ArgumentException(string.Format(Msg.OPTION_CANNOT_CONTAIN_VALUE, Name, valueAsString, DrCmdValueFlags.Forbidden, CommandName));
            }
            // Required
            if ((isSpecifiedOption) && (ValueFlags.HasFlag(DrCmdValueFlags.Required)) & (valueAsStringArray.Length == 0))
            {
                throw new ArgumentException(string.Format(Msg.OPTION_MUST_CONTAIN_VALUE, Name, DrCmdValueFlags.Required, CommandName));
            }
            if ((ValueFlags.HasFlag(DrCmdValueFlags.ListOfRestriction)) && (valueAsStringArray.Length > 0))
            {
                ValidateOptionValueByRestrictionList(valueAsStringArray);                                                                                             // RestrictionList and AllowNumeric
            }
        }
Esempio n. 16
0
        public DbgDotNetValueImpl(DbgEngineImpl engine, ValueLocation valueLocation, Value value)
        {
            this.engine        = engine ?? throw new ArgumentNullException(nameof(engine));
            this.valueLocation = valueLocation ?? throw new ArgumentNullException(nameof(valueLocation));
            this.value         = value ?? throw new ArgumentNullException(nameof(value));
            Type     = MonoValueTypeCreator.CreateType(engine, value, valueLocation.Type);
            rawValue = new DbgDotNetRawValueFactory(engine).Create(value, Type);

            var flags = ValueFlags.None;

            if (value is PrimitiveValue pv && (pv.Value is null || ((Type.IsPointer || Type.IsFunctionPointer) && boxed0L.Equals(pv.Value))))
            {
                if (Type.IsByRef)
                {
                    flags |= ValueFlags.IsNullByRef;
                }
                else
                {
                    flags |= ValueFlags.IsNull;
                }
            }
Esempio n. 17
0
        ///////////////////////////////////////////////////////////////////////

        public ReturnCode GetMember(
            string text,
            TypedInstance typedInstance,
            MemberTypes memberTypes,
            BindingFlags bindingFlags,
            ValueFlags valueFlags,
            CultureInfo cultureInfo,
            ref TypedMember value,
            ref Result error
            )
        {
            CheckDisposed();

            if (parentBinder == null)
            {
                throw new InvalidOperationException();
            }

            return(parentBinder.GetMember(
                       text, typedInstance, memberTypes, bindingFlags, valueFlags,
                       cultureInfo, ref value, ref error));
        }
Esempio n. 18
0
        ///////////////////////////////////////////////////////////////////////

        public ReturnCode GetObject(
            string text,
            TypeList types,
            AppDomain appDomain,
            BindingFlags bindingFlags,
            Type type,
            ValueFlags valueFlags,
            CultureInfo cultureInfo,
            ref TypedInstance value,
            ref Result error
            )
        {
            CheckDisposed();

            if (parentBinder == null)
            {
                throw new InvalidOperationException();
            }

            return(parentBinder.GetObject(
                       text, types, appDomain, bindingFlags, type, valueFlags,
                       cultureInfo, ref value, ref error));
        }
Esempio n. 19
0
        public DbgDotNetValueImpl(DbgEngineImpl engine, DbgCorValueHolder value)
        {
            this.engine = engine ?? throw new ArgumentNullException(nameof(engine));
            this.value  = value ?? throw new ArgumentNullException(nameof(value));
            Type        = value.Type;
            var corValue = value.CorValue;

            rawValue = new DbgDotNetRawValueFactory(engine).Create(corValue, Type);

            var flags = ValueFlags.None;

            if (corValue.IsNull)
            {
                if (Type.IsByRef)
                {
                    flags |= ValueFlags.IsNullByRef;
                }
                else
                {
                    flags |= ValueFlags.IsNull;
                }
            }
            this.flags = flags;
        }
Esempio n. 20
0
 /// <summary>
 /// Verify flag of value for option.
 /// In the case of the incongruous flags are detected ​​the <exception cref="FormatException">FormatException</exception>will be thrown
 /// </summary>
 public void VerifyValueRestrictionsType()
 {
     try
     {
         #region Forbidden
         if ((ValueFlags.HasFlag(DrCmdValueFlags.Forbidden)) && (ValueFlags != DrCmdValueFlags.Forbidden))
         {
             throw new FormatException(string.Format(Msg.WITH_THIS_TYPE_CANNOT_BE_SPECIFIED_MORE_THAN_OTHER_TYPES, DrCmdValueFlags.Forbidden));
         }
         #endregion Forbidden
         if ((ValueFlags.HasFlag(DrCmdValueFlags.AllowNumeric)) && (!ValueFlags.HasFlag(DrCmdValueFlags.ListOfRestriction)))
         {
             throw new FormatException(string.Format(Msg.CANNOT_SPECIFY_ONE_TYPE_WITHOUT_SECOND_TYPE, DrCmdValueFlags.AllowNumeric, DrCmdValueFlags.ListOfRestriction)); // AllowNumeric without ListOfRestriction
         }
         var restrictionList            = GetAttributeValue(DrCmdOptionSettings.RestrictionList, new string[] { }).GetValueAsStringArray();
         var restrictionListDescription = GetAttributeValue(DrCmdOptionSettings.RestrictionListDescription, new string[] { }).GetValueAsStringArray();
         if (ValueFlags.HasFlag(DrCmdValueFlags.AllowNumeric)) // if AllowNumeric is true need to check both list element count -> RestrictionList and RestrictionListAsNumeric
         {
             var restrictionListAsNumeric = GetAttributeValue(DrCmdOptionSettings.RestrictionListAsNumeric, new int[] { }).GetValueAsIntArray();
             if (restrictionList.Length != restrictionListAsNumeric.Length)
             {
                 throw new FormatException(string.Format(Msg.ELEMENT_COUNT_IN_RESTRICTION_LIST_IS_NOT_EQUALS_OF_NUMERIC_LIST_COUNT, Name, restrictionList.Length.ToString(), restrictionListAsNumeric.Length.ToString()));
             }
         }
         if ((restrictionList.Length > 0) && (restrictionListDescription.Length > 0) && (restrictionList.Length != restrictionListDescription.Length))
         {
             throw new FormatException(string.Format(Msg.ELEMENT_COUNT_IN_RESTRICTION_LIST_IS_NOT_EQUALS_OF_RESTRICTIOM_DESCRIPTION_LIST, Name, restrictionList.Length.ToString(), restrictionListDescription.Length.ToString()));
         }
         CheckIncongruousTypeOfValue(ValueFlags, DrCmdValueFlags.Optional, DrCmdValueFlags.Required);                                                             // Optioanl & Required
         CheckIncongruousTypeOfValue(ValueFlags, DrCmdValueFlags.Single, DrCmdValueFlags.List);                                                                   // Single & List
     }
     catch (ApplicationException e)
     {
         throw new FormatException(string.Format(Msg.OPTION_TYPE_IS_WRONG, Name, ValueFlags.ToString()), e);
     }
 }
Esempio n. 21
0
        /// <summary>
        /// Checks the value of the options on their compliance with the list of allowed values ​​or, if enabled, their numerical conform
        /// If the option value is incorrect by restriction list from attribute <see cref="DrCmdOptionSettings.RestrictionList"/> the <exception cref="ArgumentException">ArgumentException</exception> will be thrown.
        /// </summary>
        /// <param name="valueAsStringArray">option values as string array</param>
        private void ValidateOptionValueByRestrictionList(IEnumerable <string> valueAsStringArray)
        {
            var restrictionListArray = GetAttributeValue(DrCmdOptionSettings.RestrictionList, new string[] { }).GetValueAsStringArray();

            var ignoreCase = !Command.Settings.GetSettingsCaseSensitive();

            foreach (var val in valueAsStringArray)
            {
                if ((ValueFlags.HasFlag(DrCmdValueFlags.AllowNumeric)) && (val.IsPositiveNumber()))
                {
                    continue;
                }
                var isMatched = false;
                foreach (var restrictionItem in restrictionListArray)
                {
                    if (string.Compare(restrictionItem, val, ignoreCase) == 0)
                    {
                        isMatched = true;
                        break;
                    }
                }
                if (!isMatched)
                {
                    var text = string.Format(Msg.OPTION_HAS_INCORRECT_VALUE, Name, val, CommandName) + " ";
                    if (ValueFlags.HasFlag(DrCmdValueFlags.AllowNumeric))
                    {
                        text += string.Format(Msg.OPTION_SUPPORT_ONLY_FOLLOWING_VALUES_OR_NUMERIC, GetRestrictionListWithValueAsString(", "));
                    }
                    else
                    {
                        text += string.Format(Msg.OPTION_SUPPORT_ONLY_FOLLOWING_VALUES, GetRestrictionListAsString(", "));
                    }
                    throw new ArgumentException(text);
                }
            }
        }
Esempio n. 22
0
 public FlagData(CommonFlags cf, ValueFlags vf)
 {
     commonFlags = cf;
     valueFlags  = vf;
 }
Esempio n. 23
0
 public CallableValue(ICallable callable, ValueFlags flags)
 {
     Callable = callable;
     Flags    = flags;
 }
Esempio n. 24
0
        ///////////////////////////////////////////////////////////////////////

        public static IOption FromString(
            Interpreter interpreter,
            string text,
            AppDomain appDomain,
            ValueFlags valueFlags,
            CultureInfo cultureInfo,
            ref Result error
            )
        {
            StringList list = null;

            if (Parser.SplitList(
                    interpreter, text, 0, Length.Invalid, true,
                    ref list, ref error) != ReturnCode.Ok)
            {
                return(null);
            }

            if (list.Count < MinimumElementCount)
            {
                error = String.Format(
                    "cannot create option, only {0} of {1} " +
                    "required elements were specified", list.Count,
                    MinimumElementCount);

                return(null);
            }

            bool allowInteger;
            bool strict;
            bool verbose;
            bool noCase;

            _Public.Value.ExtractTypeValueFlags(
                valueFlags, out allowInteger, out strict,
                out verbose, out noCase);

            object enumValue = EnumOps.TryParseFlagsEnum(
                interpreter, typeof(OptionFlags), null,
                list[0], cultureInfo, allowInteger, strict,
                noCase, ref error);

            if (!(enumValue is OptionFlags))
            {
                return(null);
            }

            OptionFlags optionFlags = (OptionFlags)enumValue;
            string      name        = list[1];

            if (name == null)
            {
                error = "invalid option name";
                return(null);
            }

            int  nextIndex = MinimumElementCount;
            Type type      = null;

            if (FlagOps.HasFlags(
                    optionFlags, OptionFlags.MustBeEnumMask, false))
            {
                if (nextIndex >= list.Count)
                {
                    error = String.Format(
                        "option with {0} or {1} flags must have type name",
                        FormatOps.WrapOrNull(OptionFlags.MustBeEnum),
                        FormatOps.WrapOrNull(OptionFlags.MustBeEnumList));

                    return(null);
                }

                ResultList errors = null;

                if (_Public.Value.GetType(
                        interpreter, list[nextIndex], null, appDomain,
                        _Public.Value.GetTypeValueFlags(optionFlags),
                        cultureInfo, ref type, ref errors) != ReturnCode.Ok)
                {
                    error = errors;
                    return(null);
                }

                nextIndex++;
            }

            Variant value = null;

            if (ScriptOps.GetOptionValue(
                    interpreter, list, type, optionFlags, false, allowInteger,
                    strict, noCase, cultureInfo, ref value, ref nextIndex,
                    ref error) != ReturnCode.Ok)
            {
                return(null);
            }

            int groupIndex = _Constants.Index.Invalid;

            if (nextIndex < list.Count)
            {
                if (_Public.Value.GetInteger2(
                        list[nextIndex], ValueFlags.AnyInteger, cultureInfo,
                        ref groupIndex, ref error) != ReturnCode.Ok)
                {
                    return(null);
                }

                nextIndex++;
            }

            return(new Option(
                       type, optionFlags, groupIndex, _Constants.Index.Invalid,
                       name, value));
        }
Esempio n. 25
0
 public Local(string name, ValueFlags flags, ITypeInfo returnType)
 {
     Name       = name;
     Flags      = flags;
     ReturnType = returnType;
 }
Esempio n. 26
0
        public override void WriteTo(byte[] buffer, int offset)
        {
            int nameLen;

            if (string.IsNullOrEmpty(_name))
            {
                _flags &= ~ValueFlags.Named;
                nameLen = 0;
            }
            else
            {
                _flags |= ValueFlags.Named;
                nameLen = _name.Length;
            }

            Utilities.StringToBytes("vk", buffer, offset, 2);
            Utilities.WriteBytesLittleEndian(nameLen, buffer, offset + 0x02);
            Utilities.WriteBytesLittleEndian(_dataLength, buffer, offset + 0x04);
            Utilities.WriteBytesLittleEndian(_dataIndex, buffer, offset + 0x08);
            Utilities.WriteBytesLittleEndian((int)_type, buffer, offset + 0x0C);
            Utilities.WriteBytesLittleEndian((ushort)_flags, buffer, offset + 0x10);
            if (nameLen != 0)
            {
                Utilities.StringToBytes(_name, buffer, offset + 0x14, nameLen);
            }
        }
Esempio n. 27
0
        ///////////////////////////////////////////////////////////////////////

        private static ReturnCode CreateOtherDbConnection(
            Interpreter interpreter,
            DbConnectionType dbConnectionType,
            string connectionString,
            string typeFullName,
            string typeName,
            ValueFlags valueFlags,
            ref IDbConnection connection,
            ref Result error
            )
        {
            if (interpreter == null)
            {
                error = "invalid interpreter";
                return(ReturnCode.Error);
            }

            if (String.IsNullOrEmpty(typeFullName) &&
                String.IsNullOrEmpty(typeName))
            {
                error = String.Format(
                    "invalid type name for database connection type \"{0}\"",
                    dbConnectionType);

                return(ReturnCode.Error);
            }

            ResultList errors = null;

            foreach (string thisTypeName in new string[] {
                typeFullName, typeName
            })
            {
                if (!String.IsNullOrEmpty(thisTypeName))
                {
                    try
                    {
                        Type type = null;

                        if (Value.GetType(
                                interpreter, thisTypeName, null,
                                interpreter.GetAppDomain(), valueFlags,
                                interpreter.CultureInfo, ref type,
                                ref errors) == ReturnCode.Ok)
                        {
                            connection = (IDbConnection)Activator.CreateInstance(
                                type, new object[] { connectionString });

                            return(ReturnCode.Ok);
                        }
                    }
                    catch (Exception e)
                    {
                        if (errors == null)
                        {
                            errors = new ResultList();
                        }

                        errors.Add(e);
                    }
                }
            }

            error = errors;
            return(ReturnCode.Error);
        }
Esempio n. 28
0
        ///////////////////////////////////////////////////////////////////////

        public static ReturnCode CreateDbConnection(
            Interpreter interpreter,
            DbConnectionType dbConnectionType,
            string connectionString,
            string typeFullName,
            string typeName,
            ValueFlags valueFlags,
            DbConnectionTypeStringDictionary dbConnectionTypeFullNames,
            DbConnectionTypeStringDictionary dbConnectionTypeNames,
            ref IDbConnection connection,
            ref Result error
            )
        {
            try
            {
                switch (dbConnectionType)
                {
                case DbConnectionType.None:
                {
                    //
                    // NOTE: The caller explicitly requested an invalid
                    //       database connection; therefore, return one.
                    //
                    connection = null;
                    return(ReturnCode.Ok);
                }

                case DbConnectionType.Odbc:
                {
                    connection = new OdbcConnection(connectionString);
                    return(ReturnCode.Ok);
                }

                case DbConnectionType.OleDb:
                {
                    connection = new OleDbConnection(connectionString);
                    return(ReturnCode.Ok);
                }

                case DbConnectionType.Sql:
                {
                    connection = new SqlConnection(connectionString);
                    return(ReturnCode.Ok);
                }

                case DbConnectionType.Other:
                {
                    return(CreateOtherDbConnection(
                               interpreter, dbConnectionType, connectionString,
                               typeFullName, typeName, valueFlags, ref connection,
                               ref error));
                }

                default:
                {
                    //
                    // NOTE: Lookup the type name and/or full name and
                    //       then go to the "other" case (for database
                    //       connection types that are not "built-in").
                    //
                    bool found = false;

                    if ((dbConnectionTypeFullNames != null) &&
                        dbConnectionTypeFullNames.TryGetValue(
                            dbConnectionType, out typeFullName))
                    {
                        found = true;
                    }

                    if ((dbConnectionTypeNames != null) &&
                        dbConnectionTypeNames.TryGetValue(
                            dbConnectionType, out typeName))
                    {
                        found = true;
                    }

                    if (found)
                    {
                        goto case DbConnectionType.Other;
                    }

                    error = String.Format(
                        "unsupported database connection type \"{0}\"",
                        dbConnectionType);

                    break;
                }
                }
            }
            catch (Exception e)
            {
                error = e;
            }

            return(ReturnCode.Error);
        }