Exemplo n.º 1
0
 public void SetTitle()
 {
     mp.Reset();
     IsTitle       = true;
     TitlePosition = 0;
     DoUpdate();
     OnInfo?.Invoke(null, new MediaPlayer.InfoEventArgs(true, null, MediaInfo.VideoRenderingStart, 0));
     OnPrepared?.Invoke();
 }
Exemplo n.º 2
0
        private void Mp_Prepared(object sender, EventArgs e)
        {
            mediaisprepared = true;
            MyDuration      = mp.Duration;
            DoUpdate();
            mp.SeekTo(InPoint);

            //OnInfo?.Invoke(sender, new MediaPlayer.InfoEventArgs(true,sender as MediaPlayer,MediaInfo.VideoRenderingStart,0));
            OnPrepared?.Invoke();

            mp.Start();
            switchingmedia = false;
        }
Exemplo n.º 3
0
        public IDbCommand Prepare(IDbConnectionSession dbSession, RequestContext context)
        {
            var dbCommand = dbSession.Connection.CreateCommand();

            dbCommand.CommandType = context.CommandType;
            dbCommand.Transaction = dbSession.Transaction;
            switch (dbCommand.CommandType)
            {
            case CommandType.Text:
            {
                string sql = context.RealSql;
                if (_sqlParamsTokens.IsMatch(sql))
                {
                    HashSet <string> parameters = new HashSet <string>();
                    sql = _sqlParamsTokens.Replace(sql, match =>
                        {
                            string paramName    = match.Groups[1].Value;
                            Parameter paramMap  = ParseParameter(context, paramName);
                            string propertyName = paramName;
                            string dbParamName  = regDbParamName.Replace(paramName, "$2_");

                            if (context.RequestParameters == null)
                            {
                                return($"{_smartSqlContext.DbPrefix}{dbParamName}");
                            }

                            object paramVal;
                            if (propertyName.Contains("."))
                            {
                                paramVal = ExpressionEvaluator.GetValue(context.RequestParameters, propertyName);
                            }
                            else
                            {
                                context.RequestParameters.TryGetValue(propertyName, out paramVal);
                            }

                            ITypeHandler typeHandler = paramMap?.Handler;
                            if (typeHandler != null)
                            {
                                AddParameterIfNotExists(dbCommand, dbParamName, paramVal, ref parameters, typeHandler);
                                return($"{_smartSqlContext.DbPrefix}{dbParamName}");
                            }
                            bool isString = paramVal is String;
                            if (paramVal is IEnumerable && !isString)
                            {
                                var enumParams           = paramVal as IEnumerable;
                                StringBuilder inParamSql = new StringBuilder();
                                inParamSql.Append("(");
                                int item_Index = 0;
                                foreach (var itemVal in enumParams)
                                {
                                    string itemParamName = $"{_smartSqlContext.DbPrefix}{dbParamName}_{item_Index}";
                                    inParamSql.AppendFormat("{0},", itemParamName);
                                    AddParameterIfNotExists(dbCommand, itemParamName, itemVal, ref parameters);
                                    item_Index++;
                                }
                                inParamSql.Remove(inParamSql.Length - 1, 1);
                                inParamSql.Append(")");
                                return(inParamSql.ToString());
                            }
                            else
                            {
                                if (new Regex("\\#{" + dbParamName + "}\\s*\\${wildcardEscapeClause}").IsMatch(context.Sql.ToString()))
                                {
                                    paramVal = $"%{paramVal}%";
                                }

                                AddParameterIfNotExists(dbCommand, dbParamName, paramVal, ref parameters);
                                return($"{_smartSqlContext.DbPrefix}{dbParamName}");
                            }
                        });
                }
                dbCommand.CommandText = sql;
                break;
            }

            case CommandType.StoredProcedure:
            {
                if (context.Request is IDataParameterCollection reqParams)
                {
                    foreach (var reqParam in reqParams)
                    {
                        dbCommand.Parameters.Add(reqParam);
                    }
                }
                dbCommand.CommandText = context.SqlId;
                break;
            }
            }
            OnPrepared?.Invoke(this, new OnPreparedEventArgs
            {
                RequestContext = context,
                DbSession      = dbSession,
                DbCommand      = dbCommand
            });
            if (_logger.IsEnabled(LogLevel.Debug))
            {
                StringBuilder dbParameterStr = new StringBuilder();
                foreach (IDbDataParameter dbParameter in dbCommand.Parameters)
                {
                    dbParameterStr.AppendFormat("{0}={1},", dbParameter.ParameterName, dbParameter.Value);
                }
                _logger.LogDebug($"PreparedCommand.Prepare->Statement.Id:[{context.FullSqlId}],Sql:[{dbCommand.CommandText}],Parameters:[{dbParameterStr}]");
            }
            return(dbCommand);
        }
Exemplo n.º 4
0
        public IDbCommand Prepare(IDbConnectionSession dbSession, RequestContext context)
        {
            var dbCommand = dbSession.Connection.CreateCommand();

            dbCommand.CommandType = context.CommandType;
            dbCommand.Transaction = dbSession.Transaction;
            switch (dbCommand.CommandType)
            {
            case CommandType.Text:
            {
                string sql = context.RealSql;
                if (_sqlParamsTokens.IsMatch(sql))
                {
                    sql = _sqlParamsTokens.Replace(sql, match =>
                        {
                            string paramName = match.Groups[1].Value;
                            var paramMap     = context.Statement?.ParameterMap?.Parameters?.FirstOrDefault(p => p.Name == paramName);
                            var propertyName = paramMap != null ? paramMap.Property : paramName;

                            if (!context.RequestParameters.Contains(propertyName))
                            {
                                if (_logger.IsEnabled(LogLevel.Warning))
                                {
                                    _logger.LogWarning($"PreparedCommand.Prepare:StatementKey:{context.StatementKey}:can not find ParamterName:{propertyName}!");
                                }
                                return(GetParameterName(match.Value));
                            }
                            var dbParameter          = context.RequestParameters.Get(propertyName);
                            ITypeHandler typeHandler = dbParameter.TypeHandler ?? paramMap?.Handler;
                            if (typeHandler != null)
                            {
                                AddDbParameter(dbCommand, dbParameter, typeHandler);
                                return(GetParameterName(match.Value));
                            }
                            var paramVal  = dbParameter.Value;
                            bool isString = paramVal is String;
                            if (paramVal is IEnumerable && !isString)
                            {
                                var enumParams           = paramVal as IEnumerable;
                                StringBuilder inParamSql = new StringBuilder();
                                inParamSql.Append("(");
                                int item_Index = 0;
                                foreach (var itemVal in enumParams)
                                {
                                    string itemParamName = $"{paramName}_{item_Index}";
                                    inParamSql.AppendFormat("{0}{1},", _smartSqlContext.DbPrefix, itemParamName);
                                    AddDbParameter(dbCommand, new DbParameter
                                    {
                                        Name  = itemParamName,
                                        Value = itemVal
                                    }, typeHandler);
                                    item_Index++;
                                }
                                if (_logger.IsEnabled(LogLevel.Warning))
                                {
                                    if (item_Index == 0)
                                    {
                                        _logger.LogWarning($"PreparedCommand.Prepare:StatementKey:{context.StatementKey}:ParamterName:{propertyName} no element For [In] Tag!");
                                    }
                                }
                                if (item_Index > 0)
                                {
                                    inParamSql.Remove(inParamSql.Length - 1, 1);
                                }
                                inParamSql.Append(")");
                                return(inParamSql.ToString());
                            }
                            else
                            {
                                AddDbParameter(dbCommand, dbParameter);
                                return(GetParameterName(match.Value));
                            }
                        });
                }
                dbCommand.CommandText = sql;
                break;
            }

            case CommandType.StoredProcedure:
            {
                AddDbParameterCollection(dbCommand, context.RequestParameters);
                dbCommand.CommandText = context.RealSql;
                break;
            }
            }
            OnPrepared?.Invoke(this, new OnPreparedEventArgs
            {
                RequestContext = context,
                DbSession      = dbSession,
                DbCommand      = dbCommand
            });
            if (_logger.IsEnabled(LogLevel.Debug))
            {
                string dbParameterStr = string.Join(",", dbCommand.Parameters.Cast <IDbDataParameter>().Select(p => $"{p.ParameterName}={p.Value}"));

                string realSql = _sqlParamsTokens.Replace(dbCommand.CommandText, (match) =>
                {
                    string paramName     = match.Groups[1].Value;
                    var paramNameCompare = _smartSqlContext.IgnoreParameterCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture;
                    var dbParam          = dbCommand.Parameters.Cast <IDbDataParameter>().FirstOrDefault(m => String.Equals(m.ParameterName, paramName, paramNameCompare));
                    if (dbParam == null)
                    {
                        return(match.Value);
                    }
                    if (dbParam.Value == DBNull.Value)
                    {
                        return("NULL");
                    }
                    switch (dbParam.DbType)
                    {
                    case DbType.AnsiString:
                    case DbType.AnsiStringFixedLength:
                    case DbType.DateTime:
                    case DbType.DateTime2:
                    case DbType.DateTimeOffset:
                    case DbType.Guid:
                    case DbType.String:
                    case DbType.StringFixedLength:
                    case DbType.Time:
                    case DbType.Xml:
                        { return($"'{dbParam.Value}'"); }

                    case DbType.Boolean:
                        {
                            return(((bool)dbParam.Value) ? "1" : "0");
                        }
                    }
                    return(dbParam.Value.ToString());
                });
                _logger.LogDebug($"PreparedCommand.Prepare->Statement.Id:[{context.FullSqlId}],Sql:{Environment.NewLine}{dbCommand.CommandText}{Environment.NewLine}Parameters:[{dbParameterStr}]{Environment.NewLine}Sql with parameter value: {Environment.NewLine}{realSql}");
            }
            return(dbCommand);
        }
Exemplo n.º 5
0
        public IDbCommand Prepare(IDbConnectionSession dbSession, RequestContext context)
        {
            var dbCommand = dbSession.Connection.CreateCommand();

            dbCommand.CommandType = context.CommandType;
            dbCommand.Transaction = dbSession.Transaction;
            switch (dbCommand.CommandType)
            {
            case CommandType.Text:
            {
                string sql = context.RealSql;
                if (_sqlParamsTokens.IsMatch(sql))
                {
                    sql = _sqlParamsTokens.Replace(sql, match =>
                        {
                            string paramName = match.Groups[1].Value;
                            var paramMap     = context.Statement?.ParameterMap?.Parameters?.FirstOrDefault(p => p.Name == paramName);
                            var propertyName = paramMap != null ? paramMap.Property : paramName;

                            if (context.RequestParameters == null
                                ||
                                !context.RequestParameters.TryGetValue(propertyName, out object paramVal))
                            {
                                return(match.Value);
                            }

                            ITypeHandler typeHandler = paramMap?.Handler;
                            if (typeHandler != null)
                            {
                                AddParameterIfNotExists(context, dbCommand, paramName, paramVal, typeHandler);
                                return(match.Value);
                            }
                            bool isString = paramVal is String;
                            if (paramVal is IEnumerable && !isString)
                            {
                                var enumParams           = paramVal as IEnumerable;
                                StringBuilder inParamSql = new StringBuilder();
                                inParamSql.Append("(");
                                int item_Index = 0;
                                foreach (var itemVal in enumParams)
                                {
                                    string itemParamName = $"{_smartSqlContext.DbPrefix}{paramName}_{item_Index}";
                                    inParamSql.AppendFormat("{0},", itemParamName);
                                    AddParameterIfNotExists(context, dbCommand, itemParamName, itemVal);
                                    item_Index++;
                                }
                                inParamSql.Remove(inParamSql.Length - 1, 1);
                                inParamSql.Append(")");
                                return(inParamSql.ToString());
                            }
                            else
                            {
                                AddParameterIfNotExists(context, dbCommand, paramName, paramVal);
                                return(match.Value);
                            }
                        });
                }
                dbCommand.CommandText = sql;
                break;
            }

            case CommandType.StoredProcedure:
            {
                if (context.Request is IDataParameterCollection reqParams)
                {
                    foreach (var reqParam in reqParams)
                    {
                        dbCommand.Parameters.Add(reqParam);
                    }
                }
                dbCommand.CommandText = context.SqlId;
                break;
            }
            }
            OnPrepared?.Invoke(this, new OnPreparedEventArgs
            {
                RequestContext = context,
                DbSession      = dbSession,
                DbCommand      = dbCommand
            });
            if (_logger.IsEnabled(LogLevel.Debug))
            {
                StringBuilder dbParameterStr = new StringBuilder();
                foreach (IDbDataParameter dbParameter in dbCommand.Parameters)
                {
                    dbParameterStr.AppendFormat("{0}={1},", dbParameter.ParameterName, dbParameter.Value);
                }
                _logger.LogDebug($"PreparedCommand.Prepare->Statement.Id:[{context.FullSqlId}],Sql:[{dbCommand.CommandText}],Parameters:[{dbParameterStr}]");
            }
            return(dbCommand);
        }
Exemplo n.º 6
0
        public IDbCommand Prepare(IDbConnectionSession dbSession, RequestContext context)
        {
            var dbCommand = dbSession.Connection.CreateCommand();

            dbCommand.CommandType = context.CommandType;
            dbCommand.Transaction = dbSession.Transaction;
            switch (dbCommand.CommandType)
            {
            case CommandType.Text:
            {
                string sql = context.RealSql;
                if (_sqlParamsTokens.IsMatch(sql))
                {
                    sql = _sqlParamsTokens.Replace(sql, match =>
                        {
                            string paramName = match.Groups[1].Value;
                            var paramMap     = context.Statement?.ParameterMap?.Parameters?.FirstOrDefault(p => p.Name == paramName);
                            var propertyName = paramMap != null ? paramMap.Property : paramName;

                            if (!context.RequestParameters.Contains(propertyName))
                            {
                                if (_logger.IsEnabled(LogLevel.Warning))
                                {
                                    _logger.LogWarning($"PreparedCommand.Prepare:StatementKey:{context.StatementKey}:can not find ParamterName:{propertyName}!");
                                }
                                return(match.Value);
                            }
                            var dbParameter          = context.RequestParameters.Get(propertyName);
                            ITypeHandler typeHandler = paramMap?.Handler;
                            if (typeHandler != null)
                            {
                                AddDbParameter(dbCommand, dbParameter, typeHandler);
                                return(match.Value);
                            }
                            var paramVal  = dbParameter.Value;
                            bool isString = paramVal is String;
                            if (paramVal is IEnumerable && !isString)
                            {
                                var enumParams           = paramVal as IEnumerable;
                                StringBuilder inParamSql = new StringBuilder();
                                inParamSql.Append("(");
                                int item_Index = 0;
                                foreach (var itemVal in enumParams)
                                {
                                    string itemParamName = $"{_smartSqlContext.DbPrefix}{paramName}_{item_Index}";
                                    inParamSql.AppendFormat("{0},", itemParamName);
                                    AddDbParameter(dbCommand, new DbParameter
                                    {
                                        Name  = itemParamName,
                                        Value = itemVal
                                    }, typeHandler);
                                    item_Index++;
                                }
                                inParamSql.Remove(inParamSql.Length - 1, 1);
                                inParamSql.Append(")");
                                return(inParamSql.ToString());
                            }
                            else
                            {
                                AddDbParameter(dbCommand, dbParameter);
                                return(match.Value);
                            }
                        });
                }
                dbCommand.CommandText = sql;
                break;
            }

            case CommandType.StoredProcedure:
            {
                AddDbParameterCollection(dbCommand, context.RequestParameters);
                dbCommand.CommandText = context.RealSql;
                break;
            }
            }
            OnPrepared?.Invoke(this, new OnPreparedEventArgs
            {
                RequestContext = context,
                DbSession      = dbSession,
                DbCommand      = dbCommand
            });
            if (_logger.IsEnabled(LogLevel.Debug))
            {
                string dbParameterStr = string.Join(",", dbCommand.Parameters.Cast <IDbDataParameter>().Select(p => $"{p.ParameterName}={p.Value}"));
                _logger.LogDebug($"PreparedCommand.Prepare->Statement.Id:[{context.FullSqlId}],Sql:[{dbCommand.CommandText}],Parameters:[{dbParameterStr}]");
            }
            return(dbCommand);
        }
Exemplo n.º 7
0
        public IDbCommand Prepare(IDbConnectionSession dbSession, RequestContext context)
        {
            var dbCommand = dbSession.Connection.CreateCommand();

            dbCommand.CommandType = context.CommandType;
            dbCommand.Transaction = dbSession.Transaction;
            switch (dbCommand.CommandType)
            {
            case CommandType.Text:
            {
                string sql = SqlParamAnalyzer.Replace(context.RealSql, (paramName, nameWithPrefix) =>
                    {
                        var paramMap     = context.GetParameterMap(paramName);
                        var propertyName = paramMap != null ? paramMap.Property : paramName;
                        var dbParameter  = context.RequestParameters.Get(propertyName);
                        if (dbParameter == null)
                        {
                            if (_logger.IsEnabled(LogLevel.Warning))
                            {
                                _logger.LogWarning($"PreparedCommand.Prepare:StatementKey:{context.StatementKey}:can not find ParamterName:{propertyName}!");
                            }
                            return(GetParameterName(nameWithPrefix));
                        }

                        ITypeHandler typeHandler = dbParameter.TypeHandler ?? paramMap?.Handler;
                        AddDbParameter(dbCommand, dbParameter, typeHandler);
                        return(GetParameterName(nameWithPrefix));
                    });
                dbCommand.CommandText = sql;
                break;
            }

            case CommandType.StoredProcedure:
            {
                AddDbParameterCollection(dbCommand, context.RequestParameters);
                dbCommand.CommandText = context.RealSql;
                break;
            }
            }
            OnPrepared?.Invoke(this, new OnPreparedEventArgs
            {
                RequestContext = context,
                DbSession      = dbSession,
                DbCommand      = dbCommand
            });
            if (_logger.IsEnabled(LogLevel.Debug))
            {
                string dbParameterStr = string.Join(",", dbCommand.Parameters.Cast <IDbDataParameter>().Select(p => $"{p.ParameterName}={p.Value}"));

                string realSql = SqlParamAnalyzer.Replace(dbCommand.CommandText, (paramName, nameWithPrefix) =>
                {
                    var paramNameCompare = _smartSqlContext.IgnoreParameterCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture;
                    var dbParam          = dbCommand.Parameters.Cast <IDbDataParameter>().FirstOrDefault(m => String.Equals(m.ParameterName, paramName, paramNameCompare));
                    if (dbParam == null)
                    {
                        return(nameWithPrefix);
                    }
                    if (dbParam.Value == DBNull.Value)
                    {
                        return("NULL");
                    }
                    switch (dbParam.DbType)
                    {
                    case DbType.AnsiString:
                    case DbType.AnsiStringFixedLength:
                    case DbType.DateTime:
                    case DbType.DateTime2:
                    case DbType.DateTimeOffset:
                    case DbType.Guid:
                    case DbType.String:
                    case DbType.StringFixedLength:
                    case DbType.Time:
                    case DbType.Xml:
                        { return($"'{dbParam.Value}'"); }

                    case DbType.Boolean:
                        {
                            return(((bool)dbParam.Value) ? "1" : "0");
                        }
                    }
                    return(dbParam.Value.ToString());
                });
                _logger.LogDebug($"PreparedCommand.Prepare->Statement.Id:[{context.FullSqlId}],Sql:{Environment.NewLine}{dbCommand.CommandText}{Environment.NewLine}Parameters:[{dbParameterStr}]{Environment.NewLine}Sql with parameter value: {Environment.NewLine}{realSql}");
            }
            return(dbCommand);
        }