public void BindAsync_IfUserDataType_ReturnsValidBindingData(string userPropertyName, string userPropertyValue) { // Arrange UserDataType expectedObject = new UserDataType(); PropertyInfo userProperty = typeof(UserDataType).GetProperty(userPropertyName); var parseMethod = userProperty.PropertyType.GetMethod( "Parse", new Type[] { typeof(string) }); object convertedPropertyValue = parseMethod.Invoke(null, new object[] { userPropertyValue }); userProperty.SetValue(expectedObject, convertedPropertyValue); string messageContent = JsonConvert.SerializeObject(expectedObject); ValueBindingContext context = new ValueBindingContext(null, CancellationToken.None); Action <ITriggerBinding> testBinding = (b) => { // Act Message message = new Message(Encoding.UTF8.GetBytes(messageContent)); message.ContentType = ContentTypes.ApplicationJson; ITriggerData data = _queueBinding.BindAsync(message, context).GetAwaiter().GetResult(); // Assert Assert.NotNull(data); Assert.NotNull(data.ValueProvider); Assert.NotNull(data.BindingData); Assert.True(data.BindingData.ContainsKey(userPropertyName)); Assert.Equal(userProperty.GetValue(expectedObject, null), data.BindingData[userPropertyName]); }; testBinding(_queueBinding); testBinding(_topicBinding); }
public async Task <int> Update(UserDataType pEntity) { using SqlConnection con = _connection.DBPLANILLA(); SqlCommand cmd = new SqlCommand("usp_tbl_User_Update", con) { CommandType = CommandType.StoredProcedure }; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@pUserId", SqlDbType.Int).Value = pEntity.UserId; //cmd.Parameters.Add("@pRoleId", SqlDbType.Int).Value = pEntity.RoleId; cmd.Parameters.Add("@pUserName", SqlDbType.VarChar).Value = pEntity.UserName; cmd.Parameters.Add("@pUserLastName", SqlDbType.VarChar).Value = pEntity.UserLastName; cmd.Parameters.Add("@pUserFirstName", SqlDbType.VarChar).Value = pEntity.UserFirstName; cmd.Parameters.Add("@pUserMail", SqlDbType.VarChar).Value = pEntity.UserMail; //cmd.Parameters.Add("@pCompanyId", SqlDbType.Int).Value = pEntity.CompanyId; cmd.Parameters.Add("@pUpdateUserId", SqlDbType.Int).Value = pEntity.UpdateUserId; if (con.State != ConnectionState.Open) { con.Open(); } int rowsAffect = await cmd.ExecuteNonQueryAsync(); if (con.State == ConnectionState.Open) { con.Close(); } return(rowsAffect); }
public async Task <int> Insert(UserDataType pEntity) { using SqlConnection con = _connection.DBPLANILLA(); SqlCommand cmd = new SqlCommand("usp_tbl_User_Insert", con) { CommandType = CommandType.StoredProcedure }; //cmd.Parameters.Add("@pRoleId", SqlDbType.Int).Value = pEntity.RoleId; cmd.Parameters.Add("@pUserName", SqlDbType.VarChar).Value = pEntity.UserName; cmd.Parameters.Add("@pUserPassword", SqlDbType.VarChar).Value = pEntity.UserPassword; cmd.Parameters.Add("@pUserLastName", SqlDbType.VarChar).Value = pEntity.UserLastName; cmd.Parameters.Add("@pUserFirstName", SqlDbType.VarChar).Value = pEntity.UserFirstName; cmd.Parameters.Add("@pUserMail", SqlDbType.VarChar).Value = pEntity.UserMail; //cmd.Parameters.Add("@pCompanyId", SqlDbType.Int).Value = pEntity.CompanyId; //cmd.Parameters.Add("@pCreateUserId", SqlDbType.Int).Value = pEntity.CreateUserId; cmd.Parameters.Add("@pCreateUserId", SqlDbType.Int).Value = pEntity.CreateUserId; cmd.Parameters.Add("@pUserId", SqlDbType.Int).Value = 0; cmd.Parameters["@pUserId"].Direction = ParameterDirection.Output; if (con.State != ConnectionState.Open) { con.Open(); } await cmd.ExecuteNonQueryAsync(); int newId = Convert.ToInt32(cmd.Parameters["@pUserId"].Value); if (con.State == ConnectionState.Open) { con.Close(); } return(newId); }
public bool ValidateExists(UserDataType pEntity) { int result = 0; using (SqlConnection con = _connection.DBPLANILLA()) { using (SqlCommand cmd = new SqlCommand("usp_tbl_User_ValidateExists", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@pUserName", SqlDbType.VarChar).Value = pEntity.UserName; bool openConn = (con.State == ConnectionState.Open); if (!openConn) { con.Open(); } using (var dr = cmd.ExecuteReader()) { while (dr.Read()) { result = Convert.ToInt32(dr[0]); } } } if (con.State == ConnectionState.Open) { con.Close(); } } return(result > 0); }
// ---- METHODS ------------------------------------------------------------------------------------------------ void IResData.Load(ResFileLoader loader, UserDataType Type, int count) { switch (Type) { case UserDataType.Int32: _value = loader.ReadInt32s(count); break; case UserDataType.Single: _value = loader.ReadSingles(count); break; case UserDataType.String: _value = loader.LoadStrings(count, Encoding.ASCII); break; case UserDataType.WString: _value = loader.LoadStrings(count, Encoding.Unicode); break; case UserDataType.Byte: _value = loader.ReadBytes(count); break; } }
public UserDataTypes Get(Database database) { UserDataTypes types = new UserDataTypes(database); using (SqlConnection conn = new SqlConnection(connectioString)) { using (SqlCommand command = new SqlCommand("sp_MShelptype null, 'uddt'", conn)) { conn.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { UserDataType type = new UserDataType(database); type.AllowNull = reader["nullable"].ToString().Equals("1"); type.Size = int.Parse(reader["length"].ToString()); type.Name = reader["UserDatatypeName"].ToString(); type.Owner = reader["owner"].ToString(); if (!reader["dt_prec"].ToString().Equals("")) { type.Precision = int.Parse(reader["dt_prec"].ToString()); } if (!reader["dt_scale"].ToString().Equals("")) { type.Scale = int.Parse(reader["dt_scale"].ToString()); } type.Type = reader["basetypename"].ToString(); types.Add(type); } } } } return(types); }
// ---- METHODS ------------------------------------------------------------------------------------------------ void IResData.Load(ResFileLoader loader) { Name = loader.LoadString(); ushort count = loader.ReadUInt16(); Type = loader.ReadEnum <UserDataType>(true); loader.Seek(1); switch (Type) { case UserDataType.Int32: _value = loader.ReadInt32s(count); break; case UserDataType.Single: _value = loader.ReadSingles(count); break; case UserDataType.String: _value = loader.LoadStrings(count, Encoding.ASCII); break; case UserDataType.WString: _value = loader.LoadStrings(count, Encoding.Unicode); break; case UserDataType.Byte: _value = loader.ReadBytes(count); break; } }
/// <summary> /// Get Data from UserDataType /// </summary> /// <param name="userDataType">User Data Type</param> /// <returns>returns data in form of a string</returns> public string GetData(UserDataType userDataType) { if (!CredentialDataDictionary.ContainsKey(userDataType)) { return(string.Empty); } return(CredentialDataDictionary[userDataType]); }
public void Fill(Database database, string connectionString, List <MessageLog> messages) { try { if (database.Options.Ignore.FilterUserDataType) { root.RaiseOnReading(new ProgressEventArgs("Reading UDT...", Constants.READING_UDT)); using (SqlConnection conn = new SqlConnection(connectionString)) { using (SqlCommand command = new SqlCommand(UserDataTypeCommand.Get(database.Info.Version), conn)) { conn.Open(); command.CommandTimeout = 0; using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { UserDataType item = new UserDataType(database); item.Id = (int)reader["tid"]; item.AllowNull = (bool)reader["is_nullable"]; item.Size = (short)reader["max_length"]; item.Name = reader["Name"].ToString(); item.Owner = reader["owner"].ToString(); item.Precision = int.Parse(reader["precision"].ToString()); item.Scale = int.Parse(reader["scale"].ToString()); if (!String.IsNullOrEmpty(reader["defaultname"].ToString())) { item.Default.Name = reader["defaultname"].ToString(); item.Default.Owner = reader["defaultowner"].ToString(); } if (!String.IsNullOrEmpty(reader["rulename"].ToString())) { item.Rule.Name = reader["rulename"].ToString(); item.Rule.Owner = reader["ruleowner"].ToString(); } item.Type = reader["basetypename"].ToString(); item.IsAssembly = (bool)reader["is_assembly_type"]; item.AssemblyId = (int)reader["assembly_id"]; item.AssemblyName = reader["assembly_name"].ToString(); item.AssemblyClass = reader["assembly_class"].ToString(); database.UserTypes.Add(item); } } } } if (database.Options.Ignore.FilterTable) { FillColumnsDependencies(database.Info.Version, database.UserTypes, connectionString); } } } catch (Exception ex) { messages.Add(new MessageLog(ex.Message, ex.StackTrace, MessageLog.LogType.Error)); } }
// ---- METHODS ------------------------------------------------------------------------------------------------ void IResData.Load(BfshaFileLoader loader) { Name = loader.LoadString(); long DataOffset = loader.ReadOffset(); ushort count = loader.ReadUInt16(); Type = loader.ReadEnum <UserDataType>(true); // UserDataData = loader.LoadCustom(() => loader.Load<UserDataData>(Type, count), DataOffset); }
public Protocol(ProtocolProfile config, int sessionId, UserDataType userDataType, byte[] userData) { _UserData = userData; _Version = VERSION; _SessionID = sessionId; _UserDataType = userDataType; _CompressType = config.Compress; _SerializeType = config.SerializerType; _ServiceID = config.ServiceID; _TotalLen = SFPStruct.Version + SFPStruct.TotalLen + SFPStruct.SessionId + SFPStruct.ServerId + SFPStruct.SerializeType + SFPStruct.SDPType + SFPStruct.Platform + SFPStruct.CompressType + userData.Length; }
public Protocol(ProtocolProfile config,int sessionId,UserDataType userDataType, byte[] userData) { _UserData = userData; _Version = VERSION; _SessionID = sessionId; _UserDataType = userDataType; _CompressType = config.Compress; _SerializeType = config.SerializerType; _ServiceID = config.ServiceID; _TotalLen = SFPStruct.Version + SFPStruct.TotalLen + SFPStruct.SessionId + SFPStruct.ServerId + SFPStruct.SerializeType + SFPStruct.SDPType + SFPStruct.Platform + SFPStruct.CompressType + userData.Length; }
/// <summary> /// Edits data of Credential /// </summary> /// <param name="dataType">DataType to be edited</param> /// <param name="data">Data to be edited</param> public void EditCredential(UserDataType dataType, string data) { if (string.IsNullOrEmpty(data)) { throw new ArgumentException("Data can not be NULL!"); } if (!CredentialDataDictionary.ContainsKey(dataType)) { CredentialDataDictionary.Add(dataType, data); return; } CredentialDataDictionary[dataType] = data; }
//====================================================== public void LoadData(BaseUserData userdata, UserDataType type) { string dataname = type + ""; string filepath = GameConst.GetPersistentDataPath(dataname); byte[] gzipdata = GameCommon.ReadByteToFile(filepath); if (gzipdata == null) { } else { byte[] data = GameCommon.UnGZip(gzipdata); DataStream datastream = new DataStream(data, true); userdata.Deserialize(datastream); } }
public void BindAsync_IfUserDataType_ReturnsValidBindingData(string userPropertyName, string userPropertyValue) { // Arrange UserDataType expectedObject = new UserDataType(); PropertyInfo userProperty = typeof(UserDataType).GetProperty(userPropertyName); var parseMethod = userProperty.PropertyType.GetMethod( "Parse", new Type[] { typeof(string) }); object convertedPropertyValue = parseMethod.Invoke(null, new object[] { userPropertyValue }); userProperty.SetValue(expectedObject, convertedPropertyValue); string messageContent = JsonConvert.SerializeObject(expectedObject); // Act ITriggerData data = _binding.BindAsync(messageContent, null).GetAwaiter().GetResult(); // Assert Assert.NotNull(data); Assert.NotNull(data.ValueProvider); Assert.NotNull(data.BindingData); Assert.True(data.BindingData.ContainsKey(userPropertyName)); Assert.AreEqual(userProperty.GetValue(expectedObject, null), data.BindingData[userPropertyName]); }
public static ResDict <UserData> Convert(Dictionary <string, object> userData) { ResDict <UserData> userDataDict = new ResDict <UserData>(); foreach (var param in userData) { UserData usd = new UserData(); string type = param.Key.Split('|')[0]; string name = param.Key.Split('|')[1]; UserDataType dataType = (UserDataType)Enum.Parse(typeof(UserDataType), type); if (dataType == UserDataType.Single) { usd = SetUserData(name, ((JArray)param.Value).ToObject <float[]>()); } if (dataType == UserDataType.Int32) { usd = SetUserData(name, ((JArray)param.Value).ToObject <int[]>()); } if (dataType == UserDataType.Byte) { usd = SetUserData(name, ((JArray)param.Value).ToObject <byte[]>()); } if (dataType == UserDataType.String) { usd = SetUserData(name, ((JArray)param.Value).ToObject <string[]>()); } if (dataType == UserDataType.WString) { usd = SetUserData(name, ((JArray)param.Value).ToObject <string[]>(), true); } userDataDict.Add(usd.Name, usd); } return(userDataDict); }
// ---- METHODS ------------------------------------------------------------------------------------------------ void IResData.Load(ResFileLoader loader) { if (loader.IsSwitch) { Name = loader.LoadString(); uint DataOffset = loader.ReadOffset(); uint count = 0; if (loader.ResFile.VersionMajor2 <= 2 && loader.ResFile.VersionMajor == 0) { char[] Reserved = loader.ReadChars(8); count = loader.ReadUInt32(); Type = (UserDataType)loader.ReadUInt32(); } else { count = loader.ReadUInt32(); Type = loader.ReadEnum <UserDataType>(true); char[] Reserved = loader.ReadChars(43); } switch (Type) { case UserDataType.Byte: _value = loader.LoadCustom(() => loader.ReadSBytes((int)count), DataOffset); break; case UserDataType.Int32: _value = loader.LoadCustom(() => loader.ReadInt32s((int)count), DataOffset); break; case UserDataType.Single: _value = loader.LoadCustom(() => loader.ReadSingles((int)count), DataOffset); break; case UserDataType.String: _value = loader.LoadCustom(() => loader.LoadStrings((int)count, Encoding.UTF8), DataOffset); break; case UserDataType.WString: _value = loader.LoadCustom(() => loader.LoadStrings((int)count, Encoding.Unicode), DataOffset); break; } } else { Name = loader.LoadString(); ushort count = loader.ReadUInt16(); Type = loader.ReadEnum <UserDataType>(true); loader.Seek(1); switch (Type) { case UserDataType.Int32: _value = loader.ReadInt32s(count); break; case UserDataType.Single: _value = loader.ReadSingles(count); break; case UserDataType.String: _value = loader.LoadStrings(count, Encoding.UTF8); break; case UserDataType.WString: _value = loader.LoadStrings(count, Encoding.Unicode); break; case UserDataType.Byte: _value = loader.ReadBytes(count); break; } } }
public static void FromJson(Material mat, string json) { JsonConvert.DefaultSettings = () => { var settings = new JsonSerializerSettings(); return(settings); }; var matJson = JsonConvert.DeserializeObject <MaterialStruct>(json); mat.Name = matJson.Name; mat.Visible = matJson.Visible; mat.ShaderAssign = ConvertShaderAssign(matJson.ShaderAssign); mat.TextureRefs = new List <TextureRef>(); mat.Samplers = new ResDict <Sampler>(); mat.ShaderParams = new ResDict <ShaderParam>(); mat.UserData = new ResDict <UserData>(); mat.RenderInfos = new ResDict <RenderInfo>(); mat.ShaderParamData = new byte[0]; mat.VolatileFlags = new byte[0]; if (matJson.RenderState != null) { mat.RenderState = matJson.RenderState; } foreach (var tex in matJson.Textures) { mat.TextureRefs.Add(new TextureRef() { Name = tex }); } foreach (var sampler in matJson.Samplers) { mat.Samplers.Add(sampler.Name, sampler); } mat.TextureSlotArray = new long[matJson.Textures.Count]; mat.SamplerSlotArray = new long[matJson.Textures.Count]; mat.VolatileFlags = matJson.VolatileFlags; foreach (var param in matJson.Parameters) { string type = param.Key.Split('|')[0]; string name = param.Key.Split('|')[1]; ShaderParam shaderParam = new ShaderParam(); shaderParam.Name = name; var dataType = (ShaderParamType)Enum.Parse(typeof(ShaderParamType), type); object value = null; switch (dataType) { case ShaderParamType.Float: value = Convert.ToSingle(param.Value); break; case ShaderParamType.UInt: value = Convert.ToUInt32(param.Value); break; case ShaderParamType.Int: value = Convert.ToInt32(param.Value); break; case ShaderParamType.Bool: value = Convert.ToBoolean(param.Value); break; case ShaderParamType.Srt2D: value = ((JObject)param.Value).ToObject <Srt2D>(); break; case ShaderParamType.Srt3D: value = ((JObject)param.Value).ToObject <Srt3D>(); break; case ShaderParamType.TexSrt: value = ((JObject)param.Value).ToObject <TexSrt>(); break; case ShaderParamType.TexSrtEx: value = ((JObject)param.Value).ToObject <TexSrt>(); break; case ShaderParamType.Float2: case ShaderParamType.Float2x2: case ShaderParamType.Float2x3: case ShaderParamType.Float2x4: case ShaderParamType.Float3: case ShaderParamType.Float3x2: case ShaderParamType.Float3x3: case ShaderParamType.Float3x4: case ShaderParamType.Float4: case ShaderParamType.Float4x2: case ShaderParamType.Float4x3: case ShaderParamType.Float4x4: value = ((JArray)param.Value).ToObject <float[]>(); break; case ShaderParamType.Bool2: case ShaderParamType.Bool3: case ShaderParamType.Bool4: value = ((JArray)param.Value).ToObject <bool>(); break; case ShaderParamType.Int2: case ShaderParamType.Int3: case ShaderParamType.Int4: value = ((JArray)param.Value).ToObject <int[]>(); break; case ShaderParamType.UInt2: case ShaderParamType.UInt3: case ShaderParamType.UInt4: value = ((JArray)param.Value).ToObject <uint[]>(); break; default: throw new Exception($"Unsupported parameter type! {type}"); } mat.SetShaderParameter(name, dataType, value); } foreach (var param in matJson.RenderInfo) { string type = param.Key.Split('|')[0]; string name = param.Key.Split('|')[1]; RenderInfoType dataType = (RenderInfoType)Enum.Parse(typeof(RenderInfoType), type); if (dataType == RenderInfoType.Single) { mat.SetRenderInfo(name, ((JArray)param.Value).ToObject <float[]>()); } if (dataType == RenderInfoType.Int32) { mat.SetRenderInfo(name, ((JArray)param.Value).ToObject <int[]>()); } if (dataType == RenderInfoType.String) { mat.SetRenderInfo(name, ((JArray)param.Value).ToObject <string[]>()); } } foreach (var param in matJson.UserData) { string type = param.Key.Split('|')[0]; string name = param.Key.Split('|')[1]; UserDataType dataType = (UserDataType)Enum.Parse(typeof(UserDataType), type); if (dataType == UserDataType.Single) { mat.SetUserData(name, ((JArray)param.Value).ToObject <float[]>()); } if (dataType == UserDataType.Int32) { mat.SetUserData(name, ((JArray)param.Value).ToObject <int[]>()); } if (dataType == UserDataType.Byte) { mat.SetUserData(name, ((JArray)param.Value).ToObject <byte[]>()); } if (dataType == UserDataType.String) { mat.SetUserData(name, ((JArray)param.Value).ToObject <string[]>()); } if (dataType == UserDataType.WString) { mat.SetUserData(name, ((JArray)param.Value).ToObject <string[]>(), true); } } }
/// <summary> /// Sets the stored <paramref name="value"/> as a <see cref="Single"/> array and the <see cref="Type"/> to /// <see cref="UserDataType.Single"/> /// </summary> /// <param name="value">The value to store.</param> public void SetValue(float[] value) { Type = UserDataType.Single; _value = value; }
/// <summary> /// Sets the stored <paramref name="value"/> as a <see cref="String"/> array and the <see cref="Type"/> to /// <see cref="UserDataType.String"/> or <see cref="UserDataType.WString"/> depending on /// <paramref name="asUnicode"/>. /// </summary> /// <param name="asUnicode"><c>true</c> to store data as UTF-16 encoded strings, or <c>false</c> to store it /// as ASCII encoded strings.</param> /// <param name="value">The value to store.</param> public void SetValue(string[] value, bool asUnicode = false) { Type = asUnicode ? UserDataType.WString : UserDataType.String; _value = value; }
/// <summary> /// Sets the stored <paramref name="value"/> as an <see cref="Int32"/> array and the <see cref="Type"/> to /// <see cref="UserDataType.Int32"/> /// </summary> /// <param name="value">The value to store.</param> public void SetValue(int[] value) { Type = UserDataType.Int32; _value = value; }
/// <summary> /// Sets the stored <paramref name="value"/> as a <see cref="Byte"/> array and the <see cref="Type"/> to /// <see cref="UserDataType.Byte"/> /// </summary> /// <param name="value">The value to store.</param> public void SetValue(byte[] value) { Type = UserDataType.Byte; _value = value; }