示例#1
0
        /// <inheritdoc/>
        protected override string BuildConnectionString(UrlInfo connectionUrl)
        {
            SqlHelper.ValidateConnectionUrl(connectionUrl);
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(connectionUrl.Resource, "connectionUrl.Resource");
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(connectionUrl.Host, "connectionUrl.Host");

            var builder = new FbConnectionStringBuilder();

            // host, port, database
            if (!string.IsNullOrEmpty(connectionUrl.Host))
            {
                var port = connectionUrl.Port != 0 ? connectionUrl.Port : DefaultPort;
                builder.Database              = connectionUrl.Resource;
                builder.DataSource            = connectionUrl.Host;
                builder.Dialect               = 3;
                builder.Pooling               = false;
                builder.Port                  = port;
                builder.ReturnRecordsAffected = true;
            }

            // user, password
            if (!string.IsNullOrEmpty(connectionUrl.User))
            {
                builder.UserID   = connectionUrl.User;
                builder.Password = connectionUrl.Password;
            }

            // custom options
            foreach (var parameter in connectionUrl.Params)
            {
                builder.Add(parameter.Key, parameter.Value);
            }

            return(builder.ToString());
        }
示例#2
0
        public static MethodInfo GetMethod(this Type type, string name, BindingFlags bindingFlags, string[] genericArgumentNames, object[] parameterTypes)
        {
            ArgumentValidator.EnsureArgumentNotNull(type, "type");
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(name, "name");

            if (genericArgumentNames == null)
            {
                genericArgumentNames = ArrayUtils <string> .EmptyArray;
            }
            if (parameterTypes == null)
            {
                parameterTypes = ArrayUtils <object> .EmptyArray;
            }
            bool parameterTypesAreFullyDefined = true;

            for (int i = 0; i < parameterTypes.Length; i++)
            {
                var parameterType = parameterTypes[i] as Type;
                if (parameterType == null || parameterType.IsGenericTypeDefinition || parameterType == typeof(AnyArrayPlaceholder))
                {
                    parameterTypesAreFullyDefined = false;
                    break;
                }
            }

            if (parameterTypesAreFullyDefined)
            {
                // Let's try to find an exact match
                Type[] exactParameterTypes = new Type[parameterTypes.Length];
                for (int i = 0; i < parameterTypes.Length; i++)
                {
                    exactParameterTypes[i] = (Type)parameterTypes[i];
                }
                try {
                    MethodInfo m = type.GetMethod(name, bindingFlags, null, exactParameterTypes, null);
                    if (m != null)
                    {
                        return(CheckMethod(m, type, name, genericArgumentNames, parameterTypes) ?  m : null);
                    }
                }
                catch (AmbiguousMatchException) {
                }
            }

            // No exact match... Trying to find the match by checking all methods
            MethodInfo lastMatch = null;

            foreach (MethodInfo m in type.GetMethods(bindingFlags))
            {
                if (CheckMethod(m, type, name, genericArgumentNames, parameterTypes))
                {
                    if (lastMatch != null)
                    {
                        throw new AmbiguousMatchException();
                    }
                    lastMatch = m;
                }
            }
            return(lastMatch);
        }
示例#3
0
        /// <summary>
        ///     Initializes a new instance of this class.
        /// </summary>
        /// <param name="name">Value for <see cref="Name"/>.</param>
        public SessionConfiguration(string name, SessionOptions sessionOptions)
        {
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(name, "name");

            Name    = name;
            Options = sessionOptions;
            switch (name)
            {
            case WellKnown.Sessions.System:
                Type = SessionType.System;
                break;

            case WellKnown.Sessions.Service:
                Type = SessionType.Service;
                break;

            case WellKnown.Sessions.KeyGenerator:
                Type = SessionType.KeyGenerator;
                break;

            default:
                Type = SessionType.User;
                break;
            }
        }
示例#4
0
 /// <summary>
 /// Adds mapping between <paramref name="originalName"/>
 /// and <paramref name="mappedName"/>.
 /// </summary>
 /// <param name="originalName"></param>
 /// <param name="mappedName"></param>
 public void Add([NotNull] string originalName, [NotNull] string mappedName)
 {
     ArgumentValidator.EnsureArgumentNotNullOrEmpty(originalName, "originalName");
     ArgumentValidator.EnsureArgumentNotNullOrEmpty(mappedName, "mappedName");
     this.EnsureNotLocked();
     items[originalName] = mappedName;
 }
        /// <inheritdoc/>
        public IPrincipal Authenticate(IIdentity identity, params object[] args)
        {
            ArgumentValidator.EnsureArgumentNotNull(identity, "identity");
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(identity.Name, "identity.Name");

            return(Authenticate(identity.Name, args));
        }
示例#6
0
        // Constructors

        /// <summary>
        /// Initializes a new instance of this class.
        /// </summary>
        /// <param name="source">A value for <see cref="UnaryProvider.Source"/>.</param>
        /// <param name="algorithm">A value for <see cref="Algorithm"/>.</param>
        /// <param name="isInlined">A value for <see cref="IsInlined"/>.</param>
        /// <param name="filterDataSource">A value for <see cref="FilterDataSource"/>.</param>
        /// <param name="resultColumnName">A value for <see cref="ResultColumnName"/>.</param>
        /// <param name="filteredColumns">A value for <see cref="FilteredColumns"/>.</param>
        public IncludeProvider(CompilableProvider source, IncludeAlgorithm algorithm, bool isInlined,
                               Expression <Func <IEnumerable <Tuple> > > filterDataSource, string resultColumnName, IReadOnlyList <int> filteredColumns)
            : base(ProviderType.Include, source)
        {
            ArgumentValidator.EnsureArgumentNotNull(filterDataSource, "filterDataSource");
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(resultColumnName, "resultColumnName");
            ArgumentValidator.EnsureArgumentNotNull(filteredColumns, "filteredColumns");
            Algorithm        = algorithm;
            IsInlined        = isInlined;
            FilterDataSource = filterDataSource;
            ResultColumnName = resultColumnName;

            switch (filteredColumns)
            {
            case int[] columnArray:
                FilteredColumns = Array.AsReadOnly(columnArray);
                break;

            case List <int> columnList:
                FilteredColumns = columnList.AsReadOnly();
                break;

            default:
                FilteredColumns = filteredColumns;
                break;
            }

            Initialize();
        }
        /// <summary>
        /// Creates an array of generic method invocation delegates matching the method instance
        /// with specified generic argument variants.
        /// </summary>
        /// <param name="callTarget">The delegate call target. <see langword="Null"/>, if static method should be called.</param>
        /// <param name="type">Type, which method should be called by delegate.</param>
        /// <param name="methodName">The name of the method to call by delegate.</param>
        /// <param name="genericArgumentVariants">Generic method argument variants.</param>
        /// <returns>An array of delegate allowing to call specified generic method instances on <paramref name="callTarget"/>.</returns>
        /// <typeparam name="TDelegate">Type of delegate to create.</typeparam>
        /// <exception cref="ArgumentException"><c>ArgumentException</c>.</exception>
        public static TDelegate[] CreateDelegates <TDelegate>(object callTarget, Type type, string methodName, IList <Type> genericArgumentVariants)
            where TDelegate : class
        {
            ArgumentValidator.EnsureArgumentNotNull(type, "type");
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(methodName, "methodName");
            ArgumentValidator.EnsureArgumentNotNull(genericArgumentVariants, "genericArgumentVariants");
            Type delegateType = typeof(TDelegate);

            if (!typeof(Delegate).IsAssignableFrom(delegateType))
            {
                throw new ArgumentException(string.Format(Strings.ExGenericParameterShouldBeOfTypeT,
                                                          "TDelegate", typeof(Delegate).GetShortName()));
            }

            int count = genericArgumentVariants.Count;

            TDelegate[] delegates = new TDelegate[count];
            if (count == 0)
            {
                return(delegates);
            }

            BindingFlags bindingFlags =
                BindingFlags.Public |
                BindingFlags.NonPublic |
                BindingFlags.ExactBinding;

            if (callTarget == null)
            {
                bindingFlags |= BindingFlags.Static;
            }
            else
            {
                bindingFlags |= BindingFlags.Instance;
            }
            string[] genericArgumentNames = new string[1]; // Actual names doesn't matter
            Type[]   parameterTypes       = delegateType.GetInvokeMethod().GetParameterTypes();

            MethodInfo methodInfo = MethodHelper.GetMethod(type, methodName, bindingFlags,
                                                           genericArgumentNames, parameterTypes);

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

            for (int i = 0; i < count; i++)
            {
                MethodInfo instantiatedMethodInfo = methodInfo.MakeGenericMethod(genericArgumentVariants[i]);
                if (callTarget == null)
                {
                    delegates[i] = (TDelegate)(object)Delegate.CreateDelegate(delegateType, instantiatedMethodInfo, true);
                }
                else
                {
                    delegates[i] = (TDelegate)(object)Delegate.CreateDelegate(delegateType, callTarget, instantiatedMethodInfo, true);
                }
            }
            return(delegates);
        }
示例#8
0
 /// <summary>
 /// Invoke this method to register types from the specified <see cref="Assembly"/>.
 /// Search is restricted by assembly and namespace.
 /// </summary>
 /// <param name="assembly">Assembly to search for types.</param>
 /// <param name="namespace">Namespace to search for types.</param>
 /// <exception cref="InvalidOperationException">When <see cref="Assembly.GetTypes()"/>
 /// method call has thrown an exception or if no suitable types were found.</exception>
 /// <exception cref="ArgumentNullException">When <paramref name="assembly"/> is null
 /// or <paramref name="namespace"/> is empty string.</exception>
 public void Register(Assembly assembly, string @namespace)
 {
     this.EnsureNotLocked();
     ArgumentValidator.EnsureArgumentNotNull(assembly, "assembly");
     ArgumentValidator.EnsureArgumentNotNullOrEmpty(@namespace, "@namespace");
     Register(new TypeRegistration(assembly, @namespace));
 }
        // Constructors

        /// <summary>
        /// Creates new instance of this class.
        /// </summary>
        /// <param name="name">Database name.</param>
        public DatabaseConfiguration(string name)
        {
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(name, "name");
            Name      = name;
            minTypeId = TypeInfo.MinTypeId;
            maxTypeId = int.MaxValue;
        }
        /// <summary>
        /// Initializes a new instance of this type.
        /// </summary>
        /// <param name="ownerType">Owner type with recycled field.</param>
        /// <param name="fieldName">Name of recycled field.</param>
        /// <param name="fieldType">Type of recycled field.</param>
        /// <param name="originalFieldName">Original field name.</param>
        public RecycledFieldDefinition(Type ownerType, string fieldName, Type fieldType, string originalFieldName)
        {
            Initialize(ownerType, fieldName, fieldType);
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(originalFieldName, "originalFieldName");

            OriginalFieldName = originalFieldName;
        }
示例#11
0
        public virtual IEnumerable <CommandPart> CreatePersistParts(SqlPersistTask task, string parameterNamePrefix)
        {
            ArgumentValidator.EnsureArgumentNotNull(task, "task");
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(parameterNamePrefix, "parameterNamePrefix");

            var result         = new List <CommandPart>();
            int parameterIndex = 0;

            foreach (var request in task.RequestSequence)
            {
                var tuple             = task.Tuple;
                var compilationResult = request.GetCompiledStatement();
                var configuration     = new SqlPostCompilerConfiguration();
                var part = new CommandPart();

                foreach (var binding in request.ParameterBindings)
                {
                    var parameterValue = GetParameterValue(task, binding);
                    if (binding.BindingType == PersistParameterBindingType.VersionFilter && IsHandledLikeNull(parameterValue))
                    {
                        configuration.AlternativeBranches.Add(binding);
                    }
                    else
                    {
                        var parameterName = GetParameterName(parameterNamePrefix, ref parameterIndex);
                        configuration.PlaceholderValues.Add(binding, Driver.BuildParameterReference(parameterName));
                        AddParameter(part, binding, parameterName, parameterValue);
                    }
                }

                part.Statement = compilationResult.GetCommandText(configuration);
                result.Add(part);
            }
            return(result);
        }
示例#12
0
 /// <summary>
 /// Initializes new instance of this type.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="typeName">Name of the type.</param>
 /// <param name="length">The length.</param>
 /// <param name="precision">The precision.</param>
 /// <param name="scale">The scale.</param>
 public SqlValueType(SqlType type, string typeName, int?length, int?precision, int?scale)
 {
     if ((type == SqlType.Unknown) != (typeName != null))
     {
         throw new ArgumentException(Strings.ExInvalidArgumentsNonNullTypeNameIsAllowedIfAndOnlyIfTypeEqualsSqlTypeUnknown);
     }
     if (precision.HasValue && precision != 0 && length.HasValue && length != 0)
     {
         throw new ArgumentException(Strings.ExInvalidArgumentsPrecisionAndLengthShouldNotBeUsedTogether);
     }
     if (precision.HasValue != scale.HasValue)
     {
         throw new ArgumentException(Strings.ExInvalidArgumentsScaleAndPrecisionShouldBeUsedTogether);
     }
     if (typeName != null)
     {
         ArgumentValidator.EnsureArgumentNotNullOrEmpty(typeName, "typeName");
     }
     if (length != null)
     {
         ArgumentValidator.EnsureArgumentIsGreaterThan(length.Value, 0, "length");
     }
     if (precision != null)
     {
         ArgumentValidator.EnsureArgumentIsInRange(scale.Value, 0, precision.Value, "scale");
     }
     Type      = type;
     TypeName  = typeName;
     Length    = length;
     Precision = precision;
     Scale     = scale;
 }
        // Constructors

        /// <summary>
        /// Initializes new instance of this type.
        /// </summary>
        /// <param name="provider">A value for <see cref="Provider"/>.</param>
        /// <param name="connectionString">A value for <see cref="ConnectionString"/>.</param>
        public ConnectionInfo(string provider, string connectionString)
        {
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(provider, "provider");
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(connectionString, "connectionString");

            ConnectionString = connectionString;
            Provider         = provider.ToLowerInvariant();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PairedNodeCollection{TOwner,TNode}"/> class.
 /// </summary>
 /// <param name="owner">The collection owner.</param>
 /// <param name="property">Owner collection property.</param>
 /// <param name="capacity">The initial collection capacity.</param>
 public PairedNodeCollection(TOwner owner, string property, int capacity)
     : base(capacity)
 {
     ArgumentValidator.EnsureArgumentNotNull(owner, "owner");
     ArgumentValidator.EnsureArgumentNotNullOrEmpty(property, "property");
     this.owner    = owner;
     this.property = property;
 }
示例#15
0
        // Constructors

        /// <summary>
        /// Initializes new instance of this type.
        /// </summary>
        protected DataHint(string sourceTablePath, IList <IdentityPair> identities)
        {
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(sourceTablePath, "sourceTablePath");
            ArgumentValidator.EnsureArgumentNotNull(identities, "pairs");

            SourceTablePath = sourceTablePath;
            Identities      = new ReadOnlyList <IdentityPair>(identities);
        }
示例#16
0
        // Constructors

        /// <summary>
        /// Initializes new instance of this type.
        /// </summary>
        /// <param name="parent"><see cref="Parent"/> property value.</param>
        /// <param name="name"><see cref="Name"/> property value.</param>
        protected NodeCollection(Node parent, string name)
        {
            ArgumentValidator.EnsureArgumentNotNull(parent, "parent");
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(name, "name");
            this.name   = name;
            this.parent = parent;
            Initialize();
        }
        // Constructors

        /// <summary>
        /// Initializes a new instance of this class.
        /// </summary>
        /// <param name="type">Value for <see cref="Type"/>.</param>
        /// <param name="field">Value for <see cref="Field"/>.</param>
        public RemoveFieldHint(string type, string field)
        {
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(type, "type");
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(field, "field");
            Type            = type;
            Field           = field;
            AffectedColumns = new ReadOnlyList <string>(new List <string>());
        }
示例#18
0
        // Constructors

        internal Nesting(Node node, string propertyName)
        {
            ArgumentValidator.EnsureArgumentNotNull(node, "node");
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(propertyName, "propertyName");
            Node         = node;
            PropertyName = propertyName;
            Initialize();
        }
        /// <summary>
        /// Creates and returns a <see cref="DbCommand"/> object with specified <paramref name="commandText"/>.
        /// Created command will be associated with the current connection.
        /// </summary>
        /// <returns>Created command.</returns>
        public DbCommand CreateCommand(string commandText)
        {
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(commandText, "commandText");
            var command = CreateCommand();

            command.CommandText = commandText;
            return(command);
        }
示例#20
0
 /// <summary>
 /// Instantiates specified generic type; returns <see langword="null"/>, if either no such a type,
 /// or an error has occurred.
 /// </summary>
 /// <param name="assembly">Assembly where the type is located.</param>
 /// <param name="typeName">Name of the type to instantiate.</param>
 /// <param name="genericArguments">Generic arguments for the type to instantiate 
 /// (<see langword="null"/> means type isn't a generic type definition).</param>
 /// <param name="arguments">Arguments to pass to the type constructor.</param>
 /// <returns>An instance of specified type; <see langword="null"/>, if either no such a type,
 /// or an error has occurred.</returns>
 public static object Activate(Assembly assembly, string typeName, Type[] genericArguments, params object[] arguments)
 {
   ArgumentValidator.EnsureArgumentNotNull(assembly, "assembly");
   ArgumentValidator.EnsureArgumentNotNullOrEmpty(typeName, "typeName");
   Type type = assembly.GetType(typeName, false);
   if (type==null)
     return null;
   return Activate(type, genericArguments, arguments);
 }
        public SequenceQuery(string insertQuery, string selectQuery, SequenceQueryCompartment compartment)
        {
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(insertQuery, "insertQuery");
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(selectQuery, "selectQuery");

            InsertQuery = insertQuery;
            SelectQuery = selectQuery;
            Compartment = compartment;
        }
        // Constructors

        /// <summary>
        /// Initializes a new instance of this class.
        /// </summary>
        /// <param name="type">Value for <see cref="Type"/>.</param>
        /// <param name="fieldName">Value for <see cref="FieldName"/>.</param>
        public ChangeFieldTypeHint(Type type, string fieldName)
        {
            ArgumentValidator.EnsureArgumentNotNull(type, "type");
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(fieldName, "sourceField");

            Type            = type;
            FieldName       = fieldName;
            AffectedColumns = new ReadOnlyList <string>(new List <string>());
        }
示例#23
0
        // Constructors

        /// <summary>
        /// Initializes a new instance of this class.
        /// </summary>
        /// <param name="targetType">The current type.</param>
        /// <param name="oldFieldName">Old name of the field.</param>
        /// <param name="newFieldName">New name of the field.</param>
        public RenameFieldHint(Type targetType, string oldFieldName, string newFieldName)
        {
            ArgumentValidator.EnsureArgumentNotNull(targetType, "targetType");
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(oldFieldName, "oldFieldName");
            ArgumentValidator.EnsureArgumentNotNull(newFieldName, "newFieldName");

            TargetType   = targetType;
            OldFieldName = oldFieldName;
            NewFieldName = newFieldName;
        }
        private void EnsureItemIsValid(SessionConfiguration item)
        {
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(item.Name, "SessionConfiguration.Name");
            var current = this[item.Name];

            if (current != null)
            {
                throw new InvalidOperationException(string.Format(Strings.ExConfigurationWithXNameAlreadyRegistered, current.Name));
            }
        }
示例#25
0
 public static SqlRenameTable Rename(Table table, string newName)
 {
     ArgumentValidator.EnsureArgumentNotNull(table, "table");
     ArgumentValidator.EnsureArgumentNotNullOrEmpty(newName, "newName");
     if (table.Name == newName)
     {
         throw new ArgumentException(Strings.ExTableAlreadyHasSpecifiedName);
     }
     return(new SqlRenameTable(table, newName));
 }
示例#26
0
 public static SqlAlterTable Rename(TableColumn column, string newName)
 {
     ArgumentValidator.EnsureArgumentNotNull(column, "table");
     ArgumentValidator.EnsureArgumentNotNullOrEmpty(newName, "newName");
     if (column.Name == newName)
     {
         throw new ArgumentException(Strings.ExColumnAlreadyHasSpecifiedName);
     }
     return(Alter(column.Table, new SqlRenameColumn(column, newName)));
 }
        private void Initialize(Type ownerType, string fieldName, Type fieldType)
        {
            ArgumentValidator.EnsureArgumentNotNull(ownerType, "ownerType");
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(fieldName, "fieldName");
            ArgumentValidator.EnsureArgumentNotNull(fieldType, "fieldType");

            OwnerType = ownerType;
            FieldName = fieldName;
            FieldType = fieldType;
        }
示例#28
0
        /// <summary>
        /// Defines the field and adds it to the <see cref="Fields"/>.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="valueType">The type of the field value.</param>
        /// <returns></returns>
        public FieldDef DefineField(string name, Type valueType)
        {
            ArgumentValidator.EnsureArgumentNotNull(valueType, "type");
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(name, "name");

            FieldDef field = builder.DefineField(UnderlyingType, name, valueType);

            fields.Add(field);
            return(field);
        }
        // Constructors

        /// <summary>
        /// Initializes a new instance of this class.
        /// </summary>
        /// <param name="sourceType">Value for <see cref="SourceType"/>.</param>
        /// <param name="sourceField">Value for <see cref="SourceField"/>.</param>
        /// <param name="targetType">Value for <see cref="TargetType"/>.</param>
        /// <param name="targetField">Value for <see cref="TargetField"/>.</param>
        public CopyFieldHint(string sourceType, string sourceField, Type targetType, string targetField)
        {
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(sourceType, "sourceType");
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(sourceField, "sourceField");
            ArgumentValidator.EnsureArgumentNotNull(targetType, "targetType");
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(targetField, "targetField");
            SourceType  = sourceType;
            SourceField = sourceField;
            TargetType  = targetType;
            TargetField = targetField;
        }
        // Constructors

        public QueryParameterIdentity(TypeMapping mapping, object closureObject, string fieldName, QueryParameterBindingType bindingType)
        {
            ArgumentValidator.EnsureArgumentNotNull(mapping, "mapping");
            ArgumentValidator.EnsureArgumentNotNull(closureObject, "closureObject");
            ArgumentValidator.EnsureArgumentNotNullOrEmpty(fieldName, "fieldName");

            Mapping       = mapping;
            ClosureObject = closureObject;
            FieldName     = fieldName;
            BindingType   = bindingType;
        }