public IEngineRepositoryContext OpenContext(string apiKey)
 {
     return(new EngineRepositoryContext(
                new DatabaseManagerPool(
                    SusanooCommander.ResolveDatabaseManagerFactory(),
                    factory => factory.CreateFromConnectionString(
                        System.Data.SqlClient.SqlClientFactory.Instance,
                        _ConnectionString)),
                _StringSerializer, _logger, apiKey));
 }
Esempio n. 2
0
        /// <summary>
        /// Gets the default compare method.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns>CompareMethod.</returns>
        private static CompareMethod GetDefaultCompareMethod(Type type)
        {
            var result = Comparison.Equal;

            if (type == typeof(string))
            {
                result = CompareMethod.Contains;
            }
            else if (type == typeof(DateTime) || SusanooCommander.GetDbType(type) == null)
            {
                result = CompareMethod.Ignore;
            }

            return(result);
        }
Esempio n. 3
0
        /// <summary>
        ///     Builds the data type table used for testing conversions.
        /// </summary>
        private static void BuildDataTypeTable()
        {
            SusanooCommander.DefineCommand(
                @"
                IF OBJECT_ID('tempdb..#DataTypeTable') IS NOT NULL 
                BEGIN
                    DROP TABLE #DataTypeTable;
                END

                SELECT 
                    Bit = CAST(1 AS BIT),
                    TinyInt = CAST(5 AS TINYINT),
                    SmallInt = CAST(4 AS SmallInt),
                    Int = CAST(1 AS INT),
                    BigInt = CAST(2147483648 AS BIGINT),
                    SmallMoney = CAST($10000.50 AS SMALLMONEY),
                    Money = CAST($1000000.50 AS MONEY),
                    Numeric = CAST(1000000.50 AS NUMERIC(10, 2)),
                    Decimal = CAST(1000000.50 AS DECIMAL(10, 2)),
                    Character = CAST('c' AS CHAR(1)),
                    String = CAST('varchar' AS VARCHAR(7)), 
                    Text = CAST('text' AS Text),
                    Date = CAST('12/25/2014' AS Date),
                    SmallDateTime = CAST('12/25/2014 12:00:00' AS SmallDateTime),
                    DateTime = CAST('12/25/2014 12:00:00' AS DateTime),
                    DateTime2 = CAST('12/25/2014 12:00:00' AS DateTime2(7)),
                    Time = CAST('12:00:00' AS Time),
                    Guid = CAST('E75B92A3-3299-4407-A913-C5CA196B3CAB' AS uniqueidentifier),
                    IgnoredByComponentModel = CAST('ignored' AS VARCHAR(7)),
                    IgnoredByDescriptorActionsNone = CAST('ignored' AS VARCHAR(7)),
                    IgnoredByDescriptorActionsUpdate = CAST('ignored' AS VARCHAR(7))
                INTO #DataTypeTable;",
                CommandType.Text)
            .Compile()
            .ExecuteNonQuery(DatabaseManager);
        }
Esempio n. 4
0
 /// <summary>
 /// Determines whether this deserializer applies to the type.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <returns><c>true</c> if this instance can deserialize; otherwise, <c>false</c>.</returns>
 public bool CanDeserialize(Type type)
 {
     return(SusanooCommander.GetDbType(type) != null);
 }
Esempio n. 5
0
        /// <summary>
        ///     Builds the property inclusion parameters.
        /// </summary>
        /// <param name="databaseManager">The database manager.</param>
        /// <param name="filter">The filter.</param>
        /// <returns>IEnumerable&lt;DbParameter&gt;.</returns>
        public virtual IEnumerable <DbParameter> BuildPropertyParameters(IDatabaseManager databaseManager, object filter)
        {
            var parameters = new List <DbParameter>();

            if (typeof(TFilter).GetTypeInfo().IsValueType || filter != null)
            {
                if (_explicitInclusionMode)
                {
                    foreach (var item in _parameterInclusions)
                    {
                        var propInfo = filter.GetType().GetTypeInfo()
                                       .GetProperty(item.Key, BindingFlags.Instance | BindingFlags.Public);
                        var param = databaseManager.CreateParameter();

                        param.SourceColumn  = propInfo.Name;
                        param.ParameterName = item.Key;
                        param.Direction     = ParameterDirection.Input;

#if !NETFX40
                        param.Value = propInfo.GetValue(filter);
#else
                        param.Value = propInfo.GetValue(filter, null);
#endif

                        var type = SusanooCommander.GetDbType(propInfo.PropertyType);

                        if (type.HasValue)
                        {
                            param.DbType = type.Value;
                        }

                        var value = item.Value;
                        if (value != null)
                        {
                            value.Invoke(param);
                            if (_nullValueMode == NullValueMode.FilterOnlyFull ||
                                _nullValueMode == NullValueMode.Full)
                            {
                                param.Value = ReplaceNullWithDbNull(param.Value);
                            }
                        }
                        else if (_nullValueMode == NullValueMode.FilterOnlyMinimum ||
                                 _nullValueMode == NullValueMode.FilterOnlyFull ||
                                 _nullValueMode == NullValueMode.Full)
                        {
                            param.Value = ReplaceNullWithDbNull(param.Value);
                        }

                        parameters.Add(param);
                    }
                }
                else
                {
                    var implicitProperties = _propertyMetadataExtractor
                                             .FindAllowedProperties(
                        filter.GetType().GetTypeInfo(),
                        DescriptorActions.Insert | DescriptorActions.Update | DescriptorActions.Delete,
                        _parameterInclusions.Select(p => p.Key).ToArray(),
                        _parameterExclusions.ToArray());

                    foreach (var propInfo in implicitProperties)
                    {
                        if (!_parameterExclusions.Contains(propInfo.Value.ActiveAlias))
                        {
                            var param = databaseManager.CreateParameter();

                            param.SourceColumn  = propInfo.Key.Name;
                            param.ParameterName = propInfo.Value.ActiveAlias;
                            param.Direction     = ParameterDirection.Input;
#if !NETFX40
                            param.Value = propInfo.Key.GetValue(filter);
#else
                            param.Value = propInfo.Key.GetValue(filter, null);
#endif

                            var type = SusanooCommander.GetDbType(propInfo.Key.PropertyType);

                            if (type.HasValue)
                            {
                                param.DbType = type.Value;
                            }

                            Action <DbParameter> value;
                            if (_parameterInclusions.TryGetValue(propInfo.Value.ActiveAlias, out value))
                            {
                                if (value != null)
                                {
                                    value.Invoke(param);
                                    if (_nullValueMode == NullValueMode.FilterOnlyFull ||
                                        _nullValueMode == NullValueMode.Full)
                                    {
                                        param.Value = ReplaceNullWithDbNull(param.Value);
                                    }
                                }
                                else if (_nullValueMode == NullValueMode.FilterOnlyMinimum ||
                                         _nullValueMode == NullValueMode.FilterOnlyFull ||
                                         _nullValueMode == NullValueMode.Full)
                                {
                                    param.Value = ReplaceNullWithDbNull(param.Value);
                                }
                            }
                            else
                            {
                                if (type == null)
                                {
                                    continue; //If we don't know what to do with the Type of the property
                                }
                                //and there isn't a explicit inclusion of the property, then ignore it.

                                if (_nullValueMode == NullValueMode.FilterOnlyMinimum ||
                                    _nullValueMode == NullValueMode.FilterOnlyFull ||
                                    _nullValueMode == NullValueMode.Full)
                                {
                                    param.Value = ReplaceNullWithDbNull(param.Value);
                                }
                            }

                            parameters.Add(param);
                        }
                    }
                }
            }

            return(parameters);
        }