예제 #1
0
        private static List <PropertyMetaData> TypePropertiesCache(Type type)
        {
            List <PropertyMetaData> pis;

            if (PropertyMetaDataDic.TryGetValue(type.TypeHandle, out pis))
            {
                return(pis);
            }
            var properties = type.GetProperties().Where(p => p.CanWrite && p.CanRead).ToArray();

            pis = new List <PropertyMetaData>();
            foreach (var prop in properties)
            {
                PropertyMetaData propertyMetaData = new PropertyMetaData();
                propertyMetaData.EntityType   = type;
                propertyMetaData.PropertyName = prop.Name;
                propertyMetaData.PropertyType = prop.PropertyType;
                propertyMetaData.ColumnName   = prop.Name;
                var attribute = prop.GetCustomAttribute(typeof(PropertyAttribute)) as PropertyAttribute;
                if (attribute != null)
                {
                    propertyMetaData.IsPrimaryKey = attribute.IsPrimarykey;
                    propertyMetaData.IsMust       = attribute.IsMust;
                }
                pis.Add(propertyMetaData);
            }
            PropertyMetaDataDic[type.TypeHandle] = pis;
            return(pis);
        }
        public Expression DeserializerExpression(
            ParameterExpression streamReaderExpression, 
            ParameterExpression serializationContextExpression, 
            Expression assignmentTargetExpression, 
            PropertyMetaData propertyMetaData)
        {
            var deserializerMethodInfo =
                ReflectionHelper
                    .GetMethodInfo
                    <PlayfieldVendorInfoSerializer, Func<StreamReader, SerializationContext, PropertyMetaData, object>>(
                        o => o.Deserialize);
            var serializerExp = Expression.New(this.GetType());
            var callExp = Expression.Call(
                serializerExp, 
                deserializerMethodInfo, 
                new Expression[]
                    {
                        streamReaderExpression, serializationContextExpression, 
                        Expression.Constant(propertyMetaData, typeof(PropertyMetaData))
                    });

            var assignmentExp = Expression.Assign(
                assignmentTargetExpression, Expression.TypeAs(callExp, assignmentTargetExpression.Type));
            return assignmentExp;
        }
예제 #3
0
 public object Deserialize(
     StreamReader streamReader,
     SerializationContext serializationContext,
     PropertyMetaData propertyMetaData = null)
 {
     return(streamReader.ReadUInt16());
 }
예제 #4
0
        private static List <SelectListItem> GetSelectedListItems(
            PropertyMetaData property, System.Collections.IEnumerable source)
        {
            var          result = new List <SelectListItem>();
            var          relatedPropertyType = property.ForeignType();
            var          foreignMetaData     = MetaDataProvider.Get(relatedPropertyType);
            var          first        = true;
            PropertyInfo propertyInfo = null;

            foreach (var o in source)
            {
                object id;
                if (first)
                {
                    propertyInfo = o.GetType().GetProperty(property.Info.Name);
                    first        = false;
                }
                if (propertyInfo != null)
                {
                    id = o.GetValue(property.Info.Name);
                }
                else
                {
                    id = o.GetValue(LinqToSqlUtils.GetPKPropertyName(
                                        foreignMetaData.EntityType));
                }
                result.Add(new SelectListItem
                {
                    Text  = GetDisplay(o, foreignMetaData).ToString(),
                    Value = id.ToString()
                });
            }

            return(result.OrderBy(sli => sli.Text).ToList());
        }
예제 #5
0
        public void Serialize(StreamWriter streamWriter, SerializationContext serializationContext, object value,
                              PropertyMetaData propertyMetaData = null)
        {
            var genericCmd = (GenericCmdMessage)value;

            streamWriter.WriteInt32((int)genericCmd.N3MessageType);
            streamWriter.WriteInt32((int)genericCmd.Identity.Type);
            streamWriter.WriteInt32(genericCmd.Identity.Instance);
            streamWriter.WriteByte(genericCmd.Unknown);
            streamWriter.WriteInt32(genericCmd.Temp1);
            streamWriter.WriteInt32(genericCmd.Count);
            streamWriter.WriteInt32((int)genericCmd.Action);
            streamWriter.WriteInt32(genericCmd.Temp4);
            streamWriter.WriteInt32((int)genericCmd.User.Type);
            streamWriter.WriteInt32(genericCmd.User.Instance);

            if (genericCmd.Action == GenericCmdAction.UseItemOnItem)
            {
                streamWriter.WriteInt32((int)genericCmd.Source.Type);
                streamWriter.WriteInt32(genericCmd.Source.Instance);
            }

            streamWriter.WriteInt32((int)genericCmd.Target.Type);
            streamWriter.WriteInt32(genericCmd.Target.Instance);
        }
 public object Deserialize(
     StreamReader streamReader, 
     SerializationContext serializationContext, 
     PropertyMetaData propertyMetaData = null)
 {
     return this.serializer.Deserialize(streamReader, serializationContext, propertyMetaData);
 }
        /// <summary>
        /// Try to get the type of a property from the information
        /// returned by the cloud service. This should be overridden
        /// if anything other than simple types are required.
        /// </summary>
        /// <param name="propertyMetaData">
        /// The <see cref="PropertyMetaData"/> instance to translate.
        /// </param>
        /// <param name="parentObjectType">
        /// The type of the object on which this property exists.
        /// </param>
        /// <returns>
        /// The type of the property determined from the Type field
        /// of propertyMetaData.
        /// </returns>
        protected virtual Type GetPropertyType(
            PropertyMetaData propertyMetaData,
            Type parentObjectType)
        {
            if (propertyMetaData == null)
            {
                throw new ArgumentNullException(nameof(propertyMetaData));
            }
            switch (propertyMetaData.Type)
            {
            case "String":
                return(typeof(string));

            case "Int32":
                return(typeof(int));

            case "Boolean":
                return(typeof(bool));

            case "JavaScript":
                return(typeof(JavaScript));

            case "Double":
                return(typeof(double));

            case "Array":
            default:
                throw new PipelineException(string.Format(
                                                CultureInfo.InvariantCulture,
                                                Messages.ExceptionCloudPropertyType,
                                                parentObjectType,
                                                propertyMetaData.Name,
                                                propertyMetaData.Type));
            }
        }
        public object Deserialize(
            StreamReader streamReader,
            SerializationContext serializationContext,
            PropertyMetaData propertyMetaData = null)
        {
            var mess = new GenericCmdMessage();
            mess.N3MessageType = (N3MessageType)streamReader.ReadInt32();
            mess.Identity = streamReader.ReadIdentity();
            mess.Unknown = streamReader.ReadByte();
            mess.Temp1 = streamReader.ReadInt32();
            mess.Count = streamReader.ReadInt32();
            mess.Action = (GenericCmdAction)streamReader.ReadInt32();
            mess.Temp4 = streamReader.ReadInt32();
            mess.User = streamReader.ReadIdentity();
            int len = 1;
            if (mess.Action == GenericCmdAction.UseItemOnItem)
            {
                len = 2;
            }

            mess.Target = new Identity[len];
            for (int i = 0; i < mess.Target.Length; i++)
            {
                mess.Target[i] = streamReader.ReadIdentity();
            }
            return mess;
        }
        public Expression DeserializerExpression(
            ParameterExpression streamReaderExpression,
            ParameterExpression serializationContextExpression,
            Expression assignmentTargetExpression,
            PropertyMetaData propertyMetaData)
        {
            var deserializerMethodInfo =
                ReflectionHelper
                .GetMethodInfo
                <SimpleCharFullUpdateSerializer, Func <StreamReader, SerializationContext, PropertyMetaData, object> >
                    (o => o.Deserialize);
            var serializerExp = Expression.New(this.GetType());
            var callExp       = Expression.Call(
                serializerExp,
                deserializerMethodInfo,
                new Expression[]
            {
                streamReaderExpression, serializationContextExpression,
                Expression.Constant(propertyMetaData, typeof(PropertyMetaData))
            });

            var assignmentExp = Expression.Assign(
                assignmentTargetExpression, Expression.TypeAs(callExp, assignmentTargetExpression.Type));

            return(assignmentExp);
        }
        public object Deserialize(
            StreamReader streamReader, 
            SerializationContext serializationContext, 
            PropertyMetaData propertyMetaData = null)
        {
            var identityType = (IdentityType)streamReader.ReadInt32();
            if (identityType != IdentityType.VendingMachine)
            {
                streamReader.Position = streamReader.Position - 4;
                return null;
            }

            var playfieldVendorInfo = new PlayfieldVendorInfo
                                          {
                                              Unknown1 =
                                                  new Identity
                                                      {
                                                          Type = identityType, 
                                                          Instance = streamReader.ReadInt32()
                                                      }, 
                                              Unknown2 = streamReader.ReadInt32(), 
                                              VendorCount = streamReader.ReadInt32(), 
                                              FirstVendorId = streamReader.ReadInt32()
                                          };
            return playfieldVendorInfo;
        }
 public object Deserialize(
     StreamReader streamReader,
     SerializationContext serializationContext,
     PropertyMetaData propertyMetaData = null)
 {
     return(new SimpleCharFullUpdateMessage());
 }
예제 #12
0
 public object Deserialize(
     StreamReader streamReader,
     SerializationContext serializationContext,
     PropertyMetaData propertyMetaData = null)
 {
     return(this.DeserializerLambda(streamReader, serializationContext));
 }
        public object Deserialize(
            StreamReader streamReader,
            SerializationContext serializationContext,
            PropertyMetaData propertyMetaData = null)
        {
            switch (this.arraySizeType)
            {
            case ArraySizeType.NoSerialization:
                return(null);

            case ArraySizeType.Byte:
                return((int)streamReader.ReadByte());

            case ArraySizeType.Int16:
                return((int)streamReader.ReadInt16());

            case ArraySizeType.Int32:
                return(streamReader.ReadInt32());

            case ArraySizeType.X3F1:
                var length3F1 = streamReader.ReadInt32();
                return((length3F1 / 0x03F1) - 1);

            case ArraySizeType.NullTerminated:
                return(null);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
 public object Deserialize(
     StreamReader streamReader, 
     SerializationContext serializationContext, 
     PropertyMetaData propertyMetaData = null)
 {
     return streamReader.ReadInt16();
 }
        public object Deserialize(
            StreamReader streamReader,
            SerializationContext serializationContext,
            PropertyMetaData propertyMetaData = null)
        {
            var mess = new GenericCmdMessage();

            mess.N3MessageType = (N3MessageType)streamReader.ReadInt32();
            mess.Identity      = streamReader.ReadIdentity();
            mess.Unknown       = streamReader.ReadByte();
            mess.Temp1         = streamReader.ReadInt32();
            mess.Count         = streamReader.ReadInt32();
            mess.Action        = (GenericCmdAction)streamReader.ReadInt32();
            mess.Temp4         = streamReader.ReadInt32();
            mess.User          = streamReader.ReadIdentity();
            int len = 1;

            if (mess.Action == GenericCmdAction.UseItemOnItem)
            {
                len = 2;
            }

            mess.Target = new Identity[len];
            for (int i = 0; i < mess.Target.Length; i++)
            {
                mess.Target[i] = streamReader.ReadIdentity();
            }
            return(mess);
        }
예제 #16
0
        public virtual IQueryable GetComboBoxSource(
            PropertyMetaData propertyMetaData, bool onlyActive, string filter)
        {
            var relatedMeta = MetaDataProvider.Get(
                propertyMetaData.ForeignType());
            var idProperty = LinqToSqlUtils.GetPKPropertyName(relatedMeta.EntityType);
            var selector   = "new(" + idProperty +
                             " as " + propertyMetaData.Info.Name +
                             ", " + relatedMeta.DisplayProperty().Name + ")";

            var result =
                DynamicRepository.GetAll(propertyMetaData.ForeignType());

            if (filter != null)
            {
                result = result.Where(filter);
            }

            /*       if(onlyActive)
             *         foreach (var property in Const.Common.ActiveProperties)
             *         {
             *             if(propertyMetaData.ForeignType.HasProperty(property))
             *                 result = result.Where(property);
             *         }*/

            return(result.Select(selector));
        }
        public Expression DeserializerExpression(
            ParameterExpression streamReaderExpression,
            ParameterExpression serializationContextExpression,
            Expression assignmentTargetExpression,
            PropertyMetaData propertyMetaData)
        {
            if (this.arraySizeType == ArraySizeType.NoSerialization)
            {
                return(null);
            }

            MethodInfo readMethodInfo = null;

            if (this.type == typeof(byte))
            {
                readMethodInfo = ReflectionHelper.GetMethodInfo <StreamReader, Func <byte> >(o => o.ReadByte);
            }

            if (this.type == typeof(short))
            {
                readMethodInfo = ReflectionHelper.GetMethodInfo <StreamReader, Func <short> >(o => o.ReadInt16);
            }

            if (this.type == typeof(int))
            {
                readMethodInfo = ReflectionHelper.GetMethodInfo <StreamReader, Func <int> >(o => o.ReadInt32);
            }

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

            Expression deserializedValueExpression;

            if (propertyMetaData.Options.IsFixedSize)
            {
                deserializedValueExpression = Expression.Constant(propertyMetaData.Options.FixedSizeLength, this.type);
            }
            else
            {
                deserializedValueExpression = Expression.Call(streamReaderExpression, readMethodInfo);
            }

            if (this.arraySizeType == ArraySizeType.X3F1)
            {
                var originalValue = deserializedValueExpression;
                deserializedValueExpression =
                    Expression.Subtract(
                        Expression.Divide(originalValue, Expression.Constant(0x03F1)), Expression.Constant(1));
            }

            var deserializerExpression = Expression.Assign(
                assignmentTargetExpression,
                this.type == assignmentTargetExpression.Type
                    ? deserializedValueExpression
                    : Expression.Convert(deserializedValueExpression, assignmentTargetExpression.Type));

            return(deserializerExpression);
        }
예제 #18
0
        public object Deserialize(
            StreamReader streamReader,
            SerializationContext serializationContext,
            PropertyMetaData propertyMetaData = null)
        {
            object obj = null;
            long   streamReaderPosition = streamReader.Position;

            try
            {
                obj = this.DeserializerLambda(streamReader, serializationContext);
            }
            catch (Exception e)
            {
                Probe pb = serializationContext.BeginProbe();
                try
                {
                    streamReader.Position = streamReaderPosition;
                    obj = this.DeserializerLambda(streamReader, serializationContext);
                }
                catch (Exception)
                {
                }
                serializationContext.EndProbe(pb);
                throw new Exception("TypeSerializer failed (" + this.Type.ToString() + ")." + Environment.NewLine + e.Message + string.Join(Environment.NewLine, pb.DiagnosticInfo) + Environment.NewLine, e);
            }
            return(obj);
        }
 public object Deserialize(
     StreamReader streamReader, 
     SerializationContext serializationContext, 
     PropertyMetaData propertyMetaData = null)
 {
     var address = new IPAddress(streamReader.ReadBytes(4));
     return address;
 }
예제 #20
0
        private static List <SelectListItem> GetSelectedListItems(
            PropertyMetaData property, System.Collections.IEnumerable source, object value)
        {
            var result = GetSelectedListItems(property, source);

            SetSelected(result, new [] { value });
            return(result.OrderBy(sli => sli.Text).ToList());
        }
예제 #21
0
 public Expression DeserializerExpression(
     ParameterExpression streamReaderExpression,
     ParameterExpression serializationContextExpression,
     Expression assignmentTargetExpression,
     PropertyMetaData propertyMetaData)
 {
     throw new NotImplementedException();
 }
예제 #22
0
 public void Serialize(
     StreamWriter streamWriter,
     SerializationContext serializationContext,
     object value,
     PropertyMetaData propertyMetaData = null)
 {
     streamWriter.WriteInt16((short)value);
 }
 public void Serialize(
     StreamWriter streamWriter, 
     SerializationContext serializationContext, 
     object value, 
     PropertyMetaData propertyMetaData = null)
 {
     streamWriter.WriteSByte((SByte)value);
 }
 public void Serialize(
     StreamWriter streamWriter,
     SerializationContext serializationContext,
     object value,
     PropertyMetaData propertyMetaData = null)
 {
     streamWriter.WriteSByte((SByte)value);
 }
예제 #25
0
 public Expression SerializerExpression(
     ParameterExpression streamWriterExpression,
     ParameterExpression serializationContextExpression,
     Expression valueExpression,
     PropertyMetaData propertyMetaData)
 {
     throw new NotImplementedException();
 }
 public void Serialize(
     StreamWriter streamWriter, 
     SerializationContext serializationContext, 
     object value, 
     PropertyMetaData propertyMetaData = null)
 {
     streamWriter.WriteInt16((short)value);
 }
예제 #27
0
 public void Serialize(
     StreamWriter streamWriter,
     SerializationContext serializationContext,
     object value,
     PropertyMetaData propertyMetaData = null)
 {
     this.SerializerLambda(streamWriter, serializationContext, value);
 }
 public Expression DeserializerExpression(
     ParameterExpression streamReaderExpression, 
     ParameterExpression serializationContextExpression, 
     Expression assignmentTargetExpression, 
     PropertyMetaData propertyMetaData)
 {
     throw new NotImplementedException();
 }
예제 #29
0
 protected override Type GetPropertyType(PropertyMetaData propertyMetaData, Type parentObjectType)
 {
     if (_complexPropertyTypes.ContainsKey(propertyMetaData.Name))
     {
         return(_complexPropertyTypes[propertyMetaData.Name]);
     }
     return(base.GetPropertyType(propertyMetaData, parentObjectType));
 }
예제 #30
0
        public static List <SelectListItem> GetSelectedListItems(
            PropertyMetaData property, System.Collections.IEnumerable source,
            List <object> values)
        {
            var result = GetSelectedListItems(property, source);

            SetSelected(result, values);
            return(result.OrderBy(sli => sli.Text).ToList());
        }
        private Probe BeginProbeDeserialize(
            StreamReader streamReader, SerializationContext serializationContext, PropertyMetaData propertyMetaData)
        {
            var probe = serializationContext.BeginProbe();

            probe.DiagnosticInfo.Offset           = streamReader.Position;
            probe.DiagnosticInfo.PropertyMetaData = propertyMetaData;
            return(probe);
        }
        public Expression SerializerExpression(
            ParameterExpression streamWriterExpression,
            ParameterExpression serializationContextExpression,
            Expression valueExpression,
            PropertyMetaData propertyMetaData)
        {
            if ((this.arraySizeType == ArraySizeType.NoSerialization) || (this.arraySizeType == ArraySizeType.NullTerminated))
            {
                return(null);
            }

            MethodInfo writeMethodInfo = null;

            if (this.type == typeof(byte))
            {
                writeMethodInfo = ReflectionHelper.GetMethodInfo <StreamWriter, Action <byte> >(o => o.WriteByte);
            }

            if (this.type == typeof(short))
            {
                writeMethodInfo = ReflectionHelper.GetMethodInfo <StreamWriter, Action <short> >(o => o.WriteInt16);
            }

            if (this.type == typeof(int))
            {
                writeMethodInfo = ReflectionHelper.GetMethodInfo <StreamWriter, Action <int> >(o => o.WriteInt32);
            }

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

            Expression serializedValueExpression;

            if (propertyMetaData.Options.IsFixedSize)
            {
                serializedValueExpression = Expression.Constant(propertyMetaData.Options.FixedSizeLength, this.type);
            }
            else
            {
                serializedValueExpression = Expression.Convert(
                    Expression.Property(valueExpression, "Length"), this.type);
            }

            if (this.arraySizeType == ArraySizeType.X3F1)
            {
                var originalValue = serializedValueExpression;
                serializedValueExpression = Expression.Multiply(
                    Expression.Add(originalValue, Expression.Constant(1)), Expression.Constant(0x03F1));
            }

            var serializerExpression = Expression.Call(
                streamWriterExpression, writeMethodInfo, new[] { serializedValueExpression });

            return(serializerExpression);
        }
        public object Deserialize(
            StreamReader streamReader,
            SerializationContext serializationContext,
            PropertyMetaData propertyMetaData = null)
        {
            var address = new IPAddress(streamReader.ReadBytes(4));

            return(address);
        }
예제 #34
0
        public static List <SelectListItem> GetSourceForFilter(
            PropertyMetaData property, System.Collections.IEnumerable source, Type entityType,
            object filterValue)
        {
            var result = GetSelectedListItems(property, source, filterValue);

            result.Insert(0, _emtpySelectItem);
            return(result);
        }
        /// <summary>
        /// Translate the specified property from <see cref="PropertyMetaData"/>
        /// to <see cref="AspectPropertyMetaData"/>.
        /// </summary>
        /// <param name="property">
        /// The <see cref="PropertyMetaData"/> instance to translate.
        /// </param>
        /// <param name="parentObjectType">
        /// The type of the object on which this property exists.
        /// </param>
        /// <returns>
        /// A new <see cref="AspectPropertyMetaData"/> instance, created from
        /// the values in the supplied <see cref="PropertyMetaData"/>.
        /// </returns>
        private AspectPropertyMetaData LoadProperty(PropertyMetaData property, Type parentObjectType = null)
        {
            // If parent object type is not set then use the type of the
            // data returned by this engine.
            if (parentObjectType == null)
            {
                parentObjectType = typeof(T);
            }
            // Get the property info for this property based on the
            // supplied name.
            var propertyType = GetPropertyType(property, parentObjectType);


            // Load any sub properties.
            List <AspectPropertyMetaData> subProperties = null;

            if (property.ItemProperties != null &&
                property.ItemProperties.Count > 0)
            {
                subProperties = new List <AspectPropertyMetaData>();
                if (typeof(IEnumerable).IsAssignableFrom(propertyType) &&
                    propertyType.IsGenericType)
                {
                    // Get the type of the items in this list so
                    // LoadProperty can use reflection to get its
                    // properties.
                    var itemType = propertyType.GetGenericArguments()[0];
                    foreach (var subproperty in property.ItemProperties)
                    {
                        var newProperty = LoadProperty(subproperty, itemType);
                        if (newProperty != null)
                        {
                            subProperties.Add(newProperty);
                        }
                    }
                }
                else
                {
                    Logger.LogWarning($"Problem parsing sub-items. " +
                                      $"Property '{parentObjectType.Name}.{property.Name}' " +
                                      $"does not implement IEnumerable<>.");
                }
            }

            // Create the AspectPropertyMetaData instance.
            return(new AspectPropertyMetaData(this,
                                              property.Name,
                                              propertyType,
                                              property.Category,
                                              new List <string>(),
                                              true,
                                              "",
                                              subProperties,
                                              property.DelayExecution,
                                              property.EvidenceProperties));
        }
 private void EndProbeSerialize(
     StreamWriter streamWriter,
     SerializationContext serializationContext,
     object value,
     PropertyMetaData propertyMetaData,
     Probe probe)
 {
     probe.DiagnosticInfo.Length = streamWriter.Position - probe.DiagnosticInfo.Offset;
     serializationContext.EndProbe(probe);
 }
        public void Serialize(
            StreamWriter streamWriter,
            SerializationContext serializationContext,
            object value,
            PropertyMetaData propertyMetaData = null)
        {
            var address = (IPAddress)value;

            streamWriter.WriteBytes(address.GetAddressBytes());
        }
예제 #38
0
        public object Deserialize(
            StreamReader streamReader,
            SerializationContext serializationContext,
            PropertyMetaData propertyMetaData = null)
        {
            var header = new ChatHeader();

            header.PacketType = (ChatMessageType)streamReader.ReadInt16();
            header.Size       = streamReader.ReadInt16();
            return(header);
        }
예제 #39
0
        public void Serialize(
            StreamWriter streamWriter,
            SerializationContext serializationContext,
            object value,
            PropertyMetaData propertyMetaData = null)
        {
            var header = (ChatHeader)value;

            streamWriter.WriteInt16((short)header.PacketType);
            streamWriter.WriteInt16(header.Size);
        }
예제 #40
0
        //Upsert de Identity Parametre İçin Eklendi.
        public static SqlQueryParameter EnsureHasParameter(SqlQuery query, PropertyMetaData property, object entity)//inset de bu parametre normalde eklenmez ama upsert de update where de eklendiği için bu yapı kullanılıyor.
        {

            SqlQueryParameter identityParameter = query.Parameters.Find(property.ParameterName);
            if (null == identityParameter)
            {
                object parValue = property.Property.GetValue(entity, null);
                identityParameter = SqlQueryParameter.Create(property, parValue);

                query.Parameters.Add(identityParameter);
            }
            return identityParameter;
        }
 public object Deserialize(
     StreamReader streamReader, 
     SerializationContext serializationContext, 
     PropertyMetaData propertyMetaData = null)
 {
     var header = new Header();
     header.MessageId = streamReader.ReadUInt16();
     header.PacketType = (PacketType)streamReader.ReadInt16();
     header.Unknown = streamReader.ReadInt16();
     header.Size = streamReader.ReadInt16();
     header.Sender = streamReader.ReadInt32();
     header.Receiver = streamReader.ReadInt32();
     return header;
 }
예제 #42
0
        public virtual void SetColumnValue(IEntityMetaData metaData, int index, SqlQuery query, PropertyMetaData pm, object entity)//Parametewnin eklenip eklenmeyeceği bilinmdeğinden prefix ve entity verilmek zorunda.
        {
            SchemaInfo schema = pm.Schema;
            PropertyInfo pi = pm.Property;
            object parValue = pm.Property.GetValue(entity, null);

            StringBuilder text = query.Text;
            if (schema.DefaultValue.Length != 0)
            {
                object defaultValue = ReflectionExtensions.GetDefault(pi.PropertyType);
                if (Object.Equals(defaultValue, parValue))//Eğer Property Değeri Default Haldeyse yazdır Bunu
                {
                    text.Append(schema.DefaultValue);
                    return;
                }
            }

            switch (schema.SqlValueType)
            {
                case SqlValueType.Parameterized:
                    text.Append(this.Prefix);

                    string parameterName = metaData.GetParameterName(pm, index);
                    text.Append(parameterName);

                    SqlQueryParameter par = SqlQueryParameter.Create(parameterName, pm, parValue);

                    query.Parameters.Add(par);
                    break;
                case SqlValueType.Text:
                    string textValue = null;
                    if (null != parValue)
                    {
                        Type dataType = pm.Schema.DataType;//Neden Schema.DataType çünkü pi.PropertyType nullable olabalir.
                        if (WithQuotes.Contains(dataType))
                        {
                            textValue = "'" + parValue + "'";
                        }
                        else
                        {
                            IFormattable f = parValue as IFormattable;
                            textValue = null != f ? f.ToString(null, NumericCulture) : parValue.ToString();
                        }
                    }
                    text.Append(textValue);
                    break;
                default:
                    throw new NotSupportedException(schema.SqlValueType.ToString());
            }
        }
        public object Deserialize(
            StreamReader streamReader,
            SerializationContext serializationContext,
            PropertyMetaData propertyMetaData = null)
        {
            int arrayLength;
            var array = Array.CreateInstance(this.typeSerializer.Type, 0);
            if (propertyMetaData.Options.SerializeSize == ArraySizeType.NullTerminated)
            {
                List<object> temp = new List<object>();
                int check = 0;
                do
                {
                    check = streamReader.ReadInt32();
                    if (check != 0)
                    {
                        streamReader.Position -= 4;
                        var element = this.typeSerializer.Deserialize(
                            streamReader,
                            serializationContext,
                            propertyMetaData);
                        temp.Add(element);
                    }
                }
                while (check != 0);
            }
            else
            {
                if (propertyMetaData.Options.SerializeSize != ArraySizeType.NoSerialization)
                {
                    var arraySizeSerializer = new ArraySizeSerializer(propertyMetaData.Options.SerializeSize);
                    arrayLength = (int)arraySizeSerializer.Deserialize(streamReader, serializationContext, propertyMetaData);
                }
                else
                {
                    arrayLength = propertyMetaData.Options.FixedSizeLength;
                }

                array = Array.CreateInstance(this.typeSerializer.Type, arrayLength);
                for (var i = 0; i < arrayLength; i++)
                {
                    var element = this.typeSerializer.Deserialize(streamReader, serializationContext, propertyMetaData);
                    array.SetValue(element, i);
                }
            }

            return array;
        }
        public Expression DeserializerExpression(
            ParameterExpression streamReaderExpression, 
            ParameterExpression serializationContextExpression, 
            Expression assignmentTargetExpression, 
            PropertyMetaData propertyMetaData)
        {
            var beginMethodInfo =
                ReflectionHelper
                    .GetMethodInfo
                    <DiagnosticSerializer, Func<StreamReader, SerializationContext, PropertyMetaData, Probe>>(
                        o => o.BeginProbeDeserialize);
            var callBeginExpression = Expression.Call(
                Expression.Constant(this), 
                beginMethodInfo, 
                new Expression[]
                    {
                       streamReaderExpression, serializationContextExpression, Expression.Constant(propertyMetaData) 
                    });

            var probeExpression = Expression.Variable(typeof(Probe));
            var assignProbeExpression = Expression.Assign(probeExpression, callBeginExpression);

            var deserializerExpression = this.serializer.DeserializerExpression(
                streamReaderExpression, serializationContextExpression, assignmentTargetExpression, propertyMetaData);

            var endMethodInfo =
                ReflectionHelper
                    .GetMethodInfo
                    <DiagnosticSerializer, Action<StreamReader, SerializationContext, PropertyMetaData, object, Probe>>(
                        o => o.EndProbeDeserialize);
            var callEndExpression = Expression.Call(
                Expression.Constant(this), 
                endMethodInfo, 
                new Expression[]
                    {
                        streamReaderExpression, serializationContextExpression, Expression.Constant(propertyMetaData), 
                        Expression.Convert(assignmentTargetExpression, typeof(object)), probeExpression
                    });

            var tryFinallyExpression =
                Expression.TryFinally(
                    Expression.Block(assignProbeExpression, deserializerExpression), callEndExpression);

            var block = Expression.Block(new[] { probeExpression }, new[] { tryFinallyExpression });

            return block;
        }
        public Expression DeserializerExpression(
            ParameterExpression streamReaderExpression, 
            ParameterExpression serializationContextExpression, 
            Expression assignmentTargetExpression, 
            PropertyMetaData propertyMetaData)
        {
            var readMethodInfo = ReflectionHelper.GetMethodInfo<StreamReader, Func<short>>(o => o.ReadInt16);
            var callReadExp = Expression.Call(streamReaderExpression, readMethodInfo);
            if (assignmentTargetExpression.Type.IsAssignableFrom(this.type))
            {
                return Expression.Assign(assignmentTargetExpression, callReadExp);
            }

            var assignmentExp = Expression.Assign(
                assignmentTargetExpression, Expression.Convert(callReadExp, assignmentTargetExpression.Type));
            return assignmentExp;
        }
        public Expression SerializerExpression(
            ParameterExpression streamWriterExpression, 
            ParameterExpression serializationContextExpression, 
            Expression valueExpression, 
            PropertyMetaData propertyMetaData)
        {
            var writeMethodInfo = ReflectionHelper.GetMethodInfo<StreamWriter, Action<SByte>>(o => o.WriteSByte);
            if (valueExpression.Type.IsAssignableFrom(this.type))
            {
                return Expression.Call(streamWriterExpression, writeMethodInfo, new[] { valueExpression });
            }

            var callWriteExp = Expression.Call(
                streamWriterExpression, 
                writeMethodInfo, 
                new Expression[] { Expression.Convert(valueExpression, this.type) });
            return callWriteExp;
        }
        public Expression DeserializerExpression(
            ParameterExpression streamReaderExpression, 
            ParameterExpression serializationContextExpression, 
            Expression assignmentTargetExpression, 
            PropertyMetaData propertyMetaData)
        {
            var expressions = new List<Expression>();

            var lengthExpression = Expression.Variable(typeof(int), "length");

            Expression assignLengthExpression;

            if (propertyMetaData.Options.SerializeSize == ArraySizeType.NoSerialization)
            {
                assignLengthExpression = Expression.Assign(
                    lengthExpression, Expression.Constant(propertyMetaData.Options.FixedSizeLength, typeof(int)));
            }
            else
            {
                assignLengthExpression =
                    new ArraySizeSerializer(propertyMetaData.Options.SerializeSize).DeserializerExpression(
                        streamReaderExpression, serializationContextExpression, lengthExpression, propertyMetaData);
            }

            expressions.Add(assignLengthExpression);

            var readMethodInfo = ReflectionHelper.GetMethodInfo<StreamReader, Func<int, string>>(o => o.ReadString);
            var callReadExp = Expression.Call(
                streamReaderExpression, readMethodInfo, new Expression[] { lengthExpression });

            Expression setString = assignmentTargetExpression.Type.IsAssignableFrom(this.type)
                                       ? Expression.Assign(assignmentTargetExpression, callReadExp)
                                       : Expression.Assign(
                                           assignmentTargetExpression, 
                                           Expression.Convert(callReadExp, assignmentTargetExpression.Type));

            expressions.Add(setString);

            var block = Expression.Block(new[] { lengthExpression }, expressions);
            return block;
        }
        public object Deserialize(
            StreamReader streamReader,
            SerializationContext serializationContext,
            PropertyMetaData propertyMetaData = null)
        {
            byte infoType = streamReader.ReadByte();
            if (infoType == 1)
            {
                var followCoordinateInfo = new FollowCoordinateInfo();
                followCoordinateInfo.FollowInfoType = 1;
                followCoordinateInfo.MoveMode = streamReader.ReadByte();
                followCoordinateInfo.CoordinateCount = streamReader.ReadByte();
                followCoordinateInfo.CurrentCoordinates=new Vector3();
                followCoordinateInfo.CurrentCoordinates.X = streamReader.ReadSingle();
                followCoordinateInfo.CurrentCoordinates.Y = streamReader.ReadSingle();
                followCoordinateInfo.CurrentCoordinates.Z = streamReader.ReadSingle();
                followCoordinateInfo.EndCoordinates=new Vector3();
                followCoordinateInfo.EndCoordinates.X = streamReader.ReadSingle();
                followCoordinateInfo.EndCoordinates.Y = streamReader.ReadSingle();
                followCoordinateInfo.EndCoordinates.Z = streamReader.ReadSingle();
                return followCoordinateInfo;
            }
            if (infoType == 2)
            {
                var followTargetInfo = new FollowTargetInfo();
                followTargetInfo.FollowInfoType = 2;
                followTargetInfo.MoveType = streamReader.ReadByte();
                IdentityType itype = (IdentityType)streamReader.ReadInt32();

                followTargetInfo.Target = new Identity() { Type = itype, Instance = streamReader.ReadInt32() };
                followTargetInfo.Dummy = streamReader.ReadByte();
                followTargetInfo.Dummy1 = streamReader.ReadInt32();
                followTargetInfo.X = streamReader.ReadInt32();
                followTargetInfo.Y = streamReader.ReadInt32();
                followTargetInfo.Z = streamReader.ReadInt32();
                return followTargetInfo;
            }

            streamReader.Position = streamReader.Position - 1;
            return null;
        }
        public object Deserialize(
            StreamReader streamReader, 
            SerializationContext serializationContext, 
            PropertyMetaData propertyMetaData = null)
        {
            int length;
            if (propertyMetaData.Options.SerializeSize == ArraySizeType.NoSerialization)
            {
                length = propertyMetaData.Options.FixedSizeLength;
            }
            else
            {
                var arraySizeSerializer = new ArraySizeSerializer(propertyMetaData.Options.SerializeSize);
                length =
                    (int)
                    arraySizeSerializer.Deserialize(
                        streamReader, serializationContext, propertyMetaData: propertyMetaData);
            }

            return streamReader.ReadString(length);
        }
        public Expression DeserializerExpression(
            ParameterExpression streamReaderExpression, 
            ParameterExpression serializationContextExpression, 
            Expression assignmentTargetExpression, 
            PropertyMetaData propertyMetaData)
        {
            var readMethodInfo = ReflectionHelper.GetMethodInfo<StreamReader, Func<int, byte[]>>(o => o.ReadBytes);
            var callReadExp = Expression.Call(
                streamReaderExpression, readMethodInfo, new Expression[] { Expression.Constant(4) });

            var createInstance = Expression.New(this.constructor, new Expression[] { callReadExp });

            if (assignmentTargetExpression.Type.IsAssignableFrom(this.type))
            {
                return Expression.Assign(assignmentTargetExpression, createInstance);
            }

            var assignmentExp = Expression.Assign(
                assignmentTargetExpression, Expression.Convert(createInstance, assignmentTargetExpression.Type));
            return assignmentExp;
        }
 public object Deserialize(
     StreamReader streamReader, 
     SerializationContext serializationContext, 
     PropertyMetaData propertyMetaData = null)
 {
     switch (this.arraySizeType)
     {
         case ArraySizeType.NoSerialization:
             return null;
         case ArraySizeType.Byte:
             return (int)streamReader.ReadByte();
         case ArraySizeType.Int16:
             return (int)streamReader.ReadInt16();
         case ArraySizeType.Int32:
             return streamReader.ReadInt32();
         case ArraySizeType.X3F1:
             var length3F1 = streamReader.ReadInt32();
             return (length3F1 / 0x03F1) - 1;
         case ArraySizeType.NullTerminated:
             return null;
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
예제 #52
0
        public virtual SqlQuery CreateQuery(object entity, IEntityMetaData metaData, int index, out PropertyMetaData identity)
        {
            if (null == entity)
                throw new ArgumentNullException(nameof(entity));

            identity = null;

            bool insertFieldsEnabled = !this.InsertFields.IsEmptyList();

            SqlQuery query = new SqlQuery();
            StringBuilder text = query.Text;
            text.Append("INSERT INTO ");
            text.Append(metaData.TableName);
            text.Append(" (");

            List<PropertyMetaData> validInfos = new List<PropertyMetaData>();
            foreach (PropertyMetaData property in metaData.Properties)
            {
                SchemaInfo schema = property.Schema;

                switch (schema.DatabaseGeneratedOption)
                {
                    case StoreGeneratedPattern.Identity:
                        if (null != identity)
                            throw new MultipleIdentityColumnFoundException(entity);

                        identity = property;
                        break;

                    case StoreGeneratedPattern.Computed:
                        break;

                    default:
                        if (insertFieldsEnabled && !this.InsertFields.Contains(schema.ColumnName))
                            continue;

                        text.Append(schema.ColumnName);
                        text.Append(',');

                        validInfos.Add(property);
                        break;
                }
            }

            text.Remove(text.Length - 1, 1);
            text.Append(") VALUES (");

            foreach (PropertyMetaData property in validInfos)
            {
                SqlQueryHelper.SetColumnValue(ValueSetter.Instance, metaData, index, query, property, entity);

                text.Append(',');
            }
            text.Remove(text.Length - 1, 1);
            text.Append(')');
            if (null != identity)
            {
                text.Append(" RETURNING ");
                text.Append(identity.Schema.ColumnName);
                text.Append(';');
            }
            else if (this.UseSemicolon)
                text.Append(';');

            return query;
        }
예제 #53
0
        public virtual SqlQuery CreateQuery(object entity, IEntityMetaData metaData, int index, out PropertyMetaData sequenceIdentity)
        {
            if (null == entity)
                throw new ArgumentNullException(nameof(entity));

            sequenceIdentity = null;

            bool insertFieldsEnabled = !this.InsertFields.IsEmptyList();

            SqlQuery query = new SqlQuery();
            StringBuilder text = query.Text;
            text.Append("INSERT INTO ");
            text.Append(metaData.TableName);
            text.Append(" (");

            List<PropertyMetaData> validInfos = new List<PropertyMetaData>();
            foreach (PropertyMetaData property in metaData.Properties)
            {
                SchemaInfo schema = property.Schema;

                switch (schema.DatabaseGeneratedOption)
                {
                    case StoreGeneratedPattern.Identity://Oracle 12c ile test edilip bu kısımda çalışılabilr hale getirilecek.
                    case StoreGeneratedPattern.Computed:
                        continue;// not in insert list.

                    //case StoreGeneratedPattern.Sequence:
                    //    if (schema.DefaultValue.Length == 0)
                    //        throw new NullReferenceException("if SchemaInfo.DatabaseGeneratedOption = Sequence then Schema.DefaultValue can not be null or empty");
                    //    break;
                    case StoreGeneratedPattern.AutoGenerateSequence:
                        if (null != sequenceIdentity)
                            throw new MultipleIdentityColumnFoundException(entity);

                        sequenceIdentity = property;
                        break;//Identity ise insert list e giriyor.
                    default:
                        if (insertFieldsEnabled && !this.InsertFields.Contains(schema.ColumnName))
                            continue;
                        break;
                }


                text.Append(schema.ColumnName);
                text.Append(',');

                validInfos.Add(property);
            }

            text.Remove(text.Length - 1, 1);
            text.Append(") VALUES (");

            bool addSequenceIdentity = null != sequenceIdentity;

            foreach (PropertyMetaData property in validInfos)
            {
                SchemaInfo schema = property.Schema;

                if (addSequenceIdentity && sequenceIdentity.Schema.Equals(schema))
                {
                    text.Append(SequenceManager.GetSequenceName(this.dataAccess, metaData.TableName, sequenceIdentity.Schema.ColumnName));
                    text.Append(".NEXTVAL,");
                    addSequenceIdentity = false;
                }
                else
                {
                    SqlQueryHelper.SetColumnValue(ValueSetter.Instance, metaData, index, query, property, entity);

                    text.Append(',');
                }
            }
            text.Remove(text.Length - 1, 1);
            text.Append(')');
            if (null != sequenceIdentity)
            {
                text.AppendLine();

                text.Append("RETURNING ");
                text.Append(sequenceIdentity.Schema.ColumnName);
                text.Append(" INTO :");

                string parameterName = metaData.GetParameterName(sequenceIdentity, index);
                text.Append(parameterName);

                SqlQueryParameter identityParameter = SqlQueryHelper.EnsureHasParameter(query, parameterName, sequenceIdentity, entity);
                identityParameter.Direction = this.isUpsert ? System.Data.ParameterDirection.InputOutput : System.Data.ParameterDirection.Output;
            }
            if (this.UseSemicolon)
                text.Append(';');

            return query;
        }
 public Expression SerializerExpression(
     ParameterExpression streamWriterExpression,
     ParameterExpression serializationContextExpression,
     Expression valueExpression,
     PropertyMetaData propertyMetaData)
 {
     MethodInfo serializerMethodInfo =
         ReflectionHelper
             .GetMethodInfo
             <VendingMachineFullUpdateMessageSerializer,
                 Action<StreamWriter, SerializationContext, object, PropertyMetaData>>(o => o.Serialize);
     NewExpression serializerExp = Expression.New(this.GetType());
     MethodCallExpression callExp = Expression.Call(
         serializerExp,
         serializerMethodInfo,
         new[]
         {
             streamWriterExpression, serializationContextExpression, valueExpression,
             Expression.Constant(propertyMetaData, typeof(PropertyMetaData))
         });
     return callExp;
 }
        public Expression SerializerExpression(
            ParameterExpression streamWriterExpression, 
            ParameterExpression serializationContextExpression, 
            Expression valueExpression, 
            PropertyMetaData propertyMetaData)
        {
            var writeMethodInfo = ReflectionHelper.GetMethodInfo<StreamWriter, Action<byte[]>>(o => o.WriteBytes);
            var getAddressBytesMethodInfo =
                ReflectionHelper.GetMethodInfo<IPAddress, Func<byte[]>>(o => o.GetAddressBytes);

            var callGetAddressBytesExp = Expression.Call(valueExpression, getAddressBytesMethodInfo);

            var callWriteExp = Expression.Call(
                streamWriterExpression, writeMethodInfo, new Expression[] { callGetAddressBytesExp });
            return callWriteExp;
        }
 public void Serialize(
     StreamWriter streamWriter, 
     SerializationContext serializationContext, 
     object value, 
     PropertyMetaData propertyMetaData = null)
 {
     var address = (IPAddress)value;
     streamWriter.WriteBytes(address.GetAddressBytes());
 }
        public object Deserialize(
            StreamReader streamReader,
            SerializationContext serializationContext,
            PropertyMetaData propertyMetaData = null)
        {
            VendingMachineFullUpdateMessage message = new VendingMachineFullUpdateMessage();
            message.N3MessageType = (N3MessageType)streamReader.ReadInt32();
            message.Identity = streamReader.ReadIdentity();
            message.Unknown = streamReader.ReadByte();

            message.TypeIdentifier = streamReader.ReadInt32();

            var identityType = (IdentityType)streamReader.ReadInt32();
            int identityInstance = streamReader.ReadInt32();

            message.NpcIdentity = new Identity() { Type = identityType, Instance = identityInstance };

            if (message.NpcIdentity.Instance == 0)
            {
                message.Coordinates = new Vector3();
                message.Coordinates.X = streamReader.ReadSingle();
                message.Coordinates.Y = streamReader.ReadSingle();
                message.Coordinates.Z = streamReader.ReadSingle();
                message.Heading = new Quaternion();
                message.Heading.X = streamReader.ReadSingle();
                message.Heading.Y = streamReader.ReadSingle();
                message.Heading.Z = streamReader.ReadSingle();
                message.Heading.W = streamReader.ReadSingle();
            }
            message.PlayfieldId = streamReader.ReadInt32();
            message.Unknown4 = streamReader.ReadInt32();
            message.Unknown5 = streamReader.ReadInt32();
            message.Unknown6 = streamReader.ReadInt16();

            int x3f1 = streamReader.ReadInt32();
            x3f1 = x3f1 / 0x03f1;
            List<GameTuple<CharacterStat, uint>> temp = new List<GameTuple<CharacterStat, uint>>();
            while (x3f1 > 1)
            {
                var temptuple = new GameTuple<CharacterStat, uint>();
                temptuple.Value1 = (CharacterStat)streamReader.ReadInt32();
                temptuple.Value2 = streamReader.ReadUInt32();
                temp.Add(temptuple);
                x3f1--;
            }
            message.Stats = temp.ToArray();

            message.Unknown7 = streamReader.ReadString(streamReader.ReadInt32()).Replace("\0", "");
            /*int templen = streamReader.ReadInt32(); // String length!!
            message.Unknown7 = "";
            while (templen > 0)
            {
                message.Unknown7 += (char)streamReader.ReadByte();
                templen--;
            }
            message.Unknown7 = message.Unknown7.TrimEnd('\0');*/
            message.Unknown8 = streamReader.ReadInt32();

            if (message.Unknown8 == 2)
            {
                message.Unknown9 = streamReader.ReadInt32();
                x3f1 = streamReader.ReadInt32();
                x3f1 = x3f1 / 0x03f1;
                List<Identity> tempids = new List<Identity>();
                while (x3f1 > 1)
                {
                    identityType = (IdentityType)streamReader.ReadInt32();
                    identityInstance = streamReader.ReadInt32();
                    tempids.Add(new Identity() { Type = identityType, Instance = identityInstance });
                    x3f1--;
                }
                message.Unknown10 = tempids.ToArray();
            }
            message.Unknown11 = streamReader.ReadInt32();
            return message;
        }
예제 #58
0
        public virtual SqlQuery CreateQuery(object entity, IEntityMetaData metaData, out PropertyMetaData identity)
        {
            EntitySqlQueryBuilderUpdate builderUpdate = new EntitySqlQueryBuilderUpdate();
            builderUpdate.ParameterIndex = this.ParameterIndex;
            builderUpdate.UpdatedFields = this.UpdatedFields;

            SqlQuery query = builderUpdate.CreateQuery(entity, metaData);
            StringBuilder text = query.Text;

            text.AppendLine();
            text.Append("IF @@ROWCOUNT = 0");
            text.AppendLine();
            text.Append("BEGIN");
            text.AppendLine();

            EntitySqlQueryBuilderInsert builderInsert = new EntitySqlQueryBuilderInsert();
            builderInsert.ParameterIndex = this.ParameterIndex;
            builderInsert.InsertFields = this.InsertFields;
            query.Combine(builderInsert.CreateQuery(entity, metaData, out identity));

            text.AppendLine();
            text.Append("END");

            return query;
        }
예제 #59
0
        public virtual SqlQuery CreateQuery(object entity, IEntityMetaData metaData, out PropertyMetaData identity)
        {
            if (null == entity)
                throw new ArgumentNullException("entity");

            identity = null;

            SqlQueryHelper.IndexParameterNames(metaData, this.ParameterIndex);

            bool insertFieldsEnabled = !this.InsertFields.IsEmptyList();

            SqlQuery query = new SqlQuery();
            StringBuilder text = query.Text;
            text.Append("INSERT INTO ");
            text.Append(metaData.TableName);
            text.Append(" (");

            List<PropertyMetaData> validInfos = new List<PropertyMetaData>();
            foreach (PropertyMetaData property in metaData.Properties)
            {
                SchemaInfo schema = property.Schema;

                switch (schema.DatabaseGeneratedOption)
                {
                    case StoreGeneratedPattern.Identity:
                        if (null != identity)
                            throw new MultipleIdentityColumnFoundException(entity);

                        identity = property;
                        break;

                    case StoreGeneratedPattern.Computed:
                        break;

                    default:
                        if (insertFieldsEnabled && !this.InsertFields.Contains(schema.ColumnName))
                            continue;

                        text.Append(schema.ColumnName);
                        text.Append(',');

                        validInfos.Add(property);
                        break;
                }
            }

            text.Remove(text.Length - 1, 1);
            text.Append(") VALUES (");

            foreach (PropertyMetaData property in validInfos)
            {
                SchemaInfo schema = property.Schema;

                SqlQueryHelper.SetColumnValue(ValueSetter.Instance, query, property, entity);

                text.Append(',');
            }
            text.Remove(text.Length - 1, 1);
            text.Append(')');
            if (null != identity)
            {
                text.AppendLine();

                text.Append("SELECT @");
                text.Append(identity.ParameterName);
                text.Append("=SCOPE_IDENTITY()");

                SqlQueryParameter identityParameter = SqlQueryHelper.EnsureHasParameter(query, identity, entity);
                identityParameter.Direction = System.Data.ParameterDirection.InputOutput;
            }

            return query;
        }
예제 #60
0
        public virtual SqlQuery CreateQuery(object entity, IEntityMetaData metaData, int index, out PropertyMetaData sequenceIdentity)
        {
            EntitySqlQueryBuilderUpdate builderUpdate = new EntitySqlQueryBuilderUpdate() { UseSemicolon = true };
            builderUpdate.UpdatedFields = this.UpdatedFields;

            SqlQuery query = new SqlQuery();
            StringBuilder text = query.Text;

            if (!this.isBatchUpsert)
                text.Append(GlobalInternal.OracleBeginStatement);

            query.Combine(builderUpdate.CreateQuery(entity, metaData, index));

            text.AppendLine();
            text.Append("IF SQL%ROWCOUNT = 0 THEN ");
            text.AppendLine();

            EntitySqlQueryBuilderInsert builderInsert = new EntitySqlQueryBuilderInsert(this.dataAccess, true) { UseSemicolon = true };
            builderInsert.InsertFields = this.InsertFields;

            query.Combine(builderInsert.CreateQuery(entity, metaData, index, out sequenceIdentity));

            text.AppendLine();
            text.Append("END IF;");

            if (!this.isBatchUpsert)
                text.Append(GlobalInternal.OracleEndStatement);

            return query;
        }