Esempio n. 1
0
        public override void WriteOutputToDisk(byte[] bytes, string fileName = null, string fileExt = ".json")
        {
            if (string.IsNullOrWhiteSpace(_reassignAssemblySubjectName))
            {
                base.WriteOutputToDisk(bytes, fileName, fileExt);
                return;
            }

            var isFullAssemblyName = NfReflect.IsAssemblyFullName(_reassignAssemblySubjectName);
            var isFullPath         = Path.IsPathRooted(_reassignAssemblySubjectName);
            var isFileName         = _reassignAssemblySubjectName.EndsWith(".dll") ||
                                     _reassignAssemblySubjectName.EndsWith(".exe");

            if (isFullAssemblyName)
            {
                var assemblyName = new System.Reflection.AssemblyName(_reassignAssemblySubjectName);
                _reassignAssemblySubjectName = assemblyName.Name;
            }

            if (isFullPath)
            {
                var dirName = Path.GetDirectoryName(_reassignAssemblySubjectName);
                if (!string.IsNullOrWhiteSpace(dirName))
                {
                    _reassignAssemblySubjectName = _reassignAssemblySubjectName.Replace(dirName, "");
                }
            }

            if (isFileName)
            {
                var flname = Path.GetFileNameWithoutExtension(_reassignAssemblySubjectName);
                if (!string.IsNullOrWhiteSpace(flname))
                {
                    _reassignAssemblySubjectName = flname;
                }
            }

            var tn = fileName ?? GetType().Name;

            tn = NfPath.SafeFilename(tn);
            var dir = MyProgram == null ? NfSettings.AppData : MyProgram.LogDirectory;

            var rootAsmName = NfPath.SafeDirectoryName(_reassignAssemblySubjectName);

            dir = Path.Combine(dir, rootAsmName);
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            File.WriteAllBytes(Path.Combine(dir, tn + fileExt), bytes);
        }
Esempio n. 2
0
        public SqlDbType GetSqlDataType()
        {
            if (IsUserDefinedType && NfReflect.IsAssemblyFullName(DataType))
            {
                return(SqlDbType.Udt);
            }

            if (NfReflect.IsAssemblyFullName(DataType))
            {
                return(SqlDbType.NVarChar);
            }

            SqlDbType dbTypeOut;

            Enum.TryParse(dataType, true, out dbTypeOut);
            return(dbTypeOut);
        }
Esempio n. 3
0
        /// <summary>
        /// With a MSSQL Stored Proc there is no way of knowing what, if any, kind of dataset
        /// will be returned.  This is inteneded as a heuristic solution and is expected to
        /// be called prior to actually invoking the stored proc on a SqlClient connection\command.
        /// </summary>
        /// <param name="sqlParams"></param>
        public void AssignSpParams(SqlParameterCollection sqlParams)
        {
            if (string.IsNullOrWhiteSpace(ProcName))
            {
                throw new RahRowRagee("This instance does not have a ProcName assigned.");
            }
            var myRand = new Random(Convert.ToInt32(string.Format("{0:ffffff}", DateTime.Now)));

            foreach (var param in Parameters)
            {
                if (param.IsDataTable())
                {
                    sqlParams.Add(new SqlParameter(param.ParamName, null));
                    continue;
                }
                var randStr = new StringBuilder();
                var llen    = param.StringLength > MAX_STR_LEN || param.StringLength < 0
                    ? MAX_STR_LEN
                    : param.StringLength;

                //assign some lower-case letters
                for (var i = 0; i < llen; i++)
                {
                    randStr.Append(Convert.ToChar((byte)myRand.Next(0x61, 0x7A)));
                }

                if (param.IsOpenToSqlInj.GetValueOrDefault(false))
                {
                    randStr.Clear();
                    //we just want the schema not the data...
                    randStr.Append(" AND 1 = 0");
                }

                SqlParameter sqlParam;
                var          sqlParamType = param.GetSqlDataType();
                switch (sqlParamType)
                {
                case SqlDbType.NText:
                case SqlDbType.NVarChar:
                case SqlDbType.Text:
                case SqlDbType.VarChar:
                    sqlParam = new SqlParameter(param.ParamName, param.GetSqlDataType())
                    {
                        IsNullable = param.IsNullable,
                        Direction  = param.IsOutput ? ParameterDirection.Output : ParameterDirection.Input,
                        Value      = randStr.ToString()
                    };
                    break;

                case SqlDbType.Xml:
                    sqlParam = new SqlParameter(param.ParamName, param.GetSqlDataType())
                    {
                        IsNullable = param.IsNullable,
                        Direction  = param.IsOutput ? ParameterDirection.Output : ParameterDirection.Input,
                        Value      = "<my-node>" + randStr + "</my-node>"
                    };
                    break;

                case SqlDbType.NChar:
                case SqlDbType.Char:
                    sqlParam = new SqlParameter(param.ParamName, param.GetSqlDataType())
                    {
                        IsNullable = param.IsNullable,
                        Direction  = param.IsOutput ? ParameterDirection.Output : ParameterDirection.Input,
                        Value      = Convert.ToChar((byte)myRand.Next(0x61, 0x7A))
                    };
                    break;

                case SqlDbType.BigInt:
                case SqlDbType.Decimal:
                case SqlDbType.Float:
                case SqlDbType.Int:
                case SqlDbType.Money:
                case SqlDbType.Real:
                case SqlDbType.SmallInt:
                case SqlDbType.SmallMoney:
                case SqlDbType.TinyInt:
                    sqlParam = new SqlParameter(param.ParamName, param.GetSqlDataType())
                    {
                        IsNullable = param.IsNullable,
                        Direction  = param.IsOutput ? ParameterDirection.Output : ParameterDirection.Input,
                        Value      = myRand.Next(1, 255)//should fit all types
                    };
                    break;

                case SqlDbType.Bit:
                    sqlParam = new SqlParameter(param.ParamName, param.GetSqlDataType())
                    {
                        IsNullable = param.IsNullable,
                        Direction  = param.IsOutput ? ParameterDirection.Output : ParameterDirection.Input,
                        Value      = 1
                    };
                    break;

                case SqlDbType.Date:
                case SqlDbType.DateTime:
                case SqlDbType.DateTime2:
                case SqlDbType.DateTimeOffset:
                case SqlDbType.SmallDateTime:
                case SqlDbType.Time:
                    sqlParam = new SqlParameter(param.ParamName, param.GetSqlDataType())
                    {
                        IsNullable = param.IsNullable,
                        Direction  = param.IsOutput ? ParameterDirection.Output : ParameterDirection.Input,
                        Value      = DateTime.Now
                    };
                    break;

                default:
                    sqlParam = new SqlParameter(param.ParamName, param.GetSqlDataType())
                    {
                        IsNullable = param.IsNullable,
                        Direction  = param.IsOutput ? ParameterDirection.Output : ParameterDirection.Input,
                        Value      = DBNull.Value
                    };
                    break;
                }


                if (param.IsUserDefinedType && NfReflect.IsAssemblyFullName(param.DataType))
                {
                    sqlParam.UdtTypeName = param.SqlUdtTypeName;
                }

                sqlParams.Add(sqlParam);
            }
        }
Esempio n. 4
0
 public bool IsDataTable()
 {
     return(!string.IsNullOrWhiteSpace(DataType) && NfReflect.IsAssemblyFullName(DataType) &&
            DataType.StartsWith("System.Data.DataTable"));
 }